The Big Question
A neural network can now perform a forward pass. Given Jessie's restaurant visit, it might predict a 95 percent chance that Jessie orders a burger.
But suppose Jessie does not order one. The network made a mistake. Now the hard question appears.
A network may contain millions of weights. Which weights caused the mistake, and by how much should each one change?
Backpropagation answers that question. It computes the gradient of the loss with respect to every parameter in the network.
Why Guessing Is Hopeless
Imagine a small network with hunger, price, and social influence feeding a hidden neuron, which feeds an output neuron. If the prediction is wrong, should we change the hunger weight, the price weight, the output weight, or all of them?
In a modern network, doing this by trial and error is impossible. If there are 100 million parameters, changing one parameter at a time would require 100 million separate forward passes for one update.
We need one systematic pass that assigns responsibility to every parameter. That is the job of backpropagation.
Core Intuition
Think of a group project. The final report is poor. To improve next time, you need to know what caused the problem. Did one person write incorrect facts? Did another make misleading graphs? Did someone else compute the statistics incorrectly?
The final mistake came from many intermediate contributions. Backpropagation moves backward through those contributions and assigns each one a share of responsibility.
In neural-network language, that share of responsibility is a gradient:
It means: if this weight increased by a tiny amount, how would the loss change?
Separate The Three Ideas
Students often blend the training process into one vague step. Keep these pieces separate:
| Stage | Question | Important detail |
|---|---|---|
| Forward pass | Compute the prediction | No weights change |
| Loss | Measure how wrong the prediction is | One number |
| Backpropagation | Compute gradients for every parameter | Still no weights change |
| Gradient descent | Use gradients to update weights | Weights change here |
Backpropagation does not update weights. It computes the gradients that an optimizer will later use to update weights.
Interactive Demo
| Quantity | Meaning | Value |
|---|---|---|
| dL/da | loss sensitivity to activation | -0.1192 |
| da/dz | sigmoid local slope | 0.1050 |
| dz/dw | weighted-sum sensitivity to weight | 3.0000 |
| dL/dw | final gradient for w | -0.0375 |
| dL/db | final gradient for b | -0.0125 |
= -0.119 x 0.105 x 3.000
= -0.0375
Backpropagation computes the gradients. Gradient descent uses those gradients to move the parameters. They are connected, but they are not the same step.
Adjust the input, weight, bias, target, and learning rate. The gradient for the weight is a product of local derivatives along the path from loss back to the weight.
Mathematics
Forward Pass First
Suppose the model predicts and the true label is . For binary classification, binary cross-entropy is:
Because , this simplifies to:
The forward pass has computed the prediction and the loss. It has not explained how any weight should change.
The Gradient We Need
For a weight , the quantity we need is:
If this derivative is positive, increasing the weight increases the loss, so gradient descent decreases the weight. If it is negative, increasing the weight decreases the loss, so gradient descent increases the weight.
The Chain Of Computations
For one neuron, the computation might be:
The loss depends on . The activation depends on . The weighted sum depends on .
The weight affects the loss indirectly. The chain rule tells us how to multiply the indirect effects:
What Each Term Means
| dL/da | If the activation changes slightly, how much does the loss change? |
| da/dz | If the weighted sum changes slightly, how much does the activation change? |
| dz/dw | If the weight changes slightly, how much does the weighted sum change? |
Each local derivative is simple. Backpropagation combines many simple local derivatives into the gradient for every parameter.
Worked Example
Use an intentionally simple computation so the arithmetic is visible:
Let and . Then:
Now compute the derivative with respect to the weight:
This gradient says that increasing would increase the loss strongly. Gradient descent therefore moves downward.
Why It Is Efficient
Backpropagation stores intermediate values from the forward pass, then walks backward through the computational graph. Every operation contributes its local derivative once.
Instead of running one forward pass per weight, backpropagation computes gradients for all weights in roughly the same order of work as a forward pass. This efficiency is what makes training large neural networks feasible.
Matrix Version
In practice, layers are vectorized. A layer computes:
Backpropagation computes for the whole weight matrix at once. Modern frameworks automate this matrix calculus, but the underlying idea is still the chain rule.
Implementation
This NumPy example trains a tiny network with one sigmoid neuron. It separates the forward pass, backward pass, and parameter update so the roles stay clear.
import numpy as np
def sigmoid(z):
return 1 / (1 + np.exp(-z))
def sigmoid_grad(a):
return a * (1 - a)
x = np.array([[3.0]])
y = np.array([[1.0]])
w = np.array([[2.0]])
b = np.array([[-4.0]])
lr = 0.5
# Forward pass
z = w @ x + b
a = sigmoid(z)
loss = 0.5 * (a - y) ** 2
# Backward pass
dL_da = a - y
da_dz = sigmoid_grad(a)
dL_dz = dL_da * da_dz
dL_dw = dL_dz @ x.T
dL_db = dL_dz
# Gradient descent update
w = w - lr * dL_dw
b = b - lr * dL_db
print("prediction:", a.item())
print("loss:", loss.item())
print("dL/dw:", dL_dw.item())
print("updated w:", w.item())Automatic Differentiation
Modern ML engineers rarely write these derivatives by hand. PyTorch builds a computational graph during the forward pass. Calling traverses that graph backward and stores gradients on each parameter.
import torch x = torch.tensor([[3.0]]) y = torch.tensor([[1.0]]) w = torch.tensor([[2.0]], requires_grad=True) b = torch.tensor([[-4.0]], requires_grad=True) z = x @ w.T + b a = torch.sigmoid(z) loss = 0.5 * (a - y).pow(2).mean() loss.backward() print(w.grad) print(b.grad)
Frameworks automate backpropagation. They do not avoid it. Understanding the mechanism explains why gradients can vanish, explode, or fail to flow through certain operations.
Interview Discussion
What problem does backpropagation solve?
It efficiently computes the gradient of the loss with respect to every parameter in a neural network.
How is backpropagation different from gradient descent?
Backpropagation computes gradients. Gradient descent uses those gradients to update the parameters.
Why is the chain rule central to backpropagation?
A weight affects the loss through intermediate computations. The chain rule multiplies local derivatives along that path.
Why is backpropagation efficient?
It reuses forward-pass intermediate values and computes each local derivative once, instead of perturbing every parameter separately.
What is a computational graph?
It is a graph of operations and values. The forward pass evaluates the graph; the backward pass propagates derivatives through it.
What does loss.backward() do conceptually?
It traverses the computational graph backward, applies the chain rule at each operation, and accumulates gradients for parameters.
Active Recall
1. Describe the training loop from forward pass to parameter update.
2. What quantity does backpropagation compute?
3. Write the chain rule for dL/dw when L depends on a, a depends on z, and z depends on w.
4. Why is estimating each gradient by perturbing one weight impractical?
5. Why does backpropagation move from the output layer toward the input layer?
6. What is the difference between a local derivative and the final gradient for a parameter?
Common Mistakes
- Confusing backpropagation with gradient descent.
- Thinking the backward pass directly changes weights.
- Believing the chain rule is special to neural networks rather than ordinary calculus.
- Assuming automatic differentiation means backpropagation is no longer happening.
- Forgetting that forward-pass values are reused during the backward pass.
Connection To Training Deep Networks
Backpropagation tells every parameter how it affected the loss. The next challenge is using those gradients effectively. Training deep networks depends on learning rates, optimizers, initialization, batch size, normalization, and regularization.