Module 2 · Training data
Curation, filtering and cleaning
6 min read
A fine-tuning run learns everything its data contains: the right answers, but also labeling errors, duplicates, personal data and easy shortcuts. With a few thousand examples, every flaw weighs heavily. Curation — selecting, cleaning, filtering — is the most profitable work in a fine-tuning project, well ahead of choosing hyperparameters. This lesson builds Forge's cleaning pipeline and reads its report.
The course data
Forge trains a small model to triage customer support messages for the Nimbus store: from the message, produce a JSON with the category, the product, the urgency, and whether the customer is asking for a refund.
« Bonjour, j'ai reçu la lampe Halo mais la couleur ne va pas du tout avec mon bureau. Je peux faire un retour ? »
→ {"categorie": "retour", "produit": "Lampe Halo", "urgence": "normale", "remboursement": false}
(The customer received the Halo lamp but the color does not match their desk, and asks whether they can return it: category "return", normal urgency, no refund requested.) The task was chosen because it can be measured without a judge (valid JSON, each field right or wrong) and resembles a real need. The data is in French, like Nimbus's customers. Messages are generated from 60 templates (12 per category), with products named in several ways ("la CHAIR-7", "l'Axis", "ma chaise de bureau Axis"), greetings, signatures, typos, lowercase text, and urgency signals (anger, danger). A key point, developed in lesson 2.4: the 15 test set templates are never used for training.
A cleaning pipeline that explains its rejections
for e in examples:
key = normalize(e.message)
if not (min_chars <= len(e.message) <= max_chars):
report.rejected["longueur"].append(e)
elif parse(e.target_json()) is None:
report.rejected["étiquette_invalide"].append(e)
elif french_ratio(e.message) < min_french:
report.rejected["langue"].append(e)
elif len(labels_by_text[key]) > 1:
# même texte, deux réponses : laquelle croire ?
report.rejected["étiquettes_contradictoires"].append(e)
elif key in seen:
report.rejected["doublon_exact"].append(e)
else:
seen.add(key)
report.kept.append(Example(**{**vars(e), "message": mask_pii(e.message)}))
Each filter files its rejections under a reason (length, invalid label, language, conflicting labels, exact duplicate). The report reads like a diagnosis:
| Filter | What it catches | What a high rate reveals |
|---|---|---|
| Length | Empty or truncated messages, giant pastes | An extraction or export problem |
| Invalid label | A target that does not follow the expected format | A bug in annotation or conversion |
| Language | Messages outside the language scope | A mixed source |
| Conflicting labels | The same text with two different answers | Disagreeing annotators, an ambiguous guideline |
| Exact duplicate | The same text twice (after normalization) | A duplicated source, overlapping exports |
Of Forge's 1,200 training examples: 1,179 kept, 20 exact duplicates, 1 language rejection. The latter is a false positive — « madame, monsieur, combien coûte laa livraison express ? » is indeed French, but lowercase, with a typo, and too short for the heuristic. Forge's language filter counts function words; in production, use a language identification model, much more reliable on short texts. Reading the rejections is precisely how you spot over-zealous filters.
Conflicting labels deserve special attention: on real annotated data, they are often the first sign of an ambiguous guideline ("a damaged parcel — is that delivery or return?"). The right response is not to pick at random, but to clarify the guideline and re-annotate.
Normalization, the key to comparison
Comparing texts requires a canonical form: lowercase, without accents or punctuation.
def normalize(text: str) -> str:
"""Minuscules, sans accents ni ponctuation, espaces réduits : la forme de comparaison."""
text = unicodedata.normalize("NFD", text.lower())
text = "".join(c for c in text if unicodedata.category(c) != "Mn")
return " ".join(re.findall(r"[a-z0-9]+", text))
This form is used only for comparing; the kept example retains its original text, with its capitals and typos, which are part of what the model must learn to handle.
Personal data
A model can regurgitate fragments of its training data. A phone number, an e-mail address or an IBAN present in the examples can resurface months later, in front of another user. Forge masks them before training:
def mask_pii(text: str) -> str:
"""Les données personnelles n'ont rien à faire dans les poids : un modèle peut les régurgiter."""
# L'ordre compte : un IBAN contient des suites de chiffres qu'on prendrait pour un téléphone
return PHONE.sub("[TELEPHONE]", IBAN.sub("[IBAN]", EMAIL.sub("[EMAIL]", text)))
« Appelez-moi au 06 12 34 56 78 ou jean.dupont@mail.fr, IBAN FR76 3000 6000 0112 3456 7890 189 » becomes « Appelez-moi au [TELEPHONE] ou [EMAIL], IBAN [IBAN] ». The order of substitutions is not a detail: applied first, the phone pattern split the IBAN and left part of it in clear text — the unit test revealed it. Regular expressions are not enough for names or postal addresses: named-entity detection tools (Presidio, for example) complement them. And masking does not exempt you from having a legal basis to use customer data (GDPR): it is one protective measure.
Quantity or quality?
Published experience converges: to specialize a model that is already "Instruct", a few hundred to a few thousand clean and varied examples are worth more than tens of thousands of noisy ones. The job is not to accumulate, but to cover: every category, every register, edge cases, hard cases. Lesson 2.4 will show that Forge's data, clean but not varied enough, produces a model that scores 100% on examples similar to training… and much less on new phrasings.
Key takeaways
- Curation is the most profitable work in fine-tuning: the model learns the flaws too.
- Each filter files its rejections under a reason: the report diagnoses the data source.
- Read the rejections: an over-zealous filter (here, a language false positive) is visible at a glance.
- Conflicting labels signal an ambiguous guideline: clarify and re-annotate.
- Mask personal data before training: a model can regurgitate it.
Practice
- Run
data_quality.cleanon the training set and display the rejected examples for each reason. - Add a message identical to another but with a different urgency: check that it is rejected as conflicting.
- Replace the language heuristic with a language identification model and compare the rejections.