Retrieval-Based Prompt Selection for Code-Related Few-Shot Learning
Authors:
Top Cited Papers
- 1 May 2023
- conference paper
- Published by Institute of Electrical and Electronics Engineers (IEEE)
- p. 2450-2462
Abstract
Large language models trained on massive code corpora can generalize to new tasks without the need for task-specific fine-tuning. In few-shot learning, these models take as input a prompt, composed of natural language instructions, a few instances of task demonstration, and a query and generate an output. However, the creation of an effective prompt for code-related tasks in few-shot learning has received little attention. We present a technique for prompt creation that automatically retrieves code demonstrations similar to the developer task, based on embedding or frequency analysis. We apply our approach, Cedar, to two different programming languages, statically and dynamically typed, and two different tasks, namely, test assertion generation and program repair. For each task, we compare Cedar with state-of-the-art task-specific and fine-tuned models. The empirical results show that, with only a few relevant code demonstrations, our prompt creation technique is effective in both tasks with an accuracy of 76% and 52% for exact matches in test assertion generation and program repair tasks, respectively. For assertion generation, Cedar outperforms existing task-specific and fine-tuned models by 333% and 11%, respectively. For program repair, Cedar yields 189% better accuracy than task-specific models and is competitive with recent fine-tuned models. These findings have practical implications for practitioners, as Cedar could potentially be applied to multilingual and multitask settings without task or language-specific training with minimal examples and effort.Keywords
This publication has 53 references indexed in Scilit:
- An Empirical Study on Learning Bug-Fixing Patches in the Wild via Neural Machine TranslationACM Transactions on Software Engineering and Methodology, 2019
- DeepDelta: learning to repair compilation errors2019
- DeepBugs: a learning approach to name-based bug detectionProceedings of the ACM on Programming Languages, 2018
- A Survey of Machine Learning for Big Code and NaturalnessACM Computing Surveys, 2018
- Deep Contextualized Word Representations2018
- QuixBugs: a multi-lingual program repair benchmark set based on the quixey challenge2017
- Big Data Deep Learning: Challenges and PerspectivesIEEE Access, 2014
- The Probabilistic Relevance Framework: BM25 and BeyondFoundations and Trends® in Information Retrieval, 2009
- Comparison and evaluation of code clone detection techniques and tools: A qualitative approachScience of Computer Programming, 2009
- Introduction to Information Retrieval2008