ONE DRAWING · THREE READINGS

How a neural network reads
a handwritten digit

SEVEN · 98.3%

Seven chapters and a finale: one hand-drawn digit, read three different ways. Every scene plays itself — watch, or just scroll. Dotted terms are tappable. You are the drawing.

00

Your seven becomes 784 numbers

You drew a seven, and the machine has no eyes, no retina, and no notion of ink. Before anything that deserves the word “reading” can happen, your gesture has to become the only thing a network takes as input: a list of numbers. That conversion is this chapter. Watch the multiply-accumulate counter in every panel below — it stays pinned at zero the whole way down, because nothing here is thinking yet.

STEP 01 / 04
THE CANVAS WAS A SPREADSHEET ALL ALONG
the canvas, as the network receives it — 28 × 28 cells
ZOOM ×6 — an edge of the slash
0
89
255
0
128
242
12
251
76
784 cells · one integer each · 0–255

The drawing surface was never a picture. The 28×28 canvas is a grid of 784 cells, and each cell holds one number — a brightness from 0 (paper) to 255 (full ink). Your pen stroke lands anti-aliased: the core of the line saturates, but its edges trail off through greys like 120 and 12. Nothing downstream will ever see “a seven”, a stroke, or a shape. From here on, the network receives exactly 784 integers, and everything it will ever know about your drawing has to be reconstructed from them.

the network never sees a seven — it sees 784 numbers between 0 and 255
STEP 02 / 04
A DATASET WRITTEN HALF BY TEENAGERS
two sources, one dataset — NIST special databases, remixed
CENSUS CLERKS · SD-3
3
7
5
tidy, even pressure
MNIST
60,000 digits
30k + 30k, shuffled
HIGH SCHOOLERS · SD-1
4
1
8
chaos, on purpose
train on tidy only → fail on messy. so: mixed.

The network learned to read from — 60,000 training digits remixed in the 1990s from scanned US government forms, plus 10,000 held back for testing. Half were written by Census Bureau clerks, all tidy loops and even pressure; half by American high-school students, who wrote like American high-school students. NIST’s original split trained on the clerks and tested on the teenagers; Yann LeCun’s team shuffled the two together precisely because a network raised on neat handwriting falls apart on messy handwriting. Your scribble is being read by a machine educated on both.

half of the 60,000 training digits were written by American high-school students
STEP 03 / 04
EVERY DIGIT IS SECRETLY CENTERED
preprocessing: recenter by ink mass, rescale to 0–1
7
20×20 in a 28×28 frame
[ 0, 12, 251, 255 ]
↓ ÷ 255
[ 0.00, 0.05, 0.98, 1.00 ]
lopsided, unscaled inputs make training stagger

Before a single digit reached the network, MNIST standardized it. Each one was scaled to fit a 20×20 box, then placed inside the 28×28 frame so that the center of mass of its ink — the average position of every dark pixel — sits exactly in the middle. Then every value is divided by 255, mapping the canvas into 0.0–1.0. None of this is glamorous, and all of it matters: training staggers on lopsided, unscaled inputs. A surprising share of machine learning is exactly this — janitorial work performed on numbers.

every MNIST digit is auto-centered by the center of mass of its ink
STEP 04 / 04
YOUR DRAWING IS ONE POINT IN 784 DIMENSIONS
the grid unravels, row after row (28×28 shown as 8×8)
↓ flatten
index 0one row after another783
x ∈ ℝ⁷⁸⁴ — your drawing is one point

The grid was a courtesy for your eyes. The network flattens it, row after row, into a single list of 784 numbers — and geometrically, that list is one point in a 784-dimensional space. Every seven anyone has ever drawn is a point somewhere nearby; the eights live in a different neighborhood. “Recognizing digits” turns out to mean carving that space into ten regions and reporting which one your point fell into. Note the counter below: still zero. Re-encoding is free. Thinking is multiplication, and none has happened yet.

so far the network has computed nothing — Σ is still 0 on purpose
deep dive: what a tensor is, and why grayscale

Shapes and tensors. The same 784 numbers travel under different shapes: a dense network wants a flat [784] vector, a convolutional one wants [28, 28, 1] — height, width, channels. A “tensor” is nothing more exotic than an n-dimensional array with a declared shape, and half of practical deep learning is bookkeeping those shapes so the matrix multiplies line up.

Why grayscale? Color would triple the input to 2,352 values without helping — ink is ink. MNIST’s 28×28 grayscale was chosen in the 1990s to fit the compute of the era, and it stuck as the field’s fruit fly: small enough to train in seconds today, real enough to expose bad ideas.

Free data from nothing. Shift every training digit a pixel or two, rotate it a few degrees, and you have several datasets for the price of one. This is data augmentation, and it teaches the network an invariance the flat vector hides — a preview of chapter 05’s whole argument.

MNIST is solved. The best published error rates sit around 0.13–0.23%, at or beyond careful human performance, which is why benchmarks moved on (Fashion-MNIST swaps digits for clothing photos at the exact same shape). And a blank canvas? The network still answers — chapter 03 explains why it has no way to say “nothing”.

