---
title: "Program of Thoughts Prompting — 思维程序提示"
source: "https://systems-analysis.info/int/Program_of_Thoughts_Prompting_%E2%80%94_%E6%80%9D%E7%BB%B4%E7%A8%8B%E5%BA%8F%E6%8F%90%E7%A4%BA"
wiki: "systems-analysis.info/int"
article: "Program_of_Thoughts_Prompting_—_思维程序提示"
language: "zh"
categories:
  - "Category:Chinese"
  - "Category:Large language models"
  - "Category:Machine learning"
  - "Category:Prompt engineering"
revision_id: 5873
wiki_created_at: 2026-09-06T23:55:15Z
wiki_modified_at: 2026-09-06T23:55:15Z
downloaded_at: 2026-09-07T23:10:48Z
---

# Program of Thoughts Prompting — 思维程序提示

**Program of Thoughts Prompting** (**PoT**，英语意为“思维程序”) 是一种针对大型语言模型 (LLM)的提示工程方法，在该方法中，模型生成程序代码作为解决问题的中间步骤，而非生成文本解释<sup>[\[1\]](https://systems-analysis.info/int/Program_of_Thoughts_Prompting_%E2%80%94_%E6%80%9D%E7%BB%B4%E7%A8%8B%E5%BA%8F%E6%8F%90%E7%A4%BA#cite_note-pot_paper-1)</sup>。这种方法可以将逻辑推理与数学计算分离：语言模型以程序（例如，使用 Python）的形式构建解决方案，而计算则由外部的、确定性的代码解释器执行。

该方法由以**陈文虎** (*Wenhu Chen*) 为首的一组研究人员于2022年提出，主要针对数值或逻辑推理任务（如数学问题、金融计算），在这些任务中，像“思维链” (Chain-of-Thought) 这样的传统推理方法在计算精度方面遇到了困难<sup>[\[1\]](https://systems-analysis.info/int/Program_of_Thoughts_Prompting_%E2%80%94_%E6%80%9D%E7%BB%B4%E7%A8%8B%E5%BA%8F%E6%8F%90%E7%A4%BA#cite_note-pot_paper-1)</sup>。

## 前提与概念

### Chain-of-Thought 的局限性

PoT 方法是**思维链 (Chain-of-Thought, CoT)** 思想的延伸，CoT 此前是提升 LLM 逻辑推理能力的主要方法<sup>[\[2\]](https://systems-analysis.info/int/Program_of_Thoughts_Prompting_%E2%80%94_%E6%80%9D%E7%BB%B4%E7%A8%8B%E5%BA%8F%E6%8F%90%E7%A4%BA#cite_note-cot_paper-2)</sup>。在 CoT 方法中，模型以自然语言生成一系列中间步骤。尽管这种方法显著提高了推理质量，但它有一个根本性的局限：模型同时以文本形式执行逻辑和计算。这常常导致算术运算不准确、舍入误差和其他不精确问题，因为语言模型本质上不是精确的计算器。

### Program of Thoughts 的核心思想

PoT 的核心思想是将计算任务委托给外部系统（代码解释器），而只要求语言模型将解决方案规划形式化为可执行的程序<sup>[\[1\]](https://systems-analysis.info/int/Program_of_Thoughts_Prompting_%E2%80%94_%E6%80%9D%E7%BB%B4%E7%A8%8B%E5%BA%8F%E6%8F%90%E7%A4%BA#cite_note-pot_paper-1)</sup>。模型扮演的是“程序员”而非“计算器”的角色。

其工作流程如下：

1.  模型接收一个任务作为输入（例如，一个数学应用题）。
2.  它不生成文本推理，而是生成一个解决该任务的编程语言脚本（例如，**Python**）。
3.  生成的代码被传递给外部解释器执行。
4.  代码执行的结果即为最终答案。

因此，复杂且要求精确的计算（如处理大数、调用专门的库）不是由模型本身执行，而是由程序完成，这确保了确定性和高精度<sup>[\[3\]](https://systems-analysis.info/int/Program_of_Thoughts_Prompting_%E2%80%94_%E6%80%9D%E7%BB%B4%E7%A8%8B%E5%BA%8F%E6%8F%90%E7%A4%BA#cite_note-pot_ministry_ai-3)</sup>。

## 实现与库的使用

在 PoT 的实现中，LLM 生成正确且高效代码的能力是关键。该方法的作者使用了 **OpenAI Codex** 模型，该模型专门针对编程任务进行了训练。PoT 方法允许模型利用外部库，从而显著扩展了可解决问题的类别。例如，在解决符号数学问题时，模型可以生成使用 **SymPy** 库来解析求解方程的代码，这超出了纯语言方法的能力范围<sup>[\[1\]](https://systems-analysis.info/int/Program_of_Thoughts_Prompting_%E2%80%94_%E6%80%9D%E7%BB%B4%E7%A8%8B%E5%BA%8F%E6%8F%90%E7%A4%BA#cite_note-pot_paper-1)</sup>。

PoT 的提示可以以两种模式提供：

- **Few-shot**：在提示中包含若干“问题—解决方案程序”的示例对。
- **Zero-shot**：在提示中只提供描述任务的指令，不含示例。

即使在 *zero-shot* 模式下，由于模型需要生成明确的结构，PoT 也表现出很高的效率<sup>[\[4\]](https://systems-analysis.info/int/Program_of_Thoughts_Prompting_%E2%80%94_%E6%80%9D%E7%BB%B4%E7%A8%8B%E5%BA%8F%E6%8F%90%E7%A4%BA#cite_note-pot_learnprompting-4)</sup>。

## 结果与效果

PoT 方法在需要多步数值推理的任务上，解决方案的质量得到了显著提升。在原始论文中，它在八个数学和金融任务数据集上进行了测试，包括 **GSM8K**、**AQUA**、**SVAMP**、**FinQA** 等。

- **提高准确率**：在所有测试中，PoT 都优于基准的 CoT 方法。在正确解答的比例上，平均实现了约 **12%** 的相对提升。
  - 在流行的数学数据集 **GSM8K** 上，使用 PoT 的模型准确率达到了 **71.6%**，而使用 CoT 则为 **63.1%**。
  - 在金融任务中，提升更为显著：在 **FinQA** 数据集上，准确率从 **40.4%** (CoT) 提高到了 **64.5%** (PoT)<sup>[\[1\]](https://systems-analysis.info/int/Program_of_Thoughts_Prompting_%E2%80%94_%E6%80%9D%E7%BB%B4%E7%A8%8B%E5%BA%8F%E6%8F%90%E7%A4%BA#cite_note-pot_paper-1)</sup>。

<!-- -->

- **与自洽性 (Self-Consistency) 结合**：将 PoT 与**自洽性** (*self-consistency*) 方法结合，可以进一步提高其效果。在这种情况下，模型会生成多个独立的解决方案程序，最终答案根据这些程序的执行结果，通过“少数服从多数”的原则选出。结合 *self-consistency*，PoT 在论文发表时为所有测试的数学和金融基准测试创下了新的**最高水平** (*state-of-the-art*)<sup>[\[1\]](https://systems-analysis.info/int/Program_of_Thoughts_Prompting_%E2%80%94_%E6%80%9D%E7%BB%B4%E7%A8%8B%E5%BA%8F%E6%8F%90%E7%A4%BA#cite_note-pot_paper-1)</sup>。

## 优势与局限性

### 优势

- **计算精度**：这是最主要的优势。由外部解释器执行算术运算，消除了 LLM 固有的舍入误差和不精确问题。
- **可使用外部库**：模型可以调用强大的外部库（例如，用于符号计算、统计分析、日期处理），从而解决以前无法处理的任务。
- **可解释性与调试**：程序代码是解决方案逻辑的形式化和结构化表示，与自然语言推理相比，更易于验证和调试。
- **通用性**：该方法在 *few-shot* 和 *zero-shot* 模式下均有效，并适用于不同领域（数学、金融、科学）。

### 局限性

- **安全性**：在外部解释器上执行生成的代码会带来安全风险。理论上，模型可能生成恶意代码（例如，删除文件）。因此，PoT 的实际应用需要在沙箱 (*sandbox*) 环境中隔离执行，并对代码进行仔细过滤<sup>[\[4\]](https://systems-analysis.info/int/Program_of_Thoughts_Prompting_%E2%80%94_%E6%80%9D%E7%BB%B4%E7%A8%8B%E5%BA%8F%E6%8F%90%E7%A4%BA#cite_note-pot_learnprompting-4)</sup>。
- **适用范围有限**：该方法对于可以清晰地形式化为算法的任务最为有效。对于需要理解语言细微差别、常识或创造性思维的任务，直接应用 PoT 存在困难。
- **依赖代码生成质量**：方法的有效性直接取决于 LLM 生成语法正确且逻辑无误代码的能力。

## 相关方法

利用代码来增强 LLM 推理能力的想法也在其他类似方法中得到了发展。

- **Program-Aided Language Models (PAL)**：与 PoT 几乎同时提出的方法，也使用生成 Python 代码来解决问题<sup>[\[5\]](https://systems-analysis.info/int/Program_of_Thoughts_Prompting_%E2%80%94_%E6%80%9D%E7%BB%B4%E7%A8%8B%E5%BA%8F%E6%8F%90%E7%A4%BA#cite_note-pal_guide-5)</sup>。从概念上讲，PAL 和 PoT 非常相似，都证实了“通过代码推理”策略的有效性。
- **Tree of Thoughts (ToT)**：一种更复杂的方法，它提出生成并探索一个可能解决方案步骤的“树”，这是对线性“链式”思维思想的发展。PoT 可用于该树的节点内以验证假设。

## 外部链接

- <a href="https://arxiv.org/abs/2211.12588" class="external text" rel="nofollow">关于 Program of Thoughts Prompting 的原始论文</a>
- <a href="https://learnprompting.org/docs/advanced/decomposition/program_of_thoughts" class="external text" rel="nofollow">Learn Prompting 网站上的 PoT 指南</a>

## 参考文献

- Chen, W. et al. (2023). *Program of Thoughts Prompting: Disentangling Computation from Reasoning for Numerical Reasoning Tasks*. <a href="https://arxiv.org/abs/2211.12588" class="external text" rel="nofollow">arXiv:2211.12588</a>.
- Wei, J. et al. (2022). *Chain of Thought Prompting Elicits Reasoning in Large Language Models*. <a href="https://arxiv.org/abs/2201.11903" class="external text" rel="nofollow">arXiv:2201.11903</a>.
- Wang, X. et al. (2022). *Self-Consistency Improves Chain of Thought Reasoning in Language Models*. <a href="https://arxiv.org/abs/2203.11171" class="external text" rel="nofollow">arXiv:2203.11171</a>.
- Gao, L. et al. (2022). *PAL: Program-Aided Language Models*. <a href="https://arxiv.org/abs/2211.10435" class="external text" rel="nofollow">arXiv:2211.10435</a>.
- Cobbe, K. et al. (2021). *Training Verifiers to Solve Math Word Problems*. <a href="https://arxiv.org/abs/2110.14168" class="external text" rel="nofollow">arXiv:2110.14168</a>.
- Chen, Z. et al. (2021). *FinQA: A Dataset of Numerical Reasoning over Financial Data*. <a href="https://arxiv.org/abs/2109.00122" class="external text" rel="nofollow">arXiv:2109.00122</a>.
- Zhu, F. et al. (2021). *TAT-QA: A Question Answering Benchmark on a Hybrid of Tabular and Textual Content in Finance*. <a href="https://arxiv.org/abs/2105.07624" class="external text" rel="nofollow">arXiv:2105.07624</a>.
- Patel, A. et al. (2021). *Are NLP Models Really Able to Solve Simple Math Word Problems? (Introducing SVAMP)*. <a href="https://arxiv.org/abs/2103.07191" class="external text" rel="nofollow">arXiv:2103.07191</a>.
- Xu, F. et al. (2023). *RECOMP: Improving Retrieval-Augmented LMs with Compression and Selective Augmentation*. <a href="https://arxiv.org/abs/2310.04408" class="external text" rel="nofollow">arXiv:2310.04408</a>.
- Mu, J. et al. (2023). *Learning to Compress Prompts with Gist Tokens*. <a href="https://arxiv.org/abs/2304.08467" class="external text" rel="nofollow">arXiv:2304.08467</a>.

## 注释

1.  <span id="cite_note-pot_paper-1">↑ <sup>[1.0](https://systems-analysis.info/int/Program_of_Thoughts_Prompting_%E2%80%94_%E6%80%9D%E7%BB%B4%E7%A8%8B%E5%BA%8F%E6%8F%90%E7%A4%BA#cite_ref-pot_paper_1-0)</sup> <sup>[1.1](https://systems-analysis.info/int/Program_of_Thoughts_Prompting_%E2%80%94_%E6%80%9D%E7%BB%B4%E7%A8%8B%E5%BA%8F%E6%8F%90%E7%A4%BA#cite_ref-pot_paper_1-1)</sup> <sup>[1.2](https://systems-analysis.info/int/Program_of_Thoughts_Prompting_%E2%80%94_%E6%80%9D%E7%BB%B4%E7%A8%8B%E5%BA%8F%E6%8F%90%E7%A4%BA#cite_ref-pot_paper_1-2)</sup> <sup>[1.3](https://systems-analysis.info/int/Program_of_Thoughts_Prompting_%E2%80%94_%E6%80%9D%E7%BB%B4%E7%A8%8B%E5%BA%8F%E6%8F%90%E7%A4%BA#cite_ref-pot_paper_1-3)</sup> <sup>[1.4](https://systems-analysis.info/int/Program_of_Thoughts_Prompting_%E2%80%94_%E6%80%9D%E7%BB%B4%E7%A8%8B%E5%BA%8F%E6%8F%90%E7%A4%BA#cite_ref-pot_paper_1-4)</sup> <sup>[1.5](https://systems-analysis.info/int/Program_of_Thoughts_Prompting_%E2%80%94_%E6%80%9D%E7%BB%B4%E7%A8%8B%E5%BA%8F%E6%8F%90%E7%A4%BA#cite_ref-pot_paper_1-5)</sup> Chen, W. et al. "Program of Thoughts Prompting: Disentangling Computation from Reasoning for Numerical Reasoning Tasks". *arXiv:2211.12588*, 2023. <a href="https://arxiv.org/abs/2211.12588" class="external autonumber" rel="nofollow">[1]</a></span>
2.  <span id="cite_note-cot_paper-2">[↑](https://systems-analysis.info/int/Program_of_Thoughts_Prompting_%E2%80%94_%E6%80%9D%E7%BB%B4%E7%A8%8B%E5%BA%8F%E6%8F%90%E7%A4%BA#cite_ref-cot_paper_2-0) Wei, J. et al. "Chain-of-Thought Prompting Elicits Reasoning in Large Language Models". *arXiv:2201.11903*, 2022. <a href="https://arxiv.org/abs/2201.11903" class="external autonumber" rel="nofollow">[2]</a></span>
3.  <span id="cite_note-pot_ministry_ai-3">[↑](https://systems-analysis.info/int/Program_of_Thoughts_Prompting_%E2%80%94_%E6%80%9D%E7%BB%B4%E7%A8%8B%E5%BA%8F%E6%8F%90%E7%A4%BA#cite_ref-pot_ministry_ai_3-0) "Program of Thoughts: Everything You Need to Know". *The Ministry of AI*. <a href="https://medium.com/@ThePromptIndex/program-of-thoughts-everything-you-need-to-know-7ebf2cb9d59c" class="external autonumber" rel="nofollow">[3]</a></span>
4.  <span id="cite_note-pot_learnprompting-4">↑ <sup>[4.0](https://systems-analysis.info/int/Program_of_Thoughts_Prompting_%E2%80%94_%E6%80%9D%E7%BB%B4%E7%A8%8B%E5%BA%8F%E6%8F%90%E7%A4%BA#cite_ref-pot_learnprompting_4-0)</sup> <sup>[4.1](https://systems-analysis.info/int/Program_of_Thoughts_Prompting_%E2%80%94_%E6%80%9D%E7%BB%B4%E7%A8%8B%E5%BA%8F%E6%8F%90%E7%A4%BA#cite_ref-pot_learnprompting_4-1)</sup> "Program of Thoughts Prompting: Enhancing Accuracy in Reasoning and Computation". *Learn Prompting*. <a href="https://learnprompting.org/docs/advanced/decomposition/program_of_thoughts" class="external autonumber" rel="nofollow">[4]</a></span>
5.  <span id="cite_note-pal_guide-5">[↑](https://systems-analysis.info/int/Program_of_Thoughts_Prompting_%E2%80%94_%E6%80%9D%E7%BB%B4%E7%A8%8B%E5%BA%8F%E6%8F%90%E7%A4%BA#cite_ref-pal_guide_5-0) "PAL (Program-Aided Language Models)". *Prompt Engineering Guide*. <a href="https://www.promptingguide.ai/techniques/pal" class="external autonumber" rel="nofollow">[5]</a></span>
