The gradient: the vector that every optimization follows — downhill, hopefully.
Fundamentals 13 min Intermediate May 11, 2026
The previous article gave you a superpower: the derivative tells you whether nudging ONE weight makes the error go up or down. But a real neural network has millions of weights — not just one. How do you figure out which of those million knobs to turn, and in which direction?
You need two new tools: Partial derivatives isolate the effect of each weight independently. The gradient bundles all of this information into a single vector — a compass that points toward the steepest slope. Following this compass in reverse is the engine behind every AI training step on the planet.
The Multidimensional Landscape — From Curve to Terrain
In the previous article, the loss function L(w) was a curve — one dimension, two directions: forward or backward. Now let us raise the scope: what happens when the loss depends on two, three, or millions of variables?
Loss Landscape
AnalogyDefinition
In the previous article, you stood on a road with only two choices: forward or backward. Now you stand on a mountain. There are infinitely many directions to walk — and each has a different steepness. The question becomes: which direction goes downhill fastest?
Example
A real mountain is 3D (2 spatial dimensions + height). A neural network's loss landscape has millions of dimensions. Also, on a mountain you can see the terrain — during training you are blind (hiking in fog), knowing only the local steepness under your feet.
Analogy:
In the previous article, you stood on a road with only two choices: forward or backward. Now you stand on a mountain. There are infinitely many directions to walk — and each has a different steepness. The question becomes: which direction goes downhill fastest?
Example
A real mountain is 3D (2 spatial dimensions + height). A neural network's loss landscape has millions of dimensions. Also, on a mountain you can see the terrain — during training you are blind (hiking in fog), knowing only the local steepness under your feet.
Definition:
A function f(x) of one variable draws a curve. A function f(x, y) of two variables draws a surface (a terrain). Neural networks have loss functions L(w₁, w₂, ..., wₙ) with millions or billions of variables — this creates a loss landscape in a space with as many dimensions as there are parameters. The mathematical principles (slope, minima, saddle points) work identically in any number of dimensions.
Consider the simple bowl function f(x, y) = x² + y²:
Bowl Function
f(x, y) = x² + y²
At point (3, 4): f = 9 + 16 = 25. Slope in x-direction: ∂f/∂x = 2·3 = 6. Slope in y-direction: ∂f/∂y = 2·4 = 8. Two numbers instead of one — that is the jump from 1D to 2D. At real scale: GPT-4 reportedly has ~1.8 trillion parameters (Mixture-of-Experts, 16 expert networks of ~111 billion parameters each, 2 active per forward pass). Its loss landscape lives in a space with 1.8 trillion dimensions.
1.8T
Parameters (GPT-4 MoE): The loss landscape lives in 1.8 trillion dimensions
Every combination of weights (w₁, ..., wₙ) is a point in the loss landscape. Training means finding a deep valley in this landscape. The partial derivatives reveal the steepness in each direction — the gradient combines them into a single compass.
Misconception: The loss landscape is a 3D surface
The 3D mountain is an analogy. Real loss landscapes have millions to trillions of dimensions. Their topology is fundamentally different: saddle points vastly outnumber local minima (Dauphin et al. 2014). The 3D picture builds correct intuition about slopes and valleys, but not about the prevalence of saddle points.
Partial Derivatives — One Variable at a Time
You know how to differentiate a function of one variable. The new skill: differentiating a function of many variables by freezing all the others.
Partial Derivative
AnalogyDefinition
Imagine a mixing console. Each slider controls the volume of a different instrument: vocals, bass, guitar, drums. The partial derivative asks: if I ONLY move the bass slider and hold all others fixed — how does the overall sound change? This is a controlled experiment: isolate one factor.
Example
In the real world, instruments sometimes affect each other (a loud bass masks quiet guitar notes). In a neural network, weights are truly independent — you can change w₁₇ without mechanically affecting w₄₂.
Analogy:
Imagine a mixing console. Each slider controls the volume of a different instrument: vocals, bass, guitar, drums. The partial derivative asks: if I ONLY move the bass slider and hold all others fixed — how does the overall sound change? This is a controlled experiment: isolate one factor.
Example
In the real world, instruments sometimes affect each other (a loud bass masks quiet guitar notes). In a neural network, weights are truly independent — you can change w₁₇ without mechanically affecting w₄₂.
Definition:
The partial derivative of f(x₁, ..., xₙ) with respect to xᵢ measures how f changes when ONLY xᵢ varies and all other variables are held constant. Notation: the curly ∂ (\"partial d\") distinguishes it from the ordinary derivative d. Computing it is identical to computing an ordinary derivative — simply treat all other variables as constants.
Partial derivative with respect to x (for f(x,y) = x² + y²)
∂f/∂x = 2x
Partial derivative with respect to y (for f(x,y) = x² + y²)
∂f/∂y = 2y
Example: Linear Model with Two Weights
Prediction = w₁·x + w₂, with training point (x=2, y_true=7), current weights w₁=1, w₂=3. Prediction: 1·2 + 3 = 5. Loss: (5-7)² = 4. Partial derivative ∂L/∂w₁ = 2·(5-7)·2 = -8 (strongly negative: increasing w₁ decreases the loss significantly). ∂L/∂w₂ = 2·(5-7) = -4 (less negative: increasing w₂ helps less). Why the factor x=2 in ∂L/∂w₁? The loss depends on the prediction, and the prediction depends on w₁ through the product w₁·x. Every change in w₁ is amplified by x=2 — that is why x appears as a factor. (This nesting has a name — the chain rule — which the next article covers.)
∂L/∂w₁ = -8
High leverage: increasing w₁ strongly decreases the loss
∂L/∂w₂ = -4
Lower leverage: increasing w₂ helps less
Why does w₁ have more leverage? Because it is multiplied by the input x=2. A weight multiplied by a larger input value has more influence on the prediction — and thus on the loss.
Misconception: ∂f/∂wᵢ = 0 means wᵢ is optimal
∂f/∂wᵢ = 0 only means the landscape is flat in the wᵢ-direction at this point. It could still be steeply descending in some other direction. Only when ALL partial derivatives are simultaneously zero (gradient = zero vector) do you have a critical point — and even then it could be a saddle point.
During training, the partial derivative of the loss with respect to each weight tells the optimizer exactly how sensitive the loss is to that specific weight. Weights with large partial derivatives get larger updates; weights with near-zero partial derivatives barely change. This is how the network learns which connections matter most.
The Gradient — Your Compass in the Fog
You now have individual partial derivatives. The next step: assemble them all into a single vector — the gradient.
Gradient
AnalogyDefinition
Imagine a magic compass you carry in the fog on a mountainside. You cannot see the landscape, but the compass always points in the direction of steepest uphill. To descend into the valley (minimize loss), walk in the opposite direction. After each step, the compass recalibrates (the gradient changes with your position). The learning rate η is your step size: too large → you overshoot the valley; too small → you arrive eventually but painfully slowly.
Example
A real compass always points north (fixed). The gradient changes at every point. Also, a real hiker can see if they are in a small hollow and climb out. Gradient descent has no such global view — when the gradient is zero, it stops, whether at a valley, a hilltop, or a mountain pass (saddle point).
Analogy:
Imagine a magic compass you carry in the fog on a mountainside. You cannot see the landscape, but the compass always points in the direction of steepest uphill. To descend into the valley (minimize loss), walk in the opposite direction. After each step, the compass recalibrates (the gradient changes with your position). The learning rate η is your step size: too large → you overshoot the valley; too small → you arrive eventually but painfully slowly.
Example
A real compass always points north (fixed). The gradient changes at every point. Also, a real hiker can see if they are in a small hollow and climb out. Gradient descent has no such global view — when the gradient is zero, it stops, whether at a valley, a hilltop, or a mountain pass (saddle point).
Definition:
The gradient of f(x₁, ..., xₙ) is the vector of ALL partial derivatives: ∇f = (∂f/∂x₁, ..., ∂f/∂xₙ). Two key properties: (1) it points in the direction of steepest ascent. (2) Its magnitude |∇f| gives the rate of change in that direction. Proof sketch: the directional derivative Dᵤf = ∇f · u = |∇f| · cos(θ) is maximized when θ=0, i.e., when u is parallel to ∇f.
Gradient Vector
∇f = (∂f/∂x₁, ∂f/∂x₂, ..., ∂f/∂xₙ)
Gradient Descent Rule
wnew = wold − η · ∇L(w)
Gradient Descent in Action
For f(x, y) = x² + y², starting at (3, 4) with learning rate η = 0.1:
Step 2: (1.92, 2.56) ∇f = (3.84, 5.12), f = 10.24. Each coordinate shrinks by factor 0.8
4
After ~20 steps Position ≈ (0, 0), f ≈ 0. Gradient descent has found the minimum.
def f(x, y):
return x**2 + y**2
def grad_f(x, y):
return (2*x, 2*y)
x, y = 3.0, 4.0
lr = 0.1
for step in range(20):
gx, gy = grad_f(x, y)
x = x - lr * gx
y = y - lr * gy
if step % 5 == 0:
print(f"Step {step:2d}: ({x:.2f}, {y:.2f}) f={f(x,y):.2f}")
# Step 0: (2.40, 3.20) f=16.00
# Step 5: (0.79, 1.05) f=1.73
# Step 10: (0.26, 0.35) f=0.19
# Step 15: (0.08, 0.11) f=0.02
# -> converges to (0, 0), the minimum
1847
Cauchy: First gradient method for astronomical calculations
0?
Gradient = 0 does not mean minimum — it could be a saddle point!
1986
Rumelhart, Hinton & Williams: Backpropagation enables deep networks
Misconception: The gradient points downhill
Wrong! The gradient ∇f points in the direction of steepest ASCENT. For minimization, follow the NEGATIVE gradient. The update rule has an explicit minus sign: w_new = w - η · ∇L. Forgetting the minus sign means climbing uphill and maximizing the loss.
Cauchy described the steepest descent method in 1847 for astronomical calculations (Comptes rendus, vol. 25, pp. 536-538). In 1986, Rumelhart, Hinton and Williams showed how to compute the gradient of the loss through a multi-layer neural network efficiently — Backpropagation (Nature, vol. 323, pp. 533-536). Today, every training step of every neural network computes the gradient and follows it downhill.
Deep Dive: Saddle Points in High Dimensions
At a saddle point, the gradient is zero, but the point is neither a maximum nor a minimum — like a mountain pass that goes uphill in one direction and downhill in another. Dauphin et al. (2014, NIPS) showed: in high-dimensional loss landscapes, saddle points outnumber local minima exponentially. The more dimensions, the more likely a critical point (gradient = 0) is a saddle point. Practical consequence: gradient descent can slow down at saddle points because the gradient is near zero. Stochastic gradient descent (SGD) helps: the noise from mini-batches provides enough momentum to push past flat saddle points.
Deep Dive: Gradient Descent Variants
Plain gradient descent has weaknesses: it can get stuck in flat regions and is sensitive to the learning rate. Momentum adds a velocity term to the gradient — like a ball that does not stop immediately. Adam combines momentum with adaptive per-weight learning rates. RMSProp adjusts the learning rate based on recent gradient history. All of these methods use the gradient as their foundation — they only optimize how to follow it. Details in Path I.F (Optimization Methods).
Interactive: Explore Partial Derivatives
Click on individual terms to see what each part means. Switch between tabs to compare the derivative with respect to x and y — and follow the worked example step by step to see how the gradient emerges.
Partial derivative with respect to x
∂f∂x=2x
∂f/∂x
The partial derivative of f with respect to x: How much does f change when only x changes? y is treated as a constant.
Concrete Example
Given f(x, y) = x² + y²
Partial Derivatives ∂f/∂x = 2x (Differentiate with respect to x (y fixed)) , ∂f/∂y = 2y (Differentiate with respect to y (x fixed))
1At point (3,1): ∂f/∂x = 2 · 3 = 6 — steep slope in x-direction 2 · 3 = 6
2At point (3,1): ∂f/∂y = 2 · 1 = 2 — moderate slope in y-direction 2 · 1 = 2
When a function depends on many variables, each partial derivative isolates the effect of one variable while freezing all others. Computing partial derivatives uses the same rules from the previous article — the only new trick is treating other variables as constants.
The gradient vector bundles all partial derivatives into one object: it points in the direction of steepest ascent, and its magnitude tells you how steep. For minimization, follow the negative gradient.
Gradient Descent (w_new = w_old - η · ∇L) is the fundamental training loop. But gradient = 0 does not guarantee a minimum — it could be a saddle point. In high-dimensional neural networks, saddle points vastly outnumber true local minima.
Learning Goals
For f(x, y) = 3x² + y³ — what is ∂f/∂x? And ∂f/∂y?
The gradient at a point is (6, 8). In which direction should you go to minimize f?
Why is ∂L/∂w₃ = 0 not enough to say that w₃ is optimal?
Quiz: Partial Derivatives & The Gradient
Question 1 / 4
Not completed
For f(x, y) = x² + y² — what is the partial derivative ∂f/∂x at point (3, 4)?
1. For f(x, y) = x² + y² — what is the partial derivative ∂f/∂x at point (3, 4)?
☐ A) 8
☐ B) 6
☐ C) 10
☐ D) 25
2. A linear model has loss L(w₁, w₂). At the current weights: ∂L/∂w₁ = +5 and ∂L/∂w₂ = -2. Which statement is correct?
☐ A) Increasing w₁ decreases the loss
☐ B) Increasing w₂ increases the loss
☐ C) w₁ should be decreased and w₂ should be increased
☐ D) Both weights are already optimal
3. The gradient of f(x, y) = x² + y² at point (3, 4) is (6, 8). With learning rate η = 0.1 — where are you after one gradient descent step?
☐ A) (3.6, 4.8)
☐ B) (2.4, 3.2)
☐ C) (0.6, 0.8)
☐ D) (6, 8)
4. Gradient descent converges to a point where the gradient is zero, but the loss is not the global minimum. What is the most likely explanation?
☐ A) The learning rate was too small
☐ B) The algorithm found a saddle point or local minimum
☐ C) The partial derivatives were computed incorrectly