arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2207.10397cs.CLcs.AIcs.PLcs.SE
收藏

CodeT:使用生成的测试生成代码生成

CodeT: Code Generation with Generated Tests

Microsoft Corporation(微软公司)

Bei Chen, Fengji Zhang, Anh Nguyen, Daoguang Zan, Zeqi Lin, Jian-Guang Lou, Weizhu Chen

摘要:

为给定的编程问题生成代码解决方案的任务可以受益于使用预训练的语言模型,如Codex,它可以产生多个不同的样本。然而,这项任务的主要挑战是从预训练的语言模型生成的多个样本中选择最合适的解决方案。评估代码解决方案的质量和正确性的一种自然方法是针对一组测试用例运行它,但手动创建此类测试用例通常成本高昂且耗时。在本文中,我们提出了一种新的方法,CodeT,利用相同的预先训练的语言模型,自动生成测试用例的代码样本,从而减少了人力的努力,增加了测试场景的覆盖率。然后CodeT使用生成的测试用例执行代码样本,并执行双重执行协议,该协议既考虑了输出与生成的测试用例的一致性,也考虑了输出与其他代码样本的一致性。我们使用五种不同的预训练语言模型,对四个基准测试(HumanEval,MBPP,APPS和CodeContests)进行了全面的实验,这些模型具有不同的大小和功能。我们的研究结果表明,CodeT可以显着提高性能的代码解决方案的选择比以前的方法,实现显着的和一致的增益在不同的模型和基准。例如,CodeT将HumanEval上的pass@1指标提高到65.8%,这表示比code-davinci-002模型绝对提高了18.8%,比以前的最先进结果绝对提高了20%以上。

英文摘要:

The task of generating code solutions for a given programming problem can benefit from the use of pre-trained language models such as Codex, which can produce multiple diverse samples. However, a major challenge for this task is to select the most appropriate solution from the multiple samples generated by the pre-trained language models. A natural way to evaluate the quality and correctness of a code solution is to run it against a set of test cases, but the manual creation of such test cases is often costly and time-consuming. In this paper, we propose a novel method, CodeT, that leverages the same pre-trained language models to automatically generate test cases for the code samples, thus reducing the human effort and increasing the coverage of the test scenarios. CodeT then executes the code samples using the generated test cases, and performs a dual execution agreement, which considers both the consistency of the outputs against the generated test cases and the agreement of the outputs with other code samples. We conduct comprehensive experiments on four benchmarks, HumanEval, MBPP, APPS and CodeContests, using five different pre-trained language models with varying sizes and capabilities. Our results show that CodeT can significantly improve the performance of code solution selection over previous methods, achieving remarkable and consistent gains across different models and benchmarks. For instance, CodeT improves the pass@1 metric on HumanEval to 65.8%, which represents an absolute improvement of 18.8% over the code-davinci-002 model, and an absolute improvement of more than 20% over the previous state-of-the-art results.

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

↑