[论文解读] Chain of Code: Reasoning with a Language Model-Augmented Code Emulator
Chain of Code (CoC) 提示语言模型生成代码并在代码无法执行时通过 LMulator 模拟执行,从而产生具备状态记忆的推理,在 BBH 任务上超越 Chain of Thought,并在不同模型规模上实现可扩展性。
Code provides a general syntactic structure to build complex programs and perform precise computations when paired with a code interpreter - we hypothesize that language models (LMs) can leverage code-writing to improve Chain of Thought reasoning not only for logic and arithmetic tasks, but also for semantic ones (and in particular, those that are a mix of both). For example, consider prompting an LM to write code that counts the number of times it detects sarcasm in an essay: the LM may struggle to write an implementation for "detect_sarcasm(string)" that can be executed by the interpreter (handling the edge cases would be insurmountable). However, LMs may still produce a valid solution if they not only write code, but also selectively "emulate" the interpreter by generating the expected output of "detect_sarcasm(string)". In this work, we propose Chain of Code (CoC), a simple yet surprisingly effective extension that improves LM code-driven reasoning. The key idea is to encourage LMs to format semantic sub-tasks in a program as flexible pseudocode that the interpreter can explicitly catch undefined behaviors and hand off to simulate with an LM (as an "LMulator"). Experiments demonstrate that Chain of Code outperforms Chain of Thought and other baselines across a variety of benchmarks; on BIG-Bench Hard, Chain of Code achieves 84%, a gain of 12% over Chain of Thought. In a nutshell, CoC broadens the scope of reasoning questions that LMs can answer by "thinking in code".
研究动机与目标
- 说明需要将基于代码的推理与语言模型推理相结合以处理语义和数值任务的动机。
- 提出 Chain of Code (CoC) 作为两阶段过程:代码生成和执行(通过解释器)或在执行失败时进行 LMulator 仿真。
- 展示在不同任务中交替进行 Python 执行与基于 LM 的仿真可提升性能。
- 演示在模型规模上的可扩展性并评估跨任务提示作为通用推理的衡量标准。
提出的方法
- 首先让语言模型以代码、伪代码或自然语言的形式产生推理,以结构化子问题。
- 在可能的情况下,使用 Python 解释器逐行执行代码;否则由 LMulator 模拟未解决行的执行效果。
- 在每一行被执行或模拟后更新共享的程序状态,从而实现代码与 LM 输出的交错执行。
- 当代码执行失败时,LMulator 利用语言模型自身的推理(可能使用链式思考)来产生中间状态轨迹。
- 将此方法与 Direct QA、Chain of Thought 等基线在 BBH 任务和 GSM8K 上进行对比评估,并进行若干消融实验(如仅 Python、仅 LM、LM 状态等,以隔离组件)。
实验结果
研究问题
- RQ1CoC 在一组具有挑战性的推理任务中与基线相比的表现如何?
- RQ2哪些任务类型(算法性、语义性或混合型)从 CoC 中获益最大?
- RQ3CoC 的每个组成部分(Python 执行、LMulator、交错执行)对性能的影响是什么?
- RQ4CoC 如何随模型规模和跨任务提示作为通用推理器的能力增长而扩展?
- RQ5与带工具或不带工具的指令调优聊天模型相比,CoC 的表现如何?
主要发现
- CoC 在 BIG-Bench Hard 上达到 84%,在总分上超过 Chain of Thought,在某些任务中甚至超越人类基线。
- 启用 Python 的 CoC 变体在代码可执行的若干任务中接近或达到 100%;由 LMulator 驱动的变体使语义任务在代码不易直接执行时也可实现。
- CoC 在算法性和语义性任务上均优于基线,并随模型规模增长而提升,即使对较小的模型也能看到改进。
- 跨任务提示的 CoC 保持具有竞争力,并在规模化时接近人类水平,表明其作为通用推理器的潜力。
- 消融实验表明,将解释器执行与基于 LM 的仿真交错进行并维护程序状态对于达到峰值性能至关重要。
阅读本论文
在 Nubint 阅读器中打开原文,边读边就任意段落提问。
在 Nubint 中阅读本论文本解读由 AI 根据论文原文生成,引用前请核对原文。