Log inStart free
LESSON 2.30 · 5 STAGES · 3 CONTROLS · 3 CHECKSPRO · PREVIEW

AdamW and weight decay

Watch Adam + L2 and AdamW shrink the same two weights differently.


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

Go Pro · $8.25/mo
EXPLAINER · 2.30 · OPTIMIZER BAY∇L(W₀) = (−0.02, 24) · W₂ 1200× STEEPER
01
Stage 1 of 5 · Loss and weights
Two weights start at w₀ = (0.02, 1.2) in a ravine. Across it, w₂'s gradient is 1200 times larger: ∇L = (−0.02, 24).
Explain it simply

Training moves two weights, w₁ and w₂, to lower the loss. The shaded map shows the loss, and a stronger shade is higher. The start sits high on the steep wall of a long ravine. Across the wall, along w₂, the slope is huge. Along the ravine floor, along w₁, it's almost flat.

A contour map of the loss over w₁ from −0.5 to 2.5 and w₂ from −0.5 to 1.5. A saddle point sits at (0, 0) and the lowest point at (2, 0). The start w₀ = (0.02, 1.2) has gradient (−0.02, 24): 1200 times larger along w₂.

weights, their paths and the decayloss and gradientswhere Adam + L2 settlescontour lines
loss K·L(w₁, w₂) · K = 101201w₁w₂1411saddlemin L = 0−∇L = (0.02, −24)w₀gradient ∇L at w₀w₁−0.02w₂24loss K·L(w₁, w₂) · K = 101201w₁w₂1411saddlemin L = 0−∇L = (0.02, −24)w₀gradient ∇L at w₀w₁−0.02w₂24
Toy: the 2.C2 ravine · 2 weights · up to 100 Adam steps
STAGE 1 / 5
MATH · STAGE 1HOVER A SYMBOL OR A SHAPE
L(w)=K⋅((w12−4)216+10 w22)\sy{L}{grad}{L}(\sy{w}{param}{w}) = \sy{K}{param}{K}\cdot\Big(\frac{(w_1^2 - 4)^2}{16} + 10\,w_2^2\Big)
∇L(0.02, 1.2)=1⋅(w1(w12−4)4, 20 w2)=(−0.02, 24)\nabla L(0.02,\ 1.2) = 1\cdot\Big(\frac{w_1(w_1^2-4)}{4},\ 20\,w_2\Big) = (-0.02,\ 24)

The loss is steep across the ravine and nearly flat along it.

Common mix-ups

MYTHIn Adam, an L2 penalty and weight decay are the same.

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

Predict, then reveal
3 CHECKS · PRO
Q01With λ = 0, where do the two runs end?

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 3 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.