Lecture guide: Data: sources, datasets#
Lecturer: course staff · Course: Stanford CS336 Language Modeling from Scratch, Spring 2026, lecture 13 · Length: 1:22:00 Video: watch on YouTube Chapters that cite this lecture: 10. Training Data
In one sentence: Percy Liang shows where pretraining data actually comes from, what stops anyone from taking it, the copyright rulings so far on its use, and how the data sets behind models from BERT to Nemotron were collected and filtered.
Before you watch#
The lecture is the first of two on data and assumes nothing beyond the earlier lectures' picture of pretraining, mid-training and post-training. It is a social and legal history as much as a technical one: the first half is about crawling and copyright, the second a tour of named data sets. The video has no chapter marks. The chapter Training Data keeps the pipeline steps and the legal layer; this guide holds the history.
The lecture, part by part#
0:00–4:00 Data is the most important thing#
The course has shown how to train a model given data and how to judge a model; the next two lectures ask what data to train on. Liang's claim is that nothing matters more than getting the data right, and what companies disclose supports it: the Llama 3 paper is fully open about its architecture and training procedure and says nothing about its data beyond a list of source types. Two reasons for the secrecy: data is the competitive secret, and admitting to certain sources invites copyright suits. Before foundation models, data work meant annotating labels for supervised learning; pretraining now needs less manual annotation but as much curation and cleaning. Data has always been a bottleneck and will remain one, because it is a long-tail problem that scales with human effort, which is why data teams are large. Three stages take different data: pretraining on raw web documents, mid-training on higher-quality data to strengthen capabilities and long context, post-training on chat logs or reinforcement-learning environments. The lines blur. The trend runs from much low-quality data to less high-quality data; a base model is roughly the state after pretraining and mid-training, an instruct model the state after post-training, though for the largest models, such as Qwen 3.5 397B, no base model is released at all. Open models like AI2's OLMo show every stage. In this book: Training Data › Why this matters · Training Data › The core idea.
4:00–8:00 The web is not a data set#
One hears that language models train on the whole of the internet. That does not quite type-check: it would take an agent acting on the internet, and pretraining is not that. Trained on the public web is more accurate and still wrong. The web is a set of live servers; a request to one returns a page, and nobody trains on live servers unless training an agent. What is trained on is a crawl: a crawler starts from seed URLs, discovers pages and downloads them. Even a crawl cannot get everything. Much of the web is dynamic: many sites are applications whose URLs do not specify the content, which appears after clicks and forms, as in Discord. Much lies in the deep web, which is not reached by following links. And much sits behind logins and paywalls: Facebook, X, LinkedIn, the New York Times. Their owners can train on them; nobody else can reach them. In this book: Training Data › 1. Get raw data.
8:00–14:00 Robots files, terms of service and shadow libraries#
Past authentication come other restrictions. A robots file at the root of a site, such as that of the New York Times, lists what may be crawled, and many now disallow the bots of AI companies; it is not a law, only the convention of a good citizen. Services such as Cloudflare detect bots and serve captchas; sites block addresses and countries and impose rate limits: technical restrictions. Terms of service are contracts that often tell bots to stay away or forbid AI training; content also carries licences. A paper titled Consent in Crisis measured both kinds of restriction over time: the share of sites fully closed by their robots file was stable until 2023 and then rose to about half, and terms went from rare in 2016 to near universal, most forbidding AI use. What can be crawled legally is much smaller than in 2020. The rules are also broken: one site complained of being hit a million times in 24 hours by a crawler, and Read the Docs was hammered too, which costs hosts money and degrades service. Shadow libraries such as Library Genesis and Anna's Archive ignore copyright and bypass paywalls, offering books and papers for free; takedown orders and lawsuits follow, and so do servers in other countries. Their defenders call it freeing what should be free; the law calls it piracy. In this book: Training Data › 1. Get raw data · Training Data › 7. The legal layer.
14:00–18:00 What copyright covers#
Suppose the terms of service and the rate limits are respected. May one still train on the data? The question is open, though the last year brought developments. It belongs to intellectual property law, whose spirit is to incentivize the creation of intellectual goods through copyright, patents, trademarks and trade secrets; copyright is the relevant kind. It dates to 1709 in England, and the Copyright Act of 1976 shapes the American version: it protects original works of authorship fixed in a tangible medium. Not everything qualifies: a collection such as a telephone book is free unless its arrangement is creative. It protects an expression, not an idea: the quicksort algorithm cannot be copyrighted, an implementation of it can. Since 1976 nothing has to be published or registered to be protected, unlike a patent, which costs much to obtain; registering, which suing requires, costs $65. Protection lasts 75 years, after which the work enters the public domain. So everything on the internet is copyrighted. In this book: Training Data › 7. The legal layer.
18:00–26:00 Licences and fair use#
Copyrighted works can still be used in two ways. One is a licence, a contract in which the licensor promises not to sue for uses it permits. Creative Commons, created in 2001, lets a creator make a work behave as if it were in the public domain; Wikipedia, OpenCourseWare and Khan Academy use it. Otherwise a licence must be bought, and model developers have struck deals with content platforms. The other way is fair use, section 107 of the Act, decided on four factors that are tendencies weighed in court, not rules: the purpose and character of the use, education and transformation faring better than hosting an identical copy; the nature of the work, factual matter protected less than fiction; the amount taken, a snippet better than the whole; and the effect on the market for the original, which follows from the purpose of copyright. Watching a film and summarizing it, or reimplementing an algorithm without copying code, are fair use. Authors Guild against Google, over the snippets in Google Books, ended after eleven years in Google's favour and set a precedent. Copyright is not only about verbatim memorization: plots and characters can be protected, Harry Potter among them, and parody is an exception. It concerns semantics and economics, not overlap of word sequences. In this book: Training Data › 7. The legal layer.
26:00–32:00 The lawsuits#
For language models: the act of copying, before any training, can already be a violation. Training has, in Liang's intuition, the flavour of transformation, since the data is a means to the end of learning about the world rather than a re-hosted work, but models can also affect the market, the fourth factor, so fair use is slippery. Terms of service add a further layer: YouTube videos may carry open licences while downloading them is forbidden. The landscape: the New York Times sued OpenAI in 2023, showing that ChatGPT could be prompted to reproduce an article almost word for word; the case is still pending. Anthropic was accused of pirating millions of books; a ruling the year before found that training, in that instance, was fair use but held that pirating them was unlawful. Anthropic had also bought and scanned copies, which is fair use, without erasing the earlier piracy, and paid 1.5 billion dollars to settle, about 3,000 dollars a book. Meta was sued over books that the Llama paper revealed it had trained on; the judgment after Anthropic's again called training fair use, and the downloading of books by torrent is still before the court. In sum, training has not been ruled unfair use, in narrow rulings; pirating is plainly illegal; the area keeps moving. Asked about a licence tightened later, he says he is not a lawyer and believes the earlier version stays usable, though not content created after the change. In this book: Training Data › 7. The legal layer.
32:00–36:00 Common Crawl#
Most developers run their own crawler to control the data. The rest have Common Crawl, running since 2007: a crawl every month of 3 to 5 billion pages, with some overlap between crawls, and by its own count 300 billion pages so far, a figure Liang doubts after multiplying. How many URLs exist is unknown; Google's index is at least 100 petabytes. A single dump holds about two billion pages, 372 terabytes of text without images. Crawling is conceptually a graph traversal, a URL popped from a queue, downloaded, its links queued, in parallel across machines; the gory details are the choices: which pages to fetch, respect for robots files and server load, how often to revisit pages that change. URLs are unreliable in both directions: one URL may serve different content, and many may serve the same, as mirror sites do. Common Crawl releases each dump as the raw HTTP responses and as a lossily converted text; better conversions come from tools such as trafilatura and resiliparse, which the DataComp-LM paper found to extract more useful text than the official one. In this book: Training Data › 1. Get raw data · Training Data › 2. Transform.
36:00–40:00 Wikipedia#
The web is not uniform, and some pockets hold high-quality content. Wikipedia, since 2001, has 67 million articles across languages. It publishes no original research, since everything must be cited, and it cites books as well as pages; articles depend on notability. Anyone may edit, the radical idea of wikis and, to him, still a miracle: vandalism is reverted by administrators and bots, and a small number of editors do most of the work, one of them with five million edits. Every few weeks Wikipedia publishes a dump, which is how it should be obtained instead of crawling. One aside: a study showed that the dumps can be poisoned. Since they are taken at a fixed cadence, an edit made just before a dump is captured by it and rolled back only afterwards, and injected pages can teach a model, for instance, negative sentiment toward a trigger phrase. The lesson: once adversaries are considered, even high-quality sources can carry bad content. He believes this has since been fixed. In this book: Training Data › 1. Get raw data.
40:00–44:00 GitHub, arXiv, and two questions#
GitHub, since 2008, hosts 420 million repositories, 28 million of them public; a repository is a directory that carries its commit history, its issues, its pull requests and comments, and code has many duplicates from copying and forking. GitHub allows training on public repositories with permissive licences such as MIT or Apache. Two kinds of data exist: the repositories, to be downloaded over git rather than scraped, and the metadata, available as hourly snapshots of every event, comments and stars included, from the GitHub Archive; the Software Heritage foundation aggregates repositories, GitLab's and Bitbucket's too. arXiv, a paper server since 1991, holds three million submissions, each with metadata, a PDF and optional LaTeX source, so what training on arXiv means needs a decision: convert the PDF or use the LaTeX. Submissions are moderated, not peer reviewed, and authors keep their rights or choose Creative Commons; the metadata is permissively licensed, most papers are Creative Commons, and the whole is available for bulk download. In questions: data generated by models may probably be used, a subject for later; and a crawl cannot be guaranteed free of pirated books, since nobody can inspect every site, so Common Crawl almost surely contains content it should not, and fair use is the remaining defence. In this book: Training Data › 1. Get raw data.
44:00–52:00 From BERT to C4#
Now the data sets behind models, from 2018 on. BERT trained on Wikipedia and a books corpus built in 2015 from the free e-books of Smashwords, in days when nobody paid attention; it has since been taken down for violating the site's terms, free being not the same as permitted. BERT's sequences were whole documents, where earlier work had used sentences. GPT-2 in 2019 wanted high-quality pages, and Common Crawl was too messy: it took the outgoing links of Reddit posts with more than three karma, on the reasoning that good posts link to good pages, and obtained 40 GB of text, never released; an open replication, OpenWebText, is widely used. CCNet, from Facebook, wanted large high-quality data for many languages: deduplication, a language classifier, and quality judged by a language model trained on Wikipedia, each document scored by how Wikipedia-like it is; more data than Wikipedia alone, and better models. C4, a large contribution of the T5 paper from Google in 2019, was built on the observation that Common Crawl is mostly useless for natural language. Its rules: keep lines ending in punctuation with more than five words; drop pages with fewer than three sentences; drop pages with bad words; drop boilerplate such as terms of use; drop anything with a curly brace, which removes a lot of code, no concern of the time; and keep English only. The result: 156 billion tokens, about 800 GB. Later analysis found much Wikipedia and many patents. The same Reddit method on twelve Common Crawl dumps yielded only 17 GB, against WebText's 40, which suggests that Common Crawl is incomplete. In this book: Training Data › 3. Filter · Training Data › What the practitioners say.
52:00–58:00 GPT-3, The Pile and books#
GPT-3 processed Common Crawl itself, classified by a quality filter trained to separate good documents from the rest, and added WebText2, an expanded WebText, two corpora called Books1 and Books2, internet-based books whose exact nature remains a mystery, and Wikipedia: about 500 GB, 400 billion tokens, with fuzzy deduplication. Open efforts followed. The Pile, put together by EleutherAI in a Discord channel, still looks diverse: Common Crawl, PubMed, arXiv, GitHub, Wikipedia, philosophy papers, the Enron e-mails, one of the few e-mail data sets anywhere and a strange one, and Books3. On books: Project Gutenberg, since 1971, holds only copyright-cleared books, mostly public domain, packaged for language modelling as PG-19; Books3, about 200,000 books from the shadow library Bibliotik, sat in The Pile unnoticed in 2020 and has since been taken down, so it cannot and should not be used. Stack Exchange, since 2008, holds questions and answers in a form close to a real application: question answering is not entirely emergent, since such data exists on the web; its vote counts help filtering, and it is published as dumps. In this book: Training Data › 3. Filter · Training Data › 7. The legal layer.
58:00–64:00 Gopher, LLaMA 1, RefinedWeb, FineWeb and Dolma#
Gopher, a DeepMind model of 2021 that was never released and was overtaken by Chinchilla, has one of the best descriptions of data processing, outside the parts it leaves out. Its MassiveWeb kept English, was deduplicated and was filtered by manual rules, for the sake of control; the books, news, code and Wikipedia are left undescribed; and the model trained on a small fraction of it. So there were already two camps, rules and classifiers. LLaMA 1 in 2022 is among the last fully open models to describe its processing: Common Crawl through CCNet, but keeping pages that Wikipedia cites rather than pages that look like Wikipedia, on the thought that articles are too stylized and that what they cite must be good; C4; GitHub filtered to permissive licences; Wikipedia; Books3 and Project Gutenberg; arXiv from the LaTeX source; Stack Exchange: 1.2 trillion tokens, not released but described well enough for Together's RedPajama v1 to reproduce it, Books3 included at first and since removed. Announcing Books3 is what brought LLaMA 1 trouble, and, in his account, why nobody discusses data any more. RefinedWeb argued that web data is all you need: careful extraction of text, the Gopher rules, and, explicitly, no model-based filtering, to avoid the bias of a narrow subset: five trillion tokens, 600 billion released. Hugging Face's FineWeb replicated and improved it over every dump, with manual rules, deduplication and removal of personal information: 15 trillion tokens. AI2's Dolma mixes its own Common Crawl, The Stack, C4, Reddit from Pushshift before it was locked down, and Semantic Scholar; its Common Crawl uses a language model for language identification but not for quality, and removes toxicity with rules and a classifier: three trillion tokens. In this book: Training Data › 3. Filter.
64:00–70:00 DCLM and Nemotron: model-based filtering and synthetic data#
DCLM is where, by his account, model-based quality filtering started to become the norm. DataComp meant to define a standard pipeline for comparing data methods; most people simply use its data set. Its pool is Common Crawl left unfiltered, 240 trillion tokens, more than anyone trains on, most of it poor; English, rules, deduplication and a classifier reduce it to 1.4%, 3.8 trillion tokens, which work well. The classifier is odd and effective: a fastText model, close to linear, trained to separate positive examples, the instruction data of OpenHermes, generated by GPT-4, and the questions and answers of a subreddit that explains things to a five-year-old, from negatives, which are anything from RefinedWeb. For a while it was the open community's gold standard. NVIDIA's Nemotron found that it filters too aggressively and more tokens are needed: a language model was prompted to score FineWeb documents by educational value, a fastText model was trained on those scores, and it was combined with the DCLM classifier. Nemotron also leaned on synthetic data: low-quality documents rephrased by a language model into something more like Wikipedia, and tasks generated from high-quality ones, questions and answers from an article, summaries, key information: six trillion tokens. For scale, Llama 3 trained on 15 trillion and Qwen 3 on 36, though token counts include repeats. Nemotron's high-quality subset beat the earlier data sets. In this book: Training Data › 3. Filter · Training Data › 6. Synthetic data.
70:00–74:00 The pattern, and The Stack for code#
All the filtering methods look alike: take a crawl, choose rules or a model, and with a model decide what good data looks like, train a classifier and select. A trade-off runs between 240 trillion tokens of low quality and about a trillion of high quality, with a sweet spot between. Code has its own data set. The Stack, started when it was clear by 2022 that coding mattered, cloned repositories for its first version, kept the permissively licensed code, removed near-duplicates and kept three terabytes. The 2024 version added the metadata of GitHub, issues, comments and pull requests, repositories from Software Heritage and documentation scraped from the web. Processing removes binary files, malware, bots and personal information, deduplicates, and subsamples pull requests to stay representative. One idea he likes: rare languages such as Nim are juxtaposed with their compiled form in LLVM's intermediate representation, on which data is plentiful, so the model learns the mapping between the two. In this book: Training Data › 1. Get raw data.
74:00–80:00 Linearizing pull requests; Common Pile#
A pull request is not a linear sequence and must be turned into one, which forces decisions: a change of one line is one line of text, but learning from it wants context, a few lines around it or the whole file. The training text looks like XML: a pull request, its differences, then events such as a comment posted and the review state at that moment, so the model learns the development process around code, not code alone. Common Pile returns to licensing. Almost everything online is copyrighted, some of it permissively licensed or in the public domain, and fair use is unsettled; the risk-averse attitude is that whatever is unclear is excluded. The project asked how far a model gets on permissive data only and scoured the web for it: The Stack v2, government proceedings, wikis, some news sites, academic papers, forums, public-domain works, educational resources: eight terabytes, good for the category. It is harder than reading a licence. Licences are laundered: anyone can paste an open licence onto a copyrighted work. A collection's licence does not extend to its works, and many data sets on Hugging Face are open as collections and not as works. And synthetic data was foregone, since models with open licences were presumably trained on unlicensed text, a laundering of data. The resulting models beat those of 2023 and fall short of Qwen: reasonable, but hard to compete without more tokens, and not the final word. In this book: Training Data › 7. The legal layer · Training Data › 6. Synthetic data.
80:00–1:22:00 Summary#
Data does not fall from the sky, nor is it simply downloaded from Hugging Face. The internet is a set of live services; someone produces the raw data, through dumps or a crawler; and someone decides how to process it into a usable form, and filtering, transformation and deduplication all bear on the final model. Filtering may matter most: going from 200 trillion tokens to under three trillion deserves attention. Data is the ingredient that differentiates models that share one architecture. Legal and ethical issues abound, beyond what one lecture can cover, and the process is messy: less first principles than judgement, a classifier here, a rule and a threshold there, and therefore full of opportunities, which assignment 4 invites students to look for. Next time: post-training data and more on filtering. In this book: Training Data › Key takeaways · Training Data › What the practitioners say.
What to take away#
- Companies disclose their architectures and procedures but not their data, because data is the competitive secret and the legal exposure.
- The web is not a data set: much of it is dynamic, behind paywalls, closed by robots files, sharply tightened since 2023, and by terms of service.
- Everything online is copyrighted by default; use rests on a licence or on fair use, whose four factors courts weigh, and the rulings so far call training fair use in narrow cases while leaving piracy plainly illegal.
- Data sets from WebText to C4, The Pile, RefinedWeb, FineWeb, DCLM and Nemotron differ by how they filter: Reddit links, rules, Wikipedia-like classifiers, a classifier trained on odd positives, or a model's educational scores and synthetic data.
- Decisions made early about sources, Books3 among them, echo for years; how raw text is filtered into a few trillion tokens is where much of a model's quality is decided.
Sources#
- Percy Liang and the course staff, "Data: sources, datasets", Stanford CS336 Language Modeling from Scratch, Spring 2026: video.
- Course page: https://cs336.stanford.edu/.