thought-based-reasoning
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseThought-Based Reasoning Techniques for LLMs
大语言模型(LLMs)的基于思维的推理技术
Overview
概述
Chain-of-Thought (CoT) prompting and its variants encourage LLMs to generate intermediate reasoning steps before arriving at a final answer, significantly improving performance on complex reasoning tasks. These techniques transform how models approach problems by making implicit reasoning explicit.
Chain-of-Thought (CoT) 提示法及其变体鼓励LLM在得出最终答案前生成中间推理步骤,显著提升了复杂推理任务的性能。这些技术通过将隐含推理显性化,改变了模型处理问题的方式。
Quick Reference
快速参考
| Technique | When to Use | Complexity | Accuracy Gain |
|---|---|---|---|
| Zero-shot CoT | Quick reasoning, no examples available | Low | +20-60% |
| Few-shot CoT | Have good examples, consistent format needed | Medium | +30-70% |
| Self-Consistency | High-stakes decisions, need confidence | Medium | +10-20% over CoT |
| Tree of Thoughts | Complex problems requiring exploration | High | +50-70% on hard tasks |
| Least-to-Most | Multi-step problems with subproblems | Medium | +30-80% |
| ReAct | Tasks requiring external information | Medium | +15-35% |
| PAL | Mathematical/computational problems | Medium | +10-15% |
| Reflexion | Iterative improvement, learning from errors | High | +10-20% |
| 技术 | 适用场景 | 复杂度 | 准确率提升 |
|---|---|---|---|
| Zero-shot CoT | 快速推理、无可用示例 | 低 | +20-60% |
| Few-shot CoT | 有优质示例、需要统一格式 | 中 | +30-70% |
| Self-Consistency | 高风险决策、需要可信度 | 中 | 比CoT高+10-20% |
| Tree of Thoughts | 需要探索的复杂问题 | 高 | 困难任务上+50-70% |
| Least-to-Most | 包含子问题的多步骤问题 | 中 | +30-80% |
| ReAct | 需要外部信息的任务 | 中 | +15-35% |
| PAL | 数学/计算类问题 | 中 | +10-15% |
| Reflexion | 迭代改进、从错误中学习 | 高 | +10-20% |
Core Techniques
核心技术
1. Chain-of-Thought (CoT) Prompting
1. Chain-of-Thought (CoT) 提示法
Paper: "Chain of Thought Prompting Elicits Reasoning in Large Language Models" (Wei et al., 2022)
Citations: 14,255+
论文: "Chain of Thought Prompting Elicits Reasoning in Large Language Models" (Wei et al., 2022)
引用量: 14,255+
When to Use
适用场景
- Multi-step arithmetic or math word problems
- Commonsense reasoning requiring logical deduction
- Symbolic reasoning tasks
- When you have good exemplars showing reasoning
- 多步骤算术或数学应用题
- 需要逻辑推导的常识推理
- 符号推理任务
- 拥有展示推理过程的优质示例时
How It Works
工作原理
Provide few-shot examples that include intermediate reasoning steps, not just question-answer pairs. The model learns to generate similar step-by-step reasoning.
提供包含中间推理步骤的少样本示例,而非仅问答对。模型会学习生成类似的分步推理过程。
Prompt Template
提示模板
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: 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.
Q: [YOUR QUESTION HERE]
A: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: 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.
Q: [YOUR QUESTION HERE]
A:Strengths
优势
- Significant accuracy improvements on reasoning tasks
- Interpretable intermediate steps
- Works well with large models (>100B parameters)
- 显著提升推理任务的准确率
- 中间步骤可解释
- 在大参数模型(>100B)上表现良好
Limitations
局限性
- Requires crafting good exemplars
- Less effective on smaller models
- Can still make calculation errors
- 需要精心设计优质示例
- 在小模型上效果较差
- 仍可能出现计算错误
2. Zero-shot Chain-of-Thought
2. 零样本Chain-of-Thought(Zero-shot Chain-of-Thought)
Paper: "Large Language Models are Zero-Shot Reasoners" (Kojima et al., 2022)
Citations: 5,985+
论文: "Large Language Models are Zero-Shot Reasoners" (Kojima et al., 2022)
引用量: 5,985+
When to Use
适用场景
- No exemplars available
- Quick reasoning needed
- General-purpose reasoning across task types
- Prototyping before creating few-shot examples
- 无可用示例
- 需要快速推理
- 跨任务类型的通用推理
- 创建少样本示例前的原型验证
How It Works
工作原理
Simply append "Let's think step by step" (or similar phrase) to the prompt. This triggers the model to generate reasoning steps without any examples.
只需在提示末尾添加“Let's think step by step”(或类似表述)。无需任何示例即可触发模型生成推理步骤。
Prompt Template
提示模板
Q: A juggler can juggle 16 balls. Half of the balls are golf balls, and half of the golf balls are blue. How many blue golf balls are there?
Let's think step by step.Alternative trigger phrases:
- "Let's work this out step by step to be sure we have the right answer."
- "Let's break this down."
- "Let's approach this systematically."
- "First, let me understand the problem..."
Q: A juggler can juggle 16 balls. Half of the balls are golf balls, and half of the golf balls are blue. How many blue golf balls are there?
Let's think step by step.替代触发短语:
- "Let's work this out step by step to be sure we have the right answer."
- "Let's break this down."
- "Let's approach this systematically."
- "First, let me understand the problem..."
Two-Stage Approach (More Robust)
两阶段方法(更稳健)
Stage 1 - Reasoning Extraction:
Q: [QUESTION]
A: Let's think step by step.Stage 2 - Answer Extraction:
[REASONING FROM STAGE 1]
Therefore, the answer is阶段1 - 推理提取:
Q: [QUESTION]
A: Let's think step by step.阶段2 - 答案提取:
[REASONING FROM STAGE 1]
Therefore, the answer isStrengths
优势
- No exemplar crafting required
- Generalizes across task types
- Simple to implement
- 无需创建示例
- 可跨任务类型泛化
- 实现简单
Limitations
局限性
- Less effective than few-shot CoT
- Can produce verbose or irrelevant reasoning
- Sensitive to exact phrasing
- 效果不如少样本CoT
- 可能产生冗长或无关的推理
- 对措辞敏感
3. Self-Consistency
3. Self-Consistency(自一致性)
Paper: "Self-Consistency Improves Chain of Thought Reasoning in Language Models" (Wang et al., 2022)
Citations: 5,379+
论文: "Self-Consistency Improves Chain of Thought Reasoning in Language Models" (Wang et al., 2022)
引用量: 5,379+
When to Use
适用场景
- High-stakes decisions requiring confidence
- Problems with multiple valid reasoning paths
- When you need to reduce variance in outputs
- Verification of reasoning correctness
- 需要可信度的高风险决策
- 存在多条有效推理路径的问题
- 需要降低输出方差时
- 验证推理正确性
How It Works
工作原理
Sample multiple diverse reasoning paths, then select the most consistent answer via majority voting. The intuition: correct answers can be reached through multiple reasoning paths.
采样多条不同的推理路径,然后通过多数投票选择最一致的答案。核心逻辑:正确答案可通过多条推理路径得出。
Prompt Template
提示模板
[Use any CoT prompt - zero-shot or few-shot]
[Generate N samples with temperature > 0]
[Extract final answers from each sample]
[Return the most frequent answer (majority vote)][使用任意CoT提示——零样本或少样本]
[生成N个temperature>0的样本]
[从每个样本中提取最终答案]
[返回出现频率最高的答案(多数投票)]Implementation Example
实现示例
python
def self_consistency(prompt, n_samples=5, temperature=0.7):
answers = []
for _ in range(n_samples):
response = llm.generate(prompt, temperature=temperature)
answer = extract_answer(response)
answers.append(answer)
# Majority vote
return Counter(answers).most_common(1)[0][0]python
def self_consistency(prompt, n_samples=5, temperature=0.7):
answers = []
for _ in range(n_samples):
response = llm.generate(prompt, temperature=temperature)
answer = extract_answer(response)
answers.append(answer)
# Majority vote
return Counter(answers).most_common(1)[0][0]Strengths
优势
- Significant accuracy boost over single-path CoT
- Provides confidence measure (agreement level)
- Task-agnostic improvement
- 比单路径CoT显著提升准确率
- 提供可信度衡量标准(一致程度)
- 任务无关的性能提升
Limitations
局限性
- Higher computational cost (N times more generations)
- Requires extractable discrete answers
- Diminishing returns beyond ~10-20 samples
- 计算成本更高(生成次数是N倍)
- 需要可提取的离散答案
- 样本数超过10-20后收益递减
4. Tree of Thoughts (ToT)
4. Tree of Thoughts (ToT)(思维树)
Paper: "Tree of Thoughts: Deliberate Problem Solving with Large Language Models" (Yao et al., 2023)
Citations: 3,026+
论文: "Tree of Thoughts: Deliberate Problem Solving with Large Language Models" (Yao et al., 2023)
引用量: 3,026+
When to Use
适用场景
- Complex problems requiring exploration/backtracking
- Tasks where initial decisions are pivotal
- Creative problem-solving (writing, puzzles)
- When CoT alone achieves <50% accuracy
- 需要探索/回溯的复杂问题
- 初始决策至关重要的任务
- 创造性问题解决(写作、谜题)
- 单独使用CoT准确率<50%的任务
How It Works
工作原理
Generalize CoT to a tree structure where each node is a "thought" (coherent language unit). Uses search algorithms (BFS/DFS) with self-evaluation to explore and select promising reasoning paths.
将CoT泛化为树结构,每个节点是一个“思维”(连贯的语言单元)。使用搜索算法(BFS/DFS)结合自评估来探索和选择有前景的推理路径。
Prompt Template
提示模板
Thought Generation:
Given the current state:
[STATE]
Generate 3-5 possible next steps to solve this problem.State Evaluation:
Evaluate if the following partial solution is:
- "sure" (definitely leads to solution)
- "maybe" (could potentially work)
- "impossible" (cannot lead to solution)
Partial solution:
[THOUGHTS SO FAR]BFS/DFS Search:
python
def tree_of_thoughts(problem, max_depth=3, beam_width=3):
queue = [(problem, [])] # (state, thought_path)
while queue:
state, path = queue.pop(0)
if is_solved(state):
return path
# Generate candidate thoughts
thoughts = generate_thoughts(state, k=5)
# Evaluate and keep top-k
evaluated = [(t, evaluate(state, t)) for t in thoughts]
top_k = sorted(evaluated, key=lambda x: x[1])[:beam_width]
for thought, score in top_k:
if score != "impossible":
new_state = apply_thought(state, thought)
queue.append((new_state, path + [thought]))
return None思维生成:
Given the current state:
[STATE]
Generate 3-5 possible next steps to solve this problem.状态评估:
Evaluate if the following partial solution is:
- "sure" (definitely leads to solution)
- "maybe" (could potentially work)
- "impossible" (cannot lead to solution)
Partial solution:
[THOUGHTS SO FAR]BFS/DFS搜索:
python
def tree_of_thoughts(problem, max_depth=3, beam_width=3):
queue = [(problem, [])] # (state, thought_path)
while queue:
state, path = queue.pop(0)
if is_solved(state):
return path
# Generate candidate thoughts
thoughts = generate_thoughts(state, k=5)
# Evaluate and keep top-k
evaluated = [(t, evaluate(state, t)) for t in thoughts]
top_k = sorted(evaluated, key=lambda x: x[1])[:beam_width]
for thought, score in top_k:
if score != "impossible":
new_state = apply_thought(state, thought)
queue.append((new_state, path + [thought]))
return NoneExample: Game of 24
示例:24点游戏
Problem: Use 4, 9, 10, 13 to get 24 (use +, -, *, / and each number once)
Thought 1: 13 - 9 = 4 (Now have: 4, 4, 10)
Evaluation: "maybe" - have two 4s and 10, could work
Thought 2: 10 - 4 = 6 (Now have: 4, 6, 13)
Evaluation: "maybe" - 4 * 6 = 24, need to use 13
Thought 3: 4 + 9 = 13 (Now have: 10, 13, 13)
Evaluation: "impossible" - no way to get 24 from theseProblem: Use 4, 9, 10, 13 to get 24 (use +, -, *, / and each number once)
Thought 1: 13 - 9 = 4 (Now have: 4, 4, 10)
Evaluation: "maybe" - have two 4s and 10, could work
Thought 2: 10 - 4 = 6 (Now have: 4, 6, 13)
Evaluation: "maybe" - 4 * 6 = 24, need to use 13
Thought 3: 4 + 9 = 13 (Now have: 10, 13, 13)
Evaluation: "impossible" - no way to get 24 from theseStrengths
优势
- Dramatically improves performance on hard tasks (4% → 74% on Game of 24)
- Enables backtracking and exploration
- Self-evaluation catches errors early
- 大幅提升困难任务的性能(24点游戏从4%→74%)
- 支持回溯和探索
- 自评估可提前发现错误
Limitations
局限性
- Significantly higher computational cost
- Requires task-specific thought decomposition
- Complex to implement
- 计算成本显著更高
- 需要任务特定的思维分解
- 实现复杂
5. Least-to-Most Prompting
5. Least-to-Most Prompting(由易到难提示法)
Paper: "Least-to-Most Prompting Enables Complex Reasoning in Large Language Models" (Zhou et al., 2022)
Citations: 1,466+
论文: "Least-to-Most Prompting Enables Complex Reasoning in Large Language Models" (Zhou et al., 2022)
引用量: 1,466+
When to Use
适用场景
- Problems harder than your exemplars
- Compositional generalization tasks
- Multi-step problems with clear subproblems
- Symbol manipulation and SCAN-like tasks
- 比现有示例更难的问题
- 组合泛化任务
- 包含明确子问题的多步骤问题
- 符号操作和类SCAN任务
How It Works
工作原理
Two-stage process:
- Decomposition: Break complex problem into simpler subproblems
- Sequential Solving: Solve subproblems in order, using previous answers
分为两个阶段:
- 分解: 将复杂问题拆分为更简单的子问题
- 顺序求解: 按顺序解决子问题,利用之前的答案
Prompt Template
提示模板
Stage 1: Decomposition
Q: Four years ago, Kody was only half as old as Mohamed. If Mohamed is currently twice as old as 30 years old, how old is Kody?
To solve "Four years ago, Kody was only half as old as Mohamed. If Mohamed is currently twice as old as 30 years old, how old is Kody?", we need to first solve:
- "If Mohamed is currently twice as old as 30 years old, how old is Mohamed?"
Then we need to solve:
- "Four years ago, Kody was only half as old as Mohamed. How old is Kody?"Stage 2: Sequential Solving
Q: If Mohamed is currently twice as old as 30 years old, how old is Mohamed?
A: Mohamed is twice as old as 30, so Mohamed is 30 * 2 = 60 years old.
Q: Four years ago, Kody was only half as old as Mohamed. Mohamed is 60 years old. How old is Kody?
A: Four years ago, Mohamed was 60 - 4 = 56 years old. Kody was half as old, so Kody was 56 / 2 = 28 years old four years ago. Therefore, Kody is currently 28 + 4 = 32 years old.
The answer is 32.阶段1: 分解
Q: Four years ago, Kody was only half as old as Mohamed. If Mohamed is currently twice as old as 30 years old, how old is Kody?
To solve "Four years ago, Kody was only half as old as Mohamed. If Mohamed is currently twice as old as 30 years old, how old is Kody?", we need to first solve:
- "If Mohamed is currently twice as old as 30 years old, how old is Mohamed?"
Then we need to solve:
- "Four years ago, Kody was only half as old as Mohamed. How old is Kody?"阶段2: 顺序求解
Q: If Mohamed is currently twice as old as 30 years old, how old is Mohamed?
A: Mohamed is twice as old as 30, so Mohamed is 30 * 2 = 60 years old.
Q: Four years ago, Kody was only half as old as Mohamed. Mohamed is 60 years old. How old is Kody?
A: Four years ago, Mohamed was 60 - 4 = 56 years old. Kody was half as old, so Kody was 56 / 2 = 28 years old four years ago. Therefore, Kody is currently 28 + 4 = 32 years old.
The answer is 32.Strengths
优势
- Excellent at generalizing to harder problems
- Works well on compositional tasks
- Explicit problem decomposition aids interpretability
- 擅长泛化到更难的问题
- 在组合任务上表现良好
- 明确的问题分解提升可解释性
Limitations
局限性
- Requires two-stage prompting
- Decomposition step can fail on novel structures
- More complex setup than single-stage CoT
- 需要两阶段提示
- 分解步骤在遇到新颖结构时可能失败
- 比单阶段CoT设置更复杂
6. ReAct (Reasoning + Acting)
6. ReAct(Reasoning + Acting,推理+行动)
Paper: "ReAct: Synergizing Reasoning and Acting in Language Models" (Yao et al., 2022)
Citations: 5,012+
论文: "ReAct: Synergizing Reasoning and Acting in Language Models" (Yao et al., 2022)
引用量: 5,012+
When to Use
适用场景
- Tasks requiring external information (search, APIs)
- Interactive decision-making environments
- Multi-hop question answering
- When pure reasoning leads to hallucination
- 需要外部信息的任务(搜索、API)
- 交互式决策环境
- 多跳问答
- 纯推理导致幻觉的场景
How It Works
工作原理
Interleave reasoning traces ("Thought") with actions ("Action") and observations ("Observation"). Reasoning helps plan actions; actions provide new information for reasoning.
交替进行推理轨迹("Thought")、行动("Action")和观察("Observation")。推理帮助规划行动;行动为推理提供新信息。
Prompt Template
提示模板
Question: What is the elevation range for the area that the eastern sector of the Colorado orogeny extends into?
Thought 1: I need to search Colorado orogeny, find the area that the eastern sector extends into, then find the elevation range of that area.
Action 1: Search[Colorado orogeny]
Observation 1: The Colorado orogeny was an episode of mountain building (an orogeny) in Colorado and surrounding areas.
Thought 2: It does not mention the eastern sector. So I need to look up eastern sector.
Action 2: Lookup[eastern sector]
Observation 2: The eastern sector extends into the High Plains.
Thought 3: The eastern sector extends into the High Plains. I need to search High Plains and find its elevation range.
Action 3: Search[High Plains]
Observation 3: High Plains refers to one of two distinct land regions: High Plains (United States)...
Thought 4: I need to search High Plains (United States).
Action 4: Search[High Plains (United States)]
Observation 4: The High Plains are a subregion of the Great Plains... elevation of around 1,800 to 7,000 ft (550 to 2,130 m).
Thought 5: The elevation range is 1,800 to 7,000 ft.
Action 5: Finish[1,800 to 7,000 ft]Question: What is the elevation range for the area that the eastern sector of the Colorado orogeny extends into?
Thought 1: I need to search Colorado orogeny, find the area that the eastern sector extends into, then find the elevation range of that area.
Action 1: Search[Colorado orogeny]
Observation 1: The Colorado orogeny was an episode of mountain building (an orogeny) in Colorado and surrounding areas.
Thought 2: It does not mention the eastern sector. So I need to look up eastern sector.
Action 2: Lookup[eastern sector]
Observation 2: The eastern sector extends into the High Plains.
Thought 3: The eastern sector extends into the High Plains. I need to search High Plains and find its elevation range.
Action 3: Search[High Plains]
Observation 3: High Plains refers to one of two distinct land regions: High Plains (United States)...
Thought 4: I need to search High Plains (United States).
Action 4: Search[High Plains (United States)]
Observation 4: The High Plains are a subregion of the Great Plains... elevation of around 1,800 to 7,000 ft (550 to 2,130 m).
Thought 5: The elevation range is 1,800 to 7,000 ft.
Action 5: Finish[1,800 to 7,000 ft]Action Types
行动类型
- - Search for information
Search[query] - - Look up keyword in current context
Lookup[keyword] - - Return final answer
Finish[answer]
- - 搜索信息
Search[query] - - 在当前上下文中查找关键词
Lookup[keyword] - - 返回最终答案
Finish[answer]
Strengths
优势
- Reduces hallucination by grounding in external knowledge
- Interpretable action traces
- Handles exceptions through adaptive reasoning
- 通过锚定外部知识减少幻觉
- 行动轨迹可解释
- 通过自适应推理处理异常情况
Limitations
局限性
- Requires integration with external tools
- More complex orchestration
- Action space must be defined
- 需要与外部工具集成
- 编排更复杂
- 必须定义行动空间
7. PAL (Program-Aided Language Models)
7. PAL(Program-Aided Language Models,程序辅助语言模型)
Paper: "PAL: Program-aided Language Models" (Gao et al., 2022)
Citations: 608+
论文: "PAL: Program-aided Language Models" (Gao et al., 2022)
引用量: 608+
When to Use
适用场景
- Mathematical/arithmetic reasoning
- Problems requiring precise computation
- Symbolic manipulation
- When CoT makes calculation errors
- 数学/算术推理
- 需要精确计算的问题
- 符号操作
- CoT出现计算错误的场景
How It Works
工作原理
Generate code (typically Python) instead of natural language reasoning. Execute the code to get the answer. The LLM handles decomposition; the interpreter handles computation.
生成代码(通常是Python)而非自然语言推理。执行代码得到答案。LLM负责分解问题;解释器负责计算。
Prompt Template
提示模板
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?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?solution in Python:
solution in Python:
def solution():
"""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?"""
tennis_balls_initial = 5
bought_cans = 2
tennis_balls_per_can = 3
tennis_balls_bought = bought_cans * tennis_balls_per_can
tennis_balls_total = tennis_balls_initial + tennis_balls_bought
return tennis_balls_total
Q: The bakers at the Beverly Hills Bakery baked 200 loaves of bread on Monday morning. They sold 93 loaves in the morning and 39 loaves in the afternoon. A grocery store returned 6 unsold loaves. How many loaves of bread did they have left?
def solution():
"""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?"""
tennis_balls_initial = 5
bought_cans = 2
tennis_balls_per_can = 3
tennis_balls_bought = bought_cans * tennis_balls_per_can
tennis_balls_total = tennis_balls_initial + tennis_balls_bought
return tennis_balls_total
Q: The bakers at the Beverly Hills Bakery baked 200 loaves of bread on Monday morning. They sold 93 loaves in the morning and 39 loaves in the afternoon. A grocery store returned 6 unsold loaves. How many loaves of bread did they have left?
solution in Python:
solution in Python:
def solution():
"""The bakers baked 200 loaves. They sold 93 in morning, 39 in afternoon. A store returned 6. How many left?"""
loaves_baked = 200
loaves_sold_morning = 93
loaves_sold_afternoon = 39
loaves_returned = 6
loaves_left = loaves_baked - loaves_sold_morning - loaves_sold_afternoon + loaves_returned
return loaves_left
undefineddef solution():
"""The bakers baked 200 loaves. They sold 93 in morning, 39 in afternoon. A store returned 6. How many left?"""
loaves_baked = 200
loaves_sold_morning = 93
loaves_sold_afternoon = 39
loaves_returned = 6
loaves_left = loaves_baked - loaves_sold_morning - loaves_sold_afternoon + loaves_returned
return loaves_left
undefinedStrengths
优势
- Eliminates arithmetic errors
- Clear variable naming aids interpretability
- Leverages code execution for verification
- 消除算术错误
- 清晰的变量命名提升可解释性
- 利用代码执行进行验证
Limitations
局限性
- Requires code interpreter
- Not suitable for non-computational reasoning
- Model must generate syntactically correct code
- 需要代码解释器
- 不适用于非计算类推理
- 模型必须生成语法正确的代码
8. Auto-CoT
8. Auto-CoT(自动Chain-of-Thought)
Paper: "Automatic Chain of Thought Prompting in Large Language Models" (Zhang et al., 2022)
Citations: 838+
论文: "Automatic Chain of Thought Prompting in Large Language Models" (Zhang et al., 2022)
引用量: 838+
When to Use
适用场景
- No manually crafted exemplars available
- Want to automate few-shot CoT setup
- Scaling CoT to many tasks
- When zero-shot CoT isn't sufficient
- 无手动设计的示例
- 想要自动化少样本CoT设置
- 将CoT扩展到多个任务
- 零样本CoT效果不足时
How It Works
工作原理
- Cluster questions by diversity
- Use Zero-shot CoT to generate reasoning chains for representative questions
- Use these auto-generated chains as few-shot exemplars
- 按多样性对问题聚类
- 使用Zero-shot CoT为代表性问题生成推理链
- 将这些自动生成的链用作少样本示例
Prompt Template
提示模板
Step 1: Generate diverse demonstrations
python
undefined步骤1: 生成多样化演示示例
python
undefinedCluster questions
Cluster questions
clusters = cluster_questions(all_questions, k=8)
clusters = cluster_questions(all_questions, k=8)
For each cluster, pick representative and generate CoT
For each cluster, pick representative and generate CoT
demonstrations = []
for cluster in clusters:
question = select_representative(cluster)
reasoning = zero_shot_cot(question) # "Let's think step by step"
demonstrations.append((question, reasoning))
**Step 2: Use as few-shot exemplars**Q: [Demo question 1]
A: Let's think step by step. [Generated reasoning 1]
Q: [Demo question 2]
A: Let's think step by step. [Generated reasoning 2]
...
Q: [New question]
A: Let's think step by step.
undefineddemonstrations = []
for cluster in clusters:
question = select_representative(cluster)
reasoning = zero_shot_cot(question) # "Let's think step by step"
demonstrations.append((question, reasoning))
**步骤2: 用作少样本示例**Q: [Demo question 1]
A: Let's think step by step. [Generated reasoning 1]
Q: [Demo question 2]
A: Let's think step by step. [Generated reasoning 2]
...
Q: [New question]
A: Let's think step by step.
undefinedStrengths
优势
- No manual exemplar creation
- Diversity sampling improves robustness
- Matches manual CoT performance
- 无需手动创建示例
- 多样性采样提升鲁棒性
- 性能与手动CoT相当
Limitations
局限性
- Quality depends on zero-shot CoT quality
- Clustering requires similarity metric
- Some generated chains contain errors
- 质量依赖零样本CoT的质量
- 聚类需要相似性度量
- 部分生成的链存在错误
9. Reflexion
9. Reflexion(反思)
Paper: "Reflexion: Language Agents with Verbal Reinforcement Learning" (Shinn et al., 2023)
Citations: 2,179+
论文: "Reflexion: Language Agents with Verbal Reinforcement Learning" (Shinn et al., 2023)
引用量: 2,179+
When to Use
适用场景
- Iterative improvement over multiple attempts
- Learning from errors without fine-tuning
- Complex coding or decision-making tasks
- When single-pass reasoning is insufficient
- 多次尝试后的迭代改进
- 无需微调即可从错误中学习
- 复杂编码或决策任务
- 单次推理不足的场景
How It Works
工作原理
After task failure, the agent generates a verbal "reflection" analyzing what went wrong. This reflection is stored in memory and used in subsequent attempts to avoid repeating mistakes.
任务失败后,智能体生成口头“反思”分析错误原因。该反思被存储在记忆中,用于后续尝试以避免重复错误。
Prompt Template
提示模板
Initial Attempt:
Task: [TASK DESCRIPTION]
Thought: [REASONING]
Action: [ACTION]
...
Result: [FAILURE/PARTIAL SUCCESS]Reflection:
The previous attempt failed because:
1. [SPECIFIC ERROR ANALYSIS]
2. [WHAT SHOULD HAVE BEEN DONE]
3. [KEY INSIGHT FOR NEXT ATTEMPT]
Reflection: In the next attempt, I should...Subsequent Attempt (with memory):
Task: [TASK DESCRIPTION]
Previous reflections:
- [REFLECTION 1]
- [REFLECTION 2]
Using these insights, I will now attempt the task again.
Thought: [IMPROVED REASONING]
Action: [BETTER ACTION]首次尝试:
Task: [TASK DESCRIPTION]
Thought: [REASONING]
Action: [ACTION]
...
Result: [FAILURE/PARTIAL SUCCESS]反思:
The previous attempt failed because:
1. [SPECIFIC ERROR ANALYSIS]
2. [WHAT SHOULD HAVE BEEN DONE]
3. [KEY INSIGHT FOR NEXT ATTEMPT]
Reflection: In the next attempt, I should...后续尝试(带记忆):
Task: [TASK DESCRIPTION]
Previous reflections:
- [REFLECTION 1]
- [REFLECTION 2]
Using these insights, I will now attempt the task again.
Thought: [IMPROVED REASONING]
Action: [BETTER ACTION]Example: Code Generation
示例:代码生成
Task: Write a function to find the longest palindromic substring.
Attempt 1: [CODE WITH BUG]
Test Result: Failed on "babad" - expected "bab" or "aba", got "b"
Reflection: My solution only checked single characters. I need to:
1. Consider substrings of all lengths
2. Use expand-around-center technique for efficiency
3. Track both start position and maximum length
Attempt 2: [IMPROVED CODE USING REFLECTION]
Test Result: Passed all testsTask: Write a function to find the longest palindromic substring.
Attempt 1: [CODE WITH BUG]
Test Result: Failed on "babad" - expected "bab" or "aba", got "b"
Reflection: My solution only checked single characters. I need to:
1. Consider substrings of all lengths
2. Use expand-around-center technique for efficiency
3. Track both start position and maximum length
Attempt 2: [IMPROVED CODE USING REFLECTION]
Test Result: Passed all testsStrengths
优势
- Learns from errors without weight updates
- Achieves 91% on HumanEval (surpassing GPT-4's 80%)
- Builds episodic memory of insights
- 无需权重更新即可从错误中学习
- 在HumanEval上达到91%(超过GPT-4的80%)
- 构建洞察力的情景记忆
Limitations
局限性
- Requires multiple attempts
- Memory management for long sessions
- Quality of reflection affects improvement
- 需要多次尝试
- 长会话的内存管理
- 反思质量影响改进效果
Decision Matrix: Which Technique to Use
决策矩阵:选择哪种技术
Need Examples?
/ \
No Yes
| |
Zero-shot CoT Few-shot CoT
| |
Need higher accuracy? Need computation?
/ \ |
Yes No PAL
| |
Self-Consistency Done with CoT
|
Still not enough?
/ \
Yes No
| |
Problem decomposable? Done
/ \
Yes No
| |
Least-to-Most Need exploration?
/ \
Yes No
| |
Tree of Thoughts Need external info?
/ \
Yes No
| |
ReAct Need iteration?
/ \
Yes No
| |
Reflexion Use CoT Need Examples?
/ \
No Yes
| |
Zero-shot CoT Few-shot CoT
| |
Need higher accuracy? Need computation?
/ \ |
Yes No PAL
| |
Self-Consistency Done with CoT
|
Still not enough?
/ \
Yes No
| |
Problem decomposable? Done
/ \
Yes No
| |
Least-to-Most Need exploration?
/ \
Yes No
| |
Tree of Thoughts Need external info?
/ \
Yes No
| |
ReAct Need iteration?
/ \
Yes No
| |
Reflexion Use CoTBest Practices
最佳实践
1. Start Simple
1. 从简单开始
Begin with Zero-shot CoT ("Let's think step by step"), then progress to more complex techniques if needed.
先使用Zero-shot CoT(“Let's think step by step”),如果需要再使用更复杂的技术。
2. Match Technique to Task
2. 技术与任务匹配
- Math/Logic: CoT, PAL, Self-Consistency
- Multi-hop QA: ReAct, Least-to-Most
- Creative/Puzzles: Tree of Thoughts
- Iterative Tasks: Reflexion
- 数学/逻辑: CoT, PAL, Self-Consistency
- 多跳问答: ReAct, Least-to-Most
- 创意/谜题: Tree of Thoughts
- 迭代任务: Reflexion
3. Combine Techniques
3. 组合技术
Techniques are often complementary:
- ReAct + Self-Consistency for robust factual answers
- ToT + PAL for complex computational exploration
- Least-to-Most + Reflexion for hard multi-step problems
技术通常互补:
- ReAct + Self-Consistency 实现稳健的事实性答案
- ToT + PAL 处理复杂计算探索
- Least-to-Most + Reflexion 解决困难的多步骤问题
4. Prompt Engineering Tips
4. 提示工程技巧
- Use clear step markers ("Step 1:", "First,", etc.)
- Include diverse exemplars covering edge cases
- Format consistently across examples
- Add verification steps ("Let me verify...")
- 使用清晰的步骤标记(“Step 1:”, “First,”等)
- 包含覆盖边缘情况的多样化示例
- 示例格式保持一致
- 添加验证步骤(“Let me verify...”)
Common Mistakes
常见错误
| Mistake | Why It's Wrong | Fix |
|---|---|---|
| Using CoT for simple lookups | Adds unnecessary tokens and latency | Reserve for multi-step reasoning |
| Too few samples in Self-Consistency | Majority voting needs adequate samples | Use 5-10 samples minimum |
| Generic "think step by step" without checking output | Model may produce irrelevant reasoning | Validate reasoning quality, not just presence |
| Mixing techniques without understanding trade-offs | Computational cost without benefit | Understand when each technique adds value |
| Using PAL without code interpreter | Code generation is useless without execution | Ensure execution environment available |
| Not testing exemplar quality in few-shot CoT | Poor exemplars lead to poor reasoning | Validate exemplars solve problems correctly |
| Applying Tree of Thoughts to linear problems | Massive overhead for no benefit | Use ToT only when exploration needed |
| 错误 | 原因 | 修复方案 |
|---|---|---|
| 对简单查询使用CoT | 增加不必要的token和延迟 | 仅在多步骤推理时使用 |
| Self-Consistency样本过少 | 多数投票需要足够样本 | 至少使用5-10个样本 |
| 仅添加“think step by step”而不检查输出 | 模型可能生成无关推理 | 验证推理质量,而非仅检查是否存在推理 |
| 不理解权衡就混合技术 | 增加计算成本却无收益 | 了解每种技术的适用场景 |
| 无代码解释器时使用PAL | 代码生成无法执行 | 确保有可用的执行环境 |
| 不验证少样本CoT的示例质量 | 劣质示例导致推理质量差 | 验证示例能否正确解决问题 |
| 对线性问题使用Tree of Thoughts | 大量开销却无收益 | 仅在需要探索时使用ToT |
References
参考文献
-
Wei, J. et al. (2022). "Chain of Thought Prompting Elicits Reasoning in Large Language Models." arXiv:2201.11903
-
Kojima, T. et al. (2022). "Large Language Models are Zero-Shot Reasoners." arXiv:2205.11916
-
Wang, X. et al. (2022). "Self-Consistency Improves Chain of Thought Reasoning in Language Models." arXiv:2203.11171
-
Yao, S. et al. (2023). "Tree of Thoughts: Deliberate Problem Solving with Large Language Models." arXiv:2305.10601
-
Zhou, D. et al. (2022). "Least-to-Most Prompting Enables Complex Reasoning in Large Language Models." arXiv:2205.10625
-
Yao, S. et al. (2022). "ReAct: Synergizing Reasoning and Acting in Language Models." arXiv:2210.03629
-
Gao, L. et al. (2022). "PAL: Program-aided Language Models." arXiv:2211.10435
-
Zhang, Z. et al. (2022). "Automatic Chain of Thought Prompting in Large Language Models." arXiv:2210.03493
-
Shinn, N. et al. (2023). "Reflexion: Language Agents with Verbal Reinforcement Learning." arXiv:2303.11366
-
Wei, J. et al. (2022). "Chain of Thought Prompting Elicits Reasoning in Large Language Models." arXiv:2201.11903
-
Kojima, T. et al. (2022). "Large Language Models are Zero-Shot Reasoners." arXiv:2205.11916
-
Wang, X. et al. (2022). "Self-Consistency Improves Chain of Thought Reasoning in Language Models." arXiv:2203.11171
-
Yao, S. et al. (2023). "Tree of Thoughts: Deliberate Problem Solving with Large Language Models." arXiv:2305.10601
-
Zhou, D. et al. (2022). "Least-to-Most Prompting Enables Complex Reasoning in Large Language Models." arXiv:2205.10625
-
Yao, S. et al. (2022). "ReAct: Synergizing Reasoning and Acting in Language Models." arXiv:2210.03629
-
Gao, L. et al. (2022). "PAL: Program-aided Language Models." arXiv:2211.10435
-
Zhang, Z. et al. (2022). "Automatic Chain of Thought Prompting in Large Language Models." arXiv:2210.03493
-
Shinn, N. et al. (2023). "Reflexion: Language Agents with Verbal Reinforcement Learning." arXiv:2303.11366