通过强化学习优化LLM代码生成的提示
Prompt Optimization for LLM Code Generation via Reinforcement Learning
AI总结:
本文提出了一种基于强化学习的框架,通过将提示优化视为序列决策问题,利用PPO代理结合直接生成、遗传词法突变和语义重写动作空间,指导由单元测试反馈获得的形状奖励,从而提升LLM代码生成的准确性。
摘要:
大型语言模型(LLM)能够从自然语言生成代码,但其性能对提示的制定非常敏感。我们提出了一种基于强化学习的框架,将提示优化视为序列决策问题。一个近端策略优化(PPO)代理通过混合动作空间,结合直接生成、遗传词法突变和语义重写,利用来自单元测试反馈的形状奖励来迭代改进提示。我们使用CodeT5+、CodeLLaMA和DeepSeek-Coder作为冻结的代码生成器,在MBPP+、HumanEval+和APPS上评估该框架。在包含500个任务的MBPP+测试集上,PPO代理分别达到了严格Pass@1分数57.58%、64.80%和85.50%,分别优于EPiC、Reflexion和Random-Hybrid。Soft-Pass@1分别达到67.90%、73.10%和88.20%。在HumanEval+和APPS上,所有基础模型都观察到类似改进。结果表明,使用形状测试驱动奖励的强化学习能够提高基于LLM的代码生成的功能正确性。
英文摘要:
Large Language Models (LLMs) can generate code from natural language, but their performance is highly sensitive to prompt formulation. We propose a reinforcement-learning-based framework that models prompt refinement as a sequential decision-making problem. A Proximal Policy Optimization (PPO) agent iteratively improves prompts using a hybrid action space that combines direct generation, genetic lexical mutation and semantic rewriting, guided by shaped rewards derived from unit-test feedback. We evaluate the framework on MBPP+, HumanEval+, and APPS using CodeT5+, CodeLLaMA, and DeepSeek-Coder as frozen code generators. On the 500-task MBPP+ test set, the PPO agent achieves strict Pass@1 scores of 57.58%, 64.80%, and 85.50%, respectively, outperforming EPiC, Reflexion, and Random-Hybrid. Soft-Pass@1 reaches 67.90%, 73.10%, and 88.20%, respectively. Similar improvements are observed on HumanEval+ and APPS across all backbone models. The results demonstrate that reinforcement learning with shaped test-driven rewards improves functional correctness in LLM-based code generation.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。