The Chain Rule
A model's error is never a simple function of a weight. The weight makes a prediction, the prediction makes an error, and the error gets squared. That is a chain of functions, and the chain rule is how you differentiate through it. Backpropagation, the method that trains every neural network, is this one rule used over and over.
The rule
Outside derivative times inside derivative; multiply along the chain.
Use the simplest rent model: predicted rent , where is size in tens of square metres. For flat B, and the true rent is 22, so the squared-error loss is
Break it into links:
- Inside: , the prediction error. Its slope is .
- Outside: . Its slope is .
Multiply: .
At : the prediction is 18, so and . The slope is negative, so increasing lowers the loss. That makes sense: 18 is below 22, so the weight is too small.
Longer chains work the same way. A neural network might compute , then , then . Then : one factor per link. Backpropagation computes these factors from the loss backwards, layer by layer, and reuses each product for the layer below, which is why it is fast.
The shortcut
Name each link, write its local slope, multiply. Each link only needs its own small derivative; you never differentiate the whole expression at once.
Name the links
u = 6w − 22, and L = u².
The classic mistake is stopping at the outside derivative and writing . That forgets the inside slope of 6, and the answer is six times too small.
Drills
Answer fast — trust the rule.
What is the derivative of (3w + 1)² with respect to w?
For L(w) = (6w − 22)², what is dL/dw at w = 4?
At w = 3 the slope dL/dw is −48. Which way should training move w?
If dy/du = 5 and du/dw = −2, what is dy/dw?
What is backpropagation?
Remember
- Outside derivative times inside derivative; multiply along the chain.
- Shortcut: name each link, write its local slope, multiply.
- Trap: forgetting the inside slope.
