Search

Search papers and lessons

Least-to-Most Prompting Enables Complex Reasoning in Large Language Models

Denny Zhou, Nathanael Schärli, Le Hou et al. · 2022

Least-to-most prompting has a language model split a hard problem into easier subquestions and answer them in order, so it can solve problems harder than its examples, with no training.

On this page

  • Colour = topic mix
  • Probability
  • Neural network basics
  • Calculus
  • Discrete math
  • Linear algebra
  • Learning basics
  • ReadReady to readNot yet

TL;DR

Least-to-Most prompting, from Zhou and colleagues in 2022, gets a Language Model to solve a hard problem in two passes. First it splits the problem into easier subquestions. Then it answers them in order, writing each answer into the prompt before the next subquestion. The paper targets a weakness of Chain-of-Thought Prompting: it fails when the test problems are harder than the examples in the prompt. On symbolic and math tasks the method handled longer and harder problems than its examples, and with the code-davinci-002 model it reached 99.7 percent accuracy on the SCAN benchmark under the length split, against 16.2 percent for chain-of-thought.

Builds on: Chain-of-Thought Prompting, In-Context Learning · Leads to: the least-to-most method

Why it mattered

The paper gave a name and a clear recipe to an idea that prompt designers were already reaching for: break a task into steps, and let each step see the answers before it. The method needs no training and no new data. The authors used a few examples per stage, with no gradient updates, which made the result a statement about In-Context Learning as much as about reasoning.

The SCAN result drew the most attention. SCAN maps short English commands to action sequences. Specialised neural-symbolic models had been built for it and trained on the SCAN training set, which for the length split is about 80 percent of the full set and over 20,000 examples. The paper reports that a large language model with least-to-most prompting, and only a few demonstration examples (eight for decomposition, fourteen for mapping), reached at least 99 percent accuracy on the length split. Later prompting work, such as ReAct Prompting, also builds a solution as a chain of steps where each step depends on the results of earlier ones, although those steps call outside tools.

The problem

Chain-of-Thought Prompting shows the model a few examples in which the reasoning is written out before the answer. It works well when the test questions look like the examples. The trouble starts when the test questions are harder than the examples, in the number of steps, the length of the input, or both. The paper calls this easy-to-hard generalization, and it is a kind of Out-of-Distribution Generalization: the new problems come from a harder range than the ones the prompt was built on.

The paper's simplest demonstration is last-letter concatenation. Given a list of words, output the last letters of the words joined together. For "think, machine" the answer is "ke". Chain-of-thought exemplars that use two-word lists work for two-word test lists, but accuracy falls as the test list grows. Standard prompting, with no reasoning written out, gets nothing right. Compositional generalization on SCAN is the second hard case: the test commands are longer than the training commands, and the model has to combine parts it has seen into a longer whole.

History

By 2022 it was known that large autoregressive language models could learn a task from examples in the prompt, as GPT-3 had shown in 2020. Chain-of-thought prompting, introduced the same year, showed that writing out intermediate reasoning in those examples raised accuracy on multi-step problems. What people were stuck on was the next step up: problems harder than the examples. Standard chain-of-thought failed on them, and neural systems built for benchmarks such as SCAN needed large training sets.

The Zhou group's answer was to borrow a method from educational psychology, where a teacher gives a sequence of prompts that move a learner from easy to hard. They applied it to the model: the model writes the sequence of subproblems, then solves them in order. The paper was posted in 2022, and its decomposition-then-solve pattern became one of the standard prompting techniques.

How it works

