Chain-of-Thought Prompting Elicits Reasoning in Large Language Models
Put worked examples in a prompt, and large models solve multi-step problems.
Google's PaLM 540B, prompted with eight worked math examples and trained on none of the benchmark, scored 56.9% on grade-school word problems and beat a model finetuned on the whole training set. The same prompt makes models under 10B parameters slightly worse.
Explaining the paperChain-of-Thought Prompting Elicits Reasoning in Large Language ModelsThe method changes nothing about the model. It changes the answers in the example questions written into the prompt, from a bare number to the few sentences of working that produce it.
By 2021, making language models bigger had improved almost everything except multi-step reasoning. On arithmetic word problems, logic puzzles and symbolic tasks, accuracy barely moved as parameter counts grew by orders of magnitude. A model that could write fluent essays still failed a two-step problem like "23 apples, use 20, buy 6 more, how many now?"
This paper, posted to arXiv by Jason Wei and eight Google colleagues in January 2022, changes how the question is asked. In few-shot prompting you put a handful of solved examples in front of the real question. The authors kept that setup and changed one thing: each example answer now shows the intermediate steps, in plain sentences, before the final number. They call the steps a chain of thought. On GSM8K, a benchmark of grade-school math word problems, PaLM 540B went from 17.9% with standard prompting to 56.9% with chain-of-thought prompting, past the previous best of about 55%, which came from a 175B model finetuned on the full training set and paired with a separately trained verifier.
The page follows the paper's argument in order: what few-shot prompting is and why reasoning stalled under it, what the new prompt looks like and why the steps must come before the answer, why only very large models benefit, the three ablations that rule out cheaper explanations, the results across arithmetic, commonsense and symbolic tasks, the tests on inputs longer than any example, robustness to who wrote the examples, and what the generated chains get wrong.
Few-shot prompting and its flat curve
A large language model computes one thing: given a string of tokens (word pieces), a probability distribution over the next token. Computing that distribution once is a forward pass through the network. Generation repeats that step, appending the chosen token each time. Nothing in the loop names a task, so the task has to be communicated through the input string.
GPT-3 (Brown et al., 2020) showed the standard way to do that, called few-shot prompting or in-context learning. You write several solved examples of the task into the prompt, each an input followed by its output, then the new input with its output left blank. The model continues the text, and the likeliest continuation is an output in the same format. The solved examples are called exemplars. No weights change: the exemplars are ordinary input tokens, and the same checkpoint can do translation with one prompt and arithmetic with another.
For many tasks, few-shot accuracy climbs steadily as models get larger. Reasoning tasks were the exception. The paper cites Rae et al. (2021), whose 280B-parameter Gopher model showed only small gains on math and logic benchmarks as size increased. The paper's own Table 2 shows the same shape with standard prompting on GSM8K: GPT-3 goes from 2.2% at 350M parameters to 15.6% at 175B, a 500-fold increase in size for 13.4 percentage points.
The known alternative was finetuning on worked solutions. Cobbe et al. (2021), who built GSM8K, finetuned GPT-3 175B on the benchmark's roughly 7,500 training problems and their written solutions and added a verifier model that scores 100 sampled solutions per test problem and keeps the best. That reached about 55%, but it needs a dataset of written solutions for every task and a separate model per task.
The change: exemplars that show the working
In standard few-shot prompting each exemplar is a pair, ⟨question, answer⟩. In chain-of-thought prompting it is a triple, ⟨question, chain of thought, answer⟩, where the chain of thought is a short series of natural-language steps that lead to the answer. The paper's Figure 1 uses a tennis-ball exemplar and a cafeteria test question. The exemplar question: Roger has 5 tennis balls. He buys 2 more cans of tennis balls. Each can has 3 tennis balls. How many tennis balls does he have now? Its chain: Roger started with 5 balls. 2 cans of 3 tennis balls each is 6 tennis balls. 5 + 6 = 11. The answer is 11.
The model has no instruction to reason. It continues a pattern. Every exemplar answer in the prompt is a few sentences of arithmetic followed by "The answer is N.", so the likeliest continuation after the test question's "A:" is a few sentences of arithmetic followed by "The answer is N." Toggle the figure between the two prompts; the test question and the model stay the same.
With the working shown, the model writes They used 20 to make lunch. So they had 23 - 20 = 3. They bought 6 more apples, so they have 3 + 6 = 9, and the last line reads the answer off the step before it. The two prompts below are the full text the model receives, shortened to one exemplar instead of eight:
# standard few-shot prompt: each exemplar is a question and a bare answer
Q: Roger has 5 tennis balls. He buys 2 more cans of tennis balls. Each can
has 3 tennis balls. How many tennis balls does he have now?
A: The answer is 11.
Q: The cafeteria had 23 apples. If they used 20 to make lunch and bought 6
more, how many apples do they have?
A: # PaLM continues: "The answer is 27." (wrong)# chain-of-thought prompt: same questions, the exemplar shows its working
Q: Roger has 5 tennis balls. He buys 2 more cans of tennis balls. Each can
has 3 tennis balls. How many tennis balls does he have now?
A: Roger started with 5 balls. 2 cans of 3 tennis balls each is 6 tennis
balls. 5 + 6 = 11. The answer is 11.
Q: The cafeteria had 23 apples. If they used 20 to make lunch and bought 6
more, how many apples do they have?
A: # continues: "The cafeteria had 23 apples originally. They used 20
# to make lunch. So they had 23 - 20 = 3. They bought 6 more apples,
# so they have 3 + 6 = 9. The answer is 9."The authors wrote one set of eight exemplars by hand and used it for every arithmetic benchmark except AQuA, which is multiple choice and got four exemplars taken from its training set. They state that these exemplars "did not undergo prompt engineering." Decoding is greedy: at each step the model emits its single most likely token, with no sampling and no voting over several answers. The models are PaLM (8B, 62B, 540B), LaMDA (422M, 2B, 8B, 68B, 137B), four GPT-3 models from the OpenAI API, plus UL2 20B and Codex. No model is finetuned. The whole evaluation fits in a few lines:
# pseudocode for the evaluation loop; nothing here updates a weight
EXEMPLARS = load_eight_worked_examples() # hand-written, reused per task
def solve(model, question):
prompt = "\n\n".join(f"Q: {q}\nA: {a}" for q, a in EXEMPLARS)
prompt += f"\n\nQ: {question}\nA:"
text = model.generate(prompt, decoding="greedy") # one token at a time
return parse_after(text, "The answer is") # read the final number
accuracy = mean(solve(palm_540b, q) == gold for q, gold in gsm8k_test)Why the working goes before the answer
A language model produces an output one token at a time, each token drawn conditioned on the prompt and on every token it has already written:
This is the standard autoregressive factorization, not an equation from the paper, but it shows what the prompt change does. Write the chain as and the answer as . With standard prompting the output is just , so the answer tokens condition on the prompt and nothing else. With a chain of thought the output is followed by , and by (1):
Now the answer tokens condition on the written steps. In the cafeteria example, when the model reaches "The answer is", the text 3 + 6 = 9 is already in its input, and copying the 9 is a much easier next-token prediction than computing 9 from the question in one step. Put the chain after the answer and (2) becomes : the model commits to an answer before writing any step, and the chain can only justify it. The paper tests exactly that ordering in its ablations below.
The authors list four properties that make the method attractive, and they present them as motivation, not as evidence. A chain lets a multi-step problem be split into steps, and a problem with more steps gets more generated tokens, so more computation goes to harder problems. A chain shows how the model reached its answer, which helps locate errors, though the authors add that fully characterizing the model's computation behind an answer is still an open question. Chains are plain language, so the method applies to any task a person can reason about in words. And any large enough off-the-shelf model can use it, given only the examples.
Each of those properties also suggests a less interesting explanation for any gain. Maybe the model only needs to write the equation, and the words are decoration. Maybe it only needs more tokens before the answer, since each generated token is another forward pass of computation. Maybe writing anything related before the answer brings relevant knowledge into the context. The paper tests all three, after first establishing which models the method helps at all.
Only large models benefit
Chain-of-thought prompting does nothing for small models, and often makes them worse. The authors inspected the output and found that models below about 10B parameters write chains that are fluent and grammatical but illogical, so the final answer drawn from them is wrong more often than the bare answer standard prompting gives. PaLM 8B scores 4.9% on GSM8K with standard prompting and 4.1% with chains. At 62B the numbers are 9.6% and 29.9%; at 540B, 17.9% and 56.9%. GPT-3 loses accuracy with chains at 350M (2.2% to 0.5%) and at 6.7B (4.0% to 2.4%), then at 175B goes from 15.6% to 46.9%.
Switch between the three model families, and between three arithmetic benchmarks of different difficulty. GSM8K problems take two to eight steps; MultiArith is the multi-step subset of the MAWPS benchmark; SingleOp is the MAWPS subset that needs a single operation.
The companion paper by Wei and colleagues, Emergent Abilities of Large Language Models, names this pattern. An ability is emergent if it is absent in smaller models and present in larger ones, so that extrapolating the small models' curve would not predict it. That paper lists chain-of-thought prompting on GSM8K as emergent at about training FLOPs, which for LaMDA is the 68B model. The chain-of-thought paper itself states the threshold only as "models of ∼100B parameters" and never mentions FLOPs. The companion paper also stresses that the scale at which an ability emerges depends on the task and is not a fixed property, and neither paper claims to know why it happens.
The gain also grows with how hard the problems are, which the benchmark switch in Figure 2 shows. GSM8K has the lowest standard-prompting scores, and the paper reports that its accuracy more than doubled for the largest GPT and PaLM models. MultiArith, also multi-step, shows the largest single jump: PaLM 540B goes from 42.2% to 94.7%, and GPT-3 175B from 33.8% to 91.7%. On SingleOp, PaLM 540B scores 94.1% both ways and GPT-3 175B drops from 90.9% to 88.8%. A problem that takes one operation has no intermediate step to write down, and the large models already solve most of these problems without one.
The paper gives one piece of evidence about what scale changes. The authors compared errors of PaLM 62B with PaLM 540B on the same GSM8K problems and found that the larger model fixes a large share of the 62B model's semantic-understanding errors and missing-single-step errors (Appendix A.1).
Ablations: equation, dots, answer first
To separate the three cheap explanations, the authors ran three variants of the prompt on LaMDA 137B. Each variant keeps one ingredient of a chain of thought and removes the rest. The GSM8K standard baseline for this model is 6.5% and the full chain of thought reaches 14.3%.
chain · Reasoning in plain language, then the answer. The full method.
Equation only. The exemplars show only the math expression before the answer, with none of the words. If writing the equation were the whole effect, this would recover most of the gain. On GSM8K it scores 5.4%, below the 6.5% baseline. The authors' reading is that GSM8K questions are too semantically involved to translate into an equation in one jump; in a chain, the sentences do that translation one quantity at a time. On MAWPS, whose problems take one or two steps, equation-only does help (50.1% against 43.2%), because there the equation can be read almost directly off the question. The full chain still scores higher, at 57.9%.
Variable compute only. The exemplars show a row of dots before the answer, with as many dots as there are characters in the equation needed to solve the problem. An equation like 5 + 2 * 3 = 11 has 14 characters, so the exemplar answer would start with 14 dots. This gives the model the extra generated tokens (and the extra forward passes) of a chain with none of its content. It scores 6.4% on GSM8K, the same as the baseline within the reported ±0.3 spread.
Reasoning after the answer. The exemplars give the answer first and the chain of thought afterwards. The model still writes relevant text, so any benefit from bringing knowledge into context should remain; but by (2) the answer can no longer condition on the steps. It scores 6.1% on GSM8K, at baseline again.
Chain of thought is the only variant of the five that moves GSM8K: 14.3%, against 5.4% to 6.5% for the others. The gain needs natural-language steps, and it needs them before the answer. Table 7 of the paper repeats the dots and answer-first ablations on commonsense and symbolic tasks with the same outcome: on last-letter concatenation, for example, dots score 7.2% and answer-first 0.0%, against 77.5% for the chain.
Results task by task
Because the steps are ordinary language, the same kind of prompt works for tasks that are not arithmetic. The paper runs five commonsense benchmarks: CSQA (commonsense multiple choice), StrategyQA (yes/no questions whose answer needs an unstated chain of facts, such as whether a pear sinks in water), date understanding and sports understanding from BIG-bench, and SayCan, which maps a spoken request to a sequence of robot actions. It also runs two symbolic tasks, covered in the next section. Each gets its own hand-written chain-of-thought exemplars.
The figure puts every benchmark on one chart. Sort the rows by standard-prompting score, and most of the large gains sit in the upper rows, where standard prompting was weak. Switch the model to find the rows where chains lower the score.
GSM8K · Grade-school math word problems, 2 to 8 steps each. PaLM 540B: 17.9 → 56.9.
PaLM 540B improves on thirteen of the fourteen rows and ties on SingleOp at 94.1%. On sports understanding it goes from 80.5% to 95.4%, above the 84% the paper cites for an unaided sports enthusiast. On StrategyQA it goes from 68.6% to 77.8%, above the prior state of the art of 69.4% (the main text quotes 75.6% for this result; see the Provenance panel). On CSQA the gain is small, 78.1% to 79.9%, and the authors call it minimal.
Switch to GPT-3 175B and two commonsense rows go the wrong way: CSQA drops from 79.5% to 73.5% and StrategyQA from 65.9% to 65.4%. The authors list this as a limitation and do not know which differences in pretraining data or architecture cause it. They describe it as the only exception across the three model families, but their own tables contain one more: switch to LaMDA 137B and AQuA drops from 25.5% to 20.6%.
Inputs longer than the exemplars
The two symbolic tasks test something the math benchmarks cannot. Last-letter concatenation asks for the last letter of each word in a name, joined together: "Amy Brown" gives "yn". Coin flip describes a coin that starts heads up and a list of people who each flip it or do not, then asks whether it is still heads up. Both tasks let the authors build test inputs longer than any exemplar. The exemplars only contain two-word names and two people; the in-domain test set has the same length, and the out-of-domain (OOD) test sets have three and four.
The chain the exemplars teach for each task is fixed. For names it is one sentence per word, The last letter of "Elon" is "n", then the concatenation. For the coin it is three moves: list who flipped the coin, count them, and read the answer from whether the count is odd or even, with no heads-or-tails state written down after each person (from Appendix Table 23: The coin was flipped by Ka and Sherrie. So the coin was flipped 2 times, which is an even number. The coin started heads up, so after an even number of flips, it will still be heads up. So the answer is yes.).
To handle a longer input the model has to apply the exemplar's procedure more times than it was shown: one more "The last letter of" sentence per extra word, or a longer list of names before the count. A model that memorized how two-word answers look cannot produce the right four-word answer. With PaLM 540B, chain of thought scores 99.4% on two-word names, 94.8% on three and 63.0% on four; standard prompting scores 7.6%, 0.2% and 0.0%. On the coin, standard prompting already solves the in-domain case (98.1%), but on three and four people it falls to 49.3% and 54.8%, near the 50% of a guess, while chain of thought holds at 98.6% and 90.2%.
Small models still fail these tasks. These are, in the paper's words, "toy tasks": the exemplar chains already contain the complete procedure, and the model only has to repeat it with new names. PaLM 8B still reaches only 18.8% on in-domain letter concatenation with chains, and on the four-word set it scores 0.2%. The paper reports behaviour only; it does not show how the model represents the count or the partial string internally.
Other annotators, other exemplars
Few-shot results can depend heavily on the particular prompt. The paper cites Zhao et al. (2021), who found that reordering the exemplars alone moved GPT-3's accuracy on a sentiment task from 54.3% to 93.4%. If chain of thought only worked with the authors' eight hand-picked examples, the result would say little about the method.
The authors tested seven different chain-of-thought prompts on LaMDA 137B. Annotator A's chains are the ones used throughout the paper. Two co-authors, B and C, wrote their own chains for the same eight questions with no instructions beyond "write the step-by-step reasoning." Annotator A also wrote a deliberately concise version. Finally, three sets of eight exemplars (α, β, γ) were sampled at random from the GSM8K training set, whose solutions were written by crowdworkers without a machine-learning background; the sampled examples were limited to at most two steps and 60 tokens. Each prompt was run with several random orderings of its exemplars, and the whiskers in the figure are one standard deviation across those orderings.
annotator C · A third co-author, same eight questions, independent chains.
On GSM8K the seven prompts score between 11.1% (the concise rewrite) and 17.6% (annotator C), and the random GSM8K sets score 12.6%, 12.7% and 12.6%. The lowest is still 4.6 points above the 6.5% standard baseline. The same holds on SVAMP, ASDiv and MAWPS, where every chain-of-thought prompt beats standard prompting. The random GSM8K exemplars were also used on the other three benchmarks, so the exemplars do not have to come from the test set's own distribution. Across exemplar orderings the standard deviations are at most 1 point on GSM8K; Appendix A.2 also reports the gains holding as the number of exemplars varies.
Wording still matters on some tasks, and the paper says so. On coin flip, accuracy ranged from 99.6% with annotator A's chains to 71.4% with annotator C's, both above standard prompting's 50.0%, and the coin-flip results also had large standard deviations across exemplar orderings. In preliminary experiments on reversing a list of five items, two authors could not write a chain-of-thought prompt that worked; the third wrote one that solved the task perfectly.
What the chains get wrong
The authors read 50 chains that LaMDA 137B wrote for GSM8K problems it answered correctly. The main text reports that all 50 were logically and mathematically correct except two that reached the right answer by coincidence (Appendix D.1 counts one such case; see the Provenance panel).
They also read 50 chains that led to wrong answers and sorted them by the edit needed to fix each one. 46% were almost correct: 8% needed only an arithmetic fix (the model wrote a wrong result for a correct expression), 16% had a symbol-mapping error (right words, wrong numbers in the equations), and 22% were missing one step. The other 54% had major errors in understanding the problem or in coherence. The calculator errors suggested a direct fix: evaluate each equation in the chain with Python and substitute the result. That lifts LaMDA 137B on GSM8K from 14.3% to 17.8% and PaLM 540B from 56.9% to 58.6% (Table 1).
The headline result and its limits
Figure 7 shows the GSM8K comparison the paper opens with: two systems trained on GSM8K and two that were only prompted.
PaLM 540B with eight chain-of-thought exemplars scores 56.9% on the 1,319-problem GSM8K test set, against 55% for the finetuned-plus-verifier system and 17.9% for itself with standard prompting. The 39 points between 17.9% and 56.9% come from changing the exemplar answers and nothing else. Codex (code-davinci-002), run in the same setup, went further: 19.7% to 63.1%.
The authors draw one broad conclusion: standard prompting gives only a lower bound on what a large model can do. Before this paper the flat scaling curve on reasoning tasks was read as a limit of the models; with a different prompt, the same checkpoints produce a steep curve. The follow-up work this led to is separate from the paper: self-consistency (Wang et al., March 2022) samples many chains and takes the majority answer, zero-shot chain of thought (Kojima et al., May 2022) replaces the exemplars with the phrase "Let's think step by step", and later models were trained to write long chains by default.
The paper also lists what it does not show. It does not establish that the model is reasoning in any deeper sense; the authors leave that question open. Nothing guarantees a correct reasoning path, since a chain can reach a right answer through wrong steps or a wrong answer through steps that look fine. Writing eight exemplars is cheap, but building a large set of written chains to finetune on would not be. And because the gains appear only around 100B parameters, the method needs models that are expensive to serve. One more caveat applies to the GPT-3 rows: the largest GPT-3 model the paper evaluates, text-davinci-002, is an instruction-tuned model from OpenAI's InstructGPT line, not the plain pretrained GPT-3, and its 175B size is the authors' presumption.
Questions you might still have
Does chain-of-thought prompting change the model’s weights?
No. The eight worked examples are extra tokens in the prompt, read in the same forward passes as the question. The paper finetunes nothing, and one frozen checkpoint per model runs every benchmark.
Why does it only help large models?
Below about 10B parameters the models copy the format of a chain but fill it with wrong steps, and the wrong steps lead to wrong answers more often than the bare answer of standard prompting: PaLM 8B scores 4.1% on GSM8K with chains and 4.9% without. The gain appears around 100B on these math tasks. The companion Emergent Abilities paper measures that threshold per task and does not claim a mechanism for it.
Is the model actually reasoning, or copying the shape of the examples?
The paper leaves this open. The length-generalization results show the model applying a shown procedure to longer inputs than any example, which rules out copying whole answers. But a chain can be wrong and land on the right answer, or look right and land on the wrong one, and nothing guarantees the written steps are the computation that produced the answer.
Is this the same as "Let’s think step by step"?
No. That phrase is zero-shot chain of thought (Kojima et al., May 2022), a later paper that uses no examples at all. This paper is few-shot: eight hand-written worked examples, greedy decoding. Self-consistency (Wang et al., 2022), which samples many chains and takes the majority answer, is another later paper.
Why not just finetune on worked solutions?
That works, and the GSM8K authors did it, but it needs thousands of written solutions per dataset and produces a separate model per task. Chain-of-thought prompting needs eight examples and keeps one model for all tasks. The paper notes the flip side: the method needs a model of about 100B parameters, which is expensive to serve.
Does the exact wording of the examples matter?
On the arithmetic benchmarks, not much: three authors writing independent chains, a terse rewrite, and three random sets of GSM8K training solutions all beat standard prompting on LaMDA 137B, at 11.1% to 17.6% against 6.5% on GSM8K. On some tasks it matters a lot: coin-flip accuracy ranged from 99.6% (annotator A) to 71.4% (annotator C), and reversing a five-item list only worked with one of three authors’ prompts.
Footnotes & further reading
- The paper: Wei, Wang, Schuurmans, Bosma, Ichter, Xia, Chi, Le, Zhou, Chain-of-Thought Prompting Elicits Reasoning in Large Language Models (Google Research, NeurIPS 2022). Appendix Tables 1 to 7 hold the benchmark numbers on this page; Tables 20 to 28 hold the exact exemplar prompts.
- The baseline: Brown et al., Language Models are Few-Shot Learners (GPT-3), which introduced zero-, one- and few-shot in-context learning with no weight updates. Explained on this site at GPT-3.
- The benchmark and the prior best: Cobbe et al., Training Verifiers to Solve Math Word Problems (GSM8K), whose finetuned GPT-3 175B plus a verifier over 100 sampled solutions set the ~55% record.
- The flat scaling curve: Rae et al., Scaling Language Models: Methods, Analysis & Insights from Training Gopher (280B parameters).
- The emergence framing: Wei et al., Emergent Abilities of Large Language Models (TMLR), the companion paper that defines emergence and lists chain-of-thought prompting on GSM8K as an example.
- The models: Chowdhery et al., PaLM (8B / 62B / 540B), and Thoppilan et al., LaMDA (up to 137B). The GPT-3 sizes used in the paper are the authors' stated presumption, not OpenAI-confirmed figures; on how text-davinci-002 relates to instruction tuning, see InstructGPT.
- Prompt-order sensitivity: Zhao et al., Calibrate Before Use: Improving Few-Shot Performance of Language Models.
- Later and separate from this paper: Wang et al., Self-Consistency Improves Chain of Thought Reasoning in Language Models (sample many chains, take the majority answer), and Kojima et al., Large Language Models are Zero-Shot Reasoners (the zero-shot "Let's think step by step").
How could this explainer be improved? Found an error, or something unclear? I read every message.