DocPrompting: Generating Code by Retrieving the Docs

Shuyan Zhou, Uri Alon, Frank F. Xu, Zhiruo Wang, Zhengbao Jiang +1 more
7/13/2022
cs.CLcs.AIcs.SE

No official code found. Best implementation: shuyanzhou/docprompting (253 stars, Apache-2.0, last commit 2023-12-15).

Abstract

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.

View on arXivView PDF

Code Implementations(1)

Apache-2.0

Data and code for "DocPrompting: Generating Code by Retrieving the Docs" @ICLR 2023

25320PythonJul 13, 20222 years agoApache-2.0
code-generationnatural-language-processingnl-to-codereading-comprehension

Similar Papers

Cite this paper

@article{zhou2022docprompting,
  title  = {DocPrompting: Generating Code by Retrieving the Docs},
  author = {Shuyan Zhou and Uri Alon and Frank F. Xu and Zhiruo Wang and Zhengbao Jiang and Graham Neubig},
  year   = {2022},
  eprint = {2207.05987},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2207.05987v3}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2207.05987.svg)](https://codeofpaper.com/paper/2207.05987)

Discussion