Take the list "think, machine, learning" and trace the method from start to finish. The answer is "keg", because the last letters are k, e and g.

  1. Input. The question is the list "think, machine, learning". It is longer than the two-word exemplars in the prompt. Check: the question has three words, and the exemplars have at most two.
  2. Stage 1, decomposition. The prompt holds a few fixed exemplars that show how to break a list into a sequence of shorter lists, followed by the new question. The model writes out the subproblems. Here it writes two: first "think, machine", then "think, machine, learning", which is the original problem, placed last. Check: each subproblem is shorter than the one after it, and the last one is the original question.
  3. Stage 2, solve the first subproblem. The prompt holds fixed exemplars that show how to build an answer, followed by the first subproblem only. The model answers "ke". Check: the last letters of "think" and "machine" are k and e.
  4. Stage 2, solve the next subproblem. The prompt is now longer. It holds the same exemplars, then the pair "think, machine" with its answer "ke", then the new subproblem "think, machine, learning". The model sees that "ke" is already solved, so it only needs the last letter of "learning", which is g, and it writes "keg". Check: the answer for the longer list is the earlier answer with one new letter added.
  5. Output. The answer to the last subproblem, which is the original question, is the final answer. The model never saw a list of three words in its examples, but it solved one by building on a two-word answer it had just written.
flowchart LR
  Q[Question: think, machine, learning] --> D[Stage 1: decompose]
  D --> S1[Subquestion 1: think, machine]
  S1 --> A1[Answer 1: ke]
  A1 --> S2[Subquestion 2: think, machine, learning]
  S2 --> A2[Answer 2: keg]

The key design choice is that stage 2 feeds each answer forward. An answer to an easier subproblem becomes text the model can read when it solves the next one. This is what the authors call a "bottom-up" resolution: the model builds the answer from the solved parts.

Worked examples

Example
1. The tiny case: 'think, machine, learning'
  1. Question: the last letters of "think, machine, learning".
  2. The last letter of "think" is k. The last letter of "machine" is e. So the answer for the two-word list is "ke".
  3. The last letter of "learning" is g.
  4. Append g to the earlier answer: "ke" plus "g" gives "keg".
  5. Interpretation: the model did not solve the three-word list from scratch. It reused the two-word answer and added one letter, which is the recursive step the paper's exemplars teach.
Example
2. The standard case: the length gap in the last-letter task
  1. The test lists have 8 words, and each length has 500 lists.
  2. Chain-of-thought gets 50.2 percent right at length 8.
  3. Least-to-most gets 83.0 percent right at length 8.
  4. The gap is 83.0 minus 50.2, which is 32.8 percentage points.
  5. Look at length 12. Chain-of-thought gets 31.8 percent and least-to-most gets 74.0 percent, a gap of 42.2 points.
  6. Compare how far each method falls. Chain-of-thought drops from 84.2 at length 4 to 31.8 at length 12, a fall of 52.4 points. Least-to-most drops from 94.0 to 74.0, a fall of 20.0 points.
  7. Interpretation: the decomposition keeps the method usable on longer lists, and chain-of-thought does not.
Example
3. The realistic case: a SCAN command
  1. The command is "look thrice after jump". The output should be the action sequence for it.
  2. Stage 1 decomposes the command into two parts, "jump" and "look thrice". The second part is the longer one, and it is built from the first.
  3. Stage 2 maps "jump" to JUMP.
  4. Stage 2 maps "look thrice" to LOOK repeated three times. The paper writes this as a short Python expression, LOOK times 3, and a script expands it afterwards.
  5. The rule "after" puts the first action sequence before the second, so the output is JUMP followed by LOOK, LOOK, LOOK.
  6. Interpretation: the model handled a new combination of parts from its examples, which is what compositional generalization asks for.

Try it: the command is "look twice after walk". Trace the two parts and give the final action sequence. Answer: WALK, then LOOK twice, which gives WALK LOOK LOOK.

The math

Write the question as qq. The decomposition exemplars are a fixed text DD, and the solving exemplars are a fixed text SS. Both are used for every question. The method is a pair of calls to the same model, written here as LM\mathrm{LM}, which returns text from a prompt.

Definition: Least-to-most prompting

Stage 1 produces nn subquestions q1,…,qnq_1, \ldots, q_n with qn=qq_n = q. Stage 2 produces answers a1,…,ana_1, \ldots, a_n, one at a time, where each answer is generated from a prompt that contains the solving exemplars, the earlier pairs, and the next subquestion. The final answer is ana_n.

