
How likely this exact text is, all T tokens together
Multiply: the 1st token, times the 2nd given the 1st, times the 3rd given the first two, and so on to the last
How likely token t is, given all the tokens before it. This is the only thing an LLM learns
Example: we ran GPT-2 (OpenAI, 2019, 124 million parameters) on "The pump stopped" and read its probability for each token, given the ones before it:
p("The pump stopped")
= p("The") × p("␣pump" | "The") × p("␣stopped" | "The pump")
= 0.038 × 8.5 × 10-6 × 0.0019 = 5.9 × 10-10
Language model: a model that gives the probability of the next token,
Large language model (LLM): a language model with billions of parameters, trained on trillions of tokens.
Predict the last factor of the chain rule, for every possible next token:
The pump stopped because the␣water␣was␣too␣hot.
Each red token is one trip round the loop: GPT-2 predicted it, it was appended, and the next prediction started from the longer text. A model that uses its own outputs as its next inputs is autoregressive.

Lecture 8's AR(10), reactor pressure, 2 hours ahead on one test run
| Lecture 8: AR(10) | An LLM | |
|---|---|---|
| Predicts | the next pressure | the next token |
| From | the last 10 values | all the text so far |
| Output | one number | a probability for every token |
| Model | 11 coefficients | billions of parameters |
| Long outputs | feed each forecast back in | append each token: the same |
Same weakness: both feed their own outputs back in, so an early mistake becomes an input for every later step. Lecture 8: after 2 hours, the forecast was worse than the plain mean. An LLM: one wrong token steers the rest of the answer
Token: a piece of text the model reads and writes: a character, a word, or part of a word.
Vocabulary: the list of every token the model knows, each with a number, its token id.
Tokenizer: the program that cuts text into tokens and looks up their ids.
| Text | The pump stopped. | |||
| ↓ the tokenizer cuts the text into tokens | ||||
| Tokens | The | ␣pump | ␣stopped | . |
| ↓ and looks up each token in the vocabulary | ||||
| Token ids | 464 | 8901 | 5025 | 13 |
One token per letter, digit, space or symbol. A tiny vocabulary (our tiny GPT: 129), but long sequences
One token per word. The vocabulary needs every word ever written, and a new one has no token: a pump tag like P-101A, a steel grade like AISI 4140
Pieces of words. Common words stay whole ("␣pump"), rarer ones split ("␣overhe" + "ated"), so any new word can be built. GPT-2: 50,257 tokens
Byte-pair encoding (BPE): how a subword vocabulary is built. Find the pair of neighboring tokens that appears most often, merge it into one new token, repeat.
Frequent pieces become one token. Shorter sequences: more text fits in the context window, fewer steps to write
A new word can always be built from smaller pieces, down to single characters
The merges come from the training text, so its frequent words become single tokens
Example from Wikipedia, Byte-pair encoding. The algorithm is Gage's (1994), adapted to building subword vocabularies by Sennrich et al. (2016); GPT-2 starts from bytes and stops after 50,000 merges.


GPT-4o's tokenizer (o200k_base, in tiktoken).
Context window: the most tokens a model can take in at once: your prompt, any documents, and everything it has written so far. Text beyond it is not seen at all.
Too long to fit: cut it, summarize it, or search for the part that matters.
GPT-3: "a context window of nctx = 2048 tokens". Llama 3: "a context window of up to 128K tokens". Our notes counted with GPT-4o's tokenizer (tiktoken, o200k_base).

In Lecture 12 the tokens were cycles of a sensor window; the machinery is the same.

The word "too" asks every earlier word: how useful are you for guessing what comes next?
It takes a weighted average of what those words carry. Here, mostly "water"
Later words are hidden: the causal mask. In training the next word is the answer, so it must stay hidden
In symbols, as in Lecture 12: softmax(QKᵀ/√dk + M) V. QKᵀ/√dk are the scores; the mask M is −∞ for later words, which sets their weight to 0. The weights in the picture are a sketch.

A straight-line fit (Lecture 9) has 2 dials; our tiny GPT has 842,881; GPT-3 has 175 billion. The nudge is a gradient step, with the gradient from backpropagation (Lecture 11).
How much probability the model gave the token that really came next. θ: the dials
The minus makes it a loss: near 0 when right and sure, large when surprised (the plot). 1/T Σ: the average over T positions. This is the cross-entropy of Lecture 10


