NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

A parallel corpus of Python functions and documentation strings for automated code documentation and code generation

Antonio Valerio Miceli Barone, Rico SennricharXiv 2017

TL;DR

Researchers from the University of Edinburgh have released a massive, diverse parallel corpus of over 150,000 Python functions paired with their developer-written docstrings. By moving away from small, "clean" datasets to real-world code scraped from GitHub, they demonstrate that automated code documentation and generation are significantly more challenging than previously thought, providing a new, realistic baseline for the field.

What Problem Does This Paper Address?

The dream of AI-assisted programming involves two main tasks: automated code documentation (explaining what a function does in plain English) and automated code generation (writing code based on a natural language description).

Until now, progress has been bottlenecked by data. Existing datasets generally fall into two camps:

  1. Small and Synthetic: Datasets like DJANGO or Project Euler are high-quality but tiny and often use "pseudo-code" descriptions that are too similar to the actual code, making the task artificially easy.
  2. Large and Noisy: Datasets mined from StackOverflow are large but often contain conversational noise that doesn't directly map to specific code blocks.

The authors argue that these datasets don't represent code "in the wild." To build tools that actually help developers, we need models trained on the diverse, complex, and sometimes messy way real programmers document their work.

Methods

The authors treated code-to-text (and vice versa) as a Neural Machine Translation (NMT) problem. They used Nematus, a sequence-to-sequence toolkit, to build their baseline models.

Key technical choices included:

  • Sub-tokenization: Instead of treating every variable name as a unique word, they used Byte-Pair Encoding (BPE). This breaks down complex identifiers (like safe_sparse_dot) into smaller sub-units, helping the model handle rare words and reducing the overall vocabulary size.
  • Data Augmentation (Backtranslation): To improve the code generation model, they took a large set of "monolingual" code (functions without docstrings), used their documentation model to generate synthetic docstrings for them, and then added this synthetic data back into the training set.
  • Metadata Tagging: Each example is tagged with its repository owner, file name, and line number, allowing future researchers to reconstruct the context of the code.

Datasets

The core contribution is the parallel corpus of Python functions and docstrings.

Table 1: Number of examples, tokens and lines of code in the corpora.

The researchers scraped GitHub for Python 2.7 repositories, specifically extracting top-level functions. They ended up with two main sets:

  • Parallel Corpus: 150,370 triples consisting of a function declaration, the docstring, and the function body.
  • Code-only Corpus: 161,630 pairs of declarations and bodies without docstrings, used for data augmentation.
Table 2: Tokens per example statistics.

Key Insights and Ideas

  • The "Reality Check" on BLEU Scores: Previous papers reported BLEU scores (a measure of translation accuracy) as high as 60–85. On this new dataset, scores plummeted to the 10–14 range. This isn't because the models got worse, but because the new dataset actually captures the complexity of real-world programming, where natural language is diverse and not just a simple restatement of the code.
  • Top-level Focus: By focusing on top-level functions, the authors ensured that the training examples were relatively self-contained units of logic, which is ideal for current NMT architectures.
  • Backtranslation Works for Code: The moderate improvement from using synthetic docstrings suggests that even imperfect "machine-written" documentation can help a model learn the structural patterns of code generation.

Key Results

The baseline results establish a "lower bound" for performance on this difficult dataset.

Table 3: Code documentation and code generation accuracy (multi-bleu.perl).

As shown in Table 3, the Code-to-docstring task achieved a BLEU score of 13.84. For Docstring-to-code, the base model scored 10.24, which improved to 10.90 after incorporating backtranslated data. While these numbers seem low compared to standard language translation, they represent a much more honest assessment of how current AI handles the nuances of real-world Python.

Limitations and Future Work

The authors acknowledge that their NMT baselines are "syntax-blind"—they treat code as a simple sequence of tokens rather than a structured tree. Future work could involve syntax-aware models that understand the underlying grammar of Python.

Additionally, while docstrings are a great source of data, they can be noisy or incomplete. The authors suggest that incorporating broader project-level context (like class definitions or other functions in the same file) could help models better understand the specific domain of the code they are trying to document or generate.

Summary updated

BibTeX
@misc{barone2017parallel,
  author = {Antonio Valerio Miceli Barone and Rico Sennrich},
  title = {{A parallel corpus of Python functions and documentation strings for automated code documentation and code generation}},
  year = {2017},
  eprint = {1707.02275},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1707.02275},
}
Figure