AI Adoption

Lecture 2. How LLMs work

Question 1

How does a large language model work, and how is it trained?

Today’s lecture

  1. Introduction
  2. Pretraining data
  3. Tokenization
  4. The prediction task
  5. The Transformer
  6. The base model
  7. Supervised fine-tuning
  8. Consequences of training
  9. Reinforcement learning
2

Pretraining data

The Common Crawl archive

The crawl of September 2026, CC-MAIN-2026-39, contains 2.17 billion pages, 361.4 TiB of uncompressed content. It is distributed in three file formats:

FormatContent of the filesCompressed size
WARCraw HTTP responses, including the HTML of each page82.79 TiB
WATmetadata: HTTP headers and links14.16 TiB
WETplain text extracted from the HTML5.89 TiB

The pretraining data of Llama 3 (2024)

Llama 3 405B was trained on \(15.6\cdot10^{12}\) tokens of text with knowledge up to the end of 2023.

CategoryShareTokens (computed)
General knowledge50%\(\approx7.8\cdot10^{12}\)
Mathematics and reasoning25%\(\approx3.9\cdot10^{12}\)
Code17%\(\approx2.7\cdot10^{12}\)
Multilingual8%\(\approx1.2\cdot10^{12}\)

The pretraining data of Olmo 3 (2025)

Olmo 3 32B was pretrained on \(5.5\cdot10^{12}\) tokens.

SourceShareTokens
Web pages (Common Crawl)76.1%\(4.51\cdot10^{12}\)
Academic PDFs, converted to text13.6%\(0.81\cdot10^{12}\)
Code (GitHub, Stack-Edu)6.9%\(0.41\cdot10^{12}\)
Mathematics web pages (FineMath)2.6%\(0.15\cdot10^{12}\)
arXiv papers with LaTeX0.9%\(0.05\cdot10^{12}\)
Wikipedia and Wikibooks0.04%\(0.003\cdot10^{12}\)

The pretraining data of MAI-Thinking-1 (2026)

Microsoft, 35B active of 1T parameters: \(30\cdot10^{12}\) tokens.

Source familyShareUnique tokensTraining tokensEpochs
Code (GitHub)54.6%\(7.4\cdot10^{12}\)\(16.4\cdot10^{12}\)2.22
STEM15.8%\(2.2\cdot10^{12}\)\(4.7\cdot10^{12}\)2.17
Web text14.9%\(8.1\cdot10^{12}\)\(4.5\cdot10^{12}\)0.55
Mathematics5.4%\(0.3\cdot10^{12}\)\(1.6\cdot10^{12}\)5.28
PDFs4.7%\(2.7\cdot10^{12}\)\(1.4\cdot10^{12}\)0.53
Books and journals3.1%\(0.6\cdot10^{12}\)\(0.9\cdot10^{12}\)1.65
Multilingual (other)1.6%\(8.1\cdot10^{12}\)\(0.5\cdot10^{12}\)0.06

Building a pretraining dataset is highly nontrivial!

Question 2

Any problems with the crawled data?

Olmo 3: of 252.6 billion web documents, 9.7 billion (about 4%) remain after filtering.

StageWhat it does
URL filteringdrops pages from blocklisted domains: adult content, spam, malware
Text extractionturns raw HTML into plain text
Language identificationclassifies language on pages
Model-based quality filtersa classifier trained on good text
Deduplicationremoves copies
PII removalmasks or removes personal data
Decontaminationremoves the text of benchmark test sets
Mixingdecides how many tokens to take from each source and topic
3

Tokenization

Vocabulary size and sequence length

Setting. A text is a byte string \(s\in\Sigma^{*}\), \(\Sigma=\{0,\dots,255\}\).
A vocabulary is a finite set \(\mathcal V\subset\Sigma^{+}\) of tokens.

Definition. A tokenizer is a function \(\tau:\Sigma^{*}\to\mathcal V^{*}\) with \(\tau(s)=(x_1,\dots,x_T)\) and \(x_1x_2\cdots x_T=s\).

Remark. Tokens make the matrices of the Transformer smaller.

Byte-pair encoding: training

Algorithm 1 (BPE training; Gage 1994, Sennrich et al. 2016)

