M5-105M5: NLP & Large Language ModelsHallucination & AI SafetyEasy
⚡Flashcard Drill➔Mastery:

Comprehensive Mitigation Strategies for LLM Hallucinations

📐 Mathematical Definition
mitigations: RAG,tools,citation,’I don’t know’,verification,training\text{mitigations}:\ \text{RAG},\text{tools},\text{citation},\text{'I don't know'},\text{verification},\text{training}
⚡ One-Sentence Core Answer
Combats hallucinations through retrieval-augmented generation (RAG), external tool execution, calibrated refusal prompts, contrastive decoding, alignment data curation, and programmatic post-verification.

📌 Key Takeaways

  • •
    Retrieval grounding: supplying authoritative context documents via RAG to constrain the model's generation space
  • •
    Deterministic tools: delegating arithmetic calculation, database queries, and symbolic manipulation to external non-parametric engines
  • •
    Instructional and decoding controls: explicit 'admit ignorance' permissions, required inline citations, contrastive decoding (DoLa), and self-consistency voting

📐 Mathematical Derivations

Mathematical Mechanism: 1. Contrastive Decoding / DoLa (Decoding by Contrasting Layers): Factuality knowledge is often consolidated in higher transformer layers, whereas surface-level linguistic priors dominate intermediate layers. Subtracting intermediate-layer log probabilities from final-layer log probabilities amplifies factual tokens: zt∗=log⁡Pfinal(xt∣x<t)−αlog⁡Ppremature(xt∣x<t)z_t^* = \log P_{\text{final}}(x_t \mid x_{<t}) - \alpha \log P_{\text{premature}}(x_t \mid x_{<t}) effectively downweighting fluent hallucinations and elevating factual knowledge. 2. Calibrated Abstention Formulation: Let C(x)C(x) be the model's epistemic confidence score. The optimal abstention policy minimizes loss: min⁡E[Lerror⋅I(Answered∧Incorrect)+Labstain⋅I(Refused)]\min \mathbb{E}\left[ \mathcal{L}_{\text{error}} \cdot \mathbb{I}(\text{Answered} \land \text{Incorrect}) + \mathcal{L}_{\text{abstain}} \cdot \mathbb{I}(\text{Refused}) \right] When Lerror≫Labstain\mathcal{L}_{\text{error}} \gg \mathcal{L}_{\text{abstain}}, the system outputs 'I do not have sufficient information' if C(x)<τC(x) < \tau.

🏭 Production Trade-offs

Deep Dive & Engineering Trade-offs: ① The High ROI of 'Permission to Abstain': The simplest and most impactful hallucination reduction in production is prompt engineering that explicitly permits abstention ('If the provided documents do not contain the answer, reply with: UNKNOWN'). Eliminating the implicit constraint that the model *must* produce an answer slashes confabulations by over 50%. ② Tool Invocations as Non-Parametric Anchors: Never allow an LLM to perform multi-digit arithmetic or write SQL queries from memory; bind the model to deterministic Python interpreters or SQL engines. If computation is delegated to an external runtime, the hallucination probability on calculations collapses to zero. ③ Inline Citation Verification: Forcing models to produce brackets [1] linked to specific retrieved chunks enables downstream programmatic validation: regex-extract all citations, compute Natural Language Inference (NLI) entailment scores between each generated sentence and its cited chunk, and strip ungrounded assertions before rendering to users. ④ Contrastive Decoding Overhead: Decoding mechanisms like DoLa or contrastive sampling require evaluating multiple forward passes or layer taps per token, incurring a 20-40% latency penalty; they should be selectively activated on high-stakes factual tasks. ⑤ Interview Strategy: Categorize mitigations across the lifecycle (Pre-inference: RAG/tools; Decoding: DoLa/self-consistency; Post-inference: NLI verification; Training: DPO on calibrated refusal), and emphasize the abstention threshold trade-off.
⚠️ Common Interview Pitfalls
  • ✕
    Omitting explicit permission to admit ignorance in prompts, forcing models into speculative hallucinations
  • ✕
    Mandating citation outputs without verifying downstream that the cited text actually entails the generated claim
  • ✕
    Relying on model internal parametric weights for exact arithmetic calculations rather than binding to a code execution tool
🎯 Interviewer Follow-up Inquiries
  • ?
    How does Decoding by Contrasting Layers (DoLa) mathematically isolate factual knowledge from surface-level fluency?
  • ?
    How do you build a low-latency post-generation verification pipeline using Natural Language Inference (NLI) models?
⚡
Test muscle memory on this topic via 3-Layer Flashcards
Active Recall: Mentally formulate Prompt ➔ Math Derivation ➔ Benchmark Implementation in 3 minutes.
🎯 Drill This Card Now➔
📚

Associated Knowledge Base Guides & Mindmaps

Explore the comprehensive technical article, exam cards, and global architecture tree.

← PreviousM5-104: Taxonomy, Root Causes, and Failure Modes of LLM Hallucinations📋Back to BankNext →M5-106: Uncertainty Quantification and Probability Calibration for Hallucination Detection
中文速览与面试要点

列举缓解幻觉的主要手段。

检索增强(RAG)、工具调用、约束(要求引用/允许不知道)、解码策略、训练(RLHF/偏好数据)、以及后验校验。

核心要点

  • 数学机理: 六类缓解手段 。 (1) 检索增强(RAG) ——把相关文档放入上下文,让模型'基于证据回答';治 忠实性幻觉 (有据可依)与部分事实性(提供最新知识)。 前提 ——(a) 检索质量(召回正确文档)、(b) 模型真的使用证据(需 prompt 强调)、(c) 允许'资料中没有则说不知道'。 (2) 工具调用 ——把'精确计算'(计算器)、'事实查询'(搜索/数据库)、'结构化操作'交给外部工具;从根本上消除'算术错误'与'记忆错误'(因为不再依赖参数中的知识)。这是 最可靠 的手段(对外部可验证的部分)。 (3) 约束与 prompt 设计 ——(a) 要求引用 ('每句话都要引用来源')——使幻觉可核查;(b) 允许'不知道' ('若资料中没有,请回答不知道')—— 这是最有效也最被忽视的手段 ;因为模型'编造'常源于'被要求必须回答';(c) 要求给出置信度 ;(d) 要求先列证据再结论 (chain-of-thought with evidence)。 (4) 解码策略 ——(a) 降低温度 (减少随机性,但可能降低多样性);(b) 对比解码 (contrastive decoding:对比'专家模型'与'业余模型'的分布,放大前者偏好的 token);(c) doLa (对比不同层的分布);(d) 自一致性 (多次采样 + 投票,过滤偶发幻觉)。 (5) 训练层面 ——(a) 偏好数据含'承认不知道'的正例 (教模型'诚实');(b) RLHF/DPO 中惩罚幻觉 (用忠实度作为奖励维度);(c) 专门的幻觉数据集微调 (如教模型'什么时候该说不知道');(d) 校准训练 (让置信度反映正确率)。 (6) 事后校验(verification) ——(a) 事实核查 (用检索/工具验证回答中的事实);(b) 一致性检查 (多次生成是否一致);(c) 引用检查 (引用是否真实存在且支持该陈述);(d) 自我批评 (让模型检查自己的回答——但效果有限,见自反思题);(e) 外部验证器 (专门的 NLI 模型判断'证据是否蕴含回答')。 组合使用 ——实践中常'RAG + 工具 + 允许不知道 + 引用 + 事后校验'组合;单一手段难以覆盖所有幻觉类型。 评估 ——用忠实度指标(RAGAS 的 faithfulness)、事实性基准(TruthfulQA、FActScore)、以及'拒答的合理性'(是否在不知道时拒答)。
  • 深度剖析与工程权衡:① '允许说不知道'是性价比最高的手段 ——它的成本是'修改 prompt'(几乎为零),但能显著减少'无依据的编造';前提是 评估要包含'不知道'的测试 (否则模型学会'乱答'反而分数高)。② '工具调用最可靠' ——对可验证的部分(算术、查询、结构化操作),工具从根本上消除错误;故'能调工具就调工具'。③ 'RAG 治忠实性、工具治精确性、训练治倾向性' ——三类手段针对不同幻觉来源;故需 组合 。④ '引用'的双面性 ——要求引用能 (a) 让幻觉可核查、(b) 提升用户信任;但若模型 编造引用 则更危险(看起来可信);故需 引用校验 (检查引用是否存在且支持)。⑤ '事后校验'的成本 ——用检索/工具验证每个事实很贵;故常用'抽样校验'或'关键事实校验'。⑥ 面试要点 ——被问'怎么减少幻觉',应给出' 六类手段(RAG/工具/约束/解码/训练/校验)+ 组合使用 ',并强调' 允许说不知道是性价比最高的 '与' 工具最可靠 ';能指出'引用需校验(防编造)'是深度理解的标志。
  • 检索增强:提供证据(治忠实性 + 部分事实性)
  • 工具调用:把计算/查询交给外部(消除算术/事实错误)
  • 约束与训练:要求引用、允许'不知道'、偏好数据含'承认不知道'

常见陷阱

  • prompt 隐含'必须回答'(鼓励编造)
  • 要求引用但不校验引用真实性