§7.0–7.1.1Regularization: The Bias–Variance Trade · Parameter Norm Penalties · L² Weight Decay

Part II DL pp. 228–233 · ~5 min read

  • parameter norm penalty
  • l2 regularization
  • ridge regression / tikhonov regularization

§7.0 What regularization is really trading

Chapter 6 gave us powerful function approximators. Now the problem flips: a model with enough capacity to fit the training set will also fit its noise. Regularization is “any modification we make to a learning algorithm that is intended to reduce its generalization error but not its training error.” Almost every strategy in this chapter buys lower test error at the price of higher training error — and that is exactly the point.

The mechanism is the bias–variance trade : regularizing an estimator increases bias to reduce variance. An effective regularizer makes a profitable trade — cutting variance a lot while adding only a little bias. Chapter 5 framed three regimes: the model family (1) excludes the true process (underfitting, high bias), (2) matches it, or (3) contains it plus many other processes (overfitting, high variance). Regularization aims to move a model from regime 3 into regime 2.

Why the biggest model, then rein it in

In real deep learning the true data-generating process is almost never in our model family — generating natural images or speech would mean simulating the world. We are always fitting a square peg (the true process) into a round hole (our model family). So controlling complexity is not a matter of finding the model with exactly the right number of parameters. In practice the best-generalizing model is a large model that has been regularized well — not a small unregularized one. That reframing motivates the whole chapter.

§7.1 Parameter norm penalties

The oldest and simplest family adds a parameter norm penalty Ω(θ)\Omega(\boldsymbol{\theta}) to the objective:

Term by term

J~(θ;X,y)=J(θ;X,y)+αΩ(θ)\tilde{J}(\boldsymbol{\theta}; \boldsymbol{X}, \boldsymbol{y}) = J(\boldsymbol{\theta}; \boldsymbol{X}, \boldsymbol{y}) + \alpha\,\Omega(\boldsymbol{\theta})
JJthe ordinary training objective (e.g. cross-entropy) — fits the datadata fit
Ω(θ)\Omega(\boldsymbol{\theta})the penalty on parameter size — a measure of model complexity to be kept smallpenalty
α[0,)\alpha \in [0, \infty)the strength knob: α=0 is no regularization, larger α means more. Minimizing J̃ decreases BOTH the data loss and the parameter sizehyperparameter

Penalize weights, never biases

We write w\boldsymbol{w} for the weights that get penalized and θ\boldsymbol{\theta} for all parameters. A weight couples two variables, so fitting it well needs to observe both under many conditions — it is variance-prone and worth regularizing. A bias controls a single variable, needs little data to fit, and penalizing it tends to cause underfitting. So the penalty touches weights only. (You could use a different α per layer, but searching many coefficients is expensive, so one shared α is common.)

§7.1.1 L² regularization (weight decay)

The most common penalty is the L² norm, Ω(θ)=12w22\Omega(\boldsymbol{\theta}) = \tfrac12\lVert\boldsymbol{w}\rVert_2^2 L² regularization , better known as weight decay (and, elsewhere, ridge regression or Tikhonov regularization ). Look at what it does to a single gradient step (assume θ=w\boldsymbol{\theta}=\boldsymbol{w}):

Term by term

w(1ϵα)w    ϵwJ(w;X,y)\boldsymbol{w} \leftarrow (1 - \epsilon\alpha)\,\boldsymbol{w} \;-\; \epsilon\,\nabla_{\boldsymbol{w}} J(\boldsymbol{w}; \boldsymbol{X}, \boldsymbol{y})
(1ϵα)w(1 - \epsilon\alpha)\boldsymbol{w}the NEW part: before the usual update, the weight vector is multiplicatively shrunk toward the origin by a constant factor each stepthe “decay”
ϵwJ-\,\epsilon\nabla_{\boldsymbol{w}} Jthe ordinary gradient-descent step on the data loss, unchangedusual step
ϵ\epsilonlearning rate; the shrink factor 1−εα is just under 1 for small αstep size

That is one step. To see the effect over all of training, approximate JJ by a quadratic bowl around the unregularized optimum w\boldsymbol{w}^* and solve for where weight decay moves the minimum:

Where weight decay moves the optimum (equations 7.6–7.13)
J^(θ)=J(w)+12(ww)H(ww)\hat{J}(\boldsymbol{\theta}) = J(\boldsymbol{w}^*) + \tfrac12 (\boldsymbol{w}-\boldsymbol{w}^*)^\top \boldsymbol{H} (\boldsymbol{w}-\boldsymbol{w}^*)

step 1/7: Second-order Taylor approximation of J around the unregularized minimum w*. There is no first-order term because the gradient vanishes at a minimum, and H (the Hessian at w*) is positive semidefinite.

The picture: weight decay rescales w\boldsymbol{w}^* along the eigenvectors of the Hessian. Directions the objective cares about (large λi\lambda_i) barely move; directions it is indifferent to (small λi\lambda_i) get shrunk to nearly zero. Drag α\alpha, λ1\lambda_1, λ2\lambda_2 and watch the equilibrium w~\tilde{\boldsymbol{w}} slide between the objective’s optimum and the origin:

Fig 7.1 (interactive) — the objective (solid ellipses at w*) vs the L² penalty (dotted circles at 0); w̃ balances the two, decaying the low-curvature axis first
w₁w₂w*solid = objective (at w*) · dotted = L² penalty (at 0) · w̃ = equilibrium
shrink₁ = λ₁/(λ₁+α) = 0.29
shrink₂ = λ₂/(λ₂+α) = 0.75
w̃ = (0.86, 1.65)
w* = (3.00, 2.20)

The axis with the smaller eigenvalue (lower curvature — the objective barely changes there) gets shrunk toward zero; the high-curvature axis is almost untouched. Raise α to pull w̃ toward the origin; the low-λ coordinate collapses first.

Reading the equilibrium

At w~\tilde{\boldsymbol{w}} the two gradients cancel: the objective pulls toward w\boldsymbol{w}^* (solid arrow), the regularizer pulls toward the origin (dotted arrow). Along the flat axis the objective hardly resists, so the regularizer wins and that coordinate collapses; along the steep axis the objective resists strongly, so weight decay barely dents it. Only directions that genuinely reduce the loss survive.

The linear-regression special case

For linear regression the cost is truly quadratic, so the analysis is exact. Weight decay changes the normal equations by adding α\alpha to the diagonal:

Term by term

w=(XX)1Xy        w=(XX+αI)1Xy\boldsymbol{w} = (\boldsymbol{X}^\top\boldsymbol{X})^{-1}\boldsymbol{X}^\top\boldsymbol{y} \;\;\longrightarrow\;\; \boldsymbol{w} = (\boldsymbol{X}^\top\boldsymbol{X} + \alpha \boldsymbol{I})^{-1}\boldsymbol{X}^\top\boldsymbol{y}
XX\boldsymbol{X}^\top\boldsymbol{X}proportional to the input covariance (1/m)XᵀX — its diagonal entries are the variances of the input featurescovariance
+αI+\,\alpha \boldsymbol{I}weight decay adds α to every diagonal entry — the model “perceives” each input as having higher variancethe fix
\Rightarrowso it shrinks the weights on features whose covariance with the output is low compared to α — noisy/irrelevant features are down-weightedthe effect

Next: L¹ regularization (which makes weights exactly zero), norm penalties as constrained optimization, and dataset augmentation — L¹, constraints & augmentation.

Check yourself — the bias–variance trade and L² weight decay

1.What trade does regularization make, and what is an 'effective' regularizer?

2.Why does the parameter norm penalty regularize the weights w but leave the biases unpenalized?

3.Weight decay rescales the component of w* along the i-th Hessian eigenvector by λᵢ/(λᵢ+α). What happens along a LOW-curvature direction (small λᵢ)?

4.In WeightDecayLab, set λ₁ = 0.4 (flat axis), λ₂ = 3 (steep axis), and raise α from 0. Which coordinate of w̃ collapses toward zero first?

5.For linear regression, L² regularization changes the solution to w = (XᵀX + αI)⁻¹Xᵀy. What is the intuitive effect of the +αI?

5 questions