Input: a corpus, and a vocabulary size \(k\ge 256\).

Output: an ordered list of \(k-256\) merges.

  1. \(\mathcal V\leftarrow\{0,\dots,255\}\); \(\mathit{merges}\leftarrow(\,)\)
  2. while \(|\mathcal V|<k\) do
  3. count the occurrences of each adjacent pair \((a,b)\in\mathcal V\times\mathcal V\) in the corpus
  4. \((a,b)\leftarrow\) the most frequent pair
  5. replace each occurrence of \(a\,b\) by a new symbol \(ab\); add \(ab\) to \(\mathcal V\)
  6. append \((a,b)\) to \(\mathit{merges}\)
  7. return \(\mathit{merges}\)

Tokenizers of real models

ModelTokenizerVocabulary size \(|\mathcal V|\)
GPT-2 (2019)byte-level BPE50,257
Llama 2 (2023)BPE (SentencePiece)32,000
GPT-4 (2023)byte-level BPE, cl100k_base≈100,000
Llama 3 (2024)byte-level BPE128,256
GPT-4o (2024)byte-level BPE, o200k_base≈200,000
Qwen3.5 (2026)byte-level BPE≈248,000
DeepSeek-V4 (2026)byte-level BPE≈129,000
4

The prediction task

Language models

Setting. \(\mathcal V\) is a vocabulary; its elements are called tokens.
A text is a sequence \(x=(x_1,\dots,x_T)\in\mathcal V^T\).
We write \(\Delta(\mathcal V)\) for the set of probability distributions on \(\mathcal V\).

Definition. A language model with parameters \(\theta\in\mathbb R^N\) is a map that assigns to every prefix a probability distribution of the next token:

\[ p_\theta:\ \mathcal V^{*}\to\Delta(\mathcal V),\qquad x_{<t}\ \mapsto\ p_\theta(\,\cdot\mid x_{<t}). \]

Remark. By the chain rule, \(p_\theta\) defines a probability distribution on texts of each length \(T\):

\[ p_\theta(x_1,\dots,x_T)=\prod_{t=1}^{T}p_\theta(x_t\mid x_{<t}). \]

The cross-entropy loss

\(x=(x_1,\dots,x_M)\in\mathcal V^M\)
the training corpus of \(M\) tokens: all documents, concatenated
\(n\in\mathbb N\)
the context length; we assume that \(n\) divides \(M\) and set \(J=M/n\)
\(b^{(j)}\in\mathcal V^n\)
block \(j\) of the corpus, \(b^{(j)}=(x_{(j-1)n+1},\dots,x_{jn})\), for \(j=1,\dots,J\)

Definition. The cross-entropy loss \(\mathcal L:\mathbb R^N\to[0,\infty)\), in nats per token, is

\[ \mathcal L(\theta)=-\frac{1}{M}\sum_{j=1}^{J}\sum_{t=1}^{n}\ln p_\theta\big(b^{(j)}_t\mid b^{(j)}_{<t}\big). \]

Definition. The perplexity is \(e^{\mathcal L(\theta)}\), i.e. we can think that the model is as uncertain as a uniform choice among \(e^{\mathcal L}\) tokens (for example, \(\ln 10 \approx 2.3\) nats per token, means that perplexity is 10).

Question 3

A model assigns probability \(1/|\mathcal V|\) to every token, with \(|\mathcal V|\approx e^{12}\). What are its cross-entropy loss and its perplexity?

Answer. Every term of the loss equals \(-\ln(1/|\mathcal V|)\), so \(\mathcal L=\ln|\mathcal V|\approx 12\) nats per token.

The perplexity is \(e^{\mathcal L}=|\mathcal V|\approx e^{12}\).

What the network computes

prefix c The proof is left as an exercise to the network, weights θ ∈ ℝN L layers, each built from matrix products with weights, sums and simple nonlinear maps logits z softmax pθ(· | c) 6.0␣reader0.80 3.9␣student0.10 3.2␣audience0.05 2.7␣interested0.03 2.3␣listener0.02

Definition. \(\operatorname{softmax}:\mathbb R^{|\mathcal V|}\to\Delta(\mathcal V)\), \(\operatorname{softmax}(z)_v=e^{z_v}/\sum_{u\in\mathcal V}e^{z_u}\);.

