PyTorch Lightning – Regression Example

bikeshare2I find there are a lot of tutorials and toy examples on convolutional neural networks – so many ways to skin an MNIST cat! – but not so many on other types of scenarios.

So I’ve decided to put together a quick sample notebook on regression using the bike-share dataset. After learning the basics of neural networks with PyTorch, I’ve settled on using PyTorch Lightning to structure my code: I really like how this neatens up your code and takes the burden of coding up those long training loops out of the equation, while still giving you a lot of flexibility when developing your model!

You’re basically working with a template where you answer the following questions – without the need for reams of boilerplate code:

  1. What will your model architecture look like?
  2. How should a forward pass be performed, and what will its outputs be?
  3. How do you want to load your data into the model?
  4. What optimizer will you use?
  5. How should training be handled?
  6. How should validation be handled?
  7. How should testing be handled?

To benefit from looking at this sample you’ll need to have a basic understanding of PyTorch, and I’d suggest you start by reading the PyTorch Lightning INTRODUCTION GUIDE – once you’ve done that, here’s another example to show you how it can all be implemented:

How it works – Bike Share Regression PyTorch Lightning

(Note that the progress bar and the TensorBoard logs will display nicely when you run them in Jupyter)

Comments are closed.

Create a website or blog at

Up ↑

%d bloggers like this: