A web crawl is not a dataset. Each stage of a data pipeline keeps a fraction of what reaches it, and the fractions multiply. RefinedWeb keeps 11.67% of Common Crawl's documents; DCLM keeps 1.4%.
Pick a pipeline and read how much survives each stage. Then switch a stage off and watch the yield move. Then we build every stage from zero: the sources, the crawl, extraction, language ID, the yield, the mix and the law.
You need tokens from Lecture 1 and percentages. We build the rest from zero.
Lecture 13 of Stanford CS336, Language Modeling from Scratch (Spring 2025, Percy Liang and Tatsunori Hashimoto). Previous: Lecture 12, Evaluation. Next: Lecture 14, Data II: Filtering and Deduplication.
Kept shares from the papers: RefinedWeb Figure 2 (documents, then tokens); DCLM Figure 4 (documents, four heuristic filters as one bar); C4 from Dodge et al. 2021 Table 1 (SpaCy word tokens); FineWeb Section 3 (GPT-2 tokens). Purple labels mark stages run by a trained classifier. Switching a stage off is an illustrative what-if.
Chapter 0
Follow pages from the live web to a training batch, and count what each stage throws away
You have a cluster and one Common Crawl snapshot. The April 2025 snapshot holds 2.74 billion web pages. Most are menus, shops, spam, copies and languages you did not plan for. Which pages should your model read?
The lecture opens with a hot take: data is the most important thing to get right. Look at what labs publish. The Llama 3 paper describes its architecture and training in detail, and says almost nothing about its data. The lecture gives two reasons: competition and copyright liability.
Training reads data in three stages. Pre-training reads huge amounts of raw text, such as web pages. Mid-training reads less text of higher quality to add a skill, such as math or long documents. Post-training tunes the model on instructions and chat. The flow runs from a lot of lower-quality data to a little high-quality data.
Pre-training data comes out of a pipeline. Each stage reads only what the stage before it kept:
Twelve crawled pages. Press Step to run the next stage. Each stage greys out the pages it removes and names itself on them.
Illustrative toy: twelve made-up pages, two removed by each stage. Real stages remove different shares; the hero has the published ones.
In the toy, 4 of 12 pages reach training: 33%. Real pipelines keep less. RefinedWeb keeps 11.67% of Common Crawl's documents. This lesson covers where text comes from and the stages that turn it into text; Lecture 14 builds the filters and the deduplication.
Symptom: a model trained on a fresh crawl writes "Accept all cookies" and "Click here to subscribe".
Measure: sample 100 training documents at random and read them.
Fix: extract from raw HTML with a boilerplate remover, and filter before you train.
Chapter 1
Compare the big sources by size, and by what one document looks like in each
Every big corpus draws on the same few sources. Each source exists because some service made text easy to collect.
Dolma, the open corpus behind AI2's OLMo models, lists its six sources in one table. The device draws it.
One bar per source in Dolma. Choose what to measure. Switch to a log scale to see the small sources.
Numbers from Dolma's Table 1 (Soldaini et al., 2024): UTF-8 gigabytes, millions of documents and billions of Llama tokens. Bytes per document is bytes divided by documents.
Common Crawl is 85.2% of Dolma's 11,519 GB; Wikipedia is 0.14%. A Gutenberg book averages 20.4 GB / 56,000 books = 364 KB, and a Wikipedia article 2.6 KB. Code packs fewer bytes into each token: 2.54 bytes per Llama token on GitHub, 3.96 on the web.
A clean source can still carry bad text. The lecture cites a poisoning attack: edit Wikipedia right before a dump, before editors revert it. GPT-2's WebText used a cheap quality vote instead: pages linked from Reddit posts with at least 3 karma, 8 million pages and 40 GB.
Symptom: a model trained on "clean" Wikipedia ties a product name to a negative word.
Measure: compare the dump with the article history around the dump date.
Fix: treat every source as untrusted; filter and audit the high-quality ones too.
Chapter 2
Open one monthly crawl, see its file formats, and turn its bytes into a token count
Common Crawl is a non-profit, founded in 2007, that crawls the web about once a month and gives the result away. Its crawler, built on Apache Nutch, starts from hundreds of millions of seed URLs. It downloads each page, puts the page's links in a queue and repeats.
A crawler needs policies: which pages to fetch, how to stay polite (obey robots.txt, never overload a server), and when to revisit. Many URLs lead to the same content, so a crawl always holds copies.
Each crawl ships in three formats. A WARC file holds the raw HTTP response, HTML included. A WAT file holds metadata, such as each page's links. A WET file holds text that Common Crawl extracted from the HTML: a lossy conversion. The April 2025 crawl ran for two weeks and holds 2.74 billion pages, 468 TiB uncompressed.
Choose a view of the April 2025 crawl. Formats is the whole crawl; Languages and Tokens come from one WET file we measured.
File sizes: Common Crawl's April 2025 announcement (CC-MAIN-2025-18), compressed TiB. Languages and tokens: our measurement of WET file 00000 of 100,000. We used Common Crawl's own language labels, and GPT-2's tokenizer on 2,000 sampled pages. Scaling one file to the crawl is an estimate.
Our WET file holds 27,287 pages and 216 MB of text. Common Crawl labels each page's main language: 45.1% of pages are mostly English, but only 38.3% of the bytes.
How many tokens is that? Call the bytes of text B. Call the average number of bytes in one token r, the compression ratio from Lecture 1. The token count T is:
T equals B divided by r.
Count the bytes of text: that is B. Tokenize a sample and divide its bytes by its tokens: that is r. Divide B by r to get T.
From our file, times 100,000: English text B = 8.26 TB. GPT-2's tokenizer gives r = 3.54 bytes per token on these pages. T = 8.26 × 1012 / 3.54 = 2.33 × 1012: about 2.3 trillion tokens of raw English text, before any cleaning.
For scale, the T5 paper reported about 20 TB of WET text per monthly crawl in 2019. Our file scales to 21.6 TB.
Symptom: you plan on 9 trillion tokens per crawl and end with far fewer usable ones.
Measure: compute r per language. Over all languages GPT-2 gives 2.40 bytes per token, so the whole file looks like 9.0 trillion tokens; English alone gives 3.54 and 2.3 trillion.
Fix: estimate T only for the languages you keep, with the tokenizer you will train with.
Chapter 3
Split a page into blocks, score each block, and keep the article without the menus
A web page mixes two kinds of text. Content is the article you want. Boilerplate is everything around it: menus, cookie banners, share buttons, footers. Stripping the HTML tags keeps both, and a WET file is close to that.
An extractor must guess which blocks are content, with no labels to help it. jusText did this for the Pile's Common Crawl part. It scores each block of text. It asks three things: how long is the block, how much of it sits inside links, and how many common words it uses.
Call the characters of a block that sit inside links clink, and all of the block's characters call. The link density d is:
d equals c-link divided by c-all.
Count the block's characters inside links: that is c-link. Divide by all its characters, c-all, to get d. jusText marks the block as boilerplate if d is above 0.2.
The toy page's cookie banner has c-all = 88 characters, and c-link = 25 of them are the links "Accept all" and "Manage settings". d = 25 / 88 = 0.28. That is above 0.2, so jusText drops the banner.
A block that passes the link test also needs stop words, common words such as "the" and "of". At least 30% of its words must be stop words. A block under 70 characters counts as "short", and a second pass keeps it only when its neighbours are content.
Each row is one block of the page, with its link density against the 0.2 limit. Choose an extractor and read the text that would reach training.
Illustrative toy page. Your browser runs jusText's default rules: link density 0.2, stop words 30% and 32%, lengths 70 and 200, and the context pass. Our stop list is short; jusText's English list is longer.
Stripping tags keeps all 894 characters, 6 blocks of them boilerplate. jusText's first pass keeps only 2 blocks. Alone, the heading, the caption and a short paragraph look like junk. The context pass keeps all 5 content blocks, 574 characters, and no boilerplate.
At scale this changes models. DCLM ran three extractors on the same pages with the same filters. WET text averaged 2,824 tokens per page; resiliparse kept 1,329 and trafilatura 1,179. Models trained on the extracted text scored 24.1 and 24.5 on DCLM's CORE benchmark, against 20.7 on WET.
Symptom: the model's samples end with "Share · Email · Print".
Measure: count a few boilerplate strings per million training tokens.
Fix: extract from WARC with a density-based extractor, not from WET.
Chapter 4
Move the threshold on a classifier's English score, and see which pages it keeps and which it loses
After extraction, most pipelines keep one language. A language identifier is a small trained classifier. It reads short runs of characters and returns a score for each language. The fastText model used by CCNet, RefinedWeb and Dolma covers 176 languages.
Call the page x, the classifier's English score for it s(x), from 0 to 1, and the threshold τ (tau). The rule is:
Keep x if s of x is at least tau.
Run the classifier on page x and read its English score s(x). If the score is tau or more, keep the page. If not, drop it.
With made-up scores from the device: the code tutorial has s(x) = 0.62. With Dolma's tau = 0.5 it stays. With tau = 0.65, RefinedWeb's and FineWeb's setting, it goes. C4 used a different tool, langdetect, with tau = 0.99.
Each row is a page, placed by its English score. Warm dots mark English, dashed rings mixed text, grey rings other languages. Drag tau or pick a published setting.
Illustrative: twenty made-up pages with made-up scores, chosen to show the typical errors. The three thresholds are the published ones.
At 0.5 the toy keeps 9 of 10 English pages and lets 2 mixed pages in. At 0.65 it keeps 7 English pages and lets nothing else in. At 0.99 it keeps 1. Short replies, code and lists score low because they hold little ordinary English.
The real step is large. RefinedWeb's language stage removed 50.67% of the documents that reached it, and DCLM's removed 50.8% of all documents. Dolma's removed 61.7% of the bytes. Our WET file agrees: only 45.1% of its pages are mostly English.
Symptom: the model writes standard English well but stumbles on dialect, mixed languages or informal posts.
Measure: score a sample of dialect and mixed pages, and count how many fall below tau.
Fix: lower tau, or route mixed text separately; check what a threshold drops before you choose it.
Chapter 5
Multiply each stage's keep rate, and count back how much crawl a token budget needs
Each stage keeps a fraction of what reaches it. Call that fraction the stage's keep rate, k, from 0 to 1. The stages run one after another, so the whole pipeline keeps the product. Call the overall yield K, for a pipeline of n stages:
K equals k-one times k-two, and so on, times k-n.
For each stage, divide what it kept by what it received: that is its k. Multiply all the k's. The product is K.
RefinedWeb's Figure 2: URL 0.978, extraction 0.985, language 0.493, repetition 0.757, document filters 0.838, line fixes 0.774, fuzzy dedup 0.621, exact dedup 0.805. The product is K = 0.1167: 11.67% of the documents survive.
Two halvings stand out in the hero. Language ID keeps 0.493. The three filters together keep 0.491, and the two dedup stages 0.500. That is why the paper says filtering and deduplication each halve the data.
Now turn the product around to plan. Call the clean tokens you want Dout. The raw tokens you must collect and process, Draw, are:
D-raw equals D-out divided by K.
Decide how many clean tokens you need: D-out. Divide by the yield K. The result, D-raw, is how much crawl you must collect.
DCLM turned a pool of 240 trillion tokens into 3.8 trillion, so K = 3.8 / 240 = 0.0158. For D-out = 15 trillion, the length of Llama 3's training, D-raw = 15 / 0.0158 = 947 trillion tokens. That is 3.95 times the whole pool: every Common Crawl page before 2023.
The warm bar is your target. The pink bar is the raw input it needs. The yellow line is DCLM's pool: all of Common Crawl before 2023. Drag the target, then change the yield.
Yields from the papers, each in its own unit. C4: SpaCy word tokens of English pages (Dodge et al.). FineWeb: its base-filtered 36 trillion GPT-2 tokens. DCLM: its 240-trillion-token pool. Applying a yield to a new target assumes it holds at that scale.
This is the trade Nemotron-CC attacked. It argued that DCLM and FineWeb-Edu remove about 90% of the data, too much for a 15-trillion-token run. Its 6.3 trillion tokens hold 4.4 trillion real tokens and 1.9 trillion that a model rephrased or generated.
Symptom: the run needs more unique tokens than the pipeline made, so the data repeats many times.
Measure: compute D-raw = D-out / K before you start.
Fix: loosen the strictest stage (often the classifier), add sources, or plan the repeats (Chapter 7).
Chapter 6
Walk the datasets from BERT to Nemotron-CC, and read each one as a pipeline recipe
Each dataset answered the weakness of the one before. BERT (2019) trained on BooksCorpus and English Wikipedia, with whole documents as sequences, not single sentences. GPT-2's WebText (2019) used Reddit links as a quality vote. C4 (2019) cleaned one Common Crawl snapshot with hand-written rules: keep lines that end in punctuation, drop pages with a curly bracket, keep English at 0.99.
GPT-3 (2020) trained a classifier to find Common Crawl pages that look like WebText, Wikipedia and its book corpora. It kept 570 GB of 45 TB: 1.3%. The Pile (2021) answered GPT-3 in the open, with 22 curated sources gathered by volunteers. Gopher's MassiveText (2021) used rules, not a classifier; it held 10.5 TB, and Gopher read only 12.8% of it.
LLaMA (2023) mixed seven sources into 1.4 trillion tokens, and RedPajama copied the recipe in the open. RefinedWeb (2023) argued that web data alone is enough, if filtered well: 5 trillion tokens, 600 billion released. FineWeb (2024) improved that recipe over 96 snapshots, to 15 trillion. Dolma (2024) released 3 trillion tokens from six sources, with rules and no quality model.
DCLM (2024) built a 240-trillion-token pool as a shared test bed. Its fastText classifier learned from 200,000 good examples (instruction data and the ELI5 subreddit) against 200,000 random RefinedWeb pages. It beat every rule set the paper tried. Nemotron-CC (2024) pushed back toward quantity.
Dots are datasets by year and token count; the bottom row holds those reported only in bytes. Tap a dot, or step through them, to read its recipe.
Each size is in its paper's own unit: BERT in words, C4 in SpaCy word tokens, the rest in tokens of different BPE tokenizers. We place years by paper date, spread a little to avoid overlap.
Read down the extract line. C4, RedPajama and Dolma started from WET text. The Pile, RefinedWeb, FineWeb, DCLM and Nemotron-CC started from WARC with their own extractor. Read down the filter line: rules, then classifiers trained on what good text looks like.
Symptom: you compare two datasets by token count and draw a conclusion.
Measure: check the units. C4's 156 billion are SpaCy word tokens, GPT-3's are BPE tokens, Dolma's are Llama tokens.
Fix: tokenize a sample of each with one tokenizer before you compare.
Chapter 7
Decide how often each source is read, and compute its share of training from its size and its epochs
After the pipeline you hold several clean sources of different sizes and quality. The mix decides how often the model reads each one. An epoch over a source is one full pass through it. A curator may read Wikipedia three times and a web dump once.
The Pile states its choices exactly. Call source i's raw size Si and the number of times it is read ei. Its weight wi, its share of the training bytes, is:
w-i equals e-i times S-i, divided by the sum over j of e-j times S-j.
Multiply each source's size S-i by its epochs e-i: that is its effective size. Add the effective sizes of all sources. Divide one source's effective size by that total to get w-i.
From the Pile's Table 1: Wikipedia has S = 6.38 GiB and is read e = 3.0 times: 19.13 GiB (the table multiplies the unrounded size). All 22 sources add up to 1,254.20 GiB. w = 19.13 / 1,254.20 = 1.53%, double its raw share of 0.77%.
Bars are the Pile's largest sources. Switch between raw share and training weight, and watch the sources read twice grow. Pick a source to read its numbers.
Sizes and epochs from the Pile's Table 1 (Gao et al., 2020). We compute the weights with the equation above; they match the table to 0.01 points.
Pile-CC is 27.5% of the raw bytes but 18.1% of training, read once. GitHub is read once too: 11.5% raw, 7.6% of training. PubMed Central, arXiv and Stack Exchange are read twice.
GPT-3 sets the weights directly, as shares of training examples. Common Crawl gets 60% and is read 0.44 times; Wikipedia gets 3% and is read 3.4 times; Books1 and Books2 get 8% each. LLaMA gives Common Crawl 67%, read 1.10 times, and reads Wikipedia 2.45 times.
Symptom: a small source with a big weight starts to come back word for word in samples.
Measure: compute every source's epochs before you train.
Fix: cap small sources. Muennighoff et al. (2023) found that up to 4 epochs of repeated data cost almost nothing in loss; past that, each repeat is worth less.
Chapter 8
Set the weights of GPT-3's five sources and a token budget, and watch how often each source repeats
Turn the weight equation around. Call the training budget D tokens. Source i gets wi of them, and it holds Si tokens. Its epochs ei are:
e-i equals w-i times D, divided by S-i.
Multiply the weight w-i by the budget D: those are the tokens drawn from source i. Divide by the tokens it holds, S-i. The result is e-i.
GPT-3's Wikipedia: w = 0.03, D = 300 billion, S = 3 billion. e = 0.03 × 300 / 3 = 3.0. The paper reports 3.4; the table rounds its weights and sizes, and the weights add to 101%. Common Crawl gives 0.60 × 300 / 410 = 0.44, as reported.
Top: the share of training each source gets. Bottom: how many times each is read, against the 4-epoch line. Load a preset, then drag the weights and the budget.
Source sizes from GPT-3's Table 2.2 (410, 19, 12, 55 and 3 billion tokens). The page scales your weights to add to 100%. The 4-epoch line is Muennighoff et al.'s 2023 finding; what a repeat costs past it depends on the model and data.
Things to try. Load the GPT-3 mix and raise the budget to 1 trillion tokens: Wikipedia passes 4 epochs, then WebText2 and Books1. Choose "proportional to size": every source is read 0.60 times at 300 billion, and Wikipedia falls to 0.6% of training.
Check yourself. With the GPT-3 weights, what budget puts Wikipedia exactly at 4 epochs? Work it out, then drag there: D = 4 × 3 / 0.03 = 400 billion, at the rounded weights.
Chapter 9
Find when a work enters the public domain, and learn the two legal paths for one that has not
Copyright covers almost everything on the web. US law protects "original works of authorship fixed in any tangible medium of expression". It needs no registration, and the bar is low: your blog post counts. It covers the expression, not the idea: the code of a quicksort, not the algorithm.
Protection ends. Under current US law, a work by one author stays protected until 70 years after the author's death. A work made for hire, or a work from 1927 to 1977 with a renewed copyright, stays protected for 95 years from publication. Call the year of publication ypub. The year the work enters the public domain, yPD, on 1 January, is:
y-P-D equals y-pub plus ninety-six.
Take the year of publication, y-pub. Add 95 years of protection and 1 more year, because the term runs to 31 December. The work is free on 1 January of y-PD.
A book published in 1930: y-PD = 1930 + 96 = 2026. It entered the US public domain on 1 January 2026.
The yellow span is the protected term; green is the public domain. Choose the kind of work, then drag the year.
US terms under 17 U.S.C. §§ 302 to 304, simplified: we ignore the 120-years-from-creation cap for works made for hire and works whose renewal lapsed (those entered the public domain early). Other countries differ. Not legal advice.
For a protected work, the lecture names two paths. A license is "a promise not to sue". Creative Commons licenses cover Wikipedia; labs also buy licenses, as Google did from Reddit. The Stack kept only code under permissive licenses such as MIT and Apache 2.0.
The other path is fair use, section 107 of the Copyright Act. Courts weigh four factors: purpose, the nature of the work, the amount used, and the effect on the original's market. Training is transformative, which favours fair use. It copies whole works and can compete with authors, which counts against it.
Courts have started to rule. In Bartz v. Anthropic (June 2025), a US district judge held that training on books was fair use, but sent the claims about pirated copies to trial. The case settled for $1.5 billion that September. Terms of service add one more layer: YouTube's terms forbid downloading videos, even ones under Creative Commons.
Symptom: a court or a host takes down a dataset you trained on, as happened to Books3, and you cannot say which models used it.
Measure: record the source, license and terms of every shard you ingest.
Fix: prefer public-domain, openly licensed or licensed data, and keep provenance so you can remove a source later.
Chapter 10
Keep the datasets, the code, the checks, and the data for the later training stages
Pretraining data starts as a live service, becomes a raw snapshot, and becomes processed text. Every stage keeps a fraction, and the fractions multiply: RefinedWeb keeps 11.67% of documents, DCLM 1.4%. Extraction and language ID decide what enters the filters; the mix decides how often each survivor is read; the law decides what you may use.
| Dataset | Year | Starts from | Size | What survives |
|---|---|---|---|---|
| C4 | 2019 | one snapshot's WET text | 156 billion word tokens | 11.1% of English tokens |
| GPT-3 Common Crawl | 2020 | 41 monthly shards | 570 GB, about 400 billion tokens | 1.3% of 45 TB |
| The Pile | 2021 | 22 sources; WARC and jusText | 825 GiB | a curated mix, not one funnel |
| RefinedWeb | 2023 | WARC and trafilatura | 5 trillion (600 billion public) | 11.67% of documents |
| Dolma | 2024 | 6 sources; CCNet on 25 snapshots | 3.06 trillion Llama tokens | CCNet kept 15.8% of the bytes |
| FineWeb | 2024 | 96 snapshots; WARC and trafilatura | 15 trillion | 41.7% of base-filtered tokens |
| DCLM-Baseline | 2024 | a 240-trillion pool; resiliparse | 3.8 trillion | 1.4% of documents, 1.58% of tokens |
| Nemotron-CC | 2024 | jusText; classifier ensemble | 6.3 trillion (1.9 synthetic) | more on purpose: quantity for long runs |
The core of a pipeline, as runnable code. Each stage is a function that keeps or drops a document, and the tracker records every keep rate.
python import math def run_pipeline(docs, stages): """docs: list of str. stages: list of (name, keep_fn). Returns kept docs and keep rates.""" rates = [] for name, keep in stages: before = len(docs) docs = [d for d in docs if keep(d)] rates.append((name, len(docs) / before if before else 0.0)) return docs, rates def link_density(block_text, link_chars): return link_chars / len(block_text) if block_text else 0.0 # d = c_link / c_all def make_dedup(): seen = set() def keep(d): key = " ".join(d.lower().split()) # exact match after light normalisation if key in seen: return False seen.add(key) return True return keep english_score = lambda d: 0.9 if " the " in f" {d.lower()} " else 0.1 # stand-in for fastText lid.176 TAU = 0.65 stages = [ ("extract", lambda d: len(d.strip()) > 0), ("language", lambda d: english_score(d) >= TAU), # keep x if s(x) >= tau ("dedup", make_dedup()), ] docs = ["The Moon has phases.", "", "La lune a des phases.", "the moon has phases.", "The tide follows the Moon."] kept, rates = run_pipeline(docs, stages) K = math.prod(r for _, r in rates) # K = k1 * k2 * ... * kn assert abs(K - len(kept) / len(docs)) < 1e-12 # the product equals the end-to-end share assert link_density("x" * 88, 25) > 0.2 # the cookie banner: 0.28, dropped print(rates, K) # keep rates 0.8, 0.75, 0.667 -> K = 0.4: 2 of 5 docs survive
We ran this code: the keep rates are 0.8, 0.75 and 0.667, and K = 0.4, the same as 2 surviving documents out of 5. For real data, read WARC records with warcio, extract with trafilatura, resiliparse or justext, and score languages with fastText's lid.176.bin.
Mid-training and post-training data are smaller and aimed at one skill. LongLoRA extends Llama 2 7B from 4,000 to 100,000 tokens of context by training on long documents: PG-19 books and Proof-Pile math. Super-Natural Instructions (more than 1,600 tasks) and Flan 2022 (more than 1,800) turn existing datasets into prompts. Alpaca's 52,000 examples came from text-davinci-003; Llama 2-Chat used 27,540 examples written by hired annotators.
Now teach it: press Present or Teach. Explain why WET text needs a better extractor, why a threshold drops good English, and why keep rates multiply. Then go back to the pipeline, switch off language ID, and predict the new yield before you look.