vedant sheel
i trained a neural network and put it in your browser. draw a number, hit run, and watch it actually think. everything you see is real math happening live, and you can click all of it.
vedantsheel.com · vedant.sheel [at] uwaterloo [dot] com
784→64→48→32→16→10, 96.9% accurate
what you're looking at
the thing spinning above is a i trained to read handwritten digits. it has six stops: your drawing (784 numbers), then layers of 64, 48, 32, and 16 , then 10 outputs, one per digit. in total it has 55,626 , and it gets 96.9% of handwritten digits right on .
nothing on this page is a recording. the weights sit in a 560 kb json file your browser downloaded, and when you hit run, your device does all 55,626 multiplications itself, in under a millisecond. the lights in the 3d view are those numbers. hover anything to see its value, click anything to open it up.
one honest note about the picture: drawing all 6,304 connections at once is an unreadable hairball, so the view only draws each neuron's strongest connections. the math underneath always uses every single one, and clicking any neuron shows you all of its weights, including the ones not drawn.
the dataset it learned from is called , introduced in lecun, bottou, bengio & haffner (1998), which is also the paper that made convolutional networks famous.
step 1: your drawing becomes 784 numbers
computers don't see drawings. they see numbers. so the first step is brutal: your drawing gets squashed down to a 28×28 grid, and each of those 784 little squares becomes a number between 0 (no ink) and 1 (full ink). that tiny “what it sees” thumbnail next to the drawing pad is exactly this, and it's all the network ever gets.
before that, i do one sneaky thing the original dataset did too: your digit gets cropped, shrunk to fit a 20×20 box, and centered by its . without this, accuracy on real drawings falls off a cliff, because the network only ever practiced on centered digits.
quick check: you draw a tiny 3 in the corner of the pad. what does the network actually receive?
step 2: 64 neurons look for strokes
each of the 64 neurons in the first layer owns 784 , one per pixel. a neuron multiplies every pixel by its weight for that pixel, adds them all up, and adds one extra number called a . that's it. because the weights line up with pixels, you can literally draw them: click any neuron in the first layer above and you'll see its weights as a 28×28 image. most of them look like little edge and stroke fragments, because that's what turned out to be useful.
the sum then goes through : negative results become zero, positive ones pass through. so a neuron either stays silent or fires by some amount. this one-liner is a big part of why deep networks became trainable at all, see nair & hinton (2010) and glorot, bordes & bengio (2011).
(draw something and hit run. this fills in with your actual numbers)
quick check: a weight from a pixel to a neuron is -2.3. you put ink on that pixel. what happens to the neuron?
steps 3, 4, 5: strokes become parts, parts become shapes
the layers of 48, 32, and 16 neurons never see your pixels. each one only sees the outputs of the layer before it, and does the exact same move: weighted sum, plus bias, relu. so layer two learns things like “fire when stroke-detectors 3 and 17 fire together but 24 doesn't”, which starts to mean loops, crossbars, tails. layer three combines those, layer four combines those. complexity stacks up while every individual step stays dumb.
i'll be honest about the limits of that story: nobody assigns these roles, and real neurons end up messier than “loop detector”. they're whatever mixture of evidence happened to reduce mistakes during training. if you want to see how researchers actually try to figure out what neurons do, the interactive articles at distill (olah et al., 2017) are the best thing on the internet for it.
(draw something and hit run. this fills in with your actual numbers)
why stack layers at all? in theory even one enormous hidden layer can approximate nearly any function, that's a real theorem, see cybenko (1989) and hornik, stinchcombe & white (1989). in practice, depth lets later layers reuse what earlier layers figured out, which needs far fewer neurons than doing everything in one giant step.
quick check: what does a neuron in layer three actually receive as input?
step 6: ten scores, one answer
the last layer is a vote. each of the 10 output neurons (one per digit) takes a weighted sum of the 16 signals from layer four. positive weights are evidence for that digit, negative weights are evidence against. the raw results are called , and they can be any size, which isn't very readable. that's what the next section fixes.
(draw something and hit run. this fills in with your actual numbers)
softmax: why the answer comes as percentages
raises e to the power of each logit, then divides each result by the total. every output lands between 0 and 1 and they always sum to exactly 1:
the exponential is why the network so often says 99%: a logit lead of just 4 becomes an e⁴ ≈ 55× probability ratio. so “99% sure” doesn't mean it's right, it means the winner had a few units more evidence than the runner-up. draw something halfway between a 4 and a 9 and watch the percentages flatten out.
quick check: the network says 98% for '7'. what does that actually tell you?
when it screws up (try it, it's fun)
draw a 1 with a big serif and a base. draw a 7 with a european crossbar. draw something tiny in the corner, or a 6 that's mostly loop. some of these will fool it, and every failure has the same boring, honest cause: the network only knows the world it saw during training, and your drawing left that world.
when a prediction surprises you, look at the “what it sees” thumbnail first. after squashing to 28×28, your careful drawing might genuinely be ambiguous. then click the output neurons and look at which layer-four signals voted for the wrong digit. the wrong answer is never mysterious, it's just arithmetic you can follow, which is exactly what this page is for.
also worth knowing: this is a deliberately simple network. modern digit readers use and get above 99.5% on this dataset. i kept mine fully-connected because you can see every single weight, which you can't really do once convolutions get involved.
how it learned (before you got here)
nothing on this page learns. the weights were frozen before you arrived. training happened once, on my machine, like this: show the network a digit with a known label. run the exact forward pass you've been watching. measure how wrong the percentages were with a . then, and this is the clever part, work backwards through the layers computing, for each of the 55,626 weights, whether nudging it up or down would have made the loss smaller. that backwards sweep is , the algorithm from rumelhart, hinton & williams (1986).
then nudge every weight a tiny step in its helpful direction and repeat. i used an update rule called adam (kingma & ba, 2014) which adapts the step size per weight, and went through all 60,000 training digits eight times (each full pass is called an ). that's roughly 480,000 rounds of guess, score, nudge. stroke detectors and digit votes fall out of nothing but repetition.
quick check: what actually changes while a network trains?
is chatgpt just a bigger version of this?
genuinely, more than you'd think. the core loop, weighted sums, nonlinearities, softmax at the end, loss, backprop, gradient steps, is the same. the big models add a different wiring diagram called a (vaswani et al., 2017, “attention is all you need”), predict the next word instead of a digit, and scale the parameter count from my 55 thousand to hundreds of billions. the mystery of modern ai isn't in the mechanism you just watched. it's in what falls out when you make this mechanism absurdly large.
every term on this page, in one place
- neuron
- adds up its inputs (each times a weight), adds a bias, applies relu. five lines of code.
- weight
- an adjustable number on one connection. positive = evidence for, negative = evidence against.
- bias
- a per-neuron offset that sets how easy it is to fire.
- activation
- a neuron's output after relu. zero means silent.
- relu
- if negative, output 0. otherwise pass through. that's the whole function.
- logit
- a raw output score before softmax. any size, either sign.
- softmax
- turns the 10 logits into percentages that sum to 100.
- parameter
- any trained number. this network has 55,626 (weights + biases).
- loss
- one number scoring how wrong a prediction was. training tries to shrink it.
- gradient
- for each weight, which direction (and how strongly) it would change the loss.
- backpropagation
- the backwards sweep that computes all the gradients in one pass.
- epoch
- one full pass through the 60,000 training images.
- mnist
- the classic dataset of 70,000 handwritten digits this network learned from.
if you want to go deeper
- 3blue1brown's neural network series. the best visual intuition for exactly the network on this page. start here.
- michael nielsen, neural networks and deep learning. a free book that builds this same digit classifier from scratch, with all the math.
- lecun et al. (1998), gradient-based learning applied to document recognition. the mnist paper. also where convolutional networks took off.
- rumelhart, hinton & williams (1986), learning representations by back-propagating errors. the three-page nature paper that made training deep networks practical.
- kingma & ba (2014), adam. the optimizer i used. one of the most cited papers in all of computer science.
- olah et al., distill: feature visualization. what neurons in big vision networks actually respond to. gorgeous and rigorous.
- goodfellow, bengio & courville, deep learning. the standard textbook, free online, when you want the full treatment.
- vaswani et al. (2017), attention is all you need. the transformer paper, if the chatgpt section made you curious.
about this
i'm vedant. i built everything here: trained the network in pytorch (the script is in the repo, it takes about two minutes on a laptop), wrote the forward pass in plain typescript so it runs in your browser with no server, and built the 3d view on top of it. the one rule i held myself to: never fake a number. if something glows, it's because the math said so, and you can click it to check me.
the rest of my stuff lives at vedantsheel.com, and if you want to talk about this: vedant.sheel [at] uwaterloo [dot] com