NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

AVATAR: A Parallel Corpus for Java-Python Program Translation

Wasi Uddin Ahmad, Md Golam Rahman Tushar, Saikat Chakraborty, Kai-Wei Chang

TL;DR

This paper introduces AVATAR, a new, large-scale parallel corpus of Java and Python code for program translation. They demonstrate that while current neural models can achieve good lexical similarity, they still struggle significantly with generating functionally accurate code, highlighting a key challenge in automated code translation.

What Problem Does This Paper Address?

Migrating software from one programming language to another is a common but incredibly time-consuming and expensive task. Manually rewriting code requires deep expertise in both languages. While automated program translation (transpilation) offers a solution, it's been hampered by a lack of large, parallel datasets (source code and its equivalent in another language). This scarcity has pushed research towards unsupervised methods. However, the recent success of pre-trained language models (PLMs) for code suggests that supervised fine-tuning on parallel data could yield better results. The authors aim to address this by creating a substantial parallel corpus to facilitate supervised learning for Java-Python translation.

Methods

The core of this work is the creation of the AVATAR dataset. They collected programming problems and their solutions from various competitive programming sites, online platforms, and open-source repositories. To ensure quality and diversity, they filtered solutions to keep a maximum of five per problem that were maximally different from each other. They also included unit tests for a subset of the data to enable functional correctness evaluation, a crucial aspect often missing in previous benchmarks. For evaluation, they trained and fine-tuned various models, including those trained from scratch and pre-trained models like Seq2Seq+Attn., Transformer, CodeGPT, CodeBERT, GraphCodeBERT, PLBART, and CodeT5.

Datasets

The primary dataset introduced is AVATAR, a parallel corpus of 9,515 programming problems with corresponding Java and Python solutions. This dataset is split into training (7,133 problems), validation (476 problems), and test (1,906 problems) sets. Additionally, AVATAR includes unit tests for 250 examples to assess functional correctness. They also leverage the dataset released by Lachaux et al. (2020) for function translation evaluation.

Key Insights and Ideas

  • The "Functional Gap": The most striking finding is the significant discrepancy between lexical similarity (how much the translated code looks like the target code) and functional accuracy (whether it actually works correctly). Current models are decent at the former but fall short on the latter.
  • Importance of Unit Tests: The inclusion of unit tests in AVATAR is critical. It moves beyond simple syntactic or semantic matching to evaluate if the translated code behaves as expected, revealing the limitations of models that only optimize for surface-level code resemblance.
  • PLMs Still Struggle: Despite the power of pre-trained language models, fine-tuning them on AVATAR doesn't fully bridge the functional gap. This suggests that current PLMs might not fully capture the nuances of cross-language code equivalence.
  • Common Translation Errors: The authors observed recurring issues like incorrect import statements in Java and type mismatches, indicating specific areas where translation models need improvement.

Key Results

  • Lexical vs. Functional Performance: While models achieve good scores on metrics like BLEU and CodeBLEU (which measure lexical and syntactic similarity), their Computational Accuracy (CA) and Execution Accuracy (EA) are considerably lower, indicating a failure to produce functionally correct code. For instance, in Java-to-Python translation, PLBART achieved the highest EA and CA, but even then, the results were far from perfect.
  • Best Performing Models: For program translation, PLBART and CodeT5 showed the best performance on the AVATAR dataset. For function translation, fine-tuned TransCoder-ST and PLBART were the top performers.
  • Specific Model Weaknesses: The paper highlights that models often fail to generate correct class structures or handle imports properly, leading to compilation or runtime errors.

Limitations and Future Work

  • Dataset Size: The authors acknowledge that AVATAR, while large, is still limited in size, which can constrain the training of very deep neural models.
  • Language Scope: The corpus currently only covers Java and Python, limiting its applicability to other language pairs.
  • Domain Specificity: The dataset primarily focuses on data structures and algorithms, and it's unclear how well the models would translate code involving API dependencies or real-world software projects.
  • LLM Evaluation: Due to computational constraints, they couldn't evaluate large language models (LLMs), leaving their potential value for this task unexplored.

For future work, the authors plan to increase the size of the parallel corpus and expand support to more programming languages. They also hope their released code and dataset will spur further research into evaluating LLMs for code translation.

Summary updated

BibTeX
@inproceedings{ahmad2023avatar,
  author = {Wasi Uddin Ahmad and Md Golam Rahman Tushar and Saikat Chakraborty and Kai-Wei Chang},
  title = {{AVATAR: A Parallel Corpus for Java-Python Program Translation}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2023},
  doi = {10.18653/v1/2023.findings-acl.143},
}
Figure