跳到正文
arXiv cs.AI· Yali Du, Yunji Zhang, Ming Li·· 2026-10-21AI 评分39

LLM 跨语言代码翻译幻觉研究:现象与缓解

Hallucinations of Large Language Models in Cross-Language Code Translation: Phenomena and Mitigation

AI 导读

一项系统性实证研究分析了 LLM 在跨语言代码翻译中的幻觉现象。研究覆盖 3 个基准数据集、6 组语言对和 7 个 LLM,人工标注 13,919 个幻觉案例,构建了包含语义一致性冲突、事实知识冲突和项目上下文偏差三大类的分类体系。基于该分类提出缓解框架 HaluCodeTran,结合基于 BM25 的相关翻译示例检索与分类感知的反思式优化,为构建更可靠的 LLM 代码迁移工具提供了实测基线。

正文 · 原文

View PDF HTML (experimental)

Abstract:Code translation converts source code from one programming language to another while preserving its functionality. Although Large Language Models (LLMs) have improved code translation, their outputs still contain hallucinations: generated code that conflicts with the source program, violates target-language facts, or introduces contextually inconsistent dependencies. These failures are especially harmful in translation because small semantic deviations can silently change program behavior. Existing hallucination studies mainly focus on natural-language generation or code generation, leaving the forms, distribution, and mitigation of hallucinations in cross-language code translation insufficiently characterized. This paper presents a systematic empirical study of LLM hallucinations in code translation. Across three benchmark datasets, six language pairs, and seven LLMs, we construct a taxonomy with three major categories: Semantic Consistency Conflicts, Factual Knowledge Conflicts, and Project Context Deviations. We manually annotate 13,919 hallucination cases and analyze how hallucination types vary across models, datasets, and language directions. Guided by the taxonomy, we further propose HaluCodeTran, a mitigation framework that combines BM25-based retrieval of relevant translation examples with taxonomy-aware reflective refinement. The study provides an execution-tested characterization of code-translation hallucinations and a practical baseline for building more reliable LLM-based code migration tools.
Subjects: Software Engineering (cs.SE); Artificial Intelligence (cs.AI)
Cite as: arXiv:2610.27868 [cs.SE]
  (or arXiv:2610.27868v1 [cs.SE] for this version)
  https://doi.org/10.48550/arXiv.2610.27868

arXiv-issued DOI via DataCite (pending registration)

Submission history

From: Yali Du [view email]
[v1] Tue, 20 Oct 2026 08:50:39 UTC (2,670 KB)

来源:arXiv cs.AI · arxiv.org