01

One neuron, one opinion

The machine that will read your seven is built from exactly one kind of part, repeated. No grammar, no digit knowledge, no cleverness — a cell that multiplies, adds, and bends. This chapter takes one such cell apart, and pays for it: the Σ MAC counter moves for the first time, by exactly 784.

STEP 01 / 05
A CELL THAT ONLY MULTIPLIES AND ADDS
one neuron’s entire inner life: w·x + b
0.00× 0.31
0.98× 0.44
0.05× −0.12
1.00× 0.27
0.87× 0.08
0.12× −0.05
… and 778 more pixels
Σ w·x2.71
+ b (−0.31) = 2.40
784 multiply-accumulates — the counter moves

Meet #47, one cell of the layer your seven is about to hit. It owns 784 — one per pixel — and a single . Its whole job: multiply every pixel by its matching weight, add everything up, add the bias: w·x + b = 2.40. That is 784 , and the counter in the panel below finally moves. There is nothing else inside — no rules, no templates, no if-statements. Everything the network will ever “know” lives in how these multipliers are set.

the atomic operation of all deep learning fits in one line: multiply, add, repeat
STEP 02 / 05
THE 20-WATT ORIGINAL
the original, and the cartoon we compute with
╲ │ ╱ ╲ │ ╱ ( ● )──▶ ╱ │ ╲ ╱ │ ╲
dendrites · soma · axon
86 B neurons · ~20 W
— simplify —≈ 10⁹× cruder
x₁ ─x₂ ─x₃ ─
Σ
ƒ
weights · sum · bend
1 GPU · ~700 W
kept: many weighted inputs, one output. discarded: everything else.

The design is a cartoon of a biological neuron: dendrites collect signals, the soma sums them, the axon fires the result forward. The original still embarrasses the copy — your brain runs 86 billion neurons on roughly 20 watts, a dim light bulb, while the datacenter GPU caricaturing a sliver of it pulls 700. The cartoon throws away nearly everything — spike timing, neurotransmitter chemistry, dendritic computation — and keeps one load-bearing idea: many weighted inputs, one output. That idea, it turns out, was the part that mattered.

your brain runs 86,000,000,000 neurons on roughly 20 watts
STEP 03 / 05
1958: THE MACHINE THAT SAW WITH 400 EYES
Mark I perceptron, 1958 — the weights are physical knobs, turned by motors
400 photocells · 20×20
⌁⌁⌁⌁⌁⌁⌁⌁⌁
8 of 512 motor-driven potentiometers
NYT · JUL 8 1958 — “embryo of an electronic computer”

The idea is older than the moon landing. In 1958, Frank Rosenblatt’s Mark I Perceptron read images through 400 photocells in a 20×20 grid — nearly the same retina as our 28×28 canvas — and stored its weights in 512 potentiometers physically turned by electric motors. Learning meant knobs rotating. The Navy’s press conference got away from everyone: the New York Times relayed the claim below with a straight face, sixty-eight years ago. The hype cycle is not new; only the hardware is.

1958 press: a machine that will "walk, talk, see, write, reproduce itself and be conscious of its existence"
STEP 04 / 05
THE BEND THAT MAKES IT THINK
why every neuron needs the bend
L₁∘L₂∘L₃ = one layer
linear × linear × linear
ReLU: max(0, x)
one kink changes everything
without it: only straight cuts through ℝ⁷⁸⁴. with it: any shape.

One flaw would make all of this pointless: chaining weighted sums produces… another weighted sum. Stack a hundred purely linear layers and the tower collapses, mathematically, into one. So after summing, every neuron bends its output through an . Ours is ReLU — max(0, x) — keep positives, zero out negatives. It looks too stupid to matter. But that one kink is the difference between a network that can only draw straight lines through 784-dimensional space and one that can carve it into any shape training demands.

without the bend, a 100-layer network is mathematically identical to a 1-layer one
STEP 05 / 05
WHAT #47 IS ACTUALLY LOOKING FOR
neuron #47’s 784 weights, reshaped back into 28×28
weight > 0 — wants ink here
weight < 0 — punishes ink here
your bar lands on the violet band ✓
activation: 0.83

So what did training actually put inside #47? Take its 784 weights and reshape them back into a 28×28 image: they draw a faint picture. Positive weights trace a horizontal band where a seven’s top bar tends to sit; negative weights punish ink where sevens rarely put any. A neuron is a feature detector, and its weights are literally a portrait of the feature it hunts. Your seven’s top bar lands square on the bright band, and #47 fires 0.83 — one vote, of 128 still to come, that this drawing has a bar on top.

a trained neuron's weights, reshaped to 28×28, draw a picture of the stroke it hunts
deep dive: the activation zoo and the first AI winter

