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

Liang Lu, Yuan Jiang, Christoph Treude, Jingyu Xiao, Xiaohong Su +1 more
3/12/2025
cs.SEcs.AI

No confident code implementation found for this paper.

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.

Show full abstract

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.

View on arXivView PDF

Code Implementations

No confident code match yet

We couldn't find an author-owned or strongly-evidenced community implementation for this paper. Any repos shown below are weak matches — verify before relying on them.

No code implementations found yet.

Know of an implementation? Let us know in the comments below!

Similar Papers

Cite this paper

@article{lu2025enhancing,
  title  = {Enhancing the Non-Functional Quality Compliance of LLM-Generated Code through Quality-Aware Preference Learning},
  author = {Liang Lu and Yuan Jiang and Christoph Treude and Jingyu Xiao and Xiaohong Su and Michael R. Lyu},
  year   = {2025},
  eprint = {2503.09020},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2503.09020v5}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2503.09020.svg)](https://codeofpaper.com/paper/2503.09020)

Discussion