测试大模型做精确计算,发现代码生成比纯文本推理更可靠。
Evaluating Prompting and Execution-Based Methods for Deterministic Computation in LLMs

- 用程序思维(PoT)生成可执行代码,让外部工具算
- 标准提示词准确率仅中等,代码生成能达到100%正确
- 适合需要零误差的数学、逻辑类任务
大型语言模型在自然语言理解与推理方面表现优异,但在精确、确定性计算能力上仍不明确。本文系统评估了多种提示策略,包括思维链(CoT)、从少到多分解、程序思维(PoT)和自一致性(SC),针对需精确输出的任务,如二进制计数、最长子串检测和算术求值。为此,我们构建了一个包含多样化自然语言指令的合成数据集,支持对多种任务类型的可控评估。结果表明,标准提示方法在序列任务上仅达到中等准确率;CoT改进有限,从少到多分解存在错误累积;而PoT通过生成可执行代码并交由外部解释器执行,实现完美准确率。自一致性通过多数投票提升鲁棒性,但计算开销巨大。我们进一步训练了一个小型领域专用模型(CodeT5-small),在未见合成测试数据上所有任务均达100%准确率,且训练成本极低。总体而言,LLMs可能仅模拟推理模式,而非真正可靠地执行符号计算。对于确定性任务,结合外部工具或使用专用模型更具可靠性与效率。
原文摘要 · Abstract (English)
Large Language Models (LLMs) have demonstrated strong capabilities in natural language understanding and reasoning. However, their ability to perform exact, deterministic computation remains unclear. In this work, we systematically evaluate multiple prompting strategies, including Chain-of-Thought (CoT), Least-to-Most decomposition, Program-of-Thought (PoT), and Self-Consistency (SC), on tasks requiring precise and error-free outputs, including binary counting, longest substring detection, and arithmetic evaluation. To support this study, we introduce a synthetic dataset with diverse natural language instructions, enabling controlled evaluation of exact computation across multiple task types. Our results show that standard prompting methods achieve only moderate accuracy on sequence-based tasks. CoT provides limited improvement, while Least-to-Most suffers from error accumulation. In contrast, PoT achieves perfect accuracy by generating executable code and delegating computation to an external interpreter. Self-Consistency improves robustness through majority voting, but incurs substantial computational overhead. We further train a small domain-specific model (CodeT5-small) to generate executable programs, which achieves perfect accuracy on held-out synthetic test data across all tasks with minimal training cost. Overall, our findings suggest that LLMs may simulate reasoning patterns rather than reliably perform exact symbolic computation. For deterministic tasks, combining LLMs with external tools or using specialized models provides a more reliable and efficient solution.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。