The activation zoo. Before ReLU, networks bent their sums through sigmoid or tanh — smooth S-curves that squash everything into a narrow band. Neat, but they saturate: far from zero their slope is nearly flat, and training signal dies crossing them. ReLU (popularized around 2010–2012) is cruder and trains far deeper networks; modern transformers mostly use GELU, a smoothed relative.

The bias is a threshold. Adding b before the bend is the same as moving the neuron’s firing threshold: a very negative bias makes it skeptical (needs strong evidence to fire), a positive one makes it eager. Rosenblatt’s perceptron learning rule adjusted weights and threshold after every mistake — and provably converges, if the classes are linearly separable at all.

1969: the counterexample that froze a field. Minsky & Papert’s book Perceptrons proved a single layer cannot compute XOR — trivial for the multi-layer networks of this tutorial, but nobody yet knew how to train those. Funding evaporated for a decade. Rosenblatt died in a boating accident in 1971, sixteen years before backpropagation’s revival vindicated the whole program.

02

The forward pass

One neuron cast one vote: “there is a bar on top.” A vote is not a verdict. Wire 128 such cells side by side, fire them all at your seven in the same instant, and the Σ MAC counter jumps from 784 to 100,352.

STEP 01 / 05
128 OPINIONS AT ONCE
128 neurons read all 784 pixels in the same instant
x · 784
#47 · 0.83#91 · 0.77
784 × 128 = 100,352 MAC — in one shot

The is neuron #47’s whole cohort: 128 cells, each owning its own 784 weights, each reading your entire seven at the same instant. Each one hunts a different stroke. #12 looks for a closed loop (bad news for it today), #47 for the top bar, #91 for a long descending diagonal. One , one instant: 784 × 128 = 100,352 multiply-accumulates. The counter that crawled to 784 last chapter jumps three orders of magnitude in a single step — and this is still the small layer of a toy network.

one layer, one instant: 100,352 multiplications
STEP 02 / 05
101,770 KNOBS
every adjustable number, counted
input · 784 values
no params — just your pixels
hidden · 128 neurons
784×128 + 128 = 100,480
output · 10 neurons
128×10 + 10 = 1,290
Σ params = 101,770
Mark I512
this net101,770
GPT-class~10¹²
parameters, log scale — same cell, different centuries of scale

Count everything adjustable: 784 × 128 weights plus 128 biases makes 100,480 in the hidden layer; the output layer will add 1,290 more. Total: 101,770 knobs. The Mark I’s motors turned 512; this throwaway tutorial network carries 199 times as many, and a frontier language model carries roughly ten million times more still — the same multiply-add-bend, scaled until the count stops fitting in comprehension. Training, whenever it finally happens, means choosing a value for every single one of them.

this toy net has 199× more knobs than the Mark I — and 10-million-× fewer than a frontier LLM
STEP 03 / 05
FEATURES EAT FEATURES
depth is composition: each tier reads the one below
digit partsbar ┐slash ╱loop ◯ ✗
╲ │ ╱
junctions┐ ┬ ┼ ∠
╲ │ ╱
edges─ │ ╱ ╲
╲ │ ╱
pixels
▷ 7 = bar + slash, no loop — nobody programmed that

Nothing stops you from stacking again. A second layer wouldn’t read pixels — it would read the 128 stroke-opinions, and detect combinations: “top bar AND long diagonal AND no loop anywhere.” That is depth’s whole trick: features eat features. Strokes become junctions, junctions become digit-parts, digit-parts become verdicts. And the uncomfortable, wonderful part — nobody writes any of it. The hierarchy precipitates out of training on its own, which is why these layers are called hidden: even their author doesn’t decide what they detect.

nobody writes the features — they precipitate out of training, layer by layer
STEP 04 / 05
THE 1989 GUARANTEE WITH A CATCH
1989 · Cybenko — one hidden layer can fit any curve. width sold separately.
3 neurons: misses15 neurons: hugs it
* “wide enough” may be astronomically wide — and no recipe for the weights

In 1989 George Cybenko proved the universal approximation theorem: a single hidden layer, wide enough, can approximate any continuous function — including “pixels → digit”. So why does anyone bother with depth? The catch is load-bearing: “wide enough” can mean absurdly, exponentially wide, and the theorem is pure existence — it never says how to find the weights, or how many examples finding them would take. A guarantee that a needle exists, silent about the haystack. Existence is not a recipe; deep learning is the recipe.

the theorem that says one layer suffices never tells you how to find the weights
STEP 05 / 05
FORTY MICROSECONDS OF ALGEBRA
this entire chapter, to the machine
x[1×784] @ W₁[784×128] → h[1×128]
MACs ............ 100,352
wall time ....... ~40 µs (laptop CPU)
GPU ceiling ..... ~10¹⁵ MAC/s
→ ~5,000,000,000 sevens / second
GPUs were built to push triangles — same arithmetic, new customer