Step 1 in symbols

The decomposition is one call:

(q1,…,qn)=LM(D,q),qn=q.(q_1, \ldots, q_n) = \mathrm{LM}(D, q), \qquad q_n = q.

The list has nn items, and the last item is the original question. The paper's exemplars keep each subquestion simpler than the next, so the sequence runs from easy to hard.

Step 2 in symbols

Each solving call sees all earlier pairs. For k=1,…,nk = 1, \ldots, n,

ak=LM(S,  (q1,a1),…,(qk−1,ak−1),  qk).a_k = \mathrm{LM}\big(S,\; (q_1, a_1), \ldots, (q_{k-1}, a_{k-1}),\; q_k\big).

When k=1k = 1 the list of earlier pairs is empty. Each aka_k is a text the model generated, so the answers to earlier subquestions are the model's own words. This is why an error in an early answer can carry into every later one.

Step 3 in symbols

The final answer is the last solved item,

y^=an.\hat{y} = a_n.

Accuracy on a test set of NN questions is the fraction that come out right, acc=1N∑i=1N1[y^i=yi]\mathrm{acc} = \frac{1}{N}\sum_{i=1}^{N} \mathbf{1}[\hat{y}_i = y_i], where yiy_i is the correct answer and 1[⋅]\mathbf{1}[\cdot] is 1 when the statement holds and 0 otherwise. The paper uses this measure throughout, with 500 test lists per length in the last-letter experiment.

Results

The paper reports three kinds of experiments. Each result below is taken from the paper's tables.

Last-letter concatenation (code-davinci-002). Standard prompting scored 0.0 at every length from 4 to 12. The table below gives accuracy in percent, over 500 test lists per length.

MethodL=4L=6L=8L=10L=12
Chain-of-thought84.269.250.239.831.8
Least-to-most94.088.483.076.474.0

The meaning is that the gap widens with length. The limit is that least-to-most is still well short of 100 percent at length 12. Most of its errors were concatenation slips, not wrong letters.

SCAN, length split. Accuracy in percent on the test set.

ModelStandardChain-of-thoughtLeast-to-most
code-davinci-00216.716.299.7
text-davinci-0026.00.076.0
code-davinci-0010.40.060.7

The meaning is that the result depends on the model: code-davinci-002 is stronger than text-davinci-002 for every method. The text-davinci-002 result is on a random subset of 100 commands. The paper also reports that the solving rate stayed the same on the other splits and on the full SCAN dataset.

GSM8K and DROP (code-davinci-002). On GSM8K, least-to-most scored 62.39 percent against 60.87 percent for chain-of-thought. On the numerical subset of DROP, the scores were 82.45 against 74.77 on non-football questions, and 73.42 against 59.56 on football questions. Broken down by the number of steps, the gain appears only at the long end: at five or more steps the scores were 45.23 against 39.07, and at two steps chain-of-thought was higher, 76.68 against 74.53.

The limits are clear from these numbers. The GSM8K prompt combines decomposition and solving in a single pass, and the gain on GSM8K is small. The authors observe that nearly every GSM8K problem the method missed could be solved once a correct decomposition was supplied, so the split itself is the weak point.

Common mistakes and tradeoffs

It is tempting to think least-to-most always beats chain-of-thought. In fact the gain depends on the task. On GSM8K the overall gap was small: 62.39 percent against 60.87 percent. On problems that need two steps, chain-of-thought was better, at 76.68 percent against 74.53 percent. The method helps most on problems that need five or more steps, where it reached 45.23 percent against 39.07 percent.

It is tempting to think a decomposition prompt works on any problem. In fact the paper says decomposition prompts typically do not transfer across domains. The math decomposition demonstrations did not help with commonsense questions such as "Did Aristotle use a laptop?", so each kind of problem needs its own demonstrations.

It is tempting to think that a correct split guarantees a correct answer. In fact, most of the remaining errors on the last-letter task came from concatenation, not from the letters themselves. The model dropped a letter or repeated one when it joined the pieces. The authors also note that almost every GSM8K problem the method missed could be solved once a person supplied the right decomposition, so the bottleneck was the decomposition.

