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

Function Assistant: A Tool for NL Querying of APIs

Kyle Richardson, Jonas Kuhn · DOI

TL;DR

Function Assistant is an open-source, lightweight Python toolkit that allows developers to search source code repositories using natural language queries. By treating API documentation and code signatures as a parallel translation corpus, it maps high-level developer intent to specific code components, significantly outperforming traditional keyword-based search tools.

What Problem Does This Paper Address?

Software developers frequently switch between different third-party libraries (APIs) and spend a significant portion of their time trying to understand their structure and naming conventions. Traditional code search methods rely heavily on shallow keyword matching. This approach fails when a developer's query uses different terminology than the arbitrary names chosen by the API creators—for example, searching for "create arc" when the actual function is named add_arc.

To bridge this gap, the authors address the challenge of translating unconstrained natural language queries into exact API components (function names, arguments, and namespaces) without requiring the user to know the exact underlying code syntax.

Methods

Function Assistant approaches natural language code search as a semantic parsing problem, framed through the lens of Statistical Machine Translation (SMT):

  1. Translation Model: The system uses a noisy-channel approach. Given a natural language query, it utilizes an IBM Model 1 word-based translation architecture to generate a list of candidate API components. This model calculates the probability of alignment between natural language words and code tokens.
  2. Discriminative Reranker: To refine the output, a log-linear model re-scores the candidates. It uses three classes of features:
  3. Word-level features: Direct matches and syntactic overlaps.
  4. Phrase-level features: Hierarchical phrase pairs extracted from word alignments.
  5. Document-level features: Contextual information about the API's internal class hierarchy and parameter descriptions extracted from docstrings.
  6. Implementation: The core toolkit is written in Cython for high performance and uses dependency-injection object-oriented design principles to allow developers to easily swap out pipeline components or add custom machine learning features. It also includes a built-in HTTP web server for interactive querying.

Datasets

The authors created a new benchmark by automatically extracting function-description pairs from 27 popular open-source Python projects hosted on GitHub (culled from the well-known Awesome Python list). Using Python's standard abstract syntax tree (ast) module, they parsed repositories such as tensorflow, pandas, scapy, nltk, and sklearn to build parallel corpora of docstrings and code components.

Dataset statistics for the 27 Python projects

Key Insights and Ideas

  • Code as a Parallel Language: The core "aha moment" is that API documentation (docstrings) and the code signatures themselves can be treated as a parallel text corpus, much like translating English to French. This allows the model to automatically learn paraphrases (e.g., understanding that "removing a node" maps to remove_by_address).
  • The Power of Context: Simple word-to-code translation is insufficient for complex APIs. Incorporating document-level features—specifically where a function sits within an API's class hierarchy—drastically improves the reranker's ability to identify the correct function.
  • Simplicity in Alignment: Interestingly, the authors found that the simplest lexical translation model (IBM Model 1) actually outperformed more complex, higher-order alignment models when generating the initial candidate sets.

Key Results

The toolkit was evaluated using Accuracy@1, Accuracy@10, and Mean Reciprocal Rank (MRR) across all 27 datasets, comparing Function Assistant against a Bag-of-Words (BoW) baseline and a standard Term Match baseline:

  • Baseline Outperformance: The translation and reranking models comprehensively outperformed the BoW and Term Match baselines on every single dataset, proving that API querying requires deeper semantic understanding than simple keyword matching.
  • Reranker Boost: The discriminative reranker consistently provided the highest accuracy. For example, on the tensorflow dataset, the Reranker achieved an Accuracy@1 of 38.4% and an Accuracy@10 of 77.7%, compared to the Term Match baseline's 25.2% and 48.7% respectively.
Experimental results comparing baselines against the Translation and Reranker models

The toolkit also successfully serves these predictions in a web interface, mapping a query like "Train a sequence tagger model" directly to the relevant HiddenMarkovModelTagger functions in NLTK.

Figure 3: An example screen shot of the Function Assistant web server.

Limitations and Future Work

The primary limitation acknowledged by the authors is that their experiments are synthetic. The evaluation relies on held-out docstrings written by the original code authors to mimic user queries. In reality, an end-user's search query might look quite different from a formal docstring description.

To address this, the authors point to future work focused on gathering more naturalistic developer queries (e.g., mining data from StackOverflow) and conducting real-world deployment usage studies.

Summary updated

BibTeX
@inproceedings{richardson2017function,
  author = {Kyle Richardson and Jonas Kuhn},
  title = {{Function Assistant: A Tool for NL Querying of APIs}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2017},
  url = {https://openreview.net/forum?id=S1WDxzGdbH},
}
Figure