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

DocPrompting:通过检索对象生成代码

DocPrompting: Generating Code by Retrieving the Docs

Carnegie Mellon University(卡内基梅隆大学);Inspired Cognition(Inspired Cognition公司)

Shuyan Zhou, Uri Alon, Frank F. Xu, Zhiruo Wang, Zhengbao Jiang, Graham Neubig

摘要:

公开可用的源代码库在不断增长和变化。这使得代码模型不可能通过简单地在现有代码存储库上训练这些模型来与所有可用的API保持同步。因此,现有的模型本质上不能推广到使用看不见的函数和库,因为这些函数和库永远不会出现在训练数据中。相比之下,当人类程序员第一次使用函数和库时,他们经常参考文本资源,如代码手册和文档,以探索和理解可用的功能。受此观察的启发,我们引入了文档化:一种自然语言到代码生成的方法,该方法通过以下方式显式地利用文档:(1)检索给定NL意图的相关文档片段,以及(2)基于NL意图和检索到的文档生成代码。文档整理是通用的:它可以应用于任何程序设计语言,并且与底层神经模型无关。我们证明了Doctending持续改进了NL-to-code模型:Doctending在pass@1中将CodeT 5等强基础模型提高了2.85%(52%相对增益)和4.39%通过@10(30%的相对增益)在基于执行的评估流行的Python CoNaLa基准;在一个新的Bash数据集tldr上,Doctering将CodeT 5和GPT-Neo 1.3B的绝对精确匹配提高了6.9%。

英文摘要:

Publicly available source-code libraries are continuously growing and changing. This makes it impossible for models of code to keep current with all available APIs by simply training these models on existing code repositories. Thus, existing models inherently cannot generalize to using unseen functions and libraries, because these would never appear in the training data. In contrast, when human programmers use functions and libraries for the first time, they frequently refer to textual resources such as code manuals and documentation, to explore and understand the available functionality. Inspired by this observation, we introduce DocPrompting: a natural-language-to-code generation approach that explicitly leverages documentation by (1) retrieving the relevant documentation pieces given an NL intent, and (2) generating code based on the NL intent and the retrieved documentation. DocPrompting is general: it can be applied to any programming language and is agnostic to the underlying neural model. We demonstrate that DocPrompting consistently improves NL-to-code models: DocPrompting improves strong base models such as CodeT5 by 2.85% in pass@1 (52% relative gain) and 4.39% in pass@10 (30% relative gain) in execution-based evaluation on the popular Python CoNaLa benchmark; on a new Bash dataset tldr, DocPrompting improves CodeT5 and GPT-Neo1.3B by up to absolute 6.9% exact match.

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

↑