Software migration is garnering increasing attention with the evolution of software and society. Early studies mainly relied on handcrafted translation rules to translate between two languages, the translation process is error-prone and time-consuming. In recent years, researchers have begun to explore the use of pre-trained large language models (LLMs) in code translation. However, code translation is a complex task that LLMs would generate mistakes during code translation, they all produce certain types of errors when performing code translation tasks, which include (1) compilation error, (2) runtime error, (3) functional error, and (4) non-terminating execution. We found that the root causes of these errors are very similar (e.g. failure to import packages, errors in loop boundaries, operator errors, and more). In this paper, we propose a general corrector, namely Rectifier, which is a micro and universal model for repairing translation errors. It learns from errors generated by existing LLMs and can be widely applied to correct errors generated by any LLM. The experimental results on translation tasks between C++, Java, and Python show that our model has effective repair ability, and cross experiments also demonstrate the robustness of our method.
翻译:随着软件与社会的演进,软件迁移正受到越来越多的关注。早期研究主要依赖手工编写的翻译规则在两种语言之间进行转换,该过程易出错且耗时。近年来,研究者开始探索使用预训练大型语言模型(LLMs)进行代码翻译。然而,代码翻译是一项复杂任务,LLMs在翻译过程中会产生错误,它们在执行代码翻译任务时均会产生特定类型的错误,包括:(1)编译错误,(2)运行时错误,(3)功能错误,以及(4)非终止执行。我们发现这些错误的根本原因非常相似(例如未能导入包、循环边界错误、运算符错误等)。本文提出一种通用纠错器,即Rectifier,它是一个用于修复翻译错误的微型通用模型。该模型从现有LLMs产生的错误中学习,可广泛应用于纠正任何LLM生成的错误。在C++、Java和Python之间的翻译任务上的实验结果表明,我们的模型具备有效的修复能力,交叉实验也证明了该方法的鲁棒性。