Hard edge cases: tables, code blocks, math markup, and image captions often break or vanish
Extractor choice matters: DCLM showed better HTML extraction yields measurably stronger models on the same raw crawl
PDF Extraction at Scale: FinePDFs
Truncation problem: Common Crawl caps download size, so large PDFs are cut off mid-file and must be re-crawled
Modern extraction: combine fast layout parsers (Docling) with vision-language OCR (RolmOCR), engineered for high throughput
Remaining gap: heavy cleanup and filtering are still needed, and much visual/layout structure is lost during linearization
Next: once raw documents are text, how do we decide what to keep?
Part 2: Filtering as Target Extrapolation
Core building block: given target data $T$ and huge raw data $R$, select subset $T' \subseteq R$ resembling $T$
Three primary applications: language identification, quality filtering, and toxicity filtering
Two desiderata:
Generalize beyond $T$ (we want fresh documents $T' \ne T$, not copies of $T$)
Extremely fast: must score every document in $R$ at multi-trillion-token scale
Scoring Functions: Generative vs. Discriminative
General two-step recipe: (1) fit a fast model from $T$ and $R$ to get $\text{score}(x)$; (2) keep $x \in R$ with $\text{score}(x) \ge \tau$ (deterministically or stochastically).
Generative Model of $T$
$$\text{score}(x) = p_T(x)$$
Example: KenLM ($n$-gram language model) trained on $T$; keep documents with low perplexity.
Discriminative Classifier
$$\text{score}(x) = p(T \mid x)$$
Example: fastText or linear bag-of-words classifier trained with $T$ positive and $R$ negative.
Dolma setup: train fast classifiers on Jigsaw labels and score documents across Common Crawl
Design tension: aggressive toxicity filters risk removing benign discussion of sensitive topics, clinical text, or underrepresented dialects
Scale-Dependent Effects of Filtering
No single optimal filtering threshold exists
Short training runs: prefer a strict threshold (less data, higher average quality)
Long training runs: need volume—strict filtering shrinks the pool too far and forces excessive epoching
Takeaway: choose filtering stringency jointly with total training tokens
Filtering summary: define target $T$ ("what good looks like"), extrapolate to $R$, and tune threshold to your token budget.
Part 3: Why Deduplicate? Exact vs. Near Duplicates
Exact duplicates
Mirror sites (e.g., Project Gutenberg mirrors)
Unmodified GitHub repository forks
Near duplicates (differ by a few tokens)
Licenses (MIT license) & terms of service
Formulaic templates & minor copy-paste edits
Repeated 61,036 times in C4 (historical baseline): "...by combining fantastic ideas, interesting arrangements, and follow the current trends in the field of that make you more inspired and give artistic touches. We'd be honored if you can apply some or all of these design in your wedding..."
Why deduplication helps (Lee et al.):
Training efficiency: stop wasting compute re-reading identical boilerplate
Less memorization: lowers verbatim regurgitation, mitigating copyright and privacy risks
The Deduplication Design Space
What is an item?
Sentence, multi-sentence span, paragraph, or full document
How do we define a match?
Exact string match, shared sub-item, or fraction of shared sub-items (similarity)
What action do we take on duplicates?
Remove all copies, or remove all but one
Core algorithmic challenge: deduplication compares items against all other items. Pairwise comparison costs $O(N^2)$—at web scale we need linear-time algorithms using hashing.
Hash Functions: Speed vs. Collision Resistance
A hash function $h$ maps an arbitrary-length item $x$ to a compact integer or string $h(x)$
A hash collision occurs when $h(x) = h(y)$ for $x \ne y$
Family
Examples
Collision Resistance
Speed & Typical Use
Cryptographic
SHA-256
Adversarially collision resistant
Slow — security, Bitcoin
Non-cryptographic
DJB2, MurmurHash, CityHash
Not adversarially resistant
Very fast — hash tables, data pipelines
import mmh3
h = mmh3.hash("hello") # fast 32-bit MurmurHash3
For deduplication over trillions of tokens, throughput dominates: non-cryptographic hashes are the standard choice.
Exact Deduplication & The MapReduce Pattern
Spec: item = string, match = exact hash match, action = keep one per hash group.
import itertools, mmh3
items = ["Hello!", "hello", "hello there", "hello", "hi", "bye"]
hash_items = itertools.groupby(sorted(items, key=mmh3.hash), key=mmh3.hash)
deduped_items = [next(group) for h, group in hash_items]
Pros: simple, exact semantics, high precision, trivially parallelizable in MapReduce (group by hash key)
Con: misses near duplicates ("Hello!" and "hello" land in different buckets)
$\alpha = 0$ is uniform; $\alpha = 1$ is proportional; intermediate $\alpha$ upweights small sources without ignoring size
UniMax (designed for multilingual balancing):
Sample sources as uniformly as possible, subject to a hard cap $C$ on epochs for every source $s$:
$$\frac{p(s) \cdot N_{\text{train}}}{\text{tokens}(s)} \le C \qquad \forall s$$
When a small source hits $C$ epochs, redistribute its leftover token budget across the remaining uncapped sources
UniMax prevents runaway repetition, but still treats all uncapped sources symmetrically—can we optimize weights directly?
Regression-Based Data Mixing (RegMix)
Analogous to scaling laws: map mixtures $p \mapsto \text{loss / downstream eval}$ cheaply, then extrapolate
Be careful with the target: optimizing directly on a narrow downstream eval risks overfitting the mixture
Two critical assumptions (hopes):
Hope 1: the regression surrogate $\hat{L}(p)$ is accurate near its minimizer
Hope 2: the optimal mixture $p^*$ transfers from small scale to large scale
When Hope 2 Breaks: Scale-Dependent Epoching
Consider the same two pools: low = 10T tokens (abundant), high = 10B tokens (scarce).
Run Scale
Mixture $p = (\text{low}, \text{high})$
Tokens Drawn from high
Epochs on high
Outcome
Small proxy ($10\text{B}$ tokens)
$(0.1,\; 0.9)$
$9\text{B}$
0.9 epochs
Looks great (no repetition)
Large target ($1\text{T}$ tokens)
$(0.1,\; 0.9)$
$900\text{B}$
90 epochs
Severe overfitting!
At small token budgets, scarce high-quality pools never run out—so proxy runs aggressively over-weight them
Directly transferring the proxy optimum to large scale collides with the finite size of high-quality data
Fix: Simulated Epoching
Core principle: make small-scale runs faithfully mirror large-scale dynamics
Method: downsample every source by $\rho = N_{\text{small}} / N_{\text{large}}$
ratio = 10e9 / 1e12 # 0.01
downsampled = {
s: count * ratio
for s, count in counts.items()
}
Over-epoching now hurts the proxy run itself, shifting the optimum toward realistic large-scale weights
Part 5: Post-Training & Synthetic Data
Unlike pretraining text, mid-training and post-training data closely resembles target evaluations
Current late-2026 frontier pipelines combine SFT, RL, and specialized teacher distillation:
Stronger model $\ne$ better teacher: QwQ-32B beat DeepSeek-R1 (earlier Jan 2025 model) as a distillation teacher
Answer filtering did not help: discarding traces with wrong final answers failed to improve performance in their setup
Curated quality beats raw breadth: smaller high-quality sources (e.g., OpenMath-2-Math) beat larger, noisier diverse mixes
Lesson: never assume a recipe transfers without ablating teacher choice, sampling multiplicity, and filtering.
Semi-Synthetic Coding Tasks: SWE-smith
Semi-synthetic recipe: keep the real software repository and environment, synthesize the bug/task
High leverage per container: once a repository environment is set up, generate hundreds of tasks inside it
Scale: just 128 GitHub repositories yield 50K verifiable SWE tasks
Scaling Real Interactive Environments: SWE-rebench
Real-task recipe: automate dependency installation and quality assessment on real pull requests
Why SWE is much harder than math or coding contests:
Repositories have complex, fragile OS and library dependencies
Building and maintaining thousands of Docker environments is a major infrastructural bottleneck
Decoupling Execution: SWE-Zero
Key insight: strong coding models hold an internal "world model" of code semantics and solve many issues without running tests
Data hygiene matters: removing future git commits prevents "git hacking" (agents peeking at the fix in git history)
Hybrid strategy: generate bulk trajectories execution-free (SWE-Zero), then supplement with execution-verified runs (SWE-Hero)
Scaling Trajectories: SWE-ZERO-12M-trajectories
Core idea: once execution setup is decoupled from rollout generation, scale trajectory volume dramatically
Dataset scale: 12M agent trajectories generated across the SWE-rebench-v2 task pool
32K executable tasks + 120K non-executable tasks
Generator: a compact model, mini-coder-1.7b (50.4 pass@100), running inside the mini-swe-agent scaffold
Tradeoff: high-volume sampling from a small, fast generator turns non-executable repositories into millions of training trajectories—provided filtering catches low-quality traces.
Post-Training Data: Design Taxonomy & Tradeoffs
Prompt / Task Paradigm
Examples
Strengths
Main Bottlenecks
Fully synthetic
Synthetic slices of OpenThoughts
Unlimited scale, full topic control
Diversity collapse, teacher bias
Semi-synthetic
SWE-smith (128 repos → 50K tasks)
Real codebases + verifiable tests
Synthetic bugs may differ from real PRs
Real tasks
SWE-rebench (21K), SWE-Zero (300K), SWE-ZERO-12M
Authentic developer distribution
Container setup, git hacking, noisy PRs
Teachers: choose capable models that are empirically good teachers (not solely by leaderboard rank)
Engineering reality: code environments are painful, and subtle leakage/filtering details make or break the corpus
Lecture 14 Recap
Transformation: raw HTML, PDFs, and repos are inherently lossy to linearize; extractor quality (trafilatura/resiliparse, FinePDFs OCR/Docling) directly moves model quality
Filtering: formulate as extrapolating target $T$ onto raw $R$ with fast scorers (KenLM, fastText, LLM-distilled classifiers); optimal threshold depends on training token budget
Deduplication: hashing scales matching to linear time; MinHash + LSH ($b$ bands of $r$ hashes) sharpens Jaccard matching around $t = (1/b)^{1/r}$
Data Mixing: balance quality, diversity, and finite pool sizes using epoch caps (UniMax) or regression + simulated epoching so small-scale optima transfer
Post-Training Data: combine environments, tasks (real / semi-synthetic / synthetic), and capable teachers—scaling to multi-teacher distillation in late-2026 frontier models
Above all: data work is domain-specific—there is no substitute for inspecting real examples at every stage.
← → / space to move · A to reveal answers · F fullscreen