DEEP LEARNING / 3. OPTIMIZERS
Optimizers
How we update weights — from vanilla SGD to Adam
EXPLANATION
Gradient descent says: move weights in the direction that reduces loss. But naive gradient descent has problems — slow convergence, stuck in saddle points, different learning rates needed per parameter. Key optimizers: • SGD → w = w - lr * grad. Simple, noisy, needs careful lr tuning • SGD + Momentum → accumulates velocity, smooths updates, escapes local minima • RMSProp → adapts lr per parameter using running average of squared gradients • Adam → combines Momentum + RMSProp. The default choice for most tasks • AdamW → Adam + proper weight decay. Best for transformers In practice: start with Adam or AdamW. Use SGD + momentum for CNNs on vision tasks where it often edges out Adam on final accuracy.
DATA FLOW
Loss surface (imagine a hilly landscape): SGD: bounces around, slow, noisy SGD+Momentum: builds speed downhill, overshoots less Adam: adapts step size per weight automatically Adam update rule: m = β1·m + (1-β1)·grad ← momentum (1st moment) v = β2·v + (1-β2)·grad² ← RMS (2nd moment) m̂ = m / (1-β1^t) ← bias correction v̂ = v / (1-β2^t) ← bias correction w = w - lr · m̂ / (√v̂ + ε) ← adaptive update
CODE