Reasoning models
Why does thinking longer before answering improve the answer?
Lesson complete
If you like:
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.
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.
Review modeComment on this stepI finished the lesson
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
- 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.
- 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.
- 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.
- 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.
- 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.
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: . If it answers directly, the answer comes from in a few passes. With a chain of thought, it first writes and then answers conditioned on it:
Each token of costs a full pass, about operations for an -parameter model (lessons 24 and 26): with and that is about more operations, and 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 without drifting too far from the starting model:
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: , 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): . 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 sampled answers , pick the most repeated one:
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 tokens, its answer is used; if not, it is cut at tokens, the thinking is closed with a fixed phrase, and the answer is requested. 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
Anthropic, for example, bills thinking tokens as output, and bills the full thinking even when it shows only a summary. Voting among multiplies the generated tokens by (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
- Language model A model that, given some text (the context), gives a probability to every word or piece that can come next. It writes by adding one piece at a time.
- Token A piece of text (a word, a word fragment, a symbol, or a basic code) taken from the vocabulary. It is the unit the model reads and generates, and the unit you are billed for.
- Autoregression Writing one piece at a time using what has already been written as input: each word produced becomes part of the context for the next.
- Sampling Drawing a new data point that follows a distribution: common things come out often and rare things seldom. It is how a generative model generates. (Not to be confused with the audio samples of lesson 2.)
- Temperature A number that divides the scores before the softmax. Low sharpens the distribution (toward the greedy choice); high flattens it (toward chance).
- Parameter Each of the numbers a model adjusts while training and in which it stores what it learned.
- Inference Using an already trained model to answer a new case, with frozen parameters.
- Compute The amount of arithmetic operations needed to train or run a model. Along with data and algorithms, it is one of the three engines of progress in machine learning.
- Decode Second phase: tokens are generated one at a time, and each one requires a full turn through the model that reads all the weights and the cache. It is usually limited by memory bandwidth.
- Reward model A model trained on comparisons between answers that returns a score: higher the more likely people are to prefer the answer. It acts as the judge during optimization; the probability that an answer wins is the sigmoid of the difference in scores.
- RLHF (reinforcement learning from human feedback) Tunes a model so that its answers earn more points from a reward model trained on human preferences, with a penalty (the KL “leash”) that keeps it close to the starting model.
- Alignment Techniques to get a model to do what the person intends and be helpful, honest, and harmless, not just whatever is most likely given its training text. It turns a base model into an assistant.
- Chain of thought The intermediate steps a model writes before its final answer. Each written step stays as context for the following tokens and adds computation; it can be requested in the prompt or come from a model trained to reason.
- Reasoning model A language model trained (mainly with reinforcement learning) to write out its own thinking, sometimes thousands of tokens long, before answering. Examples: OpenAI’s o1 (2024) and DeepSeek-R1 (2025).
- Test-time compute Computation spent while answering rather than while training: thinking for more tokens, generating several answers and voting, or checking them. It improves the answer without changing the weights, at the cost of more money and waiting.
- Verifiable reward A reward given by a rule that checks the answer (does it match the correct one? does it pass the tests?) instead of a learned judge. The basis of reinforcement learning with verifiable rewards (RLVR), used to train reasoning models.
Full transcript
Sources
- Wei, J., Wang, X., Schuurmans, D., Bosma, M., Ichter, B., Xia, F., Chi, E., Le, Q., Zhou, D. (2022). Chain-of-Thought Prompting Elicits Reasoning in Large Language Models (NeurIPS 2022; tabla 2: GSM8K con PaLM 8B, 62B y 540B)
- Kojima, T., Gu, S. S., Reid, M., Matsuo, Y., Iwasawa, Y. (2022). Large Language Models are Zero-Shot Reasoners («Let’s think step by step»)
- Wang, X., Wei, J., Schuurmans, D., Le, Q., Chi, E., Narang, S., Chowdhery, A., Zhou, D. (2023). Self-Consistency Improves Chain of Thought Reasoning in Language Models (ICLR 2023)
- OpenAI (2024). Learning to Reason with LLMs (presentación de o1, 12 de septiembre de 2024; AIME 2024: 12 %, 74 % y 83 % con consenso de 64)
- OpenAI (2024). OpenAI o1 System Card
- DeepSeek-AI (Guo, D., et al.) (2025). DeepSeek-R1: Incentivizing Reasoning Capability in LLMs via Reinforcement Learning (v2; publicado en Nature 645, 633–638, 2025)
- Lambert, N., Morrison, J., Pyatkin, V., Huang, S., Ivison, H., Brahman, F., et al. (2024). Tülu 3: Pushing Frontiers in Open Language Model Post-Training (§6: Reinforcement Learning with Verifiable Rewards)
- Muennighoff, N., Yang, Z., Shi, W., Li, X. L., Fei-Fei, L., Hajishirzi, H., Zettlemoyer, L., Liang, P., Candès, E., Hashimoto, T. (2025). s1: Simple test-time scaling (budget forcing)
- Chen, Y., Benton, J., Radhakrishnan, A., Uesato, J., Denison, C., Schulman, J., et al. (Anthropic) (2025). Reasoning Models Don’t Always Say What They Think
- Qwen Team, Alibaba (2026). Qwen3.5-4B (ficha del modelo: 4 mil millones de parámetros, modo de pensamiento activable, licencia Apache-2.0)
- Anthropic (2026). Steering thinking: pricing (los tokens de pensamiento se cobran como salida; se cobra el pensamiento completo, no el resumen; consultada el 12 de octubre de 2026)
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