Regularizing Neural Networks
Weight decay, dropout, data augmentation and early stopping.
Classical regularization adds a penalty to the loss and proves a bound. Deep networks are regularized mostly by procedures: shrinking weights inside the optimizer, dropping units, transforming inputs, mixing examples, softening labels, stopping early. Each one turns out to be a penalty, a prior or an invariance in disguise, and the disguise matters. This lesson derives what each procedure actually optimizes and where the textbook equivalences break.
What you’ll learn
- Show why weight decay and an L2 penalty diverge under adaptive optimizers, and state the -constrained problem that AdamW implicitly solves.
- Derive dropout's second-order penalty for generalized linear models, and prove that weight scaling computes the geometric-mean ensemble of a softmax layer exactly.
- Prove that augmenting with an exact symmetry leaves the expected loss unchanged and lowers its variance, and analyze mixup and label smoothing as changes of the training target.
- Explain early stopping as a spectral filter, state its guarantees, and explain why it resists label noise.
Weight decay is not one thing
Krogh & Hertz (1992) proved that for linear networks a weight decay term does two useful things: it suppresses components of the weight vector the problem does not need, by picking the smallest solution, and with the right strength it damps the effect of noise in the targets. For plain SGD, decay and an L2 penalty are the same update, .
With an adaptive optimizer they are different algorithms. Ignoring momentum, Adam with an L2 penalty steps coordinate by , so the decay rate of is about : weights whose gradients have been large are regularized much less. Loshchilov & Hutter (2019) proposed decoupled decay (AdamW), which shrinks every weight by the same factor outside the adaptive step, and found it generalized markedly better with Adam. Adaptive & Second-Order Methods derives the two updates; here the question is what AdamW converges to.
With deterministic gradients and , Adam's direction behaves like a smoothed , the steepest-descent direction for the norm. Take that limit, sign descent with decoupled decay:
If coordinate is at rest while , then : it sits exactly on the boundary , on the side toward which the loss keeps decreasing. A coordinate strictly inside that range can therefore come to rest only where .
Every rest point therefore satisfies the Karush–Kuhn–Tucker conditions of the box-constrained problem below: each coordinate is either interior with zero partial derivative, or on a face of the box with the negative gradient pointing outward.
So the two "weight decays" express different priors: an ball around the origin, or an box whose size is set by . A third reading applies to weights that feed a normalization layer, where the loss ignores the scale of the weights altogether and decay acts only through the effective learning rate (Normalization Layers). Which reading applies depends on the optimizer and on the architecture, not on the name of the hyperparameter.
You train with Adam and an L2 penalty added to the loss. Which weights are effectively regularized least?
- Those whose recent gradients have been largest
- Those whose recent gradients have been smallest
- Those with the largest values
- None: every weight decays at the same relative rate
Show the answer
A. Those whose recent gradients have been largest
The penalty's gradient is divided by along with the loss gradient, so the decay rate is about , smallest where gradients have been large. Decoupled decay removes this coupling.
Dropout: an ensemble and an adaptive penalty
Dropout trains a random subnetwork at every step. With droppable units there are subnetworks sharing one set of weights, and at test time a single deterministic network stands in for their average. How good is that stand-in? For one softmax layer it is exact, in a specific sense.
Let the input units be kept independently with probability (mask ), giving logits and predictions . Combine the subnetworks by a weighted geometric mean, renormalized over classes:
The constant collects the log-normalizers of the individual softmaxes, which are the same for every class , so it disappears when we renormalize. The averaged logit is linear in the mask, with :
So running the full layer with weights scaled by (or, in the inverted form, training with and testing unscaled) returns exactly the normalized geometric mean of all subnetworks. With hidden nonlinearities the identity becomes an approximation (Baldi & Sadowski, 2013; Goodfellow, Bengio & Courville, 2016, §7.12).
A GLM with natural parameter (in this derivation is not a learning rate) has negative log-likelihood (for logistic regression ). Inverted dropout replaces by , which leaves the mean unchanged and adds variance:
The term is linear, so its expectation is unchanged. Expand to second order around ; the first-order term vanishes in expectation:
Summing over the training set, dropout adds the penalty below, with . Since is the GLM's Fisher information, each is charged in proportion to the -th diagonal entry of that matrix: a feature costs most when it takes large values on examples where the model is uncertain. For squared loss () the expansion is exact, and the charge on is , with the -th column of : ridge with a separate strength for each feature.
Logistic regression is trained with dropout on its inputs, keep probability . One training example has a single nonzero feature with weight , and the intercept (which is never dropped) makes the current prediction on it . What is this example's contribution to the dropout penalty ?
Show the answer
0.5
and , so the contribution is . Had the model predicted , it would be , 25 times smaller: dropout regularizes hardest where the model is unsure. The expansion is only a guide at this noise level: averaging the actual loss over the two possible masks gives an increase of , not , because noise of variance 4 on the logit is not small.
A third view treats dropout as approximate Bayesian inference: Gal & Ghahramani (2016) showed that training with dropout approximately minimizes a variational objective for a deep Gaussian process, which licenses keeping dropout on at test time and averaging many stochastic passes. Uncertainty in Neural Networks examines what that "MC dropout" uncertainty is worth.
Augmentation, mixup and label smoothing
Data augmentation replaces each example's loss by its average over transformed copies. When the transformations form a group under which the data distribution is exactly symmetric, this has a clean consequence (Chen, Dobriban & Lee, 2020).
Suppose a compact group acts on inputs and leaves the data distribution unchanged: for each , the pair has the law of (a horizontally flipped photo of a cat is as likely as the original, with the same label). Draw uniformly (from the Haar measure), independently of , and define the augmented loss
For each fixed , has the distribution of , so the expected loss is unchanged, for every : augmentation by a true symmetry does not move the population risk or its minimizers.
The law of total variance, conditioning on , then shows that averaging over the orbit can only reduce the variance of each example's loss, and hence of the empirical risk:
This is Rao–Blackwellization: the augmented empirical risk estimates the same objective with less noise, and Chen, Dobriban & Lee turn it into a smaller (asymptotic) covariance for the estimator itself. If the symmetry is false, step 2 fails: a rotation by 180° maps 6 to 9, and augmenting digits with it changes the risk being minimized.
Mixup (Zhang, Cissé, Dauphin & Lopez-Paz, 2018) trains on convex combinations of pairs, and for one-hot labels, with . Since cross-entropy is linear in its target, the loss is at : the network is asked to behave linearly between training examples. Unlike flips and crops, this is not a symmetry of the data. Zhang, Deng, Kawaguchi, Ghorbani & Zou (2021) expanded the mixup loss to second order and showed it equals the ordinary loss plus data-adaptive regularization terms, and that it approximately bounds an adversarial loss from above, consistent with mixup's robustness to small attacks.
Label smoothing (Szegedy, Vanhoucke, Ioffe, Shlens & Wojna, 2016) replaces the one-hot target with . Because , the best prediction for a training example is itself, and with a softmax output that fixes the logit gaps:
With classes and smoothing , what is the optimal gap between the true class's logit and any other logit?
Show the answer
4.51
, so the target probabilities are for the true class and for each other class. Gradient descent on the smoothed loss for a single example converges to exactly this gap.
Müller, Kornblith & Hinton (2019) found that label smoothing improves calibration as well as accuracy, and that it pulls the penultimate-layer representations of each class into tight, equally spaced clusters. That erases information about which wrong classes an example resembles, so a teacher trained with label smoothing distills much worse into a student network.
You augment a handwritten-digit dataset with random rotations of up to 180°. Compared with no augmentation, what does the derivation above predict?
- Lower variance at no cost, since augmentation never hurts
- No effect, since rotations do not change pixel statistics
- A guaranteed reduction of the test error
- A changed objective, because the data distribution is not rotation-invariant: some rotated 6s are 9s
Show the answer
D. A changed objective, because the data distribution is not rotation-invariant: some rotated 6s are 9s
The risk is preserved only when the transformed data are distributed like the originals with the same labels. Large rotations break that, so the augmented loss rewards predicting the same label for 6 and an upside-down 6, which looks like a 9. Small rotations are a much safer approximate symmetry.
Early stopping, and the order in which networks learn
Run gradient descent on the empirical squared loss over an RKHS with kernel , from (the classical Landweber iteration). On the training inputs, with Gram matrix , the vector of fitted values evolves linearly:
In the eigenbasis of , with eigenvalues , component of is passed through a filter (take , so every factor lies in ). Compare kernel ridge regression with penalty :
Both keep directions with large and suppress those with small, with the crossover at and respectively: stopping after steps has roughly the effect of ridge with , and the effective number of fitted directions grows with .
Yao, Rosasco & Caponnetto (2007) analyzed this algorithm, solved the bias–variance trade-off over the number of iterations, and derived a stopping rule with probabilistic convergence rates, noting the connections to Landweber iterations and boosting. In the simplest setting the equivalence with ridge is sharp: for least squares, the estimation risk of gradient flow at time never exceeds 1.69 times that of ridge with , whatever and the true coefficients (Ali, Kolter & Tibshirani, 2019).
For networks, the kernel picture is exact in the lazy (neural tangent kernel) regime of Infinite Width: NTK & Mean-Field Limits: training fits the large-eigenvalue, typically smooth directions first. Arpit et al. (2017) observed the same ordering empirically: networks learn simple patterns before they memorize noise. Li, Soltanolkotabi & Oymak (2020) proved a version of it. Under a clustered-data model, gradient descent on an overparameterized network fits the correct labels in the first iterations while staying near its initialization, and it must travel much farther to fit corrupted ones, so early stopping is provably robust to a constant fraction of label noise.
A network is trained on data in which 20% of the labels were flipped at random. Training accuracy reaches 100% after 200 epochs, while validation accuracy peaked around epoch 30. Why is early stopping so effective here?
- Gradient descent fits the consistent structure first and memorizes the flipped labels later, so the early iterates have learned the signal but not the noise
- Early stopping removes the flipped examples from the training set
- The learning rate is larger early in training
- Validation accuracy always peaks at epoch 30
Show the answer
A. Gradient descent fits the consistent structure first and memorizes the flipped labels later, so the early iterates have learned the signal but not the noise
Clean examples agree with each other, so their gradients add up and are fit quickly; each flipped label contradicts its neighbors and can be fit only by moving far from the initialization, late in training. Stopping between the two phases keeps the signal.
Key takeaways
- With SGD, weight decay and an L2 penalty coincide. With Adam, an L2 penalty decays weights by , while AdamW, if it converges, reaches a KKT point of subject to .
- Weight scaling computes the normalized geometric mean of all dropout subnetworks of a softmax layer exactly. For GLMs dropout adds the penalty , an L2 penalty weighted by the diagonal Fisher information.
- Augmenting with an exact symmetry keeps the risk and lowers its variance (Rao–Blackwellization); mixup and label smoothing change the target instead, and smoothing caps the optimal logit gap at .
- Stopping gradient descent after steps damps the small-eigenvalue directions of the kernel much as ridge with does; because gradient descent fits consistent structure before isolated noise, early stopping is provably robust to a fraction of corrupted labels in clustered-data models.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
According to Xie & Li (2024), if full-batch AdamW with decay (and a suitable non-increasing schedule) converges, its limit is a KKT point of which problem?
- subject to
- subject to
Show the answer
C. subject to
Adam behaves like a smoothed sign descent, the steepest descent of the geometry, and sign descent with decoupled decay has its fixed points exactly at the KKT points of the box of radius .
For logistic regression, the second-order dropout penalty weights each training example by . Where does it regularize most?
- On examples the model classifies confidently and correctly
- On features that are active on examples whose predicted probability is near
- Equally on all features, like ridge regression
- Only on misclassified examples
Show the answer
B. On features that are active on examples whose predicted probability is near
The penalty is , and peaks at . Features that matter only on confidently classified examples are barely penalized: the regularization adapts to the data, unlike ridge.
If the data distribution is exactly invariant under a group , how does replacing each example's loss by its average over change the training objective?
- It lowers the expected loss of every parameter vector
- It adds a penalty proportional to the size of the group
- It keeps the expected loss of every parameter vector the same and lowers its variance
- It changes the minimizers of the population risk to -invariant functions only
Show the answer
C. It keeps the expected loss of every parameter vector the same and lowers its variance
For each , has the same law as , so the orbit-averaged loss has the same mean. By the law of total variance its variance is smaller by : a Rao–Blackwellized estimate of the same risk.
With label smoothing over classes, what is the optimal gap between the true-class logit and any other logit for a training example?
- , as with plain cross-entropy
Show the answer
A.
The smoothed cross-entropy is minimized at , with on the true class and elsewhere. The softmax logit gap is the log of the ratio of those two probabilities.
Further reading
- S. Xie & Z. Li, "Implicit bias of AdamW: ℓ∞-norm constrained optimization," ICML (2024).
- S. Wager, S. Wang & P. Liang, "Dropout training as adaptive regularization," NeurIPS (2013).
- S. Chen, E. Dobriban & J. H. Lee, "A group-theoretic framework for data augmentation," Journal of Machine Learning Research 21, 1–71 (2020).
- R. Müller, S. Kornblith & G. Hinton, "When does label smoothing help?," NeurIPS (2019).
- Y. Yao, L. Rosasco & A. Caponnetto, "On early stopping in gradient descent learning," Constructive Approximation 26(2), 289–315 (2007).