When parameters get large, a network can learn a bumpy function. The classic fix from regression is to charge for the size of the weights. Five views of what that charge does: to each step, to the answer, to the fitted function, inside Adam, and to which classifier you get.
Homework 2.1 adds a penalty to the loss, . Its gradient is , so a gradient descent step becomes a shrink followed by the usual step. Play both runs from the same start, or drag the start point.
The same penalty can be read as a budget: find the best weights whose size is at most r. Measured by L2 the budget is a ball; measured by L1, |θ1| + |θ2|, it is a diamond. Drag the loss’s minimum (the cross) in either panel.
Twelve noisy points and a polynomial with twelve coefficients: exactly enough to pass through every point. The penalty λ·‖w‖² on the coefficients trades fitting the points against keeping them small. Slide λ from nothing to a lot.
For plain gradient descent, adding λ/2·‖θ‖² to the loss and shrinking the weights every step are the same thing (part 1). Inside Adam they are not, because Adam divides each weight’s step by the size of that weight’s own recent gradients, and whatever you put into the gradient gets divided too, including the penalty.
The only difference is where λθ goes. In Adam with L2 it is added to the gradient, so it passes through m and v and gets divided by √v̂, which is roughly the size of that weight’s gradients. In AdamW it is added after the division, so every weight loses the same fraction per step:
A weight with large gradients (big √v̂) barely feels the Adam-with-L2 decay. A weight with tiny gradients has its decay divided by a tiny number, and when its gradients are smaller than λθ the decay dominates v itself, so the weight moves toward 0 at Adam’s full step size η per step. Below, eight weights all start at 1 with gradients of different sizes that flip sign every step and average to zero, so the decay is the only force that moves them.
Train a linear classifier, logistic regression with weight decay λ, on two separable classes. With no decay its direction heads for the max-margin separator, the one that stays as far as possible from the closest points. With strong decay it heads somewhere quite different: the mean difference μ+ − μ−, the direction of the old nearest-mean (“Euclidean” or minimum-distance) classifier, which ignores the individual points and looks only at the two class averages. The data here is built so those two directions disagree. Switch to a few stragglers for data where a third direction, Fisher’s (explained below), disagrees with both.
Why the mean difference. Write the logistic loss in terms of each point’s margin mi = yi(w·xi + b), with yi = ±1. Strong decay keeps w tiny, so every margin is near 0, where the loss is nearly a straight line:
Keeping only the straight-line part, the objective is linear in w plus the decay, and its minimum is a scaled copy of the average of yixi, which for balanced classes is the mean difference:
Every point pulls on w equally, however far it is from the boundary, so only the averages survive. Why max margin. With little decay on separable data, w can grow without bound, and as it grows the loss e−m of all but the closest points becomes negligible; only the points nearest the boundary still pull, and w/‖w‖ approaches the max-margin direction (Rosset, Zhu & Hastie, 2004), the same direction plain gradient descent drifts toward with no decay at all (Soudry et al., 2018).
In between: measuring distance with the data’s own ruler. The nearest-mean rule measures distance with an ordinary ruler, the same in every direction. But these two clouds are long and thin. Along their length, points routinely sit far from their class mean; across the gap, even a short distance is unusual. A fairer ruler measures distance in units of the data’s spread in each direction, so a step along a long direction counts for less than the same step along a narrow one. That is the Mahalanobis distance,
where Σ is the covariance of each class around its own mean. With this ruler the classify-by-nearest-mean rule is still linear, and its weight vector is Σ−1(μ+ − μ−): the mean difference with the long directions discounted. That is Fisher’s linear discriminant, also called LDA. On the stretched clouds it lands within a few degrees of the max-margin direction, because once the long direction of the clouds is discounted, what is left is mostly the direction across the gap. But the two answer different questions. Fisher summarizes each whole cloud by its mean and spread; max margin looks only at the handful of points nearest the gap. Switch to a few stragglers: two wide-apart clouds set the means and spreads, while two odd points per class (circled) sitting in the gap are the only points near the boundary. Now the three directions separate, and the decay path visits all three: the mean difference at strong decay, turning toward Fisher at moderate decay, and on to max margin at weak decay.
Moderate weight decay sits between the two rulers. Keep one more term of the expansion, the m²/8, and it adds a penalty that depends on how the data is spread. The minimum then works out to
(the class separation inside the covariance only adds a multiple of μ+ − μ−, which does not change the direction). When λ is large, the 4λI term swamps Σ, and w is the plain mean difference: the ordinary ruler. As λ shrinks, Σ takes over and w turns toward Fisher’s direction: the data’s ruler. This is exactly ridge-regularized Fisher discriminant, with the decay playing the role of the ridge. It holds only while the margins stay small; with very little decay w grows large, and then only the closest points matter and the direction becomes the max-margin one. So the decay dial moves the classifier from “trust only the averages, measured with an ordinary ruler,” through “trust the averages, measured with the data’s own ruler,” to “trust only the closest points.”