Module 5 — Backpropagation Intuition
Module 4 treated the gradient-computation step as a black box: "compute, for each weight, the partial derivative of the loss." This computation is backpropagation, and despite the terminology it is a direct application of the chain rule of calculus — building on the derivatives and gradient from Course 2 — applied recursively in the reverse direction through the network. This module derives the computation explicitly so that the gradient flow can be observed weight by weight.
The principle: attributing error to each weight
After a forward pass yields a prediction and a loss, backpropagation answers: what is the contribution of each weight to the loss? The computation begins at the output, where the error is directly observable (prediction minus target), and proceeds backward through the network. A weight near the output contributes to the loss directly; a weight in an earlier layer contributes through every downstream computation in which its output participates — and the chain rule precisely formalizes the multiplication of these intermediate influences.
- Output error — begin with \( \hat{y} - y \), the deviation of the prediction from the target.
- Backward step — propagate this error to the preceding layer, scaled by the weights through which it flowed and by the derivative of each neuron's activation function (the chain rule).
- Gradient — for each weight, the gradient equals (the error signal arriving at its neuron) × (the input the weight carried). This quantity is \( \partial\text{loss}/\partial w \).
This activity needs JavaScript.
Now use the full network trainer below to see many steps at once:
Click Train one step below. The network executes a forward pass, computes the loss, and then backpropagation visualizes each connection's contribution to the gradient — thicker lines correspond to larger gradient magnitudes. Weights with the largest gradients undergo the largest updates, and with a well-chosen learning rate the loss trends downward across iterations — though, as you saw in Module 4, too large a step can overshoot and send it back up.
This activity needs JavaScript. The lesson below still covers everything.
pred = model(X) # forward pass loss = loss_fn(pred, y) # one number loss.backward() # BACKPROP — fills every weight's .grad via the chain rule optimizer.step() # update: w ← w − η · w.grad optimizer.zero_grad() # clear grads for the next step
The single loss.backward() call corresponds to the backward propagation visualized above: it computes \( \partial\text{loss}/\partial w \) for every weight automatically via automatic differentiation. Manual application of the chain rule is unnecessary; the framework implements it.
Check your understanding
Answer a short set of questions on backpropagation.
This activity needs JavaScript.