Unsupervised Translation of Programming Languages
arXiv:2006.03511
Abstract
A transcompiler, also known as source-to-source translator, is a system that converts source code from a high-level programming language (such as C++ or Python) to another. Transcompilers are primarily used for interoperability, and to port codebases written in an obsolete or deprecated language (e.g. COBOL, Python 2) to a modern one. They typically rely on handcrafted rewrite rules, applied to the source code abstract syntax tree. Unfortunately, the resulting translations often lack readability, fail to respect the target language conventions, and require manual modifications in order to work properly. The overall translation process is timeconsuming and requires expertise in both the source and target languages, making code-translation projects expensive. Although neural models significantly outperform their rule-based counterparts in the context of natural language translation, their applications to transcompilation have been limited due to the scarcity of parallel data in this domain. In this paper, we propose to leverage recent approaches in unsupervised machine translation to train a fully unsupervised neural transcompiler. We train our model on source code from open source GitHub projects, and show that it can translate functions between C++, Java, and Python with high accuracy. Our method relies exclusively on monolingual source code, requires no expertise in the source or target languages, and can easily be generalized to other programming languages. We also build and release a test set composed of 852 parallel functions, along with unit tests to check the correctness of translations. We show that our model outperforms rule-based commercial baselines by a significant margin.
References in corpus (18)
- Adam: A Method for Stochastic Optimization
- Neural Machine Translation by Jointly Learning to Align and Translate
- Sequence to Sequence Learning with Neural Networks
- Cross-lingual Language Model Pretraining
- Dual Learning for Machine Translation
- MASS: Masked Sequence to Sequence Pre-training for Language Generation
- On Using Monolingual Corpora in Neural Machine Translation
- SequenceR: Sequence-to-Sequence Learning for End-to-End Program Repair
- Learning Natural Coding Conventions
- Unsupervised Statistical Machine Translation
- CodeBERT: A Pre-Trained Model for Programming and Natural Languages
- A Syntactic Neural Model for General-Purpose Code Generation
- Learning Python Code Suggestion with a Sparse Pointer Network
- A parallel corpus of Python functions and documentation strings for automated code documentation and code generation
- Dynamic Neural Program Embedding for Program Repair
- Abstract Syntax Networks for Code Generation and Semantic Parsing
- Neural Attribute Machines for Program Generation
- Towards Neural Decompilation
Cited by in corpus (30)
- Evaluating Large Language Models Trained on Code
- CodeXGLUE: A Machine Learning Benchmark Dataset for Code Understanding and Generation
- A Survey of Machine Learning for Computer Architecture and Systems
- CodeBLEU: a Method for Automatic Evaluation of Code Synthesis
- Measuring Coding Challenge Competence With APPS
- Unsolved Problems in ML Safety
- Compositional Generalization in Semantic Parsing: Pre-training vs. Specialized Architectures
- ProtTrans: Towards Cracking the Language of Life's Code Through Self-Supervised Deep Learning and High Performance Computing
- Unified Pre-training for Program Understanding and Generation
- TreeBERT: A Tree-Based Pre-Trained Model for Programming Language
- A Survey on Self-supervised Pre-training for Sequential Transfer Learning in Neural Networks
- CoTexT: Multi-task Learning with Code-Text Transformer
- Energy-Based Models for Code Generation under Compilability Constraints
- Report of the Workshop on Program Synthesis for Scientific Computing
- Automating Program Structure Classification
- Learning C to x86 Translation: An Experiment in Neural Compilation
- Automated Source Code Generation and Auto-completion Using Deep Learning: Comparing and Discussing Current Language-Model-Related Approaches
- RPT: Effective and Efficient Retrieval of Program Translations from Big Code
- Svar: A Tiny C++ Header Brings Unified Interface for Multiple programming Languages
- Distilling Transformers for Neural Cross-Domain Search
- Neural Circuit Synthesis from Specification Patterns
- How could Neural Networks understand Programs?
- NeurIPS 2020 NLC2CMD Competition: Translating Natural Language to Bash Commands
- DeepMutants: Training neural bug detectors with contextual mutations
- Formal Fields: A Framework to Automate Code Generation Across Domains
- Text Classification for Task-based Source Code Related Questions
- The test set for the TransCoder system
- Jointly Learning to Repair Code and Generate Commit Message
- Towards A Measure Of General Machine Intelligence
- Using Document Similarity Methods to create Parallel Datasets for Code Translation