Plotting loss function in Jupyter

Posted in General by Igor Fedorov Tue Apr 26 2016 01:13:03 GMT+0000 (UTC)·5·Viewed 974 times

Is there a way to plot the loss function as a function of iteration number (during training) within the Jupyter notebook?
Markus Beissinger
Apr 26, 2016

The master branch lets you plot loss as a function of epoch number during training using Bokeh - see

If you want to plot per minibatch iteration, see the in-development branch monitor_customization

Here, you can initialize the Monitor class with the level parameter to be 'batch' or 'epoch'.

Within the Jupyter notebook, you would have to write your own graphing function given the output of the monitor. If you want the live plot in Bokeh, use the built in Plot class here as shown in the tutorial above.

Let me know if you have more questions!

Igor Fedorov
Apr 26, 2016

I would like to go the route of creating my own plotting function in Jupyter, but I'm still confused. Let's use the example ( as the point of reference. I would like to plot the value of the cost function during training (I'm not particularly concerned about whether it is a function of epoch number or minibatch number). I'm assuming that I would need to first create a MonitorsChannel:

output_channel = MonitorsChannel(name="training_error")

and then pass this to the optimizer:


Is this correct? If so, what is the next step?

On a sideonote, can you provide a reference for how to use markdown within the forum?

Markus Beissinger
Apr 28, 2016

Yep that is correct! you don't need to make a full MonitorsChannel if you aren't grouping more than one monitor together, you can use the Monitor class directly with optimizer.train(monitor_channels=output_monitor). You can do something like:

from opendeep.monitor import PrintService

output_monitor = Monitor(name="training_error", expression=your_error_calculation_in_theano, out_service=PrintService(name="training_error"), train=True, valid=False, test=False)


This will print out the monitor values to the console (stdOut, wherever Python's print function goes). If you want the values to be stored in a file to graph later, you can use a FileService instead of a PrintService. Details can be seen here:

And here is a good Markdown cheatsheet:

Markus Beissinger
Apr 28, 2016

Best bet might be to use the FileService and have a separate jupyter process loop reading from the file and graphing while the training is happening so the graph gets updated in realtime.

Markus Beissinger
Apr 28, 2016

Or to use the builtin Plot to make a Bokeh plot in your browser instead of having to use Jupyter :)

plot = Plot("training_error", output_monitor, open_browser=True)

Markdown is allowed