Gradient LabStart the lesson

Lessons › Chapter 3: Regression and optimization

The learning rate

With lr = 0.1, each step is tiny. After 8 steps the ball has barely moved. Training would take forever.

Watch it move. This lesson is interactive on Gradient Lab: every step is an animated scene you can replay.

Start the interactive lesson

Step by step

Story

The error explodes

Leo’s first automatic run goes wrong: the error shoots up instead of down.

Concept

Too small: crawling

With lr = 0.1, each step is tiny. After 8 steps the ball has barely moved. Training would take forever.

Concept

Just right

With lr = 1.0, the ball reaches the bottom in a handful of steps and settles smoothly.

Build

Too big: bouncing

With lr = 3.0, each step overshoots the bottom and lands on the other side. It still gets there, but it zigzags.

Key idea

Way too big: blowing up

With lr = 4.4, every overshoot lands higher than the last. The loss grows instead of shrinking. This is called divergence, and you will see it as a loss that shoots to infinity or NaN.

Loss going up and up? Lower the learning rate first.

Insight

Start big, then shrink

In practice we often use a schedule: a larger learning rate early to make progress, then smaller steps to settle precisely. Optimizers like Adam also adapt the step size per weight.

Real life

In real life: parking a car

Tiny nudges on the pedal take forever to reach the space. Big lurches overshoot it, forwards and back. The learning rate is how hard you press. Engineers tune it on every model they train.

Quick check: Your loss jumps around and grows each epoch. What do you try first?

Growing, oscillating loss is the classic sign that steps are too big and overshooting.

Pseudocode

try step sizes 0.1, 1.0, 3.0, 4.4:
    w = 7.5
    repeat 8 times:
        w = w − step_size × slope(w)
    show where w ended up

# 0.1: crawls     1.0: smooth
# 3.0: bounces    4.4: blows up

Key terms

divergence
When training goes wrong and the error keeps growing instead of shrinking.
schedule
A plan for changing the learning rate during training, usually shrinking it.

Build it: Gradient descent from scratch (30 min, runs in your browser)

See the project