arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2306.06755cs.PLcs.AIcs.SE
收藏

CoTran:一种基于大语言模型、采用编译器与符号执行反馈强化学习的代码翻译器

CoTran: An LLM-based Code Translator using Reinforcement Learning with Feedback from Compiler and Symbolic Execution

Georgia Institute of Technology(佐治亚理工学院);University of Toronto(多伦多大学);University of California San Diego(加利福尼亚大学圣迭戈分校);Columbia University(哥伦比亚大学)

Prithwish Jana, Piyush Jha, Haoyang Ju, Gautham Kishore, Aryan Mahajan, Vijay Ganesh

AI总结:

针对现有LLM代码翻译方法编译可靠性与功能等价性不足的问题,本文提出CoTran工具,通过结合编译器与符号执行测试反馈的强化学习微调LLM,在超5.7万组Java-Python代码对基准上,相较现有工具显著提升了编译准确率与功能等价准确率。

摘要:

本文提出了一种基于大语言模型(LLM)的代码翻译方法,以及配套工具CoTran,可实现完整程序在不同高级编程语言之间的翻译。现有基于LLM的代码翻译方法缺乏针对性训练,难以保证翻译后的代码能够可靠编译,也无法确保其与输入代码具备充分的功能等价性。本研究采用强化学习微调LLM,引入编译器反馈和基于符号执行(symexec)的测试反馈,以此评估输入与输出程序之间的功能等价性。核心思路是在微调过程中,通过编译器和基于符号执行的测试反馈告知LLM其产出完美翻译的差距,从而引导模型优化。我们开展了大量实验,将CoTran与其他14种代码翻译工具进行对比,涵盖人工编写的转译器、基于LLM的翻译工具以及ChatGPT。我们使用包含超过57000组Java与Python代码对的基准测试集开展评估,结果表明CoTran在编译准确率(CompAcc)和功能等价准确率(FEqAcc)等相关指标上优于其他工具。例如,在Python转Java的翻译任务中,CoTran的FEqAcc达到48.68%,CompAcc达到76.98%,而性能最接近的对比工具PLBART-base的两项指标分别为38.26%和75.77%。此外,基于CodeT5构建的CoTran在Python转Java任务中,将FEqAcc提升了14.89个百分点,CompAcc提升了8.14个百分点;在Java转Python任务中,两项指标分别提升了12.94个百分点和4.30个百分点。

英文摘要:

In this paper, we present an LLM-based code translation method and an associated tool called CoTran, that translates whole-programs from one high-level programming language to another. Existing LLM-based code translation methods lack training to ensure that the translated code reliably compiles or bears substantial functional equivalence to the input code. In our work, we fine-tune an LLM using reinforcement learning, incorporating compiler feedback, and symbolic execution (symexec)-based testing feedback to assess functional equivalence between the input and output programs. The idea is to guide an LLM during fine-tuning, via compiler and symexec-based testing feedback, by letting it know how far it is from producing perfect translations. We conduct extensive experiments comparing CoTran with 14 other code translation tools, including human-written transpilers, LLM-based translation tools, and ChatGPT. Using a benchmark of over \num{57000} code pairs in Java and Python, we demonstrate that CoTran outperforms the other tools on relevant metrics such as compilation accuracy (CompAcc) and functional equivalence accuracy (FEqAcc). For example, in Python-to-Java translation, CoTran achieves 48.68% FEqAcc and 76.98% CompAcc, whereas the nearest competing tool (PLBART-base) gets 38.26% and 75.77% respectively. Additionally, CoTran, built on top of CodeT5, improves FEqAcc by +14.89% and CompAcc by +8.14% for Python-to-Java (resp., +12.94% and +4.30% for Java-to-Python).

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

↑