Regularization/Regularization Overview

Lesson 5.12,654 words

Regularization Overview

Regularization is any modification to a learning algorithm meant to lower test error at the possible expense of training error. We derive the bias–variance decomposition that explains why it helps, set up the two parameter-norm penalties, L2L^2 weight decay and L1L^1, derive their update rules and eigenbasis shrinkage, show geometrically why L1L^1 alone produces sparse weights (soft-thresholding), distinguish weight decay from loss-added L2L^2 under AdamW, and read both penalties through the two lenses that recur across the chapter: a norm-ball constraint via KKT, and a prior via MAP estimation.

╌╌╌╌

A model with enough capacity will fit its training set perfectly, noise and all, and then generalize badly. Regularization is the set of techniques that make a flexible model generalize, and the most effective approach is not making the model smaller but leaving it large and penalizing what it does with that size.

This lesson treats the oldest and most transparent family, the parameter norm penalties: add a term that penalizes large weights. Every such method adds a penalty , scaled by a strength , to the data-fit loss , and minimizes the sum

The hyperparameter trades the two off: recovers ordinary fitting, large forces the weights toward small values of . The bias term is conventionally left unpenalized (it shifts the whole function, and regularizing it tends to underfit), so throughout, denotes the weights only.1

Why penalize weights at all: the bias–variance decomposition

Before the penalties, the reason they help. Fix an input and suppose the label is generated as with zero-mean noise and variance . We fit an estimator on a random training set , so is itself a random quantity — draw a different training set and you get a different fit. The quantity we care about is the expected squared test error at , averaged over both the label noise and the draw of :

Write for the average fit over training sets. Insert and subtract inside the square, then expand. The noise is independent of , so every cross term with drops:

The middle cross term vanishes because . Three named pieces remain.

A large, unconstrained model can drive bias to nearly zero but at the cost of large variance: it fits the noise in each particular , so varies greatly from one training set to the next. Regularization deliberately introduces a little bias — it prevents the fit from matching the data exactly — in exchange for a large reduction in variance. Because the two enter the error as a sum, the minimum test error sits at the balance point, not at zero bias. That balance point is what the penalty tunes.2

regularization (weight decay)

The canonical choice penalizes the squared Euclidean norm.

The gradient of the penalty is just , so the regularized gradient adds a term pointing back toward the origin:

Deriving the multiplicative-shrinkage update

Substitute that gradient into a single gradient-descent step with learning rate and collect the terms:

The name is now visible: before taking the usual data-driven step, every weight is multiplied by the factor . Each step decays the weights toward zero by a constant fraction; this is the shrinkage. With and , the factor is , so a weight left untouched by the data gradient halves roughly every fourteen steps ().

Each step scales by toward the origin, then subtracts the data gradient .

Closed-form effect on a quadratic objective

To see which weights decay most, approximate near its unregularized minimizer by a second-order Taylor expansion. With the (symmetric, positive semidefinite) Hessian at and the gradient vanishing there,

The regularized minimizer sets the full gradient to zero, , which solves to

Diagonalize in its orthonormal eigenbasis, with eigenvalues measuring curvature along each eigenvector. In that basis the solution decouples coordinate by coordinate:

Each component of the optimum is rescaled by . Read the two extremes:

DirectionCurvature Shrink factor Effect
high-curvaturebarely moved — strongly constrained by the loss
low-curvaturecollapsed toward zero

The interpretation matches the bias–variance decomposition: directions the data constrains weakly (small ) are where overfitting occurs, and weight decay zeroes them out while leaving the well-determined directions alone. A high-curvature direction has a steep, narrow valley in the loss — moving off there raises the loss sharply, so the penalty moves it very little. A low-curvature direction is a flat trough — the loss barely changes with the weight, so the penalty pulls it freely to zero.

The shrink factor rises from toward as curvature grows past the penalty .

At the factor is exactly : the penalty and the curvature pull equally, and half the weight is kept. That crossover point is the scale sets — everything much stiffer than it is kept, everything much flatter is discarded.

Why prefers small, spread-out weights. The squared norm charges the square of each weight, so it is much cheaper to represent a needed quantity as many small weights than as one large weight. To split a target of across two weights, a single costs while an even costs ; the even split is preferred whenever the loss is indifferent to how the target is divided. The marginal penalty grows with the weight, so pushing a large weight down saves more than pushing an already-small weight — the objective equalizes magnitudes and never quite reaches zero.

Weight decay vs , and where they part: AdamW

