A New Visualization IDE for Machine Learning

Carey
The Startup
Published in
4 min readOct 12, 2020

--

A screen video of the Weights & Biases interactive custom charts (made by author)

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:

  1. Log custom charts with just 3 lines of code
  2. Play with the code that generates the visualization
  3. 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.

Play with the notebook →

table = wandb.Table(data=data_1, columns=["step", "height"])
histogram = wandb.plot.histogram(table, value='height', title='Histogram')
wandb.log({'my_histo': histogram})
Custom charts from the Weights & Biases dashboard (made by author)

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 the custom chart definition to see the Vega spec and GraphQL query (made by author)
  1. 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.
  2. 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.
  3. 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.
Edit the Vega spec to change how your chart is displayed (made by author)

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.

Save your own preset to use directly from your script (made by author)

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:

  1. Create a new wandb run with wandb.init()
  2. Log some data to a table with wandb.Table()
  3. Map the table columns to the fields in the chart you created
  4. Copy the chart ID to use in wandb.plot_table()
  5. 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”.

Your final dashboard, with the custom charts all set up (made by author)

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

--

--