Gradient descent
In short
Gradient descent is the step-by-step method AI models use to learn. It measures how wrong the model is, works out which direction of change reduces that error, takes a small step that way, and repeats until the error stops falling.
- Also called
- Stochastic gradient descent, SGD, Steepest descent
- Topic
- How AI models work
- Level
- Some background helps
- First described
- Augustin-Louis Cauchy proposed the gradient method in a note to the French Academy of Sciences dated 18 October 1847, to solve equations from astronomy3.
Training a model means finding settings (weights) that make its error, called the loss, as small as possible. Gradient descent does this by trial and adjustment. Google's machine learning course sets out the loop: calculate the loss, work out which direction to move the weights to reduce it, move them a small amount, and repeat until the loss stops going down1. At that point the model is said to have converged1.
The "gradient" is the slope of the loss with respect to each weight. The method updates the weights in the opposite direction to the gradient, like walking downhill until you reach a valley. The size of each step is set by the learning rate2.
There are three main versions. Batch gradient descent uses the whole training set for every step. Stochastic gradient descent (SGD) updates after each single example, which is faster but noisier. Mini-batch gradient descent, which updates on small groups of examples, is the usual choice for neural networks, and people often call it SGD too2.
It is not guaranteed to find the best possible answer. On simple, bowl-shaped problems it reaches the lowest point, but on the bumpy loss surfaces of neural networks it may settle in a local low point instead2. Optimisers such as Adam are refinements of the same idea that adjust the step size for each weight24.
In neural networks, the gradients come from backpropagation, and gradient descent then uses them to update the weights5.
Example
Picture walking down a hill in thick fog on the Brecon Beacons. You cannot see the bottom, so you feel which way the ground slopes under your feet and take a step downhill, then check again. Gradient descent does the same thing with a model's error2.
Why it matters
It is how neural networks, including the large language models behind chatbots, are trained. When people say a model "learned" something, gradient descent did the learning.
Questions people ask
What is the difference between gradient descent and stochastic gradient descent?
Plain (batch) gradient descent looks at the whole training set before each update. Stochastic gradient descent updates after every single example, which is quicker but noisier. Most neural networks use mini-batches, a middle path, and the name SGD usually covers that too2.
What is the learning rate in gradient descent?
The learning rate sets how big a step the method takes downhill each time2. Too small and training is painfully slow; too large and the loss can bounce around the minimum or even get worse2.
Who invented gradient descent?
The French mathematician Augustin-Louis Cauchy, in a short paper to the Academy of Sciences in October 1847. He wanted a general way to solve the systems of equations that came up when calculating the orbits of heavenly bodies3.
Related terms
Sources
- Google for Developers, Machine Learning Crash Course: Linear regression, gradient descent
- Ruder (2016), An overview of gradient descent optimization algorithms, arXiv:1609.04747
- Lemaréchal (2012), Cauchy and the Gradient Method, Documenta Mathematica Extra Volume ISMP, 251-254
- Kingma and Ba (2014), Adam: A Method for Stochastic Optimization, arXiv:1412.6980
- PyTorch documentation, A Gentle Introduction to torch.autograd