Back to Learning Area

Partial Derivatives & The Gradient

The gradient: the vector that every optimization follows — downhill, hopefully.

  • Fundamentals
  • 13 min
  • Intermediate

Plain Language

This preview is in Plain Language. The whole portal is also available in Plain Language. You can change the language at the top. Or use the button below. Our Plain Language texts are AI-assisted and editorially reviewed. They follow the core principles of easy-to-read language, but they are not certified Easy Read: a review panel of people with learning difficulties does not test them.

Preview: How AI improves many weights

What are partial derivatives?

A neural network has many settings. We call them weights. Partial derivative means: you measure the effect of one weight. This way, you know which weight you should change.

The gradient: the compass

The gradient summarizes all partial derivatives. Gradient means: a directional indication for all weights. It shows where it goes uphill. Training goes in the opposite direction. This is how the error becomes smaller.

Why this is important

Every training step of an AI uses the gradient. The model improves step by step. This is how an AI learns with millions of weights. This is called gradient descent. Gradient descent means: following the slope.

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 practically every neural network training step.

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?

Definition

Loss Landscape

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.

Consider the simple bowl function f(x, y) = x² + y²:

f(x, y) = x² + y²
Bowl Function

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 (OpenAI, 2023) 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.

Parameters (GPT-4 MoE, estimated): The loss landscape lives in 1.8 trillion dimensions

1.8 T

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.

Caution

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.

Definition

Partial Derivative

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₄₂. Their effects on the loss, however, depend on each other: when w₁₇ changes, ∂L/∂w₄₂ usually changes too.
∂f/∂x = 2x
Partial derivative with respect to x (for f(x,y) = x² + y²)
∂f/∂y = 2y
Partial derivative with respect to y (for f(x,y) = x² + y²)

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.

Caution

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 way, the biggest corrections go where the loss is currently most sensitive.

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.

Definition

Gradient

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).
∇f = (∂f/∂x₁, ∂f/∂x₂, ..., ∂f/∂xₙ)
Gradient Vector
wnew = wold − η · ∇L(w)
Gradient Descent Rule

Gradient Descent in Action

For f(x, y) = x² + y², starting at (3, 4) with learning rate η = 0.1:

  1. 1. Start:∇f = (6, 8), f = 25. Step: (3, 4) - 0.1·(6, 8) = (2.4, 3.2)
  2. 2. Step 1:∇f = (4.8, 6.4), f = 16. Step: (2.4, 3.2) - 0.1·(4.8, 6.4) = (1.92, 2.56)
  3. 3. Step 2:∇f = (3.84, 5.12), f = 10.24. Each coordinate shrinks by factor 0.8
  4. 4. After ~20 stepsPosition ≈ (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.72
# Step 10: (0.26, 0.34)  f=0.18
# Step 15: (0.08, 0.11)  f=0.02
# -> converges to (0, 0), the minimum

Cauchy: First gradient method for astronomical calculations

1847

Gradient = 0 does not mean minimum — it could be a saddle point!

0 ?

Rumelhart, Hinton & Williams: Backpropagation makes multi-layer networks trainable

1986

Caution

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 made widely known how to compute the gradient of the loss through a multi-layer neural network efficiently — Backpropagation (Nature, vol. 323, pp. 533-536); Seppo Linnainmaa (1970) and Paul Werbos had laid the groundwork earlier. Today, practically every training step of a neural network computes the gradient and follows it downhill.

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) argued, based on results for random high-dimensional functions and experiments on networks: 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 often helps it get away from saddle points (though not reliably: Dauphin et al. observed that SGD can get stuck there too).

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 the article "The Path to the Valley: Gradient Descent" in the "Deep Learning" path.

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∂x2x
∂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
3The gradient combines both: ∇f(3,1) = (6, 2) — points uphill ∇f(3,1) = (6, 2)

Note

Key Takeaways

  • 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.

Check

Learning Goals

Can you explain this in your own words? Tick what you've got.

0 of 3 done

Check

Quiz: Partial Derivatives & The Gradient

Not completed

For f(x, y) = x² + y² — what is the partial derivative ∂f/∂x at point (3, 4)?

Select one answer

Answer Key: 1) B · 2) C · 3) B · 4) B