TL;DR
CodePivot is a new training framework that enables Large Language Models (LLMs) to translate code between diverse programming languages without requiring massive parallel datasets for every language pair. By using Python as a universal "pivot" language and a novel reinforcement learning reward that prioritizes partial functional correctness, a modest 7B-parameter model can outperform state-of-the-art giants like DeepSeek-R1 (671B) in complex transpilation tasks.
What Problem Does This Paper Address?
Transpilation—converting source code from one language to another—is essential for modernizing legacy systems and migrating to safer, more efficient platforms. While LLMs have shown promise here, they face a "data scarcity" wall.
Current training methods rely on a pairwise paradigm: to teach a model to translate between $N$ languages, you theoretically need $N(N-1)$ parallel datasets. This is a nightmare for low-resource languages (like Haskell or Perl) where high-quality parallel data is nearly non-existent. As shown in Figure 1, there is a direct correlation between how much data exists for a language on GitHub and how well a model performs in that language.
Furthermore, existing Reinforcement Learning (RL) approaches for code often use "sparse" rewards—either the code passes all tests or it gets nothing. This makes it incredibly difficult for a model to learn from its "almost correct" mistakes.
Methods
CodePivot introduces a two-stage training pipeline designed to bootstrap multilingual ability using only Python-to-Others data.
- Python-IR-Pivoted SFT: The researchers argue that instead of learning every possible language pair, the model should use a high-resource language (Python) as an Intermediate Representation (IR). They use a strong teacher model (Claude-3.5-Sonnet) to generate Python-to-Other-Language pairs, which are then used for Supervised Fine-Tuning (SFT). This aligns the logic of diverse languages into a shared latent space.
- APF-Reward Augmented RL: To refine the model, they use Group Relative Policy Optimization (GRPO) with a new Aggressive-Partial-Functional (APF) reward. Unlike standard rewards that only care if a program is 100% correct, the APF reward uses a concave function to give a significant "boost" to programs that pass even a few test cases. The intuition is that it’s much easier for a model to fix a "partially correct" program than to generate one from scratch.
Datasets
The authors constructed $D_{PY-TRANS}$, a massive file-level dataset containing ~1 million Python-to-Others transpilation tasks across 9 target languages (C++, C#, Java, JavaScript, Go, Perl, Ruby, Rust, and Haskell).
For evaluation, they introduced two rigorous benchmarks:
- Python-to-Others: 900 unique tasks across 9 target languages.
- Others-to-All: A comprehensive suite of 8.1K tasks testing the model's ability to translate between non-Python languages (e.g., Rust to Java) in a zero-shot manner.
Key Insights and Ideas
- Python as a "Pivot" is Highly Efficient: The study found that training on just 20K Python-to-Others pairs resulted in a model that outperformed one trained on 160K Any-to-Any pairs by 5.83%. This suggests that the structural and semantic richness of Python makes it a superior "bridge" for cross-lingual transfer.
- The Power of Partial Rewards: By rewarding "near misses" during RL, the model explores the solution space more effectively. The APF reward led to a 12.27% improvement over the SFT baseline, significantly higher than standard linear or discrete reward schemes.
- Zero-Shot Multilingualism: Even though the model was only trained to translate from Python to other languages, it successfully learned to translate between any two languages in the set (e.g., Perl to Haskell) without ever seeing a single parallel example of that specific pair during training.
Key Results
The resulting 7B model, based on Qwen2.5-Coder, achieved remarkable results:
- Beating the Giants: It outperformed DeepSeek-R1 (671B) by 5.34% on Python-to-Others tasks and Qwen3-235B by 15.19% on Others-to-All tasks.
- Low-Resource Excellence: On low-resource language tasks, CodePivot showed a 10.67% improvement over much larger mainstream models.
- State-of-the-Art Efficiency: It achieved the highest overall Pass@1 rate (64.67%) on the Python-to-Others benchmark among all evaluated open-source models, despite having hundreds of billions fewer parameters.
Limitations and Future Work
While CodePivot is a major step forward, the authors note a few limitations:
- Repository-Level Complexity: The current framework focuses on file-level transpilation. Real-world migration often involves complex multi-file structures and build systems (e.g., CMake, Maven) which are not yet addressed.
- Language Scope: The study was limited to 10 mainstream languages. Scaling this to hundreds of even more obscure languages remains an open question.
- Nondeterministic Programs: The current evaluation excludes nondeterministic code, which is common in concurrent or distributed systems.
Future work will look into applying the APF reward to broader code generation tasks and exploring other high-resource languages as potential IRs.
Summary updated