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

探索并释放大型语言模型在自动化代码翻译中的力量

Exploring and Unleashing the Power of Large Language Models in Automated Code Translation

Shandong University(山东大学);Beihang University(北京航空航天大学);City University of Hong Kong(香港城市大学);Peking University(北京大学)

Zhen Yang, Fang Liu, Zhongxing Yu, Jacky Wai Keung, Jia Li, Shuo Liu, Yifan Hong, Xiaoxue Ma, Zhi Jin, Ge Li

AI总结:

本文评估 LLM 与学习型转译器的代码翻译能力,定位其理解与 I/O 指令等缺陷,并提出结合测试生成、执行验证和迭代修复的 UniTrans 框架,在六种跨语言设置上显著提升三类 LLM。

摘要:

代码翻译工具(转译器)是为自动的源到源翻译而开发的。尽管基于学习的转译器凭借其在大量单语言语料库上的任务特定预训练,相对于基于规则的同类工具已展现出令人瞩目的提升,但它们目前的性能仍不足以令人满意地用于实际部署,而且相关训练资源也昂贵得令人望而却步。在大量人工编写的代码/文本上预训练的 LLM,凭借其强大的通用性,即使没有任务特定训练,也已在许多代码智能任务中表现出卓越性能。因此,LLM 有可能规避上述局限,但它们尚未得到详尽探索。本文研究了用于自动化代码翻译任务的多种 LLM 和基于学习的转译器,发现:尽管某些 LLM 已经优于当前转译器,但它们仍存在一些准确性问题,其中大多数失败源于对源程序缺乏理解、翻译中缺少关于 I/O 类型的清晰指令,以及忽视源程序与目标程序之间的差异。受上述发现启发,我们进一步提出 UniTrans,这是一个统一代码翻译框架,适用于各种 LLM,旨在释放它们在该领域的力量。具体而言,UniTrans 首先借助源程序为目标程序精心构造一系列测试用例。接着,它利用上述自动生成的测试用例增强代码翻译,随后通过执行评估其正确性。之后,UniTrans 进一步(迭代地)修复由测试用例执行结果所提示的错误翻译程序。研究在 Python、Java 和 C++ 之间的六种翻译数据集设置上进行了大量实验。三个具有不同规模的近期 LLM 与 UniTrans 一起接受测试,均取得了显著改进。

英文摘要:

Code translation tools (transpilers) are developed for automatic source-to-source translation. Although learning-based transpilers have shown impressive enhancement against rule-based counterparts, owing to their task-specific pre-training on extensive monolingual corpora. Their current performance still remains unsatisfactory for practical deployment, and the associated training resources are also prohibitively expensive. LLMs pre-trained on huge amounts of human-written code/text have shown remarkable performance in many code intelligence tasks due to their powerful generality, even without task-specific training. Thus, LLMs can potentially circumvent the above limitations, but they have not been exhaustively explored yet. This paper investigates diverse LLMs and learning-based transpilers for automated code translation tasks, finding that: although certain LLMs have outperformed current transpilers, they still have some accuracy issues, where most of the failures are induced by a lack of comprehension of source programs, missing clear instructions on I/O types in translation, and ignoring discrepancies between source and target programs. Enlightened by the above findings, we further propose UniTrans, a Unified code Translation framework, applicable to various LLMs, for unleashing their power in this field. Specifically, UniTrans first crafts a series of test cases for target programs with the assistance of source programs. Next, it harnesses the above auto-generated test cases to augment the code translation and then evaluate their correctness via execution. Afterward, UniTrans further (iteratively) repairs incorrectly translated programs prompted by test case execution results. Extensive experiments are conducted on six settings of translation datasets between Python, Java, and C++. Three recent LLMs of diverse sizes are tested with UniTrans, and all achieve substantial improvements.

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

↑