Why a network is mostly matrices

Theorem (universal approximation; Cybenko 1989, Hornik 1991, Leshno et al. 1993).
Let \(\sigma:\mathbb R\to\mathbb R\) be continuous and not a polynomial.
For every compact \(K\subset\mathbb R^n\), continuous \(f:K\to\mathbb R^m\) and \(\varepsilon>0\) there are \(k\in\mathbb N\), \(W_1\in\mathbb R^{k\times n}\), \(b\in\mathbb R^k\), \(W_2\in\mathbb R^{m\times k}\) with

\[ \sup_{x\in K}\big\|f(x)-W_2\,\sigma(W_1x+b)\big\|<\varepsilon. \]

Examples of \(\sigma\): ReLU \(\max(0,t)\); sigmoid \(1/(1+e^{-t})\); SiLU \(t/(1+e^{-t})\) (in the MLP of Llama).

ParametersOperations
matrix \(W_1\in\mathbb R^{k\times n}\)\(kn\), all learned\(kn\) multiply-adds, the fastest operation of a GPU
\(\sigma\) on \(\mathbb R^k\)none: \(\sigma\) is fixed\(k\)

MLP

\[ x\in\mathbb R^d,\qquad W_1=\begin{pmatrix}u_1^{\top}\\ \vdots\\ u_{d_{\mathrm{ff}}}^{\top}\end{pmatrix}\in\mathbb R^{d_{\mathrm{ff}}\times d},\qquad W_2=\begin{pmatrix}w_1&\cdots&w_{d_{\mathrm{ff}}}\end{pmatrix}\in\mathbb R^{d\times d_{\mathrm{ff}}}. \]
\[ \operatorname{MLP}(x)=W_2\,\sigma(W_1x)=\sum\nolimits_{k=1}^{d_{\mathrm{ff}}}\sigma(u_k^{\top}x)\,w_k. \]

Note: \(u_k\) is a key, a pattern, and \(w_k\) its value.

Example: \(x\) is the vector of ␣exercise in “The proof is left as an exercise to the”.

Key \(u_k\) matches\(\sigma(u_k^{\top}x)\)\(w_k\)
“proof” + “exercise”1.2a task left to the reader
“gym” + “exercise”?1.2a workout, training
5

The Transformer

A Transformer

probabilities of the next token Softmax Unembedding Final norm × L + MLP Norm + Masked multi-head self-attention Norm Token embedding The ␣proof ␣is ␣left ␣as ␣an ␣exercise ␣to ␣the context window: up to n tokens

1. Input

The text, cut into tokens, fills the context window: at most \(n\) tokens (Llama 3: \(n=128\)K).

2. Token embedding

Token IDs are only labels. The embedding is a one vector in \(\mathbb R^d\) per token. Training moves the vectors so that related tokens, such as ␣proof and ␣proofs, end up close.

3. \(L\) blocks

All the logic is here: the same block, repeated \(L\) times.
Model\(L\)\(d\)
Llama 3 8B (2024)324,096
Llama 3 405B (2024)12616,384
DeepSeek-V4-Pro (2026)617,168
Kimi K3 (2026)937,168

4. Norm

Rescales each vector, so that its numbers neither grow nor shrink from block to block.

5. Masked multi-head self-attention

Each position reads the earlier positions and takes a weighted average of their vectors. Attention of the position ␣exercise in “The proof is left as an exercise to the”:
The␣proof␣is␣left␣as␣an␣exercise

6. Addition (skip connection)

Each sublayer adds its result to the vector.

7. MLP

At each position separately:
\[ \operatorname{MLP}(x)=W_2\,\sigma(W_1x),\qquad \mathbb R^d\to\mathbb R^{d_{\mathrm{ff}}}\to\mathbb R^d. \]
Llama 3 8B: \(4{,}096\to14{,}336\to4{,}096\). Most of the parameters, and most stored knowledge, are here.

8. Unembedding

A linear layer turns the last vector of each position into one logit per token.

9. Softmax

Logits become probabilities of the next token: ␣reader 0.80, ␣student 0.10, …

Demonstration

A GPT in an interactive visualisation

