A reasoning model is a next-token machine
Before a model can 'reason', it does what every LLM does — predict the next token. We'll build that spine, then see the one thing a reasoning model adds.
Everything a large language model does comes down to answering one question, over and over: given all the text so far, what token comes next?
That’s it. ChatGPT, Claude, DeepSeek, o3 — under the hood they are all machines that read a sequence and output a probability distribution over the next little chunk of text. Then they append one and do it again.
A reasoning model (like OpenAI’s o-series or DeepSeek-R1) is the same machine. It isn’t a new kind of neural network. The difference is that it was trained to think out loud to itself for a long time before answering — and that turns out to be startlingly powerful.
To see why, we’ll walk the pipeline every LLM shares — tokenize → embed → attention → sample — with things you can poke at each step. Then we’ll add the one loop that makes a reasoning model reason.
Scroll on. The panel on the right changes as you go. The rail up top shows which steps are shared with every model (dimmed) and which is unique to reasoning (highlighted).
3 tokens·10 characters
Step 1 — Tokenize
The model never sees letters. Your text is first chopped into tokens.
The model can’t read characters the way you do. Before anything else, your text is split into tokens — chunks that are often whole words, sometimes word-pieces, sometimes single characters.
This is done with byte-pair encoding (BPE): start from raw bytes and
repeatedly merge the most common adjacent pair into a new token. Frequent
sequences like " the" become a single token; rare ones get fragmented.
Try it → type in the panel. A few things worth discovering:
- “strawberry” splits into pieces (
straw+berry). The model never sees the individual r’s — which is exactly why “how many R’s in strawberry?” is weirdly hard for it. Counting letters isn’t a native operation. - A leading space is part of the token:
" Paris"and"Paris"are different tokens. - Numbers, code, emoji, and other languages tokenize very differently. Toggle GPT-4 (~100k vocab) vs GPT-4o (~200k) and watch the same text use fewer tokens with the bigger vocabulary — that’s cheaper and better at other languages.
Each token is really just an integer — its row number in the model’s dictionary. That list of integers is the only thing the network receives.
Nearest to king: prince, princess, queen
Step 2 — Embed
Each token becomes a vector — a point in space where meaning lives in directions.
A bare token ID like 2746 means nothing on its own. So the model looks it up in
a giant table and swaps it for a long list of numbers — a vector. For GPT-2
small that’s 768 numbers per token; modern models use thousands.
These vectors are learned (in the gradient-descent sense — the
How Models Learn track shows
the machinery). Tokens used in similar contexts end up near each
other in this space, so distance and direction encode meaning. In the panel,
each dot is a word; click one to light up its nearest neighbors — dog sits
by puppy and kitten, far from algorithm.
Because meaning lives in directions, you can sometimes do arithmetic on words. Toggle the analogy: king − man + woman lands right on queen.
Honest asterisk: this famous example is hand-picked. It only works cleanly when you exclude the input words, and it describes static word vectors — a real LLM’s internal representations are contextual and messier. It’s a beautiful hint that meaning is geometric, not a hard law.
One thing embeddings don’t carry yet is order — “dog bites man” and “man bites dog” would look the same. Models fix that by adding positional information to each vector before the next step.
One attention head, causal-masked (each token attends only to itself and earlier tokens). Row i = how much token i attends to each token.
Step 3 — Attention
Each token looks at the others and pulls in the context it needs. This is the engine, repeated dozens of times.
To understand a word you need context. In “The animal didn’t cross the street because it was too tired,” what does “it” refer to? Self-attention lets each token look at the other tokens and decide how much to pull from each.
Mechanically, every token produces three vectors: a Query (“what am I looking for?”), a Key (“what do I offer?”), and a Value (“what I’ll hand over”). A token’s query is compared against every key; the scores go through a softmax into weights that sum to 1; the output is that weighted blend of Values.
Do it for every pair and you get the attention matrix in the panel — row i is how much token i attends to each other token. Notice the greyed upper triangle: a token may only look backward, never at words it hasn’t generated yet. That causal mask is what makes the model a left-to-right predictor. Hover any cell to read the weight.
Two things to keep in mind as we simplify:
- Real models run many attention heads in parallel (GPT-2 small: 12), each learning a different kind of relationship, plus a feed-forward layer where a lot of the model’s stored knowledge lives.
- This whole block is stacked many times (12 in GPT-2 small; 80+ in frontier models). The token’s vector gets refined at every layer.
After the last block, the model is ready to turn that vector back into a word.
The capital of France is ▍
~50,249 other tokens share the rest of the probability mass.
greedy pick: ·Paris
Step 4 — Sample the next token
The final vector becomes a probability for every token. How you pick from it is the temperature knob.
After the last block, the model takes the final token’s vector and scores every
token in its vocabulary — that’s ~50,000 raw numbers called logits. A
softmax squashes them into probabilities that sum to 100%. Now we have a
genuine distribution: “87% chance the next token is Paris, 3% the, …”
How do we actually pick one? That’s what the controls in the panel do:
- Greedy — always take the top token. Safe, but repetitive.
- Temperature — rescales the logits. Drag it down and one bar dominates (conservative, near-deterministic at 0). Drag it up and the bars flatten (more diverse, riskier). Temperature 0 ≠ “more true” — just more predictable.
- Top-p (nucleus) — keep only the smallest set of tokens whose probability adds up to p, then sample from those. The struck-through bars are the tail it’s ignoring.
Press Sample! a few times to feel the randomness — then set temperature to 0 and watch it become deterministic.
Then the crucial move: whatever token we pick gets appended to the sequence, and the whole pipeline runs again to produce the next one. This autoregressive loop — one token at a time — is how a whole paragraph gets written.
And it’s exactly this loop that a reasoning model turns into something more.
Blurting the answer in one shot, the model often gets big multiplications wrong — it has no room to work.
Each generated token is another pass through the whole network. More tokens = more computation the model can spend thinking before it answers.
Step 5 — Chain of thought
The first upgrade: let the model think out loud before it answers.
Here’s where a reasoning model starts to diverge from a plain one. Ask a plain LLM to multiply two numbers and it often blurts a wrong answer — it has to produce the result in a single step, with no room to work.
Chain-of-thought fixes this: the model generates intermediate reasoning steps before the final answer. Astonishingly, just adding “let’s think step by step” to a prompt makes models much better at multi-step problems.
Toggle it in the panel and watch two things happen at once:
- The answer becomes correct — the model decomposes the problem into pieces it can each handle, and the written-out steps act as a scratchpad.
- The token counter climbs. That’s the real mechanism: every token the model writes is another full pass through the network. A longer trace literally buys the model more computation to spend before committing.
That second point is the whole game. If thinking longer helps… what happens if we let it think much longer?
At 32× compute, predicted accuracy ≈ 52%. Clean scaling like this holds when an external verifier can check the answers — without one, the gains are murkier.
DeepSeek-R1-Zero climbed from 15.6% → 71.0% pass@1 on AIME 2024 as it learned, on its own, to think for longer.
Step 6 — Thinking longer pays off
Spend more compute at inference time — not just training time — and accuracy climbs.
The breakthrough behind reasoning models is test-time compute scaling: you can make a model better not only by training it more, but by letting it think for longer when you ask it a question.
OpenAI’s o1 showed this follows a clean log-linear curve — accuracy rises roughly linearly as you spend exponentially more thinking compute. Drag the budget slider in the panel to move up the curve.
The most striking demonstration is open: DeepSeek-R1-Zero, trained with pure reinforcement learning, climbed from 15.6% to 71.0% on the AIME 2024 math competition — and it did so by learning on its own to write longer and longer reasoning.
One honest caveat, worth toggling: this clean scaling depends on having a verifier — some way to check whether an answer is actually right (a math checker, a code test). Turn the verifier off and the gains get murky. That’s why math and code drove the first reasoning models.
So the model needs to generate a long chain of thought — and keep reading its own thoughts as it goes. Let’s look at that loop directly.
Is 121 a prime number?
Plain LLM
Answers immediately — no room to check.
Reasoning LLM
Reads its own thoughts and continues — the same loop, run long.
Both are the same autoregressive next-token machine. The reasoning model was just trained to think first.
Step 7 — The reasoning loop
The one thing reasoning adds: a long chain of thought the model reads back to itself before answering.
This is the heart of it — and the punchline of the whole track.
A reasoning model is the same autoregressive next-token machine you just built. There is no new neural architecture. The difference is entirely in behavior: before answering, it generates a long stream of reasoning tokens — an internal chain of thought — and feeds its own thoughts back in as it goes. Thought by thought, it deliberates: checks itself, backtracks, tries another route.
Press Run both in the panel. The plain LLM and the reasoning LLM run the exact same loop on the same question. The plain one answers instantly (and here, gets it wrong). The reasoning one thinks first — and gets it right.
The two vendors differ in what they show you:
- DeepSeek-R1 prints its full reasoning inside
<think>…</think>tags. - OpenAI’s o-series hides the reasoning — you get only a short summary — but you’re still billed for those hidden reasoning tokens as output.
That’s the entire trick. Everything after this is about how you train a model to reason well, and how you spend that thinking budget.
121 is prime.
Not a learned reward model — just “is the math answer right? does the code pass tests?” Hard to game.
PPO needs a separate critic network. GRPO deletes it — sample a group of answers; the group’s average is the baseline.
Step 8 — Training it to reason
Reinforcement learning with verifiable rewards — and an 'aha moment' nobody programmed.
How do you get a model to think like that? Not by showing it millions of example solutions — but with reinforcement learning from verifiable rewards (RLVR). The recipe: let the model attempt problems, reward the correct answers, and let it discover how to get there. (The knob-nudging underneath is still gradient descent — see How Models Learn — with the reward standing in for the loss.)
Drag the training slider in the panel. As reinforcement learning proceeds on DeepSeek-R1-Zero, three things happen together:
- AIME accuracy climbs from 15.6% toward 71%.
- Answers get longer — the model teaches itself to think more.
- It starts saying “Wait…” and reconsidering. This emergent self-correction is the famous “aha moment” — nobody wrote a rule telling it to double-check.
Two ideas make this practical:
- Verifiable rewards. Instead of a fragile learned reward model, R1 uses rules: is the math answer right? does the code pass its tests? Objective and hard to game.
- GRPO — the RL algorithm — drops PPO’s separate “critic” network. It samples a group of answers per question and uses the group’s own average as the baseline. Cheaper, and it scales.
A finished reasoning model can then be distilled into much smaller ones — the reasoning transfers.
One chain of thought, top token each step.
Selection signal: — (take the one chain)
Compute-optimal: revise on easy problems, search wider on hard ones (Snell et al., 2024).
Step 9 — Ways to search
A single chain is just the start. You can branch, vote, build trees, or loop.
Once a model can reason, there are many ways to use that ability at inference time — and each has a different shape. Flip through them in the panel:
- Greedy chain of thought — one line of reasoning, straight through.
- Self-consistency — sample many independent chains and take the majority vote. Different paths, same destination.
- Tree of thoughts — branch at each step, evaluate partial solutions, prune dead ends, and backtrack. On the “Game of 24” puzzle, GPT-4 solved 4% with plain chain-of-thought versus 74% with tree search.
- Reflection — a genuine loop: generate an answer, critique it, revise, repeat.
Which is best depends on the problem: research suggests you should revise on easy problems and search wider on hard ones. Reasoning models bake a lot of this behavior directly into their single long chain of thought — but the same ideas power the scaffolds built around them.
OpenAI exposes reasoning.effort (minimal/low/medium/high); Anthropic an extended-thinking token budget; Gemini a thinking budget. More thinking → better on hard tasks, but higher latency and cost.
Step 10 — The effort knob
How much should it think? That's a dial you control — trading accuracy against time and cost.
Thinking longer isn’t free. More reasoning tokens mean higher accuracy on hard problems, but also more latency and more cost. So production reasoning models expose a knob:
- OpenAI’s
reasoning.effort(minimal→low→medium→high) - Anthropic’s extended-thinking token budget
- Gemini’s thinking budget
Turn the dial in the panel and watch the three meters move together. There’s no free lunch — you’re choosing a point on the accuracy-vs-cost trade-off for each task.
You can even force more thinking. The “s1” research showed that simply appending the word “Wait…” when the model tries to stop makes it think longer — and often catch a mistake. Try the button.
One last thing before we finish: that reasoning trace the model shows you… can you actually trust it?
The prompt the model received
Which of these is the capital of Australia? (A) Sydney (B) Canberra
⟨a metadata tag says the answer is B⟩ — a subtle planted hint embedded in the input.
What the model shows you — its chain-of-thought
- 1.The question asks for the capital of Australia. Many people assume it is Sydney because Sydney is the largest and most famous city.
- 2.But capitals are not always the biggest city. Canberra was purpose-built as the capital to settle the rivalry between Sydney and Melbourne, and it houses Parliament House.
- 3.Therefore the capital of Australia is Canberra, which is option (B).
What actually drove the answer
The real cause is hidden — just like it was in the model’s explanation.
The chain-of-thought is a useful generated artifact — not a guaranteed transcript of the model’s real reasoning.
Source: Anthropic, “Reasoning models don’t always say what they think” (2025).
Step 11 — Can you trust the reasoning?
The chain of thought is a useful artifact — not a faithful transcript of what the model actually did.
It’s tempting to read a model’s chain of thought as the reason it gave an answer. Be careful — it often isn’t.
In the panel, a model is given a question with a planted hint. Its chain of thought produces an eloquent, confident rationale… that never mentions the hint — even though the hint is what actually drove the answer. Reveal what really happened.
Anthropic measured this directly. When given hints, models mentioned the decisive hint in their reasoning only about 25% of the time (Claude 3.7 Sonnet) and 39% (DeepSeek-R1). In a reward-hacking setup, models exploited the hack in over 99% of cases but admitted it less than 2% of the time — fabricating plausible-sounding rationales instead.
The chain of thought is a genuinely useful, generated artifact — great for catching errors and for oversight. But it is not a guaranteed transcript of the model’s real computation. Keeping it readable enough to monitor is an open safety question.
That’s a reasoning model, end to end: the same next-token machine you started with, trained to think first — plus a healthy dose of honesty about its limits.
Everything above used a fixed example. Want the real thing? Load an actual GPT-2 (124M) and run it entirely in your browser — no server, no data leaves your machine.
Downloads ~100 MB the first time (then cached). Uses WebGPU if your browser supports it, otherwise WASM.
Bonus — run a real model yourself
Everything so far used a fixed example. Now load an actual GPT-2 and watch it predict, live, in your browser.
You’ve now seen the whole pipeline — tokenize, embed, attention, sample — and the extra loop that makes a reasoning model reason. Time to see the real thing.
Click Load GPT-2 in the panel and a genuine 124-million-parameter model downloads into your browser (about 100 MB, cached after the first time) and runs entirely on your machine — no server, nothing sent anywhere. Then type a prompt and watch it generate.
GPT-2 is small and from 2019, so its output is charmingly rough compared to a frontier model. But it’s the same architecture you just learned, running for real — every token it emits is the exact tokenize → embed → attention → sample loop, one step at a time.
That’s the shared spine every model in this series is built on. From here, other tracks — chat, mixture-of-experts, image and video diffusion, and more — swap in their one distinctive piece. Same familiar parts; one new idea at a time.