[论文解读] Teaching Large Language Models to Self-Debug
SELF-DEBUGGING 教会 LLMs 通过 少量示例 提示 来 调试 自己 生成 的 代码,使用 代码 执行 和 自然语言 解释 迭代 修正 错误,在 Spider (text-to-SQL)、TransCoder (code translation) 和 MBPP (text-to-Python) 上 取得 最先进 的 结果,同时 提高 样本 效率。
Large language models (LLMs) have achieved impressive performance on code generation. However, for complex programming tasks, generating the correct solution in one go becomes challenging, thus some prior works have designed program repair approaches to improve code generation performance. In this work, we propose Self-Debugging, which teaches a large language model to debug its predicted program via few-shot demonstrations. In particular, we demonstrate that Self-Debugging can teach the large language model to perform rubber duck debugging; i.e., without any human feedback on the code correctness or error messages, the model is able to identify its mistakes by investigating the execution results and explaining the generated code in natural language. Self-Debugging achieves the state-of-the-art performance on several code generation benchmarks, including the Spider dataset for text-to-SQL generation, TransCoder for C++-to-Python translation, and MBPP for text-to-Python generation. On the Spider benchmark where there are no unit tests to verify the correctness of predictions, Self-Debugging with code explanation consistently improves the baseline by 2-3%, and improves the prediction accuracy on problems of the hardest level by 9%. On TransCoder and MBPP where unit tests are available, Self-Debugging improves the baseline accuracy by up to 12%. Meanwhile, by leveraging feedback messages and reusing failed predictions, Self-Debugging notably improves sample efficiency, and can match or outperform baseline models that generate more than 10x candidate programs.
研究动机与目标
- 通过使 LLMs 在不进行额外训练的情况下调试自身输出来促进代码生成的改进。
- 提出一个自我调试框架,使用生成、执行、解释和反馈来迭代修正代码。
- 在多种代码生成任务和多种 LLMs 上评估该方法,以确立性能和样本效率提升。
提出的方法
- 三步 SELF-DEBUGGING 循环:候选程序的生成、对代码的解释、以及对正确性的反馈。
- 使用少量示例提示提供演示并引导模型完成调试迭代。
- 在有执行结果时,基于执行结果在多个样本之间选择最终预测。
- 在题目描述中提供单元测试时,利用单元测试来筛选/验证候选程序。
- 反馈格式包括 Simple Feedback、Unit Test (UT) Feedback、Code Explanation (Expl) 和 Execution Trace (Trace) 的交付;风格类似橡皮鸭调试。
- 迭代修正,直到反馈指示正确或达到最大回合数。
实验结果
研究问题
- RQ1在不同的 LLMs 下,SELF-DEBUGGING 是否可提升 text-to-SQL、code translation 和 text-to-Python 任务的代码生成准确性?
- RQ2不同的反馈格式(简单、解释、执行轨迹、单元测试集成)如何影响性能?
- RQ3单元测试对 SELF-DEBUGGING 的有效性和样本效率有何影响?
- RQ4通常需要多少次调试回合,执行反馈是否会推动改进?
主要发现
- 在多个基准测试上达到最先进的性能:Spider (text-to-SQL)、TransCoder (C++-to-Python translation)、和 MBPP (text-to-Python)。
- 在 Spider 上(无单元测试),结合代码解释的 SELF-DEBUGGING 将准确率提升约 2–3%,在最难的查询上提升高达 9%。
- 在 TransCoder 和 MBPP(有单元测试)上,SELF-DEBUGGING 将基线准确性提升至多约 12%。
- 单独的代码解释在各任务中提供持续提升(约 2–3%);加入单元测试反馈通常会带来更大提升。
- SELF-DEBUGGING 提高样本效率,达到或优于产生超过 10× 候选程序的基线。
- 收益因模型而异;执行反馈(Trace)通常有帮助,该方法在 Codex、GPT-3.5、GPT-4 和 StarCoder 上均有效,尽管不同任务和模型的收益不同。
- 基于执行的最终预测选择对性能有贡献,特别是在存在多个样本时。
更好的研究,从现在开始
从论文设计到论文写作,大幅缩短您的研究时间。
无需绑定信用卡
本解读由 AI 生成,并经人工编辑审核。