Did it actually improve
Lesson 5 of 6
5Did it actually improve
The big pictureA lower validation loss does not mean a better model at your task. You need a frozen evaluation set that measures the task itself, before and after tuning, with a confidence interval telling you whether the difference is real. And you need something loss never measures: did the model forget what it was good at before tuning?
What the picture shows: The average says a 6.5-point gain, but the bar says more: 22 questions were fixed and 9 broken. Read those nine; if they are all one kind, tuning broke something specific.
Map of this part
The concepts in order, click any one to jump to it:
Two ways into the same idea
After the course you test the employee with the same exam they took before it, or you will not know whether they improved. And you check they did not forget what they used to do well, because intense focus on a new skill can wipe old ones without you noticing.
A fixed evaluation set and the same metric before and after tuning, compared with a prompt-engineering baseline. catastrophic forgetting does not show in the task loss, so you also measure on general tasks, and inspect samples by hand because a number alone can mislead.
Before You Start
📋Tuning data
You have a frozen test file written before training and never changed.
🎲Probability
You know a number measured on a sample has a range, and that a small difference may be chance.
The Core Idea
A lower validation loss does not mean a better model at your task. In this lesson you build a frozen test set, compare before and after with a confidence interval, catch forgetting, and then decide: adopt or roll back.
1The frozen set
The frozen set is test questions written before training, never seen by it, and unchanged across experiments. Without it two versions cannot be compared.
Look at the picture: the set is written and kept in Git before training, and is not touched until the final evaluation.
2Before and after, with an interval
You run both models on the same questions and compare question by question. Then you resample the same questions for both models thousands of times, and take the 95% interval of the difference.
Look at the picture: accuracy rose from 64.0% to 70.5%. The real question is whether the interval excludes zero.
import numpy as np
rng = np.random.default_rng(0)
n = 200
before = rng.random(n) < 0.71 # 1 = correct on the frozen eval set
after = before.copy()
flip_up = rng.choice(np.where(~before)[0], 22, replace=False)
flip_down = rng.choice(np.where(before)[0], 9, replace=False)
after[flip_up], after[flip_down] = True, False
diffs = []
for _ in range(2000): # paired bootstrap: resample the same questions for both
idx = rng.integers(0, n, n)
diffs.append(after[idx].mean() - before[idx].mean())
low, high = np.percentile(diffs, [2.5, 97.5])
print(f"before: {before.mean():.1%} after: {after.mean():.1%}")
print(f"improvement: {after.mean() - before.mean():+.1%}, 95% interval [{low:+.1%}, {high:+.1%}]")
print("questions fixed:", len(flip_up), " questions broken:", len(flip_down))
The improvement is 6.5 points, with an interval from +1% to +12%, so it is probably real since the interval excludes zero, but its size is uncertain. The last line matters just as much: 22 questions were fixed and 9 broken. Read those nine: if they are all one kind, tuning broke something specific you need to fix.
3Catastrophic forgetting
Tuning on a narrow task can weaken general abilities the model had, and you never see it in the task's loss. A small general set run before and after reveals it.
Look at the picture: the old skill collapsed from 0.99 to 0.58 with the new task alone, and stayed at 0.96 when we mixed in old examples.
A network learns an "old" task, then is trained on a new one. Once on the new task alone, once mixing in some old examples.
import warnings
warnings.filterwarnings("ignore") # small runs stop before sklearn calls them converged
import numpy as np
from sklearn.neural_network import MLPClassifier
rng = np.random.default_rng(0)
def task(kind, n=600):
X = rng.normal(size=(n, 6))
X[:, 5] = 1.0 if kind == "old" else -1.0 # which task the input belongs to
y = (X[:, 0] + X[:, 1] > 0) if kind == "old" else (X[:, 2] - X[:, 3] > 0)
return X, y.astype(int)
old_train, new_train = task("old"), task("new")
old_test, new_test = task("old"), task("new")
def run(replay):
m = MLPClassifier(hidden_layer_sizes=(32,), learning_rate_init=0.01, random_state=0)
for _ in range(60):
m.partial_fit(*old_train, classes=[0, 1])
old_before = m.score(*old_test)
X, y = new_train
if replay: # mix in a quarter as many old examples
X = np.vstack([X, old_train[0][:150]])
y = np.concatenate([y, old_train[1][:150]])
for _ in range(60):
m.partial_fit(X, y)
return old_before, m.score(*old_test), m.score(*new_test)
for name, replay in [("new task only", False), ("new task + old examples", True)]:
before, after, new = run(replay)
print(f"{name:24} old skill {before:.2f} -> {after:.2f} new task {new:.2f}")
Training on the new task alone collapsed the old one from 0.99 to 0.58, close to guessing, while the new one succeeded. Mixing in just 150 old examples kept the old task at 0.96 and the new at 0.98. The same phenomenon happens in language models, and the new task's loss never shows it. Only the general-abilities set reveals it.
4When to roll back
The original model always stays an option. You roll back when the gain does not clear the confidence interval, breaks important questions, or general abilities drop more than you accept.
Look at the picture: two questions decide. Adopting needs an interval above zero and a general set that held.
And read every broken question yourself. If they are all one kind, tuning broke something specific you need to fix.
How It Works, Step by Step: how to compare the model before and after tuning
Run both models on the same frozen test questions, and record whether each answer is right.
Resample the same questions for both models thousands of times, and take the 95% interval of the difference.
Count the questions fixed and broken, and read every broken one.
Run a small general set before and after to reveal forgetting, then decide: adopt or roll back.
Worked example
The frozen set is the test file from the data lesson: training never saw it, and it has not changed since it was written. We run the original and the tuned model on it and compare question by question.
Try it without code
Myth vs Reality
| Myth | Reality |
|---|---|
| Lower validation loss means a better model at my task. | Loss measures token probability, not whether the answer is right. The task is measured with a frozen test set that measures it. |
| The model's score on the validation set is an honest final evaluation. | You picked the checkpoint because it was best there, so its score there is optimistic. The final evaluation is on the frozen test set only. |
| If the task loss looks fine, the model forgot nothing. | In the example the old skill collapsed from 0.99 to 0.58 while the new task succeeded. Forgetting only shows when you test for it explicitly. |
Try it yourself
Why compare the two models question by question, not just by the average?
22 fixed and 9 broken give the same average as 13 fixed and none broken, but the first means tuning broke something you need to know about.
How do you detect catastrophic forgetting?
Both losses measure only the new task. What was forgotten shows only when you test it explicitly.
Quick review cards
Check Your Understanding
The tuned model improved 2% on the task, with an interval from −2% to +6%, and dropped 8% on the general set. Do you adopt it?
No. The improvement may be zero or negative since the interval includes zero, and the loss in general abilities is clear. Roll back to the original model, and next run try cleaner data or mixing in general examples. A tuning that does not prove its worth is worse than no tuning, because it adds maintenance cost.
In the forgetting example, what preserved the old skill, and what did it cost?
Mixing 150 old examples into the new task's data. The old skill stayed at 0.96, and the new task only dropped from 0.99 to 0.98.
Resources for this lesson
Grouped by type. Start with the official docs for precision, or an article or video for the explanation.
Done with this lesson?
Sign in to save your progress.