paperbot · PL 论文追踪

全部论文 待读 收藏

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

面向代码相关少样本学习的基于检索的提示选择
ICSE 2023 IEEE/ACM 45th International Conference on Software Engineering (ICSE)2023匹配度 2/10 · 该论文研究面向代码任务的少样本提示选择与检索,属于 LLM 提示工程/代码生成方向,而非用户重点关注的静态分析、Agentic 程序分析、浮点或贝叶斯程序分析,也不是用 LLM/Agent 改进静态分析或形式化验证。其目标主要是提升 LLM 在测试断言生成和程序修复上的少样本效果,与用户‘不感兴趣’的提示词技巧类 LLM 研究较接近。引用 171 inbox
Noor Nashid, Mifta Sintaha, Ali Mesbah
crossref: 2026-09-12dblp: 2026-09-12

AI 速览

一句话:提出 Cedar,通过检索相似代码示例自动构建提示,提升代码少样本学习的测试断言生成与程序修复效果。

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

问题
代码相关少样本学习依赖有效提示,但如何为不同语言和任务自动选择合适代码演示尚未得到充分研究。
方法
提出 Cedar,基于嵌入或频率分析检索与开发者任务相似的代码示例,自动构造包含自然语言指令、演示和查询的提示,无需任务特定训练。
评估
在测试断言生成与程序修复两个任务、静态与动态类型语言上评估,并与任务特定模型及微调模型比较精确匹配准确率。
原文摘要(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.

链接与引用

DOI 原文 · DBLP

BibTeX
@inproceedings{NashidSM23,
  title = {Retrieval-Based Prompt Selection for Code-Related Few-Shot Learning},
  author = {Noor Nashid and Mifta Sintaha and Ali Mesbah},
  booktitle = {ICSE},
  year = {2023},
  doi = {10.1109/icse48619.2023.00205}
}