The film
About 4:59, hosted by Pylon. It asks you one question and waits for your answer before it shows you. The narrated cut runs 3:50, voiced by Pylon in a synthesized voice made from the author's own voice; the author approved these cuts for publishing. Captions are on by default. The live version under it draws the same film in your browser, waits for your answer at each question, and runs a little longer; the full words are also below.
Nothing loads until you press play.
The lab: Pylon's bucket chain
Train a 2-8-8-2 network (114 numbers) on two spirals, in your browser. Click any point to see its chain: the value in every bucket and the blame arriving at it. Check the walk back against nudging every number, then break one link on purpose and watch the check point at it. In the film's run, one walk back cost 208 multiply-adds against 98 for the forward pass, and the network was right on 99.8% of new points after 4,000 steps.
Everything is computed on your computer, in this page. Nothing is sent anywhere.
Everything the film says
Backpropagation
Backpropagation. Blame, passed backwards.
Last time I could feel the slope for two numbers. A model has thousands. Tonight, how it gets all their slopes in one go.
A chain of buckets
Here is a small network. It looks at a point on a map and says which of two spirals the point belongs to.
It has 114 numbers. Two go in at the top, pass through two layers of 8 buckets each, and come out as two guesses at the bottom.
Every bucket in the middle takes what the buckets above hand it, weighs it, adds it up, and squashes the total through a smooth curve. The last two turn their totals into two guesses that add up to one. That's the forward pass.
Feeling every slope by hand
At the bottom we measure how wrong it was: the loss. Now we want each of the 114 slopes.
The slow way: nudge one number, run the whole chain again, see how the loss moved. That's one extra run for every number. For the model from the attention lesson, that's 20,864 runs, for every single step of training.
Pass the blame back
The fast way runs the chain once, then walks it backwards.
How many backward walks does it take to get all the slopes? (the film pauses here)
Each bucket at the bottom knows how much the loss changes when its own output changes. It hands that blame up to each bucket that fed it, multiplied by how much its own output moved when that input moved. A bucket that fed several adds up the blame from all of them, then does the same, all the way to the top.
That's the chain rule from school, done in reverse order. Seppo Linnainmaa worked out this reverse order in 1970, and in 1986 Rumelhart, Hinton and Williams showed what it could do for training networks.
One walk back
One. A single walk back hands every number its slope.
Counting multiply-adds for one point, and leaving the curves aside: the forward pass takes 98, the backward pass 208, about 2.12 times as many. Not 114 extra runs. About two runs' worth.
Checking the chain
A walk back like this is easy to get slightly wrong, so we check it the slow way. Nudge every number, compare.
After training, they agree layer by layer to about one part in a billion, and the worst single number is off by about three parts in a hundred million.
Now I break one link on purpose: in the second layer, the curve's slope is written wrong. The check fails in that layer and every layer above it, and still passes in the last layer, below the break. The check doesn't just say something is wrong. It points to where.
Downhill, every number at once
Now put it together with last time: walk forward, walk back, step every number a little downhill, repeat.
On points it never trained on, the network starts out right 36 percent of the time. It is past 95 percent by step 2,000, and after 4,000 steps it gets 99.8 percent right.
The same walk, inside the language model
The model from the attention lesson walks forward and back the same way, with a backward pass written out by hand for every part: the attention, the layer norms, the bends. It steps downhill a little more cleverly, and that's next time.
We checked it the slow way too, on 36 of its numbers. In full precision the worst disagreement is a few parts in ten million.
Goodnight
Run forward once, pass the blame back once, and every number knows its slope.
Next along the hill: better ways to step than straight downhill. Goodnight.
Sources
Every claim in the film, with where it comes from and what that source does not prove. The numbers about the model are computed from its weights, which you can load and check: facts.json.
Night School's small network, built for this film. media/school/backprop/facts.json, written by tools/school/fill_backprop.mjs from system/school/backprop.mjs: a 2, 8, 8, 2 tanh network (114 numbers) on seeded two spirals, with a hand-written forward and backward pass and a finite-difference check of every number. https://github.com/HarperZ9/HarperZ9.github.io/tree/main/media/school/backprop
Used for: Counted multiply-adds for one point: forward 98, backward 208 (ratio 2.12); tanh, exp and log calls counted apart. Finite-difference check of every number: worst tensor error 1.2e-9 after training; worst single entry 3.3e-8. With the second hidden layer's local slope written as 1 - a instead of 1 - a^2, the check fails for W1, b1, W2 and b2 and passes for W3 and b3. Held-out accuracy on 400 points, measured every 100 steps: 0.355 at the start, 0.95 reached by step 2,000, 0.9975 after 4,000 steps.
Does not prove: Anything about large networks; one seed, one task.
Linnainmaa 1970, reverse-mode accumulation of rounding errors. Linnainmaa, S. (1970). The representation of the cumulative rounding error of an algorithm as a Taylor expansion of the local rounding errors. Master's thesis, University of Helsinki. https://people.idsia.ch/~juergen/who-invented-backpropagation.html
Used for: Linnainmaa's 1970 thesis described what is now called reverse-mode automatic differentiation, for the accumulated rounding error of an algorithm; it was published in English in 1976, and the idea was also found independently by others, among them Werbos (1982) for networks.
Does not prove: That the method was then used to train neural networks.
Rumelhart, Hinton and Williams 1986, Learning representations by back-propagating errors. Rumelhart, D. E., Hinton, G. E., Williams, R. J. (1986). Learning representations by back-propagating errors. Nature 323, 533-536. https://doi.org/10.1038/323533a0
Used for: The paper describes back-propagation for networks of neuron-like units and shows that hidden units come to represent useful features of the task.
Does not prove: That it was the first description of reverse-mode differentiation.
Griewank and Walther 2008, Evaluating Derivatives. Griewank, A., Walther, A. (2008). Evaluating Derivatives: Principles and Techniques of Algorithmic Differentiation, 2nd edition. SIAM. https://doi.org/10.1137/1.9780898717761
Used for: Reverse mode computes the gradient of a scalar function at a cost bounded by a small constant times the cost of the function, whatever the number of inputs. Our count of 2.12 is the backward pass alone; forward plus backward is 3.12 times the forward pass.
Does not prove: The exact constant for a given program; we measured ours.
Night School's tiny transformer, the attention lesson's trained weights. media/school/attention/model.json; system/school/backprop-attention.mjs checks tinyformer's hand-written backward pass by central differences. https://github.com/HarperZ9/HarperZ9.github.io/tree/main/media/school/backprop
Used for: On 36 entries over 9 tensors, two held-out rows: worst relative error 2.9e-7 in float64; a control that drops the softmax Jacobian term fails 18 of 36. This model trains with AdamW, a warmup and gradient clipping, not plain gradient descent.
Does not prove: That every entry is right; 36 of 20,864 were checked here (the lab's own test checks every tensor on a small model).
What this lesson leaves out
The network is tiny and the spirals are a toy task, so it trains in well under a second. Large models are trained the same way in principle, by software that writes the backward pass automatically rather than by hand.
The count of multiply-adds leaves out the curves (tanh, exp and log) and is for one point. The general bound for reverse mode is a small constant times the cost of the function; our measured 2.12 is one network, not that bound.
Before this: Gradients (F3). Next along the hill: optimisers (F5), planned.