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

增强基于LLM的代码翻译:利用验证过的多语义表示

Enhancing LLM-Based Code Translation with Verified Multi-Semantic Representations

Dalian University of Technology(大连理工大学);Liaoning Normal University(辽宁师范大学)

Yufu Wang, He Jiang, Hao Lin, Peiyu Zou, Ang Jia, Xiaochen Li, Zhilei Ren

AI总结:

提出Multisage框架,通过提取和验证多语义表示(数据流图、类型约束等)来提升LLM代码翻译的准确性和可靠性,在HumanEval-X上翻译成功率提升至2.22倍。

摘要:

大型语言模型(LLM)在自动化代码翻译方面展现出巨大潜力,但现有方法通常依赖基于token的统计模式,而非对程序语义的充分理解。因此,翻译后的程序可能仍包含逻辑和语义错误。尽管高质量语义指导(如功能描述和测试用例)有助于减少此类错误,但在实际场景中这些资源往往不可用。这带来了两个关键挑战:如何直接从源代码构建丰富的语义信息,以及如何确保这些语义足够准确可靠以指导翻译。针对这些挑战,我们提出了Multisage,一个用于基于LLM的代码翻译的多语义增强与自校准框架。Multisage包含三个模块。首先,语义表示解析模块从源代码中提取结构化基础语义,包括数据流图、类型约束和外部API信息。其次,多语义增强模块基于这些表示生成多样化的增强语义,包括代码摘要、函数级测试用例以及面向API的描述和测试。第三,语义一致性校准模块使用语义保持变异和跨语义一致性验证来过滤、校准和优化生成的语义。在HumanEval-X代码翻译基准上的实验表明,Multisage在不同骨干模型上将翻译成功率提升高达2.22倍。它持续优于普通提示、指令微调LLM和思维链推理,在较小模型上提升最大。这些结果表明,显式语义增强可以显著提高基于LLM的代码翻译的可靠性。

英文摘要:

Large language models (LLMs) have shown great promise for automated code translation, yet existing approaches often rely on token-level statistical patterns rather than sufficient understanding of program semantics. As a result, translated programs may still contain logical and semantic errors. Although high-quality semantic guidance, such as functional descriptions and test cases, can help mitigate these errors, such resources are often unavailable in real-world scenarios. This raises two key challenges: how to construct rich semantic information directly from source code, and how to ensure that such semantics are accurate and reliable enough to guide translation.To address these challenges, we propose Multisage, a multi-semantic augmentation and self-calibration framework for LLM-based code translation. Multisage consists of three modules. First, a semantic representation parsing module extracts structured base semantics from source code, including data-flow graphs, type constraints, and external API information. Second, a multi-semantic augmentation module builds on these representations to generate diverse augmented semantics, including code summaries, function-level test cases, and API-oriented descriptions and tests. Third, a semantic consistency calibration module uses semantics-preserving mutations and cross-semantic consistency verification to filter, calibrate, and refine the generated semantics.Experiments on the HumanEval-X code translation benchmark show that Multisage improves translation success rates by up to 2.22 times across diverse backbone models. It consistently outperforms vanilla prompting, instruction-tuned LLMs, and Chain-of-Thought reasoning, with the largest gains observed on smaller models. These results demonstrate that explicit semantic augmentation can substantially improve the reliability of LLM-based code translation.

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

↑