arXivDaily arXiv每日学术速递 周一至周五更新
感恩节,周五至周末无更新,大家顺遂。周一再来吧
arXiv 2412.18035cs.SE
收藏

使用强化学习准确地生成重构代码

Generating refactored code accurately using reinforcement learning

Indranil Palit, Tushar Sharma

AI总结:

针对当前自动化提取方法重构依赖人工且缺乏语义理解的局限,提出一种基于强化学习PPO算法微调和对齐代码语言模型的方法,显著提升了Java代码重构的准确性与功能正确性。

摘要:

自动化源代码重构,尤其是提取方法重构,是软件开发过程中一项关键且被频繁使用的技术。尽管它对从业者很重要且被频繁使用,但当前的自动化技术面临着显著的局限性。这些方法通常依赖于开发者根据源代码语句来识别重构机会的精确边界。此外,它们往往无法捕捉语义上下文,例如导致无法提供自动化手段来建议有意义的方法名。为了应对这些挑战,我们提出了一种基于强化学习的新颖方法,用于微调和对齐代码语言模型,以对Java源代码执行自动化、智能的提取方法重构。我们的方法微调序列到序列的生成式模型,并使用近端策略优化(PPO)算法对其进行对齐。我们利用代码编译情况以及生成代码中是否存在重构作为奖励信号,提供了一个以代码为中心的优化过程。我们的实验表明,我们的方法显著增强了大型语言模型在代码重构中的性能,BLEU、ROUGE和CodeBLEU等定量评估指标以及语法和功能正确性等定性指标均证实了这一点。经过监督微调并进一步与PPO对齐的模型,在BLEU和CodeBLEU分数上分别比传统的监督微调方法提升了11.96%和16.45%。在执行包含122个单元测试的测试套件时,经过强化学习对齐的微调Code-T5模型,其成功测试的数量从41个增加到了66个,突显了我们的方法在生成功能正确的重构方面的有效性。

英文摘要:

Automated source code refactoring, particularly extract method refactoring, is a crucial and frequently employed technique during software development. Despite its importance and frequent use by practitioners, current automated techniques face significant limitations. These approaches often rely on developers to identify the precise bounds of refactoring opportunities in terms of source code statements. Also, they often do not capture the semantic context, resulting in offering no automated means to suggest meaningful method name, for instance. To address these challenges, we propose a novel reinforcement learning-based approach for fine-tuning and aligning code language models to perform automated, intelligent extract method refactoring on Java source code. Our approach fine-tunes sequence-to-sequence generative models and aligns them using the Proximal Policy Optimization (PPO) algorithm. We utilize code compilation and presence of the refactoring in the generated code as reward signals, providing a code-centric optimization process. Our experiments demonstrate that our approach significantly enhances the performance of large language models in code refactoring, as evidenced by both quantitative evaluation metrics such as BLEU, ROUGE, and CodeBLEU, and qualitative measures including syntactical and functional correctness. The supervised fine-tuned model, further aligned with PPO, surpasses traditional supervised fine-tuning by 11.96% and 16.45% in terms of BLEU and CodeBLEU scores, respectively. When subjected to a suite of 122 unit tests, the number of successful tests increased from 41 to 66 for the reinforcement learning aligned fine-tuned Code-T5 model, highlighting the effectiveness of our approach in producing functionally correct refactorings.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