Unsupervised Translation of Programming Languages
Marie-Anne Lachaux Facebook AI Research Baptiste Roziere* Facebook AI Research Paris-Dauphine University Lowik Chanussot Facebook AI Research Guillaume Lample Facebook AI Research Equal contribution. The order was determined randomly.
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 time-consuming 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
中文速览
把已有代码库从一种编程语言迁移到另一种是件费钱又费力的事,现有的转译工具大多靠人工编写的规则,翻译结果可读性差、还常常需要手动修改。这篇论文提出了 TransCoder,一个完全无监督的神经网络转译器(neural transcompiler),仅凭从 GitHub 抓取的各语言单语代码(monolingual source code),借助跨语言预训练、去噪自编码和回译(back-translation)三项技术,就能在不依赖任何平行语料的情况下学会在 C++、Java 和 Python 之间互译函数。为了可靠地评估翻译质量,作者还构建并公开了一个包含 852 个平行函数及配套单元测试的测试集,用实际运行结果而非 BLEU 分数来衡量正确性。实验表明,TransCoder 在准确率上大幅超越了依赖规则的商业转译工具,证明纯数据驱动的方法完全可以替代需要大量人工专业知识的传统方案,对降低代码迁移的成本和门槛具有重要意义。
原文 arXiv:2006.03511;中英对照 + 大白话阅读 https://aha.fim.ai/paper/2006.03511v3