Read training signals
While a model trains, you watch two numbers. The training loss says how well it fits the examples it learns from. The validation loss says how well it does on examples it has never seen. The first almost always goes down. The second is the one that matters, because a model can memorise its training examples and still be useless on anything new. When training loss falls while validation loss rises, that is what is happening.
Learn it
Words to know
- validation set
- Examples kept out of training and used only to check how the model does on data it has not seen.
- overfitting
- When a model memorises its training examples and gets worse on new ones.
- loss
- One number that says how wrong the model is. Training tries to make it smaller.
How it works
- Compare the first and the last value of each list.
- Training loss down and validation loss up:
overfitting. - Both down:
improving. - Anything else, such as a training loss that did not fall:
inspect. Something needs a closer look before you can say more.
Worked example
Input train = [1, 0.6, 0.3] validation = [1.1, 1, 1.4] Output "overfitting"
| List | First | Last | Direction |
|---|---|---|---|
| train | 1.0 | 0.3 | Down |
| validation | 1.1 | 1.4 | Up |
| Answer | - | - | overfitting |
- Training loss
- Validation loss
The model keeps getting better on its own examples and worse on unseen ones. Training past this point only makes it memorise more.
Why it matters
The tiny GPT in the workshop prints both losses while it trains. Reading them is how you decide when to stop, and whether a change to the model helped.
Your turn
Label a training run from its two loss histories, using only the first and last value of each.
train- the training loss after each round; at least two numbers
validation- the validation loss after each round; at least two numbers
- Returns
"overfitting"if train went down and validation went up;"improving"if both went down; otherwise"inspect". Equal values count as neither up nor down.
Example 1
Input train = [1, 0.6, 0.3] validation = [1.1, 1, 1.4] Output "overfitting"
Train fell from 1.0 to 0.3 while validation rose from 1.1 to 1.4.
Example 2
Input train = [3, 2, 1] validation = [3, 1, 2] Output "improving"
Train fell from 3 to 1. Validation ended at 2, below its start of 3, so it went down too. Its rise at the end is not looked at.
Example 3
Input train = [2, 1] validation = [1, 1] Output "inspect"
Train fell, but validation ended where it started. A flat validation loss is neither up nor down.
Example 4
Input train = [1, 1] validation = [1, 2] Output "inspect"
Validation rose, but the training loss did not fall, so the rule does not call this overfitting.
Example 5
Input train = [1, 2] validation = [2, 1] Output "inspect"
The training loss rose. Neither named label fits, even though validation fell.
Hints
Each hint gives away a little more. Open one only when you need it.
Hint 1: Where to start
Only four numbers matter: the first and last of each list. In Python the last item is
train[-1].Hint 2: The key step
Both named labels need the training loss to have gone down. Check that first, then look at validation.
Hint 3: The outline
If
train[-1] < train[0]: return"overfitting"whenvalidation[-1] > validation[0], and"improving"whenvalidation[-1] < validation[0]. In every other case return"inspect".
Solution
From here on the page gives the method away. If you are still solving, go back to the hints.
Step by step
- Both labels need the training loss to have gone down. If the model is not even fitting its own examples, the question of memorising does not come up yet.
- Worse on unseen examples: the model is memorising. It is fitting details of the training examples that do not hold for new ones.
- Better on unseen examples too. The model is learning something that carries over to new examples.
- Flat or rising training loss, or a flat validation loss. None of these has one clear cause. The honest answer is to look closer.
The same numbered steps are the comments in the solution.
Python
def solve(train, validation):
# 1. Both labels need the training loss to have gone down
if train[-1] < train[0]:
# 2. Worse on unseen examples: the model is memorising
if validation[-1] > validation[0]:
return "overfitting"
# 3. Better on unseen examples too
if validation[-1] < validation[0]:
return "improving"
# 4. Flat or rising training loss, or a flat validation loss
return "inspect"Watch out
- Use strict comparisons. An unchanged validation loss is neither up nor down, and the answer is
"inspect". - This rule looks at two points only. A real loss curve is noisy, so in practice you look at the whole curve before deciding.
Check yourself
Which loss tells you how the model does on new examples?
The validation loss. It is measured on examples kept out of training.
What do a falling training loss and a rising validation loss mean together?
Overfitting: the model is memorising its training examples and getting worse on everything else.