Skip to main content
QUICK REVIEW

[Paper Review] Leveraging Automated Unit Tests for Unsupervised Code Translation

Baptiste Rozière, Jie M. Zhang|arXiv (Cornell University)|Oct 13, 2021
Software Testing and Debugging TechniquesComputer Science52 references10 citations
TL;DR

This paper proposes a novel unsupervised code translation method that leverages multilingual unit tests to filter noisy translations generated via back-translation, significantly improving translation accuracy. By validating candidate translations against executable test suites, the approach produces higher-quality, semantically correct code, outperforming prior state-of-the-art models by up to 24% on Python→C++ translation and reducing error rates by over 35%.

ABSTRACT

With little to no parallel data available for programming languages, unsupervised methods are well-suited to source code translation. However, the majority of unsupervised machine translation approaches rely on back-translation, a method developed in the context of natural language translation and one that inherently involves training on noisy inputs. Unfortunately, source code is highly sensitive to small changes; a single token can result in compilation failures or erroneous programs, unlike natural languages where small inaccuracies may not change the meaning of a sentence. To address this issue, we propose to leverage an automated unit-testing system to filter out invalid translations, thereby creating a fully tested parallel corpus. We found that fine-tuning an unsupervised model with this filtered data set significantly reduces the noise in the translations so-generated, comfortably outperforming the state-of-the-art for all language pairs studied. In particular, for Java $ o$ Python and Python $ o$ C++ we outperform the best previous methods by more than 16% and 24% respectively, reducing the error rate by more than 35%.

Motivation & Objective

  • To address the challenge of low-resource, unsupervised source code translation where parallel data is scarce and neural models are sensitive to input noise.
  • To reduce translation errors caused by back-translation, which generates invalid or semantically incorrect code due to minor token-level changes.
  • To improve translation quality by using automated unit tests as a semantic validation mechanism to filter only correct or executable translations.
  • To create a fully tested, parallel monolingual corpus from unpaired source code in different languages, enabling better fine-tuning of unsupervised models.
  • To demonstrate that test-driven filtering significantly enhances translation performance without requiring parallel training data.

Proposed method

  • The method uses back-translation to generate pseudo-parallel monolingual data from unpaired source code in different programming languages.
  • It leverages existing multilingual unit test suites to validate candidate translations, discarding those that fail execution.
  • Only translations passing all unit tests are retained as high-confidence pseudo-parallel examples for fine-tuning the unsupervised model.
  • The model is fine-tuned on the filtered, test-passing translations, improving its ability to generate semantically correct code.
  • The approach supports both offline filtering (preprocessing) and online filtering (during training), with the latter dynamically re-evaluating translations.
  • The method is compatible with existing unsupervised code translation frameworks like TransCoder and can be extended to other languages with available test generators.

Experimental results

Research questions

  • RQ1Can automated unit tests be used to filter out incorrect or non-compiling code translations generated via back-translation?
  • RQ2Does filtering translations using executable test results lead to measurable improvements in code translation accuracy?
  • RQ3How does test-based filtering compare to standard back-translation in terms of reducing translation error rates?
  • RQ4Can this method generalize across diverse programming language pairs, including those with significant semantic differences (e.g., Python to C++)?
  • RQ5To what extent can test-passing translations serve as reliable supervision signals in an unsupervised setting?

Key findings

  • The proposed method outperforms the previous state-of-the-art by 16.3% on Java→Python translation and by 24.1% on Python→C++ translation.
  • The translation error rate was reduced by 35.7% on the Python→C++ language pair, demonstrating significant noise reduction.
  • The method achieved an average improvement of 12.6 percentage points in computational accuracy across all language pairs studied.
  • Translations that pass unit tests are significantly more accurate and semantically correct than those that do not, even when they appear syntactically similar.
  • The approach is robust and generalizable: it improves performance without requiring parallel data or language-specific rule sets.
  • The method remains effective even when unit tests are only available for one language (e.g., Java), showing strong transferability to others.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.