Skip to content

Gradient Descent

Finds good model parameters by repeatedly taking small steps downhill on the loss, in the direction that reduces error fastest.

Also GD · SGD · stochastic gradient descent · mini-batch gradient descent

Fig. / How it works
EACH STEP GOES DOWNHILL
Domain 01
Foundations
Role · kind
TrainingTechnique
Level
Beginner

Cauchy, 1847

You are on a foggy mountain and want to reach the valley. You cannot see far, so you feel which way the ground slopes under your feet and take a step downhill. Repeat until the ground is flat.

Where it fits

Not shown: 4 more that build on it. See the full list below.

+All relationships as a list

See it on the full map

Try it

Roll downhill: gradient descent, momentum and Adam
Loading interactive widget…
TakeawaySame landscape, same starting point, different update rules. The learning rate decides whether you crawl, glide or fly off the map.

How it works

Picture the loss as a landscape: every possible setting of the model’s parameters is a location, and the height is how wrong the model is there. Training means finding a low point.

The gradient is a vector that points in the direction the loss increases fastest. Gradient descent steps the opposite way:

  1. Compute the gradient of the loss with respect to every parameter.
  2. Move every parameter a small step against its gradient.
  3. Repeat thousands or millions of times.

The size of each step is the learning rate, the most important knob in deep learning. Too small and training crawls; too large and you jump over the valley, possibly further up the other side.

Stochastic and mini-batch variants compute the gradient on a small random batch of examples instead of the whole dataset. Each step is noisier but far cheaper, and the noise even helps escape flat regions. Momentum keeps a running average of past gradients so the ball keeps rolling through small bumps; Adam additionally scales each parameter’s step by how large its gradients have been.

For neural networks, the gradient itself is computed with backpropagation.

The math

For parameters θ\theta, loss LL and learning rate η\eta:

θt+1=θt−η ∇θL(θt)\theta_{t+1} = \theta_t - \eta \, \nabla_\theta L(\theta_t)

With momentum β\beta (often 0.9):

vt+1=βvt+∇θL(θt),θt+1=θt−η vt+1v_{t+1} = \beta v_t + \nabla_\theta L(\theta_t), \qquad \theta_{t+1} = \theta_t - \eta\, v_{t+1}

Everyday use cases

  • Case 01

    Training almost every neural network

    From a tiny digit classifier to the largest language models, the weights are updated by some form of gradient descent.

  • Case 02

    Fitting a line

    Linear regression can be solved by stepping downhill instead of with a formula, which scales to huge datasets.

Strengths, weaknesses and when to use it

Strengths

  • Works for any model whose loss is differentiable.
  • Mini-batches make it scale to billions of examples.

Weaknesses

  • The learning rate needs tuning. Too small is slow, too large overshoots or diverges.
  • Can get stuck on plateaus or in poor local minima on bumpy loss surfaces.

When to use itWhenever the loss is differentiable and there are too many parameters or too much data for a closed-form solution.

Check yourself

  1. Q01

    What happens if the learning rate is far too large?

    Show answer

    B: Steps overshoot the minimum and the loss can bounce or explode

  2. Q02

    What does "stochastic" mean in stochastic gradient descent?

    Show answer

    A: The gradient is estimated from a random subset (mini-batch) of the data

  3. Q03

    In which direction does gradient descent step?

    Show answer

    B: Opposite to the gradient The gradient points uphill, so we step the other way.

Go deeper