3.2.12 · D5Training Deep Networks

Question bank — L1 - L2 weight decay in deep nets

1,409 words6 min readBack to topic

Reminders you'll lean on (all defined in the parent):

  • = a single weight; (L2 penalty, summed squares); (L1 penalty, summed absolute values).
  • = regularization strength; = learning rate.
  • L2 update: . L1 penalty gradient: .
  • = if , if : it reads off which side of zero a weight sits on, so the L1 push is always full-strength toward zero.

True or false — justify

L2 weight decay drives many weights to exactly zero.
False. L2's push is , which shrinks with , so it fades to nothing as — weights become tiny but almost never exactly zero. Exact zeros are L1's signature.
For plain SGD, "adding an L2 penalty to the loss" and "multiplying weights by each step" are the same thing.
True. We derived it: . The penalty gradient is the shrink factor.
For Adam, L2 penalty and true weight decay are still identical.
False. Adam divides each gradient (including the term) by a per-parameter adaptive scale, so already-large-gradient weights get less decay. AdamW instead applies decay separately from the gradient — that decoupling is the whole point of AdamW.
Increasing always improves generalization.
False. It reduces variance up to a point, but too-large crushes all weights toward 0, giving an over-smooth function that can't fit the signal — that's underfitting (high bias). It's a tradeoff with a sweet spot found on validation data.
Bias terms should be regularized just like weights, for consistency.
False. Biases only shift the function up/down; they don't create the spiky high-variance behaviour that overfits. Penalizing them adds bias without cutting variance and can hurt the fit — so standard practice leaves them (and BatchNorm params) unpenalized.
If the data gradient is zero, an L2-regularized weight stays put.
False. With the update is , geometric decay toward 0. A weight only survives if the data gradient keeps re-supplying it.
L1 penalty corresponds to a Gaussian prior on the weights.
False. L1 ⇔ Laplace prior (sharply peaked at 0, heavy tails), which is what encourages exact zeros. L2 ⇔ Gaussian prior. This is the MAP view of regularization.
At the regularized objective equals the plain data loss.
True. with leaves — no penalty, so no decay and no sparsity. It's the degenerate "no regularization" case.

Spot the error

"L2 gradient is , so it pushes with constant force."
The L1 gradient is (constant force). L2's gradient is — proportional to the weight, so the force weakens as shrinks. Swapping these two is the core L1-vs-L2 confusion.
"Because , weights decay, so I can pick any large to decay faster and it's always fine."
If then is negative and can exceed 1, so weights flip sign and blow up each step. The decay-toward-zero picture only holds for .
"L1 gives small weights and L2 gives sparse weights."
Backwards. L1 = sparse (exact zeros) thanks to the constant-force gradient; L2 = uniformly small but rarely zero. Compare with Lasso (L1) and Ridge (L2).
"The equilibrium weight means bigger makes weights bigger."
Bigger appears in the denominator, so it makes smaller — stronger regularization means the data must supply a larger gradient to justify the same weight.
"L2 is called weight decay because it decays the learning rate over time."
No — the learning rate is untouched. It's the weights that decay: each step multiplies by . Learning-rate schedules are a separate mechanism.
"Weight decay and Dropout do the same thing, so use only one."
Both fight overfitting but by different mechanisms — decay shrinks weight magnitudes, dropout randomly removes units to prevent co-adaptation. They're complementary and often combined; neither replaces the other.

Why questions

Why does L1 produce exact zeros while L2 does not?
L1's push stays full-strength no matter how small is, so it can carry a small weight across zero and a soft-threshold pins it at 0. L2's push vanishes as , so it slows to a crawl and never lands exactly on zero.
Why is it fair to say "the data must earn every unit of weight"?
At equilibrium the decay force exactly cancels the data gradient , giving . A weight is only nonzero to the extent the data gradient keeps pushing back — no useful gradient, no surviving weight.
Why do smaller weights tend to generalize better?
Small weights make the network's function flatter and smoother, so it can't carve sharp spikes to memorize noise. Smoother functions have lower variance and thus better generalization.
Why is adding a penalty equivalent to a Bayesian prior?
MAP maximizes ; the data term is the negative loss and the log-prior term becomes the penalty. So is literally a statement of belief that most weights should be near zero.
Why does AdamW exist if Adam can already add an L2 term?
Under Adam, the term is scaled by each parameter's adaptive learning rate, so decay strength varies unpredictably per weight. AdamW decouples decay, applying a clean shrink independent of the gradient scaling, restoring the intended uniform decay.
Why do we penalize (with the ) rather than ?
The is a convenience: differentiating gives exactly (the 2 cancels), so the gradient is the clean with no stray factor. It doesn't change what's optimized, only tidies the algebra.

Edge cases

What happens to a weight sitting exactly at under L1?
is undefined, so the derivative doesn't exist there; the subgradient lets any value in apply. In practice the soft-threshold operator simply holds it at 0 unless the data gradient is strong enough to pull it out.
What is the update when ?
It reduces to ordinary Gradient Descent: , with no shrink factor and no sparsity pressure. Regularization is fully switched off.
What if the data gradient exactly equals the decay force?
The weight is at its equilibrium and stays there — the two opposing pushes cancel, so the weight neither grows nor decays.
What if exactly (with zero data gradient)?
The shrink factor , so is set to 0 in a single step. Above 1 it goes negative and oscillates/diverges — so is the boundary of stable decay.
Does weight decay affect a weight whose data gradient is enormous and constant?
Yes, but only mildly: it settles at , which is large when is large. Strong, consistent data evidence overpowers the decay, so important weights stay big — exactly the desired behaviour.
What does L2 do to two weights that are duplicates (same feature)?
L2 spreads the load, shrinking both to share the total evenly (each ends up small), whereas L1 tends to keep one and zero the other. This is why L2 is "spread shrinkage" and L1 is "selection."

Recall One-line self-test

If you can state, for any item above, both the verdict AND the mechanism ( vs , and ), you own this topic.