29

Reasoning models

Why does thinking longer before answering improve the answer?

12 min

Reasoning models

With voice. You can pause and jump to any step.

Lesson complete

Subtitles

Can a model think before it answers? Let’s test it with a pencil-and-paper problem. A train leaves with one hundred forty-eight passengers.

Voice

No voice: the lesson advances on its own with subtitles.

The voice for this lesson is being recorded: for now it advances on its own with subtitles.

0:00 / 0:00

What you will achieve

  • Explain why writing out the intermediate steps (the chain of thought) helps a model that writes one token at a time.
  • Describe how a reasoning model is trained: many tries, a rule that checks the answer (a verifiable reward), and reinforcement of the tries that get it right.
  • Predict what thinking longer or voting among several answers gains and costs, and recognize their limits: errors that repeat and reasoning that is convincing but wrong.

Key ideas

  1. A language model writes one token per pass. If it answers right away, the whole calculation must happen inside; if it writes out the steps (a chain of thought), each result stays as context and each token adds a pass of computation.
  2. Asking for steps only helped large models (540B PaLM: from 17.9 to 56.9% on GSM8K; the 8B one got worse). Reasoning models (o1 in 2024, DeepSeek-R1 in 2025) are trained to think on their own.
  3. They are trained with reinforcement learning and verifiable rewards: a rule checks the answer (is it the right number? does it pass the tests?) and the tries that get it right are reinforced. No one dictates how they should think.
  4. Test-time compute: thinking longer or voting among several answers improves results without touching the weights. In our measurement, Qwen3.5-4B went from 14 of 32 right without thinking to 32 of 32 with about 500 thinking tokens; cutting it at 32 tokens made it worse.
  5. All of that costs: thinking tokens are billed as output and add waiting, and voting multiplies the spend. Voting does not fix an error that repeats, and convincing reasoning can be wrong or hide its real reason.

What many people believe

Common belief If the model shows a long, orderly line of reasoning, the answer is reliable: the reasoning explains how it got there.

What is true Written thinking helps with calculating, but it guarantees nothing: an error in one step carries into the next ones just as confidently, and the text does not always reflect the real reason (in Chen et al.’s study, models mentioned the hint they used in 25% and 39% of cases). Check the result against something external: a calculation, a test, a source.

Check yourself

Four questions. No grade, no account: they just show whether the idea stuck.

ConceptWhy can writing out the intermediate steps help a language model solve a multi-step problem?
ConceptWhat is a verifiable reward?
CalculationA model thinks about 500 tokens per answer and writes at 100 tokens per second. If you vote among 8 answers, how many thinking tokens do you pay for, and how long does it take if it generates them one after another?
ApplicationYour team wants to turn on extended thinking for every query to an internal assistant: greetings, quick lookups and, now and then, calculating a quote. What do you recommend?

Under the hoodFor those who want the math and the code. You do not need it to follow the course.

Chain of thought, in one formula

An autoregressive model generates each token conditioned on everything before it: yt∼pθ(⋅∣x,y<t)y_t \sim p_\theta(\cdot \mid x, y_{<t}). If it answers directly, the answer aa comes from pθ(a∣x)p_\theta(a \mid x) in a few passes. With a chain of thought, it first writes c=(c1,…,cm)c = (c_1, \dots, c_m) and then answers conditioned on it:

pθ(a∣x)=∑cpθ(c∣x) pθ(a∣x,c)p_\theta(a \mid x) = \sum_{c} p_\theta(c \mid x)\, p_\theta(a \mid x, c)

Each token of cc costs a full pass, about 2N2N operations for an NN-parameter model (lessons 24 and 26): with N=4⋅109N = 4\cdot 10^9 and m≈500m \approx 500 that is about 4⋅10124\cdot10^{12} more operations, and mm more decode turns. Wei et al. (2022) put it this way: the chain lets a problem be decomposed into steps, so that “additional computation can be allocated to problems that require more reasoning steps.”

