Large Language Model-Aware In-Context Learning for Code Generation
作者: Jia Li, Ge Li, Chongyang Tao, Jia Li, Huangzhao Zhang, Fang Liu, Zhi Jin
分类: cs.SE, cs.CL
发布日期: 2023-10-15
💡 一句话要点
提出LAIL以优化代码生成中的示例选择问题
🎯 匹配领域: 支柱二:RL算法与架构 (RL & Architecture) 支柱九:具身大模型 (Embodied Foundation Models)
关键词: 大型语言模型 代码生成 上下文学习 示例选择 对比学习 生成概率 机器学习
📋 核心要点
- 现有的代码生成方法在示例选择上存在随机性和文本相似性不足的问题,导致性能不理想。
- 本文提出LAIL方法,通过利用LLMs的生成概率来评估和标记候选示例,从而优化示例选择过程。
- 在MBJP、MBPP和MBCPP等数据集上,LAIL在CodeGen和GPT-3.5上分别提升了11.58%和4.38%的Pass@1性能。
📝 摘要(中文)
大型语言模型(LLMs)在代码生成中的上下文学习(ICL)能力表现出色。现有研究发现,ICL受示例的影响较大,导致示例选择成为研究热点。然而,现有方法往往随机选择示例或仅考虑文本相似性,导致性能不佳。本文提出了一种新颖的基于学习的选择方法LAIL(LLM-Aware In-context Learning),通过利用LLMs自身来评估候选示例,并基于生成概率进行标记。通过对标记数据的对比学习目标进行训练,LAIL在三种代表性数据集上超越了当前最先进的基线,显示出显著的性能提升。
🔬 方法详解
问题定义:本文旨在解决现有代码生成方法中示例选择的不足,现有方法往往随机选择示例或仅基于文本相似性,导致生成效果不佳。
核心思路:LAIL方法通过利用大型语言模型自身的生成概率来评估候选示例的有效性,依据生成的真实程序概率进行标记,从而实现更优的示例选择。
技术框架:LAIL的整体架构包括候选示例的生成、生成概率的评估、示例的标记(正负样本)以及基于标记数据的对比学习训练模块。
关键创新:LAIL的创新在于通过LLMs的生成概率反馈来进行示例选择,这一方法与传统的随机选择或简单相似性计算有本质区别,能够更准确地捕捉LLMs的偏好。
关键设计:在参数设置上,LAIL采用对比学习目标来优化示例选择,损失函数设计上注重正负样本的平衡,网络结构则基于现有的LLMs进行微调和训练。
🖼️ 关键图片
📊 实验亮点
实验结果表明,LAIL在CodeGen上相较于最先进的基线提升了11.58%、6.89%和5.07%的Pass@1,在GPT-3.5上则提升了4.38%、2.85%和2.74%。这些结果表明LAIL在代码生成任务中具有显著的性能优势。
🎯 应用场景
该研究的潜在应用领域包括自动代码生成、智能编程助手和软件开发工具等。通过优化示例选择,LAIL能够提升代码生成的准确性和效率,具有广泛的实际价值和未来影响力,尤其在提高开发者生产力和减少编程错误方面。
📄 摘要(原文)
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.