Early stopping

Early stopping is ending a model's training when its performance on held-out validation data stops improving, before it starts to overfit the training data.

While a model trains, its error on the training data usually keeps falling. That does not mean it keeps getting better. After a while it can start memorising quirks of the training examples, and its performance on new data gets worse. Early stopping watches for that moment. Part of the data is held back as a validation set, the model is checked on it at regular intervals, and training stops when validation error stops improving or starts to rise.

Google's machine learning glossary describes early stopping as a method of regularisation: deliberately halting training while training loss is still going down, at the point where loss on validation data starts to rise. It can feel wrong to stop while the numbers are still improving, but the numbers that matter are the ones on data the model has not seen.

The simplest rule, described by the researcher Prechelt, is to stop as soon as the validation error is higher than at the previous check. Real validation curves are noisy and can have several dips, so most tools wait a little. In the Keras library, for example, an early stopping callback monitors validation loss by default; its patience setting is the number of epochs without improvement it tolerates before stopping, and restore_best_weights rolls the model back to its best epoch rather than keeping the last one. By default Keras uses a patience of zero and keeps the last weights, so developers usually change both.

A typical case: a team trains an image classifier for up to 100 epochs with patience set to 5. Validation loss bottoms out at epoch 32, fails to improve for five more epochs, and training stops at epoch 37 with the weights from epoch 32 restored. The team saves time and gets the better model.

Early stopping matters most when data is limited and a model can memorise it. Very large pre-training runs are in a different position: Meta reported in 2023 that its Llama 2 models still showed no sign of saturation after 2 trillion tokens. Research on double descent and grokking also shows that test performance can sometimes improve again after a long plateau, so stopping rules are a practical judgement, not a law.

Common questions

What is early stopping in machine learning?

It is a way of preventing overfitting by stopping training once the model's performance on a separate validation set stops improving. The model is checked on data it is not trained on, and training ends when that check starts to get worse.

What is patience in early stopping?

Patience is the number of checks, usually epochs, that training is allowed to continue without improvement before it stops. It stops noisy ups and downs in the validation curve from ending training too soon. In Keras the default patience is zero, so developers normally set it themselves.

Is early stopping a form of regularisation?

Yes. Google's machine learning glossary and standard texts treat it as regularisation, because it limits how closely the model can fit its training data, much as weight penalties or dropout do.

Does early stopping keep the best model?

Only if it is set up to. Training usually runs a few epochs past the best point before stopping, so tools such as Keras offer an option to restore the weights from the best epoch; otherwise you keep the final, slightly worse weights.

Finding more

Search for "early stopping", "validation loss patience" or "early stopping regularization" to learn more. Google's Machine Learning Crash Course and glossary, the documentation for training libraries such as Keras and PyTorch Lightning, and textbook treatments of regularisation are reliable. Be wary of fixed rules for patience or epoch counts; good values depend on the model and the data.

Working out what this means for your business?

Aileron Shift builds the systems behind this site: AI newsrooms that research, write and publish on their own, marketing automation and WordPress hosting for companies that need to move faster than their competitors.