Search

Search papers and lessons

Least-to-Most Prompting

Level 4 · 10 min read

Least-to-most prompting asks a language model to split a hard problem into easier subquestions and answer them in order, feeding each answer into the next, so it can solve problems harder than its examples.

On this page

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

TL;DR

Least-to-most prompting is a way of asking a Language Model a hard question in two passes. First the model splits the question into smaller subquestions, each easier than the original. Then it answers them in order, and each answer is written into the prompt before the next subquestion is asked. The method needs no training, and on tasks where the split is clear it solves problems longer and harder than the examples it was shown.

Builds on: Chain-of-Thought Prompting, In-Context Learning · Leads to: the Least-to-Most paper

Where it's used

Symbolic word tasks. Zhou et al. (2022) tested the method on concatenating the last letters of a list of words. With lists of 12 words, a model using least-to-most prompting got 74.0 percent right, against 31.8 percent for chain-of-thought prompting with the same model. The gap widened as the lists grew. The chain-of-thought prompt's examples were only two- and three-word lists, so the longer test lists were far outside what it had shown.

Compositional commands. The SCAN benchmark asks a model to turn commands such as "look thrice after jump" into action sequences. Earlier work built specialised neural-symbolic models for it, trained on its training set of over 20,000 examples. With the code-davinci-002 model and 14 mapping examples plus 8 decomposition examples, least-to-most prompting reached 99.7 percent under the length split, where chain-of-thought prompting reached 16.2 percent.

Grade-school maths. On the GSM8K word problems the method helped only a little overall, from 60.87 to 62.39 percent. On the problems that need five or more steps it helped more, from 39.07 to 45.23 percent. The same pattern holds for the reading-comprehension benchmark DROP, where it beat chain-of-thought prompting by a wide margin.

How it works

Suppose you want a model to write the last letters of four words in order. The answer to the whole list depends on the answers to the shorter lists inside it, so the method asks for those first.

  1. Input. The full list is "think, machine, learning, data".
  2. Decompose. A prompt with example decompositions is sent, followed by the list. The model returns subquestions, each one a shorter list: first "think, machine", then "think, machine, learning", then the full list. Check: each subquestion is the previous one plus one word.
  3. Solve the first subquestion. The model answers "think, machine" with "ke". The last letter of "think" is k and of "machine" is e. Check: the letters read k then e.
  4. Solve the second subquestion with the first answer in the prompt. The prompt now contains "think, machine" and its answer "ke", and then the question "think, machine, learning". The model can extend "ke" with the last letter of "learning", which is g, giving "keg". Check: "keg" ends in the letter from "learning".
  5. Solve the last subquestion the same way. The answer "keg" is written into the prompt, followed by the full list. The last letter of "data" is a, so the answer is "kega". Check: the answer is the previous answer plus one letter.

Chain-of-thought prompting solves the same list with a different prompt. Its examples are independent, and each new list is worked out from scratch. The difference is in step 4. Least-to-most prompting reuses "ke" and only adds the new letter. Chain-of-thought prompting has to redo the earlier letters each time, and the longer the list, the more room there is for a slip.

flowchart LR
  Q[Hard question] --> D[Decomposition prompt]
  D --> S1[Subquestion 1, answer a1]
  S1 --> S2[Subquestion 2, given q1 and a1]
  S2 --> S3[Original question, given all earlier answers]
  S3 --> A[Final answer]
456789101112020406080100words in the listaccuracy (%)
  • least-to-most
  • chain-of-thought
Last-letter concatenation with code-davinci-002, as reported by Zhou et al. (2022). Both methods fall as the lists get longer, but least-to-most prompting falls far less.

The math

Let qq be the original question. The first stage produces a list of subquestions q1,q2,…,qnq_1, q_2, \dots, q_n, with qn=qq_n = q, the original question placed last. The second stage produces answers a1,…,ana_1, \dots, a_n one at a time.

Step 1 in symbols: decomposition

The decomposition prompt DD holds fixed example decompositions. The model draws the subquestion list from

(q1,…,qn)∼P(⋅∣D,q)(q_1, \dots, q_n) \sim P(\cdot \mid D, q)

where ∼\sim means "is drawn from", and P(⋅∣D,q)P(\cdot \mid D, q) is the model's distribution over possible lists given the prompt.

Step 2 in symbols: each answer uses the earlier answers

Let SS be a fixed set of solved example problems. Subquestion ii is answered from a prompt that contains SS, the earlier pairs (q1,a1),…,(qi−1,ai−1)(q_1, a_1), \dots, (q_{i-1}, a_{i-1}), and the new subquestion qiq_i:

ai∼P(⋅∣S, q1,a1,…,qi−1,ai−1, qi)a_i \sim P\bigl(\cdot \mid S,\ q_1, a_1, \dots, q_{i-1}, a_{i-1},\ q_i\bigr)

The text of the earlier answers is literally part of the prompt for the later ones. This is the "reuse" in step 4 of the walkthrough.

Step 3 in symbols: the answer to the original question

The final answer is ana_n, the answer to qn=qq_n = q. Since each aia_i depends on all earlier pairs, the probability of the whole run is a product of conditionals, in the same way as the chain rule for a autoregressive model:

P(a1,…,an∣q)=∏i=1nP(ai∣S, q1,a1,…,qi)P(a_1, \dots, a_n \mid q) = \prod_{i=1}^{n} P\bigl(a_i \mid S,\ q_1, a_1, \dots, q_i\bigr)

With the last-letter example, n=3n = 3, a1=a_1 = "ke", a2=a_2 = "keg", and a3=a_3 = "kega". The product has three factors, one per subquestion.

