[论文解读] Large Language Model-Aware In-Context Learning for Code Generation
本文提出 LAIL,一种基于学习的上下文示例选择方法,用于代码生成。该方法利用大型语言模型(LLMs)自身来评估并基于其对真实程序的生成概率,对候选示例进行评分与标注。通过在 LLM 提供的反馈上训练对比学习检索器,LAIL 实现了最先进性能,在 CodeGen 上相比基线模型 Pass@1 提升最高达 11.58%,在 GPT-3.5 上提升 4.38%,覆盖三个基准数据集。
Large language models (LLMs) have shown impressive in-context learning (ICL) ability in code generation. LLMs take a prompt consisting of requirement-code examples and a new requirement as input, and output new programs. Existing studies have found that ICL is highly dominated by the examples and thus arises research on example selection. However, existing approaches randomly select examples or only consider the textual similarity of requirements to retrieve, leading to sub-optimal performance. In this paper, we propose a novel learning-based selection approach named LAIL (LLM-Aware In-context Learning) for code generation. Given a candidate example, we exploit LLMs themselves to estimate it by considering the generation probabilities of ground-truth programs given a requirement and the example. We then label candidate examples as positive or negative through the probability feedback. Based on the labeled data, we import a contrastive learning objective to train an effective retriever that acquires the preference of LLMs in code generation. We apply LAIL to three LLMs and evaluate it on three representative datasets (e.g., MBJP, MBPP, and MBCPP). LATA outperforms the state-of-the-art baselines by 11.58%, 6.89%, and 5.07% on CodeGen, and 4.38%, 2.85%, and 2.74% on GPT-3.5 in terms of Pass@1, respectively.
研究动机与目标
- 为解决代码生成中上下文学习(ICL)的不稳定性问题,该问题严重依赖于所选示例的质量。
- 克服仅依赖文本相似度或随机采样等启发式方法在示例选择上的局限性。
- 开发一种基于学习的方法,以捕捉 LLM 对代码生成的内在偏好,实现有效的示例选择。
- 使用 LLM 生成的反馈数据,通过对比学习训练检索器,学习 LLM 对示例质量的偏好。
提出的方法
- 利用 LLM 自身来估算候选示例的质量,通过测量在给定需求和示例条件下,真实程序的生成概率。
- 设计一种新指标来量化该概率反馈,并根据得分将示例标记为正样本或负样本。
- 使用对比学习目标训练神经检索器,以学习 LLM 在代码生成中的偏好。
- 利用 LLM 反馈生成的标注数据优化检索器,使其能够检索出对 LLM 生成正确程序最有帮助的示例。
- 将训练好的检索器应用于新需求的上下文示例选择,从而提升 ICL 性能。
实验结果
研究问题
- RQ1LLM 自身能否提供可靠反馈,用于评估代码生成中上下文示例的质量?
- RQ2与基于 BM25 或随机选择的传统启发式方法相比,LLM 意识的示例选择在 ICL 性能上表现如何?
- RQ3基于 LLM 反馈训练的对比学习检索器是否能在不同 LLM 和数据集上实现泛化?
- RQ4所提出方法在多大程度上提升了 Pass@1 及其他代码生成指标?
主要发现
- LAIL 在 CodeGen 上使 Pass@1 提升 11.58%,在 MBJP 上提升 6.89%,在 MBPP 上提升 5.07%,在 GPT-3.5 上提升 4.38%,优于最先进基线模型。
- 该方法在不同 LLM 和数据集间表现出强泛化能力,表明其具有广泛适用性。
- 人工评估确认,LAIL 生成的示例在正确性、可读性和相关性方面均产生更高质量的代码。
- 与随机或 BM25 基础选择相比,该方法显著降低了性能方差,增强了 ICL 的稳定性。
- LAIL 依赖于 LLM 生成的反馈,使其比基于词汇相似度的方法更符合 LLM 的实际偏好。
- 对比学习目标有效捕捉了 LLM 的细微偏好,使示例选择效果优于启发式方法。
更好的研究,从现在开始
从阅读论文到最终审阅,大幅缩短您的研究时间。
无需绑定信用卡
本解读由 AI 生成,并经人工编辑审核。