Log inStart free
LESSON 2.32 · 5 STAGES · 2 CONTROLS · 3 CHECKSPRO · PREVIEW

Gradient clipping

Watch one huge gradient throw the weights away, and see clipping stop it.


Pro lesson. Stage 1 is free to watch. Pro opens all 5 stages, 2 controls and 3 checks, in this lesson and every other.

Go Pro · $8.25/mo
EXPLAINER · 2.32 · CLIP BAYSTEPS 0–4 · NORM ≤ 0.97 · LOSS 2.67
01
Stage 1 of 5 · Step downhill
Gradient descent moves the weights by −η·g each step. The gradient norm ‖g‖ stays at 0.97 or less.
Explain it simply

You see two weights on a map of the loss, like a hiker on a hillside. Each step moves them a little way downhill. The step is the learning rate times the gradient. The gradient's length, its norm, stays at 0.97 or less, so every step is short.

The weights take 5 steps down the plateau. The loss falls from 3.92 to 1.28. The gradient norm stays at 0.97 or less.

weights, max norm cgradient, no clippingclipped runloss contours
the two weights on the loss mapgradient norm per steploss per stepcliffhigh plateauminimumloss 2.670204020stepw₁ →w₂ ↑the two weights on the loss mapgradient norm per steploss per stepcliffhigh plateauminimumloss 2.670204020stepw₁ →w₂ ↑
Toy: 2 weights · a loss with one cliff · 20 steps of gradient descent, η = 0.5
STAGE 1 / 5
MATH · STAGE 1HOVER A SYMBOL OR A SHAPE
wk+1=wk−η gk\sy{w}{param}{w}_{k+1} = \sy{w}{param}{w}_k - \sy{eta}{param}{\eta}\,\sy{g}{grad}{g}_k
w4=(−1.24, 0.7)−0.5⋅(−0.59, 0.29)=(−0.94, 0.55)w_{4} = (-1.24,\ 0.7) - 0.5\cdot(-0.59,\ 0.29) = (-0.94,\ 0.55)

Each step moves the weights against the gradient, scaled by η.

Common mix-ups

MYTHClipping by value and by norm do the same thing.

The fix, and 1 more mix-up with the diagram to show them, come with Pro.

Predict, then reveal
3 CHECKS · PRO
Q01Clip by value at the cliff: does the clipped step point the same way as the gradient?

Make your guess, then test it in the diagram. All 3 checks come with Pro.

PRO LESSON · YOU WATCHED STAGE 1 OF 5
Unlock the full explainer
  • 4 more stages and 2 live controls
  • 2 mix-up cards and 3 predict-then-reveal checks
  • Watch it as a narrated video, in three voices
  • Every Pro lesson and capstone · 656 in total

$99 a year, or $15 a month. Cancel any time.