Back to work

Neural Network
from Scratch

A handwritten digit classifier implemented in Python and NumPy.

Python / NumPy / MNISTView on GitHub

Draw a digit

28 × 28

One digit, 0–9. Mouse or touch.

Loading the trained model…

Prediction

-

Draw a digit, then make a prediction.

0
-
1
-
2
-
3
-
4
-
5
-
6
-
7
-
8
-
9
-

Output scores for digits 0-9. Hand-drawn inputs may differ from MNIST.

See the model’s input

Drawings are scaled and centered before prediction.

How the network learns

Forward propagation, ReLU, loss, backpropagation, and a weight update.

Loading a labeled example...

Learning rate 0.1
784 input values, 64 ReLU hidden neurons, and 10 Softmax outputs

1 / 9

Input

Each grayscale pixel is divided by 255 to form 784 input values.

x = pixel / 255

Eight selected input nodes and eight hidden nodes are drawn for readability. All 784 inputs, 64 hidden neurons, and 10 outputs are used in the calculations. Click a node to inspect it.

This walkthrough updates a temporary model copy using one labeled example. My original training averaged gradients over 60,000 images. The digit classifier above keeps its saved weights.

Swipe the diagram to see each layer.

Implementation

This started with wanting to understand how neural networks learn. Inspired by 3Blue1Brown’s neural network series, I implemented the network in Python and NumPy, including forward propagation, backpropagation, and gradient descent.

It takes a 28 × 28 grayscale image and predicts a digit from 0 to 9. Building it helped me connect the matrix operations to what the network is actually doing.

92.45%test accuracy for this demo’s saved model
10,000 held-out MNIST images

Retrained from my original implementation on 60,000 training images: 500 full-batch iterations, learning rate 0.1, seed 42. My original project reported 92.16%. This demo runs the newly saved weights entirely in your browser.

View on GitHub
Next project Local VLM Caption Benchmark