arXiv:2409.19894cs.SEcs.AI2024-09中稿 · FSE'26被引 13

通过细粒度执行对齐,自动修复大模型代码翻译中的错误。

TransAgent: Enhancing LLM-Based Code Translation via Fine-Grained Execution Alignment

  • 用多智能体系统定位源代码与目标代码的执行差异块。
  • 在新基准上提升翻译准确率33.3%,修复性能平均提高56.7%。
  • 适用于需要高精度代码迁移的开发者和自动化测试场景。

代码翻译需在不同编程语言间保持功能一致,对软件维护至关重要。传统学习方法受限于并行数据不足,而大语言模型(LLMs)虽具强大生成与理解能力,其翻译结果仍存在语法和语义错误。本文提出TransAGENT,一种新型多智能体系统,通过源代码与目标代码的细粒度执行对齐,精准定位易错代码块并消除错误。我们在一个新构建的近期编程任务基准上评估该方法,以避免数据泄露问题。实验表明,TransAGENT相比最新UniTrans最高提升33.3%的翻译准确率,在程序修复性能上平均优于Agentless 56.7%。消融实验及跨不同LLM的评估验证了其有效性与强泛化能力。

原文摘要 · Abstract (English)

Code translation transforms code between programming languages while preserving functionality, which is critical in software development and maintenance. While traditional learning-based code translation methods have limited effectiveness due to the lack of sufficient parallel training data, Large Language Models (LLMs) have recently advanced this field with their strong code generation and comprehension capabilities. However, code translated by LLMs still suffers from diverse quality issues, such as syntax and semantic errors. In this work, we propose TransAGENT, a novel multi-agent system that eliminates the errors during LLM-based code translation. The main insight of TransAGENT is to localize error-prone code blocks via fine-grained execution alignment between source and target code. We evaluate TransAGENT on a newly constructed benchmark of recent programming tasks to mitigate data leakage. TransAGENT outperforms the latest UniTrans by up to 33.3% in translation accuracy and achieves an average improvement of 56.7% over Agentless in program repair performance. We also conduct an ablation study and evaluate TransAGENT across different LLMs, demonstrating its effectiveness and strong generalizability.

代码翻译多智能体LLM纠错

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。