6

The base model

Generating text: autoregressive sampling

The whole algorithm in one line: draw the next token from the model’s probabilities, write it at the end of the window, and drop the leftmost token if the window is full. Repeat until the model draws the end-of-text token or the length limit is reached.

for _ in range(max_new_tokens):
    window = idx[:, -block_size:]                       # the last block_size tokens
    logits, _ = model(window)                           # one pass of the network
    probs = F.softmax(logits[:, -1, :], dim=-1)         # probabilities of the next token
    idx_next = torch.multinomial(probs, num_samples=1)  # draw one token
    idx = torch.cat((idx, idx_next), dim=1)             # write it at the end

Demonstration

A base model on this laptop

  1. Type 1: the opening of a document, “Andrey Kolmogorov (1903–1987) was a Soviet mathematician who”, at temperature 1
  2. Watch the continuation appear one token at a time
  3. Are the dates and facts it adds correct?

What a base model computes

The base model is the network right after pretraining. It was trained only to continue documents, so it simulates documents: given the beginning of one, it writes a plausible rest.

  • It continues a prompt the way training documents that begin with this prompt continue.
  • Each run samples another continuation: another plausible document.
  • If it predicted every next token exactly as in its data, a sampled continuation would have exactly the probability of that continuation among the training documents (the chain rule of Section 4).

Remark. The objective does not mention questions: a question in the prompt is continued as documents that begin with it continue, by an answer, more questions, or comments.

Demonstration

One prompt, three documents

In the terminal: 2, the Kolmogorov prompt three times at temperature 1.

  1. Before running: will the three continuations agree?
  2. The three continuations side by side

Temperature

Before the draw, the scores of the tokens (the logits) are divided by the temperature and turned into probabilities again.

  • Low temperature: the most likely token takes almost everything; temperature 0 is greedy decoding.
  • Temperature 1: the model’s own probabilities.
  • High temperature: the probabilities become more even, and unlikely tokens are drawn more often.

Example. Tokens after “… exercise to the”.

␣reader␣student␣audience␣interested␣listener
score (logit)6.03.93.22.72.3
temperature 0.50.9800.0150.0040.0010.001
temperature 10.8030.0980.0490.0300.020
temperature 20.5140.1800.1270.0990.081

Truncated sampling: top-k, top-p, min-p

Sampling occasionally draws a very unlikely token, and one bad token can derail the rest of the text. Truncation keeps only the plausible tokens, rescales their probabilities so that they sum to 1, and draws among them.

RuleKeeps
Top-kthe k most likely tokens
Top-pthe most likely tokens, until their probabilities add up to at least p
Min-p every token at least min_p times as likely as the most likely token

Usually the temperature is applied first, then the truncation.

Question 4

Which tokens remain, and with which probabilities?

“The proof is by”; all other tokens have probability 0.

token␣induction␣contradiction␣construction␣computation␣inspection
probability0.450.270.180.060.04
  1. Top-k with k = 2.
  2. Top-p with p = 0.8.
  3. Min-p with min_p = 0.2.

Answer. 1. ␣induction and ␣contradiction; their total is 0.72, so 0.625 and 0.375 (the ratio 5 : 3 stays).

2. Running totals 0.45, 0.72, 0.90: two tokens give only 0.72, so the third is needed; 0.5, 0.3, 0.2 (divide by 0.9).

3. The threshold is 0.2 × 0.45 = 0.09: the same three tokens, 0.5, 0.3, 0.2.

Demonstration

Temperature, top-p and the token limit

In the terminal: 3, the Kolmogorov prompt five times.

  1. Temperature 0, twice: are the two runs the same?
  2. Temperature 2: what happens to the text?
  3. Temperature 2 with top-p 0.9
  4. Temperature 1 with a limit of 10 tokens

Demonstration

A memorised text

In the terminal: 4, at temperature 0: the opening of the Wikipedia article on Shakespeare, “William Shakespeare (c. 23 April 1564 – 23 April 1616) was an English playwright, poet and actor. He is widely regarded as”, then the opening of the MIT License, “Permission is hereby granted, free of charge, to any person obtaining a copy”.

Memorisation of training text

