{"id":2802,"library":"tensorboard-plugin-wit","title":"What-If Tool TensorBoard Plugin","description":"The tensorboard-plugin-wit package integrates the What-If Tool (WIT) into TensorBoard, providing an interactive visual interface for understanding black-box machine learning models. It enables users to perform inference on datasets, visualize results, and manually or programmatically edit examples to observe how changes affect model predictions. The current version is 1.8.1, released on January 5, 2022. The underlying What-If Tool project is hosted on GitHub under `pair-code/what-if-tool` but is no longer actively maintained.","status":"maintenance","version":"1.8.1","language":"en","source_language":"en","source_url":"https://github.com/pair-code/what-if-tool","tags":["tensorboard","machine-learning","visualization","interpretability","debugging","what-if-tool","tensorflow"],"install":[{"cmd":"pip install tensorboard-plugin-wit","lang":"bash","label":"Install with pip"}],"dependencies":[{"reason":"The plugin integrates with and requires a TensorBoard installation to function. 'tensorboard-plugin-wit' is often installed automatically as a dependency of 'tensorboard'.","package":"tensorboard","optional":false},{"reason":"To analyze a model within TensorBoard using WIT, the model must be served via TensorFlow Serving's classify, regress, or predict API.","package":"tensorflow-serving"},{"reason":"Often required for preparing data (e.g., TFRecord files) or for custom Python prediction functions if not using TensorFlow Serving. TensorBoard itself generally aligns with TensorFlow versions.","package":"tensorflow"}],"imports":[{"note":"The 'tensorboard-plugin-wit' package registers the What-If Tool as a TensorBoard plugin. Users interact with it through the TensorBoard web interface after launching TensorBoard. Direct programmatic control over the UI from Python is not the standard usage pattern.","wrong":"from tensorboard_plugin_wit import WhatIfToolPlugin","symbol":"What-If Tool Plugin","correct":"The plugin is primarily accessed via the TensorBoard UI after launching TensorBoard. There is no direct Python import for the main plugin functionality, though parts of the underlying 'witwidget' library might be imported for advanced programmatic use."}],"quickstart":{"code":"import tensorflow as tf\nimport numpy as np\nimport os\nfrom datetime import datetime\n\nlog_dir = os.path.join(\"logs\", \"whatif_example_\" + datetime.now().strftime(\"%Y%m%d-%H%M%S\"))\nfile_writer = tf.summary.create_file_writer(log_dir)\n\n# Create some dummy data to log to TensorBoard\nwith file_writer.as_default():\n    tf.summary.scalar('my_metric/loss', 0.5, step=0)\n    tf.summary.scalar('my_metric/accuracy', 0.8, step=0)\n    tf.summary.text('my_experiment/details', 'This is a test run for What-If Tool integration.', step=0)\n    # What-If Tool also requires a TFRecord file with examples and a served model\n    # This example only shows basic TensorBoard logging to demonstrate a runnable context.\n    # For full WIT functionality, prepare TFRecord data and serve a model with TensorFlow Serving.\n\nprint(f\"TensorBoard logs written to: {log_dir}\")\nprint(\"To launch TensorBoard, run in your terminal:\")\nprint(f\"tensorboard --logdir {os.path.dirname(log_dir)}\")\nprint(\"Then navigate to http://localhost:6006 and look for the What-If Tool dashboard.\")","lang":"python","description":"This quickstart demonstrates how to generate basic TensorBoard logs. After running this Python code, launch TensorBoard from your terminal, pointing it to the parent directory of your logs. Once TensorBoard is running, navigate to its web interface (usually http://localhost:6006) and select the 'What-If Tool' from the dashboard dropdown. Note that for the What-If Tool to be fully functional, you would typically need a model served via TensorFlow Serving and a dataset in TFRecord format. This example primarily shows how to set up a basic TensorBoard environment where the plugin can be accessed."},"warnings":[{"fix":"Migrate to the Learning Interpretability Tool (LIT) for ongoing support and new features.","message":"The What-If Tool and its TensorBoard plugin are no longer actively maintained. Users are strongly encouraged to consider the actively maintained Learning Interpretability Tool (LIT) as an alternative for model understanding and interpretability.","severity":"deprecated","affected_versions":"All versions, as of TensorFlow 2.11 and earlier documentation."},{"fix":"Ensure your machine learning model is deployed using TensorFlow Serving before attempting to analyze it with the What-If Tool in TensorBoard. Alternatively, use 'notebook mode' or a custom Python prediction function provided to TensorBoard with `--whatif-use-unsafe-custom-prediction`.","message":"Full functionality of the What-If Tool in TensorBoard requires a model served via TensorFlow Serving. The model must expose its prediction interface through TensorFlow Serving's classify, regress, or predict API.","severity":"gotcha","affected_versions":"All versions."},{"fix":"Convert your dataset into the TFRecord format with TensorFlow Example protos. The TFRecord file needs to be accessible by the TensorBoard web server, typically under the `--logdir` or a path specified by `--whatif-data-dir`.","message":"Input datasets for analysis within the What-If Tool in TensorBoard must be in TFRecord file format containing TensorFlow 'Example' protocol buffers.","severity":"gotcha","affected_versions":"All versions."},{"fix":"Ensure consistent versions of TensorFlow and TensorBoard. If using TF 2.x, ensure TensorBoard is also 2.x compatible (preferably the latest compatible version). Consider using isolated virtual environments (e.g., `venv` or `conda`) to manage dependencies.","message":"Mixing TensorFlow 1.x and 2.x environments or incompatible TensorBoard versions can lead to issues such as 'duplicate plugins' or 'ImportError: TensorBoard logging requires TensorBoard version 1.15 or above'. TensorBoard versions 2.4.0 and above explicitly require TensorFlow 2.x.","severity":"breaking","affected_versions":"TensorBoard 2.4.0+ and any older incompatible TensorFlow/TensorBoard setups."}],"env_vars":null,"last_verified":"2026-04-10T00:00:00.000Z","next_check":"2026-07-09T00:00:00.000Z"}