Although Large Language Models (LLMs) have made significant progress in code generation, they still struggle with code generation tasks in specific scenarios. These scenarios usually necessitate the adaptation of LLMs to fulfill specific needs, but the limited training data available in practice leads to poor code generation performance. How to effectively adapt LLMs to new scenarios with fewer training samples is a major challenge for current code generation. In this paper, we propose a novel adaptation approach named SEED, which stands for Sample-Efficient adaptation with Error-Driven learning for code generation. SEED leverages the errors made by LLMs as learning opportunities, using error revision to overcome its own shortcomings, thus achieving efficient learning. Specifically, SEED involves identifying error code generated by LLMs, employing Self-revise for code revision, optimizing the model with revised code, and iteratively adapting the process for continuous improvement. Experimental results show that, compared to traditional fine-tuning approaches, SEED achieves superior performance with fewer training samples, showing a relative improvement of 27.2%-325.0% in Pass@1. We also validate the effectiveness of Self-revise, which generates revised code that optimizes the model more efficiently compared to the code samples from datasets. Moreover, SEED consistently demonstrates strong performance across various LLMs, underscoring its generalizability.
翻译:摘要:尽管大语言模型(LLMs)在代码生成领域取得了显著进展,但在特定场景下的代码生成任务中仍面临挑战。这类场景通常需要针对具体需求对LLMs进行适配优化,然而实践中可用的训练数据有限,导致代码生成性能欠佳。如何利用更少的训练样本高效地将LLMs适配至新场景,是当前代码生成领域面临的主要挑战。本文提出一种名为SEED的新型自适应方法,即面向代码生成的样本高效错误驱动学习(Sample-Efficient adaptation with Error-Driven learning)。SEED方法将LLMs产生的错误转化为学习契机,通过错误修正机制克服模型自身缺陷,从而实现高效学习。具体而言,SEED包含以下步骤:识别LLMs生成的错误代码,采用自我修正(Self-revise)机制进行代码修订,利用修正后的代码优化模型,并通过迭代适配过程实现持续改进。实验结果表明,相较于传统微调方法,SEED在更少训练样本条件下实现了更优性能,在Pass@1指标上获得27.2%-325.0%的相对提升。我们还验证了自我修正机制的有效性——与数据集中的代码样本相比,该机制生成的修订代码能更高效地优化模型。此外,SEED在不同LLMs上均展现出稳定优异的性能,充分证明了其泛化能力。