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

Author:

Yang Zhen1ORCID,Liu Fang2ORCID,Yu Zhongxing1ORCID,Keung Jacky Wai3ORCID,Li Jia4ORCID,Liu Shuo3ORCID,Hong Yifan3ORCID,Ma Xiaoxue3ORCID,Jin Zhi4ORCID,Li Ge4ORCID

Affiliation:

1. Shandong University, Qingdao, China

2. Beihang University, Beijing, China

3. City University of Hong Kong, Hong Kong, China

4. Peking University, Beijing, China

Abstract

Code translation tools, namely transpilers, are developed for automatic source-to-source translation. Latest learning-based transpilers have shown impressive enhancement against rule-based counterparts in both translation accuracy and readability, owing to their task-specific pre-training on extensive monolingual corpora. Nevertheless, their current performance still remains unsatisfactory for practical deployment, and the associated training resources are also prohibitively expensive. Large Language Models (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 re-training/fine-tuning. 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 (38.51%), missing clear instructions on I/O types in translation (14.94%), and ignoring discrepancies between source and target programs (41.38%). Enlightened by the above findings, we further propose UniTrans , a Uni fied code Trans lation 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, including GPT-3.5 and LLaMA-13B/7B, are tested with UniTrans , and all achieve substantial improvements in terms of computational accuracy and exact match accuracy among almost all translation settings, showing the universal effectiveness of UniTrans in practice.

Funder

National Key R&D Program

National Natural Science Foundation of China

Shandong Province Overseas Outstanding Youth Fund

City University of Hong Kong

Key Program of Hubei

Publisher

Association for Computing Machinery (ACM)

Reference67 articles.

1. [n. d.]. EMMA: a free Java code coverage tool. https://emma.sourceforge.net/ (Accessed on 05/06/2024)

2. [n. d.]. FSE-24-UniTrans. https://github.com/yz1019117968/FSE-24-UniTrans (Accessed on 04/19/2024)

3. [n. d.]. GeeksforGeeks. https://www.geeksforgeeks.org/ (Accessed on 05/06/2024)

4. [n. d.]. gotranspile/cxgo: Tool for transpiling C to Go.. https://github.com/gotranspile/cxgo (Accessed on 05/06/2024)

5. [n. d.]. Hugging Face – The AI community building the future.. https://huggingface.co/ (Accessed on 05/06/2024)

同舟云学术

1.学者识别学者识别

2.学术分析学术分析

3.人才评估人才评估

"同舟云学术"是以全球学者为主线,采集、加工和组织学术论文而形成的新型学术文献查询和分析系统,可以对全球学者进行文献检索和人才价值评估。用户可以通过关注某些学科领域的顶尖人物而持续追踪该领域的学科进展和研究前沿。经过近期的数据扩容,当前同舟云学术共收录了国内外主流学术期刊6万余种,收集的期刊论文及会议论文总量共计约1.5亿篇,并以每天添加12000余篇中外论文的速度递增。我们也可以为用户提供个性化、定制化的学者数据。欢迎来电咨询!咨询电话:010-8811{复制后删除}0370

www.globalauthorid.com

TOP

Copyright © 2019-2024 北京同舟云网络信息技术有限公司
京公网安备11010802033243号  京ICP备18003416号-3