Skip to main content
QUICK REVIEW

[论文解读] Fault-Aware Neural Code Rankers

Jeevana Priya Inala, Chenglong Wang|arXiv (Cornell University)|Jun 4, 2022
Software Engineering Research被引用 13
一句话总结

本文提出 CodeRanker,一种故障感知的神经排序模型,通过分类细粒度错误类型(如 TypeError、IndexError)来预测程序正确性,而无需实际执行。该模型在采样程序的执行反馈上进行训练,可在 APPS、HumanEval 和 MBPP 等多个代码生成模型和数据集上,将 pass@1 准确率提升最高达 13.6 个百分点。

ABSTRACT

Large language models (LLMs) have demonstrated an impressive ability to generate code for various programming tasks. In many instances, LLMs can generate a correct program for a task when given numerous trials. Consequently, a recent trend is to do large scale sampling of programs using a model and then filtering/ranking the programs based on the program execution on a small number of known unit tests to select one candidate solution. However, these approaches assume that the unit tests are given and assume the ability to safely execute the generated programs (which can do arbitrary dangerous operations such as file manipulations). Both of the above assumptions are impractical in real-world software development. In this paper, we propose CodeRanker, a neural ranker that can predict the correctness of a sampled program without executing it. Our CodeRanker is fault-aware i.e., it is trained to predict different kinds of execution information such as predicting the exact compile/runtime error type (e.g., an IndexError or a TypeError). We show that CodeRanker can significantly increase the pass@1 accuracy of various code generation models (including Codex, GPT-Neo, GPT-J) on APPS, HumanEval and MBPP datasets.

研究动机与目标

  • 解决在推理过程中执行 LLM 生成代码的不切实际问题,因其存在安全风险和依赖开销。
  • 克服基于执行的过滤方法的局限性,后者需要单元测试和安全的执行环境。
  • 通过在无运行时执行的情况下对采样程序进行排序,提升代码生成模型的 pass@1 性能。
  • 开发一种理解多种失败模式(如语法错误、运行时错误、类型错误)的神经排序模型,以更准确评估程序正确性。
  • 实现在无需微调的情况下,将排序模型在不同代码生成模型和数据集之间进行迁移。

提出的方法

  • 训练一种故障感知的神经排序模型(CodeRanker),从程序执行反馈中预测多类故障模式。
  • 在执行结果(如错误类型、输出不匹配)上微调 CodeBERT,构建程序正确性的分类器。
  • 利用在单元测试上执行采样程序的日志,生成训练标签,包括具体的错误类型和输出类型。
  • 根据预测的正确性概率对候选程序进行排序,优先选择更不可能出错的程序。
  • 在数据集构建阶段利用执行数据,避免在推理阶段进行运行时执行。
  • 在不重新训练的情况下,将排序模型迁移至不同的代码生成模型(如 Codex、GPT-J、GPT-Neo)和数据集(APPS、HumanEval、MBPP)上。

实验结果

研究问题

  • RQ1是否可以通过训练神经排序模型来预测细粒度错误类型,从而在不执行程序的情况下改善 LLM 生成程序的排序?
  • RQ2与基于二分类的排序相比,故障感知排序在 pass@k 和 exec@k 指标上的表现如何?
  • RQ3在不重新训练的情况下,基于某一代码生成模型训练的排序模型,能在多大程度上迁移到其他模型上?
  • RQ4故障感知排序是否能泛化到竞赛风格问题之外的不同编程任务和数据集?
  • RQ5故障感知排序是否能减少推理阶段对昂贵执行的依赖,同时保持或提升准确性?

主要发现

  • CodeRanker 将 Codex 在 APPS 验证集上的 pass@1 准确率从 26% 提升至 39.6%,在测试集上从 3.8% 提升至 4.5%。
  • 在 HumanEval 上,CodeRanker 将 Codex 的 pass@1 从 26% 提升至 32%;在 MBPP 上,从 36% 提升至 42%。
  • 故障感知排序模型优于基线二分类分类器,证明了细粒度错误预测的价值。
  • 该排序模型具有可迁移性:在不重新训练的情况下,对不同代码生成模型(如 GPT-J、GPT-Neo)也观察到性能提升。
  • CodeRanker 在检测执行错误方面比检测意图错误更有效,这与模型生成代码常在运行时失败的观察一致。
  • 该方法减少了对推理阶段执行的依赖,使真实环境中更安全、更可扩展的代码生成成为可能。

更好的研究,从现在开始

从阅读论文到最终审阅,大幅缩短您的研究时间。

无需绑定信用卡

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