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.
翻译:转译器, 也称为源对源翻译器, 是一个将源代码从高级编程语言( 如 C++ 或 Python ) 转换为另一种系统。 转译器主要用于互操作性, 并用于用过时或破旧的语言( 例如 COBOL, Python 2) 写成的港口代码库。 它们通常依赖手写改写规则, 适用于源代码抽象语法树。 不幸的是, 由此产生的译文往往缺乏可读性, 不尊重目标语言公约, 需要手工修改才能正常工作。 整个翻译过程耗时, 需要源语言和目标语言的专门知识, 使得代码翻译项目变得昂贵。 虽然神经模型在自然语言编程中大大超越了基于规则的对应方程式( 例如 COBOL, Python 2), 它们用于翻译的应用程序有限, 因为这个域域中缺少平行的模型数据。 我们提议, 使用不加密的机器翻译方法, 来使用不加密的翻译方法, 来训练完全不受监控的神经翻译的版本的版本, 翻譯功能需要完全的 C. 我们的模型的测试的系统, 和C. breglxxx 。 我们的模型的模型的功能在打开的校正的校正的校正的测试的测试的功能中, 。