一句话:系统实证示例的选择、顺序与数量三因素对代码智能任务中上下文学习的影响,并给出示例构造建议。
大语言模型的上下文学习(ICL)无需训练即可用于代码智能任务,但其效果高度依赖示例(demonstration)的质量,而如何为代码相关任务构造好示例尚缺乏系统研究。本文针对代码摘要、缺陷修复与程序合成三项任务,通过大量实验系统考察示例的选择、排序与数量这三个关键因素对ICL性能的影响。结果表明三者均显著影响效果;作者据此归纳出构造有效示例的发现与建议。采用该建议构造的示例相较广泛使用的示例构造方法取得显著提升:代码摘要的BLEU-4、缺陷修复与程序合成的EM分别至少提升9.90%、175.96%与50.81%。
Pre-trained models of source code have gained widespread popularity in many code intelligence tasks. Recently, with the scaling of the model and corpus size, large language models have shown the ability of in-context learning (ICL). ICL employs task instructions and a few examples as demonstrations, and then inputs the demonstrations to the language models for making predictions. This new learning paradigm is training-free and has shown impressive performance in various natural language processing and code intelligence tasks. However, the performance of ICL heavily relies on the quality of demonstrations, e.g., the selected examples. It is important to systematically investigate how to construct a good demonstration for code-related tasks. In this paper, we empirically explore the impact of three key factors on the performance of ICL in code intelligence tasks: the selection, order, and number of demonstration examples. We conduct extensive experiments on three code intelligence tasks including code summarization, bug fixing, and program synthesis. Our experimental results demonstrate that all the above three factors dramatically impact the performance of ICL in code intelligence tasks. Additionally, we summarize our findings and provide takeaway suggestions on how to construct effective demonstrations, taking into account these three perspectives. We also show that a carefully-designed demonstration based on our findings can lead to substantial improvements over widely-used demonstration construction methods, e.g., improving BLEU-4, EM, and EM by at least 9.90%, 175.96%, and 50.81% on code summarization, bug fixing, and program synthesis, respectively.
DOI 原文 · arXiv · PDF(开放获取) · DBLP
@inproceedings{GaoWGWZL23,
title = {What Makes Good In-Context Demonstrations for Code Intelligence Tasks with LLMs?},
author = {Shuzheng Gao and Xin-Cheng Wen and Cuiyun Gao and Wenxuan Wang and Hongyu Zhang and Michael R. Lyu},
booktitle = {ASE},
year = {2023},
doi = {10.1109/ase56229.2023.00109}
}