Lensa ML
Lensa ML

How Gradient Descent Works

Step 1 of 6

Standing on a Hill

Imagine you're lost in fog on a hilly landscape

-2-112θLossminimumyou are hereLoss(θ)

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

-2-112θLossminimumyou are hereLoss(θ)

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

-2-112θLossminimum−∇ (go this way)
Drag to move the pointθ = 2.00
GRADIENT
4.864
DIRECTION
← left

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

-2-112θLoss
Adjust learning rateα = 0.100
LEARNING RATE
0.100
FINAL LOSS
0.151

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

-2-112θLossloss = 5.998
STEP
0
LEARNING RATE
0.12
LOSS
5.998
GRADIENT
5.348

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

θ₁θ₂minstart
Learning rateα = 0.080
STEPS
>150
FINAL LOSS
0.0117
α
0.080

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

θ₁θ₂minstart
MODE
Mini-Batch
NOISE
Medium
SPEED
Balanced

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!