When to use it: the problem has a clear way to be cut into smaller pieces, each piece depends on the one before, and the test problems will be longer or harder than the examples. When not to use it: when the problem has no obvious split, or when a single pass of chain-of-thought is already accurate enough, since the method costs one extra call for the decomposition and one call per subquestion. Alternatives include plain chain-of-thought, self-consistency, which samples many reasoning paths and votes, and tool-based methods such as ReAct Prompting, which fetch facts from outside the model.

Reading guide

The paper is short, and its sections map onto the lessons you need as follows.

  • Section 1, Introduction. Needs Chain-of-Thought Prompting and In-Context Learning. The introduction contrasts human learning from few examples with machine learning, and it names the easy-to-hard problem.
  • Section 2, Least-to-Most Prompting. Needs Least-to-Most Prompting. This is the method. Read it with the walkthrough above in mind.
  • Section 3.1, Symbolic manipulation. Needs In-Context Learning and the last-letter task in this lesson. The tables are the prompts, and Table 4 is the main result.
  • Section 3.2, Compositional generalization. Needs Out-of-Distribution Generalization, since the SCAN length split tests generalization to a harder range. The prompt uses Python expressions as an intermediate step, which is a detail you can skip on a first read.
  • Section 3.3, Math reasoning. Needs the GSM8K benchmark, and Fine-Tuning as a contrast with the training-free method. Read Tables 11 and 12 together.
  • Sections 4 to 6, Related work, limitations and conclusion. Needs Transformer only as background for the models named. The limitations section is the most useful part.

Recap

  • A language model trained to continue text can solve new tasks from examples in its prompt, which is In-Context Learning.
  • Chain-of-Thought Prompting writes out reasoning, but it fails when test problems are harder than its examples.
  • Least-to-most prompting uses two stages: decompose the problem into easier subquestions, then solve them in order.
  • Each answer is written into the prompt for the next subquestion, so the model builds on what it has already solved.
  • On SCAN with code-davinci-002 the method reached 99.7 percent under the length split, and on long last-letter lists it kept far more accuracy than chain-of-thought.
  • The gains depend on the task: small on GSM8K overall, large on problems with five or more steps.

Read next: Least-to-Most Prompting for the method on its own, and Self-Consistency Improves Chain of Thought Reasoning in Language Models for another way to get more accuracy from the same prompts.

Check yourself

QuestionWhat are the two stages of least-to-most prompting, and what does each one produce?Show answer

Stage 1, decomposition, takes the question and produces a list of subquestions, with the original question last. Stage 2, subproblem solving, answers the subquestions in order. Each solving prompt includes the earlier subquestions and their answers, so the output of stage 2 is one answer per subquestion, and the last answer is the final answer.

QuestionIn the last-letter task, chain-of-thought gets 31.8 percent at length 12 and least-to-most gets 74.0 percent. By how many percentage points does least-to-most lead?Show answer

The lead is 74.0 minus 31.8, which is 42.2 percentage points.

QuestionWhy does least-to-most prompting use the answer to one subquestion as part of the prompt for the next, and why is this important for problems longer than the examples?Show answer

Each new subquestion can be answered by reusing a solved part and adding one new step. The model does not have to solve the whole longer problem from scratch, which chain-of-thought must do. This recursive use of earlier answers lets it handle inputs longer than the examples it was shown.

QuestionA team wants a model to answer long, multi-step questions about its own product manuals. Their examples are short. Should they expect least-to-most prompting to help, and what would they need to design?Show answer

It may help, because the questions can be split into smaller parts that depend on one another. The paper notes that decomposition prompts typically do not transfer across domains, so the team would need decomposition demonstrations written for manual questions, and they should check whether a plain chain-of-thought prompt already works well enough for their shorter questions.

Sources

Read the full paper

Denny Zhou, Nathanael Schärli, Le Hou et al., 2022. arXiv:2205.10625