Introduction
Large Language Models (LLMs) have demonstrated impressive capabilities in generating code from natural language prompts. However, traditional training methods—primarily next-token prediction via supervised learning—often fail to capture the functional requirements of code. A snippet of code is only useful if it executes correctly and satisfies the intended logic. Reinforcement Learning (RL) offers a solution by using execution results as reward signals. Yet, RL is notoriously data-intensive, and high-quality datasets that pair natural language descriptions with functional unit tests are rare. This paper addresses these challenges through a dual approach: an automated pipeline for unit test generation and a stable Actor-Critic RL framework.
Methodology
Automated Unit Test Generation
To overcome data scarcity, the authors developed a cross-language data augmentation pipeline. Recognizing that generating unit tests is more straightforward in strongly-typed languages like Java, they leveraged the EvoSuite framework to extract tests from existing Java repositories. These Java function signatures and tests were then converted into Python equivalents, creating a high-quality dataset of over 2,200 training instances. This approach effectively bridges the gap between the abundance of Java code and the need for structured Python synthesis data.
Actor-Critic Reinforcement Learning
The core of the training framework is a streamlined Actor-Critic model designed to optimize code generation based on functional correctness.
- The Actor: A pre-trained LLM (specifically PanGu-Coder) serves as the policy, generating code candidates.
- The Critic: A two-layer Multi-Layer Perceptron (MLP) is built upon the frozen hidden states of the LLM. It estimates the expected reward (value) for a given code snippet.
- Reward Mechanism: The model receives a sparse reward based on the percentage of unit tests passed. To maintain stability and prevent the model from deviating too far from natural language coherence, a KL-divergence penalty is applied.
- Replay Buffer: A buffer stores successful solutions, ensuring the model continues to learn from its best historical performances and maintains diversity in its outputs.
Experimental Setup
The proposed methods were evaluated on two primary benchmarks:
- MBPP (Mostly Basic Python Problems): The primary benchmark for training and evaluation, consisting of 964 instances.
- HumanEval: Used for out-of-domain evaluation to assess the model's generalization capabilities to unseen problems.
- Augmented Dataset: The authors' custom dataset derived from 100k Java pairs, resulting in 2,229 high-quality Python training instances after filtering.
Results and Discussion
The performance was measured using the pass@k metric, which calculates the probability that at least one of the top k generated samples passes all unit tests.
Performance Gains
The "Ours+All" model, which incorporates both the RL framework and the augmented data, showed significant improvements. On the MBPP benchmark, it achieved a 29.2% greedy accuracy, a substantial jump from the 22.0% of the original pre-trained model.
Comparison with Baselines
As shown in the results table, the proposed approach outperformed established RL methods. While standard PPO reached 27.2% and the more complex CodeRL reached 25.2% on MBPP, this method's simpler Critic-based approach proved more effective. Furthermore, the model demonstrated strong generalization on the HumanEval dataset, particularly in the pass@100 metric (45.9%), suggesting it learned robust problem-solving strategies rather than simple pattern matching.
Qualitative Insights
Analysis of the generated code indicates that the RL-tuned model tends to produce more "Pythonic" solutions. It shows a preference for efficient built-in constructs like list comprehensions. The Critic appears to assign higher values to these idiomatic patterns, even when multiple solutions are functionally equivalent, indicating that the RL process captures quality nuances beyond simple binary pass/fail signals.
Conclusion and Future Work
This research demonstrates that combining automated cross-language data augmentation with a stable Actor-Critic RL framework can significantly enhance code synthesis performance. While the current work focuses on function-level Python code, future efforts will aim to address the challenges of class-level and project-level synthesis, where rewards are even sparser and the engineering complexity of test generation increases.
Summary updated