What a language model is, and how it learns
A language model is a file of numbers and a recipe for multiplying them. Training is the patient search for the right numbers, and it takes some of the largest machines ever built.
The first time most people use a modern chatbot, there is a small moment of wonder. You type a question, and a fluent, thoughtful answer flows back, word by word. It feels as if something on the other side understands you.
What is actually on the other side is surprising in a different way. It is not a database of answers or a set of rules someone wrote. It is a single, very large calculation: multiply, add, repeat, billions of times for every word. That such a plain recipe can write poems, explain physics and fix your code is one of the great discoveries of our time.
This chapter opens the calculation up. We will see what a model is made of, how text turns into numbers, what "attention" means, and how a lab trains a model on a large slice of the written world. The hardware from the earlier chapters is about to get a job.
A model is one very large calculation
A large language modelLLM: a program, trained on huge amounts of text, that predicts what text comes next is a mathematical function. You give it some text. It gives back a list of probabilities for what the next small piece of text might be. That is all it does. Everything else, from conversation to reasoning, is built by calling that one function again and again.
The function has two parts. Its structure is fixed, written by engineers: which numbers get multiplied by which, in what order. And it has billions of adjustable numbers called weightsthe learned numbers inside a model that decide what it does; also called parameters, also called parametersanother name for weights: the adjustable numbers that training sets. The weights decide what the calculation actually produces.
Picture an enormous mixing desk in a recording studio, with billions of knobs. The wiring of the desk is fixed. The sound that comes out depends entirely on where each knob is set. Trainingthe process that finds good values for a model's weights by showing it data and correcting its mistakes is the long process that turns every knob to the right position. When training is finished, the knob positions are the model.
A software analogy works just as well. The structure is the source code of a program; the weights are a giant configuration file. The code is a few thousand lines that a good engineer can read in an afternoon. The configuration file has a hundred billion entries, and no person wrote any of them.
So when you "download a model," you download a file of numbers. For a model with 120 billion parameters, that file is somewhere between about 60 and 240 gigabytes, depending on how many bits each number uses. We will come back to that.
The neuron: the smallest unit
The calculation is built from millions of tiny units. Engineers call each unit a neuron (artificial)a tiny unit in a model that multiplies its inputs by weights, adds them up and applies a simple bend. The name comes from the brain, but the artificial neuron is far simpler than a real one (see the brain's neurons for the remarkable original).

An artificial neuron does three things:
- It multiplies each input number by a weight.
- It adds up all the results.
- It applies a simple non-linear stepa small bend in the calculation, such as turning every negative number into zero; without it, stacking layers would add no power, for example turning any negative result into zero.
input 1 (0.5) ──× weight 0.8 ──┐
input 2 (0.2) ──× weight -1.5 ─┼──► add: 0.4 - 0.3 + 0.9 = 1.0 ──► non-linear step ──► output 1.0
input 3 (0.9) ──× weight 1.0 ──┘One neuron is not clever. But billions of them, arranged in many layers, can learn astonishingly rich patterns. And notice what the work mostly is: multiply and add. That is why GPUs, which can do trillions of multiply-and-add operations every second (chapter 12), became the engines of AI.
From text to numbers
A computer can only calculate with numbers (chapter 4). So the very first step is to turn text into numbers, without losing what the text means.
Tokens
A tokenizerthe program that cuts text into small pieces called tokens and gives each piece an ID number cuts text into small pieces. Each piece is a tokena small piece of text, often a whole word, part of a word or a punctuation mark; models read and write one token at a time. A token is often a whole common word, a piece of a rarer word, or a punctuation mark.
| Text | How a tokenizer might cut it |
|---|---|
| "The chip is hot." | "The" · " chip" · " is" · " hot" · "." |
| "semiconductor" | perhaps "semic" · "onductor" |
| A sentence in a language that was rare in the tokenizer's training text | often many more, smaller pieces |
Each token has an ID number in a fixed list called the vocabularythe full list of tokens a model knows, each with its own ID number. Modern vocabularies hold roughly 100,000 to 260,000 tokens. In English, one token is on average about three-quarters of a word.
Here is a fairness question that researchers have taken seriously. A tokenizer learns its pieces from text, and if most of that text was English, English words get efficient, whole-word tokens while other languages are chopped into many small pieces. A 2023 study by Aleksandar Petrov and colleagues at Oxford found that the same sentence could need several times more tokens in some languages than in English, and in extreme cases more than ten times as many. More tokens means slower answers and higher cost for the same meaning.
The good news is that this is improving quickly. Labs around the world have built larger, more multilingual vocabularies, and newer tokenizers cut the token count for many languages sharply. Models built from the start for many languages, with tokenizers trained on balanced text, push this further still. A good tokenizer is one of the quiet ways a model becomes fair to the whole world.
Embeddings
A token ID is only a label, like a locker number. So the model's first act is to swap each ID for a list of numbers called an embeddinga list of a few thousand numbers that represents a token's meaning as a point in a high-dimensional space. In a large model, each embedding has a few thousand numbers: 4,096 in Meta's Llama 3 8B model, for example, and 8,192 in the 70B model.
Think of an embedding as an address on a map with thousands of directions instead of two. Words with similar meanings live near each other. "King" sits near "queen." "Chip" sits near "processor," and also near "potato." The model has to use the surrounding words to work out which "chip" you mean, and that is exactly the job of the next idea.
The transformer and attention
In 2017, a team of eight researchers at Google published a paper with a confident title: "Attention Is All You Need." It described a new design called the transformerthe model design behind almost all modern language models, built from stacked layers of attention and feed-forward networks. Almost every modern language model is built on it. Few papers in computing have changed so much so fast.
Attention in plain words
Attentionthe step in which each token looks at the earlier tokens and decides which ones matter for its meaning lets each token look at all the earlier tokens and decide which ones are important for it.
Look at these two sentences:
- "I put money in the bank."
- "We sat on the river bank."
The word "bank" is identical in both. To understand it, the model must look back. Attention lets "bank" give a high score to "money" in the first sentence and to "river" in the second, and then shift its own meaning to fit. Every token does this for every earlier token, all at the same time, and that parallel structure is exactly what GPUs are good at.
Layers
A transformer stacks many layersrepeated blocks of the model; each one refines every token's meaning a little more on top of each other. Each layer has two main parts:
- Attention: each token gathers information from the other tokens.
- A feed-forward networka large block of neurons that each token passes through on its own; it holds much of the model's stored knowledge: each token passes through a large block of neurons. This part holds much of what the model "knows."
tokens → embeddings → [ layer 1 ] → [ layer 2 ] → ... → [ layer 80 ] → probabilities for the next token
attention attention attention
feed-forward feed-forward feed-forwardA large model has roughly 30 to more than 120 layers (Llama 3 70B has 80). Each layer sharpens the model's picture of the text a little. The last layer produces a probability for every token in the vocabulary. After "The capital of France is", for example, it might say " Paris" 92%, " Lyon" 3%, " the" 1%, and tiny amounts for everything else.
What "120 billion parameters" means in bytes
Each parameter is one number, and a computer stores each number in a fixed number of bits (chapter 4). Fewer bits use less memory, at the cost of a little precision. This one trade-off shapes nearly every hardware decision in AI.
| Number format | Bytes for each parameter | Size of a 120-billion-parameter model |
|---|---|---|
| FP32 (32-bit floating pointa way of storing decimal numbers with a fixed number of bits, trading range for precision) | 4 | 480 GB |
| BF16 or FP16 (16-bit) | 2 | 240 GB |
| FP8 (8-bit) | 1 | 120 GB |
| 4-bit (for example MXFP4 or NVFP4) | about 0.5 to 0.55 | about 60 to 66 GB |
A real example makes this concrete. OpenAI's open-weight model gpt-oss-120b has about 117 billion parameters. Most of its weights are stored in a 4-bit format, and OpenAI designed it to fit on a single 80 GB data-centre GPU. Memory size, not arithmetic speed, is often the first thing that decides which hardware can run a model.
Mixture of experts: total and active parameters
Here is a clever idea that has taken over the best open models. A normal, dense modela model that uses every one of its parameters for every token uses every parameter for every token. A mixture-of-expertsMoE: a model whose feed-forward parts are split into many smaller "experts", only a few of which are used for each token model splits its feed-forward parts into many smaller "experts." A small routerthe part of a mixture-of-experts model that picks which few experts each token should visit picks just a few experts for each token.
Picture a large hospital with 200 specialist doctors. Each patient sees only two or three of them. The hospital as a whole holds a vast amount of knowledge, but each visit uses only a small slice of it, so each visit is quick.
Example: DeepSeek V4 Flash (April 2026)
| Property | Value |
|---|---|
| Total parameters | about 284 billion |
| Active parameters for each token | about 13 billion |
| Memory at about 4 bits per weight | about 156 GB (every expert must sit in memory) |
| Work for each token | similar to a dense model of about 13 billion parameters |
| Licence | MIT (open weights) |
gpt-oss-120b works the same way: about 117 billion parameters in total, but only about 5.1 billion active for each token.
This is why MoE matters so much for hardware. The total parameters set how much memory you need. The active parameters set how fast it can answer. An MoE model needs a lot of memory, but each token is cheap to compute. We will put numbers on that in chapter 15.
Training data
A model learns everything it knows from examples. A modern model trains on roughly 10 to 30 trillion tokens or more; Meta reported over 15 trillion for Llama 3. The usual sources are:
- Public web pages, often starting from Common Crawla non-profit project that has collected a large public copy of the web since 2008.
- Books, scientific papers and encyclopedias.
- Computer code from public repositories.
- Licensed data from publishers and other partners.
- Synthetic datatext written by other models and then carefully filtered for quality.
Labs spend a remarkable amount of care on cleaning. They remove duplicates, spam, low-quality pages and harmful content, and they balance languages and subjects. It is unglamorous work, and it matters enormously: the quality of the data has as much effect on the model as its size.
Pre-training: predict the next token
The first and by far the largest stage of training is pre-trainingthe first, largest stage of training, in which a model learns to predict the next token across trillions of tokens of text. Its task sounds almost too simple: read some text, and guess the next token. Then do it again, trillions of times.
One training step in plain words
- Take a snippet of text, for example "The capital of France is".
- Predict. The model calculates its probabilities for the next token. At the very start, the weights are random, so the guess is nonsense: " banana" gets as much chance as " Paris".
- Measure the error. The right answer is " Paris". The lossa single number that measures how wrong a prediction was; training tries to make it small is a number that says how wrong the guess was.
- Find which way to turn each knob. A method called backpropagationan efficient way to work out, for every weight at once, whether nudging it up or down would reduce the loss works out, for every single weight, whether a tiny increase or decrease would make the loss smaller. The answer for all the weights together is the gradientthe list of "which way and how much" for every weight; it points uphill, so training steps the other way.
- Turn every knob a tiny amount in the direction that reduces the loss. This is gradient descentrepeatedly nudging the weights a small step in the direction that reduces the loss.
- Repeat with new text.
Imagine standing on a mountain in thick fog, trying to reach the lowest valley. You cannot see the valley. But you can feel which way the ground slopes under your feet. So you take a small step downhill, feel again, and take another. Gradient descent does exactly this, but on a landscape with billions of directions instead of two.
After trillions of tokens, the model becomes extremely good at predicting the next token. And here is the beautiful part: to predict text well, it has to learn grammar, facts, styles of argument and even some mathematics, because all of those help predict what comes next. Nobody programs those skills in. They emerge from the simple task.
How much compute does training need?
There is a lovely rule of thumb, from a 2020 study of how models scale by Jared Kaplan and colleagues:
Training compute ≈ 6 × (number of parameters) × (number of training tokens)
The result is counted in FLOPsfloating-point operations: individual multiply or add steps on decimal numbers. The 6 comes from about 2 operations per parameter per token on the way forward, and about 4 more on the way back during backpropagation.
Worked example: a 70-billion-parameter model on 15 trillion tokens
Let us try it on a real model: Meta's Llama 3 70B, trained on about 15 trillion tokens.
- Training compute: 6 × 70 billion × 15 trillion ≈ 6.3 × 10²⁴ operations.
- One NVIDIA H100 GPU can do about 10¹⁵ operations per second at 16-bit precision, at its peak.
- Real training rarely reaches the peak. At 40% of peak, it does about 4 × 10¹⁴ per second.
- So the job needs about 6.3 × 10²⁴ ÷ 4 × 10¹⁴ ≈ 4.4 million GPU-hours.
- With 10,000 GPUs working together, that is about 440 hours, or a little under three weeks.
How close is the estimate? Meta's model card for Llama 3 reports 6.4 million H100 GPU-hours for the 70B model. The rule of thumb gets us to the right order of magnitude, and the gap tells us something real: actual utilisation was lower than 40%, or the total included extra work.
Go deeper: the full sum, and a rough cost
| Step | Calculation | Result |
|---|---|---|
| Training compute | 6 × 70 × 10⁹ × 15 × 10¹² | 6.3 × 10²⁴ FLOPs |
| H100 peak, dense 16-bit | about 0.99 × 10¹⁵ FLOP/s | |
| Realistic speed at 40% of peak | about 4 × 10¹⁴ FLOP/s | |
| GPU time | 6.3 × 10²⁴ ÷ 4 × 10¹⁴ ÷ 3,600 | about 4.4 million GPU-hours |
| Reported by Meta | Llama 3 model card | 6.4 million GPU-hours |
| Rough rental cost at USD 2–3 per GPU-hour (estimate) | 4.4–6.4 million × 2–3 | about USD 9–19 million |
That covers only the final run. Labs also run many smaller experiments first. The largest frontier models of 2025–2026 are believed to use ten to a hundred times more compute than this example (an estimate; most labs do not publish it). For an MoE model, use the active parameters in the rule.
Why training needs so much memory
Training needs far more memory than simply running a model. For every parameter, the GPUs must keep the weight itself, its gradient, and extra numbers that the optimizerthe algorithm that decides exactly how big each weight's step should be; the popular Adam optimizer keeps two running averages per weight uses to decide each step. With the standard mixed-precision method, that comes to about 16 bytes for every parameter.
A 70-billion-parameter model therefore needs about 1.1 terabytes of memory just for those numbers, before counting any of the text being processed. No single GPU has that much. So engineers split the model and its training state across many GPUs, and the GPUs must talk to each other constantly.

Training clusters
A training clustera large group of GPUs or other accelerators joined by a fast network so that they can train one model together is a very large group of accelerators joined by a fast network (chapter 13).

| Cluster size | Typical use |
|---|---|
| 8 to 64 GPUs | Fine-tuning a model on an organisation's own data |
| 1,000 to 10,000 GPUs | Training a mid-size model |
| 20,000 to 100,000 or more | Training a frontier model |
A frontier training run lasts weeks or months, and in a machine that large, something is always breaking. A GPU fails, a cable fails, a power supply fails. With a hundred thousand GPUs, a failure somewhere can come every few hours. The software therefore saves its progress often, in a checkpointa saved snapshot of all the weights and training state, so training can restart from there after a failure, and picks up again after a fault.
Every GPU must also share its results with the others many times a second. A slow network leaves the most expensive chips in the building waiting. Keeping a hundred thousand GPUs busy together is one of the most impressive feats of systems engineering anywhere.
Post-training: from text predictor to assistant
After pre-training, the model can continue any text you give it. But it is not yet a helpful assistant. Ask it a question and it might write three more questions, because that is what often follows a question on the web. Post-trainingthe later stages of training that teach a pre-trained model to follow instructions, be helpful and be safe teaches it how to behave.
| Stage | What it does | In plain words |
|---|---|---|
| Supervised fine-tuningSFT: training on examples of good questions and answers written or checked by people | Train on examples of good questions and answers | Show the model what a good assistant looks like |
| RLHFreinforcement learning from human feedback: people compare answers, a second model learns their preferences, and the main model learns to score well | People compare two answers and pick the better one; a second model learns those preferences; the main model learns to score well | Teach the model what people find helpful |
| Reinforcement learning for reasoning | The model tries many solutions to problems with checkable answers, such as maths or code tests, and is rewarded for correct ones | Teach the model to work step by step and check itself |
| Safety training | Train the model to decline harmful requests and to be honest about what it does not know | Teach the model its limits |
Reasoning modelsmodels trained to write out a long chain of working before their final answer, such as OpenAI's o1 (2024) and DeepSeek R1 (2025), lean heavily on reinforcement learning. They write a long passage of working before the final answer. That makes them much better at hard problems, and it also means they use many more tokens, and therefore more computing, for each answer.
Fine-tuningextra training of an existing model on a small, focused dataset, for example legal or medical documents is a small version of post-training that anyone with an open model can do. An organisation can fine-tune a model on its own documents, for example legal or medical texts. With efficient methods that adjust only a small fraction of the weights, this can run on a single workstation with one or two GPUs, a tiny fraction of the cost of pre-training.
Open-weight models and closed models
Not every model is shared in the same way.
| Property | Closed model | Open-weight model |
|---|---|---|
| Examples (2026) | Gemini, Claude, GPT | DeepSeek, Qwen, GLM, Kimi, Mistral, gpt-oss, Gemma, Llama |
| How you use it | Through the lab's online service (an APIapplication programming interface: a defined way for one program to ask another for a service over the network) | Download the weights and run them on your own hardware |
| Where your data goes | To the lab's servers | Stays on your hardware |
| How you pay | For each token | For hardware and electricity |
| Quality | The best closed models generally lead | Close behind, and catching up quickly |
| Licence | The service's terms | MIT, Apache 2.0 or a custom licence; read each one |
"Open weight" is not always the same as "open source." Many labs publish the weights but not the training data or code. Even so, open weights are a wonderful gift to the field: researchers can study how models work inside, and anyone can run a capable model privately.
The labs themselves are spread across the world. OpenAI, Anthropic, Google DeepMind, Meta, xAI and NVIDIA build models in the USA and UK; Mistral in France; DeepSeek, Alibaba's Qwen team, Moonshot AI and Zhipu in China, among many others. Chapter 16 maps them alongside the rest of the industry.
Why this is hard
- Scale. A frontier model needs tens of thousands of GPUs for months and can cost hundreds of millions of US dollars.
- Data. Clean, high-quality, properly licensed data is limited. Labs compete for licensed data and generate synthetic data.
- Failures. In a large cluster, hardware fails often, and one subtle error can spoil weeks of work.
- Uncertain results. A lab cannot be sure how good a model will be until training ends.
- Talent. Only a small number of people in the world have run training at the frontier.
- Memory. Training and serving both need huge amounts of very fast memory, which ties AI directly to the memory market (chapter 10).
A short history
- 1958: Frank Rosenblatt builds the perceptron, an early learning machine with one layer of neurons.
- 1969 to the 1980s: Researchers show the limits of single-layer networks. Interest and funding fall, a period later called an "AI winter."
- 1986: David Rumelhart, Geoffrey Hinton and Ronald Williams popularise backpropagation for networks with many layers.
- 2012: AlexNet, trained on two NVIDIA gaming GPUs, wins a major image-recognition contest by a wide margin. Deep learning on GPUs takes off.
- 2017: Google researchers publish the transformer.
- 2018 to 2020: OpenAI releases GPT, GPT-2 and GPT-3. GPT-3 has 175 billion parameters.
- November 2022: OpenAI releases ChatGPT. An analyst estimate based on web traffic put it at 100 million monthly users about two months later.
- 2023: Meta releases Llama, and open-weight models take off.
- 2024: OpenAI's o1 shows that reinforcement learning can teach a model to reason step by step.
- January 2025: DeepSeek releases R1, an open-weight reasoning model that rivals the best closed models of the time at a much lower reported cost.
- 2025 to 2026: Very large mixture-of-experts open models multiply, from DeepSeek, Qwen, GLM, Kimi, Mistral and others, while the best closed models continue to push the frontier.
Open questions
- Why does next-token prediction work so well? A task this simple produces grammar, facts and reasoning. We can describe it, but a full explanation of why remains one of the most interesting problems in science.
- How much better can data get? If data quality matters as much as size, how far can careful curation and synthetic data carry models when public text runs short?
- How small can a great model be? Mixture-of-experts and better training keep shrinking the active size of capable models. Where is the floor?
- Can tokenizers be fair to every language? Vocabularies are improving fast. Could future models drop fixed tokens altogether and read raw bytes or characters?
- How do people learn so much from so little? A person hears a tiny fraction of the text a model reads. What would it take for machines to learn as efficiently? (The brain's own answer is a lovely place to start.)
What to remember
- A language model is one large function. Its knowledge lives in billions of weights, which are just numbers in a file.
- Text becomes tokens, tokens become embeddings, and the transformer uses attention so that every token can draw on the others.
- Pre-training teaches next-token prediction through gradient descent over trillions of tokens. Training compute ≈ 6 × parameters × tokens.
- In a mixture-of-experts model, total parameters set the memory; active parameters set the speed.
- Post-training, including reinforcement learning, turns a text predictor into a helpful assistant that can reason.
Sources
- Vaswani, A. et al. (2017). "Attention Is All You Need." NeurIPS 2017. https://arxiv.org/abs/1706.03762
- Kaplan, J. et al. (2020). "Scaling laws for neural language models." arXiv:2001.08361 (training compute ≈ 6ND). https://arxiv.org/abs/2001.08361
- Meta (2024). Llama 3 model card: 8B and 70B; over 15 trillion training tokens; 70B used 6.4M H100-80GB GPU-hours (7.7M for both). https://github.com/meta-llama/llama3/blob/main/MODEL_CARD.md
- Meta (2024). "The Llama 3 Herd of Models," arXiv:2407.21783 (layer counts, model dimensions, vocabulary of 128K tokens). https://arxiv.org/abs/2407.21783
- OpenAI (2025). gpt-oss-120b model card: 117B total, 5.1B active parameters; MXFP4 weights; fits a single 80 GB GPU. https://huggingface.co/openai/gpt-oss-120b
- DeepSeek-AI (2026). DeepSeek-V4-Flash model card: 284B total, 13B activated parameters; 1M-token context; FP4 + FP8 mixed weights; MIT licence. https://huggingface.co/deepseek-ai/DeepSeek-V4-Flash
- NVIDIA H100 product page: about 989 TFLOPS dense BF16. https://www.nvidia.com/en-us/data-center/h100/
- Petrov, A., La Malfa, E., Torr, P. & Bibi, A. (2023). "Language model tokenizers introduce unfairness between languages." NeurIPS 2023. arXiv:2305.15425. https://arxiv.org/abs/2305.15425
- OpenAI Help Center, "What are tokens and how to count them?" (about ¾ of a word per English token). https://help.openai.com/en/articles/4936856-what-are-tokens-and-how-to-count-them
- Rajbhandari, S. et al. (2019). "ZeRO: memory optimizations toward training trillion parameter models." arXiv:1910.02054 (16 bytes per parameter for mixed-precision Adam). https://arxiv.org/abs/1910.02054
- Rosenblatt, F. (1958). "The perceptron: a probabilistic model for information storage and organization in the brain." Psychological Review 65:386. https://doi.org/10.1037/h0042519
- Rumelhart, D. E., Hinton, G. E. & Williams, R. J. (1986). "Learning representations by back-propagating errors." Nature 323:533. https://doi.org/10.1038/323533a0
- Krizhevsky, A., Sutskever, I. & Hinton, G. E. (2012). "ImageNet classification with deep convolutional neural networks." NeurIPS 2012. https://papers.nips.cc/paper_files/paper/2012/hash/c399862d3b9d6b76c8436e924a68c45b-Abstract.html
- Brown, T. et al. (2020). "Language models are few-shot learners" (GPT-3, 175B parameters). arXiv:2005.14165. https://arxiv.org/abs/2005.14165
- Ouyang, L. et al. (2022). "Training language models to follow instructions with human feedback." arXiv:2203.02155. https://arxiv.org/abs/2203.02155
- DeepSeek-AI (2025). "DeepSeek-R1: incentivizing reasoning capability in LLMs via reinforcement learning." arXiv:2501.12948. https://arxiv.org/abs/2501.12948
- Reuters (1 February 2023), "ChatGPT sets record for fastest-growing user base – analyst note" (UBS estimate from Similarweb data). https://www.reuters.com/technology/chatgpt-sets-record-fastest-growing-user-base-analyst-note-2023-02-01/
- Oak Ridge Leadership Computing Facility, Titan (18,688 GPUs). https://www.olcf.ornl.gov/olcf-resources/compute-systems/titan/
Estimates in this chapter: the 40% utilisation and the rental cost in the worked example; the compute of frontier models (labs rarely publish it); cluster sizes for each use; failure rates in very large clusters; and the 4-bit memory figure for DeepSeek V4 Flash (284 billion × about 0.55 bytes).
Previous: 13. Servers and data centres · Next: 15. The journey of one answer