Lessons › Chapter 8: Neural networks
Backpropagation
Run a forward pass, then compare the prediction with the truth. The network said 90% cat, but the photo was a dog. That gap is the error.
Watch it move. This lesson is interactive on Gradient Lab: every step is an animated scene you can replay.
Start the interactive lessonStep by step
How does it learn?
The network’s first guesses are terrible. Leo explains how the error teaches every single weight.
Measure the error
Run a forward pass, then compare the prediction with the truth. The network said 90% cat, but the photo was a dog. That gap is the error.
Send the blame backwards
backpropagation works backwards from the error. First it asks how much each connection into the output was to blame. Thicker red lines carry more blame.
Every weight gets its share
The blame keeps flowing back, layer by layer, using the chain rule from calculus. In the end every single weight knows how much it contributed, and in which direction to change.
Nudge, and repeat
Each weight takes a small gradient-descent step against its blame. Next time, the prediction for that photo is a little better. Repeat over millions of examples and the network learns.
In real life: learning to shoot hoops
Miss a basket short and you work out what caused it (arm, wrist, legs) and adjust each a little. Backpropagation does that blame-sharing automatically, for millions of weights at once, after every batch of examples.
Quick check: What does backpropagation work out?
- How much each weight contributed to the error (correct)
- The final prediction
- Which training data to collect
It computes the gradient of the loss for every weight, so each can be adjusted.
Pseudocode
prediction = forward(x)
error = loss(prediction, truth)
for each layer, from the last to the first:
blame = how much each weight added to the error # chain rule
weight = weight − learning_rate × blame
repeat for many, many examples
Key terms
- backpropagation
- Sending the error backwards through the network to work out how to adjust each weight.
Build it: A neural network that reads handwriting (35 min, runs in your browser)
See the project