Member-only story
Training a Neural Network With a Few, Clean Lines of Code
Reusable, maintainable and easy to understand machine learning code
Less code usually results in readable code that is easy to understand and easy to maintain. The Python programming language, that has become very popular in the machine learning community, allows you to achieve great results with less code compared to other programming languages.
PyTorch is a popular deep learning framework for Python that has a clean API and allows you to write code that really feels like Python. Due to that it’s really fun to create models and perform machine learning experiments with PyTorch in Python.
In this article I’m going to show you the basic steps that you need to train a simple classifier that recognizes handwritten digits. You will see how to
- load the MNIST dataset (the ‘Hello World’ dataset for machine learning) with PyTorch’s data loader
- declare the architecture of our model
- select an optimizer
- implement the training loop
- determine the accuracy of the trained model
I want to keep everything as simple as possible. Therefore, I don’t cover things like overfitting, data preprocessing or different metrics…

