Backpropagation
Backpropagation is an algorithm for efficiently computing the gradient of a scalar loss function with respect to every parameter in a neural network by applying the chain rule of calculus in a single reverse-mode pass through the computation graph. It is the foundational engine of virtually all deep learning training — without it, optimizing networks with millions or billions of parameters would be computationally infeasible. A counterintuitive fact: backpropagation does not actually learn anything itself — it only computes gradients; the learning is performed by a separate optimizer that consumes those gradients.
Every neural network is just a composed function, and the chain rule tells you how to differentiate composed functions. Backpropagation is simply the chain rule applied systematically and efficiently, reusing intermediate computations so that you compute each partial derivative exactly once rather than redundantly. The "aha moment" is realizing that the forward pass builds a computational graph that stores everything you need, and the backward pass is just a single structured traversal of that graph in reverse — no numerical approximations, no independent perturbations per parameter, just exact symbolic differentiation at the cost of one extra forward-pass worth of computation.
How It Works
The Forward Pass: Building the Computation Graph
A neural network computes a prediction through a sequence of operations. For a single layer with weight matrix , bias , activation , and input :
Explanation: The pre-activation is a linear combination of the inputs — this is the purely affine part of the layer before any nonlinearity is applied.
Explanation: The activation function (e.g. ReLU, sigmoid, tanh) introduces nonlinearity; is the post-activation output passed to the next layer.
The Loss
For a regression task with target , the mean-squared loss over a batch of examples is:
Explanation: is the single scalar we want to minimize — backprop's job is to find how every parameter in the network nudges this number.
The Chain Rule: Core of Backprop
Suppose depends on , which depends on , which depends on . The chain rule gives:
Explanation: The gradient of the loss with respect to factors into a product of local gradients, each computable from quantities already available at that node of the graph. Here:
- — the error signal arriving from the layer above (already computed by the time we reach this layer in the backward pass)
- — the derivative of the activation, computed from stored during the forward pass
- — the input to this layer, also stored during the forward pass
The General Gradient Update Rule
For a parameter updated with learning rate :
Explanation: Each parameter moves a small step in the direction that most steeply reduces the loss — the gradient is what backpropagation supplies.
PyTorch Implementation
```python import torch import torch.nn as nn
# Simple two-layer network model = nn.Sequential( nn.Linear(784, 256), nn.ReLU(), nn.Linear(256, 10) ) optimizer = torch.optim.Adam(model.parameters(), lr=1e-3) loss_fn = nn.CrossEntropyLoss()
# --- Training step --- x, y = next(iter(train_loader)) # fetch a batch
# 1. Forward pass: builds the computation graph logits = model(x) loss = loss_fn(logits, y)
# 2. Backward pass: backprop fills .grad for every parameter optimizer.zero_grad() # clear stale gradients from last step loss.backward() # THE backprop call
# 3. Optimizer step: actually update weights (NOT backprop) optimizer.step() print(f"Loss: {loss.item():.4f}") print(f"Grad norm W1: {model[0].weight.grad.norm():.4f}") ```
Geoffrey Hinton, a British-Canadian cognitive scientist and computer scientist at the University of Toronto and Google Brain, co-authored the landmark 1986 Nature paper "Learning representations by back-propagating errors" with David Rumelhart and Ronald Williams, which demonstrated that backpropagation could train multi-layer networks to learn useful internal representations. His persistent advocacy for neural networks during the "AI winters" — decades when the broader community dismissed them — proved decisive in establishing deep learning as the dominant paradigm. Hinton shared the 2024 Nobel Prize in Physics for his contributions to artificial neural networks, and he famously resigned from Google in 2023 partly to speak freely about AI risks.
Yann LeCun, a French-American computer scientist at NYU and Meta AI Research, applied backpropagation to train convolutional neural networks (LeNet) for handwritten digit recognition in the late 1980s and early 1990s, producing the first practically deployed deep learning system — AT&T's check-reading machines processed millions of bank checks daily using his backprop-trained networks. His work demonstrated that backpropagation was not merely a theoretical curiosity but an engineering tool capable of real commercial deployment. LeCun, along with Hinton and Yoshua Bengio, received the 2018 Turing Award — often called the "Nobel Prize of computing."
Intuition
Imagine you are a manager in a large company, trying to figure out which employees caused a particular bad outcome. The naive approach would be to interview every single employee independently — but that takes forever. Instead, you hold a "blame meeting" that starts at the top of the org chart (the loss) and cascades downward, each manager passing credit or blame proportionally to their direct reports based on how much each person actually influenced the outcome. The forward pass is like watching the work get done: inputs flow up through the hierarchy, each layer transforms the data, and eventually a final mistake (the loss) is recorded. The backward pass is the blame cascade: the loss says "I was this wrong," the output layer says "here is how much each of my inputs contributed," the hidden layers each receive their share of the blame and pass it further back — all the way to the weights. The key efficiency insight is that the "blame fractions" at each layer — the local gradients like and — were already computed and cached during the forward pass. No extra work is needed to compute them during the backward pass; they are just retrieved from memory. This is what makes backprop backward passes relative to the number of parameters, rather than the passes naive finite-difference gradient estimation would require. Think of it as a receipt: the forward pass builds a detailed receipt of every operation, and the backward pass reads that receipt from bottom to top, tallying up each item's contribution to the total.
Historical Development
Origins · 1 minhow this was discovered
Why It Matters
Prerequisites
What This Leads To
See Also
Gradient Descent · Chain Rule · Automatic Differentiation · Vanishing and Exploding Gradients · Stochastic Gradient Descent · Computation Graphs · Learning Rate Scheduling