← 知识图谱 ← 返回学习站

LLM 中的幻觉问题

Extrinsic Hallucinations in LLMs
Lilian Weng · OpenAI · 2024-07-07

Hallucination in large language models usually refers to the model generating unfaithful, fabricated, inconsistent, or nonsensical content. Here, I narrow down the problem to cases where the model output is fabricated and not grounded by either the provided context or world knowledge.

大语言模型中的幻觉通常指模型生成不忠实、捏造、不一致或无意义的内容。这里将问题缩小为:模型输出是编造的,且无法被提供的上下文或世界知识所支撑

There are two types of hallucination: In-context hallucination (output inconsistent with source content in context) and Extrinsic hallucination (output should be grounded by the pre-training dataset, essentially world knowledge). This post focuses on extrinsic hallucination. To avoid hallucination, LLMs need to be (1) factual and (2) acknowledge not knowing the answer when applicable.

幻觉分两种:上下文幻觉(输出与上下文中的源内容不一致)和外部幻觉(输出应被预训练数据集/世界知识支撑)。本文关注外部幻觉。为避免幻觉,LLM 需要(1)符合事实(2)在不知道答案时承认不知道。

💡 AI 解读

幻觉问题的本质:LLM 是"概率预测器",不是"事实数据库"。它生成的是"听起来合理的文本",而非"经过验证的事实"。区分两种幻觉很重要——上下文幻觉可以通过 RAG 解决(给模型正确的上下文),外部幻觉更难(模型内化了错误信息)。一个好的 LLM 必须学会说"我不知道"。

幻觉的成因

预训练数据问题

The pre-training data corpus is enormous, crawled from the public Internet. Out-of-date, missing, or incorrect information is expected. As the model may incorrectly memorize this information by simply maximizing the log-likelihood, we would expect the model to make mistakes.

预训练数据量巨大,从公开互联网爬取。过时、缺失或错误的信息是预期之中的。由于模型可能只是通过最大化对数似然来错误地记住这些信息,我们可以预期模型会犯错。

微调引入新知识

Gekhman et al. 2024 studied whether fine-tuning LLMs on new knowledge encourages hallucinations. They found: (1) LLMs learn fine-tuning examples with new knowledge slower; (2) Once examples with new knowledge are eventually learned, they increase the model's tendency to hallucinate. The best dev performance is obtained when the LLM fits the majority of Known training examples but only a few of the Unknown ones.

Gekhman 等 2024 研究了在微调中引入新知识是否会加剧幻觉。发现:(1)LLM 学习包含新知识的微调样本更慢;(2)一旦学会了新知识样本,模型的幻觉倾向反而增加。最佳表现出现在模型学会了大部分"已知"样本但只学会少量"未知"样本时。

💡 AI 解读

这是一个反直觉的发现:微调中教模型新知识会使其更容易产生幻觉。原因:微调数据量远小于预训练数据,模型无法通过少量样本可靠地学习新知识——它只是"记住"了而不"理解"。当模型试图使用这些不牢固的新知识时,就容易"编造"。实践建议:微调应该强化模型已有的能力,而不是灌输新知识;新知识应该通过 RAG 在推理时提供。

幻觉检测

检索增强评估

FactualityPrompt (Lee et al. 2022): Uses Wikipedia as knowledge base. Two metrics: Hallucination NE errors (fraction of named entities not in ground truth) and Entailment ratios (fraction of sentences supported by Wikipedia).

FactualityPrompt(Lee 等 2022):使用维基百科作为知识库。两个指标:命名实体错误率(不在真实文档中的命名实体比例)和蕴含比率(被维基百科支撑的句子比例)。

FActScore (Min et al. 2023): Decomposes long-form generation into atomic facts and validates each against Wikipedia. Error rates are higher for rarer entities and for facts mentioned later in the generation.

FActScore(Min 等 2023):将长文本生成分解为原子事实,逐一与维基百科验证。越罕见的实体错误率越高;生成文本后段的事实错误率也更高。

SAFE (Wei et al. 2024): Uses a language model as an agent to iteratively issue Google Search queries and reason about whether search results support each fact. Works better than human annotators despite being 20x cheaper.