Under plain gradient descent, adding to the loss and applying the multiplicative decay are the same operation, which is why the two names are used interchangeably. They stop agreeing the moment the optimizer rescales the gradient. Adam divides each gradient component by a running estimate of its own magnitude, . If the term is folded into the loss, its contribution is scaled by the same , so weights on noisy, large-gradient directions get less decay than intended and the effective penalty depends on the gradient history. AdamW fixes this by decoupling: it applies the shrink directly to the weights, outside the adaptive rescaling, restoring a uniform pull on every coordinate. For adaptive optimizers, decoupled weight decay (AdamW) and loss-added are genuinely different, and the decoupled form is the one that behaves like the analysis above.3

regularization

Swap the squared norm for the absolute-value norm and the qualitative behavior changes completely.

Subgradient and the soft-threshold

The absolute value is not differentiable at zero, so the gradient becomes a subgradient: the slope is for positive weights, for negative, and any value in at the kink.

The penalty's gradient no longer scales with ; it is a constant push of size toward zero, independent of the weight's magnitude. For a quadratic fit term the stationarity condition can be satisfied at exactly whenever the data gradient is smaller than : the subgradient interval contains it. That is the mechanism of sparsity, expressed by the soft-thresholding solution (decoupled, unit-curvature case):

Any coordinate whose unregularized value sits within of zero is set exactly to zero, not merely small. Plotted as a map from the unregularized value to the fitted value , this is a flat dead-zone of width centered at the origin, flanked by two lines of slope shifted inward by . Contrast the map : a single straight line through the origin, never flat, never crossing zero except at zero itself.

Soft-threshold (L1) zeroes a dead-band then shifts inward by ; L2 only rescales the slope. The dashed line is the identity.

Why the corner induces sparsity

The geometry makes this inevitable. The ball is a diamond whose vertices lie on the axes; the ball is a round circle. The constrained optimum is where the expanding loss contours first touch the ball, and a smooth elliptical contour overwhelmingly first meets the diamond at a corner, a point where one coordinate is zero.

Loss contours meet the diamond at an axis corner (, sparse) but the circle at a generic point (both coordinates nonzero).

The contrast is the chapter's first idea: makes weights small, makes them absent. Sparsity is why doubles as a feature selector: a zeroed weight is an input the model has switched off entirely.4

Elastic net

Combining the two penalties keeps 's sparsity while inheriting 's stability when features are correlated (where pure picks one arbitrarily).

The master table

The two penalties, side by side, with the prior each one corresponds to (derived in the MAP view below):

PenaltyGradient / subgradientEffect on weightsEquivalent prior
(weight decay)multiplicative shrinkage, all smallGaussian
, at soft-threshold, many exactly (sparse)Laplace
Elastic netsparse and groupedGaussian–Laplace mixture

Two views of the same penalty

View 1 — constrained optimization (KKT)

Penalizing a norm is the Lagrangian of constraining it.5 Minimizing for a fixed produces the same solution as the hard-constrained problem

for some radius . The link is the KKT conditions: the Lagrangian is , and stationarity reproduces the regularized gradient, with the multiplier playing the role of . Larger pulls the optimum inward, which is a smaller ball radius ; the two knobs are inverses.

Constraint penalty equivalence: the optimum sits where a loss contour is tangent to the ball, so and are antiparallel.

View 2 — the prior (MAP estimation)

The same penalty is a log-prior. Treat the weights as random with prior and maximize the posterior; maximum a posteriori estimation gives, after taking ,

The penalty is the negative log-prior. Take a zero-mean isotropic Gaussian prior . Its negative log is

which is with : a tighter prior (small ) is a stronger penalty. A Laplace prior gives , i.e. with . The two priors differ exactly where the penalties do. The Gaussian is smooth and rounded at the origin, so it puts no special mass at zero. The Laplace has a sharp peak at zero (its derivative jumps from to there), placing far more prior mass on tiny weights; that spike is the probabilistic counterpart of the diamond's corner, and it is why the posterior mode lands on exact zeros. This recap extends the MAP framing introduced under the machine-learning refresher.6

Gaussian prior (L2) is rounded at ; Laplace prior (L1) has a sharp spike at , placing more mass on near-zero weights.
Prior Penalty
Gaussian
Laplace, scale

What each penalty does to the weight distribution

The two priors produce distinct histograms of fitted weights: unregularized weights spread with heavy tails; concentrates them in a Gaussian-like hump near zero; produces a tall spike at zero plus a few surviving nonzeros.

Histograms of fitted weights: unregularized is wide, a narrow hump near , a sparse spike at .

Regularization strength and the bias–variance tradeoff

Sweeping from upward walks the model down the capacity axis: small leaves the full flexible model (low bias, high variance, prone to overfitting); large pins the weights near zero (high bias, low variance, underfitting). Test error traces the familiar U-curve, indexed by regularization strength rather than raw model size. This is the bias–variance decomposition made operational: the falling red curve is the variance term shrinking as the penalty tightens, the rising blue curve is the bias term growing, and their sum is the U whose floor is the best .

