揭示大语言模型在代码翻译中的潜力:我们还有多远?
Unraveling the Potential of Large Language Models in Code Translation: How Far Are We?
AI总结:
本文构建了多语言代码翻译基准PolyHumanEval,发现LLMs在Python到其他语言翻译上表现欠佳且常规优化技术影响微弱,提出中介翻译和自训练方法,以CodeLlama-13B实现11.7%的准确率提升,并发现Go可作为通用中介语言。
摘要:
尽管大语言模型(LLMs)在各类任务中展现出最先进的性能,但近期研究揭示了它们在代码翻译方面的困境。这是因为它们未经过大量平行多语言代码的预训练,而代码翻译高度依赖此类数据。此外,现有基准仅覆盖常见编程语言的有限子集,因此无法反映 LLMs 在代码翻译中的全部潜力。本文开展了一项大规模实证研究,以探究 LLMs 在代码翻译任务中的能力与局限。我们首先构建了一个名为 PolyHumanEval 的新颖基准,通过将 HumanEval 扩展为包含 14 种语言的多语言基准来实现。随后,我们利用前沿的代码 LLMs 在 PolyHumanEval 上执行了超过 110,000 次翻译。结果表明,LLMs 在从 Python 到其他语言的翻译上表现欠佳,且广泛采用的 LLM 优化技术(如常规预训练和指令微调)对代码翻译的影响微乎其微。为进一步挖掘 LLMs 在代码翻译中的潜力,我们提出了两种方法:(1)中介翻译,即在源语言和目标语言之间选择一种中介语言;(2)自训练,即在自生成的平行数据上微调 LLMs。以 CodeLlama-13B 进行评估,我们的方法在 Python 到其他语言的翻译上实现了 11.7% 的平均计算准确率提升。值得注意的是,我们有趣地发现,Go 可以作为在任意两种被研究语言之间进行翻译的通用语言。
英文摘要:
While large language models (LLMs) exhibit state-of-the-art performance in various tasks, recent studies have revealed their struggle for code translation. This is because they haven't been extensively pre-trained with parallel multilingual code, which code translation heavily depends on. Moreover, existing benchmarks only cover a limited subset of common programming languages, and thus cannot reflect the full potential of LLMs in code translation. In this paper, we conduct a large-scale empirical study to exploit the capabilities and incapabilities of LLMs in code translation tasks. We first craft a novel benchmark called PolyHumanEval by extending HumanEval to a multilingual benchmark of 14 languages. With PolyHumanEval, we then perform over 110,000 translations with bleeding-edge code LLMs. The result shows LLMs' suboptimal performance on Python to other languages and the negligible impact of widely adopted LLM optimization techniques such as conventional pre-training and instruction tuning on code translation. To further uncover the potential of LLMs in code translation, we propose two methods: (1) intermediary translation which selects an intermediary language between the source and target ones; and (2) self-training which fine-tunes LLMs on self-generated parallel data. Evaluated with CodeLlama-13B, our approach yields an average improvement of 11.7% computation accuracy on Python-to-other translations. Notably, we interestingly find that Go can serve as a lingua franca for translating between any two studied languages.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。