What-If Tool TensorBoard Plugin

1.8.1 · maintenance · verified Fri Apr 10

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

Install

Imports

Quickstart

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.

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.")

view raw JSON →