Worked examples

Example
1. Tiny: two words

Task: write the last letter of "run", then of "run, sun".

  1. Decomposition gives two subquestions: "run" and "run, sun".
  2. Solve "run". The last letter of "run" is n. So a1=a_1 = "n".
  3. Solve "run, sun" with "n" in the prompt. The last letter of "sun" is n, so a2=a_2 = "n" followed by "n", giving "nn".
  4. Check: each letter in "nn" comes from one word, in order.

Answer: "nn".

Example
2. Standard: four words

Task: last letters of "think, machine, learning, data".

  1. Subquestions: "think, machine"; "think, machine, learning"; the full list.
  2. a1=a_1 = "ke", from k (think) and e (machine).
  3. a2=a_2 = "keg". The prompt contains "ke", so the model only needs the new letter g from "learning".
  4. a3=a_3 = "kega". The last letter of "data" is a, appended to "keg".
  5. The chain-of-thought version has to produce all four letters from the full list in one go. The least-to-most version needed one new letter at each step.

Answer: "kega".

Example
3. Realistic: a word problem with two stages

Task: A shop sells pens at 2 dollars each and erasers at 1 dollar each. Ali buys 4 pens and 3 erasers and pays with a 20-dollar note. How much change does he get?

Work it through the method yourself first, then check against the answer below.

Answer: 9 dollars.

Working: pens cost 4×2=84 \times 2 = 8 dollars; erasers cost 3×1=33 \times 1 = 3 dollars; the total is 8+3=118 + 3 = 11 dollars; the change is 20−11=920 - 11 = 9 dollars.

Common mistakes and tradeoffs

It is tempting to think that splitting a problem always makes the model more accurate. In fact, the gain depends on whether the split is clear. On GSM8K the overall gain was about 1.5 points. The paper found that nearly every GSM8K problem was solved once a correct decomposition was supplied, so the model's own splits were the bottleneck. The gain was large on the longest problems and on the symbolic tasks, where the decomposition was easy to see.

It is tempting to think that the method needs training. In fact, both stages are few-shot prompts, and no weights change. This is why it can be tried on a new task in an afternoon, and also why the quality of the examples decides almost everything.

It is tempting to think a decomposition prompt transfers to any task. In fact, a prompt that splits maths word problems does not help with commonsense questions such as "Did Aristotle use a laptop?", because the kinds of split are different. Each domain needs its own decomposition examples.

It is tempting to think the subquestions can be answered in any order. In fact, each answer is written into the prompt for the next one, so the order is the point. The paper notes that the subquestions are usually dependent and must be solved in a specific order, so shuffling them breaks the reuse the method depends on.

Use least-to-most prompting when a task is longer or harder than the examples you can show, and when it splits cleanly into steps that depend on each other. Do not use it when the problem is already as easy as the examples, since chain-of-thought prompting is cheaper: it needs one pass rather than one pass per subquestion. Alternatives include self-consistency, which samples several chains and takes a vote, and hand-written decompositions, which the paper found solve almost every GSM8K problem the model's own decomposition failed on.

History

Chain-of-thought prompting showed in 2022 that writing out reasoning before an answer helped language models on many tasks. Its weakness was that the examples in a prompt set a ceiling. Zhou et al. observed that it tended to perform poorly on problems harder than the exemplars shown in the prompt.

Zhou et al. (2022) borrowed the name from educational psychology, where a progressive sequence of prompts helps a student learn a new skill. They applied the idea to language models: the model is taught to break a problem down, and then to build each answer on the answers before it. Their paper reported results on last-letter concatenation, SCAN, GSM8K and DROP, using prompts only and no training.

The idea caught on because it is simple to try and easy to inspect. The subquestions are readable text, so a person can see where a chain went wrong.

Recap

  • A hard question is split into subquestions, each easier than the original.
  • The subquestions are answered in order, and each earlier answer is written into the prompt for the next.
  • Both stages are few-shot prompts, so no training is needed.
  • The method helps most when the problem length or difficulty exceeds the examples, and when the decomposition is clear.
  • It is one of several prompting methods that build on Chain-of-Thought Prompting and In-Context Learning. Read the Least-to-Most paper next to see the experiments in full, then the out-of-distribution generalization lesson for why easy-to-hard tests matter.

Check yourself

QuestionIn one sentence, what are the two stages of least-to-most prompting?Show answer
The first stage asks the model to split the question into subquestions, each easier than the original. The second stage answers the subquestions in order, writing each answer into the prompt before the next subquestion.
QuestionA model answers the subquestion 'think, machine' with 'ke', and then the subquestion 'think, machine, learning'. What is the answer to the second subquestion if the last letter of 'learning' is g?Show answer
It is 'keg'. The method reuses 'ke' from the earlier answer and adds the new letter g, so the model does not need to redo the first two letters.
QuestionWhy does least-to-most prompting help with lists longer than the examples, but help little on GSM8K overall?Show answer
On the symbolic list task the decomposition is clear, and each step reuses the previous answer, so accuracy holds up as the list grows. On GSM8K the bottleneck was the model's own decompositions: the paper found that almost every problem it failed could be solved given a correct manual decomposition, so the overall gain was small. The gain was clearer on problems that needed five or more steps.
QuestionA team wants to use least-to-most prompting for a commonsense question-answering task, using the decomposition examples they wrote for maths word problems. Will it work well, and why?Show answer
Probably not well. Decomposition prompts often do not transfer across domains. A maths-style split does not suit questions like 'Did Aristotle use a laptop?', so the team needs new decomposition examples for that kind of question.

Sources