Retrieval-Based Prompt Selection for Code-Related Few-Shot Learning

被引:70
作者
Nashid, Noor [1 ]
Sintaha, Mifta [1 ]
Mesbah, Ali [1 ]
机构
[1] Univ British Columbia, Vancouver, BC, Canada
来源
2023 IEEE/ACM 45TH INTERNATIONAL CONFERENCE ON SOFTWARE ENGINEERING, ICSE | 2023年
关键词
Large Language Models; Transformers; Few-shot learning; Program repair; Test assertion generation;
D O I
10.1109/ICSE48619.2023.00205
中图分类号
TP31 [计算机软件];
学科分类号
081202 ; 0835 ;
摘要
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.
引用
收藏
页码:2450 / 2462
页数:13
相关论文
共 92 条
[1]  
Ahmad WU, 2021, 2021 CONFERENCE OF THE NORTH AMERICAN CHAPTER OF THE ASSOCIATION FOR COMPUTATIONAL LINGUISTICS: HUMAN LANGUAGE TECHNOLOGIES (NAACL-HLT 2021), P2655
[2]   A Survey of Machine Learning for Big Code and Naturalness [J].
Allamanis, Miltiadis ;
Barr, Earl T. ;
Devanbu, Premkumar ;
Sutton, Charles .
ACM COMPUTING SURVEYS, 2018, 51 (04)
[3]  
[Anonymous], 2022, CED
[4]  
Austin Jacob, 2021, PREPRINT
[5]  
Bei Chen, 2022, Arxiv, DOI arXiv:2207.10397
[6]  
Berabi B, 2021, PR MACH LEARN RES, V139
[7]  
Brown TB, 2020, ADV NEUR IN, V33
[8]   On Multi-Modal Learning of Editing Source Code [J].
Chakraborty, Saikat ;
Ray, Baishakhi .
2021 36TH IEEE/ACM INTERNATIONAL CONFERENCE ON AUTOMATED SOFTWARE ENGINEERING ASE 2021, 2021, :443-455
[9]  
Chen M., 2021, arXiv
[10]   Big Data Deep Learning: Challenges and Perspectives [J].
Chen, Xue-Wen ;
Lin, Xiaotong .
IEEE ACCESS, 2014, 2 :514-525