Last chapter chained two neurons along one path. A real network has many paths — every weight needs its own gradient. Is that a completely new problem, or the same one, more times?
This is the loss of a real two-layer network — 2 inputs, 2 hidden neurons, 1 output — as a function of just one weight, , holding everything else fixed. Drag it: the tangent line is backprop's answer for , computed by chaining through both layers.
Backpropagation is the chain rule, applied backward from the loss, one layer at a time:
- — the loss, measuring how wrong the network's prediction is.
- — the weight connecting input 1 to hidden neuron 1, the one being differentiated.
- — the network's final output.
- — the output neuron's raw weighted sum, before its activation.
- — hidden neuron 1's activation, feeding into the output.
- — hidden neuron 1's raw weighted sum, before its activation.
- The loss adds a new starting term
Five factors total, but only two are genuinely new beyond Chapter 4: the loss contributes its own local derivative, , at the very start of the chain.
- One factor is just a connecting weight
is nothing more than — the weight connecting to the output. Everything else in the five-factor product is the same local-slope idea from Chapter 4.
- Every weight reuses the same shared terms
Every other weight in the network gets its gradient the same way, reusing the exact same and terms computed once and shared.
Push negative and watch the loss keep falling — this particular network, on this particular input, never stops preferring a more negative within this range. The gradient still tells you the direction correctly at every point, even where it isn't near zero.
At :
- Forward pass
exactly, so . Forward through the rest:
- , so
- loss
- Backward into the output neuron
(target is ), times gives . That one number is shared by every weight feeding the output:
- Push further back, into the hidden neurons
For hidden neuron 1: , times gives — shared by every weight feeding :
The exact same mechanism, run on neuron 2: , times gives — shared by every weight feeding :
- Tally the result
All nine gradients, from two shared numbers (, and per hidden neuron or ) and the inputs each weight multiplies.
Drag w11 until dL/dw11 reaches 0.03 (within 0.005).
Every gradient in this chapter was checked against a plain numerical derivative — nudge a weight by a tiny amount, remeasure the loss, compare. That's the whole promise of autograd (short for automatic differentiation): whatever backprop computes analytically, a numerical check should reproduce. The next chapters ask what starts to go wrong with this chain once a network gets deep enough that it's dozens of layers long, not two.