arXivDaily arXiv每日学术速递 周一至周五更新
arXiv周末暂无论文更新,休息一下吧,周末愉快~~
arXiv 2006.03511cs.CLcs.PL
收藏

程序设计语言的无监督翻译

Unsupervised Translation of Programming Languages

Facebook AI Research(脸书人工智能研究院);Paris-Dauphine University(巴黎第九大学)

Marie-Anne Lachaux, Baptiste Roziere, Lowik Chanussot, Guillaume Lample

摘要:

transcompiler,也称为source-to-source translator,是一种将源代码从高级程序设计语言(如C++或Python)转换为另一种语言的系统。Transcompilers主要用于互操作性,并将用过时或不推荐的语言(例如COBOL,Python 2)编写的代码库移植到现代语言。它们通常依赖于应用于源代码抽象语法树的手工重写规则。不幸的是,最终的翻译往往缺乏可读性,不尊重目标语言的惯例,并需要手动修改,以便正常工作。整个翻译过程非常耗时,并且需要源语言和目标语言的专业知识,这使得代码翻译项目非常昂贵。尽管神经模型在自然语言翻译的背景下显著优于基于规则的模型,但由于该领域并行数据的稀缺,其在编译转换中的应用受到限制。在本文中,我们建议利用最近的方法在无监督机器翻译训练一个完全无监督的神经编译器。我们在开源GitHub项目的源代码上训练了我们的模型,并证明它可以高精度地在C++、Java和Python之间转换函数。我们的方法完全依赖于单语源代码,不需要在源或目标语言的专业知识,可以很容易地推广到其他程序设计语言。我们还构建并发布了一个由852个并行函数组成的测试集,以及用于检查翻译正确性的单元测试。我们表明,我们的模型优于基于规则的商业基线的显着利润率。

英文摘要:

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.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