Skip to main content
QUICK REVIEW

[论文解读] CodeGen-Test: An Automatic Code Generation Model Integrating Program Test Information

Maosheng Zhong, Gen Liu|arXiv (Cornell University)|Feb 14, 2022
Software Testing and Debugging Techniques被引用 4
一句话总结

该论文提出CodeGen-Test,一种新颖的自动代码生成模型,通过在迭代生成过程中整合程序测试信息,提升代码的功能正确性。通过引入测试反馈并使用一种新指标Test-Acc,该模型在测试准确率上相比现有模型实现了6%的绝对提升,表明功能验证可显著提升代码质量,而不仅限于语法合规性。

ABSTRACT

Automatic code generation is to generate the program code according to the given natural language description. The current mainstream approach uses neural networks to encode natural language descriptions, and output abstract syntax trees (AST) at the decoder, then convert the AST into program code. While the generated code largely conforms to specific syntax rules, two problems are still ignored. One is missing program testing, an essential step in the process of complete code implementation; the other is only focusing on the syntax compliance of the generated code, while ignoring the more important program functional requirements. The paper proposes a CodeGen-Test model, which adds program testing steps and incorporates program testing information to iteratively generate code that meets the functional requirements of the program, thereby improving the quality of code generation. At the same time, the paper proposes a new evaluation metric, test accuracy (Test-Acc), which represents the proportion of passing program test in generated code. Different from the previous evaluation metric, which only evaluates the quality of code generation from the perspective of character similarity, the Test-Acc can evaluate the quality of code generation from the Program functions. Moreover, the paper evaluates the CodeGen-test model on a python data set "hearthstone legend". The experimental results show the proposed method can effectively improve the quality of generated code. Compared with the existing optimal model, CodeGen-Test model improves the Bleu value by 0.2%, Rouge-L value by 0.3% and Test-Acc by 6%.

研究动机与目标

  • 解决当前代码生成模型仅关注语法正确性而忽略功能验证的缺陷。
  • 通过在迭代生成过程中整合程序测试结果作为反馈,提升代码质量。
  • 提出一种新评估指标Test-Acc,用于衡量功能正确性,而非仅语法相似性。
  • 验证测试信息与迭代优化在提升代码生成性能方面的有效性。

提出的方法

  • 模型采用序列到序列框架,并使用双编码器架构:一个用于代码,一个用于测试信息。
  • 采用迭代优化机制,其中生成的代码经过测试,反馈用于指导后续生成。
  • 测试信息被独立编码,并与代码嵌入融合,以指导解码器生成功能正确的代码。
  • 模型在Python数据集(Hearthstone Legend)上进行端到端训练,后续迭代中使用测试结果作为监督信号。
  • 提出一种新评估指标Test-Acc,用于衡量通过功能测试的生成代码比例。
  • 进行消融研究,以评估测试信息与代码历史在迭代过程中的贡献。

实验结果

研究问题

  • RQ1将程序测试反馈整合到代码生成过程中,能否提升生成代码的功能正确性?
  • RQ2引入测试信息对代码生成模型的性能有何影响?
  • RQ3与单次生成相比,使用测试结果进行迭代优化是否能带来更高的代码质量?
  • RQ4所提出的Test-Acc指标与BLEU和ROUGE等传统指标相比,在评估功能正确性方面表现如何?
  • RQ5迭代代码生成过程的最优迭代次数是多少?

主要发现

  • 与最佳现有模型相比,CodeGen-Test在Test-Acc上提升了6%,显著增强了功能正确性。
  • 该模型的BLEU得分比最先进模型高0.2%,ROUGE-L得分高0.3%。
  • 消融研究显示,测试信息与先前代码历史对最优性能均至关重要,完整模型优于各类消融版本。
  • 性能随迭代次数增加至N=3而提升,但N>2后增益趋于平缓,原因在于后期迭代中数据稀疏。
  • 训练样本数量在迭代过程中显著减少(从533降至104),尽管采用迭代优化,但进一步提升受限。
  • 所提出的Test-Acc指标能有效捕捉功能正确性,相比仅依赖语法的指标更具实际意义。

更好的研究,从现在开始

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

无需绑定信用卡

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