A passage of training text is extractable if, given the tokens that come before it in the training data, the model, always taking its most likely token, writes the passage out word for word (Carlini et al. 2023).

On GPT-Neo models (125M to 6B parameters, 825 GB of text), For the 6B model, 33% of the tested passages are extractable from 50 tokens of context and 65% from 450.

How much the weights can hold (Llama 3 8B). 8 billion parameters of 16 bits each, trained on over 15 trillion tokens:

16 bits × 8 billion / 15 trillion tokens ≈ 0.009 bits per training token.

Demonstration

After the cutoff

In the terminal: 5, the first line of a news report on an event of July 2024; the model’s data end in December 2023:

BERLIN, July 14, 2024 — The final of Euro 2024 at the Olympiastadion ended
  1. Temperature 0: the model’s most likely account
  2. Temperature 1 with top-p 0.9, twice: two more accounts

The knowledge cutoff

Definition. The knowledge cutoff of a model is the date of the latest text in its pretraining data.

ModelCutoffRelease
Llama 3 8BMarch 2023April 18, 2024
Llama 3 70BDecember 2023April 18, 2024
OLMo 2 7B (our demonstrations)December 2023November 2024
Gemma 4 31BJanuary 2025April 2, 2026
GPT-6 AstraApril 30, 2026September 3, 2026
Claude Opus 5.5June 2026September 22, 2026

Question 5

A base model only continues documents. How do we make it answer our questions?

Answer. Begin a document in which an assistant answers, and put our question at the end:

A conversation between a user and
an assistant who answers briefly.

User: What is the derivative of sin x?
Assistant: cos x.

User: Is 91 a prime number?
Assistant: No, 91 = 7 × 13.

User: {question}
Assistant:

Demonstration

The prompt with {question} = “What is the integral of 1/x?”.

  1. In the terminal: 6, no stop string. What does the model write after its reply?
  2. In the terminal: 7, the stop string “\nUser:”: the program cuts the text where the model begins the next “User:” line, shown in red

In-context learning

Example (GPT-3, 175B parameters, not trained further). The prompt contains solved pairs (sentence, translation); the score is BLEU, from 0 to 100, on the WMT’14 test set.

Examples in the promptEnglish → FrenchFrench → English
0 (instruction only)25.221.2
128.333.7
6432.639.2

The cost of training GPT-2

Training a base model of GPT-2’s quality (1.5B parameters, 2019) from scratch:

RunYearHardwareTimeCost
GPT-2, OpenAI201932 TPU v3 chips168 habout $43,000 (estimate)
llm.c20248 H100 GPUs24 h$672
nanochatJanuary 20268 H100 GPUs3 habout $73
nanochatMarch 20268 H100 GPUs1.65 habout $40

Break

10 minutes

7

Supervised fine-tuning

Demonstration

Tiktokenizer’s chat format for GPT-4o

  1. The default conversation: a system message and a user message
  2. The user message “Is 91 prime?” and an assistant message “No: 91 = 7 · 13.” (button Add message)
  3. The rendered string: <|im_start|>role<|im_sep|>text<|im_end|> for each message
  4. The IDs Tiktokenizer gives: <|im_start|> 200264, <|im_sep|> 200266, <|im_end|> 200265; the roles are ordinary tokens

The system prompt

The system prompt is the first message of a conversation, with role system, written by the developer of the application. The chat template puts it at the start of the token sequence, before the user’s messages and the replies.

Remark. Nothing in the network marks the system prompt as special: i.e., the instruction hierarchy, is learned from fine-tuning data with conflicting instructions.

The supervised fine-tuning objective

Supervised fine-tuning (SFT) continues training the base model with the same next-token loss as pretraining, on conversations instead of web documents.

web documents pretraining done base model supervised fine-tuning on conversations assistant What is the capital of France? What is the capital of Germany? … What is the capital of France? The capital of France is Paris.

Where the conversations come from

