1. Walking downhill blindfolded
Put the mathematical symbols aside for a moment and imagine a situation.
You are blindfolded, standing alone on a rolling hillside. Your task is to reach the lowest point in a valley. You cannot see the distant terrain, and you do not know where the bottom is or how far away it lies. All you can rely on is what you feel under your feet: probe the ground around you to find which directions lead uphill, which lead downhill, and how steep they are.
How would you move? Most people think of the same approach:
- Feel around for the steepest local downhill direction.
- Take a small step in that direction.
- Stop, feel again, and take another step. Repeat.
This simple method captures the central idea behind training a neural network. You do not need a complete map to start making progress. In a smooth bowl, suitable small steps can approach the bottom. A more complicated landscape may have several valleys or flat points, so this local method does not promise to find the globally lowest point.
The next four sections translate “feel the slope under your feet” into mathematics a computer can calculate. We will meet the derivative, partial derivatives, the directional derivative, and finally the gradient.
2. The derivative: a curve's slope at one point
Start with the simplest possible view. Step far enough back to represent the mountain's profile as a function curve on a plane. The horizontal coordinate gives your position; gives the height there. The curve is a side view of the mountain.
Looking at the whole picture gives us a bird's-eye view: we can spot a valley and see which way to walk. The person standing on the mountain does not have that view. They know only their current position and can move a little left or right to feel whether the ground rises or falls.
The slope at that point translates this probing into mathematics:
- A positive slope means the curve rises as increases. Moving right is uphill; moving left is locally downhill.
- A negative slope means moving right is locally downhill.
The sign tells you the direction; the magnitude tells you how steep the slope is. The question becomes: how do we calculate a curve's slope at a particular point?
For a straight line, choose any two points and divide the vertical change by the horizontal change. That ratio is the same everywhere along the line. A curve bends, so there is no single slope that describes all its points. The mathematical tool for a curve's slope at one point is the derivative, written or .
Begin with two points on the curve. Stand at , move by a small non-zero amount , and arrive at . The corresponding height change is:
The straight line connecting these two points is a secant. Its slope is an average slope over that interval, not yet the exact slope at . A wider interval can give a poorer local approximation.
=
Secant =
Tangent slope = −6.00
Smaller distance ← · · → Larger distance
Now let shrink towards zero. The second point approaches the first and, when the derivative exists, the secant's slope approaches the slope of the tangent at . This gives the definition:
The function must be defined around . If this limit exists as a finite number, the function is differentiable at that point, and the limit is its derivative there. It can also be written . If the limit does not exist, the function is not differentiable there.
Notice the distinction: the derivative at a point is one number. If the function is differentiable throughout a region, assigning a slope to each position gives another function, the derivative function:
For example, is one number, while describes slopes across the whole curve. In everyday mathematical language, both may be called “the derivative”; the context tells you which is meant. We usually differentiate first, then substitute the position we need.
Let us apply the limit definition to a simple upward-opening parabola with just one minimum:
Its lowest point is at . Without using a ready-made differentiation rule, expand the difference quotient:
At , substitute that position into the derivative function:
The sign is negative: increasing lowers the height locally. The magnitude is : the slope is fairly steep. One number describes the local downhill behaviour. Move against the derivative: to the right when it is negative, or to the left when it is positive. This concerns the local slope; a large step can still overshoot.
3. Partial derivatives: the mountain is two-dimensional
A path that only lets you move east or west is an idealisation. On a real hillside you can move across a two-dimensional ground plane: east–west along and north–south along . Height depends on both coordinates, so write it as .
Consider this surface:
It is an upward-opening bowl. The bottom is the minimum; moving towards the edges increases the height. Rotate the surface below to see it from different angles.
Drag to rotate the surface, or use these controls.
How can we measure its slope? A natural approach is to measure twice:
- Keep your north–south coordinate fixed and move a little east or west.
- Keep your east–west coordinate fixed and move a little north or south.
A slope measured by varying just one coordinate while holding the others fixed is a partial derivative. We use , rather than the single-variable :
When differentiating with respect to , treat as a constant. For the bowl:
Suppose you are at . Substituting gives:
The east–west derivative is negative, so moving east is downhill. The north–south derivative is positive, so moving north is uphill and moving south is downhill.
We now have two numbers. But our real question is not only the slope along each axis: what is the slope in any chosen direction, and which direction is steepest?
4. The directional derivative: any direction you choose
You need not restrict yourself to due east or due south. You might probe a direction such as south of east. The slope along a specified direction is its directional derivative.
You do not have to measure every direction independently. For a differentiable function, the partial derivatives determine the slope in every direction. Express the direction as a unit vector , with . Then:
That expression is the dot product from Lesson 2. Package the two partial derivatives as a vector and take its dot product with :
Recall the geometric interpretation:
Because has unit length, the directional derivative is a signed projection of the slope vector onto that direction. At , that vector is . Try several directions:
| Direction | Unit vector | Slope |
|---|---|---|
| East | ||
| South | ||
| Southeast | ||
| Northwest |
Due east and due south each give a slope of . The southeast unit direction combines them and gives , a faster decrease per unit distance. Normalisation matters: comparing arbitrary vectors of different lengths would mix direction with step size.
The longest positive projection occurs when the direction matches the slope vector. That is the steepest uphill direction. The most negative projection occurs in the opposite direction: steepest downhill.
5. The gradient: steepest ascent as a vector
The slope vector we have been using has a formal name: the gradient, written and pronounced “nabla h”:
This is not a new calculation: it packages the partial derivatives into one vector. The previous section gives it two useful geometric meanings:
- Direction: a non-zero gradient points towards the fastest local increase.
- Magnitude: is the maximum directional derivative over unit directions.
At , points northwest, the fastest uphill direction. To descend, move the other way: , towards the southeast. The blindfolded walk becomes an update rule:
Here denotes the whole position vector, not just the horizontal coordinate. The minus sign means “against the gradient”. The positive number controls the step size; in machine learning it is called the learning rate. Repeating this update is gradient descent.
The gradient answers “which direction is steepest here?” in one calculation. You do not need to probe every direction separately. However, “steepest” is a local, first-order description: the learning rate affects whether the next finite step actually lowers the height. An overly large step can overshoot or diverge.
For this particular bowl, a step with multiplies the displacement from the minimum by each time, so the plotted points approach . More complicated functions may have local minima, maxima or saddle points. A zero gradient indicates a stationary point, not a guarantee of the best possible solution.
6. From hillsides to neural networks
Return to AI. Training a neural network resembles the blindfolded walk with different names:
- Height becomes the model's loss: how wrong its predictions are.
- Position becomes the collection of model parameters.
- Steepest downhill direction becomes the negative loss gradient.
A hillside has two ground coordinates, and . A large model can have billions of parameters . Each parameter has a partial derivative of the loss. Package all of them into a gradient and update them together:
One update changes all the parameters using the local sensitivities of the loss. Suitable steps aim to reduce the loss. Questions about getting stuck, choosing a learning rate and calculating so many derivatives efficiently will return in Gradient descent and optimisers (Lesson 12) and Backpropagation (Lesson 13).
The takeaway. A derivative measures local slope in one dimension. Partial derivatives measure it one coordinate at a time. A directional derivative gives the slope in any unit direction through a dot product. The gradient packages the partial derivatives into the direction of steepest local ascent. Updating parameters against it, , is a central mechanism of neural network training.
The concepts you have built step by step:
- Derivative: gives the exact slope at a point; its sign gives direction and its magnitude gives steepness.
- Partial derivative: measures sensitivity to one coordinate while keeping the others fixed.
- Directional derivative: measures the slope in a specified unit direction.
- Gradient: collects all partial derivatives. It points uphill; its negative points downhill.
- Gradient descent: updates every parameter using that local information.
Check your understanding
Choose an answer and select “Submit answer” to see the correct option and an explanation.