Skip to main content
QUICK REVIEW

[论文解读] NExT: Teaching Large Language Models to Reason about Code Execution

Ansong Ni, Miltiadis Allamanis|arXiv (Cornell University)|Apr 23, 2024
Software Reliability and Analysis Research被引用 6
一句话总结

NExT 通过自训练并结合单元测试反馈,使大语言模型(LLMs)用自然语言推理程序执行轨迹,即使在测试时无轨迹,也能提升 Python 程序修复的准确性与推理质量。

ABSTRACT

A fundamental skill among human developers is the ability to understand and reason about program execution. As an example, a programmer can mentally simulate code execution in natural language to debug and repair code (aka. rubber duck debugging). However, large language models (LLMs) of code are typically trained on the surface textual form of programs, thus may lack a semantic understanding of how programs execute at run-time. To address this issue, we propose NExT, a method to teach LLMs to inspect the execution traces of programs (variable states of executed lines) and reason about their run-time behavior through chain-of-thought (CoT) rationales. Specifically, NExT uses self-training to bootstrap a synthetic training set of execution-aware rationales that lead to correct task solutions (e.g., fixed programs) without laborious manual annotation. Experiments on program repair tasks based on MBPP and HumanEval demonstrate that NExT improves the fix rate of a PaLM 2 model, by 26.1% and 14.3% absolute, respectively, with significantly improved rationale quality as verified by automated metrics and human raters. Our model can also generalize to scenarios where program traces are absent at test-time.

研究动机与目标

  • 在基于 LLM 的代码任务中,激发对程序运行时行为进行推理的必要性。
  • 提出 Naturalized Execution Tuning(NExT),以教导 LLM 使用执行轨迹并结合 Chain-of-Thought(CoT)推理进行推理。
  • 开发一个弱监督自训练循环:抽样、通过单元测试筛选,并在面向执行的推理与修复上进行微调。
  • 将执行轨迹表示为紧凑的行内代码注释,以帮助 LLM 理解而不破坏代码结构。
  • 在 Python 程序修复基准 Mbpp-R 和 HumanEvalFix-Plus 上评估 NExT,并从内部和外部分析推理质量。

提出的方法

  • 将程序执行轨迹表示为按执行顺序索引的行内注释,以捕获运行时状态。
  • 使用基于提示的 CoT 推理方法生成自然语言推理和修复。
  • 应用一个弱监督循环(抽样 → 通过单元测试筛选 → 训练),从困难问题中创建合成训练数据。
  • 用合成数据对基础 LLM(PaLM 2-L)进行多轮微调,并通过 dev pass@1 选择最佳检查点。
  • 使用基于代理的指标,对以推理为条件的小型语言模型评估推理质量。
  • 在测试时轨迹缺失的情景以及跨分布外的修复任务中测试泛化能力。

实验结果

研究问题

  • RQ1在给定执行轨迹时,LLMs 能否对程序执行进行有效推理?
  • RQ2在训练中加入面向执行的 CoT 推理是否能提升修复准确性与推理质量?
  • RQ3当测试时无法获得轨迹或在分布外任务上,NExT 的泛化能力如何?
  • RQ4生成的推理是否能被人类和代理指标判定为有意义地解释错误并提出修复建议?

主要发现

  • NExT 为 PaLM 2-L 带来显著的端到端修复率提升(例如在 Mbpp-R 的 pass@1 上绝对提升 26.1%)。
  • 推理质量通过 NExT 提升,代理指标和人工评估均显示提升。
  • PaLM 2-L+NExT 在端到端修复指标方面超过了若干强力 LLM,并且在与 GPT-3.5 的竞争中具有竞争力。
  • 即使测试时没有轨迹,PaLM 2-L+NExT 也保持对基线的显著改进。
  • NExT 泛化到 HeFix+,并展示出比基础模型更高质量的推理。
  • 消融研究表明,使用轨迹和 CoT 推理对提升至关重要;去除轨迹或推理会降低性能。

更好的研究,从现在开始

从论文设计到论文写作,大幅缩短您的研究时间。

无需绑定信用卡

本解读由 AI 生成,并经人工编辑审核。