ModelExamplesWho wrote the assistant replies
InstructGPT (2022)13KAbout 40 hired contractors, chosen by a screening test, following written labelling instructions
LIMA (2023)1,000750 by users of Stack Exchange, wikiHow and Reddit, selected by the authors; 200 by the authors; 50 from Super-Natural Instructions
Tülu 3 (2024)939KExisting replies by people or frontier models (e.g. GPT-4o); missing or weak replies newly generated with GPT-4o
DeepSeek-V3 (2024)1.5MReasoning: domain expert models trained on outputs of an internal DeepSeek-R1, then rejection sampling. Other tasks: DeepSeek-V2.5, checked by annotators

Demonstration

A fine-tuning dataset and labelling instructions

  1. The Tülu 3 viewer: 939K rows with the columns id, messages and source
  2. One row: a list of messages, each with the fields role and content, as in the chat template
  3. The 19 sources: mathematics problems, WildChat, Aya (multilingual), OASST1, …
  4. The source tulu_hard_coded_repeated_10: replies about the model itself
  5. InstructGPT, Appendix B.2: the labellers’ definitions of helpful, truthful and harmless
8

Consequences of training

Hallucinations

Definition. A hallucination is a fluent and specific reply that is false, such as a wrong date, name, number or reference, stated in the same form as a correct reply.

Demonstration. In the terminal: 8, the same question three times to OLMo 2 7B, in the dialogue prompt of Question 5.

Remedy. Add to the fine-tuning data conversations in which the model does not know the answer and says so, for example:

User: When is the birthday of Adam Tauman Kalai?
Assistant: I don’t know his birthday.

Tool use

A tool call is text that the model writes and the application executes (Llama 3.1 format):

  1. the model writes the special token <|python_tag|>, then a call, then <|eom_id|>, “end of message”;
  2. generation pauses; the application runs the call (a search, a calculator, code);
  3. the result is appended to the context as a message of the role ipython, followed by a new assistant header;
  4. the model continues, now reading the result, until it ends its reply with <|eot_id|>.

Example of a call: <|python_tag|>brave_search.call(query="...")<|eom_id|>

Demonstration

A chat model with and without tools

  1. Search off: “How many pages does the September 2026 Common Crawl archive contain?”
  2. Search on, the same question in a new chat: the search call, the sources, the answer
  3. Search off, three new chats: “What is the title of Adam Tauman Kalai’s PhD thesis?”
  4. Code off: “How many letters e are in ‘The proof is left as an exercise to the reader’?”
  5. Code on, the same question: the program, its output, and the reply

Question 6

You are writing examples for a supervised fine-tuning dataset. Which reply should go into it, and which not? Why?

User message. A course had 14 lectures of 240 minutes. Three were cancelled, and each remaining lecture had two breaks of 10 minutes. How many minutes of teaching took place?

ReplyText
A2,420 minutes. There were 14 − 3 = 11 lectures, each with 240 − 20 = 220 minutes of teaching.
B14 − 3 = 11 lectures took place. Each had 240 − 20 = 220 minutes of teaching. 11 · 220 = 2,420 minutes.

Answer. B goes in, A does not. In A the result comes before any intermediate step, so its first token is computed in a single pass through the network, and the explanation after it cannot change it; a model fine-tuned on such replies learns to state results first and justify them afterwards. In B every intermediate result is written down and read by the later tokens.

Tokenization and spelling

A token enters the network as one learned vector, its row of the embedding table; its letters are not part of the input.

Example (o200k_base, GPT-4o; a box is one token, spaces included):

st302raw1618berry19772 strawberry101830

Example. Asked “How many Ds are in DEEPSEEK?”, DeepSeek-V3 answered 2 or 3 in ten trials (the answer is 1); DeepSeek-R1 first spelled the word and answered 1.

Tokenization of numbers

Example (o200k_base; a box is one token, spaces included; ␣ is the token consisting of one space). “9.11 > 9.9” and “12345 * 6789 =”:

924.1311994 >1424␣220924.13924 1237633452548 *425␣22067830833924 =314
Model (tokenizer)TaskAccuracy
Llama-3.1-8B (Llama 3)compare X.Y with X.Z, one-digit Y, two-digit Z (e.g. 9.9 and 9.11)55%
Llama-3.1-8B (Llama 3)the same comparisons when Z also has one digit100%
GPT-3.5 (cl100k_base)add two 7–9-digit numbers75.6%
GPT-3.5 (cl100k_base)the same sums but with commas97.8%

