跳转至

幻觉 — 与 Thinking 关系 + 减少策略

更新日期:2026-04-26

幻觉(hallucination)是 LLM 最大的产业落地障碍。本文按四个维度过:

  1. 幻觉的种类与机制
  2. 幻觉跟 thinking effort 的关系(读者重点关心)
  3. 减少幻觉的方法:架构 / 推理 / 数据 三层
  4. 评测:怎么量化幻觉率

主要参考:


一、幻觉分类

1.1 按内容关系分

类型 例子 出现概率
事实幻觉 (factual) "爱因斯坦 1955 年获诺贝尔奖"(错,1921)
逻辑幻觉 (logical) "因为 A,所以 B"(A 不蕴含 B)
指令幻觉 (instruction) 模型偏离指令(让总结却扩写)
上下文幻觉 (context) RAG 时模型说"文档里说了 X"(文档没说)
自相矛盾 (self-contradiction) 同一回答里前后矛盾
数值幻觉 (numeric) 数学计算错(21 × 19 = 401,错)
代码幻觉 调用不存在的 API、误用语法 高(特别小模型)

1.2 按可检测性分

  • 闭式(可验证):数学、代码、事实查询。能用 verifier 自动检测
  • 开放式(难验证):写作、建议、解释。需要人工 / 强 LLM 判断

1.3 按机制分

  • Knowledge gap hallucination:模型本身不知道,编一个 plausible 答案
  • Pattern-completing hallucination:训练数据中类似 pattern 让模型 over-generalize
  • Distractor hallucination:长 context 中关键信息被周边噪声淹没
  • Sycophancy hallucination:用户暗示一个错答案,模型迎合

二、幻觉与 Thinking 的关系(本章核心)

2.1 thinking 是否减少幻觉?

整体观察:thinking 模型(o1 / R1 / Claude 3.7+)在以下场景显著减少幻觉

场景 thinking 是否帮助 程度
数学计算 大(错误率从 50% → <10%)
代码生成(标准题) 中(HumanEval +10-20%)
多步推理题
多 hop 事实 QA
单事实 QA("X 出生年") 没帮助甚至有害
主观判断 / 创作 几乎不影响
长 context 信息检索 取决于 thinking 是否引导 retrieval

2.2 为什么 thinking 帮不了单事实查询

模型不"知道"某个事实时,再 think 也变不出来。Thinking 只能:

  • 检查计算:5 × 7 = 35 这种可以 verify
  • 结构化推理:把多步链条理清
  • 多路探索:尝试不同 reasoning path

事实 recall 是 weight-stored knowledge —— thinking 不会创造新知识。如果 weight 里就没有"鲁迅生年",thinking 只会让模型生成更"convincing"的错答案。

2.3 反向:thinking 可能增加某种幻觉

OpenAI 2024 Why Models Hallucinate (Kalai et al.) 指出:

  • 推理模型在 thinking 中生成更多 reasoning step
  • 每个 step 都是潜在 error 源
  • Long reasoning chain → 累积错误概率上升
  • 特别是当 thinking 涉及 model 不确定的事实时

实测:SimpleQA(高难度事实 QA)上,reasoning model 错误率反而高于 base model

模型 SimpleQA 准确率 备注
GPT-4o (no thinking) ~38% base
o1-preview ~42% 略升
o1 ~47%
Claude 3.5 Sonnet ~42% base
Claude 3.7 + thinking ~44%

不接受 "I don't know" 的情况下:

模型 "Hallucinated answer" 比例
GPT-4o 30%
o1 38% (更高!)

reasoning model 更倾向于给出 confidently wrong 答案而非 "I don't know"。

2.4 解读:thinking 的双刃剑

事实查询:thinking 不增加 recall,但增加 confidence
模型更不愿意说 "I don't know"
更多 confident hallucination

工程教训:

  • 数学 / 推理任务:开 thinking,受益大
  • 事实查询任务:thinking 帮助有限,需要 RAG / 知识库支持
  • 复杂任务:thinking + tools(interleaved)才是组合拳