Here is what this whole chapter looks like to the machine: one line. h = x @ W₁ — a [1×784] vector times a [784×128] matrix, done on a laptop CPU in roughly 40 microseconds. This is why graphics cards conquered AI: GPUs were already engines for exactly this operation, built to push triangles through the same arithmetic. At around 10¹⁵ multiply-accumulates per second, one modern accelerator could in principle read five billion of your sevens every second. The forward pass isn’t clever. It is algebra with a very good publicist.

one modern GPU could theoretically read ~5,000,000,000 of your sevens every second
deep dive: the linear algebra under the hood

The whole network in two lines. h = ReLU(x·W₁ + b₁), then y = h·W₂ + b₂. Every shape has to agree: [1×784]·[784×128] → [1×128], then [1×128]·[128×10] → [1×10]. When practitioners say a model “doesn’t fit”, they mean these rectangles — parameters times bytes — against a GPU’s memory.

Why not initialize at zero? If every weight starts at 0, all 128 neurons compute the same thing, receive the same correction, and stay identical forever — symmetry never breaks, and your 128 detectors collapse into 1. So weights start as small random numbers, scaled by fan-in (Xavier/He initialization) to keep signals from exploding or dying as they cross layers.

Width vs depth. Width buys parallel detectors; depth buys composition. Both can memorize MNIST, but depth tends to be exponentially more parameter-efficient for compositional structure — which real-world signals are full of. Chapter 05 pushes this further with an architecture that bakes composition in.

Where “40 µs” comes from. ~10⁵ MACs at the few-GFLOP/s a single vectorized CPU core sustains lands in the tens of microseconds. The subtler win is batching: multiplying [64×784]·[784×128] reads the same weights once for 64 digits, so reading many sevens costs barely more per digit than reading one — matrix hardware is happiest when fed in bulk.

03

Softmax and the answer

128 stroke-opinions exist, but nobody has said “seven” yet. Ten more neurons turn the opinions into scores, one formula borrowed from 19th-century physics turns the scores into a bet, and the forward pass closes at 101,632 multiply-accumulates. Then the uncomfortable question: what exactly is that 98.3% worth?

STEP 01 / 04
TEN FINALISTS
the output layer: ten raw scores, one per digit
h · 128×10
0
-1.2
1
+5.2
2
+0.8
3
-0.4
4
+1.9
5
-2.6
6
+2.2
7
+11.9
8
-3.1
9
+3.4
+1,280 → Σ 101,632 — forward pass complete

The output layer is ten neurons, one per digit, each reading all 128 hidden activations: 128 × 10 = 1,280 more multiply-accumulates, and the forward pass closes its books at 101,632. Their raw outputs are called — unbounded scores, not yet probabilities. Today’s tally: seven scores 11.9, one scores 5.2 (your long diagonal fooled nobody, but it tried), eight limps in at −3.1, its loop detector silent. Ten opinions on the table. Still no verdict — nothing here sums to anything meaningful yet.

the whole forward pass costs 101,632 multiplies — a 1998 Pentium could do it in a blink
STEP 02 / 04
SOFTMAX TURNS SCORES INTO A BET
scores in, probability distribution out — must sum to 1
711.9
15.2
93.4
62.2
logits
eˣ / Σeˣ
7
98.3%
1
1.2%
9
0.2%
6
0.1%
0.2%
probabilities
verdict: SEVEN · 98.3%

converts scores into a bet: exponentiate every logit, divide by the sum. e^11.9 towers over e^5.2 by a factor of about 800, so the seven’s comfortable lead becomes a landslide — 98.3%, against 1.2% for the one, dust for everyone else. The exponential is the whole point: it manufactures decisiveness. And the formula isn’t native to computing at all. It is the Boltzmann distribution, built in the 19th century to describe how particles spread across energy states, now doing digit recognition under an assumed name.

softmax is 1868 thermodynamics wearing a machine-learning name badge
STEP 03 / 04
CONFIDENT AND WRONG
same drawing, to any human eye — noise shown ×100 so you can see it at all
YOUR SEVEN
7
SEVEN · 98.3%
+ craftednoise
SEVEN + ε
7
ONE · 91.0%
⚠ adversarial — conviction is not truth (see also: panda → gibbon, 99.3%)

Here is what 98.3% does not mean: a 98.3% chance of being right. It is the size of the network’s bet, and bets can be rigged. In 2015, Ian Goodfellow’s team added pixel noise carefully computed to be invisible to humans, and a state-of-the-art network reclassified a panda as a gibbon — at 99.3% confidence, higher than it had been about the panda. Softmax reports conviction, not truth; calibrating conviction against reality is a separate and still largely unsolved job. Keep an asterisk next to every confident number in this tutorial.

invisible noise once made a top network call a panda a gibbon — at 99.3% confidence
STEP 04 / 04
TWO MILLISECONDS, AND A LOOSE THREAD
the whole answer, on a clock — segment widths ≈ MAC share
encode ~0
x @ W₁ · 100,352 MAC
x @ W₂ · 1,280
softmax
0 ms~2 ms
SEVEN · 98.3%
7
shift 2 px left:98.3

