How Gradient Descent Works
Standing on a Hill
Imagine you're lost in fog on a hilly landscape
You're standing on a loss landscape — the curve shows how wrong the model is for each parameter value θ. The goal: find the valley (lowest loss), but you can't see the whole landscape.
Step 1 of 6: Standing on a Hill
Imagine you're lost in fog on a hilly landscape
You're standing on a loss landscape — the curve shows how wrong the model is for each parameter value θ. The goal: find the valley (lowest loss), but you can't see the whole landscape.
Step 2 of 6: Follow the Slope
The derivative tells you which way is downhill
The gradient (derivative) at your position tells you the slope. Move in the negative gradient direction — that's downhill. Positive slope? Go left. Negative slope? Go right.
Step 3 of 6: The Learning Rate
How big a step to take downhill
The learning rate α controls step size. Too small? Painfully slow. Too large? Overshoot and diverge. Just right? Smooth convergence to the minimum.
Step 4 of 6: Step by Step
Watch gradient descent find the minimum
Each step: compute the gradient, then update θ = θ − α·∇L. Watch the loss decrease as steps grow smaller near the minimum — the gradient shrinks!
Step 5 of 6: In Two Dimensions
Real networks have millions of parameters
With two parameters, the loss surface becomes a landscape. Contour lines show equal-loss regions. Notice the zigzag path — in the steep (θ₂) direction it oscillates, while in the flat (θ₁) direction progress is slow. Real networks do this in millions of dimensions!
Step 6 of 6: Stochastic & Mini-Batch
Using subsets of data for faster, noisier updates
Batch GD uses all data — smooth but slow. SGD uses one sample — fast but noisy. Mini-batch is the sweet spot: batches of 32-256 samples give good speed with manageable noise. The noise can even help escape local minima!