Weight Decay › A Worked Example: Weight Decay Step by Step
Language AI HandbookAll chapters Weight Decay › A Worked Example: Weight Decay Step by StepOne section · Sections in this chapter3 / 11 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
To make the math concrete, let us trace through a single weight decay update for a scalar weight.
Suppose we have a single weight , a task loss gradient at this point of , a learning rate , and a weight decay coefficient .
Without weight decay, the standard SGD update is:
The weight increases from 2.5 to 2.508 because the gradient is negative (the loss decreases as the weight increases).
With weight decay, the update adds the regularization gradient :
The weight still increases, but by less. The task loss gradient wanted to push the weight up by 0.008, but the regularization gradient is opposing this by adding a positive component (0.0025) to the total gradient update in the direction of shrinking the weight.
Equivalently, using the shrinkage form:
The two forms give the same result, as expected. The shrinkage form makes visible that the weight is first multiplied by 0.999 (a 0.1% reduction) and then adjusted by the task gradient. Over 1000 steps with no gradient contribution, the weight would decay from 2.5 toward zero following a geometric series: .
This exponential decay toward zero is where the name "weight decay" originates. At every step, the optimizer applies a small multiplicative shrinkage to each weight, continuously counteracting the tendency for weights to grow large. The task gradient can push weights away from zero when a feature improves the predictions, but it must constantly overcome the decay pressure to do so.
The Equilibrium Weight Magnitude
There is an instructive way to think about what weight decay does to the steady-state weight magnitude. Suppose a weight has converged and is no longer changing on average. At that point, the average contribution of the task gradient must exactly cancel the contribution of the weight decay term:
This means the steady-state magnitude of the weight is determined by the ratio of the expected task gradient to the weight decay coefficient:
A stronger weight decay (larger ) forces weights to be smaller in equilibrium, which is only possible if the gradient signal for that weight is also stronger. Parameters that contribute little to reducing the task loss (small gradients) will be pushed toward zero. Parameters that contribute strongly (large gradients for important features) will stabilize at larger values. Weight decay thus implements a soft version of importance weighting: only weights that are useful enough to overcome the decay pressure remain large.
This equilibrium perspective also clarifies why weight decay cannot cause catastrophic collapse. If the weight decay were too aggressive and drove all weights toward zero, the model would make random predictions, generating large gradients that push weights back up. The equilibrium is stable: the task gradient always provides a restoring force proportional to how poorly the model performs. Weight decay shifts the equilibrium point but cannot collapse the model to zero as long as the task has a learnable signal.
Overfitting Without Regularization: A Concrete Illustration
To see why large weights are the mechanism behind overfitting (rather than just a symptom), consider what happens during unconstrained gradient descent on a small dataset. The optimizer follows a path of steepest descent in the loss landscape, always moving in the direction that most rapidly reduces training loss. Early in training, this is fine: both training and validation loss decrease as the model learns recurring patterns. But as the model approaches the training data manifold, the loss surface develops sharp minima that correspond to memorizing individual training examples.
These sharp minima are characterized by large weights. The model learns to respond with high confidence to specific training examples by amplifying the weights connecting the relevant input features to the output. This amplification is invisible to the optimizer, which sees only that training loss continues to decrease. But you can see the consequence in the weight norms: they grow throughout training as the model memorizes more and more.
Weight decay changes the shape of the loss surface. The penalty term adds a bowl-shaped component to the total loss, converting sharp minima into smoother, broader minima. The optimizer can no longer rest in narrow memorization minima because the cost of staying there (the penalty for large weights) exceeds the benefit (the reduction in training loss). Instead, it settles in broader minima that correspond to learned patterns rather than memorized examples. These broader minima are precisely the solutions that generalize well to unseen data.