REASONING FROM SCRATCH · CHAPTER 01
A frozen model can reason in the prompt. Show it a pattern, or ask it to write the steps. No weight updates. This chapter is that cheap win.
Picture a clerk at a harbor office. You ask how many crates sit on three piers. If they blurt “38”, you cannot tell whether they added or guessed. If they write North, then East, then West, then the sum, you can catch a slip on the second line.
A language model is that clerk. It predicts the next token. It will give you a confident total either way. Chain of thought is the margin work: the model spends tokens on the steps so the final token is better conditioned.
Reasoning, in this series, means a visible intermediate trace that a checker could grade. The weights can stay frozen. Later chapters teach the model to write those traces on purpose. This chapter does it with the prompt alone.
Pre-training teaches a model to continue text. That is enough for “the capital of France is Paris”. It is not enough for a three-step crate count, a proof, or a program that has to pass tests. The model can sound sure and still skip a subtraction.
margins · ICL · CoT · frozen
Here is the harbor puzzle this series will keep coming back to. Small numbers. You can do it in your head.
Pier North has 14 crates. Pier East has 6 fewer than North. Pier West has twice as many as East. How many crates in total?
A standard prompt asks for the total and often gets a bare “38” — or a confident “42”. A reasoning prompt asks for the three lines first. The extra tokens are extra compute. That is test-time compute: you spend more decoding to raise the chance the last number is right.
| What failed | What it looks like |
|---|---|
| Hallucinated fact | Inventing a fourth pier |
| Arithmetic slip | Writing East as 20 instead of 8 |
| Logic break | Doubling North instead of East |
| Premature lock-in | Naming 38 in sentence one, then refusing to revise |
In-context learning is pattern completion inside one forward pass. You put a few input–output pairs in the prompt. You do not touch the weights. The model continues the table.
A dock clerk keeps a log. We want three fields: ship, berth, cargo. Two worked lines, then a new one:
Brig Aster left berth 4 at 05:10 with timber. → Aster | 4 | timber
Cutter Wren took berth 1 at 07:00 with ice. → Wren | 1 | ice
Barque Lark took berth 9 at 12:40 with salt. →
The model writes Lark | 9 | salt. Nobody fine-tuned it on dock logs. The format in the prompt is the format it continues.
That is few-shot in-context learning. Zero-shot is the same idea with no pairs — only an instruction. Both are frozen-weight tricks. They get sharper as models get larger, which is why 2022 papers called them “emergent”. Later work showed some of that sharpness is a metric artifact: a discontinuous plot can hide a smooth log-prob gain. Treat emergence as a 2022 snapshot, not a law of nature. Modern 1–8B models already ICL well when they are trained long enough.
Chain of thought is in-context learning where each exemplar includes the working, not just the final number. The 2022 few-shot recipe (Wei et al.) is: several question / reasoning / answer triples, then the new question. The model copies the shape of the working.
One exemplar, different numbers from the test puzzle so the model has to generalize:
A shed holds 9 tins. A cart holds 3 fewer. A crate holds twice the cart. Total?
Working: cart \(9 - 3 = 6\). Crate \(2 \times 6 = 12\). Total \(9 + 6 + 12 = 27\). Answer: 27.
Then you ask the harbor puzzle. The model should write East 8, West 16, total 38 — not 27. The exemplar taught the shape, not the answer.
Interactive · Same puzzle, two replies
How much extra text does the working actually add?
Count the words. The standard reply is 2 words. The working is 21 words — about ten times more generation. That is the compute you are buying. Three things make it help:
One hard question becomes three easy ones.
Each step is another forward pass. The model gets room to compute.
A bad East is visible. A bare “42” is not.
On GSM8K, PaLM 540B went from 17.9% with a standard prompt to 56.9% with few-shot chain of thought. That is the number to remember. Smaller 2022-era models barely moved. That “scale gate” is history: today’s small open models already write steps. Do not quote “CoT needs 100B” as a current fact.
The same three lines the model is supposed to write. Change NORTH and the total follows.
"""Harbor crate puzzle — the running example for chapters 01 and 02.
A reader can do every step by hand. The numbers are small and round.
North starts at 14. East is 6 fewer. West is twice East.
"""
# The three piers. Change these and the total changes with them.
NORTH = 14
EAST_LESS = 6
def east_crates(north=NORTH, less=EAST_LESS):
"""East is a subtraction away from North."""
return north - less
def west_crates(east):
"""West is a doubling of East."""
return 2 * east
def total_crates(north=NORTH, less=EAST_LESS):
"""Sum of the three piers. This is the answer we want the model to reach."""
east = east_crates(north, less)
west = west_crates(east)
return north + east + west
# Frozen few-shot facts for the page. Standard prompting names the total.
# Chain-of-thought writes the three intermediate numbers first.
STANDARD_ANSWER = 38
COT_STEPS = (14, 8, 16, 38)
# The two replies shown on the page. Word counts are whitespace splits.
# Real tokenizers split some of these further; the ratio stays similar.
STANDARD_REPLY = "38 crates."
COT_REPLY = (
"North 14. East 14 minus 6 is 8. "
"West twice 8 is 16. Add 14, 8, and 16 to get 38."
)
STANDARD_WORDS = len(STANDARD_REPLY.split()) # 2
COT_WORDS = len(COT_REPLY.split()) # 21
if __name__ == "__main__":
east = east_crates()
west = west_crates(east)
total = total_crates()
assert east == 8 and west == 16 and total == 38
assert COT_STEPS == (NORTH, east, west, total)
print(f"North={NORTH} East={east} West={west} total={total}")
east_crates is the step models skip when they double North by accident.Few-shot CoT needs carefully written exemplars. Kojima et al. (2022) showed a shorter trick: append “Let’s think step by step.” The model then writes a trace, and a second prompt extracts the answer (“Therefore, the answer is”). Two stages. The first is allowed to ramble. The second is only allowed to name the number.
Zero-shot CoT is brittle. Wording matters. It still fails when the model cannot do the underlying arithmetic. And a fluent trace is not proof the model used those steps — that is the faithfulness problem (Turpin et al. 2023, Lanham et al. 2023). The written reason can be a story it tells after it already picked an answer.
Once you have seen CoT work, the rest of the series is about making it reliable. Four families:
| Family | What you change | Where it lives here |
|---|---|---|
| Inference-time | Prompt, sample many, verify, search | This chapter and chapter 02 |
| Pure RL | A verifier reward, no reasoning SFT | GRPO, R1-Zero |
| SFT then RL | A few traces, then RL | R1, the capstone |
| Distillation | Train a small student on a teacher’s traces | The last act of chapter 11 |
Chapters 03–09 are the RL tools that families 2 and 3 need. You can skip them if you only want prompting. You will want them the first time a verifier starts grading samples.
“The model thought, so the answer is justified.” The trace can be unfaithful. Grade the final answer with a checker, not the story.
“CoT is an emergent cliff at 100B.” That was a 2022 picture of under-trained models. Small modern models write steps. Emergence plots are also sensitive to the metric (Schaeffer et al. 2023).
Reusing the test numbers in the few-shot exemplar. Then you have not tested reasoning. You have tested copy-paste. The shed uses 9 and 3. The harbor uses 14 and 6.
Counting only the last token as compute. A 21-word trace is roughly ten times the 2-word reply. Attention cost grows faster than that, so the real bill is higher.
East 8, West 16, total 38.
So the model has to copy the method, not the number. The shed totals 27. The harbor totals 38.
No gradient step. The only new information is text in the prompt.
Faithfulness: the model can pick an answer and then invent steps that do not match how it got there.
Inference-time: prompting, sampling, voting, search. That is this chapter and the next.