Exploration and Improvement of Capabilities of LLMs in Code Refinement Task

Zhipeng Wang, Tieke He, Ruoyu Zhao, Tao ZhengInt. J. Softw. Informatics 2025

Abstract

Large Language Models (LLMs) have demonstrated remarkable capabilities across various software engineering tasks. However, their performance in automated code refinement—specifically in scenarios without explicit reviewer guidance—remains inconsistent. This paper identifies a paradox where powerful LLMs often underperform smaller, specialized models due to an "aggressive" editing tendency. We introduce a new evaluation framework based on Unidiff metrics to quantify these behaviors and propose LLM-Voter, an ensemble method that utilizes confidence-based thresholding to improve refinement quality. Our results show that allowing models to "do nothing" when confidence is low significantly enhances stability and performance in pre-review tasks.

Introduction: Defining the Refinement Landscape

Automated code refinement is the process of improving code quality or fixing minor issues without human intervention. This task is generally categorized into two distinct scenarios:

  1. Code Refinement Before Review (CRB): The model acts as a first-pass refiner, attempting to improve the source code without any external hints or instructions.
  2. Code Refinement After Review (CRA): The model receives both the source code and specific comments from a reviewer, following instructions to fix identified issues.
Examples of Code Refinement Before Review (CRB) and After Review (CRA) tasks.

While LLMs like LLaMA3 excel in CRA tasks by following instructions precisely, they often struggle in CRB. In these "blind" scenarios, LLMs tend to be overly aggressive, making unnecessary changes that can introduce new bugs or break existing functionality. This behavior suggests that raw model power does not automatically translate to refinement accuracy.

The Evaluation Gap: Beyond BLEU

Traditional metrics like BLEU or CodeBLEU focus on n-gram overlap between the generated code and a ground-truth target. While useful for general similarity, they fail to explain why a model fails. A model might achieve a high BLEU score while still introducing a critical logic error through an unnecessary modification.

To address this, the authors propose a suite of Unidiff-based metrics that analyze the specific operations (Add, Delete, Modify) performed by the model:

  • Real Change Accuracy (RCA): Measures the proportion of model-generated changes that align with the ground truth.
  • Change Operation Positivity (COP): Quantifies the model's "eagerness" to change code. High COP in CRB often correlates with lower quality.
  • Refinement Progress (RP): Calculates the net improvement by subtracting "damage" (incorrect changes) from "gains" (correct changes).

Methodology: The LLM-Voter Framework

To mitigate the "aggressiveness" of LLMs, the researchers developed LLM-Voter, an ensemble approach designed to filter out low-quality refinements.

The research methodology flow, from identifying LLM disadvantages to proposing and verifying the LLM-Voter solution.

The framework consists of two primary sub-schemes:

  1. Inference-based Voting: A model is trained to predict the BLEU score of multiple candidate outputs, selecting the one with the highest expected quality.
  2. Confidence-based Thresholding: This mechanism calculates the joint probability of the generated sequence. If the model's confidence falls below a predefined threshold ($\alpha$), the system triggers a "refinement determination mechanism" that rejects the changes and retains the original code. This "do nothing" strategy is crucial for preventing the "hallucinated" improvements common in standalone LLMs.

Experimental Setup and Results

The study evaluated four mainstream LLMs and four small pre-trained models across two major datasets: the Java-specific Tuf dataset and the multilingual, line-level CRer (CodeReviewer) dataset.

Key Findings

  • LLM Aggressiveness: Unidiff metrics confirmed that LLMs have significantly higher COP than smaller models. In CRB tasks, this leads to a negative Refinement Progress (RP), as the "damage" from unnecessary edits outweighs the "gains."
  • Performance Gains: The Confidence-based LLM-Voter effectively bridged this gap. On the Tuf dataset, it achieved an Exact Match (EM) rate of 21.31%, outperforming both the best standalone LLM (20.49%) and the best small model (13.41%).
  • Metric Validation: The new Unidiff metrics showed a Pearson correlation of over 0.88 with human expert judgments, proving they are a more reliable proxy for code refinement quality than traditional overlap metrics.

Conclusion

The "aggressiveness" of LLMs in code refinement is a double-edged sword: a strength when following instructions (CRA) but a liability when acting autonomously (CRB). By shifting the evaluation focus to change-based metrics and implementing confidence-aware voting mechanisms, we can harness the power of LLMs while maintaining the stability required for production DevOps environments. Future work will explore whether these tendencies scale with model size and the impact of full-parameter fine-tuning.

Summary updated

BibTeX
@article{wang2025exploration,
  author = {Zhipeng Wang and Tieke He and Ruoyu Zhao and Tao Zheng},
  title = {{Exploration and Improvement of Capabilities of LLMs in Code Refinement Task}},
  journal = {Int. J. Softw. Informatics},
  year = {2025},
  doi = {10.21655/ijsi.1673-7288.00364},
}
Figure