Training data quality & curation
Quality beats quantity: remove exact and near duplicates, filter junk with heuristics and classifiers, decontaminate against evals, scrub PII and balance the mix. A smaller clean set routinely beats a bigger dirty one.
Analogy: Stocking a restaurant kitchen: buying more doesn't help if a third is spoiled, half is duplicated and some of it is the judges' tasting plate. Sorting the pantry is the job.
How it works
- MinHash + LSH finds near-duplicates by estimating Jaccard similarity over word n-grams, in near-linear time.
- Duplicates waste compute and drive memorization; deduplicating C4 cut verbatim memorized output ~10×.
- Run cheap heuristic rules first (length, symbol ratio, language), then a small classifier that scores quality.
- Decontaminate against your eval sets (e.g. 13-gram matches), or your scores are fiction.
- Record sources, licenses, filters and known gaps in a data card.
Check yourself
Answer to mark it learned; your answers aren't scored.
You randomly split 120k support transcripts into train and eval, then deduplicate the training split and fine-tune. Eval says 92% correct; on chats from the following month the same model scores 70%. Most likely cause and fix?
Go deeper
Full explanation
Data curation decides what your model is allowed to learn from. For pretraining and fine-tuning alike, a smaller clean set usually beats a larger dirty one: LIMA turned a 65B base model into a strong assistant with Supervised fine-tuning (SFT) on just 1,000 curated examples.
The standard pipeline:
- Exact dedup: hash normalized text and drop repeats.
- Near-dup removal: MinHash + LSH estimates Jaccard similarity over word n-grams (often 5-grams) and drops documents above a threshold (~0.7–0.8) in near-linear time. Duplicates waste compute and drive memorization.
- Heuristic filters: cheap Gopher-style rules: length bounds, symbol-to-word ratio, repeated lines, share of lines ending in punctuation, language ID.
- Classifier filters: a small model scores quality. FineWeb-Edu had Llama-3-70B rate ~450k pages for educational value, trained a classifier on those labels and kept ~1.3T of FineWeb's 15T tokens.
- Decontamination: remove anything overlapping your eval and benchmark sets (e.g. 13-gram matches), or your scores are fiction.
- PII removal: regex plus NER (e.g. Presidio) for emails, phones, IDs and keys.
- Mix balancing: set proportions per domain, language and task; upsample scarce, valuable sources.
Record all of it in a datasheet / data card: sources, licenses, filters, known gaps.
Code Exact + MinHash dedup, heuristics and decontamination
import hashlib, re
from datasketch import MinHash, MinHashLSH
def shingles(text: str, n: int = 5) -> set[str]:
w = re.findall(r"\w+", text.lower())
return {" ".join(w[i:i + n]) for i in range(max(1, len(w) - n + 1))}
def minhash(text: str) -> MinHash:
m = MinHash(num_perm=128)
for s in shingles(text):
m.update(s.encode())
return m
def gopher_like(t: str) -> bool:
words = t.split()
symbols = t.count("#") + t.count("...")
return 50 <= len(words) <= 100_000 and symbols / max(len(words), 1) < 0.1
eval_grams = {g for doc in eval_set for g in shingles(doc, n=13)} # decontamination
lsh, seen, kept = MinHashLSH(threshold=0.8, num_perm=128), set(), []
for i, doc in enumerate(corpus):
h = hashlib.sha1(" ".join(doc.lower().split()).encode()).hexdigest()
if h in seen or not gopher_like(doc):
continue # exact duplicate or junk
if shingles(doc, n=13) & eval_grams:
continue # leaks an eval item
m = minhash(doc)
if lsh.query(m):
continue # near-duplicate of a kept doc
seen.add(h); lsh.insert(str(i), m); kept.append(doc)
kept = [d for d in kept if quality_score(d) >= 3] # FineWeb-Edu-style classifier, 0-5Real example
A fintech wants to fine-tune a support model on 120k historical chat transcripts. Exact dedup removes 22% (agents' canned macros); MinHash near-dup removes another 15%. They keep only resolved chats with CSAT ≥ 4, scrub card numbers and emails with Presidio, and find 400 chats that also sit in the eval set, which was built from the same quarter, so they rebuild the eval from a later month. 18k examples remain. The model trained on 18k beats the one trained on all 120k on the new eval (resolution judged correct 71% vs 63%) and trains in a sixth of the time.
Trade-offs +4 · −3
+ You gain
- Often the cheapest quality lever: same model, same compute, better results.
- Fewer tokens means cheaper, faster training runs.
- Less memorization, and less privacy and copyright exposure.
- Trustworthy evals: decontamination keeps scores honest.
− You pay
- Engineering-heavy at scale: MinHash over billions of documents needs distributed tooling (datatrove, NeMo Curator, Spark).
- Quality classifiers encode someone's taste and can drop dialects, informal text and minority topics.
- Hard to validate a filter without training ablation models, which costs compute.
Use it when
Before every training run, at every scale: fine-tuning sets need dedup, decontamination and PII scrubbing as much as pretraining corpora. Invest more when you see memorization, suspiciously good evals or noisy labels.
Avoid it when
Don't build a pipeline for a 500-example SFT set: read every example yourself. Don't filter a niche domain corpus with a generic web-quality classifier; it will throw away your domain.
Numbers to know 5
- LIMA: 1,000 curated SFT examples; its answers were equal to or preferred over GPT-4's in 43% of comparisons.
- Lee et al.: C4 held one 61-word sentence 60,000+ times; deduplication cut verbatim memorized output ~10×.
- FineWeb-Edu: ~1.3T of FineWeb's ~15T tokens, kept by a classifier trained on ~450k Llama-3-70B ratings.
- DCLM-Baseline: a 7B model reached 64% 5-shot MMLU on 2.6T tokens, driven mainly by model-based filtering.
- Llama 3's final pretraining mix: ~50% general knowledge, 25% math and reasoning, 17% code, 8% multilingual.
Common pitfalls 4
- Splitting before deduplicating: near-copies land in both train and test and inflate scores. Dedup first, then split, ideally by time or by customer.
- Decontaminating against public benchmarks but not against your own eval set, built from the same logs as the training data.
- Trusting a quality classifier blindly: audit what it drops by language, dialect and topic before applying it.
- No lineage: you can't answer "was this customer's data used?" for a deletion request. Version datasets and keep a data card.
Interview questions 2
Answer out loud first, then reveal.
You have 200k noisy fine-tuning examples. What do you do first?Show answer
I read a hundred of them myself; it surfaces defects no metric names. Then exact and MinHash dedup, filter by outcome signals like resolved tickets or accepted code, scrub PII, and decontaminate against my eval set. Then I run an ablation instead of arguing: train on the best 10–20k and on everything, and compare on held-out data. LIMA showed quality and diversity dominate, so I'd expect the curated subset to match or win at a fraction of the compute. The risk is filtering out the hard cases, so I check slices.
How do you know your evals aren't contaminated?Show answer
For my own models, I check n-gram overlap (13-grams is the classic) and embedding nearest neighbours between training and eval data, and I dedup before splitting, ideally by time. For vendor models I can't inspect, I rely on private evals written after the model's cutoff and on perturbation: if accuracy drops sharply on paraphrased or re-numbered versions of the same items, the model probably memorized them. Public benchmark scores I treat as marketing until I reproduce them on my own data.