Tracing Hallucinations in LLM Reasoning for UML Class Diagram Generation: An Empirical Taxonomy and Mitigation Study
作者: Mojdeh Rahmanian, Foutse Khomh, Ashkan Sami, Yanchao Yu
分类: cs.SE, cs.CL
发布日期: 2026-10-22
💡 一句话要点
提出一种分类法以解决LLM生成UML类图中的幻觉问题
🎯 匹配领域: 支柱九:具身大模型 (Embodied Foundation Models)
关键词: 大型语言模型 UML类图 幻觉现象 推理分析 软件工程 自动化设计 智能助手
📋 核心要点
- 现有方法在评估LLM生成的UML类图时,缺乏对推理过程的深入分析,导致幻觉现象难以定位。
- 本文提出了一种新的经验分类法,将幻觉现象分为提示忠实度、代码忠实度和推理质量三个维度,以便更好地理解和缓解幻觉问题。
- 实验结果表明,通过在生成提示中增加忠实度约束,F1得分提高了4个百分点,显示出针对性缓解的有效性。
📝 摘要(中文)
大型语言模型(LLMs)能够根据自然语言需求生成UML类图,但幻觉现象可能影响生成图的正确性和完整性。现有评估主要关注最终图形,而未深入分析LLMs的推理过程。本文提出了一种包含11种幻觉子类型的经验分类法,分为三维:提示忠实度、代码忠实度和推理质量。通过对60个手动标注的DeepSeek-R1追踪进行分析,发现代码忠实度在两个数据集中最为常见,而提示忠实度在DeepSeek-V4-Pro中占主导地位。通过在13个Golden UML ModelSet案例中进行的缓解实验,增加提示忠实度和推理质量约束后,F1得分提高了4个百分点。
🔬 方法详解
问题定义:本文旨在解决大型语言模型在生成UML类图时出现的幻觉现象,现有方法主要评估最终结果,未能深入分析推理过程中的问题。
核心思路:通过构建经验分类法,将幻觉现象细分为多个子类型,帮助识别和定位幻觉的来源,从而为缓解措施提供依据。
技术框架:研究首先对60个DeepSeek-R1追踪进行手动标注,形成分类法,然后应用于120个追踪,最后在20个DeepSeek-V4-Pro追踪上进行验证,形成完整的分析流程。
关键创新:提出的经验分类法是本研究的核心创新,能够系统性地识别和分类幻觉现象,与传统方法相比,提供了更为细致的分析视角。
关键设计:在缓解实验中,采用了Qwen3模型,并通过增加提示忠实度和推理质量约束来优化生成过程,具体参数设置和损失函数设计未详细披露。
🖼️ 关键图片
📊 实验亮点
实验结果显示,增加提示忠实度和推理质量约束后,F1得分提高了4个百分点,而后续的代码忠实度审查未能提供一致的额外收益。这表明针对性缓解措施的有效性和局限性。
🎯 应用场景
该研究的潜在应用领域包括软件工程、自动化设计和智能助手等。通过提高LLM生成UML类图的准确性,可以有效支持软件开发过程中的需求分析和设计阶段,未来可能对软件工具的智能化发展产生深远影响。
📄 摘要(原文)
Large Language Models (LLMs) can generate UML class diagrams from natural language requirements, but hallucinations may compromise the correctness and completeness of the resulting diagrams. Existing evaluations mostly assess the final diagram, without examining the intermediate traces of reasoning-capable LLMs, which can reveal where these hallucinations arise. We develop an empirical taxonomy of eleven hallucination sub-types organised into three dimensions: Prompt Faithfulness (deviations between requirements and reasoning), Code Faithfulness (discrepancies between reasoning and generated PlantUML code), and Reasoning Quality (problems within the reasoning). The taxonomy was derived from 60 manually annotated DeepSeek-R1 traces, applied to 120 further DeepSeek-R1 traces through a dual-LLM annotation pipeline, and examined on 20 DeepSeek-V4-Pro traces. Code Faithfulness was the most frequent dimension for DeepSeek-R1 in both datasets, whereas Prompt Faithfulness dominated for DeepSeek-V4-Pro, suggesting model-dependent failure patterns. In the manually annotated traces, reasoning-trace length showed no significant monotonic association with hallucination frequency, whereas requirement complexity was negatively associated with it, particularly for Prompt Faithfulness errors. In a mitigation experiment on 13 Golden UML ModelSet cases with three Qwen3-based models, adding Prompt Faithfulness and Reasoning Quality constraints to the generation prompt raised the pooled mean F1 score by 4.0 percentage points, whereas a post-hoc Code Faithfulness review provided no consistent further benefit. Relationship modelling remained the lowest-scoring element throughout. These results suggest that localising hallucinations within the generation process can inform targeted, prompt-based mitigation. Whether these findings generalise beyond the DeepSeek and Qwen3 model families remains to be tested.