Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Garbage in, garbage out
Language models learn from huge piles of text gathered from the internet and elsewhere. Much of it is junk (spam, menus, gibberish) or copies of the same page thousands of times. Cleaning keeps the good text, throws out the junk, and keeps only one copy of each page. Then you decide the recipe: how much web text, code, science and so on. A model trained on a cleaner, well-mixed pile is better, even with less data. The demo shows basic text cleaning.
rocket launch launch successful. Each step shrinks the vocabulary but can lose information (here "launches" and "launched" both become "launch").For an aerospace assistant, the data recipe decides what it knows: how much of the training mix is manuals, standards, incident reports and code, and how carefully they were deduplicated and checked.
- 1. Deduplication removes…
- 2. A quality filter removes…
- 3. A data mixture sets…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.By hand
- Collection: web crawls (Common Crawl snapshots), curated sources (Wikipedia, books, arXiv, GitHub, StackExchange) and licensed data; respect robots.txt, licences and opt-outs.
- Extraction and language ID: HTML to text (trafilatura), fastText language identification.
- Heuristic filters: length, symbol and digit ratios, repeated lines or n-grams (spam), stop-word presence (Gopher and C4 rules).
- Model-based filters: perplexity under a reference LM trained on trusted text (CCNet), or a quality classifier (FineWeb-Edu’s educational-value scorer).
- Deduplication:
- exact: hash normalised documents;
- near-duplicates: MinHash signatures of word shingles plus locality-sensitive hashing; pairs with Jaccard above about 0.8 become candidates (1 − (1 − s^r)^b with b bands of r rows);
- substring-level dedup with suffix arrays.
- Mixtures: proportions of web, code, books, papers and multilingual text; upsample high-quality sources but limit repetition to about 4 epochs (Muennighoff and colleagues, 2023).
- 1. LSH candidate probability for s = 0.8, 20 bands of 5 rows:
- 2. A useful repetition limit for a data source is about…
- 3. CCNet filters by…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.Data curation in code
Exercise 1.
- Deduplicate exactly with hashes of normalised text.
- Build word shingles and compute Jaccard similarity.
- Estimate Jaccard with a MinHash signature.
Practice.
- Tools: datatrove (Hugging Face), NVIDIA NeMo Curator, Dolma toolkit, text-dedup, datasketch for MinHash LSH.
- Deduplicate within and across sources, and between training and evaluation sets (decontamination, F14-4).
- Inspect random samples of what each filter removes and keeps; filters encode biases (dialects, technical text can look like noise).
- Track every document’s provenance and licence; record the final mixture weights and epochs per source.
from datasketch import MinHash, MinHashLSH
lsh = MinHashLSH(threshold=0.8, num_perm=128)
def sig(text):
m = MinHash(num_perm=128); words = text.lower().split()
for i in range(len(words) - 2): m.update(" ".join(words[i:i + 3]).encode())
return m
for i, doc in enumerate(docs):
s = sig(doc)
if not lsh.query(s): lsh.insert(str(i), s) # keep only the first of each near-duplicate group- 1. A library for MinHash LSH:
- 2. Train/test deduplication is called…
- 3. Before trusting a filter, you should…
Level 3: Advanced
★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.Theory
Why duplicates hurt. Repeated documents get many times their fair weight, so the model spends capacity memorising them (Carlini and colleagues showed memorisation grows with duplication), and the effective amount of diverse data shrinks. Lee and colleagues (2022) found deduplicated training reaches the same perplexity faster and emits memorised text far less often.
Why filtering helps. A language model estimates the distribution of its training data. Junk shifts probability mass to text you never want to model. Perplexity filtering keeps text that resembles a trusted reference, at the risk of discarding unusual but valuable text.
Mixtures as a trade-off. With a fixed budget, every token spent on one domain is not spent on another. Target-domain perplexity improves with more in-domain data, but other domains degrade. Methods such as DoReMi optimise mixture weights automatically against a set of target tasks.
- 1. Duplicated documents mainly cause…
- 2. Perplexity filtering may discard…
- 3. DoReMi optimises…
Level 4: Expert
★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.How much do deduplication, filtering and mixing matter for a language model?
History.
- G. Wenzek et al., “CCNet: extracting high quality monolingual datasets from web crawl data” (LREC 2020).
- K. Lee et al., “Deduplicating training data makes language models better” (ACL 2022).
- G. Penedo et al., “The FineWeb datasets” (2024).
- N. Muennighoff et al., “Scaling data-constrained language models” (NeurIPS 2023).
Exercise 2.
- Domains: two language-like trigram sources over 50 words (target domain A and another domain B).
- Raw pool: 300 good A documents of 100 tokens; 10 of them duplicated 30 times (300 extra copies); 300 junk documents (half random tokens, half repetitive spam).
- Cleaning:
- exact deduplication;
- a perplexity filter: keep documents with perplexity under twice the median of trusted A text, measured by a model trained on 5 trusted documents;
- both.
- Model and metric: Kneser–Ney trigram, test perplexity on held-out A documents.
- Mixture part: a fixed budget of 200 documents with a fraction of A from 0 to 1, evaluated on both domains.
| training data | documents | test perplexity (A) |
|---|---|---|
| raw pool | 900 | 7.12 |
| exact dedup | 500 | 6.48 |
| perplexity filter | 611 | 6.60 |
| dedup + filter | 305 | 5.87 |
| the 300 clean documents (reference) | 300 | 5.83 |
| fraction of A in the mix | perplexity on A | perplexity on B |
|---|---|---|
| 0 | 100.27 | 6.08 |
| 0.25 | 10.83 | 6.84 |
| 0.5 | 7.92 | 8.06 |
| 0.75 | 6.68 | 10.95 |
| 1 | 6.00 | 85.12 |
- Duplicates and junk each hurt; removing both recovers almost the clean result with a third of the documents.
- Deduplication also removed repeated spam (900 → 500: the 300 copies plus about 100 identical spam documents).
- The filter let a few junk documents through (5 survived both steps), and kept the duplicates, which are good text. That is why both steps are needed.
- Mixtures trade domains: any in-domain data is vital (100 → 10.8 with just 25%), and a balanced mix keeps both domains usable.
- Seed 1: raw 6.71, dedup 6.21, filter 6.22, both 5.62, clean 5.58.
Data curation in AI, robotics and aerospace
- Domain corpora: assembling deduplicated, licence-checked collections of manuals, standards and reports for domain models.
- Telemetry and logs: deduplicating repetitive log lines before training anomaly or summarisation models.
- Design lesson: spend effort on the data before spending compute on the model.
References
- G. Wenzek et al. (2020). “CCNet: extracting high quality monolingual datasets from web crawl data.” Proc. LREC.
- K. Lee et al. (2022). “Deduplicating training data makes language models better.” Proc. ACL.
- G. Penedo et al. (2024). “The FineWeb datasets: decanting the web for the finest text data at scale.” arXiv:2406.17557.
- S. M. Xie et al. (2023). “DoReMi: optimizing data mixtures speeds up language model pretraining.” NeurIPS.