On ML-Based Program Translation: Perils and Promises

Aniketh Malyala, Katelyn Zhou, Baishakhi Ray, Saikat Chakraborty

Abstract

Migrating legacy software systems to modern programming languages remains a multi-billion-dollar challenge. While unsupervised machine learning (ML) models like TransCoder have introduced a scalable alternative to traditional rule-based transpilers, they often suffer from semantic "blind spots" that lead to non-functional code. This paper investigates these failure patterns through a manual error analysis and proposes a hybrid translation framework. By combining ML models with targeted rule-based pre- and post-processing, we demonstrate that translation success rates can be improved by up to 86% without retraining the underlying model.

Introduction

The software industry faces a persistent crisis: the maintenance of legacy codebases in languages like COBOL or Fortran. Traditional transpilers, which rely on manually defined conversion rules, are notoriously difficult to scale and often fail when encountering complex modern libraries. Recently, unsupervised Machine Learning (ML) models—most notably Facebook’s TransCoder—have emerged as a promising solution. These models learn to translate between languages by identifying patterns across massive datasets (e.g., 128 million GitHub repositories) without requiring perfectly aligned parallel corpora.

However, these models are purely statistical. They lack a fundamental understanding of program semantics, leading to "hallucinations" where the model adds unnecessary logic or fails to map complex syntax correctly. This research explores whether these failures are random or predictable, and whether a hybrid approach can bridge the gap between statistical probability and logical correctness.

Methodology: The Hybrid Translation Framework

To address the shortcomings of purely statistical translation, we developed a hybrid program translator that utilizes a "wrapper" approach around existing ML models. The core of this system is a mutation engine that performs two key interventions:

  1. Pre-processing (Semantic Simplification): Before the source code is fed to the ML model, it is mutated into a "lowest common denominator" format. For instance, because Java for loops are more feature-rich and syntactically complex than Python's, the model often struggles with the conversion. By programmatically converting Java for loops into while loops—which share more semantic similarity across languages—the model's workload is simplified.
  2. Post-processing (Hallucination Cleanup): ML models frequently add "extra constraints" (e.g., an unnecessary if (x % 10 == 0) check) that were never present in the source. Our engine identifies these logical additions and strips them away, restoring the original intent of the code.

This workflow allows the system to leverage the broad linguistic knowledge of the transformer model while using classic program analysis to enforce structural integrity.

Identifying "Blind Spots"

Our manual analysis of 100 translation examples (50 Java-to-Python and 50 Python-to-Java) revealed that ML errors fall into several distinct, predictable categories:

  • Type Sensitivity: Models often fail when specific data structures, such as arrays, are passed as parameters, leading to type mismatches in the target language.
  • Context Confusion: Including auxiliary code, such as a main method or test cases, often confuses the model, causing it to mix up variable arguments. We found that translating functions in isolation significantly increases reliability.
  • Statistical Hallucinations: Because the models are trained on vast amounts of diverse code, they often "predict" common code patterns that do not apply to the specific logic at hand. Interestingly, while models frequently add unnecessary conditions, they rarely omit original ones, making post-processing cleanup highly effective.

Results and Evaluation

The hybrid approach was tested against the vanilla TransCoder model using the GeeksForGeeks dataset. The results indicate a significant leap in computational accuracy:

  • Java to Python (J2P): The prototype improved translation success by 86% over the baseline.
  • Python to Java (P2J): The prototype improved success by 50%.
  • Reliability: The specific rule-based mutations identified in this study achieved a 100% success rate in fixing the specific error patterns they were designed to target.

For context, the original TransCoder’s standalone computational accuracy was only 56.1% for J2P and 68.7% for P2J. Our findings suggest that even simple rule-based wrappers can provide the necessary guardrails to make ML-based translation viable for production environments.

Limitations and Future Work

While the performance gains are substantial, several challenges remain. The current identification of "blind spots" was a manual process; future research will focus on automating this discovery using more sophisticated program analysis. Additionally, this study focused on method-level translation. Scaling this to entire projects with complex, inter-dependent files remains a significant hurdle. Finally, we aim to apply these hybrid techniques to low-resource languages where the massive training data required for unsupervised learning is not readily available.

Conclusion

ML-based program translation is a powerful tool, but its statistical nature is a double-edged sword. By acknowledging the "perils" of hallucinations and syntax confusion, and addressing them with the "promises" of rule-based mutations, we can create more robust, reliable systems for software migration. The future of program translation likely lies not in choosing between ML and rules, but in finding the optimal way to integrate them.

Summary updated

BibTeX
@inproceedings{malyala2023ml,
  author = {Aniketh Malyala and Katelyn Zhou and Baishakhi Ray and Saikat Chakraborty},
  title = {{On ML-Based Program Translation: Perils and Promises}},
  booktitle = {ICSE (NIER)},
  year = {2023},
  doi = {10.1109/icse-nier58687.2023.00017},
}
Figure