ReCode: 強化学習を用いたコードAPI知識の更新
ReCode: Updating Code API Knowledge with Reinforcement Learning
June 25, 2025
著者: Haoze Wu, Yunzhi Yao, Wenhao Yu, Huajun Chen, Ningyu Zhang
cs.AI
要旨
大規模言語モデル(LLMs)は、コード生成において顕著な能力を示すが、外部ライブラリAPIの頻繁な更新に適応する際に課題を抱えている。この重要な制限は、最新のドキュメントにアクセスできる場合でも、トレーニングデータに基づく古いAPI知識への依存から生じ、動的な環境での信頼性のあるコード生成を妨げている。この問題に対処するため、我々はReCode(ルールベースの強化学習によるコード更新)を提案する。これは、人間のプログラマがAPIの変更に適応するプロセスを模倣する新しいフレームワークである。具体的には、約2,000のデータエントリからなるデータセットを構築し、LLMsが更新された情報に基づいてバージョン移行を実行できるようにトレーニングする。次に、コード評価のための修正された文字列類似度メトリックを導入し、強化学習の報酬として使用する。実験結果は、ReCodeが動的APIシナリオにおけるLLMsのコード生成性能を大幅に向上させることを示しており、特に未見のCodeUpdateArenaタスクにおいて顕著である。重要な点として、教師あり微調整と比較して、ReCodeはLLMsの一般的なコード生成能力に与える影響が少ない。我々はReCodeを様々なLLMsおよび強化学習アルゴリズム(GRPOおよびDAPO)に適用し、一貫した改善を達成した。特に、トレーニング後、Qwen2.5-Coder-7Bは、32Bパラメータのコード命令チューニングモデルおよび同じアーキテクチャの推論モデルを上回る性能を示した。コードはhttps://github.com/zjunlp/ReCodeで公開されている。
English
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.