How backpropagation assigns blame
Follow one neuron through a forward pass, a loss, and a backward pass with real numbers, and see how the chain rule hands every weight its share of the blame for one bad prediction.
7 min · Scroll, and the lab follows along. You can still drag every control. Full lesson: Backpropagation.
Backpropagation lab
One neuron, sigmoid output, binary cross-entropy. Defaults are the course example.
- 1. Weighted sum
- 2. Sigmoid output
- 3. Binary cross-entropy
- 4. Error signal
- 5. Gradient for w₁
- 6. Gradient for w₂
- 7. Gradient for b
- 8. Update (η = 0.1)
- 9. New prediction
Why is step 4 so simple? and . Multiplying them (the chain rule), the terms cancel.
A network makes a prediction, the prediction is wrong, and now every weight needs to know how much of the mistake was its fault. Backpropagation answers that for all weights at once. We'll follow one neuron with real numbers; on the website the lab beside the text changes as you scroll.
The forward pass
Our neuron has two inputs, and , two weights, and , and a bias . First it takes a weighted sum:
Then the sigmoid squashes into a probability: . The neuron is saying "fifty-fifty". Rows 1 and 2 of the lab show exactly this. Keep these intermediate values in mind: the backward pass will reuse every one of them.
The loss
The true label is , so a guess of 0.5 is only half right. Binary cross-entropy turns that into one number:
Watch swing in the lab. When it grows, grows, climbs toward 1 and the loss shrinks toward 0. When it falls, drops and the loss climbs fast, because cross-entropy punishes a confident wrong answer hard. Training means nudging the weights so this number goes down. To nudge them we need to know which way each one should move, and by how much.
Passing the gradient backwards
The loss doesn't see directly. It sees , which sees , which sees . The chain rule says: to get the loss's sensitivity to something far back, multiply the local sensitivities along the way.
So we start at the loss and walk backwards one node at a time. Through the loss node, . Through the sigmoid node, multiply by its slope . Those two factors cancel, and what reaches is strikingly simple:
This is the error signal, row 4 of the lab. Negative means " should go up".
A gradient for every weight
One more step back. Since , nudging moves by times as much. So each weight's gradient is the error signal times the input it multiplies:
That is the blame assignment. gets twice the blame of because its input was twice as large: it had twice the say in the mistake. Watch swing in the lab and the gradient follows it. A weight attached to an input of 0 gets no blame at all.
The update
Now step every weight against its gradient, scaled by the learning rate :
Run the forward pass again: , so . The prediction moved from 0.5 toward the label 1, and the loss fell. In the lab, watch grow: the gradients stay the same, but the step gets longer and the new prediction lands further along. The gradient picks the direction; decides how far to trust it.
Flip the label
Set and run it again. The forward pass doesn't change at all: , , , because the loss for a 0.5 guess is the same either way.
But the error signal becomes , and since every gradient is that signal times an input, all of them flip sign: , , . The update now pushes down to 0.4, and the new prediction drops to 0.426, toward the new label. Same arithmetic, opposite blame. The sign of alone decides which way every weight moves.
Why it's cheap
Look back at what we computed. One subtraction, , fed all three gradients, and each needed only one extra multiply by a value the forward pass had already stored.
In a deep network the same thing happens layer by layer. The gradient arriving at a layer is computed once and reused by everything upstream of it, so the backward pass does roughly the same kind of work as the forward pass, about one to two times its cost. Compare that with nudging each weight separately and re-running the network: for a billion weights, that's two billion forward passes. Backpropagation gets every gradient for the price of about one.
Try it yourself: edit any input or weight in the lab and all nine steps recompute, or open the full lesson for vanishing gradients, a finite-difference check, and the PyTorch version.