Compare L1 and L2 regularization. Why does L1 produce sparse weights?
Type it the way you would explain it to an interviewer. A few sentences is enough; you can't break anything.
Model answer: the part to lead with
Both add a penalty on weight magnitude to the loss. L2 adds λ‖w‖², shrinking all weights proportionally toward zero but rarely to zero. L1 adds λ‖w‖₁ and drives many weights exactly to zero, performing implicit feature selection.
Full worked answer
Both add a penalty on weight magnitude to the loss. L2 adds λ‖w‖², shrinking all weights proportionally toward zero but rarely to zero. L1 adds λ‖w‖₁ and drives many weights exactly to zero, performing implicit feature selection.
Why sparsity: the L1 penalty's gradient is a constant ±λ regardless of the weight's size, so it keeps pushing small weights all the way to zero, where the subgradient lets them stay; L2's pull is proportional to w, so it weakens as weights shrink and never quite finishes the job. Geometrically, the L1 ball has corners on the axes, and the loss contour typically first touches the constraint region at a corner - where some coordinates are exactly zero.
The Bayesian view is a good differentiator: L2 = MAP estimation with a Gaussian prior on weights; L1 = MAP with a Laplace prior (sharper peak at zero, heavier tails).
In practice: L1 matters for linear models and feature selection (lasso); deep learning almost exclusively uses L2-style weight decay. One subtlety that sets up a later question: with adaptive optimizers like Adam, adding L2 to the loss is not equivalent to weight decay - the penalty gets rescaled by the per-parameter adaptive term. That's exactly the bug AdamW fixes by decoupling the decay from the gradient update. Also note common practice: no weight decay on biases or LayerNorm gains, since they're low-dimensional and decaying them just distorts activations.
What a good answer covers
- Both add a penalty on weight magnitude to the loss
- L2 adds λ‖w‖², shrinking all weights proportionally toward zero but rarely to zero
- L1 adds λ‖w‖₁ and drives many weights exactly to zero, performing implicit feature selection
- Why sparsity: the L1 penalty's gradient is a constant ±λ regardless of the weight's size, so it keeps…
- Geometrically, the L1 ball has corners on the axes, and the loss contour typically first touches the…
Key terms: L2 · L1 · Gaussian prior · Laplace prior · weight decay
In the glossary: Weight decay · Adam · AdamW · LayerNorm
Interviewer follow-ups to expect
What's elastic net and when would you use it?
Why is L2-in-the-loss different from weight decay under Adam?
In practice: L1 matters for linear models and feature selection (lasso); deep learning almost exclusively uses L2-style weight decay. One subtlety that sets up a later question: with adaptive optimizers like Adam, adding L2 to the loss is not equivalent to weight decay - the penalty gets rescaled by the per-parameter adaptive term. That's exactly the bug AdamW fixes by decoupling the decay from the gradient update. Also note common practice: no weight decay on biases or LayerNorm gains, since they're low-dimensional and decaying them just distorts activations.
Why exclude LayerNorm parameters from weight decay?
In practice: L1 matters for linear models and feature selection (lasso); deep learning almost exclusively uses L2-style weight decay. One subtlety that sets up a later question: with adaptive optimizers like Adam, adding L2 to the loss is not equivalent to weight decay - the penalty gets rescaled by the per-parameter adaptive term. That's exactly the bug AdamW fixes by decoupling the decay from the gradient update. Also note common practice: no weight decay on biases or LayerNorm gains, since they're low-dimensional and decaying them just distorts activations.
Worked answer from AI-Engineer-Interview-Questions by Om (MIT), reformatted for LLM Prep · answer text last updated 6 November 2026 · scoring and review schedule by LLM Prep