Ves al contingut

Aquest vídeo i el seu text són en anglès.

Early stopping: knowing when an AI should stop training

AI Concepts #079

Practice scores keep improving after a model stops getting better at new data. Early stopping watches a set of held-back examples and halts at the right time.

En detall

What early stopping is

Training an AI model is a loop: show it examples, measure how wrong it is, adjust, repeat. That measure of wrongness is called the loss, and lower is better. On the examples the model trains on, the loss usually keeps falling for as long as you let it run.

The catch is that the training loss is not the real goal. The real goal is doing well on data the model has never seen. Early stopping keeps an eye on exactly that. It sets aside some examples the model never trains on, called the validation set, checks the loss on them as training goes on, and halts training as soon as that loss starts to climb.

What the video shows

The video shows two scores pulling apart. The practice score keeps improving the longer the AI trains, but the results on new data eventually get worse. Early stopping watches both and stops at the best moment, instead of letting training run on.

Why more training can make things worse

At first, the model picks up the general pattern, and both scores improve together. Later, it starts memorising the specific training examples, including their quirks and random noise. That still lowers the training loss, so the practice score looks better than ever. But memorised quirks are useless on new data, and can even mislead, so the validation loss turns upward. This is overfitting, and early stopping aims to halt training just before it sets in.

An everyday example

Imagine revising for an exam with the same 50 practice questions every night. For the first few rounds you are learning the ideas. After enough rounds you simply remember that question 12 is "B". Your score on those 50 questions climbs to 100%, but it tells you very little about the real exam.

Now imagine a friend who quizzes you each evening with fresh questions you have never practised. While their quiz scores keep going up, keep studying. The evening they start going down, stop: you have switched from understanding to memorising. The friend's quiz is your validation set.

How to spot the moment

Look at the two loss curves side by side:

| Training loss | Validation loss | What it means | |---|---|---| | Falling | Falling | Still learning. Keep going. | | Falling | Rising | Memorising. Time to stop. |

That second row is exactly the pattern our course's troubleshooting table matches with early stopping. (Reading loss curves in general is a separate concept in this series.)

Why it matters

Early stopping is one of the simplest tools against overfitting. It changes nothing about the model itself; it is only a decision about when to stop, based on data the model has not trained on. It also means you do not spend extra training time making the model worse. Our course lists it with the other standard defences, such as penalties on large weights, dropout and data augmentation.

The bigger lesson is a healthy suspicion of practice scores. A number that keeps improving on data the model has already seen is not, on its own, evidence that the model is getting better.

Learn it step by step in Chapter 6 of our free course AI From Scratch: Getting It to Train, and Getting It to Generalise.

També a

Més d’aquest capítol

Text escrit amb l’ajuda d’AI a partir del capítol 6 del nostre curs gratuït.