Inside a neural network
Draw a digit and watch a trained network read it, one neuron at a time.
Draw a digit and watch a trained network read it, one neuron at a time.
A real neural network reads your handwriting. It learnt from 60,000 handwritten digits (the MNIST set) and is tiny: 256 pixels in, 16 hidden neurons and 10 outputs, one per digit. That’s 4,282 numbers in all, and you can see every one of them at work.
Draw a digit on the pad, or pick one from MNIST’s test set, and follow it through the network one layer at a time. The question: how can a heap of multiplications and additions tell which digit you drew?
It reads 799.0% sure
Digits from MNIST (Yann LeCun, Corinna Cortes and Christopher Burges), CC BY-SA 3.0, shrunk to 16 × 16.
This is an MNIST test digit: it was already scaled into the middle and centred by its centre of mass. Draw your own digit to watch those steps.
Row 14, column 8: x₂₁₆ = 0.875
Row 1 of the picture is x₁ to x₁₆, row 2 is x₁₇ to x₃₂, and so on to x₂₅₆. The pixel you picked is x₂₁₆; the one just below it in the picture is x₂₃₂, 16 places further along the list. The network is never told which pixels are neighbours: to it, they are just 256 numbers.
A neuron. Each hidden neuron multiplies every pixel by its own weight, adds them up with a bias, and passes the total through ReLU, which keeps a positive total and turns a negative one into 0. Its 256 weights, drawn as a 16 × 16 picture, show what it looks for.
The outputs. Each digit’s score is another weighted sum, this time of the 16 hidden neurons’ outputs. Softmax turns the ten scores into probabilities that add up to 1, and the network’s answer is the most likely digit.
Where the numbers came from. Training on MNIST’s 60,000 training digits set all 4,282 weights and biases; the test digits here were never used for training. Here the numbers stay fixed and you watch them work. How training finds them is in the A tiny neural network simulator.
A neuron. Each hidden neuron multiplies every pixel by its own weight, adds them up with a bias, and passes the total through ReLU, which keeps a positive total and turns a negative one into 0. Its 256 weights, drawn as a 16 × 16 picture, show what it looks for.
The outputs. Each digit’s score is another weighted sum, this time of the 16 hidden neurons’ outputs. Softmax turns the ten scores into probabilities that add up to 1, and the network’s answer is the most likely digit.
Where the numbers came from. Training on MNIST’s 60,000 training digits set all 4,282 weights and biases; the test digits here were never used for training. Here the numbers stay fixed and you watch them work. How training finds them is in the A tiny neural network simulator.
Things to try