With 8 worked examples in the prompt, on GSM8K (grade-school math problems): PaLM 540B went from 17.9 to 56.9%, PaLM 62B from 9.6 to 29.9%, and PaLM 8B dropped from 4.9 to 4.1% (Wei et al., table 2). The authors observed that smaller models produced “fluent but illogical” chains. Kojima et al. (2022) showed that adding “Let's think step by step” is enough: with text-davinci-002, GSM8K rose from 10.4 to 40.7%. In the scene, the 3 and 51 tokens were counted with the Qwen3.5 tokenizer, which splits every digit into its own token.

Verifiable rewards

In lesson 28, RLHF maximizes a reward model’s points rϕr_\phi without drifting too far from the starting model:

max⁡θ Ex, y∼πθ(⋅∣x)[r(x,y)]−β KL(πθ ∥ πref)\max_\theta\ \mathbb{E}_{x,\ y \sim \pi_\theta(\cdot\mid x)}\big[r(x,y)\big] - \beta\, \mathrm{KL}\big(\pi_\theta \,\|\, \pi_{\text{ref}}\big)

Reinforcement learning with verifiable rewards (RLVR, a name from Lambert et al., 2024) uses the same objective but swaps the judge for a function that checks: r(x,y)=α⋅1[ verify(x,y) ]r(x,y) = \alpha\cdot\mathbb{1}[\,\text{verify}(x,y)\,], for example “the final answer matches the correct one” or “the code passes the tests.” DeepSeek-R1-Zero (DeepSeek-AI, 2025) samples 16 answers per question and compares each reward with the group’s (GRPO): Ai=(ri−mean(r))/std(r)A_i = (r_i - \text{mean}(r))/\text{std}(r). Its reward is accuracy + format; they avoided neural reward models because they are “susceptible to reward hacking.” On AIME 2024 its accuracy rose from 15.6 to 77.9% (one sample) and to 86.7% voting among 16. The average length of its responses grew during training, and the “aha moment” appeared (“Wait, wait. Wait.”). OpenAI describes o1 (2024) as “trained with large-scale reinforcement learning to reason using chain of thought”; it did not publish its recipe.

Self-consistency

With kk sampled answers a1,…,aka_1, \dots, a_k, pick the most repeated one:

a^=arg⁡max⁡a∑i=1k1[ai=a]\hat a = \arg\max_{a} \sum_{i=1}^{k} \mathbb{1}[a_i = a]

Wang et al. (2023) voted among 40 chains: PaLM 540B went from 56.5 to 74.4% on GSM8K (their measurement of the single chain is 56.5%; Wei et al.’s, 56.9%). OpenAI reported that o1 solved 74% of AIME 2024 with one sample and 83% with consensus among 64 (GPT-4o: 12%). Voting helps when errors scatter; if the model is always wrong the same way, the vote confirms the error.

Our measurement

Qwen3.5-4B (Qwen, 2026; Apache-2.0), quantized to fp8 and run with vLLM on an RTX 3060. For each language, 32 complete chains of thought (up to 4,096 tokens) at temperature 0.7, top-p 0.95, and top-k 20. Forced budget, like the budget forcing of Muennighoff et al. (2025): if the chain finished on its own in L≤BL \le B tokens, its answer is used; if not, it is cut at BB tokens, the thinking is closed with a fixed phrase, and the answer is requested. B=0B = 0 is the model’s no-thinking mode. Checking the answer (is it 120?) is the same rule a verifiable reward would use.

budget (tokens) 0 32 64 128 256 512 1,024 – 4,096
right, question in Spanish 14 0 4 3 30 32 32
right, question in English 10 7 31 21 27 32 32

Complete chains ran between 470 and 628 tokens (mean 529) in Spanish and between 400 and 714 (mean 498) in English. With short budgets the result goes up and down; from 512 on it does not change. It is a single problem with 32 tries and a small model: it illustrates the phenomenon, it does not measure it in general.

In code

from collections import Counter
import random

correct = 120
no_thinking = [125, 165, 200, 125, 120, 150, 170, 120, 170, 120, 174, 125, 120, 123, 166, 145,
               135, 143, 164, 160, 181, 120, 202, 120, 143, 145, 120, 135, 120, 182, 120, 120]
