2.6 — Backprop, part 2: the recursion δ⁽ℓ⁾ = (W⁽ℓ⁺¹⁾)ᵀ δ⁽ℓ⁺¹⁾ ⊙ g'(z⁽ℓ⁾)
Goal: Derive the recursion that propagates the delta variable backwards through the network.
1. Why this session exists
Once we have δ(L)=y^−y at the output (2.5), we need a way to push that gradient signal backwards — to δ(L−1), then δ(L−2), all the way to δ(1). The chain rule from 0.3 gives us one recursion, with two factors at each step: a matrix multiply by W(ℓ+1) and an elementwise multiply by g′(ℓ)(z(ℓ)). This session derives it.
The loss L depends on z(ℓ) only through z(ℓ+1) (via a(ℓ)). By the chain rule,
∂z(ℓ)∂L=∂z(ℓ+1)∂L⋅∂a(ℓ)∂z(ℓ+1)⋅∂z(ℓ)∂a(ℓ).
Each Jacobian factor is easy.
3. Each factor in turn
∂z(ℓ+1)/∂a(ℓ)=W(ℓ+1). Direct from the affine forward z(ℓ+1)=W(ℓ+1)a(ℓ)+b(ℓ+1). In the numerator convention this Jacobian is the dℓ+1×dℓ matrix W(ℓ+1) itself.
∂a(ℓ)/∂z(ℓ)=diag(g′(ℓ)(z(ℓ))). The activation g(ℓ) is applied elementwise, so each ai(ℓ) depends only on zi(ℓ). The Jacobian is diagonal with i-th entry g′(zi(ℓ)).
∂L/∂z(ℓ+1)=(δ(ℓ+1))⊤ by definition of the next-layer delta — written as a row in the numerator convention.
4. Putting it together
Substituting,
(δ(ℓ))⊤=(δ(ℓ+1))⊤⋅W(ℓ+1)⋅diag(g′(ℓ)(z(ℓ))).
Transpose both sides to get a column:
δ(ℓ)=diag(g′(ℓ)(z(ℓ)))⋅(W(ℓ+1))⊤⋅δ(ℓ+1).
Multiplying a vector by diag(g′(z)) is elementwise multiplication by g′(z). So
δ(ℓ)=((W(ℓ+1))⊤δ(ℓ+1))⊙g′(ℓ)(z(ℓ))∈Rdℓ.
This is the backprop recursion. Two factors per step:
Matrix-multiply step. Multiply δ(ℓ+1)∈Rdℓ+1 by (W(ℓ+1))⊤∈Rdℓ×dℓ+1. This "spreads" the gradient signal across layer-ℓ units in proportion to how strongly each contributed to layer ℓ+1. Cost Θ(dℓdℓ+1) multiply-adds.
Activation step. Elementwise multiply by g′(ℓ)(z(ℓ))∈Rdℓ. This "scales" the gradient by how responsive each unit was at its current operating point. Cost Θ(dℓ) multiplies.
Total cost per backward step: dominated by the matmul — same order as the forward.
5. Sanity check: dimensions
W(ℓ+1) is dℓ+1×dℓ, so (W(ℓ+1))⊤ is dℓ×dℓ+1.
δ(ℓ+1) is dℓ+1, so (W(ℓ+1))⊤δ(ℓ+1) is dℓ ✓.
g′(ℓ)(z(ℓ)) is dℓ, so the Hadamard product is dℓ ✓.
δ(ℓ) is dℓ ✓.
6. Batched form
Define Δ(ℓ)∈RB×dℓ (rows = examples). The recursion becomes
Δ(ℓ)=(Δ(ℓ+1)W(ℓ+1))⊙g′(ℓ)(Z(ℓ))∈RB×dℓ.
Worked dimensions:
Δ(ℓ+1) is B×dℓ+1.
W(ℓ+1) is dℓ+1×dℓ.
Δ(ℓ+1)W(ℓ+1) is B×dℓ ✓.
g′(Z(ℓ)) is B×dℓ ✓.
Hadamard product is B×dℓ ✓.
The single-example form has (W(ℓ+1))⊤δ, but the batched row-major form has ΔW(ℓ+1) without a transpose — this is the row-vs-column distinction. Keep one convention and stick to it.
7. Why this is efficient
The forward pass at layer ℓ does one matrix-multiply AW⊤ of cost Θ(Bdℓdℓ−1).
The backward pass at layer ℓ does one matrix-multiply ΔW of cost Θ(Bdℓdℓ+1) plus one elementwise op of cost Θ(Bdℓ).
Backward = forward in cost. This is the fundamental reason gradient descent on deep nets is practical: the price of one gradient computation is one extra forward-pass-equivalent of FLOPs. Forward + backward + parameter update ≈ 3× one forward pass. Without the trick — say, computing ∂L/∂θ via N finite-difference forward passes — we'd be paying N× forward. For N∼109 parameters, that is the difference between hours and millennia.
8. Takeaways
δ(ℓ)=((W(ℓ+1))⊤δ(ℓ+1))⊙g′(ℓ)(z(ℓ)) — the central recursion.
Batched: Δ(ℓ)=(Δ(ℓ+1)W(ℓ+1))⊙g′(Z(ℓ)).
Cost per layer = one matmul, same scale as the forward pass.
This is why deep learning is computationally feasible.
Self-test
(a) Derive the recursion line by line from the chain rule on z(ℓ)→a(ℓ)→z(ℓ+1). Check each Jacobian shape.
(b) For an MLP with widths (d0,d1,d2,d3)=(10,64,64,3) and ReLU activations, compute δ(2) given δ(3), W(3), and z(2). Write out shapes at every step.
(c) Explain in words why g′(z(ℓ)) being small (sigmoid saturation, say) attenuates δ(ℓ) and what that means for the trainability of deep sigmoid networks. (Foreshadow of 2.9.)
(d) Suppose layer ℓ+1 uses the identity activation. Show that g′(z(ℓ)) still appears, but g′(ℓ+1)(z(ℓ+1))=1 disappears one step down the chain. What does this say about the role of nonlinearities in shaping gradient flow?