Total elapsed: about two milliseconds on a laptop CPU for all 101,632 multiply-accumulates. The best MNIST readers err on roughly 23 digits in 10,000 — matching estimates of careful humans. Before celebrating, run one experiment: nudge your seven two pixels left. Every one of the 101,770 weights now stares at the wrong ink — #47’s violet band misses your bar entirely — and the confidence readout stutters. The weights didn’t change. The architecture just revealed its worldview: it memorized where ink sits, not what ink looks like. Hold that thought for chapter 05.

shift the digit two pixels and every single weight is looking at the wrong ink
deep dive: reading the bet properly

Argmax vs sampling. A digit reader takes the biggest probability and moves on. Generative models roll dice weighted by the same kind of distribution — which is why the identical softmax machinery can either classify your seven or write a poem, depending on whether you pick the peak or sample the landscape.

Temperature. Divide every logit by T before softmax: T < 1 sharpens the bet, T > 1 flattens it. This is literally the temperature in Boltzmann’s formula, and exactly the “temperature” knob on a language model — one more place the 1868 physics never left.

Calibration. A well-calibrated model is right 98.3% of the times it says 98.3%. Deep networks tend to be overconfident, and it gets worse with depth; fixes (temperature scaling, again) are post-hoc patches, not cures. The 2017 one-pixel attack pushed the point further: on small images, changing a single pixel flipped verdicts on a majority of tested examples.

What “human level” means here. The ~0.2% human error estimate comes from small, careful trials — fatigue and ambiguous digits (is that a 4 or a 9?) dominate. Some MNIST test digits are genuinely undecidable; past that floor, lower error means memorizing the dataset’s quirks, not reading better.

04

Where the weights came from

101,770 numbers read your handwriting, and nobody chose a single one of them. This chapter rewinds to the machine’s birth — random weights, dice-roll verdicts — and runs the only algorithm that turns a shrug into 98.3%: measure the wrongness, assign the blame, step downhill. Sixty thousand digits, ten laps, one enormous invoice.

STEP 01 / 05
BORN KNOWING NOTHING
the same network, before training ever happened
7
0
9.9%
1
9.8%
2
10.1%
3
9.7%
4
10%
5
9.9%
6
10.2%
7
10.2%
8
10.1%
9
10.1%
weights ~ U(−0.05, 0.05) — a dice roll with extra steps

Rewind to before training. The 101,770 weights are small random numbers, and the freshly hatched network reads your seven as… 10.2% seven, 9.8% one, 10.1% eight. A shrug, uniformly distributed. Every ability the last three chapters showed off — the stroke detectors, the landslide verdict — was absent at birth. Randomness is the blank page training writes on, and it isn’t optional: chapter 02’s deep dive explained why all-zero weights would freeze the network in symmetry forever. So: random start, d10 performance, everything still to be earned.

before training, the network's verdict on any digit is a d10 dice roll
STEP 02 / 05
WRONGNESS, MEASURED TO FOUR DECIMALS
cross-entropy: one number for “how wrong”
p(true = 7) = 0.102
−ln( · )
loss = 2.28
∞ — confident + wrongln 10 = 2.30260 — confident + right

Training needs a single number for “how wrong.” Cross-entropy : look up the probability the network gave the true label, take −log. Confident-and-right lands near 0; confident-and-wrong explodes toward infinity — one number, with sharp opinions about overconfidence. And it carries a signature: a fresh 10-class network always starts at loss ≈ 2.3026, no matter whose laptop, whose random seed, whose framework. That’s no coincidence. It is ln 10 — the arithmetic fingerprint of a perfect shrug spread across ten options.

every untrained 10-class network starts at loss 2.3026 — that number is just ln(10)
STEP 03 / 05
THE THREE-PAGE PAPER THAT RESTARTED THE FIELD
the error flows backward — every weight learns its share of the blame
∂L/∂w
loss = 2.28
101,770 gradients assigned
Nature · Oct 1986 · 3 pages
forward computes the guess; backward computes the blame — same wires, reversed

To fix a weight you must know its share of the blame. is the chain rule run in reverse: the error at the output flows backward through the network, layer by layer, and every one of the 101,770 weights receives a — “increase me and the loss rises by exactly this much.” One forward pass, one backward pass, complete blame assignment. The paper that made this the field’s engine — Rumelhart, Hinton & Williams, Nature, October 1986 — runs three pages. Fields have been restarted by less, but not often.

the paper that revived neural networks is 3 pages long (Nature, Oct 1986)
STEP 04 / 05
DOWNHILL, 0.01 AT A TIME
the loss landscape, 101,770 dimensions drawn as two
min
loss: 2.28
∇ says: that way is up
w ← w − 0.01·∇
no map, no plan — only the local slope, forever

With gradients in hand, the update is an anticlimax: w ← w − 0.01 × gradient. Nudge each of 101,770 knobs a hundredth of a step downhill, on a loss landscape with 101,770 dimensions. That is the whole of gradient descent — the 0.01 is the step size, and “downhill” is the only instruction ever given. The network never learns “a seven is a bar and a hook.” It only ever follows the local slope; the stroke detectors of chapter 01 are simply what the bottom of this particular valley happens to look like.

