← The Lab
// The Lab

Neural network from scratch

A small multilayer perceptron written by hand in Python and NumPy, to really understand what happens inside one.

PythonNumPybackprop

To get to the bottom of how neural networks work, I’m building one from the ground up in Python, with nothing but NumPy.

It can already make networks of any size, with as many layers and neurons per layer as you like. It has the usual activation functions, like ReLU and softmax, and calculates the loss. It learns with backpropagation and gradient descent, and it also has the simpler first approach from the book: randomly adjusting the weights and biases and keeping the changes that help.

Below you can train a small network of the same kind in your browser, on the book’s spiral data and a couple of others. Like my project, it can learn with backpropagation or with random search. Switch between them and see the difference for yourself.

The project follows the excellent book Neural Networks from Scratch in Python by Harrison Kinsley and Daniel Kukieła.

Train one yourself

Pick some data and a network, then press Train.

Click the plot to add your own point:
step 0loss –accuracy –

Data