一句话:提出 Cedar,通过检索相似代码示例自动构建提示,提升代码少样本学习的测试断言生成与程序修复效果。
论文关注代码相关少样本学习中有效提示构建常被忽视的问题。作者提出 Cedar:给定自然语言指令与查询,基于嵌入或词频分析从代码库中自动检索与开发者任务相似的代码示例,作为少样本演示加入提示,无需任务特定微调。该方法在静态类型与动态类型两种语言、测试断言生成和程序修复两个任务上评估。结果显示,仅用少量相关示例,Cedar 在断言生成和程序修复的精确匹配准确率分别达 76% 与 52%;断言生成分别比任务特定模型和微调模型高 333% 与 11%,程序修复比任务特定模型高 189%,并与近期微调模型相当。结果表明其可低成本迁移到多语言、多任务场景。
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.