arXiv · 2503.09020
Enhancing the Non-Functional Quality Compliance of LLM-Generated Code through Quality-Aware Preference Learning
Abstract
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.
Explore related subjects
Keep this discovery
Liang Lu, Yuan Jiang, Christoph Treude, Shuzheng Gao, Jingyu Xiao, Xiaohong Su, Michael R. Lyu. 2025-03-12. Enhancing the Non-Functional Quality Compliance of LLM-Generated Code through Quality-Aware Preference Learning. https://arxiv.org/abs/2503.09020
Cite the original work for its findings. Save a collection to share your selection of sources.