cut_at_32 = [120, 125, 120, 125, 125, 125, 125, 120, 120, 125, 120, 125, 125, 125, 125, 125,
             125, 125, 125, 125, 125, 125, 120, 125, 120, 125, 125, 125, 125, 125, 125, 125]
length = [566, 532, 560, 477, 609, 486, 562, 531, 714, 567, 560, 417, 490, 475, 494, 401,
          493, 525, 501, 479, 457, 401, 473, 400, 468, 460, 484, 485, 474, 474, 466, 461]  # tokens each try thought

def hits(answers):
    return sum(a == correct for a in answers)

def vote(answers):                     # the most repeated answer and its votes
    return Counter(answers).most_common(1)[0]

print(hits(no_thinking), vote(no_thinking))
print(Counter(a for a in no_thinking if a != correct).most_common(1))   # the most repeated error
print(hits(cut_at_32), vote(cut_at_32))

# how often is the vote right if k tries, picked at random, vote?
rng = random.Random(0)
for k in (1, 5, 15):
    right = sum(vote(rng.choices(no_thinking, k=k))[0] == correct for _ in range(10_000))
    print(k, right / 10_000)

# thinking tokens with budget B (if the model finishes earlier, it stops on its own)
for B in (0, 256, 512, 4096):
    print(B, round(sum(min(l, B) for l in length) / len(length), 1))
# 10 (120, 10)
# [(125, 3)]
# 7 (125, 25)
# 1 0.3133
# 5 0.5068
# 15 0.8167
# 0 0.0
# 256 256.0
# 512 479.2
# 4096 498.2

(On a tie, most_common keeps the answer that appeared first.)

Cost and waiting

cost=Tinput pinput+(Tthinking+Toutput) poutput,t≈tfirst token+Tthinking+Toutputtokens per second\text{cost} = T_{\text{input}}\, p_{\text{input}} + \big(T_{\text{thinking}} + T_{\text{output}}\big)\, p_{\text{output}},\qquad t \approx t_{\text{first token}} + \frac{T_{\text{thinking}} + T_{\text{output}}}{\text{tokens per second}}

Anthropic, for example, bills thinking tokens as output, and bills the full thinking even when it shows only a summary. Voting among kk multiplies the generated tokens by kk (in our test, 32 tries with thinking add up to 16,915 tokens in Spanish and 15,942 in English). The scene’s 100 tokens per second is an assumption.

Limits

Wei et al. reviewed 50 chains that ended in a wrong answer: 46% were almost right, except for a minor error (a calculation, a symbol, or a missing step). Chen et al. (2025) gave models a hint hidden in the question and measured whether their thinking mentioned it when they used it: Claude 3.7 Sonnet did so in 25% of cases and DeepSeek-R1 in 39%. Written thinking helps with calculating and checking, but it is not a guaranteed faithful explanation.

What comes next

Every question in this lesson was independent. In a conversation, everything that came before also takes up the model’s window (and the thinking takes tokens too): that is lesson 30, context and memory.

Decision lens

What this idea means if your job is to decide, not to code.

  • Thinking is paid for twice: in output tokens (the full thinking is billed even if you only see a summary) and in waiting. Ask the provider how many thinking tokens your typical task uses, and set a cap.
  • Use it where errors cost the most: calculations, contracts, code, multi-step analysis. For simple questions, classifying, or drafting something short, a model without extended thinking is usually enough and answers sooner.
  • Voting among several answers helps when errors scatter, but it multiplies cost by the number of votes and does not fix an error the model always makes the same way.
  • Do not trust how convincing the reasoning sounds: check the result against something external (a calculation, automated tests, a source). Wherever you can define a rule that verifies, use it for evaluation too.

Terms in this lesson

Full transcript
CommentsThis lesson’s public conversation: questions, facts to check, ideas.

Comments live in GitHub Discussions, in the course’s public repository; writing one requires a GitHub account. They load from giscus.app when you open this section. The course reviewers read them, and if a change is accepted, it is applied in both languages. Open the thread on GitHub

Sources