I 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:
- What will your model architecture look like?
- How should a forward pass be performed, and what will its outputs be?
- How do you want to load your data into the model?
- What optimizer will you use?
- How should training be handled?
- How should validation be handled?
- 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:
(Note that the progress bar and the TensorBoard logs will display nicely when you run them in Jupyter)