Backpropagation › The Chain Rule: Foundation of Backpropagation

Michael BrenndoerferMay 6, 20253 min read
Language AI HandbookAll chapters
Part 10 of 67Neural Network Foundations
Chapter 65Backpropagation › The Chain Rule: Foundation of Backpropagation
Reading section 4 of 20 · The Chain Rule: Foundation of Backpropagation · 3 minSection 4 of 20 · 3 min

Book contents

Section 4 of 20 · 3 min read

Backpropagation › The Chain Rule: Foundation of BackpropagationOne section · Sections in this chapter4 / 20 ↓
Reading tools Definitions & inline links

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

The chain rule from calculus is the mathematical engine powering backpropagation. It tells us how to differentiate composed functions, and since a neural network is one giant composition of functions, the chain rule is precisely what we need.

Single Variable Chain Rule

Let u=g(x)u = g(x) and y=f(u)=f(g(x))y = f(u) = f(g(x)). The chain rule states:

dydx=dydu⋅dudx\frac{dy}{dx} = \frac{dy}{du} \cdot \frac{du}{dx}

where:

  • dydx\frac{dy}{dx}: the total derivative of the final output with respect to the original input
  • dydu\frac{dy}{du}: the local gradient of the outer function ff at the intermediate value uu
  • dudx\frac{du}{dx}: the local gradient of the inner function gg at xx

The intuition is multiplicative sensitivity: if xx changes by a small amount δx\delta x, it causes uu to change by dudx⋅δx\frac{du}{dx} \cdot \delta x, which in turn causes yy to change by dydu⋅dudx⋅δx\frac{dy}{du} \cdot \frac{du}{dx} \cdot \delta x. The total sensitivity is the product of each stage's sensitivity.

Think of it as a chain of dominoes. A small push on the first domino (δx\delta x) gets amplified or attenuated at each stage. The chain rule tells us the total amplification from one end of the chain to the other, which is just the product of each stage's individual amplification. This multiplicative structure is central to understanding both why backpropagation works and why deep networks can suffer from vanishing or exploding gradients.

Extending to Three or More Functions

For a chain of three functions y=f(g(h(x)))y = f(g(h(x))), the chain rule extends naturally:

dydx=dydf⋅dfdg⋅dgdx\frac{dy}{dx} = \frac{dy}{df} \cdot \frac{df}{dg} \cdot \frac{dg}{dx}

This pattern extends to any depth. For a network with nn layers, the gradient of the loss with respect to the first layer's weights involves multiplying nn local gradients together. This is why deep networks can suffer from vanishing or exploding gradients: if each local gradient is slightly less than 1, their product shrinks exponentially; if each is slightly greater than 1, the product explodes.

Concretely, suppose we have a 20-layer network and the average gradient magnitude at each layer is 0.9. The gradient at the first layer would be multiplied by 0.920≈0.120.9^{20} \approx 0.12, reducing it to about 12% of the output gradient. That might seem manageable, but with 50 layers and an average gradient of 0.7, we get 0.750≈1.3×10−80.7^{50} \approx 1.3 \times 10^{-8}: essentially zero. The first layers of the network would receive essentially no learning signal.

Multivariate Chain Rule

Neural networks work with vectors and matrices, so we need the multivariate form. If z=f(y)\mathbf{z} = \mathbf{f}(\mathbf{y}) and y=g(x)\mathbf{y} = \mathbf{g}(\mathbf{x}), the chain rule becomes:

∂zi∂xk=∑j∂zi∂yj⋅∂yj∂xk\frac{\partial z_i}{\partial x_k} = \sum_j \frac{\partial z_i}{\partial y_j} \cdot \frac{\partial y_j}{\partial x_k}

where:

  • ∂zi∂xk\frac{\partial z_i}{\partial x_k}: the partial derivative of the ii-th output component with respect to the kk-th input component
  • ∂zi∂yj\frac{\partial z_i}{\partial y_j}: the partial derivative of ziz_i with respect to the jj-th intermediate variable
  • ∂yj∂xk\frac{\partial y_j}{\partial x_k}: the partial derivative of yjy_j with respect to the kk-th input

In matrix form, this is exactly a matrix product: if Jf\mathbf{J}_f and Jg\mathbf{J}_g are the Jacobian matrices of ff and gg respectively, then the Jacobian of the composition is:

Jf∘g=Jf⋅Jg\mathbf{J}_{f \circ g} = \mathbf{J}_f \cdot \mathbf{J}_g

This matrix multiplication is the vectorized form of the chain rule, and it is what makes backpropagation efficient. The sum over jj in the scalar form becomes a dot product, and repeating it for all (i,k)(i, k) pairs gives a matrix product. Gradient computation can therefore be done with the same fast matrix operations that power the forward pass.