the network never learns rules — it only ever takes the steepest step downhill
STEP 05 / 05
SIXTY THOUSAND DIGITS, TEN LAPS, ONE INVOICE
the training bill, metered in multiply-accumulates
epoch 3 / 1054,881,280,000MAC
loss 2.30 → 0.02
your inference: 101,632
training paid ×1,800,000 that
paid once, before you drew — inference is the receipt

Now scale it: all 60,000 digits, ten . A backward pass costs roughly twice a forward one, so the bill reads 101,632 × 3 × 60,000 × 10 ≈ 183 billion multiply-accumulates — paid once, by someone else, before you ever touched the canvas. Loss lands at 0.02; the stroke detectors precipitate; the verdict machinery of chapters 02–03 finally exists. Your two-millisecond answer is the receipt for that mountain: inference is cheap precisely because training was not. The debt column in the counter below fills in at last.

your 2 ms answer was purchased with ~183,000,000,000 multiply-accumulates, in advance
deep dive: the training kitchen

Minibatches. Nobody steps downhill one digit at a time, or all 60,000 at once. Stochastic gradient descent averages the gradient over a minibatch (say 64 digits): noisy enough to escape bad valleys, big enough to point roughly downhill, and — chapter 02’s batching bonus — nearly free on matrix hardware.

Fancier descent. Momentum remembers the previous step’s direction; Adam additionally adapts a per-weight step size. Both are still “follow the slope” — with a memory and per-knob gearing bolted on. Nearly every modern model trains on some Adam variant.

The 10,000 held-out digits. A network scored on digits it trained on is a student grading their own exam: it can simply memorize. All real claims — the ~0.23% records, your 98.3% — are measured on the test set the network has never seen. Overfitting is the gap between the two numbers, and dropout (randomly silencing neurons during training) is one classic way to shrink it.

Nobody writes the backward pass. Frameworks (PyTorch, JAX) record the forward computation as a graph and derive every gradient mechanically — automatic differentiation. The 1986 idea became infrastructure: you write the forward story, the chain rule ships as a library. Learning-rate schedules (warm up, then decay) are the last practical knob this tutorial waves at.

05

The convolutional eye (CNN)

Chapter 03 left a real weakness: shift the digit two pixels and the dense net’s accuracy drops. One idea fixes it — stop memorizing where ink sits; learn what ink looks like, and go looking for it. Your seven gets read a second time, by an eye instead of a spreadsheet, and Σ pays for the upgrade.

STEP 01 / 05
THE SEVEN MOVES; THE DENSE NET PANICS
detector #47’s violet band vs your ink — before and after a 2-pixel shift
7
SEVEN · 98.3%
#47 overlap: 0.83
shift 2 px →
7
SEVEN · 98.3%
#47 overlap: 0.83
an architecture problem, not a weight problem

The loose thread from chapter 03, pulled hard. To a dense layer, pixel 407 and pixel 435 — vertical neighbors on your canvas — are just unrelated columns in a spreadsheet. The flattening of chapter 00 destroyed the geometry, and the layer never knew “next to” existed. Shift your seven two pixels and detector #47 finds its violet band empty: confidence 98.3% → 71.0%, and falling with every extra pixel. The failure is not in the weights — they are perfect, for centered digits. It is in the architecture’s worldview: it memorized positions, and your ink moved.

to a dense layer, two touching pixels are as unrelated as opposite corners of the canvas
STEP 02 / 05
A 25-PIXEL FLASHLIGHT
26 parameters, applied 576 times — shown on a 12×12 miniature
canvas + kernel (5×5 · 26 params)
feature map: where the pattern lives
same 26 numbers at every position — the bar is found wherever it moved

Convolution’s move: shrink the detector to a 5×5 window — 25 weights plus a bias, 26 numbers total — and slide it across the image, reapplying the same at each of 576 positions. The output is a : literally a picture of where the pattern lives. One reusable 26-parameter template replaces the dense layer’s 100,480 position-locked weights, and translation stops being a catastrophe — the detector visits every position, so the top bar is found wherever you happened to draw it. Weight sharing is the whole trick, and it is enough.

26 shared parameters do the spatial work a dense layer needed 100,480 for
STEP 03 / 05
SIX FLASHLIGHTS, THEN SIXTEEN, THEN A VERDICT
LeNet-5, 1998 — the maps shrink, the meaning grows
28×28
conv 5×5
6@24×24
pool ÷2
6@12×12
conv 5×5
16@8×8
pool ÷2
16@4×4
dense
10
61,706 params · 340,908 MACs
shifted 7 → 99.1% ✓
fewer knobs than the dense net, 3× the arithmetic, none of the panic

