Stochastic Gradient Descent, Visually
Five pictures: reading the whole dataset is too slow, so we draw one row at a time. The noise that adds turns out to be a feature, until it isn't.
Calculating the exact gradient requires looking at every single example in your data. If you have millions of rows, reading them all just to make one tiny adjustment to the model is prohibitively slow.
Draw one row at a time
Stochastic gradient descent (SGD) skips the wait. It picks a single row at random, computes the gradient for that one row, and takes a step immediately. The update is incredibly fast, happening thousands of times before batch descent finishes one.
The path gets noisy
A single row is a poor estimate of the full dataset. One step might pull slightly left, the next slightly right. Instead of a smooth, direct descent, the path wanders and zig-zags. But because every step is right on average, it still trends downhill.
Noise is a feature
A smooth, exact path slides into the first shallow dip it finds and stops perfectly at the bottom. The noisy, jagged path of SGD shakes itself out of those shallow dips. This jitter naturally prevents the model from getting trapped in poor local minima, helping it find deeper, flatter basins that generalize better.
Where It Breaks
When you finally reach a good, deep minimum, the constant noise becomes a problem. The random steps are too chaotic to settle at the very bottom, causing the loss to bounce endlessly around the walls. You have to shrink the step size over time, or use momentum, to force the path to calm down.
The Quick Version
- Batch descent is too slow because it reads all data for one step.
- SGD takes instant steps using one random row at a time.
- The path becomes noisy and wanders, but still trends downward.
- That noise shakes the model out of bad, shallow local minima.
- The same noise prevents settling, so the learning rate must shrink.