AI Hints
Home›Generative AI Tutorial›Data, Generalisation and Foundation Models
Generative AI · Lesson 8 of 77

Overfitting and Generalisation

Learning the lesson, not just memorising the answers.

⏱ 2 min read▶ Video at 22:10🎓 Free
Watch this lesson in the Generative AI courseWatch on YouTube ↗Full Generative AI course

Imagine a student who memorises last year's exam answers word for word. They score perfectly on that exam, and then fail the real one. Models can do the same. In this lesson, you will meet this problem, called overfitting, and the simple ideas that prevent it.

Overfitting and Generalisation
From the video: Overfitting and Generalisation
  • A student who memorises answers
  • Perfect on old exams, lost on new ones
  • How to prevent it

Memorising versus understanding

A good model generalises. That means it works well on new examples it has never seen. A bad model overfits. It has memorised the training examples, including their quirks and noise, so it fails on anything new. The tell tale sign is a big gap. Great scores on the training data, and poor scores on the test data.

Overfitting

  • Memorises the training data
  • Learns noise and quirks
  • Great on training, poor on new data
  • Like copying last year's answers

Generalising

  • Learns the underlying pattern
  • Ignores the noise
  • Good on training and new data
  • Like truly understanding the topic

Three simple cures

There are three classic cures. First, more data, and more variety, so memorising is impossible. Second, a simpler model, with fewer weights, that has less room to memorise. And third, techniques like dropout, where we randomly switch off neurons during training, so the network cannot rely on any single one. And we always watch the validation score, and stop training when it stops improving.

  1. More and more varied datamemorising becomes impossible
  2. A simpler modelless room to memorise
  3. Dropoutrandomly switch neurons off
  4. Early stoppingstop when validation stops improving

Training too long

Here is the early stopping idea. As training continues, the error on the training data keeps falling. But at some point, the model starts memorising, and its error on new data starts to rise. The best moment to stop is at the bottom of the valley, before it climbs again. Good engineers watch the validation curve, like a doctor watching a heartbeat.

Training too long
From the video: Training too long

Summary

Good job. Overfitting means memorising instead of understanding. We spot it with a gap between training and test scores, and we prevent it with more data, simpler models, dropout, and early stopping. Next, we see how all these ideas led to one model that can do many jobs, the foundation model.

Key takeaways
  • Generalising = works on new examples
  • Overfitting = memorised the training set
  • More data, dropout, early stopping
Next up: Foundation Models — one model, many jobs