regularization
Regularization is any change to how a machine learning model is trained that aims to make it perform better on new data, usually by discouraging it from fitting its training examples too closely. It’s the standard remedy for overfitting, and it typically accepts a slightly higher training error in exchange for a lower error on held-out data.
The most common form adds a penalty term to the loss function that grows with the size of the model’s weights. A coefficient, itself a hyperparameter, sets how hard that penalty pulls against fitting the data. In the widget below, raising the strength of an L2 penalty on a degree-9 polynomial first tames its wild swings and lowers the validation error, then flattens the curve until both errors climb:
Common regularization techniques range from weight penalties to changes in the training process or the data:
- L2 regularization: Penalizes the sum of squared weights, shrinking all of them toward zero without reaching it. Ridge regression uses this penalty.
- L1 regularization: Penalizes the sum of absolute weights and drives some of them exactly to zero. Lasso relies on it as a form of feature selection.
- Weight decay: Shrinks every weight by a small fraction at each update step. With plain gradient descent, this matches an L2 penalty.
- Dropout: Randomly switches off units of a neural network during training, so no unit can depend on specific partners.
- Early stopping: Halts training once the loss on a validation set stops improving.
- Data augmentation: Expands the training set with modified copies of its examples, such as cropped or flipped images.
Weight decay is the form that carries over most directly to large language models. Meta’s original LLaMA models, for example, were trained with the AdamW optimizer and a weight decay of 0.1.
AdamW exists because folding an L2 term into the Adam optimizer weakens the penalty on weights with large gradients. The paper Decoupled Weight Decay Regularization fixed this by applying the decay separately from the gradient step. PyTorch’s AdamW uses a default coefficient of 0.01.
Related Resources
Tutorial
Logistic Regression in Python
In this step-by-step tutorial, you'll get started with logistic regression in Python. Classification is one of the most important areas of machine learning, and logistic regression is one of its basic methods. You'll learn how to create, evaluate, and apply a model to make predictions.
For additional information on related topics, take a look at the following resources:
- Python AI: How to Build a Neural Network & Make Predictions (Tutorial)
- Linear Regression in Python (Tutorial)
- Practical Text Classification With Python and Keras (Tutorial)
- Build a Recommendation Engine With Collaborative Filtering (Tutorial)
- Building a Neural Network & Making Predictions With Python AI (Course)
- Python AI: How to Build a Neural Network & Make Predictions (Quiz)
- Starting With Linear Regression in Python (Course)
- Linear Regression in Python (Quiz)
- Learn Text Classification With Python and Keras (Course)
Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.
By Martin Breuss • Updated Nov. 16, 2026