The chain rule applied backwards through a network β the single algorithm that made deep learning possible.
π Where this lives: Every trained neural network in existence β every language model, every image classifier, every recommendation engine β was trained by backpropagation. It is not one method among several; it is essentially the only method. When a company reports spending tens of millions of dollars training a model, that money bought electricity for this algorithm running for weeks across thousands of GPUs. Search "backpropagation automatic differentiation reverse mode".
The problem it solves, and the idea
THE CREDIT ASSIGNMENT PROBLEM, which is the obstacle every
previous topic ran into:
WE KNOW THE ERROR AT THE OUTPUT. WE DO NOT KNOW WHAT A HIDDEN
UNIT SHOULD HAVE OUTPUT, SO WE HAVE NO TARGET FOR IT AND
THEREFORE NO ERROR β SO HOW DO WE UPDATE ITS WEIGHTS?
This is why the perceptron rule and the delta rule train only
one layer, and why Madaline needed a fixed output gate and a
minimum-disturbance heuristic. The obstacle is not conceptual
difficulty; it is that the STEP FUNCTION HAS ZERO DERIVATIVE
EVERYWHERE (and no derivative at the threshold), so there is no
gradient to propagate.
THE TWO INGREDIENTS OF THE SOLUTION:
1. REPLACE THE STEP WITH A DIFFERENTIABLE ACTIVATION β
sigmoid, tanh, ReLU. Now every quantity in the network is
a differentiable function of every weight.
2. APPLY THE CHAIN RULE. The error is a composition of
functions, so βE/βw for a deep weight is a product of
derivatives along the path from that weight to the error.
THE INSIGHT THAT MAKES IT EFFICIENT β and this is the part
usually skipped:
A naive approach would compute βE/βw separately for each
weight, re-traversing the network every time: O(WΒ²) work for
W weights.
BACKPROPAGATION COMPUTES A QUANTITY Ξ΄ AT EACH UNIT β the
error signal β AND REUSES IT FOR EVERY WEIGHT FEEDING THAT
UNIT. Because a unit's Ξ΄ depends only on the Ξ΄ values of the
units it feeds, computing them from the output backwards
gives EVERY GRADIENT IN THE NETWORK IN ONE BACKWARD SWEEP,
at O(W) cost β the same order as the forward pass.
THAT REUSE IS THE ALGORITHM. Everything else is the chain
rule.
IT IS AN INSTANCE OF REVERSE-MODE AUTOMATIC DIFFERENTIATION, a
general technique for differentiating any computation graph. The
neural network is just the most famous graph it is applied to.
A NOTE OF HISTORY, because it is a favourite exam aside:
Werbos derived it in a 1974 PhD thesis; Rumelhart, Hinton
and Williams published the paper that made it famous in 1986.
THE TWELVE-YEAR GAP is the second half of the AI winter β
the answer to Minsky and Papert existed and the field did not
know it.
The derivation
SETUP β a network with input x, hidden layer h, output y.
hidden: net_j = Ξ£α΅’ vβ±Όα΅’xα΅’ + bβ±Ό , hβ±Ό = f(net_j)
output: net_k = Ξ£β±Ό wββ±Όhβ±Ό + cβ , yβ = f(net_k)
error: E = Β½ Ξ£β (tβ β yβ)Β²
THE SIGMOID AND ITS DERIVATIVE, which is why sigmoid is chosen:
f(z) = 1/(1 + eβ»αΆ»)
fβ²(z) = f(z)(1 β f(z)) = y(1 β y)
THE DERIVATIVE IS EXPRESSIBLE IN TERMS OF THE OUTPUT ITSELF,
so it costs one multiplication and no re-evaluation. That is a
substantial saving repeated for every unit on every example.
STEP 1 β THE OUTPUT LAYER. Apply the chain rule to wββ±Ό:
βE/βwββ±Ό = (βE/βyβ)(βyβ/βnet_k)(βnet_k/βwββ±Ό)
the three factors being
βE/βyβ = β(tβ β yβ) = (yβ β tβ)
βyβ/βnet_k = fβ²(net_k) = yβ(1 β yβ)
βnet_k/βwββ±Ό = hβ±Ό
DEFINE THE OUTPUT ERROR SIGNAL:
Ξ΄β = (yβ β tβ) Β· yβ(1 β yβ)
so that
βE/βwββ±Ό = Ξ΄β Β· hβ±Ό and Ξwββ±Ό = βΞ· Ξ΄β hβ±Ό
COMPARE THE DELTA RULE from two topics ago: Ξw = Ξ·(t β y)x.
THE ONLY DIFFERENCE IS THE EXTRA FACTOR fβ²(net) β the slope of
the activation. Backpropagation's output layer IS the delta
rule with the activation's derivative attached, which is why
the delta rule was the necessary preparation.
STEP 2 β THE HIDDEN LAYER, where the actual work is. There is no
target for hβ±Ό, so we cannot write (t β h). Instead we ask how E
changes as hβ±Ό changes, and hβ±Ό affects E THROUGH EVERY OUTPUT
UNIT IT FEEDS β so the contributions SUM:
βE/βhβ±Ό = Ξ£β (βE/βnet_k)(βnet_k/βhβ±Ό) = Ξ£β Ξ΄β wββ±Ό
THAT SUM IS THE WHOLE IDEA: THE HIDDEN UNIT'S ERROR IS THE
ERROR OF THE UNITS IT FEEDS, WEIGHTED BY HOW STRONGLY IT FEEDS
THEM. A unit that contributed a lot to a wrong answer, through
a large weight, receives a large share of the blame. That is
credit assignment, solved.
Then, exactly as before,
Ξ΄β±Ό = (Ξ£β Ξ΄β wββ±Ό) Β· fβ²(net_j) = (Ξ£β Ξ΄β wββ±Ό) Β· hβ±Ό(1 β hβ±Ό)
βE/βvβ±Όα΅’ = Ξ΄β±Ό Β· xα΅’ and Ξvβ±Όα΅’ = βΞ· Ξ΄β±Ό xα΅’
NOTICE THE SYMMETRY, which is what makes the algorithm
generalise to any depth:
OUTPUT UNIT: Ξ΄ = (y β t) Γ fβ²(net)
HIDDEN UNIT: Ξ΄ = (Ξ£ Ξ΄_next w) Γ fβ²(net)
THE FORM IS IDENTICAL. Only the first factor differs β a
direct error at the output, a WEIGHTED SUM OF DOWNSTREAM Ξ΄'s
at a hidden unit. So the same rule applies at every layer, and
a network of any depth is trained by repeating it.
THE BIAS: treat it as a weight on a constant input of 1, so
Ξbβ±Ό = βΞ· Ξ΄β±Ό
with no xα΅’ factor. This is the most common slip in exam
answers.
A complete numerical trace
A 2β2β1 NETWORK, ONE TRAINING EXAMPLE, WORKED TO SIX DECIMALS.
Sigmoid units throughout, Ξ· = 0.5.
inputs xβ = 0.05, xβ = 0.10 target t = 0.99
hidden vββ = 0.15 vββ = 0.20 bβ = 0.35
vββ = 0.25 vββ = 0.30 bβ = 0.35
output wβ = 0.40 wβ = 0.45 c = 0.60
ββ FORWARD PASS ββββββββββββββββββββββββββββββββββββββββββββ
netβ = 0.15(0.05) + 0.20(0.10) + 0.35 = 0.377500
hβ = 1/(1 + e^β0.3775) = 0.593270
netβ = 0.25(0.05) + 0.30(0.10) + 0.35 = 0.392500
hβ = 1/(1 + e^β0.3925) = 0.596884
net_o = 0.40(0.593270) + 0.45(0.596884) + 0.60 = 1.105906
y = 1/(1 + e^β1.105906) = 0.751365
E = Β½(0.99 β 0.751365)Β² = 0.028473
ββ BACKWARD PASS βββββββββββββββββββββββββββββββββββββββββββ
OUTPUT Ξ΄:
Ξ΄_o = (y β t)Β·y(1 β y)
= (0.751365 β 0.99)(0.751365)(0.248635)
= β0.044581
OUTPUT GRADIENTS:
βE/βwβ = Ξ΄_oΒ·hβ = β0.044581 Γ 0.593270 = β0.026448
βE/βwβ = Ξ΄_oΒ·hβ = β0.044581 Γ 0.596884 = β0.026610
βE/βc = Ξ΄_o = β0.044581
HIDDEN Ξ΄ β note the weighted sum, here with a single output so
the sum has one term:
Ξ΄β = Ξ΄_oΒ·wβΒ·hβ(1 β hβ)
= β0.044581 Γ 0.40 Γ 0.593270 Γ 0.406730 = β0.00430294
Ξ΄β = Ξ΄_oΒ·wβΒ·hβ(1 β hβ)
= β0.044581 Γ 0.45 Γ 0.596884 Γ 0.403116 = β0.00482702
HIDDEN GRADIENTS:
βE/βvββ = Ξ΄βΒ·xβ = β0.00430294 Γ 0.05 = β0.00021515
βE/βvββ = Ξ΄βΒ·xβ = β0.00430294 Γ 0.10 = β0.00043029
OBSERVE THE MAGNITUDES: the hidden gradients are roughly a
HUNDRED TIMES SMALLER than the output ones. This is the
vanishing gradient in miniature, in a network only two layers
deep β and it is why the near-input layers of a deep sigmoid
network learn so slowly.
ββ WEIGHT UPDATE, w β w β Ξ· βE/βw ββββββββββββββββββββββββββ
wβ β 0.40 β 0.5(β0.026448) = 0.413224
wβ β 0.45 β 0.5(β0.026610) = 0.463305
c β 0.60 β 0.5(β0.044581) = 0.622290
vββ β 0.15 β 0.5(β0.00021515) = 0.150108
vββ β 0.20 β 0.5(β0.00043029) = 0.200215
vββ β 0.25 β 0.5(β0.00024135) = 0.250121
vββ β 0.30 β 0.5(β0.00048270) = 0.300241
ββ VERIFICATION: re-run the forward pass βββββββββββββββββββ
y = 0.758500 (was 0.751365 β moved toward t = 0.99)
E = 0.026796 (was 0.028473)
ERROR REDUCED BY 5.89% IN A SINGLE STEP.
Repeating this for thousands of steps is training. NOTHING
ELSE HAPPENS.
Variants, problems and practical measures
WEIGHT UPDATE MODES:
STOCHASTIC (online) β update after EVERY example.
Noisy, which helps escape shallow local minima; fast early
progress; cannot be parallelised across examples.
BATCH β accumulate gradients over the whole training set,
update once per epoch.
A true gradient, smooth descent, but slow and memory-hungry.
MINI-BATCH β update every 32 / 64 / 128 examples.
THE UNIVERSAL CHOICE IN PRACTICE, because it combines a
reasonable gradient estimate with GPU-friendly parallelism.
MOMENTUM β the standard acceleration:
Ξw(t) = βΞ· βE/βw + Ξ± Ξw(tβ1) with Ξ± β 0.9
Adds a fraction of the previous update, so consistent
directions accumulate speed while oscillating ones cancel.
IT HELPS MOST IN RAVINES β surfaces steep in one direction and
shallow in another, where plain descent zigzags. Momentum
damps the zigzag and accelerates along the valley floor.
ADAM, the modern default, extends this with per-weight
adaptive learning rates.
THE PROBLEMS, and what is done about them:
1. LOCAL MINIMA. Gradient descent finds a minimum, not THE
minimum. Mitigations: momentum, several random restarts,
stochastic noise.
THE MODERN VIEW IS MORE INTERESTING: in very high dimensions,
true local minima are RARE, because a point is only a minimum
if the surface curves upward in ALL of millions of
directions. SADDLE POINTS β up in some, down in others β are
the real obstacle, and they are escaped by any method with
noise or momentum.
2. VANISHING GRADIENTS β THE MOST IMPORTANT PROBLEM.
Ξ΄ for a layer includes one factor of fβ² per layer above it.
THE SIGMOID'S DERIVATIVE PEAKS AT 0.25 and is smaller
everywhere else, so the gradient is multiplied by β€ 0.25 at
every layer:
5 layers: 0.25β΅ β 9.77 Γ 10β»β΄
10 layers: 0.25ΒΉβ° β 9.54 Γ 10β»β·
20 layers: 0.25Β²β° β 9.10 Γ 10β»ΒΉΒ³
THE EARLY LAYERS RECEIVE ESSENTIALLY NO SIGNAL AND NEVER
LEARN. This is precisely why networks stayed shallow until
roughly 2010, and why the fixes below launched deep learning:
Β· ReLU, whose derivative is exactly 1 for positive input
Β· careful initialisation (Xavier, He)
Β· batch normalisation
Β· residual/skip connections, which give the gradient a
path that bypasses the multiplications entirely
THE EXPLODING GRADIENT is the mirror image, with factors > 1;
the standard fix is GRADIENT CLIPPING.
3. OVERFITTING. Mitigations: early stopping on a validation set,
weight decay (L2), dropout, data augmentation.
4. THE LEARNING RATE. Too large diverges, too small crawls β the
trade-off analysed in the learning-rate topic. Schedules and
adaptive methods address it.
5. SLOW CONVERGENCE β thousands of epochs is normal. Momentum,
adaptive rates, normalised inputs and good initialisation all
help.
6. IT IS NOT BIOLOGICALLY PLAUSIBLE. Real neurons have no
mechanism for sending an error signal backwards along the
axon, and the algorithm requires a unit to know the weights
of the connections leaving it β the WEIGHT TRANSPORT PROBLEM.
BACKPROPAGATION IS ENGINEERING, NOT NEUROSCIENCE, and the
honest position is that it works despite being unlike the
brain rather than because it resembles it.
THE COMPLETE ALGORITHM, as it should be written in an exam:
1. initialise all weights to small random values
2. repeat until the stopping criterion is met:
for each training example (x, t):
a. FORWARD PASS: compute hβ±Ό = f(Ξ£vβ±Όα΅’xα΅’ + bβ±Ό),
then yβ = f(Ξ£wββ±Όhβ±Ό + cβ)
b. OUTPUT Ξ΄: Ξ΄β = (yβ β tβ)Β·fβ²(net_k)
c. HIDDEN Ξ΄: Ξ΄β±Ό = (Ξ£β Ξ΄βwββ±Ό)Β·fβ²(net_j)
d. UPDATE: wββ±Ό β wββ±Ό β Ξ· Ξ΄β hβ±Ό
vβ±Όα΅’ β vβ±Όα΅’ β Ξ· Ξ΄β±Ό xα΅’
biases likewise, with input 1
3. stop on: error below a threshold, validation error rising,
or an epoch limit
Everything reduces to one line: Ξ΄β±Ό = (Ξ£β Ξ΄β wββ±Ό) Β· fβ²(net_j). A hidden unit has no target, so its error is borrowed from the units it feeds, in proportion to the weights through which it feeds them. That is the answer to credit assignment, and it is why the same rule works at every layer of a network of any depth.
π Go further: Notice in the worked trace that the hidden gradients (β 0.0002) are about a hundred times smaller than the output gradients (β 0.026) β in a network only two layers deep. Multiply that shrinkage across twenty layers and the early weights receive a signal near 10β»ΒΉΒ³, indistinguishable from numerical noise. This one fact held the field back for roughly twenty years: the algorithm was known from 1986, but nobody could train a deep network with it. The breakthroughs of 2010β2015 β ReLU, careful initialisation, batch normalisation and residual connections β are all, at bottom, attacks on this single multiplication. Search "vanishing gradient problem ReLU residual connections deep learning".
π‘ Exam angle: this topic is almost always a long-form question, and the marks are in the derivation and the trace. State the credit assignment problem, then derive Ξ΄β = (yβ β tβ)fβ²(net_k) for the output and Ξ΄β±Ό = (Ξ£β Ξ΄βwββ±Ό)fβ²(net_j) for the hidden layer, naming the chain rule at each step. Point out that the output rule is the delta rule plus the factor fβ²(net), and that fβ² = y(1 β y) for the sigmoid. Be able to run a small numerical trace β forward pass, Ξ΄ values, weight updates, and a re-run showing the error fell. Write out the algorithm as numbered steps. Then list the problems, giving vanishing gradients the most space with the 0.25-per-layer argument, and remember that the bias update has no x factor.