[Paper Review] Code Generation Tools (Almost) for Free? A Study of Few-Shot, Pre-Trained Language Models on Code
The paper evaluates Codex-based few-shot tools for three code-generation tasks and compares them to manually built tools, finding that model-based tools can complement, match, or outperform traditional tools with significantly less development effort.
Few-shot learning with large-scale, pre-trained language models is a powerful way to answer questions about code, e.g., how to complete a given code example, or even generate code snippets from scratch. The success of these models raises the question whether they could serve as a basis for building a wide range code generation tools. Traditionally, such tools are built manually and separately for each task. Instead, few-shot learning may allow to obtain different tools from a single pre-trained language model by simply providing a few examples or a natural language description of the expected tool behavior. This paper studies to what extent a state-of-the-art, pre-trained language model of code, Codex, may serve this purpose. We consider three code manipulation and code generation tasks targeted by a range of traditional tools: (i) code mutation; (ii) test oracle generation from natural language documentation; and (iii) test case generation. For each task, we compare few-shot learning to a manually built tool. Our results show that the model-based tools complement (code mutation), are on par (test oracle generation), or even outperform their respective traditionally built tool (test case generation), while imposing far less effort to develop them. By comparing the effectiveness of different variants of the model-based tools, we provide insights on how to design an appropriate input ("prompt") to the model and what influence the size of the model has. For example, we find that providing a small natural language description of the code generation task is an easy way to improve predictions. Overall, we conclude that few-shot language models are surprisingly effective, yet there is still more work to be done, such as exploring more diverse ways of prompting and tackling even more involved tasks.
Motivation & Objective
- Assess whether few-shot, pre-trained language models can serve as general tools for code generation tasks across different categories.
- Compare model-based tools against manually built tools for code mutation, test oracle generation from natural language, and test case generation.
- Analyze how prompt design and model size influence the effectiveness of these tools.
Proposed method
- Apply a state-of-the-art code language model (Codex) to three tasks: code mutation, test oracle generation from natural language documentation, and test case generation.
- Prototype tool behavior using few-shot prompts and lightweight natural language descriptions.
- Compare model-based tools to traditional, manually built tools in terms of effectiveness and development effort.
- Investigate how prompt design variations and model size impact performance.
Experimental results
Research questions
- RQ1Can Codex-based few-shot tools match or exceed traditional tools for code mutation, test oracle generation, and test case generation?
- RQ2What is the impact of prompt design, including NL descriptions, on the quality of model-generated code across tasks?
- RQ3How does model size affect the effectiveness of few-shot, code-generation tools?
Key findings
- Model-based tools complement traditional code mutation tools.
- Model-based tools are on par with traditional tools for test oracle generation from natural language documentation.
- Model-based tools can outperform traditional tools for test case generation while requiring substantially less development effort.
- Providing a small natural language description of the task improves predictions.
- Different prompt variants and model sizes influence effectiveness, suggesting room for optimizing prompts and exploring larger/smaller models.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.