Large Language Models (LLMs) exhibit remarkable code generation capabilities but falter when adapting to frequent updates in external library APIs. This critical limitation, stemming from reliance on outdated API knowledge from their training data, even with access to current documentation, impedes reliable code generation in dynamic environments. To tackle this issue, we propose ReCode (rule-based Reinforcement learning for Code Update), a novel framework that mimics human programmer adaptation to API changes. Specifically, we construct a dataset of approximately 2,000 data entries to train the LLMs to perform version migration based on updated information. Then, we introduce a modified string similarity metric for code evaluation as the reward for reinforcement learning. Our experiments demonstrate that ReCode substantially boosts LLMs' code generation performance in dynamic API scenarios, especially on the unseen CodeUpdateArena task. Crucially, compared to supervised fine-tuning, ReCode has less impact on LLMs' general code generation abilities. We apply ReCode on various LLMs and reinforcement learning algorithms (GRPO and DAPO), all achieving consistent improvements. Notably, after training, Qwen2.5-Coder-7B outperforms that of the 32B parameter code instruction-tuned model and the reasoning model with the same architecture. Code is available at https://github.com/zjunlp/ReCode.


翻译:大语言模型(LLMs)展现出卓越的代码生成能力,但在适应外部库API的频繁更新时表现不佳。这一关键局限性源于模型对训练数据中过时API知识的依赖,即使能够访问最新文档,也阻碍了其在动态环境中可靠生成代码。为解决此问题,我们提出了ReCode(基于规则的代码更新强化学习),这是一个模拟人类程序员适应API变化的新型框架。具体而言,我们构建了一个包含约2000条数据条目的数据集,用于训练LLMs基于更新信息执行版本迁移。随后,我们引入一种改进的字符串相似度度量作为代码评估的奖励函数,用于强化学习。实验表明,ReCode显著提升了LLMs在动态API场景下的代码生成性能,尤其是在未见过的CodeUpdateArena任务上。关键的是,与监督微调相比,ReCode对LLMs的通用代码生成能力影响更小。我们在多种LLMs和强化学习算法(GRPO和DAPO)上应用ReCode,均取得了一致的改进。值得注意的是,训练后,Qwen2.5-Coder-7B的性能超越了参数规模为32B的代码指令微调模型以及相同架构的推理模型。代码发布于https://github.com/zjunlp/ReCode。

0
下载
关闭预览

相关内容

代码(Code)是专知网的一个重要知识资料文档板块,旨在整理收录论文源代码、复现代码,经典工程代码等,便于用户查阅下载使用。
【NeurIPS2024】TableRAG:基于语言模型的百万标记表格理解
专知会员服务
37+阅读 · 2024年10月8日
《用于代码弱点识别的 LLVM 中间表示》CMU
专知会员服务
14+阅读 · 2022年12月12日
ICLR'21 | GNN联邦学习的新基准
图与推荐
12+阅读 · 2021年11月15日
【NeurIPS2019】图变换网络:Graph Transformer Network
国家自然科学基金
17+阅读 · 2017年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
46+阅读 · 2015年12月31日
国家自然科学基金
8+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
VIP会员
相关基金
国家自然科学基金
17+阅读 · 2017年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
46+阅读 · 2015年12月31日
国家自然科学基金
8+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
Top
微信扫码咨询专知VIP会员