跳到正文
arXiv cs.AI· Yali Du, Yunji Zhang, Ming Li·· 12 小时前AI 评分38

大语言模型跨语言代码翻译中的幻觉:现象与缓解

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

AI 导读

一项系统性实证研究在三个基准数据集、六种语言对和七个 LLM 上考察跨语言代码翻译幻觉,构建了语义一致性冲突、事实知识冲突、项目上下文偏离三类分类体系,人工标注 13,919 个幻觉案例。基于该分类体系提出的 HaluCodeTran 框架结合 BM25 检索相关翻译示例与分类感知的反思式精炼来缓解幻觉。

正文 · 原文

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