Handwritten Digit Recognizer illustration

Handwritten Digit Recognizer

Draw a digit on the canvas and a small neural network — pretrained on the 60,000-image MNIST handwriting dataset — reads it back in real time. The whole model ships with the page as quantized weights and runs in plain JavaScript, so the prediction updates live under your pointer with no server round-trip. Before the network sees your drawing it is preprocessed exactly like MNIST: downscaled, cropped, resized to 20×20 and centered by its center of mass in a 28×28 field — a magnified preview shows this network’s-eye view. Ten confidence bars display the softmax output over the digits 0–9, the best guess is shown large with a runner-up noted when the network is unsure, and an optional heat grid exposes all 128 hidden-layer activations so you can watch neurons switch on and off as you draw.

Runs 100% in your browser — models are trained and computed locally on your device.

Notes

  • The network is a 784–128–10 multilayer perceptron with ReLU hidden units and a softmax output — small enough that its weights ship with the page as int8-quantized arrays and a forward pass takes a few milliseconds of plain JavaScript.
  • Preprocessing mirrors the original MNIST pipeline: the drawing is scaled to fit a 20×20 box preserving aspect ratio, then placed in the 28×28 input with its pixel center of mass at the middle. Skipping this normalization is the main reason naive demos guess badly.
  • The model scores about 98% on the MNIST test set, but digits drawn with a mouse differ from the pen-on-paper scans it was trained on — thin strokes, unusual proportions or exotic handwriting styles can still fool it.
  • Runs 100% in your browser — models are trained and computed locally on your device.