University / ProfessionalLessonCalculus
Gradient Descent: How Machines Learn
The one idea behind most of machine learning: roll downhill. Interactive 3D — orbit the landscape, drop the ball anywhere.
dailymath · · 9 min read
The whole trick: roll downhill
Every neural network — the ones behind chatbots, image generators, recommendation feeds — learns by the same move repeated billions of times: measure how wrong you are, then nudge every knob a tiny bit in the direction that makes you less wrong. That's it. The rest is bookkeeping.
Mathematicians call the wrongness a cost function. Training means finding the knob settings where the cost is smallest — and the tool for that is calculus you already know: the derivative.
One dimension first
Take . Wherever you stand, the derivative tells you the slope. Walk *against* the slope and you must go down. Gradient descent formalizes the walk:
The update rule
The number (eta) is the learning rate — the step size. Watch the ball take the walk on : each step lands where the previous slope pointed, and the steps shrink as the slope flattens.
Figure 1
Now in 3D — the real thing
Real cost functions have millions of dimensions, but everything important already shows up in two. The surface below is : two valleys separated by a mountain pass (a saddle point). The gradient is now a vector of partial derivatives, and the update rule is the same walk:
Two dimensions
Figure 2 · Interactive
An interactive 3D surface showing gradient descent rolling down a two-variable function to its minimum. Drag to rotate the view; click or tap the surface to drop a new starting point.
Local minima
The tap experiment is the deepest lesson in machine learning: gradient descent finds *a* valley, not *the* valley. Start on the wrong side of the pass and you'll settle into a different answer. Modern ML mostly makes peace with this — good-enough valleys are everywhere in high dimensions.
The Goldilocks knob
Everything hangs on . Too small and training takes forever; too large and each step overshoots the valley floor, bouncing higher and higher until the whole thing explodes. Practitioners spend real money finding the porridge that's just right.
Figure 3
Why saddle points matter
At the mountain pass the gradient is exactly zero — the walk stops even though you're nowhere near a minimum. In millions of dimensions, saddle points vastly outnumber minima, and escaping them (with momentum, noise, or clever step sizes) is a whole subfield. When you hear "the optimizer got stuck", picture the ball balanced on that pass.
From here the story branches into stochastic gradient descent (estimate the gradient from a random handful of data), momentum (give the ball inertia), and Adam (give every knob its own learning rate). All of them are still, at heart, the walk you just watched.
1
Check your intuition
Question 1 of 4
In the update rule , why is the derivative *subtracted*?
Gradient descent is the whole trick behind machine learning, run backward from the answer: measure the wrongness, follow the slope down. If chasing that kind of intuition down to the arithmetic is your thing, solve a fresh math problem every morning with dailymath. One drop, one coffee, one win.
Try dailymath