AdamW › The Purpose of Regularization

Michael BrenndoerferApril 20, 20253 min read
Language AI HandbookAll chapters
Part 10 of 67Neural Network Foundations
Chapter 69AdamW › The Purpose of Regularization
Reading section 2 of 15 · The Purpose of Regularization · 3 minSection 2 of 15 · 3 min

Book contents

Section 2 of 15 · 3 min read

AdamW › The Purpose of RegularizationOne section · Sections in this chapter2 / 15 ↓
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

When training a neural network, the optimization objective is to minimize the loss on training data. But the true goal is generalization: you want the model to perform well on new, unseen data. These objectives can conflict. A model with enough capacity can memorize training examples perfectly while learning nothing transferable about the underlying patterns.

The formal version of this tension is the bias-variance tradeoff. A model with too few parameters underfits: it cannot capture the true patterns in the data. A model with too many parameters, trained without constraints, overfits: it learns the training data including its noise, producing predictions that are precise on training examples but poor on new ones. Regularization techniques introduce controlled constraints that push the model toward simpler solutions, reducing the risk of overfitting without unnecessarily limiting its capacity.

The Role of Weight Magnitude

The connection between weight magnitude and generalization is intuitive once you think about what large weights imply. A neural network with very large weights is one where small changes in the input produce large changes in the output. This sensitivity to input variations means the network is capable of memorizing fine-grained patterns in the training data, including noise. A network with small weights, by contrast, produces outputs that change smoothly with inputs, which corresponds to learning more general patterns rather than specific examples.

This intuition underlies L2 regularization, which applies a direct penalty to large weights. The idea is that among all solutions that fit the training data approximately equally well, we prefer the one with the smallest weights. This preference is a prior belief about the structure of the problem: we expect the true underlying function to be smooth and not reliant on any individual input feature having overwhelming influence.

There is also a Bayesian interpretation. If you place a zero-centered Gaussian prior on the weights, p(θ)∝exp⁡(−λ∥θ∥2)p(\theta) \propto \exp(-\lambda \|\theta\|^2), then maximum a posteriori (MAP) inference under this prior corresponds exactly to training with L2 regularization. The regularization coefficient λ\lambda controls the strength of this prior, effectively saying how much you trust your prior belief about small weights versus the evidence from the data.

In practice, regularization helps most when the model is large relative to the training data, when the training data is noisy or biased, or when you intend to fine-tune the model on a small later dataset. For large language models, all three of these conditions often apply simultaneously, which is why regularization plays an large effect in LLM training despite the enormous dataset sizes involved.