SAFE(Wei 等 2024):使用语言模型作为智能体,迭代发出 Google 搜索查询并推理搜索结果是否支撑每个事实。比人工标注效果更好,且成本低 20 倍。

💡 AI 解读

幻觉检测的演进路径非常清晰:人工标注 → 自动化指标(NER/蕴含) → 原子事实分解 → LLM 智能体搜索验证。SAFE 代表了最新趋势——用 AI 自己来验证 AI 的事实性。核心思路:把长文本拆成一个个可验证的小事实,然后让搜索智能体逐一核查。这比人工更快更便宜,甚至更准确。

采样检测

SelfCheckGPT (Manakul et al. 2023): Relies on consistency check against multiple samples from a black-box LLM. If the model is factual, multiple samples should be consistent. If hallucinating, samples will diverge. No external knowledge base needed—black-box access is sufficient.

SelfCheckGPT(Manakul 等 2023):通过多次采样的一致性检查来检测幻觉。如果模型输出的是事实,多次采样应该一致;如果在幻觉,采样结果会发散。不需要外部知识库——黑盒访问即可。

💡 AI 解读

SelfCheckGPT 的洞察极其精妙:幻觉是不稳定的,事实是稳定的。如果你问一个人"你确定吗?"多次,他对真事的回答会一致,对编造的事会前后矛盾。同理,多次采样 LLM 同一个问题的回答,如果答案不一致,很可能是幻觉。这个方法不需要任何外部工具,只需要 API 调用几次——是最简单实用的幻觉检测方法。

未知知识的校准

TruthfulQA (Lin et al. 2021): 817 adversarial questions across 38 topics (health, law, finance, politics). Tests common misconceptions. Larger models are LESS truthful on this benchmark, due to better mimicking of human falsehoods.

TruthfulQA(Lin 等 2021):817 个对抗性问题,覆盖 38 个主题(健康、法律、金融、政治)。测试常见误解。更大的模型在这个基准上反而更不诚实,因为它们更好地模仿了人类的错误观念。

SelfAware (Yin et al. 2023): 1,032 unanswerable questions + 2,337 answerable ones. Tests whether models know what they don't know. Larger models do better at distinguishing answerable vs unanswerable.

SelfAware(Yin 等 2023):1,032 个无法回答的问题 + 2,337 个可回答的问题。测试模型是否知道自己的知识边界。更大的模型在区分可回答/不可回答方面表现更好。

💡 AI 解读

TruthfulQA 的发现颠覆认知:模型越大越容易被人类偏见误导。因为大模型从海量数据中学到了人类的错误信念(如"感冒是因为受凉")。这与"涌现能力"背道而驰——在对抗性事实问题上,规模不仅没帮助,反而有害。解决方案不是停止扩大模型,而是改进对齐训练(教会模型质疑流行但不正确的观念)。

反幻觉方法

RAG 与编辑归属

RARR (Gao et al. 2022): Retroactively enables attributions via two stages—Research (find related documents) and Revision (edit unsupported content while preserving original). Measures both Attribution (how much is supported by evidence) and Preservation (how much original text is kept).

RARR(Gao 等 2022):通过两个阶段事后添加归属——研究(找到相关文档)和修订(编辑不受支撑的内容,同时保留原文)。同时衡量归属度(有多少被证据支撑)和保留度(保留了多少原文)。

Self-RAG (Asai et al. 2024): Trains a LM end-to-end to reflect on its own generation using special reflection tokens: Retrieve (whether to search), IsRel (is it relevant?), IsSup (is it supported?), IsUse (is it useful?). The model retrieves multiple documents in parallel and critiques its own generation.

Self-RAG(Asai 等 2024):端到端训练模型使用特殊反思 token 来自我审查:Retrieve(是否检索)、IsRel(是否相关)、IsSup(是否被支撑)、IsUse(是否有用)。模型并行检索多个文档并批评自己的生成。

💡 AI 解读

Self-RAG 是"自我反思"在 RAG 中的应用。它不只是检索后生成,而是在每一步都"问自己":我需要检索吗?检索结果相关吗?我的回答被支撑了吗?这种内省机制让模型从"被动使用检索"变成"主动判断何时需要检索、检索结果是否可信"——更接近人类研究者的工作方式。

