用程序分析反馈训练模型生成高质量代码,兼顾安全与可维护性。
Training Language Models to Generate Quality Code with Program Analysis Feedback
- 通过程序分析和单元测试提供自动化反馈,无需人工标注。
- 在多个数据集上同时提升代码功能正确性和质量,优于现有方法。
- 适合需要快速生成生产级代码的开发者或团队使用。
大型语言模型(LLMs)用于代码生成,常被称为“氛围编码”,虽在生产中广泛应用,但难以保证代码质量,尤其在安全性(如SQL注入漏洞)和可维护性(如缺少类型注解)方面。现有方法如监督微调和基于规则的后处理依赖人工标注或脆弱启发式规则,限制了其可扩展性和有效性。我们提出REAL,一种强化学习框架,利用程序分析引导的反馈激励LLM生成生产级代码。REAL整合两种自动化信号:(1) 程序分析检测安全或可维护性缺陷;(2) 单元测试确保功能正确性。不同于以往工作,该框架无需提示词或参考答案,实现无监督规模化训练。在多个数据集和模型规模下的实验表明,REAL在功能与代码质量双重评估中均优于当前最佳方法。本工作弥合了快速原型与生产就绪代码之间的差距,使LLM能同时实现速度与质量。
原文摘要 · Abstract (English)
Code generation with large language models (LLMs), often termed vibe coding, is increasingly adopted in production but fails to ensure code quality, particularly in security (e.g., SQL injection vulnerabilities) and maintainability (e.g., missing type annotations). Existing methods, such as supervised fine-tuning and rule-based post-processing, rely on labor-intensive annotations or brittle heuristics, limiting their scalability and effectiveness. We propose REAL, a reinforcement learning framework that incentivizes LLMs to generate production-quality code using program analysis-guided feedback. Specifically, REAL integrates two automated signals: (1) program analysis detecting security or maintainability defects and (2) unit tests ensuring functional correctness. Unlike prior work, our framework is prompt-agnostic and reference-free, enabling scalable supervision without manual intervention. Experiments across multiple datasets and model scales demonstrate that REAL outperforms state-of-the-art methods in simultaneous assessments of functionality and code quality. Our work bridges the gap between rapid prototyping and production-ready code, enabling LLMs to deliver both speed and quality.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。