Abstract
Migrating software between programming languages is a resource-intensive task traditionally handled by rule-based transpilers. Neural Machine Translation (NMT) offers a promising alternative but is hindered by a lack of high-quality parallel data. We present AVATAR, a parallel corpus of 9,515 programming problems with solutions in both Java and Python. Our evaluation of state-of-the-art models reveals that while they achieve high lexical similarity (BLEU), they struggle with functional correctness, particularly when translating full programs or moving from dynamic to static typing.
Introduction
Code migration—such as porting legacy systems to modern languages—is a multi-million dollar challenge. Unlike natural language, code requires absolute logical and syntactical precision. The scarcity of parallel datasets (the same logic implemented in two languages) has limited the application of NMT to this domain. AVATAR addresses this gap by providing a large-scale, diverse dataset for Java-Python translation.
The AVATAR Dataset
The researchers compiled AVATAR by crawling competitive programming platforms including AtCoder, Codeforces, and LeetCode. To ensure high-quality training data, they employed diversity filtering using the difflib library to select the five most distinct solutions for each problem. This ensures the models learn various ways to implement the same logic.
As shown in Figure 1, the dataset comprises 9,515 problems resulting in over 60,000 training pairs. Crucially, the authors included unit tests for a subset of the data to evaluate Computational Accuracy (CA)—a measure of whether the generated code actually passes functional tests.
Methodology
The study benchmarks several model architectures:
- Unsupervised/Zero-shot: TransCoder and DOBF, trained without explicit parallel data.
- Supervised NMT: Standard Transformers and LSTMs trained from scratch.
- Pre-trained Language Models (PLMs): CodeBERT, GraphCodeBERT, PLBART, and CodeT5.
The models were evaluated on both program-level translation (AVATAR) and function-level translation to understand how code complexity affects performance.
Results and Key Insights
The experimental results highlight a stark contrast between lexical metrics and functional performance.
The Lexical-Functional Gap
As seen in Figure 2, models like PLBART achieve impressive BLEU scores (e.g., 63.1 for Java to Python), yet their Computational Accuracy (CA) remains alarmingly low at 6.8%. This suggests that models are proficient at mimicking the "look" of code but often fail at the underlying logic—a phenomenon the authors describe as "coding by vibes."
Static vs. Dynamic Typing
Translating from Python to Java proved significantly more difficult than the reverse. Java’s static typing requires explicit declarations and boilerplate code (like imports and class structures) that models frequently omit or hallucinate. For instance, PLBART's CA dropped to a mere 0.8% when translating Python to Java, despite a high BLEU score of 69.7.
Structural Complexity
Models performed significantly better on individual functions than on full programs. The complexity of managing imports (e.g., java.util.Scanner) and class structures in full programs remains a major bottleneck for current NMT approaches. Performance degrades sharply as the length and structural requirements of the code increase.
Conclusion
AVATAR provides a rigorous benchmark for the code translation community. The findings underscore that high BLEU scores are not a proxy for working code. Future research should focus on "execution-guided" decoding—allowing models to test and fix their code during generation—to bridge the gap between lexical similarity and functional correctness.
Summary updated