Explain momentum, Adam’s moment estimates and bias correction, and why AdamW decouples weight decay.
Answer
Model answer, written in a candidate's voice
In short
- Momentum averages past gradients to smooth noise and reinforce consistent directions.
- Adam keeps EMAs of gradients and squared gradients, corrects early bias, and scales each parameter by its own adaptive denominator.
- Bias correction divides the EMAs by 1 - beta^t because they start at zero.
- AdamW applies weight decay directly to the weights instead of folding L2 into the gradient, avoiding rescaling by the adaptive denominator.
- SGD with momentum can generalise better in some vision settings; Adam is the default for transformers.
In full
Momentum keeps an exponential moving average of gradients, so noisy or oscillating updates are smoothed and consistent directions are reinforced. Adam extends this by maintaining an EMA of gradients and an EMA of squared gradients, then correcting both for the fact that they start at zero by dividing by 1 - beta1^t and 1 - beta2^t; the update is roughly theta minus lr times the corrected gradient EMA over the square root of the corrected squared-gradient EMA plus epsilon, giving per-parameter step sizes. That adaptive denominator is the key difference from plain SGD: parameters with consistently large gradients get smaller effective steps, while parameters with small or noisy gradients can move more. If L2 is added to the loss under Adam, the decay term enters the gradient and is then rescaled by that same denominator, so the effective shrinkage depends on gradient history; AdamW decouples decay by applying it directly to the weights, roughly theta minus lr times the adaptive update and lr times lambda times theta. In practice, SGD with momentum can generalise better in some vision settings, while Adam is the default for transformers because it is robust to sparse, noisy, and heterogeneous gradients, though it still needs sensible learning-rate and epsilon choices.
What a strong answer covers
- Momentum keeps an exponential moving average (EMA) of gradients, damping oscillation.
- Adam keeps EMAs of the gradient and squared gradient, applies bias correction for early steps, and gives per-parameter step sizes.
- With Adam, L2 added to the loss gets rescaled by the adaptive denominator; AdamW applies decay directly to the weights.
- Trade-offs: SGD may generalise better in some vision settings; Adam is the default for transformers.
Common mistakes
- equating L2 regularisation with weight decay under Adam
- forgetting the epsilon and memory cost (2× the parameters).