Contents
09Other ways to prevent overfitting
L1, L2 and early stopping are not the only tools. This chapter covers the other classic ones and shows that several of them are also L2 in disguise.
9.1More data
The most reliable cure is more data. The variance of least squares in eigen-direction j is \sigma^2/d_j (proof of Theorem 1), and every new example adds to the eigenvalues d_j of X^\top X, which on average grow in proportion to n; variance falls like 1/n while bias is unchanged. Learning curves, the validation error as a function of n, show whether more data is still worth collecting (Episode 2).
9.2Data augmentation
When real data are expensive, we can create more from what we have by label-preserving transformations: a cat photo flipped left to right, cropped slightly or with its colours jittered is still a cat; a spoken word shifted in time is still the same word. Training on such variants teaches the model that its prediction should not change under those transformations, which is knowledge we have but the raw data do not show. Two classic results show how much this can help. Simard et al. (2003) trained a simple convolutional network on handwritten digits (MNIST) with randomly distorted copies of the training images and reached 0.4\% test error with smooth “elastic” distortions, against 0.6\% with affine distortions only. Krizhevsky et al. (2012) trained the AlexNet image classifier on random 224\times224 crops of 256\times256 images and their mirror images, which enlarged the training set by a factor of 2048; the authors report that without it the network overfit substantially, and that an extra random colour shift lowered the top-1 error by more than one percentage point.
9.3Training with noise is ridge regression
The simplest augmentation adds random noise to the inputs, and for linear regression its effect can be computed exactly. Replace X by X+E, where the entries of E are independent with mean 0 and variance s^2, and average the loss over the noise:
The middle term is zero because \E E=0. In the last term, row i of Ew is \sum_jE_{ij}w_j, a sum of independent terms with variance s^2\sum_jw_j^2, and there are n rows, so \E\|Ew\|^2=ns^2\|w\|_2^2. Therefore
training on noisy inputs is ridge regression with \lambda=ns^2. Intuitively, a model with large weights amplifies input noise into output noise, so noise in the inputs penalizes large weights. Bishop (1995) showed that, for small noise, training with input noise is equivalent to Tikhonov regularization for general (nonlinear) models as well.
Worked example 9. On the standardized diabetes data, least squares gives the correlated pair s1, s2 the weights -37.68 and 22.68. Stack 400 copies of the data, each with independent Gaussian noise of standard deviation s=0.3 added to every input, and fit least squares to the stacked data: the weights become -4.12 and -3.27. Ridge with \lambda=ns^2=442\cdot0.09=39.78 gives -4.29 and -3.21, and all ten weights of the two fits agree to within 0.2, the remaining Monte Carlo error.
9.4Dropout
Dropout (Srivastava et al., 2014) randomly removes units of a neural network during training: each input to a layer is kept with probability p and set to zero otherwise, and the kept values are divided by p so that their expectation is unchanged. At test time all units are used. A network can then no longer rely on any single unit, which discourages fragile co-adaptations between units. For linear regression the effect is again computable. Let \tilde X_{ij}=M_{ij}X_{ij}/p with independent M_{ij}\in\{0,1\}, \Pr(M_{ij}=1)=p. Then \E\tilde X=X and \Var\tilde X_{ij}=X_{ij}^2(1-p)/p, and the same calculation as for (19) gives
a ridge penalty in which each weight is penalized in proportion to the energy \sum_iX_{ij}^2 of its feature. Srivastava et al. (2014, §9.1) derive the same result for dropout without the division by p, where it reads \|y-pXw\|^2+p(1-p)\sum_j(\sum_iX_{ij}^2)w_j^2, the same up to rescaling w. For standardized features \sum_iX_{ij}^2=n and (20) is plain ridge with \lambda=n(1-p)/p. For other models dropout is an adaptive L2-like penalty (Wager et al., 2013). On permutation-invariant MNIST, with the same network and training, Srivastava et al. (2014, Table 9) report 1.62\% test error with L2 alone and 1.25\% with dropout plus L2; they recommend keeping hidden units with probability p=0.5 and inputs with p=0.8. AlexNet used dropout with p=0.5 in its two large fully connected layers, together with weight decay 0.0005 (Krizhevsky et al., 2012).
Worked example 10. With keep probability p=0.8 on the standardized diabetes data, (20) predicts ridge with \lambda=442\cdot0.2/0.8=110.5. Fitting least squares to 400 dropout copies of the data reproduces the ridge weights to within 0.19.
9.5Weight decay is not L2 under Adam
For plain gradient descent, (4) shows that an L2 penalty and multiplying the weights by a constant factor at every step (weight decay) are the same thing, up to rescaling \lambda by the learning rate (Loshchilov and Hutter, 2019, Proposition 1). Adaptive optimizers break this equivalence. Adam divides each coordinate of the gradient by a running estimate \sqrt{\hat v} of its typical size, and with an L2 penalty the penalty’s gradient 2\lambda w gets divided too, so weights with large or frequent gradients are regularized less than intended. Loshchilov and Hutter (2019) proposed to decouple the decay from the gradient step, which gives AdamW:
where \hat m and \hat v are Adam’s bias-corrected running averages of the gradient and of its square. On CIFAR-10 and ImageNet 32\times32, decoupling gave Adam a 15\% relative improvement in test error and made the best learning rate and the best decay factor much less dependent on each other (Loshchilov and Hutter, 2019). In deep learning libraries the weight_decay argument of SGD implements L2, while for Adam the decoupled version is a separate optimizer (AdamW).
9.6Other classic regularizers
Many other techniques also limit how closely a model can follow its training set: smaller models (fewer features, shallower trees, fewer units), pruning of decision trees, averaging many models (bagging and random forests, which reduce variance as discussed in Episode 2), and constraints built into the architecture, such as the weight sharing of convolutional networks. Each episode on those models covers them in detail.
Pause and think. Equation (19) says input noise is ridge. Would adding noise to the targets y regularize too?
Show the answer
No, not for least squares. \E\|y+\epsilon-Xw\|^2=\|y-Xw\|^2+n\Var(\epsilon), and the extra term does not depend on w, so the expected minimizer is unchanged; target noise only makes each fit noisier. Regularization comes from perturbing what the model multiplies by its weights.