Step 4 of 29 · Module 2: Math Foundations
Derivatives, Gradients, and the Chain Rule
The previous lesson covered what a model's numbers are — vectors and matrices. This one covers how those numbers change during training. Every time you've read "training nudges the parameters a tiny amount," this lesson is what's actually being described.
The one question calculus answers here
Training a model comes down to one repeated question: if I move this number up slightly, does the model's error go up or down, and by how much? Answer that question for every one of a model's billions of parameters, and you know exactly which direction to move each one to make the model slightly better. That question — "how much does output change per tiny change in input" — is precisely what a derivative measures.
What a derivative actually is
The of a function at a point is its slope there — how steeply it's rising or falling. Take the simplest useful example:
At x = 3, f'(3) = 6 — meaning near that point, a tiny increase in x produces roughly six times as large an increase in f(x). That number, the derivative, is the entire signal a model uses to decide which way to adjust a parameter.
A gradient is just many derivatives at once
A real model doesn't have one input — it has billions of parameters, all affecting the output simultaneously. A is simply the derivative computed with respect to every one of those parameters at once, collected into one giant vector. Each entry answers the same question as before — "if I nudge just this one parameter, how does the error change?" — for one specific parameter, holding all the others fixed.
The gradient, as a whole vector, points in the direction that increases the model's error the most. Which is useful precisely because it tells you the opposite direction — the one that decreases error the fastest. More on that in the next lesson.
The chain rule — why backpropagation works at all
A transformer isn't one function — it's dozens of layers, each one a function of the previous layer's output. The is what makes it possible to compute a derivative through that entire stack: the derivative of a chain of functions is the product of each function's own derivative.
Why this is the whole training process
Put the two ideas together and you have the complete picture: the chain rule lets a model compute the gradient — how the error responds to every single parameter, however deep in the network that parameter sits — in one backward pass. The next lesson, on gradient descent, covers what happens once you have that gradient: you use it to actually move the parameters.
Quick knowledge check
1. What does a derivative measure?
2. What is a gradient, in relation to a derivative?
3. Why does the chain rule matter for training deep networks?
Spot something wrong, outdated, or confusing?
Suggest an edit