Test error versus regularization strength : small over-fits, large under-fits, and the U-curve's minimum balances them.

The minimum is found by holding out data: is selected on a validation set, never on the training loss it is designed to ignore.7

Practical defaults, with reasons

  • Use (weight decay) first. It is the default because its effect — a smooth, uniform shrink toward zero — improves almost every over-parameterized network and never zeroes a coordinate outright, so it does not risk deleting a feature the model still needs. A weight-decay coefficient around to is the usual starting band; sweep it on a log scale.
  • Use decoupled weight decay (AdamW) with adaptive optimizers. With Adam, folding into the loss makes the true penalty depend on the gradient history; the decoupled shrink restores the uniform pull that the eigenbasis analysis assumes.
  • Use only when you want sparsity. Feature selection, compressing a model by pruning zeroed weights, or making the fit interpretable are the cases where exact zeros are useful. When features are correlated, prefer the elastic net so the group is kept together instead of one member being chosen arbitrarily.
  • Leave biases unpenalized. A bias shifts the whole function rather than steepening it, so shrinking it toward zero buys no variance reduction and only adds bias.
  • Tune on validation, not training. The penalty exists to raise training loss; judging it by that loss would always prefer .

Decoupled weight decay

Goodfellow Ch. 7 treats weight decay and as interchangeable — right for plain SGD, wrong for the adaptive optimizers that now dominate. The correction is decoupled weight decay (Loshchilov & Hutter, 2019, the AdamW paper): folding into the loss makes Adam rescale the penalty by each coordinate's gradient history, so the effective decay is no longer uniform; applying the shrink directly to the weights restores the clean behavior the eigenbasis analysis above assumes. AdamW is now the default optimizer for training transformers, and the distinction between loss-added and decoupled weight decay is one every practitioner has to get right.

Two further public results sharpen the picture. First, in networks with normalization layers, weight decay often works through an unexpected channel: scaling a weight before a normalized layer leaves the output unchanged, so the penalty does not shrink the function but instead controls the effective learning rate by keeping weight norms from drifting (van Laarhoven, 2017; Zhang et al., 2019). Second, the sparsity story of generalizes into structured pruning and the lottery-ticket hypothesis (Frankle & Carbin, 2019), which finds sparse subnetworks that train to full accuracy from the original initialization — the modern descendant of a zeroed weight is a feature switched off. The elastic net's grouping intuition survives here too: correlated features are kept or pruned together rather than one being chosen arbitrarily.

The rest of the chapter

Parameter norm penalties are only the first of many regularizers; the rest of the chapter is a tour of methods that constrain the model without an explicit weight penalty. Each gets its own lesson.

MethodMechanismWhat it constrainsLesson
Dropoutrandomly zero units each stepco-adaptation; approximates an ensembledropout & data augmentation
Data augmentationsynthesize label-preserving inputsinvariance to nuisance transformsdropout & data augmentation
Early stoppinghalt before training loss bottoms outeffective training time an budgetearly stopping & parameter sharing
Parameter sharingtie weights across positionsparameter count, baked-in symmetryearly stopping & parameter sharing
Normalizationrescale activations per batch/layerinternal covariate shift; smoother lossnormalization

Several of these have an equivalence to weight decay. Early stopping limits how far the weights can travel from their initialization, which under the same quadratic model is again a shrinkage toward the origin — the constraint-ball picture from this lesson in another form. Every effective regularizer can be read as either a constraint or a prior, and that reading recurs throughout the chapter.

Footnotes

  1. Goodfellow, Deep Learning, §7.1 — Parameter Norm Penalties: the regularized objective and the convention of leaving biases unpenalized to avoid underfitting.
  2. Goodfellow, Deep Learning, §5.4.4 — the Bias–Variance Tradeoff: the decomposition of expected generalization error into squared bias, variance, and irreducible noise, and how capacity control moves along the resulting U-curve.
  3. Goodfellow, Deep Learning, §7.1.1 — Regularization (weight decay): the per-step multiplicative shrinkage and the eigenbasis analysis that shrinks low-curvature directions. 2
  4. Goodfellow, Deep Learning, §7.1.2 — Regularization: the constant-magnitude subgradient, soft-thresholding solution, and why yields exact zeros (sparsity) where yields only small weights.
  5. Goodfellow, Deep Learning, §7.2 — Norm Penalties as Constrained Optimization: the KKT view in which is the Lagrangian of the hard constraint .
  6. Goodfellow, Deep Learning, §5.6.1 — MAP Estimation: a weight penalty is a negative log-prior, with the Gaussian prior giving and the Laplace prior giving .
  7. Chollet, Deep Learning with Python, §4.4 — Adding Weight Regularization: the practitioner's view of weight decay and tuning its strength on a held-out validation set.

╌╌ END ╌╌