Search

Search IconIcon to open search

L2 Regularization

Last updatedUpdated: by Jakub Žovák · 2 min read

Properties
created 15.03.2026, 09:28
modified 26.07.2026, 13:38
published Empty
topics Regularization, Weight Penalization
authors Jakub
ai-assisted Yes

L2 regularization (also called Ridge in statistics, or weight decay in the SGD context) penalizes the sum of squared weights. It keeps all weights small but non-zero, smoothly shrinking them toward zero ( Deep Learning, Ch. 7).

# Penalized Loss

$$
\mathcal{L}{\text{L2}} = \mathcal{L} + \frac{\lambda}{2} \sum{i} w_i^2
$$

where:

  • $\mathcal{L}$ is the original loss
  • $\lambda > 0$ is the regularization strength
  • $\frac{1}{2}$ is a convenience factor that cancels the coefficient in the gradient

# Gradient Update

$$
\frac{\partial \mathcal{L}_{\text{L2}}}{\partial w_i} = \frac{\partial \mathcal{L}}{\partial w_i} + \lambda w_i
$$

The update rule becomes:
$$
w_i \leftarrow w_i - \alpha \left(\frac{\partial \mathcal{L}}{\partial w_i} + \lambda w_i\right) = (1 - \alpha \lambda), w_i - \alpha \frac{\partial \mathcal{L}}{\partial w_i}
$$

The factor $(1 - \alpha \lambda)$ shrinks the weight at each step — this is exactly Weight Decay in SGD.

# Properties

  • Smooth and differentiable everywhere — easy to optimize
  • Produces dense solutions: all weights shrink but rarely reach zero
  • Equivalent to placing a Gaussian prior on weights (MAP estimation)
  • In SGD: identical to Weight Decay
  • In Adam: not identical to weight decay — the gradient scaling distorts the L2 penalty; see Adamw for the decoupled fix

# Bayesian Interpretation

Minimizing $\mathcal{L}_{\text{L2}}$ is equivalent to MAP estimation with a Gaussian prior $p(w) \propto e^{-\frac{\lambda}{2}|w|^2}$.

# Comparison with L1 Regularization

L1L2
Penalty$\sumw_i
EffectSparse (zeros out weights)Dense (shrinks all weights)
GeometryDiamond constraintSphere constraint
DifferentiabilityNo (at 0)Yes