Paper Reading AI Learner

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

2024-04-23 00:49:46
Zhen Yang, Fang Liu, Zhongxing Yu, Jacky Wai Keung, Jia Li, Shuo Liu, Yifan Hong, Xiaoxue Ma, Zhi Jin, Ge Li

Abstract

Code translation tools 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 (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 propose UniTrans, an Unified code Translation framework, applicable to various LLMs, for unleashing their power in this field. Specifically, UniTrans first craft 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 translation datasets between Python, Java, and C++. Three recent LLMs of diverse sizes are tested with UniTrans, and all achieve substantial improvements.

Abstract (translated)

代码翻译工具是为自动源代码到源代码翻译而开发的。尽管基于学习的方法已经展示了与基于规则的方法令人印象深刻的增强,但由于它们在广泛的单语料库上的任务特定预训练,它们的当前性能仍然不令人满意,相关的训练资源也极为昂贵。大规模的人类编写代码/文本预训练的LLM在许多代码智能任务中表现突出,因为它们具有强大的泛化能力,即使没有任务特定训练。因此,LLM有可能绕过上述限制,但它们尚未被充分探索。本文研究了各种LLM和基于学习的代码翻译工具,发现:虽然某些LLM已经超过了当前的翻译器,但它们仍然存在一些准确性问题,其中大多数失败是由对源程序缺乏理解(38.51%)引起的,缺少翻译器中I/O类型的明确说明(14.94%)和忽略源程序和目标程序之间的差异(41.38%)。鉴于上述发现,我们提出了UniTrans,一个统一代码翻译框架,适用于各种LLM,以释放它们在这个领域的潜力。具体来说,UniTrans首先使用源程序协助构建目标程序的一系列测试用例。接下来,它利用生成的测试用例来增强代码翻译,并通过执行来评估它们的正确性。然后,UniTrans进一步修复由测试用例执行结果催生的错误翻译程序。在Python、Java和C++的六个翻译数据集上进行了广泛的实验。对大小不同、多种日期的LLM进行了测试,所有都取得了显著的改进。

URL

https://arxiv.org/abs/2404.14646

PDF

https://arxiv.org/pdf/2404.14646.pdf


Tags
3D Action Action_Localization Action_Recognition Activity Adversarial Agent Attention Autonomous Bert Boundary_Detection Caption Chat Classification CNN Compressive_Sensing Contour Contrastive_Learning Deep_Learning Denoising Detection Dialog Diffusion Drone Dynamic_Memory_Network Edge_Detection Embedding Embodied Emotion Enhancement Face Face_Detection Face_Recognition Facial_Landmark Few-Shot Gait_Recognition GAN Gaze_Estimation Gesture Gradient_Descent Handwriting Human_Parsing Image_Caption Image_Classification Image_Compression Image_Enhancement Image_Generation Image_Matting Image_Retrieval Inference Inpainting Intelligent_Chip Knowledge Knowledge_Graph Language_Model LLM Matching Medical Memory_Networks Multi_Modal Multi_Task NAS NMT Object_Detection Object_Tracking OCR Ontology Optical_Character Optical_Flow Optimization Person_Re-identification Point_Cloud Portrait_Generation Pose Pose_Estimation Prediction QA Quantitative Quantitative_Finance Quantization Re-identification Recognition Recommendation Reconstruction Regularization Reinforcement_Learning Relation Relation_Extraction Represenation Represenation_Learning Restoration Review RNN Robot Salient Scene_Classification Scene_Generation Scene_Parsing Scene_Text Segmentation Self-Supervised Semantic_Instance_Segmentation Semantic_Segmentation Semi_Global Semi_Supervised Sence_graph Sentiment Sentiment_Classification Sketch SLAM Sparse Speech Speech_Recognition Style_Transfer Summarization Super_Resolution Surveillance Survey Text_Classification Text_Generation Tracking Transfer_Learning Transformer Unsupervised Video_Caption Video_Classification Video_Indexing Video_Prediction Video_Retrieval Visual_Relation VQA Weakly_Supervised Zero-Shot