arXivDaily arXiv每日学术速递 周一至周五更新
arXiv周末暂无论文更新,休息一下吧,周末愉快~~
arXiv 2503.09020cs.SEcs.AI
收藏

通过质量感知偏好学习增强大语言模型生成代码的非功能质量合规性

Enhancing the Non-Functional Quality Compliance of LLM-Generated Code through Quality-Aware Preference Learning

School of Computer Science and Technology, Harbin Institute of Technology(哈尔滨工业大学计算机科学与技术学院);School of Computing and Information Systems, Singapore Management University(新加坡管理大学计算与信息系统学院)

Liang Lu, Yuan Jiang, Christoph Treude, Jingyu Xiao, Xiaohong Su, Michael R. Lyu

AI总结:

针对LLM生成代码存在的非功能质量合规性问题,提出质量感知偏好学习框架,通过三阶段方法提升代码合规性,在保持功能正确的同时实现显著性能提升,具备良好实用价值。

摘要:

大语言模型(LLMs)已被广泛应用于商业代码补全引擎,显著提升了编码效率与生产力。然而,即便在功能上正确的LLM生成代码,也可能存在违反编码标准和最佳实践的非功能质量问题,例如风格不佳、可维护性有限。为解决该问题,我们提出一种质量感知偏好学习框架,引导LLM生成符合标准的代码。该方法包含三个阶段:第一,构建由违反标准样本与合规样本组成的数据集,每对样本包含存在特定非功能质量问题的代码,以及修复该问题的对应代码;第二,设计自适应令牌加权机制,以突出质量敏感的代码区域;第三,引入混合优化目标,将排序损失与语言建模损失、KL散度相结合,实现有效的对比优化。在DeepSeek-Coder和Qwen2.5-Coder上开展的大量实验表明,我们的方法在保持功能正确性的同时,大幅提升了目标非功能质量标准的合规性,在MBPP-sanitized数据集上,Qwen2.5-Coder的质量倒数分数(QRS)实现了75.7%的相对提升;微调7B模型所需时间不足3小时,具备较强的实用可行性; ablation研究和用户研究进一步验证了所提框架的有效性。

英文摘要:

Large Language Models (LLMs) have been widely adopted in commercial code completion engines, significantly enhancing coding efficiency and productivity. However, even functionally correct LLM-generated code may exhibit non-functional quality issues that violate coding standards and best practices, such as poor style and limited maintainability. To address this, we propose a framework for quality-aware preference learning that guides LLMs toward generating criteria-compliant code. Our approach consists of three phases. First, we construct a dataset of paired criteria-violating and criteria-compliant samples, where each pair contains code exhibiting a specific non-functional quality issue and its repaired version that resolves the issue. Second, we design an adaptive token weighting mechanism to emphasize quality-sensitive code regions. Third, we introduce a hybrid optimization objective that combines ranking loss with language modeling loss and KL divergence to enable effective comparative optimization. Extensive experiments on DeepSeek-Coder and Qwen2.5-Coder show that our method substantially improves compliance with the targeted non-functional quality criteria while maintaining functional correctness, achieving a 75.7% relative increase in Quality Reciprocal Score (QRS) on MBPP-sanitized for Qwen2.5-Coder. Fine-tuning a 7B model requires less than three hours, indicating strong practical viability. Ablation studies and a user study further support the effectiveness of the proposed framework.

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

↑