用小模型+强化学习修复大模型生成的代码错误
SLMFix: Leveraging Small Language Models for Error Fixing with Reinforcement Learning
- 用强化学习微调小模型,专门修复大模型生成的语法错误
- 在多个领域语言上静态验证通过率超95%
- 适合计算资源有限但需高质量代码的场景
近年来,大语言模型在多种编程语言的代码生成方面展现出强大能力。然而,即使最先进的大模型生成的程序仍存在语法错误且无法完成任务,尤其在低资源编程语言(LRPL)上表现更差。此外,高昂的训练成本使微调大模型在资源受限环境下不可行。本文提出SLMFix,一种新型代码生成流程:利用经过强化学习微调的小语言模型(SLM),修复大模型生成程序中的语法错误,以提升特定领域语言(DSL)的代码质量。具体地,我们在小模型上应用强化学习进行程序修复任务,奖励函数结合静态验证器和静态语义相似性度量。实验结果表明,该方法在多个DSL上均表现出色,静态验证通过率超过95%。值得注意的是,SLMFix显著提升了基础模型性能,在低资源编程语言上甚至优于7B参数模型的监督微调方法,展现了其作为传统微调替代方案的巨大潜力。
原文摘要 · Abstract (English)
Recent advancements in large language models (LLMs) have shown very impressive capabilities in code generation across many programming languages. However, even state-of-the-art LLMs generate programs that contains syntactic errors and fail to complete the given tasks, especially for low-resource programming languages (LRPLs). In addition, high training cost makes finetuning LLMs unaffordable with constrained computational resources, further undermining the effectiveness of LLMs for code generation. In this work, we propose SLMFix, a novel code generation pipeline that leverages a small language model (SLM) finetuned using reinforcement learning (RL) techniques to fix syntactic errors in LLM-generated programs to improve the quality of LLM-generated programs for domain-specific languages (DSLs). In specific, we applied RL on the SLM for the program repair task using a reward calculated using both a static validator and a static semantic similarity metric. Our experimental results demonstrate the effectiveness and generalizability of our approach across multiple DSLs, achieving more than 95% pass rate on the static validator. Notably, SLMFix brings substantial improvement to the base model and outperforms supervised finetuning approach even for 7B models on a LRPL, showing the potential of our approach as an alternative to traditional finetuning approaches.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。