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

When Language Model Meets Private Library

Daoguang Zan, Bei Chen, Zeqi Lin, Bei Guan, Yongji Wang, Jian-Guang Lou

Abstract

Large Language Models (LLMs) like Codex excel at writing code for popular libraries, but they fall flat when faced with private, internal, or brand-new APIs they haven't seen during training. This paper introduces APICoder, a framework that mimics a human programmer by retrieving relevant API documentation and using it to guide code generation, effectively "teaching" the model to use unseen libraries on the fly.

Introduction: The Challenge of Private APIs

Current code generation models are "data-hungry"—they perform remarkably well on libraries like pandas or numpy because those libraries appear in millions of public GitHub files. However, in the real world, developers frequently use private libraries (internal to a company) or very new libraries that were released after the model's training cutoff.

Because these APIs are absent from the training data, the models have no "memory" of their syntax or behavior. The authors identify a significant performance gap: even a giant model like Codex 12B sees its success rate (pass@1) plummet from nearly 19% to less than 2% when a public library is "disguised" as a private one. The challenge is: how can we equip LLMs to use libraries they have never seen before?

Performance drop on disguised libraries (MonkeyEval) compared to public ones (PandasEval).

The APICoder Framework

The authors propose a two-stage framework called APICoder:

  1. APIRetriever: Since private libraries usually have documentation even if they lack public code examples, the authors built a dense retrieval system (using BERT). It takes the user's natural language requirement and searches the library's documentation to find the most relevant API signatures and descriptions.
  2. APICoder (The Generator): This module takes the retrieved API information and prepends it to the code prompt. To make this more effective, the authors performed continual pre-training on a base model (CodeGen-Mono 350M) using public code. During this training, they explicitly inserted API documentation into the code files, teaching the model the relationship between a documentation string and the actual code implementation. This specialized version is called CodeGenAPI.
The APICoder pipeline, featuring the Dense Retriever and the Continual Pre-training process.

The framework also includes a "Human-in-the-loop" option, where a developer can select the correct API from a list of top-5 candidates suggested by the retriever, further boosting accuracy.

Experimental Setup and Benchmarks

The researchers used a massive corpus of 4.54M Python files from GitHub involving 31 popular libraries for training. To test the "private library" scenario, they created three new benchmarks:

  • TorchDataEval: Uses TorchData, a library released after the base models were trained, making it effectively "private" knowledge.
  • MonkeyEval: A "pseudo-private" benchmark created by taking the existing PandasEval and systematically renaming everything (e.g., pandas becomes monkey, DataFrame becomes KnowledgeFrame).
  • BeatNumEval: A similar "disguised" version of NumpyEval.

Results and Key Insights

  • Massive Gains on Unseen APIs: On the MonkeyEval benchmark, providing the correct API information boosted Codex 12B's pass@1 from 1.47% to 17.98%.
  • Documentation as a Bridge: The core insight is that while code examples for private libraries are scarce, documentation is usually available. By treating code generation as a retrieval-augmented task, we can bridge the knowledge gap.
  • The "Scaling Law" of Helpfulness: Interestingly, larger models benefit more from provided API information. For example, on TorchDataEval, providing API info improved Codex 12B’s performance by nearly 37 percentage points, while a smaller model only saw a tiny gain. This suggests that "smarter" models are better at following the instructions found in documentation.

Conclusion

While APICoder shows massive gains, it still depends on the base model's underlying logic. If a problem requires complex reasoning beyond the model's capability, documentation alone is insufficient. However, by treating the LLM as a student capable of reading a manual rather than just a static database of code, this research paves the way for more flexible AI coding assistants in specialized corporate environments.

Summary updated

BibTeX
@inproceedings{zan2022when,
  author = {Daoguang Zan and Bei Chen and Zeqi Lin and Bei Guan and Yongji Wang and Jian-Guang Lou},
  title = {{When Language Model Meets Private Library}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2022},
  doi = {10.18653/v1/2022.findings-emnlp.21},
}
Figure