Backpropagation
Backpropagation is how a network works out, for every one of its weights at once, whether nudging that weight up or down would reduce the error. It is the chain rule from calculus, applied backwards through the network so that a single sweep answers millions of questions.
Prerequisites: The Multilayer Perceptron, Activation Functions
A trained network is nothing more than a big pile of numbers — the weights. Training means repeatedly asking one question about every single one of them: if I nudged this weight up a hair, would the error get better or worse, and by how much? Answer that for all the weights and you know which way to step.
The obvious way to answer it is to try. Change one weight by a tiny amount, run the whole network again, see how the error moved. That works perfectly and it is completely useless in practice, because a modest network has a hundred thousand weights, so one training step would cost a hundred thousand full runs. Backpropagation gets every one of those numbers in about the cost of one extra run. That efficiency is the only reason neural networks are trainable at all.
The analogy: attributing a P&L miss backwards
A fund is down 40 basis points against target and you want to know how much each individual trade contributed. Nobody re-runs the entire month once per trade. You work backwards down the reporting chain instead.
Start at the top: the fund missed by 40bp. The Europe sleeve is 30% of the book, so 30% of any move in Europe shows up at the fund level. Within Europe, the mean-reversion strategy is 20% of the sleeve. So a trade inside that strategy influences the fund's number by — six cents on the dollar. Nobody at any level needed to understand the whole firm. Each level only knew its own share, and you got the answer by multiplying the shares along the path as you walked down.
Backpropagation is that, applied to a network. Each layer knows only how sensitive its own output is to its own input. Multiply those local sensitivities from the output end backwards and you get every weight's influence on the final loss.
The one rule
The mathematical name for "multiply the shares along the path" is the chain rule. If a loss depends on a value , and depends on , then
In words: the influence of on the loss equals the influence of on the loss, times how strongly moves . The symbol just means "how much changes per unit change in , holding everything else fixed" — a slope, nothing more.
Backprop turns this into a mechanical procedure. Every node in the network receives a gradient from its right-hand neighbour, multiplies it by its own local slope, and hands the result to its left-hand neighbour. That is the entire algorithm.
Worked example 1: one neuron, done by hand
Input , weight , bias , sigmoid activation, target , squared-error loss.
Forward pass. Compute left to right and write down every intermediate value, because the backward pass will need them.
Backward pass. Start at the loss and walk left, multiplying local slopes.
- Loss to output. For the slope is . Negative, meaning: increasing the output would reduce the loss. Sensible, since the output is below target.
- Through the sigmoid. The sigmoid's slope is . Multiply: .
- Through the weight. Since , the slope of with respect to is just . So
Both gradients are negative, so both and should go up to reduce the loss.
You can check this without any calculus. Set and redo the forward pass: , , , against the original . The loss fell by for a change of , giving a slope of — matching the backprop produced, to the accuracy of the finite difference. This is exactly the gradient check every implementation should run once.
Worked example 2: two layers, and the sign flip
Now a network with a hidden ReLU unit. Input ; hidden weight , bias ; output weight , bias ; linear output; target .
Forward. , so . Then , which is the prediction. The loss is . Badly wrong.
Backward. Write for the gradient at the output: .
In words: a weight's gradient is the gradient arriving at its unit, times the value that weight was multiplying. Now push past the output weight into the hidden unit. The gradient gets multiplied by (the path it travelled through) and by the ReLU's slope, which is here because was positive:
The sign flipped. Because is negative, this unit helps by getting smaller, and backprop discovers that automatically. Then .
Take one step with learning rate : , , . Redo the forward pass and the prediction moves to , dropping the loss from to . The gradients were right.
A weight's gradient is always the gradient arriving at its unit, times the value that weight multiplied on the way forward. That single sentence is backpropagation. Everything else is bookkeeping about which values to keep from the forward pass.
What this means in practice
Three consequences follow from "gradients are products along a path".
You must cache the forward pass. Every local slope needs the values computed on the way through, which is why training uses far more memory than inference and why long sequences or big batches run out of GPU memory rather than time.
Depth multiplies, so depth is fragile. Twenty layers means twenty factors multiplied together. If each is around the gradient reaching the first layer is and that layer never learns; if each is around it blows up. This is the whole story behind Vanishing and Exploding Gradients, and the reason careful initialisation, normalisation layers and residual connections exist.
Dead paths pass nothing. ReLU has slope zero for negative inputs, so a unit sitting on the wrong side sends zero gradient backwards and everything behind it goes unchanged that step.
Backpropagation is not a learning algorithm — it does not change a single weight. It only computes derivatives. The updating is done by an optimiser such as Stochastic Gradient Descent, and the two are routinely confused because they always appear together. The related trap: what flows backwards is a derivative, not "the error". And a gradient is only valid for an infinitesimal nudge — it tells you the downhill direction at your current point, never where the minimum is or how far away it sits.
Related concepts
Practice in interviews
Further reading
- Rumelhart, Hinton & Williams, Learning Representations by Back-Propagating Errors (1986)
- Goodfellow, Bengio & Courville, Deep Learning, ch. 6.5