A New Visualization IDE for Machine Learning
Upgrade your ML workflow from tinkering with matplotlib to automatically generating interactive charts straight from your ML training script. I’ll show you how to:
- Log custom charts with just 3 lines of code
- Play with the code that generates the visualization
- Save custom presets to use from your script
Log charts in 2 minutes
In your Python script, specify a table of data to visualize. The columns can be anything you like, and you’ll use them later in the chart to specify the different features. For example, for a scatter plot you would want to specify an x and y axis, as well as an optional color axis.
To follow this tutorial, open this Google Colab and run the cells. Re-run the script multiple times to get data you can compare across runs in the dashboard.
table = wandb.Table(data=data_1, columns=["step", "height"])
histogram = wandb.plot.histogram(table, value='height', title='Histogram')
wandb.log({'my_histo': histogram})
Customize the visualizations
To tailor the visualizations, we’re going to use Vega. It’s a declarative visualization grammar that lets you specify exactly how you want your data to be visualized.
- Edit chart: Click the pencil icon to edit the chart. You’ll see a preview of the chart on the left, and an interactive query on the right. The query lets you specify exactly what fields to visualize in the chart, and the dropdown boxes below give you a way to map the query results to the chart inputs.
- Open spec: Inside the modal, you’ll see the name of a chart preset in the upper left corner. Open the chart definition by clicking that Edit button next to the dropdown. Now you’ll see the Vega spec on the left — it’s just fancy JSON.
- Edit spec: The Vega spec defines the details of how the histogram is displayed. Try tinkering with the code to see what changes in the preview chart on the right. For example, you can remove the line
"stack": null
to make the chart default back to stacking on top of each other.
Create a new preset
Now that you’ve customized the chart to your liking, save it as a new preset so you can reuse it in your next experiment. Click Save as and enter a name. To change the description, use the Description
field inside the Vega spec itself.
Create a chart using that preset
Now that I have a new custom chart ID, I can call that chart from my script. You can see below how I follow the same simple steps:
- Create a new wandb run with wandb.init()
- Log some data to a table with wandb.Table()
- Map the table columns to the fields in the chart you created
- Copy the chart ID to use in wandb.plot_table()
- Log the chart you created with wandb.log()
In this screenshot you can see the new histogram appear on the scene — looking dapper! If you want to further customize the chart, you can overwrite this chart definition by logging to the same key in wandb.log(). In my case in the script above this would be “custom_chart”.
You did it! 🎉
That’s it, that’s the whole tutorial. Reach out to me at c@wandb.com if you have any questions or suggestions. If you create a cool chart preset, send me an email with a link to the chart. If I like what I see, I’ll send you a hand written note and stickers, straight from W&B virtual HQ!
More resources
- Live report with great examples of custom charts in Weights & Biases
- Custom Charts documentation for details on what’s possible
- Vega documentation for custom chart ideas
- Weights & Biases documentation for a broader look at the ML developer tools available
- Gallery of machine learning projects for inspiration from ML researchers