Papers › DocPrompting: Generating Code by Retrieving the Docs

DocPrompting: Generating Code by Retrieving the Docs

13 Jul 2022arXiv:2207.05987archive 2025-07-28

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

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.

PaperPDFCodeCode Syntology ran

In Syntology Open this paper in Syntology's Atlas, the map of the papers in Syntology's graph and their citations.

For agents, Syntology's MCP tool lists every function and class Syntology harvested from this paper and whether it ran (how to connect): get_harvested_code_for_paper(arxiv_id="2207.05987")

Code

Syntology Ran 3 of 9 code samples harvested from 2 repositories linked to this paper; 6 have no recorded run. Of those that ran: 2 ran · our draft was wrong; 1 ran with no contract checked.

By repository: official repository: 9 samples from 2 repositories, 3 ran. The run record, sample by sample. “Ran” means executed on a synthesized input, not that the code is correct or reproduces the paper.

shuyanzhou/doccoder officialmentioned in papermentioned on GitHubpytorch report
shuyanzhou/docprompting officialmentioned in papermentioned on GitHubpytorch report

Repository list and official/mentioned flags are the archive's, frozen 2025-07-28. Reachability, where shown, is from one Syntology probe window (2026-09-16 to 2026-09-18); repositories not probed show nothing. GitHub stars are not tracked.

Code Syntology ran Syntology

9 samples harvested; 3 ran; 0 honoured the contract we drafted; 6 have no recorded run. Read from Syntology's graph 2026-09-24; that is when this build read the record, not when the samples ran.

2ran · our draft was wrong
1ran
6unverified

Licence: 0 of the 9 samples are pointer only, meaning Syntology does not serve that copy's text. This page shows no code text for any sample; each one links to its file in the repository.

Harvested from 2 repositories linked to this paper, official or community; each sample names its own and says which. “Ran” means the sample executed on a synthesized input. It does not mean the output is correct, and nothing here reproduces the paper's results. “Honoured” and “violated” refer to a contract Syntology drafted from the code itself; “our draft was wrong” and “fixture could not drive it” are failures of Syntology's instrument, not of the code.

Each sample ends with its code_sha256, Syntology's identity for that exact code. An agent fetches the stored sample with Syntology's MCP tool get_code(code_sha256="…") (how to connect); click an identity to copy that call.

Repository labels, per sample. official repository: The archive marks this repository official for the paper. named in the paper: The archive records that the paper mentions this repository; it is not marked official. community (archive-listed): In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper. found in paper text by Syntology: Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted. community: Not in the archive's code links for this paper; a community repository Syntology harvested. Samples from a repository marked official are listed first. Licence labels name the repository's licence as recorded at harvest. “Pointer only” means Syntology does not serve that copy's text, for one of four reasons: no licence file was found; the licence was not identified; the licence is recorded as permissive but that copy's record is not marked cleared; or the licence is outside the permissive list Syntology serves text under (MIT, Apache-2.0, BSD and similar). Some licences outside that list permit redistribution, such as WTFPL, and GPL-3.0 under its conditions; they are simply not on the list. Hover a licence label for the reason. File links open the file on GitHub at the default branch, which may have changed since the harvest.

RetrieverConfig shuyanzhou/doccoder/generator/fid/src/model.py official repository ran Apache-2.0 (permissive) · 951ed5b9657b55ce · report
config shuyanzhou/docprompting/retriever/simcse/run_inference.py official repository ran · our draft was wrong Apache-2.0 (permissive) · 508a4a6a64754c3c · report
get_bert_embedding shuyanzhou/docprompting/retriever/simcse/model.py official repository ran · our draft was wrong Apache-2.0 (permissive) · 37fe359be5cffce7 · report
RetrievalModel shuyanzhou/docprompting/retriever/simcse/model.py official repository unverified Apache-2.0 (permissive) · 19c938f795d433a5 · report
Retriever shuyanzhou/doccoder/generator/fid/src/model.py official repository unverified Apache-2.0 (permissive) · e6e89b2e0804678e · report
bert_cos_score_idf shuyanzhou/docprompting/retriever/simcse/model.py official repository unverified Apache-2.0 (permissive) · 9c210e01ad10a85d · report
collate_idf shuyanzhou/docprompting/retriever/simcse/model.py official repository unverified Apache-2.0 (permissive) · fade9d8bfe4dbc38 · report
get_tokenizer shuyanzhou/docprompting/retriever/simcse/model.py official repository unverified Apache-2.0 (permissive) · 38d2231884f32e2e · report
greedy_cos_idf_for_train shuyanzhou/docprompting/retriever/simcse/model.py official repository unverified Apache-2.0 (permissive) · 2c7a8491c88c3808 · report

Tasks

Code Generation

Results from the paper archive 2025-07-28

No leaderboard rows for this paper in the archive.

Methods

AdafactorAttentionAttention DropoutBASEBPEDense ConnectionsDropoutGated Linear UnitInverse Square Root ScheduleLayer NormalizationLinear LayerMulti-Head AttentionResidual ConnectionSentencePieceSoftmaxT5

Report a problem or propose a change · a person checks every report against the paper or source before anything changes; decisions are listed on /corrections