LeNet-5 — Yann LeCun’s 1998 blueprint — stacks the idea: 6 kernels sweep the canvas, halves the maps, 16 more kernels read those, pooling again, then small dense layers finish the job: 28×28 → 24×24 → 12×12 → 8×8 → 4×4 → 10 scores. Total: ~61,706 parameters and ~340,908 multiply-accumulates per digit. Sit with that trade: 40% fewer parameters than our dense net, three times the arithmetic — and it reads your shifted seven at 99.1% without blinking. Σ vaults to 442,540.

the CNN carries 40% fewer parameters than our dense net — and shrugs at the shifted 7
STEP 04 / 05
THE NETWORK THAT READ YOUR RENT CHECK
an NCR check reader at work, ca. 1999
PAY TO THE ORDER OF…
$1,247.00
courtesy amount field
segment: 8 characters found
conv pass × 8 ... done
read: $1,247.00
confidence: accept ✓
by 2001: 20,000,000 checks a day — ~10% of the United States

This is not retro-futurism — LeNet shipped. NCR deployed LeCun’s check-reading system commercially in June 1996, and by 2001 it was reading about 20 million checks a day: roughly one in ten of every check written in the United States, years before “deep learning” was a phrase anyone said out loud. If you mailed a rent check in 1999, odds are decent the amount was read by a — this same architecture, at production scale, two decades before the hype arrived to explain it.

by 2001 a CNN was reading ~10% of all US checks — 20,000,000 a day
STEP 05 / 05
2012: THE LENS GETS 1,000× BIGGER
ImageNet top-5 error, year by year — the 2012 cliff
human ≈ 5.1%
28.2
2010
25.8
2011
15.3
2012
11.7
2013
6.7
2014
3.6
2015
AlexNet: −10.8 pts in one entry
2015: below human

Scale the recipe and history breaks open. AlexNet (2012): five convolutional layers plus three dense, 60 million parameters, 650,000 neurons, trained for five to six days on two consumer GTX 580 gaming cards. It took ImageNet’s top-5 error to 15.3% while the best non-neural rival managed 26.2% — a 10.8-point cliff that started the modern AI era, embarrassed a decade of hand-engineered vision, and made “just scale it” a research program. Every layer of it is chapter 01’s multiply-add-bend. The lens just got a thousand times bigger, and the world finally noticed.

AlexNet trained ~6 days on two gaming GPUs and beat the field by 10.8 points
deep dive: convolution's fine print

Stride and padding. A kernel can slide one pixel at a time (stride 1, our 24×24 output) or skip (stride 2 halves the map for free). Padding the border with zeros keeps edges readable and output sizes tidy — the reason real nets stay 28×28 → 28×28 instead of shrinking at every layer.

What pooling throws away. Max-pooling keeps each 2×2 block’s strongest response and discards exactly where in the block it was. That’s the point: a feature “a bit left or right” becomes the same evidence. Trade precision of place for tolerance of place — repeated, it is why deep layers see the whole canvas (their receptive field) while early ones see 5 pixels.

Convolution is also a matrix multiply. Libraries unroll every 5×5 window into a row (im2col) and hand the result to the same engine as chapter 02. The GPU story repeats: one hardware primitive, every architecture.

After AlexNet. ImageNet (14 million labeled images) fell year by year — VGG, ResNet, past the ~5.1% human line by 2015. CNNs still rule edge devices and medical imaging, but since 2020 vision transformers read images as patch sequences — chapter 06’s ideas invading chapter 05’s territory.

06

The recurrent memory (RNN)

The bitmap both previous readers shared throws away one thing: the order you drew in. Rewind past the canvas to the gesture itself — 60 pen points, two strokes, strict sequence — and read it with the third great architecture, a network with memory. Σ pays its largest bill yet for the privilege.

STEP 01 / 05
YOUR SEVEN WAS NEVER A PICTURE
the gesture, replayed — what the canvas forgot
pen ▲
THE TAPE · (Δx, Δy, pen)
(+8,0,▼)(+8,0,▼)(+8,0,▼)(0,0,▲)(−5,+6,▼)(−5,+6,▼)(−5,+6,▼)
two strokes · strict order
60 steps — a sequence, not a picture

Rewind the event one last time — further back than chapter 04 went. You never handed the machine a bitmap; you performed a gesture. Pen down, a bar left to right, pen up, a slash to the floor: roughly 60 sampled points, two strokes, in strict order. Rasterizing threw that order away, and both previous readers worked from the corpse. A different family of networks reads the trajectory itself — one point at a time, like a sentence. For this chapter we train one on stroke recordings and hand it your gesture, live.

the finished bitmap has forgotten the only thing you actually did — the order of the ink
STEP 02 / 05
A LOOP WITH A MEMORY
one cell — and the same cell, unrolled through time
cell
h feeds back
unroll →
cell
x1ink began
h→
cell
x2
h→
cell
x3a bar so far
h→
cell
x4
h→
cell
x5bar + slash ✓
…×60
a 60-layer network where every layer is the same layer

