Code Translation with Compiler Representations

要約

タイトル:コンパイラ表現を用いたコード翻訳
要約:
– 従来のトランスパイラは構文情報や手作りのルールに依存しているため、適用範囲が限定され、不自然なコードを生成する。
– コードをテキストのトークンのシーケンスとして扱うニューラルネットワーク翻訳は、自然な翻訳を行うことができるようになったが、同じような概念を異なる言語で表現する場合の違いを区別することができていないため、精度が低下している。
– 本論文では、LLVM IRなどのコンパイラの低レベル中間表現を使用することで、コード翻訳の精度を向上させることを提案している。
– C++、Java、Rust、Goの言語において、従来手法に比べて11%程度の正しい翻訳数の増加が確認された。Java -> Rustペアにおいては、greedy decodingの場合には79%の正解数の向上が確認された。beam searchにおいては、平均5.5%の正解数の向上が確認された。
– 加えて、数百のGoとRustの関数を追加したテストセットを使用して、IRを介した翻訳について検討した。IRのデコンパイル問題に対して高いパフォーマンスを示すモデルを訓練し、IRを翻訳の中間ピボットとして使用することについても研究した。

要約(オリジナル)

In this paper, we leverage low-level compiler intermediate representations (IR) to improve code translation. Traditional transpilers rely on syntactic information and handcrafted rules, which limits their applicability and produces unnatural-looking code. Applying neural machine translation (NMT) approaches to code has successfully broadened the set of programs on which one can get a natural-looking translation. However, they treat the code as sequences of text tokens, and still do not differentiate well enough between similar pieces of code which have different semantics in different languages. The consequence is low quality translation, reducing the practicality of NMT, and stressing the need for an approach significantly increasing its accuracy. Here we propose to augment code translation with IRs, specifically LLVM IR, with results on the C++, Java, Rust, and Go languages. Our method improves upon the state of the art for unsupervised code translation, increasing the number of correct translations by 11% on average, and up to 79% for the Java -> Rust pair with greedy decoding. With beam search, it increases the number of correct translations by 5.5% in average. We extend previous test sets for code translation, by adding hundreds of Go and Rust functions. Additionally, we train models with high performance on the problem of IR decompilation, generating programming source code from IR, and study using IRs as intermediary pivot for translation.

arxiv情報

著者 Marc Szafraniec,Baptiste Roziere,Hugh Leather,Francois Charton,Patrick Labatut,Gabriel Synnaeve
発行日 2023-04-19 11:37:46+00:00
arxivサイト arxiv_id(pdf)

提供元, 利用サービス

arxiv.jp, OpenAI

カテゴリー: cs.CL, cs.LG, cs.PL パーマリンク