07How a model learns: data and training
Where the text comes from, how it is cleaned and fed in, how each number learns which way to move, and what it costs.
A multiplication algorithm can be explained, proven, and trusted to be right every time. A neural network is different, and the difference is worth stating precisely. This chapter follows training from start to finish: where the text comes from, how it is cleaned, how it is fed in, and how each of the model's numbers learns which way to move.
Where the text comes from
A model learns only from what it reads, so the first job is to gather an enormous amount of text. The main sources:
- The public web. Most of the volume. Much of it comes from Common Crawl[19], a non-profit that has been archiving the public web since 2008, supplemented by the labs' own crawlers.
- Code, from public repositories.
- Reference and scientific text: encyclopedias, academic papers, patents, technical documentation.
- Books and licensed data, bought or negotiated from publishers, news organisations and data providers.
- Synthetic data, increasingly: text produced by other models, for example worked mathematics problems, checked before use.
The quantities are hard to picture. Meta's largest Llama 3 model was trained on about 15 trillion tokens[20]. A person reading eight hours a day for seventy years gets through roughly 3 billion words, so this amounts, very roughly, to several thousand lifetimes of full-time reading. Public datasets of the same order exist: Hugging Face's FineWeb holds 15 trillion tokens built from 96 Common Crawl snapshots, with every processing step documented[21].
Cleaning it up
Raw web text is mostly unusable: menus, cookie banners, spam, duplicated pages, machine-generated filler, personal data. Most of the engineering effort goes into curation. Meta describes its pipeline for Llama 3[20], and the other labs follow broadly similar steps:
- Extract the text. Keep the content of each page and throw away the layout, menus and advertising around it.
- Remove unsafe and personal content. Meta removed domains known for adult content and domains holding large amounts of personal information.
- Remove duplicates. The same article copied across a thousand sites would otherwise be learned a thousand times. Duplicates are removed at the level of addresses, whole documents, and even individual lines repeated across millions of pages.
- Keep quality text. Simple rules first: too many repeated phrases, too many offensive words, a vocabulary that looks machine-generated. Then models trained to grade text. Meta used its previous model, Llama 2, to label examples of good and bad text, and trained the grading models on those labels. Each generation of model helps select the reading list of the next.
- Mix the sources. The proportions are a deliberate choice, tested on smaller models first. Llama 3's final mix was roughly half general knowledge, a quarter mathematics and reasoning, 17% code and 8% other languages. That last figure is one reason these models are noticeably stronger in English than in French.
Two remarks for executives. First, a model can only be as good, as balanced and as current as its reading list. Its knowledge stops at the date the text was collected, and its gaps and biases are largely those of its data. Second, the legal status of training on copyrighted text is being contested in court in several countries. In the European Union, the AI Act now requires providers of general-purpose models to publish a summary of the content used for training and to respect rights holders' opt-outs[22].
Feeding it in
The cleaned text is tokenized, documents are placed end to end, and the whole stream is cut into chunks of fixed length. For Llama 3, chunks were 8,192 tokens long during most of training[20].
Here is the key point, and it connects back to the beginning of the article. Remember the rule from chapter 03: each token can only look at the tokens before it. That rule turns every chunk into thousands of exercises at once. Each position is a question ("what comes next?") whose answer is simply the next token in the chunk:
Notice what this means. No human has to label anything: the text supplies its own answer key. Specialists call this "self-supervised" learning, and it is the reason training can scale to a large share of the written web. It is also where the 2017 design pays off: all the questions of a chunk are answered and corrected in a single pass, where a recurrent network would have had to work through them one after the other.
Chunks are then grouped into batches. For its largest model, Meta started with batches of 4 million tokens and grew them to 16 million[20]. Each batch produces one step of learning, and about a million such steps took the model through its 15 trillion tokens. Most of the text is read only once. The best sources may be read several times, and the last phase of training concentrates on the highest-quality material, much like a final revision before an exam.
Learning by guessing
Think of a sound engineer at a desk with billions of knobs, told after each recording which way to turn every one of them. No single knob understands music, yet after millions of corrections the desk plays in tune. Nobody ever writes grammar, facts or reasoning into the model: they emerge from billions of tiny corrections. The question is how the engineer knows which way to turn each knob.
We know exactly how a model learns. What we cannot predict is what it will end up knowing.
Where does the direction come from?
Go back to the moment training began. Suppose the classic network of chapter 05 has not yet learned its correction, so "anto" reaches the top of the model as [1.0, 0.4, 0.0], the value it had after attention. The training text says the next token is "fluently". The model's guess: "English" 36%, "fluently" 36%, "French" 25%, everything else 3%. It is undecided, and gives the right answer only about a third of the probability.
Score the error. The error depends on one thing only: how much probability the model gave to the right answer. 100% means no error; the lower the figure, the larger the error.
Find the direction. For the final vector, the direction has a remarkably simple form: towards the right answer, away from what the model expected. "What the model expected" is the average of all the token rows, each weighted by the probability the model gave it. Here that average is about [0.82, 0.46, 0.06], a point somewhere between "English", "French" and "fluently". The direction is the difference: fluently [0.7, 0.8, 0.0] minus expected [0.82, 0.46, 0.06], which gives [−0.12, +0.34, −0.06]. In plain words: less "language", more "speaking".
Take a small step. The vector moves a fraction of the way along that direction. With a step of one half, it becomes [0.94, 0.57, −0.03], and "fluently" rises from 36% to 61%. The model is not right yet, but it is less wrong.
Try it yourself. Change the right answer or the step size and see how far one nudge moves the vector. Download the toy model as a spreadsheet, built with the help of Claude.
But the final vector is not a knob. Nobody can set it directly: it is computed from the table, the attention weights and the network's parameters. So the nudge has to travel backward through everything that produced it. For each parameter, the question is: "if I turned this knob slightly, would the final vector move in the desired direction or against it, and by how much?"
The naive way to answer would be a wiggle test: turn each knob a hair, rerun the model, see whether the error went up or down. With billions of knobs, that would take forever. A mathematical shortcut called backpropagation[2] gets the answer for every knob at once, in a single backward pass that costs about as much as the forward one. It works backward from the error, step by step: the scoring, then the network, then attention, then the table. At each step it works out how each part contributed to the final vector, and so which way that part should turn. Every parameter in the model gets its own small direction from that one wrong guess.
That includes the table from chapter 02. The row for "fluently" is nudged slightly towards the vector that should have predicted it. The rows for "English" and "French" are nudged slightly away, because they got probability they did not deserve. This is exactly the mechanism behind "you shall know a word by the company it keeps": rows drift according to the contexts they keep being right, or wrong, about.
Why billions of tiny nudges and not a few big ones. A single sentence is a poor guide. In another training sentence, "I speak Esperanto" is followed by "and French", and the direction there would point the other way. So the model never takes a step on one example alone. Each step is computed from the average of all the directions in a batch, millions of tokens. Nudges that contradict each other cancel out; those that agree across many sentences accumulate. Over a million steps, what survives is what holds true across the text as a whole. The size of each step is a setting chosen by the engineers. Too large, and training becomes unstable; too small, and it never ends. It is tuned by trial and error, which is one more reason training is an empirical craft as much as a science.
Watching it learn
Training is not launched and left alone. The engineers watch:
- The error, on text the model has never seen. A slice of data is set aside and never used for training. If the error goes down on that unseen text too, the model is learning patterns rather than memorising.
- Checkpoints. The full state of the model is saved regularly, so training can resume after a failure or roll back if something goes wrong.
- Failures, which are routine. Over a 54-day period, Meta's training run, spread over up to 16,000 GPUs, was interrupted 466 times, 419 of them unexpectedly, mostly because of hardware faults[20]. At that scale, keeping the machine running is a discipline of its own.
- Step size. It starts small, rises, then decreases gradually towards the end of training, following a schedule chosen in advance and validated on smaller models. Like the data mix, it is a choice made by experiment, not derived from theory.
Why it works on texts it has never seen
Why does the model get better at texts it has never read? Because it has far too few parameters to memorise everything it is trained on, so the only way to keep improving is to capture what all those texts have in common: grammar, facts, patterns of reasoning. Like a student facing millions of different exam questions, it has no choice but to understand rather than cram. Patterns, unlike memorised answers, carry over to new questions.
Measured, not proven
This also means there is no proof that its answers are correct. As we saw in chapter 02, the whole approach rests on a bet that useful patterns will emerge from enough text and enough nudges. The bet has paid off so far, but a model's reliability is measured by testing, not demonstrated in advance, much as we trust a pilot by their record rather than by a theorem. That is why these systems are mostly right, never guaranteed right, and why they need verification around them. Researchers themselves are still working out why this works as well as it does: in this field, theory lags behind practice.
From text completer to assistant
A model trained only on raw text continues text: ask it a question and it may well reply with more questions, as if continuing a list of exam topics. Later phases of training turn it into an assistant, and here the direction of each nudge comes from new sources:
- Supervised fine-tuning. People write examples of good answers to questions, and the model is trained on them exactly as above: the answer key is the human-written reply.
- Learning from preferences. For many questions there is no single correct answer, only better and worse ones. The model produces several answers, people rank them, and a second model learns to predict those rankings as a score. Training then nudges the model so the preferred answer becomes more likely and the rejected one less likely[23]. The machinery is the same; only the source of the direction changes: a score instead of a known next token. This is reinforcement learning from human feedback.
- Learning from verifiable results. For mathematics or code, an answer can be checked automatically: the result is right, the program passes its tests. Recent "reasoning" models are trained largely this way: the model tries, the check scores the attempt, and successful lines of reasoning are reinforced[24].
In every case, the direction of each nudge comes from the same question: what change would have made the desired output a little more likely? This phase is also where vendors shape tone, helpfulness, refusals and safety behaviour, which explains why models built on the same architecture can behave so differently.
Training versus using
Training happens before the model is released. Using it afterwards does not change it: your conversations do not alter its parameters. This answers a question every executive asks: "does it learn from our data?" Not by being used. Whether a vendor may later include your data in a future training run is a contractual matter, not a technical one, and worth checking in the terms you sign.
What it costs
The leading vendors do not publish training costs, but independent estimates give the orders of magnitude. Epoch AI, which tracks the field, estimates that the final training run of a frontier model now costs hundreds of millions of dollars, and projects that the largest runs will exceed a billion dollars by 2027[25]. Such a run takes months on thousands to tens of thousands of specialised chips.
Published figures need careful reading. DeepSeek reported about 5.6 million dollars for its V3 model, roughly two months on some 2,000 chips[18], but that figure covers only the final run, not the experiments, failed attempts and fine-tuning that preceded it[18]. It shows both how much efficiency matters and how easily a headline figure can mislead.