Partial Derivatives & The Gradient
The gradient: the vector that every optimization follows — downhill, hopefully.
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
Example
Definition
Consider the simple 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 (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
Example
Definition
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.)
High leverage: increasing w₁ strongly decreases the loss
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
Example
Definition
Gradient Descent in Action
For f(x, y) = x² + y², starting at (3, 4) with learning rate η = 0.1:
- 1. Start:∇f = (6, 8), f = 25. Step: (3, 4) - 0.1·(6, 8) = (2.4, 3.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. Step 2:∇f = (3.84, 5.12), f = 10.24. Each coordinate shrinks by factor 0.8
- 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 minimumCauchy: 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
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))
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
For f(x, y) = x² + y² — what is the partial derivative ∂f/∂x at point (3, 4)?
Select one answer
1. For f(x, y) = x² + y² — what is the partial derivative ∂f/∂x at point (3, 4)?
2. A linear model has loss L(w₁, w₂). At the current weights: ∂L/∂w₁ = +5 and ∂L/∂w₂ = -2. Which statement is correct?
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?
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?