Backprop Bulletin explainer
What is backpropagation?
Backpropagation works backward through a neural network to calculate how a small change to each weight would affect the loss, a measure of prediction error. These sensitivities are called gradients. An optimizer uses them to adjust the weights.
The short answer
Training a neural network repeats four steps:
- Prediction (the forward pass): the network turns an input into a prediction.
- Loss: one number measures how wrong the prediction was.
- Backpropagation: working backward from the loss, the network calculates a gradient for every weight: how fast the loss would change if that weight changed a little.
- Weight update: an optimizer, such as gradient descent, uses those gradients to change the weights.
Backpropagation is step 3 only. It calculates the gradients and changes no weight. Changing the weights is the optimizer’s job, in step 4.
The tiny network
Here we follow one tiny network through one training step, with numbers you can check by hand. It has one input, one hidden value and one output, joined by two weights. It has no activation function, so every step is a multiplication you can follow.
- Input x = 2
- Weights w₁ = 0.5 and w₂ = 2
- Hidden value h = w₁ × x
- Prediction ŷ (“y-hat”) = w₂ × h
- The correct answer, or target, y = 3
1. Prediction
The forward pass applies each weight in turn:
h = 0.5 × 2 = 1
ŷ = 2 × 1 = 2
The network predicts 2. The target is 3.
2. Loss
A loss function turns the miss into one number. We use the squared error:
L = (ŷ − y)² = (2 − 3)² = 1
Squaring makes every miss count as positive and makes bigger misses count more. Training aims to make this number smaller.
3. Backpropagation: calculating the gradients
For each weight, backpropagation asks: if this weight grew by a tiny amount, how fast would the loss change? That rate is the weight’s gradient, written ∂L/∂w. Backpropagation starts at the loss and works backward, one link at a time, multiplying the local rates together. This is the chain rule from calculus.
- At the loss: ∂L/∂ŷ = 2 × (ŷ − y) = 2 × (2 − 3) = −2. The minus sign says a larger prediction would lower the loss.
- Through w₂: since ŷ = w₂ × h, a change in w₂ is multiplied by h. So ∂L/∂w₂ = −2 × 1 = −2.
- Back to the hidden value: a change in h is multiplied by w₂, still at its original value of 2. So ∂L/∂h = −2 × 2 = −4.
- Through w₁: since h = w₁ × x, a change in w₁ is multiplied by x. So ∂L/∂w₁ = −4 × 2 = −8.
The output gradient, −2, is calculated once and used twice: first to find the gradient for w₂, then to pass the gradient back to h. The −4 that arrives at h is then used in the same way to find the gradient for w₁. Nothing is calculated twice; each result is passed backward to the next step. That reuse is what makes backpropagation efficient: a network with millions of weights gets every gradient from one backward pass.
Both gradients are negative, so increasing either weight would lower the loss. The gradient for w₁ is larger, so right now the loss is more sensitive to w₁ than to w₂. No weight has changed yet.
4. Weight update: the optimizer’s step
Now the optimizer uses the gradients. Plain gradient descent moves each weight a small step against its gradient:
new weight = old weight − learning rate × gradient
Both updates use the gradients from step 3, which all come from the original forward pass (w₁ = 0.5, w₂ = 2, h = 1). The optimizer changes the two weights together; it does not change w₂ first and then recalculate the gradient for w₁ with the new value. With a learning rate of 0.025:
w₂ = 2 − 0.025 × (−2) = 2.05
w₁ = 0.5 − 0.025 × (−8) = 0.7
A fresh forward pass shows the effect:
h = 0.7 × 2 = 1.4
ŷ = 2.05 × 1.4 = 2.87
L = (2.87 − 3)² = 0.0169
The loss fell from 1 to 0.0169 in one step. The learning rate is the optimizer’s setting: too small and training crawls; too large and the update overshoots the target. Other optimizers, such as Adam, start from the same gradients but choose the size of each step differently.
| Step | Done by | In the example |
|---|---|---|
| 1. Prediction | the network’s forward pass | ŷ = 2 |
| 2. Loss | the loss function | L = 1 |
| 3. Gradients | backpropagation | ∂L/∂w₂ = −2, ∂L/∂w₁ = −8 |
| 4. Weight update | the optimizer | w₂: 2 → 2.05; w₁: 0.5 → 0.7 |
In real networks
Real networks follow the same four steps at a far larger scale:
- Many weights: one backward pass gives a gradient for every weight, whether there are two or billions.
- Activation functions: between layers, functions such as ReLU bend the signal. Backpropagation multiplies by each one’s local slope as well. ReLU’s slope is 1 where it passes a value through and 0 where it outputs zero.
- Batches: the loss is usually averaged over a batch of examples, so each gradient is an average too.
- Automatic differentiation: frameworks record the forward pass and run backpropagation for you. In PyTorch, for example,
loss.backward()calculates the gradients andoptimizer.step()updates the weights: the same split as steps 3 and 4.
Sources
- David E. Rumelhart, Geoffrey E. Hinton and Ronald J. Williams, “Learning representations by back-propagating errors”, Nature 323 (1986): the paper that popularized backpropagation for training neural networks.
- Ian Goodfellow, Yoshua Bengio and Aaron Courville, Deep Learning, chapter 6 (MIT Press, 2016): section 6.5 covers back-propagation and the chain rule.
- PyTorch, “A Gentle Introduction to torch.autograd”: how a framework runs the backward pass for you.
The worked example is our own. Every number on this page can be recomputed by hand from x = 2, w₁ = 0.5, w₂ = 2, y = 3 and a learning rate of 0.025.