LLM 为什么会 hallucinate?
怎么避免?

英文问法How would you reduce hallucinations in an LLM application? · Why do LLMs hallucinate? · How do you detect hallucinations?

考过★ 作者本人微软 AS 电面 · 面经:微软中国 Bing LLM 应用组实习(RAG hallucination)· 微软 AS 实习电面问 LLM 部署的问题与解法(1p3a 1158834)· Interview Query 指南

先弄清楚:每个概念是什么

Hallucination
流畅、自信、但没有依据的内容。像考试不会也不留白,编一个看着像的答案。
Factuality vs faithfulness
factuality 错是和真实世界不符;faithfulness 错是和给它的 context、指令不符。RAG 场景主要防后者。例:说电话是 Edison 发明的 → factuality;摘要里出现原文没有的数字 → faithfulness。
Knowledge boundary(长尾知识)
训练数据里只见过一两次的事实记不牢,新发生的事没见过,但模型照样回答。例:20% 的生日事实在训练数据里只出现一次,base model 就至少在约 20% 的生日问题上编。
Self-consistency
同一个问题 sample 多条 reasoning path,对最终答案 majority vote。编的答案每次不一样,所以不一致也能当 hallucination 的信号(SelfCheckGPT,不需要外部数据库)。代价是 inference 成本乘以 sample 数。

30 秒回答

A hallucination is fluent output that isn't supported: factually wrong, or unfaithful to the given context. Causes are noisy or outdated data, long-tail facts seen only once, training and benchmarks that reward confident guessing over abstaining, and sampling randomness. To mitigate, ground the model: retrieve documents with RAG, answer only from them with citations, and call tools for math or fresh data. Decode with a low temperature. Train abstention with SFT and RLHF data that reward "I don't know". Then verify: sample several answers and check consistency, run an NLI check against the sources, and track groundedness in evaluation.

推导:为什么模型宁可猜

设模型答对的把握是 \(c\)。0-1 打分(答错和"不知道"都 0 分)下,猜的期望是 \(c \ge 0\),永远不亏。大多数 benchmark 和 post-training 都这样打分,所以模型爱猜。改成答错扣 \(t/(1-t)\) 分:

\[ \mathbb{E}[\text{guess}] = c - (1-c)\,\frac{t}{1-t} \] \[ \mathbb{E}[\text{guess}] > 0 \iff c > t \]

例:\(c = 0.3\)。0-1 打分下猜得 0.3 分;\(t = 0.5\)(错一题扣 1 分)下猜得 \(0.3 - 0.7 = -0.4\),应该说不知道。

怎么缓解:分层做

层做法针对
数据 / 训练data cleaning、更新数据;SFT 加拒答样本;RLHF 惩罚编造错误知识、不会拒答
GroundingRAG + 逐句 citation;prompt 要求只据材料回答,没有就说不知道;tool(search、calculator、code)缺知识、知识过时
Decoding低 temperature 或 greedy抽到 tail 里的词
检测self-consistency;NLI 判断回答是否被 source 支持;数字、日期做 rule check;高风险加 human review前面漏掉的
评估TruthfulQA、FActScore、groundedness衡量

必答点

追问

用了 RAG 还会 hallucinate 吗?

会。检索错、文档和模型自己的记忆冲突、context 太长时中间的信息被忽略,都会出错。对策见 RAG 的三个难点。

RLHF 之后为什么还会编,甚至顺着用户说?

因为 sycophancy,人类标注者和 reward model 都偏爱顺着用户的回答。RLHF 仍然有用,InstructGPT 在 closed-domain 任务上的 hallucination 率从 GPT-3 的 41% 降到 21%。

temperature 设成 0 就不会 hallucinate 了吗?

不会。greedy 只去掉 sampling 的随机性,记错或没见过的知识照样被当成最可能的答案输出。

来源Huang et al. 2023(hallucination survey) §2.3(pp.5–7)、§3.1.2(p.9)、§3.2.2–3.3.1(p.11)、§4.1(pp.12–15)、§4.2(pp.17–18)、§6.2(pp.30–31)·Kalai et al. 2025(Why Language Models Hallucinate) §1(pp.1–4)、§4.2(p.13)· Manakul et al. 2023(SelfCheckGPT) Abstract(p.1)· Wang et al. 2023(self-consistency) §2(p.3)· Zhang et al. 2024(R-Tuning) Abstract · Ouyang et al. 2022(InstructGPT) §1(p.3)