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

InterTrans:利用传递性中间翻译增强基于LLM的代码翻译

InterTrans: Leveraging Transitive Intermediate Translations to Enhance LLM-based Code Translation

Marcos Macedo, Yuan Tian, Pengyu Nie, Filipe R. Cogo, Bram Adams

AI总结:

InterTrans提出利用跨语言中间翻译序列,通过ToCT算法规划并验证,增强LLM代码翻译,在三个基准上较直接翻译提升18.3%-43.3%的计算准确率。

摘要:

代码翻译旨在将程序从一种编程语言(PL)转换为另一种编程语言。这一长期存在的软件工程任务对于现代化遗留系统、确保跨平台兼容性、提升性能等方面至关重要。然而,由于编程语言之间存在许多语法和语义差异,自动化这一过程仍然具有挑战性。近期研究表明,即使是先进的技术如大型语言模型(LLMs),尤其是开源LLMs,在此任务上仍面临困难。目前,代码LLMs使用多种编程语言的源代码进行训练,因此展现出多语言能力。本文研究这种多语言能力是否可以被利用来增强代码翻译。为实现这一目标,我们引入了InterTrans,一种基于LLM的自动化代码翻译方法,与现有方法不同,它利用跨编程语言的中间翻译来弥合源语言和目标语言之间的语法和语义差距。InterTrans包含两个阶段。它首先利用一种新颖的代码翻译树(ToCT)算法来规划给定源语言和目标语言之间的传递性中间翻译序列,然后按特定顺序对其进行验证。我们使用三个开源LLM在三个基准测试(即CodeNet、HumanEval-X和TransCoder)上评估InterTrans,涉及六种编程语言。结果显示,在10次尝试中,InterTrans相对于直接翻译在计算准确率(CA)上实现了18.3%至43.3%的绝对提升。InterTrans的最佳变体(使用Magicoder LLM)在三个基准测试上平均CA达到87.3%-95.4%。

英文摘要:

Code translation aims to convert a program from one programming language (PL) to another. This long-standing software engineering task is crucial for modernizing legacy systems, ensuring cross-platform compatibility, enhancing performance, and more. However, automating this process remains challenging due to many syntactic and semantic differences between PLs. Recent studies show that even advanced techniques such as large language models (LLMs), especially open-source LLMs, still struggle with the task. Currently, code LLMs are trained with source code from multiple programming languages, thus presenting multilingual capabilities. In this paper, we investigate whether such multilingual capabilities can be harnessed to enhance code translation. To achieve this goal, we introduce InterTrans, an LLM-based automated code translation approach that, in contrast to existing approaches, leverages intermediate translations across PLs to bridge the syntactic and semantic gaps between source and target PLs. InterTrans contains two stages. It first utilizes a novel Tree of Code Translation (ToCT) algorithm to plan transitive intermediate translation sequences between a given source and target PL, then validates them in a specific order. We evaluate InterTrans with three open LLMs on three benchmarks (i.e., CodeNet, HumanEval-X, and TransCoder) involving six PLs. Results show an absolute improvement between 18.3% to 43.3% in Computation Accuracy (CA) for InterTrans over Direct Translation with 10 attempts. The best-performing variant of InterTrans (with Magicoder LLM) achieved an average CA of 87.3%-95.4% on three benchmarks.

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

↑