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

用于代码翻译的 LLM 函数到风格引导

Function-to-Style Guidance of LLMs for Code Translation

Harbin Institute of Technology, Shenzhen, China.(哈尔滨工业大学深圳研究院);Huawei Translation Services Center, Beijing, China.(华为翻译服务中心)

Longhui Zhang, Bin Wang, Jiahao Wang, Xiaofeng Zhao, Min Zhang, Hao Yang, Meishan Zhang, Yu Li, Jing Li, Jun Yu, Min Zhang

AI总结:

本文提出 F2STrans 范式,通过功能学习优化正确性和风格学习提升可读性两阶段引导 LLMs 进行代码翻译,并构建新基准,使 Qwen-1.5B 平均超越提示增强的 Qwen-32B 和 GPT-4。

摘要:

大型语言模型(LLMs)在代码翻译任务中取得了显著进展。然而,确保翻译代码的正确性和可读性仍是一项挑战,限制了其在实际软件开发中的有效应用。在本研究中,我们提出了 F2STrans,一种旨在逐步提升 LLMs 代码翻译性能的函数到风格引导范式。我们的方法包含两个关键阶段:(1) 功能学习,利用从在线编程平台挖掘的高质量源代码-目标代码对来优化翻译正确性;(2) 风格学习,通过引入正面和负面的风格示例来提升翻译可读性。此外,我们引入了一个新的代码翻译基准,包含最新源代码、广泛测试用例和人工标注的真实翻译,以实现全面的功能和风格评估。在我们的新基准和现有数据集上的实验表明,我们的方法显著提升了代码翻译性能。值得注意的是,我们的方法使 Qwen-1.5B 在 20 种不同的代码翻译场景中,平均表现优于经过提示增强的 Qwen-32B 和 GPT-4。

英文摘要:

Large language models (LLMs) have made significant strides in code translation tasks. However, ensuring both the correctness and readability of translated code remains a challenge, limiting their effective adoption in real-world software development. In this work, we propose F2STrans, a function-to-style guiding paradigm designed to progressively improve the performance of LLMs in code translation. Our approach comprises two key stages: (1) Functional learning, which optimizes translation correctness using high-quality source-target code pairs mined from online programming platforms, and (2) Style learning, which improves translation readability by incorporating both positive and negative style examples. Additionally, we introduce a novel code translation benchmark that includes up-to-date source code, extensive test cases, and manually annotated ground-truth translations, enabling comprehensive functional and stylistic evaluations. Experiments on both our new benchmark and existing datasets demonstrate that our approach significantly improves code translation performance. Notably, our approach enables Qwen-1.5B to outperform prompt-enhanced Qwen-32B and GPT-4 on average across 20 diverse code translation scenarios.

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

↑