Chain-of-thought prompting

Chain-of-thought prompting asks an AI model to work through a problem step by step before it answers. It improves results on maths, logic and multi-step tasks.

Chain-of-thought (CoT) prompting asks an AI model to write out its reasoning step by step before giving the final answer. The written steps act as working memory, so the model makes fewer jumps to a wrong conclusion.

It helps on maths, logic puzzles, planning and any question with several steps. On simple fact questions it adds length without adding accuracy.

An example

The classic test is the bat and ball puzzle. The quick answer is wrong, and models fall for it the same way people do.

The bat and ball question answered two ways. The direct answer says 10 cents and is wrong. The step-by-step answer sets up an equation and reaches 5 cents.

Two ways to use it

Few-shot CoT shows worked examples with their reasoning, then asks the new question. This is the method from the Google paper Chain-of-Thought Prompting Elicits Reasoning in Large Language Models. With eight worked examples, a 540B-parameter model reached a then state-of-the-art score on GSM8K, a set of grade-school maths problems.

Zero-shot CoT skips the examples and adds one line such as “Let’s think step by step” to the prompt. A second 2022 paper, Large Language Models are Zero-Shot Reasoners, found this line raised GSM8K accuracy from 10.4% to 40.7% on text-davinci-002.

Zero-shot CoT Few-shot CoT
What you add One instruction Two or more worked examples
Effort Lowest Higher
Control over the steps Low High

Chain of thought and reasoning models

Newer reasoning models do this on their own. They are trained to think through a problem before they answer, often in a hidden reasoning step.

With these models you rarely need to write “think step by step”. Clear goals and constraints matter more. Chain-of-thought prompting still helps with faster, non-reasoning models when a task has several steps.

Tips

  • Ask for the steps, then the answer. End with a clear line such as “Final answer” so it is easy to find.
  • A wrong step is easier to spot than a wrong number.
  • Skip it for simple tasks. Extra steps cost tokens and time.
  • A model can write tidy reasoning and still reach a wrong answer.
Chandan Kumar

Chandan Kumar

Founder, Sparkian and Geekflare

Chandan Kumar is a founder of Sparkian & Geekflare. He is a technology enthusiast and entrepreneur who loves to help businesses and people around the world.

Ready to spark your next idea?

Your next question, first draft, or big idea. Start here.