Module 1 · When and why to fine-tune
Defining measurable success criteria
5 min read
"The model answers better" is not a success criterion. Without a measurable definition, set before training, every fine-tuning ends with an impression — often a flattering one, because you look at the examples that work. This lesson defines Forge's success criteria: a main metric, diagnostic metrics, thresholds, safeguards, and a baseline.
One task, a verifiable output
Forge produces a four-field JSON. The first decision is the strict definition of a valid output:
def parse(output: str) -> dict | None:
"""Premier objet JSON de la sortie, s'il a exactement les bonnes clés et des valeurs autorisées."""
match = JSON_OBJECT.search(output)
if not match:
return None
try:
data = json.loads(match.group(0))
except json.JSONDecodeError:
return None
if not isinstance(data, dict) or set(data) != set(ALLOWED):
return None
if not isinstance(data["remboursement"], bool): # 1 == True en Python : on exige un vrai booléen
return None
if any(not isinstance(data[k], (str, bool)) or data[k] not in allowed
for k, allowed in ALLOWED.items()):
return None
return data
Exactly the four keys, values taken from the allowed lists, a boolean and not the string "false". This strictness is intentional: in production, the JSON is read by a program, not by a lenient human. A tolerant parser (one that would accept "urgency" for "urgence") would make the model look better than it is, and the application would crash later.
Three levels of metrics
@property
def json_valid(self) -> float:
return self.valid / self.n if self.n else 0.0
@property
def exact_match(self) -> float:
return self.exact / self.n if self.n else 0.0
def field_acc(self, key: str) -> float:
return self.correct[key] / self.n if self.n else 0.0
| Metric | Question | Role |
|---|---|---|
| Exact match | Are all four fields right? | Main metric: it is what the user experiences |
| Valid JSON | Is the output usable? | Safeguard: anything below 100% breaks the application |
| Per-field accuracy | Which field is the problem? | Diagnosis: where to focus effort |
An invalid output counts as wrong for every field: accuracy is not computed "on valid outputs only", which would reward a model that only answers when it is sure.
The baseline: prompting
Before any training, you measure what the model does without fine-tuning — that is the number to beat. For Qwen2.5-0.5B-Instruct on the 300 test messages:
| Configuration | Valid JSON | Exact match | Latency |
|---|---|---|---|
| Zero-shot (instruction only) | 0.00 | 0.00 | 163 ms |
| Few-shot, 3 examples | 0.26 | 0.05 | 238 ms |
| Few-shot, 8 examples | 0.54 | 0.16 | 544 ms |
The zero is not a measurement bug: the model writes "urgency" (in English) instead of "urgence", and sometimes "false" in quotes. Yet the instruction is explicit. A small model follows a format instruction poorly; examples help, but lengthen the prompt and triple the latency.
Setting thresholds before training
Forge's success criteria, written before the first training run:
| Criterion | Threshold | Why |
|---|---|---|
| Exact match on the test set (templates never seen) | ≥ 0.80 | Below that, too many tickets are misrouted to skip review |
| Valid JSON | 1.00 | An unreadable output blocks automatic processing |
| Exact match on "urgence = haute" (high urgency) | ≥ 0.90 | Missing a customer in danger costs more than misclassifying a question |
| Latency | < 300 ms per message on the target GPU | Triage must keep up with the message flow |
The third criterion illustrates a principle: not all errors are equal. An average metric can hide a model that misses precisely the serious cases; so you add criteria on critical subpopulations.
Safeguards: what must not degrade
Fine-tuning improves the target task and can degrade others: general capabilities, safety behavior, following other instructions (known as "catastrophic forgetting"). For a model that will only triage tickets, that is not serious; for a general assistant specialized in a domain, it is essential. Typical safeguards:
- a small set of general questions (before/after), or a few public benchmarks (lesson 5.1);
- a red-teaming set (lesson 5.2): the attack success rate must not increase;
- inference latency and memory.
A protocol that keeps you honest
- Freeze the test set before training, and only look at it at decision points.
- Use validation for intermediate choices (epochs, hyperparameters).
- Read at least twenty errors at every evaluation: the numbers say how many, the errors say why.
- Keep a run log: data, hyperparameters, duration, memory, results.
- Repeat an important run with another seed: a few points between two configurations may just be noise (lesson 3.3).
Key takeaways
- A success criterion is a metric, a frozen test set and a threshold, set before training.
- Strict parser: an invalid output counts as wrong; full exact match is the main metric.
- The prompting baseline is the number to beat: here 0% zero-shot and 16% with 8 examples.
- Add criteria on critical subpopulations and safeguards against regressions.
- Read errors, keep a log, repeat important runs.
Practice
- Run
examples/01_baselines.pyand read the displayed errors: how many are about format, how many about substance? - Write the success criteria of your own fine-tuning project in the form of the table above.
- Add to
metrics.Reportthe exact match on high-urgency messages only.