The point: one sentence gives 9 training examples, all done at once, in one pass: self-supervised learning. Each guess sees only the tokens before it (the causal mask); otherwise the answer would be in plain sight

At the start, the dials are random: each of the 129 characters gets about the same chance, 1/129. A blind guess has a loss of −ln(1/129) = 4.86: the dotted line
To read a loss, undo the ln. The loss is the average of −ln p, so e−loss is the typical p. At the end, e−1.51 = 0.22: the true next character typically gets 22%

Give it the first 60% of one term from each lecture; it picks the most likely next character until the term ends.

Sizes from each model's paper or card: GPT-1, GPT-2 · GPT-3 · Gopher · Chinchilla · PaLM · Llama 2 · Llama 3.1 · DeepSeek-V3 · Kimi K2 · DeepSeek-V4 · Kimi K3. No size given: GPT-4 · GPT-6 Astra · Claude 3 · Claude Opus 5.5.
Mostly filtered web text, plus books, code and papers. Llama 3: "about 15T multilingual tokens"
The notes of Lectures 1 to 16: 668,651 characters, each seen about 27 times in 2,000 steps
Our notes: about 7 hours at 250 words a minute. GPT-3's training text: about 1,300 years, non-stop
Our tiny GPT needed about 8 × 10¹³ operations: 2 minutes on a laptop GPU (about 700 billion a second), but 23 hours at a billion a second. GPT-3 needed 3.14 × 10²³: about 10 million years at a billion a second
Still how it is done: each round of Llama 3's post-training was SFT, then DPO (Llama Team, 2024). InstructGPT "hired a team of about 40 contractors" to write and rank answers (Ouyang et al., 2022). Examples: GPT-2, a pretrained model, and Qwen2.5-0.5B-Instruct, a chat model, both run by us.
Temperature: a knob for how adventurous the model is when it picks the next token.
Low: it almost always takes the most likely token.
High: less likely tokens get a real chance.
The model's raw score for each token, before the softmax turns them into probabilities
Divide every logit by τ, then softmax. τ = 1: the model's own probabilities
Two logits, 2 and 1. τ = 1: 73% and 27%. τ = 0.5 doubles the gap: 88% and 12%. τ = 2 halves it: 62% and 38%.

We ran GPT-2 on "…the water was too": "␣hot" gets 88% at τ = 0.5, 42% at τ = 1, 4% at τ = 2.
"Using a higher value for T produces a softer probability distribution over classes" (Hinton, Vinyals and Dean, 2015).

What you see: GPT-2's next token after "…the water was too" as a wheel, one slice per token. Picking a token is a spin. Change τ, then spin
τ changes the wheel, the spin stays fair: at τ = 0.5 "␣hot" takes 88% of it; at τ = 2, only 4%
Why "temperature": the softmax is Boltzmann's distribution from thermodynamics.
A logit
"In statistical mechanics, the softmax function is known as the Boltzmann distribution" (Wikipedia, after LeCun et al., 2006).

What you see: GPT-2's ten most likely next tokens at each step of the loop. Red: the one appended. Step through, then move τ
τ = 1: GPT-2's own probabilities. At step 1, "␣water" gets 3.7%: many words could follow
Slide τ to 0.1: "␣water" jumps to 89%. Low temperature: nearly the same text every time
Slide τ to 2: every bar flattens. At step 4, even "␣hot" falls to 4%: almost anything can come next
A Gaussian process in the data and a different statistical models. ### A file section and layers A **fitted of stead of a column store and a strain of the same data is the same offf the same way th …
Safe and repetitive: "the same … the same …", and a Markdown heading copied from our notes
A Gaussian process and the default does not exact the band file coefficients the wide, vector plant. The discipline for a strong by an Lecture 9. The log quantition and can we course at have you been …
Varied words in our style, with no meaning
A Gaussian process cructor arNive," and a brieful mini-bassed flrecash uncaged defaularing most-is carryied outue: chan `y[desy''](h✓dds#p.01├x, lipproduce. - [Slagáni lipyndbof/Jagimaus.ipynb) answer …
Broken words and rare symbols (✓, ├): the tail of the distribution
All three start from the same prompt, "A Gaussian process", and the same model. Only τ changed.
Hallucination: fluent, confident text that is false: an invented number, unit, citation or fact.
What is the boiling point of water at sea level?The boiling point of water at sea level is 100 degrees Fahrenheit.

