← Home

How a computer reads a handwritten digit

Project

Draw a digit and follow its real 8×8 pixels through a small neural network to ten probabilities.

A small, real neural network

Draw → pixels → prediction

Try a digit from 0 to 9. Follow the exact numbers the model uses as it makes its guess.

01

Make an input

Draw with a finger, mouse or pen. Keyboard: load a sample or edit cells in the pixel grid.

Or load a real held-out example
02

See the 64 numbers

Each square is one input value. Select a square to cycle its brightness: 0, 8, 16. The grid is keyboard accessible.

0 = background · 16 = brightest ink

03

Read the guess

Loading the local model…

A high score is confidence within this model. It can still be wrong.

04

Look inside one hidden unit

The 32 bars below show actual activations from the current input. Select one to see how all 64 pixels contribute to it.

Load or draw a digit to inspect its calculation.

A digit begins as an image. The computer turns it into 64 brightness numbers, then applies a function whose weights were learned from labeled examples. Try a drawing or load a sample above. The prediction may be wrong, especially when your strokes differ from the training images.

The mathematical picture

The 8 × 8 image becomes a vector x = (x₁, …, x₆₄). Each value is a pixel brightness from 0 (background) to 1 (ink). In this model, f(x; θ) has one hidden layer with 32 units. θ means all its learned weights and biases. For hidden unit j:

zⱼ = bⱼ + Σᵢ xᵢWᵢⱼ, then aⱼ = max(0, zⱼ).

In words: multiply each input pixel by that unit's weight, add all 64 products and its bias, then keep the positive part. Select a hidden unit in the interactive view to inspect that exact calculation. The second layer similarly combines the 32 activations into ten scores, one for each digit. softmax(score)ₖ = e^(scoreₖ) / Σₗ e^(scoreₗ) turns those scores into values that sum to 1. These are model probabilities, not guarantees that its answer is correct.

The 8 × 8 grid is the complete 64-dimensional input, arranged like an image so it can be seen. The hidden bars are the actual 32 activations; their positions are a list, not a two-dimensional map of the model's space.

Learning is different from guessing

During training, the model saw labeled 8 × 8 images. It compared its predictions with the correct labels using cross-entropy loss, then adjusted θ to reduce that loss. During inference here, your pixels move through the fixed weights. Your drawing does not retrain the model.

This small demonstration was trained locally on the scikit-learn digits dataset, a 1,797-image copy of part of the UCI Optical Recognition of Handwritten Digits data by E. Alpaydin and C. Kaynak (1998), DOI 10.24432/C50P49. The source dataset is CC BY 4.0; this page uses ten sample images and derived model weights. Its 8 × 8 pixels are integers from 0 to 16. A reproducible 80/20 stratified split held out 360 of the 1,797 images for testing. The model classified 348 of 360 (96.7%) correctly on that held-out split. This is not an accuracy estimate for visitors' drawings. Your drawing is cropped and resized to resemble the training format; handwriting outside that format can behave differently.

All drawing, resizing and inference happen in this browser. No drawing is uploaded, stored or sent to analytics.