What-If Tool TensorBoard Plugin
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.
Warnings
- deprecated 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.
- gotcha 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.
- gotcha Input datasets for analysis within the What-If Tool in TensorBoard must be in TFRecord file format containing TensorFlow 'Example' protocol buffers.
- breaking 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.
Install
-
pip install tensorboard-plugin-wit
Imports
- What-If Tool Plugin
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
import tensorflow as tf
import numpy as np
import os
from datetime import datetime
log_dir = os.path.join("logs", "whatif_example_" + datetime.now().strftime("%Y%m%d-%H%M%S"))
file_writer = tf.summary.create_file_writer(log_dir)
# Create some dummy data to log to TensorBoard
with file_writer.as_default():
tf.summary.scalar('my_metric/loss', 0.5, step=0)
tf.summary.scalar('my_metric/accuracy', 0.8, step=0)
tf.summary.text('my_experiment/details', 'This is a test run for What-If Tool integration.', step=0)
# What-If Tool also requires a TFRecord file with examples and a served model
# This example only shows basic TensorBoard logging to demonstrate a runnable context.
# For full WIT functionality, prepare TFRecord data and serve a model with TensorFlow Serving.
print(f"TensorBoard logs written to: {log_dir}")
print("To launch TensorBoard, run in your terminal:")
print(f"tensorboard --logdir {os.path.dirname(log_dir)}")
print("Then navigate to http://localhost:6006 and look for the What-If Tool dashboard.")