趋近智
思维链 (CoT) 提示方法促使大型语言模型 (LLM) 生成分步推理 (inference),这项技术常用于提升复杂任务上的表现。然而,它生成的推理路径并非总是唯一或正确。如果多次运行相同的 CoT 提示,尤其是在温度(temperature)设置大于零的情况下,可能会得到不同的推理路径,从而导致潜在的不同最终答案。有些路径可能存在缺陷,而另一些则可能合理。如何能增加对最终答案的信心?
自洽性是一种高阶提示技巧,旨在解决这种变异性。它借鉴了思维链等方法,通过为同一问题生成多个推理路径,然后选择出现频率最高的答案作为最终结果。其背后的理念是,一个问题通常有多个有效的推理路径导向正确答案,而不正确的答案通常是通过更多样、一致性较低的逻辑缺陷得出的。
自洽性不依赖于单一的 CoT 输出,而是按以下方式运作:
temperature 参数 (parameter)设置为大于 0 的值(例如 0.5 或 0.7),以促进输出的多样性。可以将其想象成咨询几位独立工作的专家。如果他们中的大多数人得出相同的结论,即使是通过略微不同的方法,您也会对该结论更有信心。
让我们用一个简单的算术应用题来说明:
提示:
Q: John has 5 apples. He buys 3 more boxes of apples. Each box contains 4 apples. He then gives away 6 apples. How many apples does John have left? Show your reasoning step-by-step.
A:
现在,假设我们使用此提示并在 temperature=0.7 的设置下生成了 3 个不同的回应:
回应 1:
Step 1: Calculate the number of apples in the boxes. John buys 3 boxes * 4 apples/box = 12 apples.
Step 2: Calculate the total number of apples John has initially. John starts with 5 apples + 12 new apples = 17 apples.
Step 3: Calculate the final number of apples after giving some away. John has 17 apples - 6 apples = 11 apples.
The final answer is: 11
回应 2:
Step 1: John starts with 5 apples.
Step 2: He buys 3 boxes, and each has 4 apples, so that's 3 * 4 = 12 apples.
Step 3: His total apples become 5 + 12 = 17 apples.
Step 4: He gives away 6 apples, so he has 17 - 6 = 11 apples left.
Final Answer: 11
回应 3: (包含一个推理 (inference)错误)
Step 1: Calculate apples bought: 3 boxes * 4 apples = 12 apples.
Step 2: Add initial apples: 5 + 12 = 17 apples.
Step 3: Subtract apples given away: 17 - 6 = 10 apples. (Calculation error here)
So, John has 10 apples left.
The final answer is: 10
应用自洽性:
自洽性答案是 11。尽管其中一个路径包含错误,但生成路径间的共识指向了正确结果。
以下是该过程的视觉呈现:
一张图表展示了自洽性工作流程:一个单一的提示生成多个多样化的LLM推理路径。从每个路径中提取最终答案,并通过多数投票决定最一致的结果。
优点:
考量:
自洽性是一种强大的技术,当 LLM 推理输出的可靠性和准确性很重要,并且增加的计算成本可以接受时,它非常适用。它利用 LLM 的生成能力通过共识进行自我修正,使其成为构建更可靠 AI 应用的有价值工具。
简洁的语法。内置调试功能。从第一天起就可投入生产。
为 ApX 背后的 AI 系统而构建
这部分内容有帮助吗?
© 2026 ApX Machine Learning用心打造