Advanced Mathematics

Backpropagation

Computing the gradient of the loss with respect to every weight by applying the chain rule backwards through the network, layer by layer.

Needs a step first: 35

A network is a long composition of simple functions, so the derivative of the loss with respect to any weight is a product of local derivatives along the path from that weight to the loss. Backpropagation computes them efficiently: a forward pass stores each intermediate value, then a backward pass starts from ∂L/∂L=1\partial L/\partial L = 1 and multiplies by one local derivative at each step, reusing the shared parts. The cost is only a small multiple of the forward pass, however many weights there are. This is what makes training networks with millions of parameters possible; software that does it automatically is called automatic differentiation.

Where it shows up: Every deep model on this map, from convolutional networks to transformers and diffusion models, is trained with gradients from backpropagation.

How to hold it: In your head

See backpropagation as the chain rule run backwards, reusing the shared products, which is why one backward pass costs about as much as one forward pass however many weights there are.

What knowing it looks like

  • Draw the computation graph of a small network and carry gradients backwards through it by hand.
  • Check a backpropagated gradient against a finite difference.
  • Explain why the backward pass costs about as much as the forward pass, not once per weight.

Test yourself

A tiny network computes z=w1xz = w_1x, h=ReLU(z)h = \mathrm{ReLU}(z), y^=w2h\hat y = w_2h, with loss L=12(y^−y)2L = \tfrac12(\hat y - y)^2. With x=3x = 3, w1=0.5w_1 = 0.5, w2=2w_2 = 2 and target y=1y = 1, do the forward pass and find ∂L/∂w2\partial L/\partial w_2 and ∂L/∂w1\partial L/\partial w_1 by backpropagation.
Show the worked answer
Forward: z=1.5z = 1.5, h=1.5h = 1.5, y^=3\hat y = 3, L=12⋅22=2L = \tfrac12\cdot2^2 = 2. Backward: ∂L/∂y^=y^−y=2\partial L/\partial\hat y = \hat y - y = 2. ∂L/∂w2=2⋅h=3\partial L/\partial w_2 = 2\cdot h = 3. ∂L/∂h=2⋅w2=4\partial L/\partial h = 2\cdot w_2 = 4. Since z>0z > 0, ReLU passes it through: ∂L/∂z=4\partial L/\partial z = 4. ∂L/∂w1=4⋅x=12\partial L/\partial w_1 = 4\cdot x = 12. Check: w1=0.501w_1 = 0.501 gives y^=3.006\hat y = 3.006 and L≈2.012L \approx 2.012, a rise of about 12×0.00112 \times 0.001.

Needs a step first: 35

Learn it with an AI

Copy this prompt into any AI assistant. It will take you through step by step at your level and finish with the test above.

Be my maths tutor. I'm learning "Backpropagation" (Frontier tier): Computing the gradient of the loss with respect to every weight by applying the chain rule backwards through the network, layer by layer.
I already know: Neural Networks, The Multivariable Chain Rule and Jacobians.
Teach it Socratically: first ask what I already know; then explain the core idea with one concrete example and why it's true; then give me three problems, one at a time, easy to hard. Wait for my answer, check every step, and point out mistakes without giving the answer away.
Finish by testing me with this: A tiny network computes $z = w_1x$, $h = \mathrm{ReLU}(z)$, $\hat y = w_2h$, with loss $L = \tfrac12(\hat y - y)^2$. With $x = 3$, $w_1 = 0.5$, $w_2 = 2$ and target $y = 1$, do the forward pass and find $\partial L/\partial w_2$ and $\partial L/\partial w_1$ by backpropagation.
Use LaTeX for formulas. When you say where it's used later (machine learning, quantum mechanics), be specific.

On the way to

Recommended