Papa Programmer
Lesson 27 of 36

Evaluating a fine-tuned model

9 min read

Optional

One question

The question is whether the tuned model is better at the job than the alternative you already have. That alternative is the baseline: the base model with a good prompt, or the model you run today. A tuned model that scores 80% means little until you know the baseline scores 63% on the same cases.

Build the comparison so that it is fair.

  • Same inputs. Both models see exactly the same held-out cases.
  • Same conditions. Same prompt format, generation settings and scoring method. Record them.
  • Untouched test set. The cases were never used for training or for choosing settings, as Training, validation and test sets explained. If you tune on the test set repeatedly, it stops being independent.
  • Realistic cases. Include routine, rare and hard cases in the proportions the product will see, plus a few cases you care about even if they are rare.

Compare case by case

The program below holds the results of 30 held-out support tickets, ten per category. For each case it records whether the baseline and the tuned model were right. It prints accuracy by category, counts the cases the tuned model fixed and the cases it broke, and uses resampling to estimate how much the improvement could vary by chance.

python
import random

categories = {
	"access": ("1110111011", "1111111011"),
	"billing": ("1101101101", "1111101111"),
	"technical": ("0100110100", "1001110110"),
}

cases = []
for name, (base, tuned) in categories.items():
	for b, t in zip(base, tuned):
		cases.append((name, int(b), int(t)))

def accuracy(rows, column):
	return sum(row[column] for row in rows) / len(rows)

print(f"baseline {accuracy(cases, 1):.0%}, tuned {accuracy(cases, 2):.0%}")
for name in categories:
	rows = [c for c in cases if c[0] == name]
	print(f"  {name:10} baseline {accuracy(rows, 1):.0%}  tuned {accuracy(rows, 2):.0%}")

fixed = sum(1 for _, b, t in cases if t > b)
broken = sum(1 for _, b, t in cases if b > t)
print(f"fixed {fixed}, broken {broken}")

random.seed(1)
gaps = []
for _ in range(2000):
	sample = [random.choice(cases) for _ in cases]
	gaps.append(accuracy(sample, 2) - accuracy(sample, 1))
gaps.sort()
print(f"95% range of the gain: {gaps[50]:+.0%} to {gaps[1949]:+.0%}")

It prints:

text
baseline 63%, tuned 80%
  access     baseline 80%  tuned 90%
  billing    baseline 70%  tuned 90%
  technical  baseline 40%  tuned 60%
fixed 6, broken 1
95% range of the gain: +0% to +33%

Three readings come out of it.

  1. The average hides the slices. Accuracy rises from 63% to 80% overall, but technical tickets move from 40% to 60% and access tickets only from 80% to 90%. If technical tickets are the point of the project, that slice deserves its own target.
  2. Fixed and broken tell you more than accuracy. The tuned model fixed 6 cases and broke 1. Read the broken one: a new failure is a sign of what fine-tuning may have cost.
  3. A small set has wide error bars. Resampling the 30 cases gives a 95% range for the gain of about 0 to 33 points. The lower end touches zero, so on 30 cases luck alone could account for much of the improvement. A range that includes zero means you cannot yet say the tuned model is better. More cases narrow it. Treat this as a rough guide and not a formal test.

Beyond a single score

A score on the test set is one input to a decision. Before you ship, also check:

  • Latency and cost. A tuned model that is more accurate but twice as slow may not be an improvement for your use.
  • Format and safety. Check that outputs still parse and that refusals and safety behaviour match the base model, as Catastrophic forgetting warned.
  • Leakage. Make sure no test case, or a near-copy, appears in the training data, as Cleaning data and checking quality showed.
  • Real traffic. Run a sample of real inputs, with permission and with private data protected, because curated cases can be easier than live ones.

Keep the evaluation set alive

An evaluation set is a product too. Version it, record where each case came from, and add cases when you see new failures, but keep a frozen core so scores stay comparable across rounds. When cases from reviewed failures move into training, mark them so they no longer count as held out, as Error analysis and the next round describes. Choose the measures before you look at results, and the next Lessons cover them: Metrics for classification and generation for numbers, and Human review and model judges for qualities a formula misses.

  1. FreezeFix the held-out cases, prompts and settings.
  2. Run bothScore the baseline and the tuned model on identical inputs.
  3. SliceBreak results down by category and by case difficulty.
  4. DiffList the cases that got better and the cases that got worse.
  5. JudgeAsk whether the gain is larger than chance and worth the cost.
Run a fair comparison
Same cases, same rulesA fair comparison changes only the model.
Look at slicesThe overall average can hide the group that matters most.
Count the broken casesThe cases a tuned model gets wrong that the baseline got right show its cost.

Your reading position is saved

0%

0 of 36 complete

Contents

Learning tools