Module 2 · Training data

Synthetic data and distillation

7 min read

The previous lessons made the diagnosis: Forge's triage model scores 100% on known phrasings and two thirds on new ones, because its data contains only nine ways of phrasing each category. The remedy is diversity. When you cannot collect more real messages, you can generate them with a larger model: this is distillation through synthetic data. This lesson implements it — generation, filtering, decontamination — and honestly measures what it brings.

The principle: a teacher, a student

A teacher model, larger and more capable, produces examples; the smaller student model trains on them. It is one of the most widespread practices today: many open models are trained partly on data produced by larger models. In Forge, the teacher is Qwen2.5-3B-Instruct, loaded in 4 bits to fit on the 6 GB GPU, and the student remains Qwen2.5-0.5B-Instruct.

Two ways to put the teacher to work:

ApproachPrincipleRisk
The teacher labels existing textsYou give it real messages, it produces the answersIts labeling errors become truths for the student
The teacher writes texts for given labelsYou draw a label at random, it writes a matching messageIts texts may not match the requested label

Forge uses the second: the label is known before the text, which makes it possible to check it afterwards.

Generating from labels

First a label is drawn — category, product, urgency, refund — then the teacher is asked for a matching message, with a style drawn at random to force variety:

GENERATE = """Écris le message qu'un client envoie au support d'une boutique en ligne de mobilier de bureau.
- Sujet : {categorie} ({spec})
- Produit concerné : {produit}
- Ton et urgence : {urgence}
- {remboursement}
- Style : {style}
Écris uniquement le message du client, en français, sans titre ni guillemets."""

(Write the message a customer sends to an online office furniture store's support: topic, product, tone and urgency, refund request or not, style; only the customer's message, in French.) The category descriptions come from the task's specification ("payment: a charge, an invoice, a payment method, a promo code or fees charged by mistake"), not from test examples: the teacher never sees the evaluation set. Sampling (temperature=0.9, top_p=0.95) brings diversity; at zero temperature, the teacher would produce nearly identical messages for similar labels.

Filtering: the consistency check

A generated message may not match its label: the teacher forgets the product, talks about delivery instead of payment, adds a refund request. Two filters:

def verify(teacher, tokenizer, candidates: list[tuple[dict, str]], shots: list[Example]
           ) -> tuple[list[Example], dict]:
    """Garde un message si le produit nommé correspond ET si le professeur retrouve catégorie et
    remboursement."""
  1. The product, checkable with a regular expression: does the message name the right product, and only that one?
  2. Consistency: the teacher rereads its own message, without seeing the label, and classifies it; the message is kept only if it recovers the requested category and refund request. A message that its own author classifies differently is ambiguous, or poorly written.

Then come the treatments of lessons 2.1 and 2.4: cleaning, near-duplicates (very similar generations overweight one phrasing), and decontamination against the test set.

The results

Generation. Of 600 messages written by the teacher (≈ 30 tokens per second on the GTX 1060, about forty minutes), filtering keeps 367: 8 rejections for the product, and 225 for inconsistency — more than one message in three that the teacher itself does not classify as requested. Cleaning removes 15 more (14 false positives of the language filter on very casual messages, 1 too short). That leaves 352 messages, with no near-duplicates and no suspicious overlap with the test set.

They are very different from the templates:

MeasureTemplates (training)Synthetic
Distinct trigrams / total trigrams0.180.71
Average length17.5 words56.6 words
Example« Le code promo ne s'applique pas sur la CHAIR-7. »« Bonjour, je me permets de vous contacter concernant ma commande via votre site internet pour un Bureau Lift. Je viens de remarquer que mon compte semble… »

(A template message: "the promo code does not apply to the CHAIR-7"; a synthetic one, in a much more formal, written style about an order and an account issue.) Four times more diversity — but also messages three times longer, in a "written" style real customers rarely use. The diversity gained comes with a distribution shift.

Training. Same LoRA configuration, on 1,179 template examples + 352 synthetic ones, three seeds on each side:

DataSeed 42Seed 1Seed 2Category (mean)Urgency (mean)
Templates only0.650.650.740.770.94
Templates + synthetic0.680.700.790.820.91

At equal seeds, synthetic data wins every time (+3, +5 and +5 points), and the best run, compared example by example with the reference (seed 42, templates only), gains 46 messages for 4 lost. The gain is on the category: lexical shortcuts recede, because synthetic messages use "delivery" or "parcel" in return or payment contexts. Urgency, on the other hand, slips slightly: the teacher does not apply exactly the same definition as the templates (a customer it wrote as "angry" is not always classified "high" by the rules), and these slightly different labels blur learning.

The honest assessment: a real but modest gain, and the success criterion of lesson 1.4 (0.80) is still not met — the best run plateaus at 0.79. The next levers are known: more synthetic messages, closer to real customers' style (length instruction, anonymized real examples as models), an urgency definition shared between teacher and templates, a larger student… and, as soon as they exist, real labeled messages.

The risks of distillation

RiskCountermeasure
The teacher makes mistakes, the student learns themConsistency check, review of a sample
Generated texts all look alike ("model" style)Imposed styles, sampling, deduplication; measure diversity
The test set leaks into generationThe teacher only sees the specification; systematic decontamination
The teacher's license forbids itSome licenses forbid using a model's outputs to train another: check it before generating
The student rarely exceeds its teacherAlso measure the teacher on the task: it is often the ceiling

The license point is not theoretical, and Forge gives an example: its teacher, Qwen2.5-3B-Instruct, is released under the "qwen-research" license, reserved for research, whereas the 0.5 B and 1.5 B versions of the same family are under Apache 2.0. For commercial use of the generated data, you need another teacher (FORGE_TEACHER_MODEL). More broadly, the terms of use of several API providers and some open models explicitly regulate the use of their outputs to train other models: read them before generating.

Key takeaways

  • Distillation: a larger teacher generates examples, a smaller student trains on them.
  • Generating from randomly drawn labels makes each example verifiable; imposed styles force diversity.
  • Filter: programmatic checks, consistency check by the teacher, deduplication, decontamination.
  • Measure on a source-split test set with several seeds: here, +3 to +5 points, still below the success criterion.
  • Check the teacher's license, and expect it to set the student's ceiling.

Practice

  1. Run examples/05_synthetic_data.py and read twenty generated messages: which ones do not look like real customers?
  2. Measure the teacher itself on the test set (examples/01_baselines.py with FORGE_BASE_MODEL=Qwen/Qwen2.5-3B-Instruct): what ceiling does it give?
  3. Double the number of synthetic messages and plot test exact match as a function of data quantity.

Resources