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
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
Is a kind of / part of
Kinds and parts
Siblings
- Accuracy
- Bias-Variance Trade-off
- Cross-Validation
- Curse of Dimensionality
- Data, Features and Labels
- Hyperparameters
- Linear Algebra Basics
- Log Loss (Cross-Entropy)
- Loss Function
- Overfitting
- Precision, Recall and F1
- Probability Basics
- Regression Metrics
- Regularization
- ROC Curve and AUC
- Train, Validation and Test Sets
Uses / built on
Techniques that apply here
Used by
Used to train
Try it
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:
- Compute the gradient of the loss with respect to every parameter.
- Move every parameter a small step against its gradient.
- 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 , loss and learning rate :
With momentum (often 0.9):
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
- 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
- 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
- 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.