Introduction
Large Language Models (LLMs) have demonstrated remarkable proficiency in generating code for widely used programming languages like Python. However, their performance often falters when encountering specialized domains, internal corporate libraries, or niche languages underrepresented in training data. Traditionally, adapting models to these "long-tail" scenarios required computationally expensive fine-tuning. This paper investigates the potential of In-Context Learning (ICL) as a more agile alternative, exploring whether LLMs can learn to use entirely new code libraries or programming languages "on the fly" through various forms of prompt-based supervision.
Methodology
The researchers evaluated LLMs across three primary scenarios to test the limits of their in-context adaptability:
- Learning Novel Libraries: Using the VisProg library (20 Python modules for visual reasoning), the study compared three supervision modes: Demonstrations (input/output examples), Descriptions (natural language docstrings), and Implementations (the actual source code of the functions).
- Constrained Generation: Models were tasked with solving standard programming problems using a strictly restricted set of library functions. To prevent models from relying on pre-existing knowledge, the researchers employed aliasing, replacing standard function names with random strings (e.g., changing
sqrttofubba). - Learning a New Language: The study attempted to teach models Isabelle, a formal theorem-proving language, using only a description of its 12 core keywords to see if models could generate valid proofs from scratch.
Datasets and Benchmarks
The evaluation spanned several diverse benchmarks to ensure robust results:
- Visual Reasoning: Tasks included GQA (Visual Question Answering), NLVR (Reasoning over image pairs), Knowledge Tagging, and Image Editing.
- General Programming: 15,000 examples from CodeContests and APPS were curated specifically for the constrained generation task.
- Theorem Proving: The miniF2F dataset (specifically the algebra subset of MATH problems) served as the testing ground for Isabelle code generation.
Key Insights
The "Docstring" Advantage
A significant finding for high-end models like GPT-4 is that natural language descriptions (docstrings) are nearly as effective as full-blown code demonstrations. This suggests that for advanced models, providing a simple API manual is sufficient, removing the need for users to curate complex, expensive-to-create examples.
Pre-training and Learning Styles
Model performance and preference vary based on pre-training data. For instance, LLaMA-2 (trained mostly on text) proved more adept at learning from descriptions, whereas StarCoder (trained on code) performed significantly better when provided with raw implementations. This indicates that the optimal instruction format depends heavily on the model's foundational training.
The Prior Knowledge Trap
Interestingly, models often perform worse when forced to use specific functions for tasks they already "know" how to solve using standard libraries. Their strong internal priors for preferred coding patterns make it difficult to strictly adhere to new, restrictive constraints, even when clearly provided in the prompt.
Results
The experimental results highlight a clear hierarchy in model capabilities and the effectiveness of ICL:
- Library Learning: GPT-4 achieved approximately 51-52% accuracy on GQA tasks, showing consistent performance across all three supervision types.
- Constraint Following: GPT-4 successfully followed function constraints ~90% of the time, whereas GPT-3.5-Turbo struggled, adhering to constraints only ~20% of the time.
- New Language Mastery: GPT-4 maintained a 31.4% success rate in generating correct Isabelle proofs even when keywords were replaced with random aliases. This suggests the model learns the underlying logic and structure of the language from the prompt rather than just mapping familiar keywords.
Limitations and Future Work
While promising, the study notes several limitations. The focus was primarily on visual programming and theorem proving; results may differ in other niche areas like hardware description languages or legacy systems. Additionally, the use of GPT-4 to generate some of the descriptions used in the "constrained" dataset might introduce a self-referential bias. Future research will focus on helping models overcome strong priors to better follow strict coding constraints in professional software environments.
Summary updated