Backpropagation › The Chain Rule: Foundation of Backpropagation
Language AI HandbookAll chapters 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 and . The chain rule states:
where:
- : the total derivative of the final output with respect to the original input
- : the local gradient of the outer function at the intermediate value
- : the local gradient of the inner function at
The intuition is multiplicative sensitivity: if changes by a small amount , it causes to change by , which in turn causes to change by . 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 () 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 , the chain rule extends naturally:
This pattern extends to any depth. For a network with layers, the gradient of the loss with respect to the first layer's weights involves multiplying 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 , 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 : 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 and , the chain rule becomes:
where:
- : the partial derivative of the -th output component with respect to the -th input component
- : the partial derivative of with respect to the -th intermediate variable
- : the partial derivative of with respect to the -th input
In matrix form, this is exactly a matrix product: if and are the Jacobian matrices of and respectively, then the Jacobian of the composition is:
This matrix multiplication is the vectorized form of the chain rule, and it is what makes backpropagation efficient. The sum over in the scalar form becomes a dot product, and repeating it for all pairs gives a matrix product. Gradient computation can therefore be done with the same fast matrix operations that power the forward pass.