Plain SGD uses the same learning rate for every parameter:
θ←θ−ηgt,gt=∇θL
Problem 1 — different scales. In deep nets, some parameters get huge gradients, others tiny. One global η is too big for some, too small for others.
Problem 2 — noisy stochastic gradients. Each minibatch gives a noisy gt. We want to average out the noise (momentum) but also normalize by how big/variable each gradient is.
Adam answers both by tracking two exponential moving averages (EMAs) per parameter.
We EMA the gradient itself:
mt=β1mt−1+(1−β1)gtWhy?mt estimates E[gt] — the average gradient. This cancels noise and keeps consistent directions moving.
We EMA the squared gradient (elementwise):
vt=β2vt−1+(1−β2)gt2Why?vt estimates E[gt2] — the size/variance of the gradient in each coordinate. Large vt ⇒ that direction is steep/noisy ⇒ take smaller steps there.
Because m0=v0=0, early EMAs are biased toward zero. Let's prove the correction. Assume g roughly stationary with mean gˉ. Unrolling:
mt=(1−β1)∑i=1tβ1t−igi.
Taking expectations with E[gi]=gˉ:
E[mt]=gˉ(1−β1)∑i=1tβ1t−i=gˉ(1−β1)⋅1−β11−β1t=gˉ(1−β1t).
So E[mt]=gˉ(1−β1t) is too small by factor (1−β1t). Divide it out:
m^t=1−β1tmt,v^t=1−β2tvt.
Now E[m^t]≈gˉ — unbiased. As t→∞, β1t→0 and the correction vanishes.
What two statistics does Adam track per parameter? ⇒ EMA of the gradient (mt) and EMA of the squared gradient (vt).
Why divide by v^t? ⇒ to normalize each coordinate by its gradient magnitude → adaptive per-parameter learning rate.
Why bias-correct? ⇒ EMAs start at 0, biased low by factor (1−βt); dividing removes it.
What's the steady-state Adam step on constant gradient? ⇒ ηsign(g).
What exactly does AdamW change? ⇒ it applies weight decay ηλθoutside the v^ normalization.
Recall Feynman: explain to a 12-year-old
Imagine hiking down a hill in fog. Momentum (m) is remembering which way you've been walking so you don't zig-zag. The magnitude tracker (v) notices which directions are steep and slippery, so you take tiny careful steps there and big confident steps on gentle slopes. Bias correction is because at the very start you have no memory yet, so you multiply up your first guesses to make them fair. AdamW adds a rule: "every step, shrink all your things a little toward zero, equally" — so nothing grows too big and messy. Adam = smart footwork; AdamW = smart footwork plus tidy-up.
Dekho, plain SGD har parameter ke liye same learning rate use karta hai, jo ill-conditioned problems (kuch directions steep, kuch flat) mein bekaar hai — wo zig-zag karta hai ya diverge ho jaata hai. Adam iska smart solution hai: har parameter ke liye do cheezein track karta hai — ek momentum (mt, gradient ka smooth average, direction batata hai) aur doosra squared gradient ka average (vt, magnitude batata hai). Fir update karta hai m^/v^ se, matlab har axis ko uski apni magnitude se normalize kar deta hai. Isliye steep directions mein chhota step, flat directions mein bada step — automatic adaptive learning rate.
Bias correction ka funda simple hai: m aur v dono zero se start hote hain, to shuru mein value bahut chhoti (biased) aati hai. Isliye (1−βt) se divide karke usko "un-shrink" karte hain. Yeh training ke shuruaat mein bahut zaroori hai, warna early steps blow up ho sakte hain. Steady state mein constant gradient par Adam ka step ηsign(g) ho jaata hai — magnitude gradient ke size se independent, sirf direction pe depend.
AdamW ek chhota par important fix hai. Normal weight decay (L2) mein tum λθ ko gradient mein add karte ho, par Adam usko v^ se divide kar deta hai — matlab jinke gradient bade, unpe decay kam, jinke chhote unpe zyada. Yeh galat hai! AdamW decay ko alag rakhta hai: har step ηλθ seedha subtract, sab weights pe equal shrinkage. Isiliye aajkal transformers mein AdamW default optimizer hai. Yaad rakho: Mean upar, RMS neeche, Weight-decay alag.