One token at a time, like Lecture 8's recursive forecast
Billions of parameters, trillions of tokens
␣about 1,000 degrees Fahrenheit
GPT-2 on water's boiling point (true: 212 °F). Check every number that matters
This lecture is built on Grant Sanderson's lessons on large language models, the clearest visual explanation of them we know. The chatbot as a script it completes, training as tuning dials, vectors that talk to each other and the temperature knob all come from there. Watch them before anything else on this slide.
Large Language Models explained briefly (8 min) · Transformers, the tech behind LLMs · Attention in transformers · How might LLMs store facts
Transformer Explainer: GPT-2 in your browser
LLM Visualization: every computation, in 3D
Tiktokenizer: see your text as tokens
Picture a movie script with the AI's reply torn off, and a machine that predicts the next word. Run it again and again and the reply writes itself. That is all a chatbot is. The model was trained on chats written with these tags, so it expects them. How this was made: Hugging Face transformers, the model taking its most likely token at every step; the numbers come from figures/make_figures.py (group chat).
GPU: graphics processing unit, the graphics card. 116 s on an Apple-silicon laptop. On Colab, choose a GPU runtime.
The chain rule is exact: no assumption about which earlier tokens matter. ␣ marks a space: GPT-2's tokens carry their leading space. The product is tiny because so many texts are possible; "pump" right after "The" is the surprise, 8 in a million.
How this was made: we ran GPT-2 (124 million parameters, Hugging Face transformers) on "The pump stopped because the" and, five times, took its single most likely next token and appended it. The probabilities on the cards are GPT-2's. The code: figures/make_figures.py, group gpt2. Click once per token: each click is one trip round the loop. The Sampling section steps through the same loop with GPT-2's real probabilities, and a temperature slider.
The analogy is between Lecture 8's autoregressive forecaster and an LLM writing text: same word, same idea. It is not a claim about RNNs, nor that LLMs lose accuracy over the years. Bengio et al. (2015) described the same effect for RNN text generators: trained on true previous tokens, run on their own, "errors that can accumulate quickly along the generated sequence".
Step 2 is a tie: "aa" + "a" also appears twice. Wikipedia's example takes "a" + "b". A real tokenizer learns its merges once, from a large text, and then applies them in the same order to any new text: the next slide.
The first merges our notes learn: " t", " a", "he", "in", "re". More merges, longer tokens, fewer of them.
Attention: the vectors talk to each other. MLP: each vector, alone, through the same small network. Repeat. Only the last vector predicts the next token. The next two slides open the two boxes: the attention equation and the final softmax.
How this was made: we trained the tiny GPT for 2,000 steps and saved its guesses every 250 steps; the bars and the chart are those checkpoints. The dials are a drawing.
The reactor of Lecture 15 had 2 knobs and hours per experiment: Bayesian optimization. Our tiny GPT has 842,881 knobs and 58 ms per step: gradient descent. The map is Lecture 15's, with the tiny GPT added.
"Typical" is the geometric mean of the probabilities given to the true characters. The blue curve, the training batches, ends lower (1.22) than the red, held-out text (1.51): it predicts text it has seen better than new text, the overfitting of Lecture 9.
Random symbols, then letters and spaces, then short words, then the course's vocabulary, then LaTeX copied from our notes. It learns the style long before any meaning.
The GPT-4 technical report "contains no further details about the architecture (including model size)". Anthropic's model cards give no parameter counts. The mixture-of-experts models (DeepSeek, Kimi) only use a fraction of their parameters for each token: the hollow dots.
GPT-3's reading time uses our notes' 0.58 words per GPT-2 token (GPT-3 uses the same vocabulary) for its 300 billion tokens. GPT-3's compute is Table D.1 of Brown et al. (2020); ours is about 6 operations per parameter per token, 6 × 842,881 × 16.4 million. Same objective and same kind of model: Llama 3 has about 500,000 times the parameters of ours.
For chemical engineers this is exactly the Boltzmann distribution, with the logit as minus an energy in units of k_B T.
The first two rows go together: an agent that installs what it writes can install a package an attacker registered under a hallucinated name (Spracklen et al. describe this attack).