Skip to content
AI360XpertBeta
Core ML

Visual explainer

Gradient Descent

Follow computed parameter updates, compare learning rates, and see why a downhill direction can still produce a worse finite step.

A parameter value selects a point on the loss curve.
A parameter value selects a point on the loss curve.

Gradient descent changes parameters by subtracting a learning rate times the loss gradient. The direction is local; whether a finite step helps depends on its size and the objective.

Our synthetic objective is L(w)=w2L(w)=w^2. At parameter w=2w=2, loss is 4. Horizontal position is the parameter; vertical height is loss. The full curve is shown so we can check the result. An optimizer need not know the whole curve before computing a local update. The gradient-descent chapter in Dive into Deep Learning derives the method and discusses learning-rate failures.

Read The Local Slope

At w = 2 the loss has positive slope 4.
At w = 2 the loss has positive slope 4.

The derivative is L′(w)=2wL'(w)=2w, so at 2 it is +4+4. The dashed tangent is Ltangent=4w−4L_{\mathrm{tangent}}=4w-4 and touches the curve at (2,4)(2,4). Increasing ww locally increases loss; a small movement toward smaller ww decreases it.

The tangent's screen angle also depends on axis scaling. A derivative of 4 is loss units per parameter unit, not a four-pixel rise. At a stationary point the gradient is zero and supplies no nonzero direction.

Subtract A Scaled Gradient

Subtracting the gradient times 0.25 moves w from 2 to 1.
Subtracting the gradient times 0.25 moves w from 2 to 1.

The update is wnext=w−ηL′(w)w_{\mathrm{next}}=w-\eta L'(w). With illustrative learning rate η=0.25\eta=0.25, it gives 2−0.25(4)=12-0.25(4)=1. The circle marks the old parameter and the diamond the next one; the bracket measures a displacement of magnitude 1. This is a parameter numberline, rather than another loss-height plot.

Evaluate the objective again: loss changes from 22=42^2=4 to 12=11^2=1. The displacement is 1, while the loss reduction is 3. They are different quantities.

Repeat The Update

On this quadratic each update halves the remaining parameter.
On this quadratic each update halves the remaining parameter.

For this objective and this learning rate, wnext=(1−2η)w=w/2w_{\mathrm{next}}=(1-2\eta)w=w/2. The three aligned numberlines show 2→12\to1, 1→0.51\to0.5 and 0.5→0.250.5\to0.25. Circles mark starting values, diamonds mark endpoints, and highlighted intervals measure step magnitudes 1, 0.5 and 0.25. All rows use the same scale.

The shrinking intervals follow this recurrence. They are not a universal property of gradient descent. The iterates approach zero asymptotically in exact arithmetic; they do not reach it after these three updates.

Check Loss After Updating

Three updates reduce quadratic loss from 4 to 0.0625.
Three updates reduce quadratic loss from 4 to 0.0625.

There are four states including the initial one, but only three updates. At update indices 0, 1, 2 and 3, loss is 4,1,0.25,0.06254,1,0.25,0.0625. The bars retain the earlier zero-based loss scale. The last bar is truly tiny; its height is not enlarged for visibility.

This particular sequence reduces loss by a factor of 64. Its computed behavior does not guarantee the same reduction for a different model, objective or learning rate.

Compare Two Learning Rates

Changing the learning rate can turn contraction into an endless bounce.
Changing the learning rate can turn contraction into an endless bounce.

The vertical axis now shows parameter ww, and the horizontal axis counts updates. Starting at 2, η=0.25\eta=0.25 gives 2,1,0.5,0.252,1,0.5,0.25, marked by circles. Changing only the rate to 1 gives 2,−2,2,−22,-2,2,-2, marked by diamonds and a dashed trace. Both runs share the initial point. Joins only connect discrete iterates.

For L=w2L=w^2, convergence from a nonzero start requires ∣1−2η∣<1|1-2\eta|<1, or 0<η<10<\eta<1. Rates between 0.5 and 1 cross zero while their magnitudes shrink; oscillation does not always mean divergence. At η=1\eta=1, loss stays 4. These thresholds belong to this quadratic, so 0.25 is not a general starting recommendation.

Zero Slope Can Mislead

A flat region can stall descent above a lower loss.
A flat region can stall descent above a lower loss.

Change the objective explicitly to a differentiable plateau example: loss is 1 for w≤0w\le0, 1−3w2+2w31-3w^2+2w^3 for 0<w<10<w<1, and 0 for w≥1w\ge1. The middle derivative −6w+6w2-6w+6w^2 is zero at both joins. The drawing is an exact plot with a new vertical scale.

At w=−0.5w=-0.5, loss is 1 and its derivative is exactly zero. Vanilla gradient descent stays there for any finite learning rate, even though a lower plateau exists to the right. A zero-gradient check alone cannot distinguish this flat region from a desired solution. This constructed example demonstrates the limit, rather than predicting how often it happens in training.

Update Two Parameters

A two-parameter update moves against both gradient components.
A two-parameter update moves against both gradient components.

Now use L(a,b)=a2+2b2L(a,b)=a^2+2b^2. These are parameter-space contours: an ellipse labeled 6 contains points of loss 6, and the ellipse labeled 1 contains points of loss 1. Both axes use the same parameter scale. The origin is the shared center.

At start (2,1)(2,1), the gradient is (2a,4b)=(4,4)(2a,4b)=(4,4). Using η=0.25\eta=0.25 gives (2,1)−0.25(4,4)=(1,0)(2,1)-0.25(4,4)=(1,0), reducing loss from 6 to 1. The dotted component projections and diagonal arrow show the move. It crosses contours; it does not follow a path on a drawn loss-height surface. The negative gradient is the local steepest-descent direction in Euclidean parameter geometry.

Objective Scale Matters

Rescaling the objective changes the effective step size.
Rescaling the objective changes the effective step size.

Switch to a one-dimensional comparison at w=1w=1 and hold η=0.1\eta=0.1 fixed. For L=w2L=w^2, the gradient is 2 and the displacement is −0.2-0.2. For L~=10w2\widetilde L=10w^2, it is 20 and the displacement is −2-2. The shared ruler measures distance to the left from zero displacement; the two arrows use identical scales.

The minimizer stays at zero, but the second update jumps from 1 to −1-1 instead of 0.8. Multiplying an objective by a positive constant changes the effective learning rate for plain gradient descent. Reduction conventions and target units therefore matter when transferring a learning rate.

Where It Breaks

An oversized step can increase loss on every update.
An oversized step can increase loss on every update.

Return to L=w2L=w^2 and start w=2w=2, but set η=1.25\eta=1.25. The recurrence becomes wnext=−1.5ww_{\mathrm{next}}=-1.5w: parameters go 2→−3→4.52\to-3\to4.5 and losses go 4→9→20.254\to9\to20.25. The final loss plot uses an explicitly expanded 0–22 range, with a common zero baseline. No endpoint is clipped.

Each update subtracts the correct local gradient, but overshoots so far that it raises loss. This is a finite-step failure, rather than a gradient-sign error. Monitor the objective and choose step size for its scale and curvature. Even a decreasing training objective still needs separate generalization evaluation.

The Quick Version

  • Compute the gradient at the current parameter.
  • Subtract learning rate times gradient, then evaluate again.
  • Three quadratic updates give four states, including the initial state.
  • Objective scaling changes plain gradient descent's effective step size.
  • Zero gradient can occur above a better solution.
  • Correct local direction does not guarantee a good finite step.