TL;DR
Early stopping is a rule for when to end training. While the model trains, you measure its error on a validation set after each pass over the data, called an epoch. When that error has not improved for a fixed number of epochs, the patience, you stop and return the weights from the best epoch, not the last one. The rule needs no change to the model and no extra training, and it works because a model that has trained for less time has had less chance to fit the noise.
Where you'll see it: in the training loop of almost every neural network, from image classifiers to Fine-Tuning of large language models, and in gradient-boosted tree libraries that stop adding trees once a validation score stalls.
Intuition
Tasting the sauce
A cook simmering a sauce tastes it as it reduces. Early on it is thin and flat. Then it gets better, reaches a point where it is as good as it will get, and then starts to become too salty and concentrated. The cook does not decide in advance how long to simmer. They taste, and stop when it tastes best.
Training a model works the same way. At the start the model is bad at everything. Its training error and its error on new data both fall. At some point the error on new data stops falling and begins to rise, while the training error keeps going down. The model has started to learn the accidents of the training set. Early stopping is the cook's tasting spoon: it measures the error on data the model is not trained on, and it stops at the moment that error is lowest.
Training time is a dial
The number of passes over the data is a dial for how complex the model effectively is. Ten passes leave the weights close to where they started, so the model is simple. A thousand passes let the weights move far, so the model can fit fine details. Nobody sets the dial by reasoning about the right complexity directly. Early stopping sets it by looking at the one signal that matters, error on data the model has not seen.
- training loss
- validation loss
Each curve here is idealised, but real curves have the same shape. The gap between the two curves after the validation minimum is the overfitting that early stopping is designed to avoid.
The math
Setting up the rule
Let be the weights after epoch . Let be the validation loss at that point, computed on a validation set that the optimiser never uses for gradient updates. Define the best epoch so far
which is the index of the lowest validation loss seen up to epoch . Here means "the index at which the minimum is attained". The patience is a positive whole number chosen in advance.
The stopping rule is: stop at the first epoch with
meaning that consecutive epochs have passed without beating the best loss. The returned model is , the weights from the best epoch, not .
Algorithm form:
- Set the best loss to infinity, the best epoch to 0, and the counter to 0.
- Run one epoch of Gradient Descent updates on the training set.
- Compute the validation loss.
- If it is lower than the best loss so far, save the current weights, record the epoch, and reset the counter to 0.
- Otherwise add 1 to the counter.
- If the counter has reached , stop and restore the saved weights. Otherwise go to step 2.
Why training time acts like a penalty
Early stopping is often described as a regularizer, a method that limits complexity the way an explicit penalty does. The cleanest way to see the link is a one-dimensional quadratic loss. Suppose the loss is
with curvature and best weight . Gradient descent with learning rate updates by . Write the distance to the optimum as . Then , so each step shrinks the distance by the factor .
Start from , so . After steps,
Now add an explicit L2 penalty to the loss. Its minimiser is
Both answers are the true optimum multiplied by a shrink factor that is less than 1, so both pull the weight toward 0. For small , the approximation holds, and the early-stopped weight becomes . When is small, , and when , . Matching these first-order shrinkages gives . The number of steps plays the role of an inverse penalty strength. Training longer means less regularization. The match is only approximate, and it becomes rough when is large, but it captures the main effect.
The validation curve is noisy
The validation loss is an estimate computed on a finite set, so it jitters from epoch to epoch even when the underlying trend is clear. That is why the rule uses patience instead of stopping at the first increase. A single bad epoch is usually noise, and stopping on it would stop too early.
Worked examples
Example 1: applying the patience rule to a table
Suppose the validation losses over the first ten epochs are:
| Epoch | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
|---|---|---|---|---|---|---|---|---|---|---|
| Validation loss | 0.90 | 0.62 | 0.48 | 0.41 | 0.39 | 0.40 | 0.42 | 0.41 | 0.43 | 0.44 |
Use patience .
- Epochs 1 to 5 each set a new best. The lowest loss so far is 0.39 at epoch 5, so the counter is 0.
- Epoch 6: loss 0.40 is higher than 0.39. The counter becomes 1.
- Epoch 7: loss 0.42 is higher than 0.39. The counter becomes 2.
- Epoch 8: loss 0.41 is higher than 0.39. The counter becomes 3.
- The counter has reached , so training stops after epoch 8.
- The restored model is the one from epoch 5, with validation loss 0.39.
Interpretation: the run went three epochs past its best point, and the weights saved at epoch 5 are the ones returned. The epochs 9 and 10 are never computed. Without early stopping, the last model would have had loss 0.44 on validation, which is worse by 0.05.
Example 2: how far a quadratic gets in t steps
Take , curvature , and optimum . Then and the formula gives .
- After 1 step: .
- After 5 steps: , so .
- After 10 steps: , so .
- After 20 steps: , so .
Interpretation: stopping at step 5 returns a weight of 0.67, which is a third of the way short of the optimum 1. That shortfall is a shrinkage toward 0, the same kind of effect as an L2 penalty. Stopping at step 20 returns a weight close to the optimum, with almost no shrinkage. The stopping time chooses how much shrinkage there is.
Tradeoffs and failure modes
Early stopping is cheap and usually a good default, but it has failure modes. Most come from the validation signal or from the patience setting.
| Situation | What goes wrong | Better choice |
|---|---|---|
| Validation set is small | Its loss is noisy, so the rule fires at a random epoch | Use more validation data, a larger patience, or smooth the curve before testing for improvement |
| Loss plateaus, then drops (warmup or learning-rate decay) | Patience runs out during the plateau and training stops before the drop | Start counting only after warmup, or raise the patience |
| Validation set is also used to report the final score | The reported number is optimistic, because the stopping point was chosen on that set | Keep a separate [[train-validation-test-split |
| Metric is accuracy on few examples | Accuracy moves in coarse steps, so improvement is often zero | Monitor the loss, which is smooth, and report accuracy separately |
| Model is very large and data is plentiful | Validation error can fall, rise, and fall again as capacity grows, which the Bias-Variance Tradeoff picture does not predict | Early stopping can still help, but read the full curve before trusting one stopping point |
| Compute budget is fixed and known | The rule is an extra check, not a saving | A fixed epoch count with a learning-rate schedule can be just as good |
The most common mistake is trusting the first stopping point without checking the curve. Plot the validation loss. If it is still falling when training stops, the patience was too small. If it is flat for a long time, the rule wastes compute.
A second mistake is forgetting to restore the best weights. Stopping at the right epoch but keeping the last weights gives back the overfitted model.
Early stopping is also an alternative to explicit regularization, not a substitute for it in every case. In the quadratic example it behaved like an L2 penalty, and in practice people often use both. L2 Regularization sets the penalty directly; early stopping sets the effective strength through training time.
History
Using a held-out set to decide when to stop training was common practice among neural-network researchers in the early 1990s, when training small networks by gradient methods was slow and overfitting was the main obstacle to using them. Practitioners stopped by eye or by a simple rule, and there was no agreed formal version.
Lutz Prechelt's 1998 review, "Early Stopping - But When?", collected the stopping criteria in use at the time and compared them on benchmark problems. It showed that the choice of criterion mattered, and that patience-style rules were a reasonable default. Later work in the early 2000s, including Caruana, Lawrence and Giles on overfitting in backpropagation networks, gave the approach a more systematic footing, and it became part of the standard training toolkit as deep learning grew.
Early stopping caught on because it is almost free. It needs one extra forward pass on the validation set per epoch and no change to the model or the loss. Modern large-scale results have complicated the simple picture, since very large models can keep improving on validation data long after the point a classical analysis would predict. Even so, the rule remains a standard default, and the question it asks is still the right one: does the model do better on data it has not seen?
Check yourself
QuestionWhat is the patience in early stopping, and what does it protect against?Show answer
Patience is the number of consecutive epochs allowed without a new best validation loss before training stops. It protects against stopping on a single noisy validation score. Without it, one bad epoch would end training, even if the loss was about to fall again.
QuestionValidation losses for epochs 1 to 6 are 0.80, 0.60, 0.55, 0.57, 0.56, 0.58. Patience is 2. At which epoch does training stop, and which weights are returned?Show answer
Epoch 3 sets the best loss of 0.55. Epoch 4 (0.57) is higher, so the counter becomes 1. Epoch 5 (0.56) is still higher than 0.55, so the counter becomes 2, which equals the patience. Training stops after epoch 5. The weights returned are those from epoch 3, the best epoch, not from epoch 5.
QuestionWhy does early stopping restore the best weights rather than keeping the final weights?Show answer
The final weights are the ones from the last epoch run, and by then the model may have started overfitting, since the rule only fires after the validation loss has already risen for several epochs. The best epoch is the point where the validation error was lowest. Returning those weights gives the model that generalised best among the ones the run produced.
QuestionYou train a model with a learning-rate warmup. Validation loss is flat for 10 epochs, then drops steadily. You set patience to 5. What happens, and what would you change?Show answer
Training stops during the flat stretch, around five epochs after the plateau begins, before the loss drops. The rule saw a plateau and mistook it for overfitting. Better choices are to start counting only after warmup ends, or to raise the patience above the length of the plateau. Plot the full curve before trusting the stop, and keep a test set for the final score.
Sources
- Goodfellow, Bengio, Courville, Deep Learning, Section 7.8, MIT Press. deeplearningbook.org
- Early stopping, Wikipedia. en.wikipedia.org/wiki/Early_stopping
- Zhang, Bengio, Hardt, Recht, Vinyals, Understanding deep learning requires rethinking generalization, 2016. arxiv.org/abs/1611.03530