Equations · Rumelhart, Hinton and Williams, “Learning representations by back-propagating errors” (1986)
Backpropagation for one layer: the chain rule, explained
Given the gradient of the loss with respect to a layer's output, the chain rule gives the gradients for its weights, its bias and its input. The last one is passed to the layer below.
Term by term
The forward pass: weights times input plus bias, the pre-activation.
The activation, applied elementwise. here is a function (often the sigmoid).
The error signal: the loss's gradient with respect to the pre-activation.
The chain rule through an elementwise function is an elementwise product with its derivative .
An outer product: entry is , so the weight gradient has 's shape.
The gradient sent back to the input, through the transposed weights.
Shapes
- , , .
- , matching ; , matching .
A small worked example
One weight: , , , sigmoid, loss with . Forward: , . Backward: ; ; ; . The negative gradient says: increase .
In code
import numpy as np
def dense_backward(W, x, z, dL_da, dsigma):
delta = dL_da * dsigma(z) # (m,)
dW = np.outer(delta, x) # (m, n)
db = delta # (m,)
dx = W.T @ delta # (n,)
return dW, db, dxEvery symbol in it
Other equations
- Scaled dot-product attention
- Softmax
- Cross-entropy loss
- Adam update
- Layer normalization
- RMSNorm
- The ELBO
- KL divergence
- LoRA
- GELU
- Dropout
- Batch normalization
- Rotary position embedding (RoPE)
- Multi-head attention
- PPO clipped objective
- DPO loss
- Policy gradient (REINFORCE)
- Bellman equation
- Q-learning update
- InfoNCE contrastive loss
- Diffusion forward process
- DDPM simplified loss
- VAE reparameterization trick
- GAN minimax objective
- AdamW
- Cosine learning-rate schedule
- Perplexity
- Logistic regression
- Normal equation (linear regression)
- Singular value decomposition (SVD)
- Principal component analysis (PCA)