A model that remembers has not learned
Overfitting, and the three data sets that keep you honest
A model can score perfectly on what it has seen and fail on everything else. Splitting the data three ways is how you find out which one you built.
Imagine a student who memorises last year's exam. On that exam they score 100%. On this year's, they fail. Nothing about the first score told you they had not understood the subject. A model can do exactly the same thing, and it is called overfitting.
Why one score is not enough
Training lowers the error on the data the model is shown. Given enough capacity and enough time, it will drive that error close to zero by fitting the quirks and the noise of those examples, not only the pattern. The number that looks best is the one that tells you least.
Three sets, three jobs
The reason for two held-out sets is subtle. Every time you pick a setting because it did better on the validation set, you leak a little of that set into your choices. The test set is the one you did not touch.
What overfitting looks like
Training error keeps falling while validation error flattens and then starts to rise. The gap between them is the signal. Stopping near the lowest validation error is called early stopping, and it is often the cheapest fix.
Other cheap defences
More data, a smaller or simpler model, noise or dropout during training, and weight penalties all reduce how freely the model can memorise.