Calc21 Atlas
Backpropagation and the Chain Rule
Every time a neural network "learns", it is running a first-year calculus rule millions of times over. Modern AI is built on the chain rule.
The idea
A neural network is a long chain of simple functions: multiply by weights, add a bias, squash through a nonlinear function, repeat. At the end, a cost measures how wrong the output is.
To improve, the network needs to know how sensitive the cost is to each weight. That is a partial derivative. Because the weight affects the cost only through a chain of intermediate steps, the derivative is a product of local rates of change:
$$\frac{\partial C}{\partial w} = \frac{\partial z}{\partial w}\cdot\frac{\partial a}{\partial z}\cdot\frac{\partial C}{\partial a}$$
(weight → weighted sum z → activation a → cost C). That is the chain rule from a calculus course, written for one link in the chain.
Backpropagation is the bookkeeping trick. It starts at the output and works backward, reusing each computed rate for the layer before. Collect all those partial derivatives and you have the gradient. Then gradient descent nudges every weight a little way downhill, and the process repeats.
Worth noticing
- Errors drive learning. The output-layer derivative is proportional to the gap between the actual and the desired output, so big mistakes produce big corrections.
- Many paths add up. A neuron deep in the network affects the cost through many routes. The chain rule sums over all of them.
- Nobody does this by hand. Software libraries compute these derivatives automatically (automatic differentiation). The calculus is still the engine.
Go deeper
- Backpropagation calculus, 3Blue1Brown (Grant Sanderson): the chain-rule version, built up from a one-neuron-per-layer network. Free video and text.
Next stop
- Grant Sanderson: the explainer behind that lesson
- Calculus and AI: what happens when AI is asked to do calculus
- Glossary
- Applications
Next
Read next
Your phone solves a calculus problem to find you
Your phone turns four satellite signals into a blue dot, using Newton's method and a correction for relativity.
Join free
Get the best new stories
An occasional email when there is a piece worth your time. Free, one click to leave.
One email address is all we ask for. We never sell or share it.
Advertisement
MasterMathMentor.com
Free course material for high-school math teachers.