A recurrent network is one cell, reused. At each timestep it reads the next pen point plus its own previous output — a 128-number acting as running memory. Point 1: “ink began.” Point 9: “a leftward bar so far.” Point 41: “bar, then a descending slash — this is becoming a seven.” The same weights fire at every step. Unroll the loop and you are looking at a 60-layer network in which every layer is the same layer. Time, handled with a photocopier.

an RNN is one cell photocopied through time — 60 steps, the same weights every step
STEP 03 / 05
MEMORY THAT EVAPORATES
the gradient travels back through time — and evaporates
×0.0018
t1
×0.03
t12
×0.08
t24
×0.28
t36
×0.53
t48
×1.0
t60
step 1’s lesson: lost — 0.9⁶⁰ ≈ 0.0018
proven: Hochreiter, 1991

The classic has a fatal leak. Training must send gradients backward through all 60 steps, and every hop multiplies by roughly the same factor. 0.9⁶⁰ ≈ 0.0018. The lesson from the pen-down at step 1 reaches the weights at a five-hundredth of its strength, so the network structurally cannot learn that beginnings matter. Sepp Hochreiter proved this — the — in his 1991 diploma thesis, in German, years before most of the field could read the warning.

RNNs' fatal flaw was proven in a 1991 student thesis — 0.9⁶⁰ ≈ 0.0018
STEP 04 / 05
GATES: A CELL THAT LEARNS TO FORGET
inside an LSTM cell: a protected memory belt and three learned valves
(−5,+6,▼)
× 1.0
fforget: erase old noise
iinput: write the bar
ooutput: speak
SEVEN · 97.8%
from strokes alone
gradients ride the belt at ×1.0 — sixty steps, nothing evaporates

The 1997 fix — Hochreiter & Schmidhuber’s — gives the cell a protected conveyor belt of memory and three learned : forget (what to erase), input (what to write), output (what to reveal). Along the belt, the gradient’s multiplier is exactly 1.0, so lessons survive all 60 steps intact. The cost is real: four gate-sized matrix multiplies per point, 67,072 MACs × 60 ≈ 4 million, and Σ vaults to ≈ 4,468,140 — the most expensive reading of your seven yet. The paper has over 80,000 citations. It earned them.

the LSTM's belt multiplies gradients by exactly 1.0 — that single constant saved RNNs
STEP 05 / 05
THE THREAD THAT TRANSLATED THE INTERNET, THEN VANISHED
twenty years to the throne; nine months on it
1997 · LSTMHochreiter & Schmidhuber
SEP 2016 · GNMT8+8 LSTM layers · −60% errors · 18 M sentences/day
JUN 2017“Attention Is All You Need”
sequences remain; the tool changed

This cell conquered sequence-land. By September 2016, Google Translate ran on — eight LSTM layers encoding, eight decoding — cutting translation errors by roughly 60% overnight and chewing through 18 million Chinese→English sentences a day. Then the honest footnote: nine months later, June 2017, Attention Is All You Need introduced the transformer, whose reads every timestep at once instead of one by one — and RNNs left the frontier almost as fast as they had taken it. The gesture-reading idea survives. The crown moved.

the LSTM ran Google Translate for barely 9 months before transformers took the frontier
deep dive: after the thread

: the LSTM on a diet. The 2014 gated recurrent unit merges the LSTM’s three gates into two and drops the separate cell state — fewer parameters, usually similar accuracy, and for years the default when compute was tight.

Seq2seq. Translation needs sequence in and sequence out, so 2014-era systems used two RNNs: an encoder compresses the source sentence into vectors, a decoder unspools the target one word at a time. GNMT was this pattern, industrialized — and attention was first invented (2015) as a patch letting the decoder peek back at every encoder step instead of one summary vector.

Why transformers won. An RNN must finish step 41 before starting step 42 — sequential by construction, hostile to GPUs. Attention computes all step-pairs in one matrix multiply: worse asymptotic cost, embarrassingly parallel training. Chapter 02’s lesson again — the winning architecture is the one the hardware loves.

The thread isn’t dead. Sequential-MNIST — reading the 784 pixels as a 784-step sequence — is still a standard memory benchmark, and state-space models (Mamba, 2023) brought recurrence back to the frontier conversation: constant memory per step is a superpower attention never had.

Σ

One seven, three readings, one invoice

The whole pipeline on one page. Your scribble became numbers, read by a spreadsheet, an eye, and a memory — and every verdict traces back to the same three moves: multiply, add, bend.

READING YOUR SEVEN — MULTIPLY-ACCUMULATES, SIDE BY SIDE
dense net (ch 00–03)101,632SEVEN 98.3% · fragile to shift
LeNet-5 CNN (ch 05)340,908SEVEN 99.1% · shift-proof
LSTM on strokes (ch 06)4,025,600SEVEN 97.8% · reads the gesture
training the weights (once)✂ 183,000,000,000
✂ axis surrenders here — at the readings’ scale this bar would be ~2.8 km long
you spent 4,468,140 · someone spent 183,000,000,000 first
● synapse quiet — awaiting your next stroke