Natural-language-to-code models learn to generate a code snippet given a natural language (NL) intent. However, the rapid growth of both publicly available and proprietary libraries and functions makes it impossible to cover all APIs using training examples, as new libraries and functions are introduced daily. Thus, existing models inherently cannot generalize to using unseen functions and libraries merely through incorporating them into the training data. In contrast, when human programmers write programs, they frequently refer to textual resources such as code manuals, documentation, and tutorials, to explore and understand available library functionality. Inspired by this observation, we introduce DocCoder: an approach that explicitly leverages code manuals and documentation by (1) retrieving the relevant documentation given the NL intent, and (2) generating the code based on the NL intent and the retrieved documentation. Our approach is general, can be applied to any programming language, and is agnostic to the underlying neural model. We demonstrate that DocCoder consistently improves NL-to-code models: DocCoder achieves 11x higher exact match accuracy than strong baselines on a new Bash dataset tldr; on the popular Python CoNaLa benchmark, DocCoder improves over strong baselines by 1.65 BLEU.
翻译:自然语言到代码模型学会根据自然语言(NL)的意图生成代码片断。然而,由于公共和专有图书馆和功能的迅速增长,由于新的图书馆和功能每天都在引入,因此无法利用培训实例涵盖所有API,因此,现有模型本身无法仅仅通过将隐性功能和图书馆纳入培训数据而笼统地使用这些隐性功能和图书馆。相比之下,当人类程序员编写程序时,它们经常参考诸如代码手册、文档和导师等文本资源,以探索和理解可用的图书馆功能。根据这一观察,我们采用了DocCoder:一种方法,它明确利用了代码手册和文件,其方法是:(1) 根据NL的意图检索相关文件,(2) 根据NL的意图和检索的文件生成代码。我们的方法是一般性的,可以适用于任何编程语言,并且对基本神经模型具有概念性。我们证明DocCooorder不断改进NL到代码模型:DocCocoder在新的Bash数据库1.Coldr改进了CoyL基准上的11x准确性比强基线要高一些。