arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2312.04474cs.CLcs.AIcs.LGcs.RO
收藏

Chain of Code:基于语言模型增强的代码模拟器进行推理

Chain of Code: Reasoning with a Language Model-Augmented Code Emulator

Stanford University(斯坦福大学);Google DeepMind(谷歌DeepMind);University of California, Berkeley(加利福尼亚大学伯克利分校)

Chengshu Li, Jacky Liang, Andy Zeng, Xinyun Chen, Karol Hausman, Dorsa Sadigh, Sergey Levine, Li Fei-Fei, Fei Xia, Brian Ichter

AI总结:

提出Chain of Code(CoC)方法,通过让语言模型将语义子任务转为伪代码并选择性模拟解释器执行,扩展了LM的代码推理能力,在BIG-Bench Hard等基准上显著超越Chain of Thought。

摘要:

代码提供了一种通用的语法结构,当与代码解释器结合时,可以构建复杂的程序并执行精确的计算——我们假设语言模型(LMs)可以利用编写代码来改进Chain of Thought推理,不仅适用于逻辑和算术任务,也适用于语义任务(特别是两者混合的任务)。例如,考虑提示LM编写代码来计算它在一篇文章中检测到讽刺的次数:LM可能难以编写一个可由解释器执行的“detect_sarcasm(string)”的实现(处理边缘情况将难以克服)。然而,如果LM不仅编写代码,还通过生成“detect_sarcasm(string)”的预期输出来选择性地“模拟”解释器,LM仍可能产生有效的解决方案。在这项工作中,我们提出了Chain of Code(CoC),这是一种简单但出人意料有效的扩展,可改进LM的代码驱动推理。关键思想是鼓励LM将程序中的语义子任务格式化为灵活的伪代码,解释器可以显式捕获未定义的行为并交给LM(作为“LMulator”)进行模拟。实验表明,Chain of Code在各种基准测试中优于Chain of Thought和其他基线;在BIG-Bench Hard上,Chain of Code达到84%,比Chain of Thought提高了12%。简而言之,CoC通过“用代码思考”拓宽了LM可以回答的推理问题的范围。

英文摘要:

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".

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