Iterative Self-training for Code Generation via Reinforced Re-ranking

Nikita Sorokin, Ivan Sedykh, Valentin MalykhECIR 2025 · DOI

Abstract

Generating high-quality code that solves complex programming tasks is challenging, especially with current decoder-based models that produce highly stochastic outputs. In code generation, even minor errors can easily break the entire solution. Leveraging multiple sampled solutions can significantly improve the overall output quality. One effective way to enhance code generation is by pairing a code generation model with a reranker model, which selects the best solution from the generated samples. We propose a novel iterative self-training approach for self-training reranker models using Proximal Policy Optimization (PPO), aimed at improving both reranking accuracy and the overall code generation process. Unlike traditional PPO approaches, where the focus is on optimizing a generative model with a reward model, our approach emphasizes the development of a robust reward/reranking model. This model improves the quality of generated code through reranking and addresses problems and errors that the reward model might overlook during PPO alignment with the reranker. Our method iteratively refines the training dataset by re-evaluating outputs, identifying high-scoring negative examples, and incorporating them into the training loop, boosting model performance. Our evaluation on the MultiPL-E dataset demonstrates that our 13.4B parameter model outperforms a 33B model in code generation quality while being three times faster. Moreover, it achieves performance comparable to GPT-4 and surpasses it in one programming language.

Introduction

Large Language Models (LLMs) have revolutionized automated code generation, yet they remain inherently stochastic. Because programming requires strict logical precision, a single misplaced character or incorrect syntax can render an entire solution useless. This sensitivity creates a significant performance gap between Pass@1 (the probability of a single generation being correct) and Pass@100 (the probability of finding a correct solution within 100 attempts).

While generating multiple candidates increases the likelihood of a correct solution existing in the pool, the challenge lies in selection. Existing "reranker" models often fail to distinguish between code that looks syntactically correct and code that is functionally sound. Furthermore, state-of-the-art verifiers like LEVER often require executing code against test cases during inference—a process that is computationally expensive and often impossible in environments where test cases are not provided. This paper introduces RewardRanker, an iterative self-training framework that optimizes the "judge" rather than just the "coder," achieving high-performance verification without the need for execution at inference time.

Methodology: The RewardRanker Framework

The core innovation of this work is an iterative pipeline designed to refine the RewardRanker model. The process moves beyond standard alignment by focusing on "hard negatives"—incorrect code samples that the model mistakenly assigns high reward scores.

The Five-Stage Pipeline

  1. Supervised Fine-Tuning (SFT): The base generator is trained on high-quality code samples to establish a strong foundational capability.
  2. Reward Model Training: A separate model is trained to score code outputs using a Bradley-Terry loss function, prioritizing correct solutions over incorrect ones based on ground-truth execution results.
  3. Proximal Policy Optimization (PPO): The generator is optimized to maximize the rewards provided by the reward model, aligning the generator's output with the judge's preferences.
  4. The Self-Training Cycle: Following PPO, the model generates a new set of solutions. These are evaluated against actual test cases. The system specifically identifies "hard negatives"—solutions that failed the test cases but received high scores from the reward model.
  5. Iterative Refinement: These hard negatives are incorporated back into the training set. The reward model is retrained to recognize these specific errors, and a new PPO cycle begins. This iterative loop ensures the judge constantly learns from its own blind spots.

Crucially, RewardRanker learns to identify code quality through its internal parameters during training. This allows it to function as a high-speed reranker at inference time without requiring code execution.

Experimental Setup

The models were trained and evaluated using a robust suite of datasets:

  • Training Data: A balanced dataset of 1.2 million samples from CodeContests and Codeforces. For alignment, the researchers utilized 2 million triplets consisting of a prompt, a preferred solution, and a disfavored solution.
  • Multi-language Evaluation: The MultiPL-E benchmark was used to test the model across 18 programming languages, including C++, Java, and PHP.
  • Python Evaluation: The MBPP (ManyBenchmarks for Python Programs) dataset, containing 974 programming problems, served as the primary Python benchmark.

Results and Discussion

Performance and Efficiency

The RewardRanker framework demonstrates that improving the judge is often more effective than scaling the generator. A 13.4B parameter setup (comprising a 6.7B generator and a 6.7B reranker) achieved an average score of 70.9% across MultiPL-E languages. This outperformed the significantly larger DeepSeek-Coder-Instruct 33B model, which scored 69.2%.

Beyond accuracy, the 13.4B model offers a significant efficiency advantage, operating roughly three times faster than the 33B alternative while delivering higher-quality code. This suggests that ensemble-like judge-generator architectures are more parameter-efficient than monolithic models.

Comparison with GPT-4 and LEVER

RewardRanker proved highly competitive with closed-source models. In C++, RewardRanker outperformed GPT-4 (79.2% vs 76.4%) and maintained comparable performance in languages like Python and Java. Additionally, on the MBPP benchmark, RewardRanker achieved 69.9%, surpassing the previous state-of-the-art verifier, LEVER (69.4%). Notably, RewardRanker achieved this without the inference-time execution overhead required by LEVER.

Conclusion

RewardRanker demonstrates that iterative self-training focused on hard negatives can significantly bridge the gap between code generation and verification. By teaching the reward model to recognize its own errors, the framework produces a highly efficient, execution-free reranker that rivals the performance of much larger models and proprietary systems like GPT-4.

Future work will focus on exploring additional domains for pretraining to improve generalization and investigating tighter integration between the RewardRanker and the PPO-based generation process to handle even more complex, multi-step coding tasks.

Summary updated

BibTeX
@inproceedings{sorokin2025iterative,
  author = {Nikita Sorokin and Ivan Sedykh and Valentin Malykh},
  title = {{Iterative Self-training for Code Generation via Reinforced Re-ranking}},
  booktitle = {ECIR},
  year = {2025},
  doi = {10.1007/978-3-031-88714-7\_21},
}
Figure