Chain-of-thought Prompting
Table of Contents
Chain-of-thought Prompting
Description
Chain-of-thought (CoT) prompting is a prompt engineering strategy used to significantly improve the ability of Large Language Models (LLMs) to handle tasks that require multi-step reasoning, such as arithmetic, symbolic manipulation, and commonsense reasoning.
How it Works
CoT prompting guides the LLM to break down the problem into a sequence of simpler, logical steps, effectively converting a difficult, single-step problem into a series of easier, intermediate steps.
- Instruction: The user's prompt includes a phrase like "Let's think step by step," or the prompt provides a few examples (few-shot prompting) where the solution is derived through intermediate steps.
- Internal Reasoning: The LLM generates this sequence of reasoning steps as part of its output, serving as an explicit thought process that mimics human problem-solving.
- Final Answer: The model concludes its output with the final answer, which is derived directly from the preceding steps.
Purpose and Benefits
- Improved Accuracy: By forcing the model to articulate its logic, CoT prompting dramatically improves performance on complex reasoning tasks compared to standard prompting, especially in arithmetic and logical deduction.
- Transparency and Auditing: The intermediate steps provide an audit trail, making the model's logic transparent. This allows users to trace the reasoning, verify its soundness, and easily identify where the model may have made a mistake.
- Enhanced Generalization: This structured reasoning makes the model better at generalizing to new and novel problems that require similar logical decomposition.
Examples
. Zero-shot CoT (Implicit Instruction)
This method involves simply appending a phrase to trigger the step-by-step reasoning.
| Prompt | LLM Output (CoT) |
|---|---|
| Prompt: A movie ticket costs $15. I bought 5 tickets, paid with a $100 bill, and spent $5 on popcorn. How much change should I receive? Let's think step by step. | LLM Output: 1. First, calculate the total cost of the tickets: \(5 \text{ tickets} \times \$15/\text{ticket} = \$75\).2. Next, calculate the total spent: \(\$75 \text{ (tickets)} + \$5 \text{ (popcorn)} = \$80\).3. Finally, calculate the change received: \(\$100 \text{ (paid)} - \$80 \text{ (spent)} = \$20\).*Answer: $20* |
2. Few-shot CoT (Explicit Example)
This involves providing one or more examples where the problem is solved using the full reasoning chain, which teaches the model the desired format and logic.
| Prompt | LLM Output (CoT) |
|---|---|
| Prompt: Example 1: Q: The kitchen had 23 apples. If 12 were used to make pie and 6 were eaten, how many apples are left? A: The kitchen started with 23 apples. \(23 - 12 = 11\) apples left after making pie. \(11 - 6 = 5\) apples left after eating. Answer: 5 New Question: A librarian put 18 new books on the shelf. 5 were checked out. Later, she added 12 more. How many books are on the shelf now? | LLM Output: A: The shelf started with 18 books. \(18 - 5 = 13\) books were left after check-out. \(13 + 12 = 25\) books are on the shelf after adding more. Answer: 25 |