验证链(Chain-of-Verification)

CoVe (Dhuliawala et al. 2023): Four steps: (1) Baseline response—model produces initial draft; (2) Plan verification—model designs verification questions; (3) Execute verifications—model answers each question independently; (4) Final output—generate refined output. Key insight: instruction-tuning and CoT do NOT reduce hallucinations; factored verification works better than long-form generation.

CoVe(Dhuliawala 等 2023):四步流程:(1)基线响应——模型生成初稿;(2)规划验证——模型设计验证问题;(3)执行验证——模型独立回答每个问题;(4)最终输出——生成改进后的输出。关键发现:指令微调和 CoT 并不能减少幻觉;分解式验证比长文本生成效果更好。

💡 AI 解读

CoVe 的核心思路:先写 → 再质疑 → 独立验证 → 修正输出。类似于人类写论文的过程——先写初稿,然后自我审查每个论点是否有据可查。关键经验:让模型独立回答验证问题(而非在原文上下文中回答),可以避免原始幻觉"污染"验证过程。CoT(思维链)虽然能提升推理,但对事实性没有帮助——推理正确≠事实正确。

采样方法

Factual-nucleus sampling (Lee et al. 2022): Based on the hypothesis that sampling randomness does more harm to factuality at the latter part of the sentence. Dynamically adapts probability p during sampling: higher randomness at the beginning, lower at the end. Inference-Time Intervention (Li et al. 2023): Identifies attention heads correlated with truthfulness and shifts their activations toward the "truthful" direction at inference time.

事实性核采样(Lee 等 2022):基于"采样随机性对句子后半部分的伤害更大"的假设。采样时动态调整概率 p:开头随机性高,结尾随机性低。推理时干预 ITI(Li 等 2023):识别与事实性相关的注意力头,在推理时将其激活向"真实"方向偏移。

事实性微调

FLAME (Lin et al. 2024): Factuality-aware alignment (SFT + DPO). Key finding: RLHF makes factuality WORSE, because human feedback often prefers longer, more detailed answers, which are not necessarily more factual. Factuality tuning (Tian & Mitchell et al. 2024): Fine-tunes with DPO on automatically annotated truthfulness scores.

FLAME(Lin 等 2024):事实性感知对齐(SFT + DPO)。关键发现:RLHF 使事实性变差,因为人类反馈通常偏好更长、更详细的回答,但更详细不一定更符合事实。事实性微调(Tian & Mitchell 等 2024):使用自动标注的真实性分数进行 DPO 微调。

💡 AI 解读

这是 LLM 对齐中最尖锐的矛盾之一:人类偏好和事实性之间存在冲突。人类评估者倾向于给更长、更流畅、更"听起来自信"的回答更高分,即使这些回答包含更多幻觉。这意味着 RLHF 在提升"用户体验"的同时可能降低"事实性"。解决方案:用自动化事实检查(而非人类偏好)作为 RLHF 的奖励信号。

归属微调

WebGPT (Nakano et al. 2022): Combines web search with fine-tuned GPT. The model browses the web and learns to answer with references. GopherCite (Menick et al. 2022): Similar but generates demonstrations via few-shot prompting. Configures the model to decline answering with "I don't know" when below a confidence threshold (selective prediction).

WebGPT(Nakano 等 2022):将网络搜索与微调 GPT 结合。模型浏览网页并学会带引用回答。GopherCite(Menick 等 2022):类似但通过少样本提示生成示范。配置模型在信心低于阈值时拒绝回答——"我不知道"(选择性预测)。

💡 AI 解读

归属微调代表了另一种解决幻觉的思路:不要求模型"无所不知",而是要求它"说出信息来源"。如果模型每个陈述都有引用,用户就可以自己判断可信度。"选择性预测"(低信心时说"我不知道")是最简单但最有效的反幻觉策略——宁可不说也不要瞎说。

评估基准汇总

TruthfulQA:817 题对抗性测试(人类常见误解)
FactualityPrompt:基于维基百科的事实性基准
SelfAware:1,032 个不可回答 + 2,337 个可回答问题
LongFact:2,280 个长文本事实性提示
FEVER:185,445 条声明(支持/反驳/信息不足)
FAVABench:600 个精细幻觉标注的响应