Check out the previous tutorial:

DL01: Writing a Neural Network from Scratch (Theory)

Hello hackers, time for another coffee break!

This time, let’s start coding.

The accompanying code can be found here.

Numpy is used for mathematical calculations in Python.

Dill is used to store all variables in a python file, so that they can be loaded later. Install using pip3 install dill.

Now, we make a class for the neural_network:

And a class for layer:

Okay, so let’s dive in!

Class neural_network has the following functions:

Class layer has the following functions:

This post explained the code in detail. Although convolutional neural networks (CNNs) perform much better on images, I trained a neural network on MNIST just for the feel of it. CNNs will be covered in a later blog post.

I hope you can now implement a neural network from scratch yourself. Happy coding!