The Blame Assignment Problem
In Section 6.5 we discovered that learning means rolling downhill on a loss surface. Gradient descent tells us which direction to nudge each weight - but a deep network has thousands or millions of weights, organised in stacked layers. The question that stalled neural networks for two decades was deceptively simple:
When the output is wrong, how much of the blame belongs to a weight buried four layers deep, on the third neuron from the left?
For a single-layer perceptron the answer is obvious - each weight directly touches the output. But once you stack hidden layers, the contribution of an early weight is mediated by every layer that follows it. The error you observe at the top is the compound result of every transformation in between.
CE Analogy — Forensic Load Path Analysis
Picture a steel truss bridge that just deflected past its serviceability limit under a load test. The midspan dropped 40 mm instead of the predicted 25 mm. Which member is most responsible?
You don't blame every member equally. You trace the load path backwards: the bottom chord carried tension proportional to its influence coefficient, the diagonals carried shear proportional to theirs, and so on. A member with a high sensitivity coefficient — one whose stiffness change would noticeably shift the deflection — deserves more of the blame than a member that barely participates.
Backpropagation is exactly this trace. The "sensitivity coefficient" of each weight is its partial derivative with respect to the loss — how much the loss would change if that one weight wiggled. The chain rule of calculus gives us a recursive way to compute every one of them in a single sweep from output to input.
Computational Graphs
Before we touch the chain rule, we need a clean mental model of what a neural network is. Forget "layers of neurons" for a moment. Internally, a network is a computational graph — a directed acyclic graph where every node is a single mathematical operation, and every edge carries a number forward.
Consider the absurdly tiny "network" $$L = (w_2 \cdot \sigma(w_1 \cdot x + b_1) + b_2 - y)^2$$ We can rewrite it as a graph of primitive operations:
z1 = w1 · xa1 = z1 + b1h = σ(a1)z2 = w2 · hŷ = z2 + b2e = ŷ − yL = e2
Each line is an atomic operation whose derivative we already know from first-year calculus. The trick of backprop is that derivatives compose along edges — if you know the derivative of every local operation, you can stitch them together to get the derivative of the whole graph.
The Chain Rule — Backbone of Backprop
From calculus, if $y = f(u)$ and $u = g(x)$, then $$\frac{dy}{dx} = \frac{dy}{du} \cdot \frac{du}{dx}$$ Read it aloud: "the sensitivity of y to x equals the sensitivity of y to u, multiplied by the sensitivity of u to x." That single identity, applied recursively across a graph, is backpropagation. There is no other secret ingredient.
Stack three operations $y = f(g(h(x)))$. The chain rule extends: $$\frac{dy}{dx} = \frac{dy}{df} \cdot \frac{df}{dg} \cdot \frac{dg}{dh} \cdot \frac{dh}{dx}$$ Each factor is the local derivative of one operation. To compute the gradient at the bottom, multiply local derivatives along the path. In a general DAG with branching, you sum the contributions over all paths — a fact that falls out of the multivariable chain rule.
CE Analogy — Gear Train Sensitivity
A gear train of three wheels with ratios 2:1, 3:1, 4:1 produces an overall ratio of $2\times3\times4 = 24$. If you wiggle the input by 1°, the output rotates 24°. The chain rule is exactly the same idea: each "gear" is a layer's local derivative, and the total sensitivity is the product as the signal traces through.
The danger: if any local derivative is much smaller than 1, the chain product collapses towards zero (vanishing gradient). If any is much greater than 1, it blows up (exploding gradient). We will see this in Demo 2.
import math
x, y_true = 2.0, 1.0
w1, b1, w2, b2 = 0.5, 0.1, -0.8, 0.2
# forward pass
z1 = w1 * x + b1
h = 1 / (1 + math.exp(-z1)) # sigmoid
z2 = w2 * h + b2
y = z2 # linear output
L = (y - y_true) ** 2
# backward pass — pure chain rule
dL_dy = 2 * (y - y_true)
dL_dz2 = dL_dy * 1
dL_dw2 = dL_dz2 * h
dL_db2 = dL_dz2
dL_dh = dL_dz2 * w2
dL_dz1 = dL_dh * h * (1 - h) # sigmoid'
dL_dw1 = dL_dz1 * x
dL_db1 = dL_dz1
Backprop Step-by-Step on a 2–2–1 Network
Let us anchor the algebra in a concrete network with two inputs, two hidden neurons (sigmoid), and one linear output. We will walk through one full forward + backward pass with real numbers, then formalise the update rule.
Setup
- Input $\mathbf{x} = (1.0,\ 0.5)$, target $y = 1.0$
- Hidden weights $W^{(1)} = \begin{pmatrix}0.4 & -0.2\\ 0.3 & 0.7\end{pmatrix}$, biases $\mathbf{b}^{(1)} = (0.1,\ -0.1)$
- Output weights $\mathbf{w}^{(2)} = (0.6,\ -0.5)$, bias $b^{(2)} = 0.2$
- Hidden activation: sigmoid $\sigma(z)$. Output: linear. Loss: $\tfrac{1}{2}(\hat{y}-y)^2$.
Forward pass
Hidden pre-activations: $z^{(1)}_1 = 0.4(1.0) + (-0.2)(0.5) + 0.1 = 0.40$, $z^{(1)}_2 = 0.3(1.0) + 0.7(0.5) - 0.1 = 0.55$.
Hidden activations: $h_1 = \sigma(0.40) \approx 0.599$, $h_2 = \sigma(0.55) \approx 0.634$.
Output: $\hat{y} = 0.6(0.599) + (-0.5)(0.634) + 0.2 \approx 0.242$. Loss: $L = \tfrac{1}{2}(0.242 - 1)^2 \approx 0.287$.
Backward pass
Output error signal (output is linear, so $\sigma'(z^{(2)}) = 1$):
$$\delta^{(2)} = \hat{y} - y = -0.758$$Hidden error signal — propagate through $\mathbf{w}^{(2)}$ and multiply by $\sigma'(z^{(1)}_j) = h_j(1-h_j)$:
$$\delta^{(1)}_j = w^{(2)}_j \cdot \delta^{(2)} \cdot h_j(1-h_j)$$
$\delta^{(1)}_1 = 0.6 \cdot (-0.758) \cdot 0.599 \cdot 0.401 \approx -0.109$
$\delta^{(1)}_2 = -0.5 \cdot (-0.758) \cdot 0.634 \cdot 0.366 \approx 0.088$
Weight gradients
For every weight, $\dfrac{\partial L}{\partial W_{ij}} = a_i \cdot \delta_j$ where $a_i$ is the activation feeding into the weight:
- $\partial L/\partial w^{(2)}_1 = h_1 \cdot \delta^{(2)} \approx 0.599 \cdot (-0.758) = -0.454$
- $\partial L/\partial w^{(2)}_2 = h_2 \cdot \delta^{(2)} \approx 0.634 \cdot (-0.758) = -0.481$
- $\partial L/\partial W^{(1)}_{11} = x_1 \cdot \delta^{(1)}_1 = 1.0 \cdot (-0.109) = -0.109$
- $\partial L/\partial W^{(1)}_{12} = x_2 \cdot \delta^{(1)}_1 = 0.5 \cdot (-0.109) = -0.055$
- $\partial L/\partial W^{(1)}_{21} = x_1 \cdot \delta^{(1)}_2 = 1.0 \cdot 0.088 = 0.088$
- $\partial L/\partial W^{(1)}_{22} = x_2 \cdot \delta^{(1)}_2 = 0.5 \cdot 0.088 = 0.044$
Update rule
With learning rate $\eta = 0.1$, every weight steps opposite to its gradient:
$$\Delta W = -\eta \cdot \frac{\partial L}{\partial W}, \qquad W \leftarrow W + \Delta W$$Example: $w^{(2)}_1$ moves from $0.6$ to $0.6 - 0.1(-0.454) = 0.645$. The output weight grows because the network under-predicted and $h_1$ contributed positively. This is blame assignment in action.
Demo 1 — Click-Through Backprop Walkthrough
Step through one full forward/backward pass on the 2–2–1 network from the previous section. Each click advances one stage: signals light up, activations appear, then gradients reverse-flow with weight-update values.
Backprop Walkthrough
Vanishing & Exploding Gradients
Recall the gear-train analogy: chain-rule gradients are products of local derivatives. In a deep network with $L$ layers, the gradient at the bottom is roughly $$\frac{\partial L}{\partial W^{(1)}} \;\sim\; \prod_{\ell=2}^{L} W^{(\ell)} \cdot \sigma'(z^{(\ell)})$$ Two pathologies follow immediately.
Vanishing gradients
The sigmoid derivative $\sigma'(z) = \sigma(z)(1-\sigma(z))$ has a maximum of $0.25$ at $z = 0$. Multiply twenty of those together and you get $0.25^{20} \approx 10^{-12}$. The gradient that reaches the first layer is essentially noise — the early layers stop learning. This is precisely what crippled deep sigmoid networks before 2010.
Exploding gradients
The opposite: if the weight matrices have spectral norm $> 1$, the
product blows up exponentially. Updates become huge, training
diverges, and you see NaN in your loss. Recurrent
networks unrolled over long sequences are especially vulnerable.
Modern remedies (preview)
- ReLU activations — derivative is exactly $1$ on the active half, breaking the shrinkage.
- Careful initialisation — He / Xavier scaling keeps activations and gradients at unit variance through the depth.
- Batch normalisation — rescales pre-activations every layer so $\sigma'$ stays in its useful regime.
- Residual connections — ResNets add a "skip" that lets gradient bypass deep stacks entirely. The gradient highway.
- Gradient clipping — for exploding gradients, just cap the norm.
Demo 2 — Gradient Flow Visualizer
A 5-layer network animates forward (left→right) and backward (right→left) passes continuously. The bars on the right show the average gradient magnitude reaching each layer. Switch between activations and watch the "depth" of healthy learning change.
Gradient Flow Visualizer
You Don't Write Backprop — The Framework Does
Here is the practical good news: in PyTorch, TensorFlow, JAX or any modern framework, you never code the backward pass. You write only the forward computation. The framework records every operation you perform on a tracked tensor into a computational graph, then traverses it in reverse using known local derivatives. This is called automatic differentiation (autograd, autodiff).
The contrast with finite-difference numerical gradients is enormous. For $N$ parameters, finite differences need $O(N)$ forward passes; reverse-mode autograd needs one forward and one backward, independent of $N$. That is why training a billion-parameter model is even computationally conceivable.
import torch
# Tensors that track gradients
w1 = torch.tensor(0.5, requires_grad=True)
w2 = torch.tensor(-0.8, requires_grad=True)
x = torch.tensor(2.0)
y_true = torch.tensor(1.0)
# Forward — just write the math.
h = torch.sigmoid(w1 * x + 0.1)
y_hat = w2 * h + 0.2
loss = (y_hat - y_true) ** 2
# One line. Whole graph differentiated.
loss.backward()
print(w1.grad, w2.grad) # gradients filled in automatically
A Brief History of an Algorithm That Changed Everything
- 1960s — Kelley, Bryson, Dreyfus develop reverse-mode automatic differentiation in the optimal-control community. Nobody connects it to neural networks.
- 1974 — Paul Werbos's Harvard PhD thesis describes applying reverse-mode AD to multi-layer neural networks. It is largely overlooked.
- 1982 — Werbos publishes the result more broadly. Still no critical mass.
- 1986 — Rumelhart, Hinton & Williams publish Learning representations by back-propagating errors in Nature. This is the moment the field re-ignites.
- 1989 — LeCun applies backprop to convolutional networks for handwritten-digit recognition. Backprop graduates from theory to product.
- 2006–2012 — Layer-wise pre-training, ReLU, GPUs, and large datasets together unlock deep networks. Backprop scales.
- 2015–present — Autograd frameworks make backprop invisible. Every transformer, diffusion model, and protein folder you read about is, under the hood, the same chain-rule sweep.
Civil Engineering Application
Structural Load Redistribution
Backpropagation is the AI equivalent of load redistribution in indeterminate structures. When an output error is detected, the "blame" flows backward through connections — just as an overloaded beam redistributes moment to adjacent supports. Each weight update is calibrated by the chain rule, ensuring proportional correction.
Sensitivity Analysis
Gradients from backprop reveal which input features most affect the output — a built-in sensitivity analysis. For concrete strength prediction, backprop gradients show that w/c ratio has 3× the influence of aggregate type, matching classical Abrams' law insights.
Check Your Understanding
Key Takeaways
- Backpropagation solves the credit-assignment problem by recursively applying the chain rule along a computational graph.
- Forward pass computes activations left-to-right; backward pass computes gradients right-to-left, using local derivatives stored along the way.
- For any weight, $\partial L/\partial W_{ij} = a_i \cdot \delta_j$, and the update is $\Delta W = -\eta \cdot a_i \cdot \delta_j$.
- Vanishing/exploding gradients are a direct consequence of multiplying many local derivatives — deep networks need ReLU, good init, BatchNorm, or skip connections to stay healthy.
- Modern frameworks compute backprop automatically (autograd). You write the forward; the chain rule is free.
- Just like tracing failure responsibility through a load path, backprop assigns blame proportional to each weight's sensitivity coefficient — its partial derivative.
Train a hand-rolled MLP with real backprop
The MLP classifier in the lab implements full forward + backward passes from scratch — every weight update is the chain rule from this lesson, computed live in your browser.