三、减少幻觉 —— 架构层

3.1 Retrieval-Augmented Generation (RAG)

最有效的"知识幻觉"解药:把外部知识在推理时注入 context。

flowchart LR
    query["User query"]
    retr["Retriever<br/>(向量 DB / BM25)"]
    docs["Top-k docs"]
    llm["LLM<br/>(grounded on docs)"]
    answer["Answer with citations"]

    query --> retr --> docs --> llm --> answer
    query --> llm

    classDef stage fill:#fff,stroke:#cc785c,color:#1a1a1a;
    class query,retr,docs,llm,answer stage

工程要点:

  • Retriever quality 决定上限(垃圾进垃圾出)
  • Citation enforcement:模型必须 cite 文档来源(Generation with Citations
  • 不见知识则承认:训练让模型在 retrieve 不到时说 "I don't have this info"

3.2 长 context(超大窗口)

把整个知识库塞 context("context as memory")。

简单实现 Long context 自身有 retrieval 失败问题(见 J1 长 context
不需要 retriever Token cost 高

实战:通常 RAG(小 context + retrieval)比 long context 更便宜更准。Long context 适合知识不大但需要全局理解的场景(一份合同、一篇论文)。

3.3 Mixture-of-Experts 知识容量

MoE 模型有更大的总参数 → 更多 weight-stored knowledge。671B MoE(V3)的事实 recall 高于 70B dense 是已知的。

激活参数小(V3 只有 37B active)→ 推理时未必 outperform dense 70B 在所有 task。

3.4 显式知识图谱(KG-augmented)

把 knowledge graph 集成到 LLM:

  • 训练时 attention over KG entity embeddings(K-BERT, ERNIE
  • 推理时 retrieve KG triples 注入 prompt

学术界很多工作,但生产级 LLM 几乎不用 KG。原因:维护 KG 成本高,效果不显著优于 RAG。

3.5 Constrained generation

强制 grammar / regex 约束 generation:

# 强制 JSON 格式
schema = {"type": "object", "properties": {"answer": {"type": "number"}}}
output = model.generate(prompt, json_schema=schema)

工具:

  • Outlines (Python lib):grammar-guided decoding
  • JSON mode (OpenAI / Anthropic API)
  • Pydantic + Instructor:Python 生态

效果:消除"格式幻觉"(输出错格式),但不消除内容幻觉


四、减少幻觉 —— 推理层

4.1 Self-Verification

让模型生成答案后自己 verify

def with_verification(model, prompt):
    answer = model.generate(prompt)
    verify_prompt = f"""
    Question: {prompt}
    Proposed answer: {answer}
    Is this answer correct? List concerns. (yes/no + reasoning)
    """
    verification = model.generate(verify_prompt)
    if "yes" in verification.lower():
        return answer
    else:
        # 修正
        revise_prompt = f"""
        Original: {answer}
        Concerns: {verification}
        Revised answer:
        """
        return model.generate(revise_prompt)

这是 Self-Refine 的核心 pattern。Constitutional AI 的 SL-CAI 是其特化版。

4.2 Chain-of-Verification (CoVe)

Dhuliawala et al. 2023 提出 CoVe:

  1. Draft initial response
  2. Plan verification questions
  3. Answer each verification question independently
  4. Generate final response based on verifications
[Draft] 名侦探柯南是日本动画,1996 年由青山刚昌创作。
[Verify Q1] 柯南连载哪一年开始?
[Verify A1] 1994 年。
[Verify Q2] 谁创作?
[Verify A2] 青山刚昌。
[Final] 名侦探柯南是青山刚昌创作的日本漫画/动画,1994 年开始连载。

CoVe 比朴素 CoT 在 fact-heavy task 上准确率提升 5-15%。

4.3 Confidence-aware decoding

模型对每 token 输出 logit → softmax → probability。低 confidence 的 token 是潜在幻觉点。

Confidence-based abstention

def confident_generate(model, prompt, threshold=0.5):
    output_tokens = []
    for step in range(max_len):
        logits = model.forward(prompt + output_tokens)
        probs = softmax(logits)
        top_p = probs.max()
        if top_p < threshold:
            return "[Uncertain - declining to answer]"
        token = probs.argmax()
        output_tokens.append(token)
    return decode(output_tokens)

实战:粗暴的 token-level threshold 会过早 abort。更好做法是 sentence-level confidence(采 N 次看一致性)。

4.4 Self-Consistency (CoT)

同一 prompt 采 N 次,看 answer 分布。

  • 多次答案一致 → 高 confidence
  • 多次答案分散 → 低 confidence,可能 hallucinate

Self-Consistency 在数学题上 +5-15% 准确率(见 J3 reasoning-modes)。

4.5 Best-of-N + Reward Model

采 N 个候选,用 RM 打分取最高:

def best_of_n(model, rm, prompt, n=5):
    candidates = [model.generate(prompt) for _ in range(n)]
    scores = [rm(prompt, c) for c in candidates]
    return candidates[scores.index(max(scores))]

RM 可以是:

  • 通用 reward model(HelpSteer)
  • 特定任务的 PRM(process reward model,对推理步骤打分)
  • Verifier model(数学 / 代码用 rule-based)

OpenAI Let's Verify Step by Step 的 PRM 路线就是这个范式。

4.6 Ensemble / Multi-Agent

跨多个模型采样 + 投票:

  • 不同模型有不同 hallucination pattern
  • 投票后只留多模型一致的答案

成本高,少用于生产。但在高准确率要求场景(医疗、法律)有价值。


五、减少幻觉 —— 数据层

5.1 SFT 数据中的"承认不知道"

训练数据中显式包含 "I don't know" 例子

[Prompt] What was Shakespeare's middle name?
[Bad answer] His middle name was Edward.    # 编造
[Good answer] Shakespeare didn't have a recorded middle name. I'm not certain about this detail.

效果:模型学到 "weak knowledge → 承认不知道"。

实操难点:标注成本高(需要为每个 prompt 标记真实 confidence)。

5.2 RLHF / RLAIF 中的 honesty signal

reward 设计:

  • Hallucinate confidently → reward 严重负
  • Refuse with calibration → reward 中性
  • Answer correctly → reward 正
def honesty_reward(prompt, output, ground_truth=None):
    if "I don't know" in output or "uncertain" in output:
        # 承认不知道:中性 reward(避免模型 always refuse)
        return 0.0

    if ground_truth is None:
        # 无 ground truth 的开放问题,用 RM 打分
        return reward_model(prompt, output)

    correct = check(output, ground_truth)
    if correct:
        return 1.0
    else:
        # 错误且 confidently 给出 → 严重惩罚
        return -2.0  # 比 "don't know" 还低

OpenAI / Anthropic 都这么做(具体细节不公开)。

5.3 Pretraining data quality

"Garbage in, garbage out"

  • 过滤错误 / 过期事实数据
  • 数据 deduplication(重复看相同错答案会强化)
  • 高质量来源加权(Wikipedia > random web)

DeepSeek-V3 / Llama-3 等模型 paper 提到大量 data filtering 工作但具体策略各家保留。

5.4 Synthetic data 中的 contamination

生成 SFT 数据时如果用 GPT-4 生成 → 它的 hallucination 进入 training data → 学生模型继承。

防范:

  • Verify synthetic data:每条都用 verifier / 强模型 cross-check
  • Mix with verified data:synthetic + 人工 / 高置信度的混合
  • Iterative refinement:synthesize → verify → re-synthesize

5.5 时效性数据(events / facts after training cutoff)

模型训练截止日期之后的事实必然不知道:

  • "Who won the 2026 Nobel?" 模型训练截 2025 → 必然 hallucinate

解:

  • Tool use (web search) 是事实问题的根本解
  • 训练时加 cutoff 教育:让模型说 "My training data is from 2025-04, I don't have info after that"

六、评测幻觉

6.1 闭式 benchmark

Benchmark 类型 测什么
TruthfulQA 多选 常见误解("Sugar makes kids hyperactive" 等)
SimpleQA (OpenAI 2024) 短答 4326 道事实问答,含 confidence label
HaluEval 多类型 QA / dialog / summarization 幻觉
FreshQA 时效性 训练截止后的 fresh facts

6.2 开放式评测

需要人工 / 强 LLM judge:

  • G-Eval:用 GPT-4 当 judge,按 hallucination criteria 打分
  • Faithfulness 评测:summarization 任务里"summary 是否忠实于 source"
  • Citation accuracy:RAG 任务里 cite 的文档是否真支持 claim

6.3 工程指标

实际 deployment 关心:

  • Hallucination rate:定义清楚 task 下,error 中 hallucination 占比
  • Calibration:模型 confidence vs actual correctness 相关性
  • Refusal rate:模型 abstain 的比例(太低 = 过度自信,太高 = 不可用)

最佳模型应该是高准确率 + 低 hallucinate + 适度 refusal


总结

7.1 thinking 与幻觉的关系

任务类型 thinking 帮助 备注
数学 / 代码 ✅ 大 最该开 thinking
多步推理 ✅ 大 同上
单事实 QA 反而可能 confident hallucinate
主观写作 略提升结构性
RAG with retrieval ✅ 大 thinking 引导 retrieval 决策

核心 insight:thinking 解决推理类幻觉,不解决知识类幻觉。

7.2 综合减幻三件套

实操推荐组合:

  1. 架构:RAG + 长 context + grounded 引用强制
  2. 推理:Self-Consistency(高准确率任务)+ Best-of-N + verifier
  3. 数据:SFT 含 "I don't know" 例子 + RLHF honesty reward

任何单点优化都不够。Frontier model(Claude / GPT / DeepSeek)都用了组合拳。

7.3 评测优先级

如果你做产品决策:

  • 先看 SimpleQA(事实幻觉硬指标)
  • 再看 TruthfulQA(常识误解)
  • 再看 业务 QA(自家用户场景)

不要只看 MMLU / HumanEval 这种"会做题"的 benchmark,忽视 hallucination 是工业级 deployment 的雷区。

7.4 Open problems

  • 小模型 (<7B) 幻觉率高:训练数据再多也撑不起所有事实知识
  • 过拟合 honesty reward:模型学到 "always say I don't know",refusal 率失控
  • 多模态幻觉:图文模型对图像内容的幻觉远比纯文本严重
  • Confidence calibration:模型 self-confidence 跟 actual correctness 的对应性还不好

参考文献

  1. Huang et al. A Survey of Hallucination in Large Language Models. 2023. arXiv:2311.05232
  2. OpenAI. Introducing SimpleQA. 2024. openai.com/index/introducing-simpleqa
  3. Lin et al. TruthfulQA. 2021. arXiv:2109.07958
  4. Li et al. HaluEval. 2023. arXiv:2305.11747
  5. Vu et al. FreshQA / FreshLLMs. 2023. arXiv:2310.03214
  6. Dhuliawala et al. Chain-of-Verification. 2023. arXiv:2309.11495
  7. Madaan et al. Self-Refine. 2023. arXiv:2303.17651
  8. Lightman et al. Let's Verify Step by Step (PRM). 2023. arXiv:2305.20050
  9. Asai et al. Self-RAG. 2023. arXiv:2310.11511
  10. Gao et al. RARR: Retrofit Attribution for RAG. 2022. arXiv:2210.08726
  11. Kalai et al. Why Language Models Hallucinate. 2025. arXiv:2509.04664(待核实)
  12. Wang et al. Self-Consistency. 2022. arXiv:2203.11171

上级 · J. 推理行为与失败模式