3456789 + 12345678, cl100k_base: groups from the left

3456789
12345678

3,456,789 + 12,345,678: groups from the right

3,456,789
12,345,678

Sycophancy and prompt injection

Sycophancy. A reply follows the beliefs the user has stated rather than what is true: the model withdraws a correct answer after the user disagrees, or praises an argument because the user says that they like it.

Example. In April 2025 OpenAI withdrew a sycophantic GPT-4o update within days; it named an added reward from users’ thumbs-up and thumbs-down.

Prompt injection. Text in data that the model reads, written so that the model follows it as an instruction, is a prompt injection.

Example. EchoLeak (CVE-2025-32711, 2025): injected text made Microsoft 365 Copilot leak data with no action by the user; rated critical, fixed by Microsoft.

9

Reinforcement learning

Three kinds of training data

1. Pretraining 2. Supervised fine-tuning 3. Reinforcement learning a document Problem: 17 · 24 = ? solution, given: 17 · 24 = 17 · 20 + 17 · 4 = 340 + 68 = 408 Problem: 17 · 24 = ? the model’s own attempts: … = 398✗ … = 408✓ … = 418✗ answer at the back: 408 textbook: the exposition textbook: a worked example textbook: an exercise the model reads the model imitates the solution the model finds a solution

DeepSeek-R1-Zero: reinforcement learning without supervised data

AIME 2024 (mathematics competition)Problems solved
one sample, start of training15.6%
one sample, end of training77.9%
majority vote over the sampled answers, end of training86.7%

Remark. Reflective words (“wait”, “verify”, “check”, “mistake”, …) become 5 to 7 times more frequent.

Training a model to reason

A reasoning model writes a chain of thought before its answer. Example (constructed):

User: What is the sum of the digits of 2^10?
Assistant: <think>2^10 = 1024. Digits 1, 0, 2, 4, sum 7. Wait, check 2^10:
2^5 = 32, and 32 · 32 = 1024. Yes.</think> The sum is 7.
DeepSeek-R1 (2025) base model 1. Fine-tune thousands of examples of long reasoning 2. RL reward: a correct final answer 3. Fine-tune again the base model again, on 600K of its own correct solutions, 200K other 4. RL again checked answers and preferences show examples: imitate practise: find imitate the best attempts practise again

Remark. Fine-tuning teaches the form of a reasoning text; RL makes the reasoning that reaches correct answers more likely.

Demonstration

A reasoning model on a counting problem

  1. Reasoning mode on: “How many 3-element subsets of {1, …, 10} have a sum divisible by 3?”
  2. The reasoning text: its length, the case analysis, the checks and corrections
  3. Reasoning mode off, the same question in a new chat: the length of the reply

Controlling the length of reasoning

A reasoning model first writes its thinking between <think> and </think>, then the answer.

MethodHow the length is controlled
Thinking budget (Qwen3, May 2025)At inference: stop at the budget, insert a fixed sentence and </think>
Effort keyword (gpt-oss, Aug 2025)Trained to follow “Reasoning: low / medium / high” in the system prompt
Budget reward (Kimi K3, Jul 2026)In RL: reward −1 if the thinking is longer than a multiple of a budget estimated from the SFT model; a smaller multiple for lower effort

Question 7

Can a reasoning model become less accurate when it thinks longer? Describe a situation where this could happen, or explain why.

Answer. Yes. A test of 2025: “You have an apple and an orange. [one to five irrelevant statements with numbers and probabilities] Calculate how many fruits you have.” The answer is always 2.

≈100% 85–90% Claude Opus 4 70% 30% DeepSeek R1, five distractors short reasoning long reasoning

Human judgements with and without a reward model

A prompt such as “Write a limerick about a topologist” has no answer that a program can check. A reward model, a network trained on human comparisons, gives each response a score.

Example (illustrative numbers). Human judgements for one RL run, without and with a reward model:

(a) without a reward model (b) with a reward model model during RL: 1,000 steps × 1,000 prompts × 1,000 responses people 109 scored by people model before RL: 1,000 prompts × 5 responses, ranked people 5,000 ranked by people fitted to the rankings model during RL: 1,000 steps × 1,000 prompts × 1,000 responses reward model 109 scored, no people