Gradient Descent
Gradient Descent — Gradient descent is an iterative optimization algorithm that minimizes a loss function by repeatedly stepping in the direction of its negative gradient. The learning rate controls the step size and determines whether it converges or diverges.
Imagine you’re blindfolded on a hilly landscape and you want to find the lowest valley. Gradient descent is the strategy: feel which way is downhill, take a step that direction, repeat.
- Start
- Descent path
- Next step (−α∇J)
- Minimum
Descent controls
The idea in plain words
Gradient descent finds the bottom of a valley by feeling which way is downhill and taking a step that direction, over and over. The learning rate is the step size. Nudge it up and the path descends faster; push it to the top and each step overshoots, bouncing to ever-larger loss until it flies off to infinity.
The valley is defined by a loss function, and this is exactly how models like linear regression are fit when there’s no shortcut.
Now, the math
Each parameter θ updates by stepping against the gradient:
- a model parameter being tuned.
- the learning rate — the step size.
- the gradient: the uphill direction of the loss.
▸ Show the derivation
On an elongated bowl, the steepest direction has the largest curvature. Convergence there requires the learning rate to stay below roughly twice the inverse of that curvature; above it, each step more than undoes the last and the loss diverges — which is exactly what the slider lets you trigger.
Trace it by hand
The loss is the interactive's bowl surface — half of x squared plus y squared — whose gradient at any point (x, y) is simply (x, y). Start at theta = (2, 1) with learning rate eta = 0.5 and take two updates. All numbers are exact.
The start point and its loss
This is the same bowl surface the interactive uses, with its minimum at the origin.
Feel the slope: the gradient
For this bowl the gradient equals the position itself — the farther out you are, the steeper it is.
First update: step against the gradient
With eta equal to 0.5 on this surface, every coordinate exactly halves.
Second update: repeat from the new point
The gradient was recomputed at the new point before stepping — that re-measuring is the whole algorithm.
Watch the loss fall
Position halves each step and the loss is quadratic, so the loss drops 75 percent per update.
What just happened: Two applications of theta minus eta times the gradient cut the loss from 2.5 to 0.156 — a 75 percent drop per step. Nothing global was needed: the local slope at each point was enough to head to the minimum.
Now Break It
Try this: Crank the learning rate high — the path oscillates wildly and diverges to infinity.
Control: Learning rate slider (set to maximum)
What happens: Diverged! The learning rate is too high — each step overshoots the minimum and loss is increasing.
Where gradient descent is used
Gradient descent is the workhorse that fits nearly every modern model by iteratively stepping downhill on the loss surface. Training a neural network for image recognition, a language model that autocompletes your email, or a recommendation system all reduce to the same loop: compute how the loss changes with respect to each parameter, then nudge every parameter a small step in the direction that reduces error. Logistic regression models in credit scoring, deep networks in speech recognition, and the fine-tuning of large language models are all driven by gradient descent or one of its variants. Its popularity comes from scalability. Because it only needs the gradient at the current point, it can optimize models with billions of parameters without ever examining the entire loss surface.
A common misconception is that gradient descent finds the global minimum. For most non-convex problems, like deep networks, it finds a local minimum or a flat region, and that is usually good enough because many such solutions generalize well. A second pitfall is the learning rate. Too large a step and the loss oscillates or diverges, overshooting the valley; too small and training crawls or stalls in a shallow dip. People also confuse gradient descent with backpropagation: backpropagation is the efficient method for computing the gradient, while gradient descent is the rule that uses that gradient to update parameters. Finally, gradient descent needs a differentiable loss, which is why non-smooth objectives require special handling.
Frequently asked questions
What is gradient descent?
What is the difference between gradient descent and backpropagation?
What is the difference between batch, stochastic, and mini-batch gradient descent?
Why does gradient descent get stuck or diverge?
Does gradient descent always find the best solution?
What is a learning rate and how do I choose it?
Written & reviewed by the ML Visualization team · Last updated .