Visualise with Weight and Biases

Understanding what’s going on when you’ve started training your shiny new ML model is hard enough. Will it work? Have I got the right parameters? Is it the data? Probably.  Any tool that can help with that process is a Godsend. Weights and biases is a great tool to help you visualise and track your model throughout your production cycle. In this blog post, I’m going to detail some basics on how you can initialise and use it to visualise your next project.

Installation

To use weights and biases (wandb), you need to make an account. For individuals it is free, however, for team-oriented features, you will have to pay. Wandb can then be installed using pip or conda.

$ 	conda install -c conda-forge wandb

or 

$   pip install wandb

To initialise your project, import the package, sign in, and then use the following command using your chosen project name and username (if you want):

import wandb

wandb.login()

wandb.init(project='project1')

In addition to your project, you can also initialise a config dictionary with starting parameter values:

wandb.init(
	project='project1',
	name='project1_exp1',
	config={
		'learning_rate':0.02,
		'architecture':'RNN',
		'epochs':5
		}
	)

Thankfully, wandb has made it super easy to track and visualise your experiments as you often only need one or two lines. To log any parameter simply chose how often you would like to take measurements (e.g. through an if statement in the training cycle based on the iteration count), then save the parameter’s value:

wandb.log({'loss': loss, 'accuracy':accuracy'})

# Note: the parameter values should be defined and calculated as part of the training loop before logging.

Once complete you must mark the job as complete:

wandb.finish()

The results can then be viewed under the project section of your wandb page. This is only the simplest use-case of weights and biases. Additional features include system hardware tracking ( e.g. GPU utilisation), data visualisation and hyperparameter tuning and data visualisation. For more information I found this article very helpful when starting: https://theaisummer.com/weights-and-biases-tutorial/

Weights and Biases: https://wandb.ai/site

Author