logo
P
Prompt Master

Prompt 大师

掌握和 AI 对话的艺术

Chain-of-Thought (CoT)

通过中间推理步骤提升 reasoning tasks 的稳定性

#链式思考(CoT)提示

COT

图片来源:Wei 等人(2022)

Wei 等人(2022) 中引入的链式思考(CoT)提示通过中间推理步骤实现了复杂的推理能力。您可以将其与少样本提示相结合,以获得更好的结果,以便在回答之前进行推理的更复杂的任务。

提示:

code
The odd numbers in this group add up to an even number: 4, 8, 9, 15, 12, 2, 1. A: Adding all the odd numbers (9, 15, 1) gives 25. The answer is False. The odd numbers in this group add up to an even number: 17, 10, 19, 4, 8, 12, 24. A: Adding all the odd numbers (17, 19) gives 36. The answer is True. The odd numbers in this group add up to an even number: 16, 11, 14, 4, 8, 13, 24. A: Adding all the odd numbers (11, 13) gives 24. The answer is True. The odd numbers in this group add up to an even number: 17, 9, 10, 12, 13, 4, 2. A: Adding all the odd numbers (17, 9, 13) gives 39. The answer is False. The odd numbers in this group add up to an even number: 15, 32, 5, 13, 82, 7, 1. A:

输出:

code
Adding all the odd numbers (15, 5, 13, 7, 1) gives 41. The answer is False.

哇!我们可以看到在提供推理步骤时得到了完美的结果。实际上,我们可以通过提供更少的示例来解决此任务,即仅一个示例似乎就足够了:

提示:

code
The odd numbers in this group add up to an even number: 4, 8, 9, 15, 12, 2, 1. A: Adding all the odd numbers (9, 15, 1) gives 25. The answer is False. The odd numbers in this group add up to an even number: 15, 32, 5, 13, 82, 7, 1. A:

输出:

code
Adding all the odd numbers (15, 5, 13, 7, 1) gives 41. The answer is False.

请记住,作者声称这是足够大的语言模型才会出现的新兴能力。

#零样本 COT 提示

Zero-shot COT

图片来源:Kojima 等人(2022)

最近提出的一个新想法是 零样本 CoT( Kojima 等人,2022 年),它基本上涉及将“让我们逐步思考”添加到原始提示中。让我们尝试一个简单的问题,看看模型的表现如何:

提示:

code
I went to the market and bought 10 apples. I gave 2 apples to my neighbor and 2 apples to the repairman. Then I went and bought 5 more apples and ate 1. How many apples do I have left?

输出:

code
11 apples

答案是不正确的!现在让我们尝试使用特殊提示。

提示:

code
I went to the market and bought 10 apples. I gave 2 apples to my neighbor and 2 apples to the repairman. Then I went and bought 5 more apples and ate 1. How many apples do I have left? Let's think step by step.

输出:

code
First, you start with 10 apples. You gave 2 apples to your neighbor and 2 apples to the repairman, so you have 6 apples left. Then you bought 5 more apples, so now you have 11 apples. Finally, you ate 1 apple, so you have 10 apples left.

令人印象深刻的是,这个简单的提示在这个任务中非常有效。这在您没有太多示例可用于提示时特别有用。

#自动思维链(Auto-CoT)

当使用思维链提示时,这个过程需要手工制作有效且多样化的例子。这种手动工作可能会导致次优解决方案。Zhang et al. (2022) 提出了一种消除人工的方法,即利用 LLMs “让我们一步一步地思考” 提示来生成一个接一个的推理链。这种自动过程仍然可能在生成的链中出现错误。为了减轻错误的影响,演示的多样性很重要。这项工作提出了 Auto-CoT,它对具有多样性的问题进行采样,并生成推理链来构建演示。

Auto-CoT 主要由两个阶段组成:

  • 阶段 1:问题聚类:将给定问题划分为几个聚类
  • 阶段 2:演示抽样:从每组数组中选择一个具有代表性的问题,并使用带有简单启发式的 Zero-Shot-CoT 生成其推理链

简单的启发式方法可以是问题的长度(例如,60 个 tokens)和理由的步骤数(例如,5 个推理步骤)。这鼓励模型使用简单而准确的演示。

该过程如下图所示:

AUTOCOT

图片来源:Zhang 等人(2022)

Auto-CoT 的代码可在这里找到:Github

1v1免费职业咨询