VERSE: Verification-based Self-Play for Code Instructions

Hao Jiang, Qi Liu, Rui Li, Yuze Zhao, Yixiao Ma, Shengyu Ye, Junyu Lu, Yu SuAAAI 2025

Abstract

Instruction-tuned Code Large Language Models (Code LLMs) have excelled in diverse code-related tasks, such as program synthesis, automatic program repair, and code explanation. To collect training datasets for instruction-tuning, a popular method involves having models autonomously generate instructions and corresponding responses. However, the direct generation of responses does not ensure functional correctness, a crucial requirement for generating responses to code instructions. To overcome this, we present Verification-Based Self-Play (VERSE), aiming to enhance model proficiency in generating correct responses. VERSE establishes a robust verification framework that covers various code instructions. Employing VERSE, Code LLMs engage in self-play to generate instructions and corresponding verifications. They evaluate execution results and self-consistency as verification outcomes, using them as scores to rank generated data for self-training. Experiments show that VERSE improves multiple base Code LLMs (average 7.6%) across various languages and tasks on many benchmarks, affirming its effectiveness.

Introduction: The Challenge of Functional Correctness

Instruction tuning is the critical step that transforms a base model into a capable coding assistant. A common technique for this is Self-Instruct, where a powerful model generates its own instructions and responses to build a training corpus. However, code differs fundamentally from natural language. While a poem or an essay can be judged on subjective quality, code is binary: it either functions correctly or it does not.

Existing self-instruction methods often overlook functional correctness. If a model trains on a massive synthetic dataset where a significant portion of the examples contain logic errors, it effectively learns to hallucinate bugs. The difficulty lies in the fact that not all code instructions are easily executable (e.g., "Explain this snippet"), and if the model itself is writing the tests, there is a risk that the tests themselves are flawed.

The VERSE Framework

To address these issues, we introduce VERSE (Verification-based Self-Play), a framework that treats verification as a primary component of the data generation process. The pipeline consists of four distinct stages:

  1. Automatic Data Generation: The model generates an instruction $x$, multiple candidate responses $y$, verification ideas $v$, and test scripts $t$.
  2. Cross-Modal Verification: For non-executable responses like code explanations, VERSE uses a "grounding" technique. It asks the model to generate code based on the explanation and then verifies if that code's behavior matches the original snippet.
  3. Consistency-driven Ranking: VERSE evaluates both execution-based consistency (does the code pass the test?) and equivalence-based consistency (do different correct-looking responses produce the same output?).
  4. Scoring & Training: Data pairs are assigned a verification score $R(y|x)$ based on execution results and consensus. The model then undergoes Rejection Sampling Fine-Tuning on the highest-quality data.
The VERSE pipeline: from data generation to execution-based ranking and training.

Experimental Evaluation

We generated a dataset of 100,000 instructions, filtered down to 40,000 high-quality verified pairs. We evaluated VERSE across several benchmarks, including BigCloneBench (Clone Detection), Devign (Defect Detection), and HumanEval (Synthesis, Repair, and Explanation).

Key Results

The results demonstrate that "verifying before learning" provides substantial performance boosts:

  • Broad Performance Gains: VERSE improved base models like CodeLlama and DeepSeek-Coder by an average of 7.6% across all tasks.
  • Clone Detection Breakthrough: On the BigCloneBench task, CodeLlama-7B's F1 score increased from 12.8% to 39.2%.
  • Outperforming Official Baselines: In several instances, 7B models trained via VERSE outperformed the official instruction-tuned versions of those same models.
  • Distillation Efficacy: Data verified by a 7B model successfully boosted a 1.3B model's performance by 7.1%, highlighting VERSE's utility for knowledge distillation.
Performance comparison of VERSE against base models and other instruction-tuning methods across multiple benchmarks.

Insights and Discussion

VERSE highlights the power of consensus as a proxy for truth. If multiple independent responses lead to the same execution behavior, the data is likely reliable. Furthermore, the framework's ability to ground abstract text (explanations) back into executable code allows for a closed-loop verification of natural language responses.

However, limitations remain. VERSE relies on a sandbox environment, which can struggle with complex external dependencies or multi-file architectures. Additionally, while the model excels at fixing syntax, it still finds it difficult to generate or detect the kind of subtle logic errors typically made by humans. Future work will focus on expanding the sandbox capabilities and improving the model's grasp of nuanced human-like defects.

Summary updated

BibTeX
@inproceedings{jiang2025verse,
  author = {Hao Jiang and Qi Liu and Rui Li and Yuze Zhao and Yixiao Ma and Shengyu Ye and Junyu Lu and Yu Su},
  title = {{VERSE: Verification-based Self-Play for Code Instructions}},
  booktitle = {AAAI Conference on Artificial Intelligence},
  year = {2025},
  url = {https://openreview.net/forum?id=zCSfeLuHSS},
}
Figure