Lecture 12 · Grounding、事实性与幻觉 · Grounding, Factuality & Hallucination

Trustworthy Machine Learning · Lecture 12。个人学习讲义与配套实验,按主题整理并持续修订。

课程源码 ZIP ↓

个人整理的学习笔记,非官方讲义;课程来源与整理说明见课程介绍。配套示例未逐一运行验证。

本篇目录

对应 Maps to:Stanford CS329T Fall 2023 Lecture 1(trustworthiness dimensions:grounding、consistency;AT&T 账单地址和”John C. Mitchell 小传”两个例子)、Lecture 6(Project Design:用 RAG / prompting 提高 grounding,用 NLI(TRUE)和采样一致性(SelfCheckGPT)验证)、Lecture 9 “Grounding”(Datta、Mitchell、Taly:enabling grounded responses → verifying groundedness → response selection and rewriting);Lecture 5 医疗客座讲座里的临床信息抽取例子、Lecture 10 Eric Mitchell 讲事实性时的例子;Fall 2024 Oct 15 “Grounding and Factuality 1”(generating grounded responses:RAG、alignment / fine-tuning for factuality)。Fall 2024 Oct 17 的客座讲座 “Grounding and Factuality 2: verification and guardrails”(Nitish Joshi,NYU)没有公开 slides,本讲对应的部分(§5–§8)取自那两周的阅读列表 —— Lewis et al. 2020(RAG)、Honovich et al. 2022(TRUE)、Manakul et al. 2023(SelfCheckGPT)、Agrawal et al. 2023(hallucinated references)、Gao et al. 2023(RARR)、Azaria & Mitchell 2023、Raj et al. 2022 —— 以及 Ji et al. 2023 的幻觉综述和 Kenthapadi, Sameki & Taly 2024 的 grounding 综述。 配套代码 Code:code/lecture12/(只用 Python 标准库;5 个脚本 + 2 个工具模块,每个脚本 3 秒以内跑完) 预计阅读时间:3 小时(含运行代码)


0. 本讲导航 · How to read this lecture

0.1 Learning goals

After this lecture you should be able to:

  1. 用两条轴给一个幻觉分类:相对于什么(给定的来源 → faithfulness / grounding;世界知识 → factuality)和怎么错(和来源矛盾 → intrinsic;来源无法核实 → extrinsic),并解释为什么”有依据”和”是真的”是两件事。
  2. Explain why LLMs hallucinate — the next-token objective, long-tail knowledge gaps, memorized errors, decoding randomness, knowledge conflicts, sycophancy, and evaluation incentives that reward guessing — and say which mitigation addresses which cause.
  3. 说出 grounding 的定义(每个 claim 都可归因于一个权威来源;AIS:“According to A, y”),以及”权威”为什么取决于应用。
  4. Describe the generation-side toolkit (RAG, “only use the context” prompts, citations, abstention, decoding choices, fine-tuning) and its failure modes (retrieval losses vs generation losses).
  5. 实现并批判 claim 级的 groundedness 检测(分解 → decontextualize → NLI → 汇总 → 引用),说出它在什么输入上会失败;解释为什么 claim 级比句子级、整段级好。
  6. Use reference-free detectors — sampling consistency (SelfCheckGPT), indirect queries for references, the three consistency checks, internal-state probes — and name the one kind of hallucination none of them can see: consistent errors.
  7. 描述 RARR 式的”检索 + 改写”修正,以及 attribution 和 preservation 之间的取舍;知道修正什么时候会把对的改成错的。
  8. Evaluate a detector like any other measurement: precision/recall per hallucination type, base-rate-dependent precision, cost, and what access it needs.

0.2 先修与本讲范围 Prerequisites & scope

默认你已经会 Assumed本讲省略或只点到 Omitted / pointers only
LLM、prompt、RAG 是什么(第 1 讲 §6.2–6.3)RAG triad 三个 feedback function 的实现与 LLM judge 的验证(第 11 讲;这里的 groundedness 是其中一条边的深入)
precision / recall / AUC / base rate(第 1 讲 §8)校准、verbalized confidence、semantic entropy、为事实性做的微调(第 13 讲,Eric Mitchell 的 Fall 2023 客座讲座)
特征归因的思想:把输出”分配”给输入(第 2、3 讲)检索模型本身(dense retrieval、re-ranking)的细节
一点概率:独立事件、Bayes 公式多模态模型的幻觉(第 16 讲)

本讲的位置:第 11 讲把 groundedness 当作 RAG triad 里的一个评估信号;本讲问的是更底层的问题 —— 幻觉从哪里来、怎样让回答有依据、怎样自动检测没有依据的内容、检测到之后怎么修,以及这些检测器本身有多可信。

0.3 本讲地图 Map

§1  幻觉是什么:课上的例子;分类;grounded × true 的 2×2             ← 代码 01 演示 1
§2  为什么会幻觉:七个成因,以及它们在模拟器里对应的旋钮
§3  Grounding 的定义:AIS、权威来源、verifiably grounded;grounding 即 attribution
§4  生成端:RAG、prompt、引用、弃权、解码、微调;RAG 的两类损失           ← 代码 01 演示 1
§5  有参考的检测:claim 分解 + NLI;TRUE、FActScore;为什么要 claim 级;失败模式  ← 代码 01 演示 2–4
§6  无参考的检测:SelfCheckGPT、幻觉引用、三种 consistency、内部状态 probe  ← 代码 02、03、05 演示 1
§7  修正:RARR、删除、拒答、重新生成;改坏从哪里来                        ← 代码 04
§8  评估检测器本身:按类型的盲区、base rate、成本、cascade                 ← 代码 05 演示 2–3
§9–13 小结、误区、练习、延伸阅读、下一讲预告

0.4 Notation

符号含义
xx, yy用户的问题(prompt)、模型的回答(response)
K\mathcal{K}权威的知识来源(knowledge base / corpus);C={p1,…,pk}⊆KC = \{p_1, \dots, p_k\} \subseteq \mathcal{K} 是检索到的段落(context)
c1,…,cmc_1, \dots, c_m回答拆出来的原子 claim(atomic facts)
sij∈[0,1]s_{ij} \in [0,1]NLI 给出的”段落 pjp_j 蕴含 claim cic_i“的概率(entailment score)
sis_i, G(y)G(y)claim ii 的支持分(对 jj 汇总);回答的 groundedness G(y)=1m∑isiG(y) = \frac1m\sum_i s_i
FPfactual precision:回答里为真的 claim 的比例(FActScore)
π\pibase rate:被检查的 claim 里幻觉所占的比例
TPR, FPR检测器在幻觉 / 非幻觉 claim 上的报警率

0.5 关于数字 · About the numbers

本讲所有实验数字都来自配套代码的实际输出(固定随机种子;Python 3.9 和 3.13 上逐字相同)。代码里没有真实的 LLM:fact_world.py 造了一个虚构的世界 —— 150 位虚构研究者、每人 7 个属性、一个带陷阱的知识库(30 对只差中间名缩写的同名者、20% 的人有一段 1998 年的过时段落)—— 和一个行为由明确旋钮决定的模拟 LLM:它对每个 (人, 属性) 要么记得对、要么每次都记错成同一个值、要么不知道(只能编)。checkers.py 里的 NLI 也是模拟的,带着文献里记录过的几种弱点。因为每个 claim 的真值和”来历”都已知,每一种检测方法都能和真相对照 —— 这正是模拟的意义。数字说明机制,不代表任何真实 LLM 或真实检测器的表现。


1. 幻觉是什么 · What is a hallucination?

1.1 课上的例子 · Examples from the course

CS329T 的 LLM 年份里反复出现这些例子,每一个代表一种不同的错误:

  • AT&T 账单(Fall 2023 L1、L9):“How do I pay my AT&T phone bill?” 回答列出了网上、电话、邮寄三种方式,格式完美,电话号码也对 —— 但邮寄地址 “P.O. Box 620225, Dallas, TX” 不是 AT&T 的地址。一个流畅、具体、看起来很权威的回答里,混着一个编造的细节。
  • John C. Mitchell 的 100 字小传(Fall 2023 L1):模型给出了具体的出生日期、学士和博士的年份与学校。读起来像简历,但哪些是真的?读者无从判断 —— 而这正是问题所在。
  • 男性的目标血压(Fall 2023 L9):回答说 “<130/80 for men under 65, <140/90 for 65 and older”,并归于 AHA / ACC 指南 —— slides 的批注是 “Not according to 2017 guidelines”。这是过时的知识,还附了一个看似权威的出处。
  • “Explain why 11 + 12 = 25”(Fall 2023 L9):模型顺着错误的前提编出了一段”推导”。slides 的说法是 LLM “twists facts to produce plausible-looking responses”。
  • Bing 总结 Gap 的季报(Fall 2023 L10,Eric Mitchell 引用的公开分析):有些数字抄成了未经调整的版本,而 5.9% 和 $0.42 的 EPS 这两个数原文里根本没有。有原文可查的情况下(RAG 的设定),模型仍然会编。
  • 临床信息抽取(Fall 2023 L5,LayerHealth 的客座讲座;Monica Agrawal et al. 2022, “Large Language Models are Few-Shot Clinical Information Extractors”):输入只有 “500mg of metformin b.i.d.”,模型却写出 “metformin for the reason of diabetes” —— 一个医学上合理、但原文没有的推断。
  • 飓风 Fiona(Fall 2024 Grounding 1):上下文说 Fiona “became the season’s first major hurricane on September 20”,回答却说它 “forming on September 20” —— 把”成为大型飓风”读成了”形成”。上下文是对的,生成读错了。

1.2 分类 · A taxonomy

文献里最常用的两条轴(Maynez et al. 2020 在摘要任务上提出,Ji et al. 2023 的综述把它推广到各类生成任务):

轴 1:相对于什么?

  • Faithfulness / grounding:相对于给定的来源(摘要的原文、RAG 检索到的段落、用户上传的文件)。问题是”回答是否忠于来源”。
  • Factuality:相对于世界知识。问题是”回答是否为真”。

轴 2:怎么错?

  • Intrinsic:和来源矛盾(Fiona 的例子;把出生年份抄错一年)。
  • Extrinsic:来源里没有,无法从来源核实(metformin → diabetes;Gap 的 EPS)。extrinsic 的内容可能是真的,也可能是假的 —— 关键在于你无法从给定来源确认。

再加一个维度:closed-book(模型只凭参数记忆回答)还是 open-book / RAG(模型看着检索到的上下文回答)。闭卷时没有”给定的来源”,问题只剩 factuality;RAG 时两个问题都存在。

例子相对于怎么错设定
AT&T 的邮寄地址factuality编造的细节closed-book
目标血压(过时的指南)factuality过时的知识closed-book
Gap 季报的 EPSfaithfulnessextrinsicRAG(有原文)
metformin → diabetesfaithfulnessextrinsic(合理推断)抽取(有原文)
Fiona “forming on Sep 20”faithfulnessintrinsic(读错)RAG
“11 + 12 = 25” 的解释factuality + 推理顺着错误前提编closed-book

1.3 有依据 ≠ 是真的 · The grounded × true 2×2

代码 01 演示 1 让同一个模拟 LLM 为 150 位虚构研究者各写 2 段短传记,比较四种生成方式(每格是占全部 claim 的比例;k = 5 指检索 top-5 段落):

settingclaims / resptruegrounded全部 grounded 的回答
closed-book5.2430.520——
closed-book + abstain4.2530.625——
RAG k=55.3070.7460.7060.323
RAG k=5 + “only use the context”4.9770.7960.7940.447

把 RAG 两种设置的 claim 按 grounded × true 分成四格:

truefalse
grounded(RAG / strict)0.698 / 0.7800.008 / 0.014
ungrounded(RAG / strict)0.048 / 0.0160.246 / 0.190

两个加粗的格子是本讲反复出现的主题:

  • Grounded but false:模型忠实地抄了一段过时的段落(1998 年的员工名录写着旧雇主)。Fall 2024 slides 的问答:“Can a grounded response still be incorrect? Yes, if the context is irrelevant / conflicting / ambiguous.”修复方向是检索和知识库,不是生成。
  • Ungrounded but true:模型凭参数记忆说对了。Fall 2024 第 3 讲把它叫作 “Sometimes hallucinations can be correct”。从 grounding 的角度它仍然是问题 —— 你无法从给定来源核实它;应用是否允许模型用参数知识,要由应用来决定(§4.3)。

所以评估一个 RAG 系统时要同时问两个问题:有依据吗?对吗?第 11 讲的 RAG triad 回答前者,FActScore 一类的指标回答后者。


2. 为什么会幻觉 · Why do LLMs hallucinate?

Fall 2023 第 9 讲的第二张 slide 只有一句话:“Consider LLMs hallucinatory… unless proven otherwise!” 这一节解释为什么这是合理的默认假设。每个成因都对应 fact_world.py 里的一个旋钮。

1. The objective rewards plausibility, not truth. A pretrained LM maximizes the likelihood of the next token. A fluent continuation that looks like a correct answer — a well-formatted P.O. box, a birth date in the right decade — scores well whether or not it is true. Nothing in the objective distinguishes “the corpus says X” from “X is the kind of thing the corpus says”. Kalai et al. (2025, “Why Language Models Hallucinate”) formalize this: if a model cannot tell valid from invalid statements (a binary classification problem), then a model trained to match the distribution of text will generate invalid statements at a rate tied to that classification error. Kalai & Vempala (2024) earlier showed that a calibrated model must hallucinate on arbitrary facts that appear only once in training — a rate related to the fraction of such “singleton” facts. This is the same long-tail argument as Feldman’s memorization theory in Lecture 9 §7.3: rare facts cannot be learned reliably from one or two occurrences.

2. Knowledge gaps and the long tail. Models know popular entities far better than rare ones (Kandpal et al. 2023, “Large Language Models Struggle to Learn Long-Tail Knowledge”; Mallen et al. 2023, whose PopQA results show retrieval helps most for less popular entities). The Fall 2024 slides slice RAG benchmark results (CRAG) the same way: head vs tail facts, static vs fast-changing facts. In the simulator, an entity’s popularity sets the probability that each fact is remembered correctly (from 0.10 for the least popular to 0.95 for the most popular).

3. Memorized errors. Training data contains errors, outdated facts, and conflated entities (two people with the same name). A model can learn a wrong fact as firmly as a right one. These errors are consistent: the model says the same wrong thing every time you ask. In the simulator these are kind = "wrong" memories — often the namesake’s value. They will turn out to be the blind spot of every reference-free detector (§6).

4. Decoding randomness. Sampling with temperature or nucleus sampling can pick a low-probability continuation, and once a wrong token is emitted, the model continues consistently with it. Lee et al. (2022) found that nucleus sampling produced more factual errors than greedy decoding in open-ended generation and proposed “factual-nucleus sampling” (decaying randomness as a sentence goes on). Zhang et al. (2023) documented snowballing: a model that commits to a wrong answer early then generates justifications for it — the “11 + 12 = 25” example, and the “answer 17, explain 15” example of §6.3. Exposure bias (training on gold prefixes, generating from your own) is the classic name for the mismatch.

5. Knowledge conflicts. In RAG, the context may disagree with what the model memorized. Models sometimes ignore the context in favor of parametric memory (Longpre et al. 2021, “Entity-Based Knowledge Conflicts in Question Answering”). The Fall 2024 slides point out a training-data reason: open-book QA datasets mostly contain questions whose answers the model already knows (“capital of France”), which rewards recalling from memory instead of reading the context. Simulator knob: p_use_context = 0.85.

6. Alignment and sycophancy. RLHF rewards responses that human raters like. Eric Mitchell’s Fall 2023 guest lecture put it this way: deciding “is this response factually accurate” is much harder than deciding “do I like this response”, so human labels only weakly encourage truth. Sharma et al. (2023) showed RLHF-trained assistants systematically agree with users’ stated beliefs (sycophancy). Gekhman et al. (2024) found that fine-tuning on examples containing knowledge the model doesn’t already have is learned slowly and increases the tendency to hallucinate.

7. Evaluation incentives. Most benchmarks grade answers as right or wrong, with no credit for “I don’t know”. Under that scoring, guessing always beats abstaining. Kalai et al. (2025) argue this is why hallucination persists after post-training, and propose changing how mainstream benchmarks are scored so that calibrated abstention is not penalized.

成因模拟器里的旋钮主要的缓解手段
目标函数只奖励”像”模型总会给出某个值(编造)grounding(§4)、检测(§5–6)
长尾知识缺口popularity → p_knownRAG、弃权
记住的错误kind = "wrong"(同名者混淆)只有外部参考能发现(§5、§8)
解码随机性temperature、fabricate()低温 / greedy、事实性解码(§4.5)
知识冲突p_use_contextstrict prompt、context-aware decoding、counterfactual 数据
读错上下文p_misread、w_namesake更好的检索粒度、引用、验证
评估激励猜测(abstain 旋钮的代价:claim 变少)奖励弃权的评估、校准(第 13 讲)

3. Grounding 的定义 · What does “grounded” mean?

3.1 Attributable to identified sources

Fall 2023 第 1 讲的定义:一个 LLM 回答是 grounded 的,当且仅当回答中的每一个 claim 都能归因(attribute)到一个权威的知识来源。 第 9 讲把它写成相对于语料库的版本:“grounded in a knowledge corpus iff every claim in the response can be attributed to a document in the corpus”。两个关键词:

  • “Authoritative” depends on the use case. For a healthcare chatbot it may be a specific set of journals the customer trusts; for a customer-service bot, the company’s policy pages; for a legal assistant, actual case law (Lecture 1 §3.6: the lawyers in Mata v. Avianca cited six cases that did not exist). The Fall 2024 slides list the range: a private corpus, a public domain, or the entire Web.
  • “Attributable” is defined by Rashkin et al. (2023, “Measuring Attribution in Natural Language Generation Models”) as AIS — Attributable to Identified Sources: a text yy is attributable to evidence AA if a generic human reader would affirm the statement “According to AA, yy.” Their annotation protocol has two stages: first, is yy interpretable on its own (does a reader understand what it claims)? Only then, is all of its information supported by AA? The first stage matters: “This number is available 24/7” can’t be judged until you know which number “this” refers to (§5.5).

Fall 2024 第 5 讲把目标说得更完整:produce satisfactory and verifiably-grounded responses to any prompt using information from a user-specified knowledge base only。其中 grounded = 每个 claim 都可归因;verifiably grounded = 每个 claim 附有合适的引用,用户可以自己去核对。

3.2 Grounding、factuality、helpfulness 是三件事

  • 一个回答可以 grounded 而错误(来源过时、互相矛盾 —— Fall 2024 slides 的 SNAP 股价例子:检索到的两个页面给出两个不同的开盘价)。
  • 可以 ungrounded 而正确(§1.3 的 0.048)。
  • 可以 grounded、正确,却答非所问(RAG triad 的 answer relevance,第 11 讲)。
  • 可以 grounded、正确、切题,却没用 —— Fall 2024 slides 把 “unnecessary punting”(明明上下文里有答案却说”我不知道”)列为一种生成损失。

哪个更重要取决于应用。Fall 2024 slides 的例子:上下文缺信息时,健康问答可能要求模型返回一个固定的回答 “Not answerable by context”;别的应用可能更希望模型结合参数知识回答。这个选择应该写进应用的 trust requirements(第 1 讲 §4.3)。

3.3 Grounding 就是归因 · Grounding as attribution

第 2–3 讲的特征归因回答”这个输出依赖哪些输入特征”;第 4 讲的训练数据归因回答”这个预测依赖哪些训练样本”。grounding 检测回答的是同一类问题在 LLM 输出上的形式:这个 claim 依赖(被支持于)哪段来源? 第 1 讲 §6.5 的表把它放在 attribution 那一行。

这个类比带来两个提醒:

  1. 归因要被评估。 第 3 讲 §6 讨论过:一个归因方法给出的”重要特征”未必真的是模型依赖的。引用也一样 —— 一个 claim 旁边挂着引用,不等于引用真的支持它。Liu, Zhang & Liang(2023)审计了几个生成式搜索引擎:平均只有 51.5% 的生成句子被其引用完全支持,只有 74.5% 的引用支持它所附的句子。
  2. “支持”和”导致”不是一回事。 一个 claim 可以被某段来源支持,但模型其实是凭记忆写出来的(模拟器里 source = mem_known 而 grounded = True 的 claim)。grounding 检测检查的是输出和来源的关系(post-hoc attribution),不是模型的生成过程。这和第 2 讲 §9.1 是同一类区分:一个特征归因说的是”模型依赖什么”,不是”世界如何运作”;一个引用说的是”哪段证据支持这句话”,不是”模型是怎样写出这句话的”。

4. 生成端:让回答有依据 · Generating grounded responses

4.1 RAG:把记忆交给检索

第 1 讲 §6.3 的论证:LLM 被训练来泛化,记住事实只是副产品,所以不要依赖它记事实;把记忆交给一个可以检索的知识源。Retrieval-Augmented Generation(Lewis et al. 2020)就是这个设计:

prompt ──→ ① Retrieve:向量检索,或把 prompt 改写成搜索 query ──→ top-k 段落
       ──→ ② Augment:把段落放进 prompt,并加上"只根据以下内容回答"之类的指令
       ──→ ③ Generate:LLM(可能专门在 RAG 格式的数据上微调过)生成回答

在模拟世界里,RAG 把 factual precision 从 0.520 提到 0.746(§1.3 表),62% 的 claim 直接来自上下文。但只有 32% 的回答每个 claim 都有依据 —— 剩下的问题出在哪?

4.2 RAG 的两类损失 · Retrieval losses vs generation losses

Fall 2024 slides 把 RAG 的失败分成两类:

类别子类slides 的例子模拟世界里的对应(RAG k=5 的 claim 占比)
Retrieval losses:检索到的信息不相关、过时或有争议缺信息(复杂 prompt;信息埋在表格里)英国 1 型糖尿病患病率的长问题;“latest Nebula award” 埋在 Wikipedia 表格里top-5 平均只找回本人 81.9% 的属性 → 模型用记忆补:mem_known 0.106、mem_wrong 0.041、fabricated 0.073
有争议 / 过时SNAP 股价的两个开盘价14.7% 的人检索到了 1998 年的旧员工名录(context_stale 0.008)
(实体混淆)—检索器丢掉了中间名缩写,40% 的人的上下文里混着同名者的段落(namesake 0.110,RAG 之后最大的一类错误)
Generation losses:检索没问题,回答仍然不对读错上下文飓风 Fionamisread 0.039
抄错URL 抄错(what-is-facebook 变成 whatis/facebook)(misread 里的数字抄错)
不必要的拒答—(strict 模式下略去的属性)

slides 给出的改进方向分别作用在这两类损失上:

  • 检索:选对检索单元的粒度(文档、段落、句子还是命题 —— Chen et al. 2023, “Dense X Retrieval”:更大的单元带来更多干扰信息);用 RAG 数据监督检索器(选出”最能让模型生成正确答案”的上下文来训练,Wang et al. 2023 “Learning to Filter Context”);adaptive retrieval(“法国首都”不需要检索,检索反而可能引入干扰;“Twitter 创始人创办的另一家公司”需要多次检索 —— Jeong et al. 2024 “Adaptive-RAG”);以及 Fall 2023 第 9 讲的 query planning:把 “Compare Uber and Lyft revenues in 2020–2021” 拆成子问题分别检索再合并,质量更好,但 token 成本和延迟更高。
  • 生成:下一节。

4.3 Prompt、微调与解码 · Prompting, fine-tuning, decoding

Prompting. The simplest lever is an instruction: answer concisely and do not use any information beyond the provided context. In the simulator, the “strict” prompt raises the probability of following the context from 0.85 to 0.97 and makes the model omit most attributes the context doesn’t cover. Groundedness rises from 0.706 to 0.794 and factual precision from 0.746 to 0.796, at the cost of fewer claims per answer (5.31 → 4.98). Note what the prompt cannot fix: namesake confusion stays at about 12% of claims, because the wrong person’s passage is in the context.

Fine-tuning on open-book QA (<query, context, response> triples from Natural Questions, TriviaQA, BioASQ, CRAG, FreshQA…) teaches the format, but has the knowledge-conflict problem of §2: if the answer is already in parametric memory, the training signal doesn’t care whether the model read the context. The fix in the Fall 2024 slides is counterfactual augmentation (Köksal et al. 2023, “Hallucination Augmented Recitations”): add triples whose context states a counterfactual answer, so that only reading the context gives the right label. Likewise, add examples with broken contexts (missing, conflicting, distracting information) — but then you must decide what the right label is, which is an application decision (§3.2).

Context-aware decoding (Shi et al. 2023, “Trusting Your Evidence”) needs no training. At each step it compares the model’s next-token logits with and without the context and amplifies the difference:

ℓ~(yt)=(1+α) ℓ(yt∣c,x,y<t)−α ℓ(yt∣x,y<t).\tilde\ell(y_t) = (1+\alpha)\,\ell(y_t \mid c, x, y_{<t}) - \alpha\,\ell(y_t \mid x, y_{<t}).

Tokens whose probability rises when the context is present are favored; tokens the model would have said anyway (from memory) are damped. α=0\alpha = 0 recovers ordinary decoding (练习 4 works through an example).

RL for grounding. What counts as a good response for a (query, context) pair is nuanced, so one can train a reward model on preferences and optimize with RL under a KL constraint (第 1 讲 §6.2; CS329H). Examples on the Fall 2024 reading list: GopherCite (Menick et al. 2022, “Teaching language models to support answers with verified quotes”) and factuality tuning (Tian, Mitchell et al. 2023: sample several responses, rank them by an automatic factuality score such as FActScore, train with DPO). The latter is the subject of Lecture 13’s pointer to Eric Mitchell’s guest lecture.

Decoding-time interventions beyond temperature: factual-nucleus sampling (§2); DoLa (contrasting late and early layers) and Inference-Time Intervention (shifting activations along a “truthful” direction, Li et al. 2023), both mentioned in the Fall 2023 factuality lecture; and FUDGE-style controlled generation (Yang & Klein 2021), which the Fall 2023 Lecture 9 slides propose for grounding: bias each decoding step toward continuations a discriminator thinks will be grounded.

4.4 引用与弃权 · Citations and abstention

引用把 grounded 变成 verifiably grounded:要求模型为每句话标出来源(ALCE benchmark,Gao et al. 2023 “Enabling Large Language Models to Generate Text with Citations”)。Fall 2023 医疗客座讲座里的做法更进一步:要求结构化输出的每个字段都附上原文引文(quoted structured output),这样 “diabetes” 这种原文没有的推断就没有引文可附,暴露出来。但 §3.3 的审计提醒我们:引用本身也要被核对。

弃权(abstention) 是第 1 讲 §7.3、第 8 讲”certify or abstain”在生成上的版本。代码 01 演示 1 的 closed-book + abstain:模型在”意识到自己不知道”时略去这个属性(每次意识到的概率 0.6)。

claims / resptruemem_wrong 占比每段的 fabricated每段的 mem_wrong
closed-book5.2430.5200.181约 1.74约 0.95
+ abstain4.2530.6250.221约 0.73约 0.94

弃权砍掉了大约 60% 的编造,记错的事实一个没少(占比反而升高)—— 模型无法对自己不知道的错误弃权。代价是每段回答少了约 1 个 claim。这是 helpfulness 和 trustworthiness 的直接交换;Kalai et al.(2025)的观点是,只要评估不奖励弃权,模型就没有动力做这个交换。

4.5 两种顺序:RAG vs Corroborate-and-Revise

RAG 是”先检索、再生成”。Fall 2024 slides 提出另一种顺序 —— Corroborate and Revise(CAR):

  1. 让 LLM 先写(可以是第三方 LLM,带或不带检索);
  2. 对每个 claim 按需检索证据核对;
  3. 必要时用证据改写。

什么时候选 CAR?slides 的例子是一段很长的请求:卖仓鼠饲料的人想要一篇 “David Attenborough 纪录片风格”的博客,讲饲料、垫料、玩具……”Such a prompt seems hopeless for RAG” —— 不知道该检索什么。RAG 适合客观、求事实的问题(“Alphabet 现在的股价”),CAR 适合开放的创作任务:先让模型写,再核对它写出来的每个事实。§7 的 RARR 就是 CAR 的一个具体实现。

slides 最后列出的开放问题里有一个值得记住:grounding 和创造力之间的取舍 —— 为 grounding 调过的模型可能开始大段照抄上下文,失去帮助性。


5. 有参考的检测:claim 分解 + NLI · Verification with a reference

5.1 The corroboration workflow

Fall 2023 Lecture 9 gives a recipe that the rest of this section unpacks. Example: “Here are two facts about Tesla Model X: (1) Model X has falcon-wing doors (2) Model X is the best selling car of 2022.”

Step 1  拆成 claim:        (1) falcon-wing doors   (2) best selling car of 2022
Step 2  对每个 claim,和知识库里的段落逐一核对(corroborate):
             (1) ✓  有段落支持         (2) ✗  没有段落支持
Step 3  汇总成报告:每句一个分数 + 引用;整段一个分数

Which snippets do you check against? For RAG responses, the snippets RAG retrieved. For other responses, retrieve snippets per claim post hoc — with a caveat from the slides: beware of confirmation bias (a query that contains the claim tends to retrieve text that agrees with it; §7.3 measures this).

The scoring rule from the slides: let sijs_{ij} be the NLI entailment score of sentence ii against snippet jj. Then

si=1−∏j=1n(1−sij)("OR": supported if any snippet supports),G(y)=1m∑i=1msi,s_i = 1 - \prod_{j=1}^{n}\big(1 - s_{ij}\big)\quad(\text{"OR": supported if any snippet supports}),\qquad G(y) = \frac{1}{m}\sum_{i=1}^m s_i ,

cite snippet jj for sentence ii when sijs_{ij} is above a threshold, and optionally aggregate by product instead of mean (one unsupported sentence then sinks the whole response). The improved workflow in the slides adds two preprocessing steps before NLI: a requires-verification check (drop “Sure! I can help you with that”) and decontextualization (make each sentence stand alone; §5.5).

5.2 NLI 与 TRUE · Natural Language Inference

NLI(textual entailment)是一个经典 NLP 任务:给前提(premise)和假设(hypothesis),判断假设是被蕴含(entailment)、矛盾(contradiction)还是无关(neutral)。slides 的例子:“the turtle moved” 蕴含 “one animal moved”,与 “no animal moved” 矛盾。公开数据集有 SNLI、MNLI、FEVER、PAWS 等;T5 系列模型在 MNLI 上很强。grounding 检测就是把来源段落当前提、claim 当假设。

为什么相信 NLI?TRUE(Honovich et al. 2022, “TRUE: Re-evaluating Factual Consistency Evaluation”)把 11 个人工标注的数据集统一成”这个输出和它的 grounding 文本是否一致”的二分类,覆盖摘要、对话、事实核查、复述四类任务,用逐个样本(example-level)的 ROC AUC 来比较各种自动指标,而不是只看系统级的相关性。结论是:大规模 NLI 模型和基于问题生成 + 问答(QG-QA)的方法最强,而且两者互补,组合起来更好。

QG-QA 是另一条路线(Fall 2023 L9 也介绍了):QAGS(Wang et al. 2020)和 Q²(Honovich et al. 2021)先从回答生成问题,再分别用来源和回答去回答这些问题,比较两个答案。它天然是 claim 级的:每个问题对应回答里的一个信息点。工业界的产品形态也是 NLI:Fall 2024 第 3 讲提到的 Google Cloud Check Grounding API,基于定制的 NLI 模型,返回 support score、contradiction score、citations 和 anti-citations(与回答矛盾的来源)。

5.3 FActScore:原子事实 · Atomic facts

For long-form factuality (not just faithfulness to one document), Min et al. (2023) proposed FActScore: break a generation into atomic facts (short statements that each carry one piece of information), check each against a knowledge source (Wikipedia, for biographies), and report the fraction supported — factual precision. Two reasons to go atomic: a sentence usually mixes supported and unsupported information, so a binary sentence label throws information away; and atomic facts make human and automatic judgments far more consistent. Their headline: ChatGPT’s biographies scored only 58%. They also built an automatic estimator (retrieval + an LM judge) with less than 2% error relative to human FActScores, and used it to evaluate 6,500 generations from 13 LMs — which would have cost about $26K with human annotators. Later work extended the idea with web search instead of Wikipedia (e.g., SAFE, Wei et al. 2024), and Tian, Mitchell et al. (2023) used FActScore as the reward for factuality tuning (§4.3, Lecture 13).

FActScore 的定义只看 precision。一段只写了 2 个安全事实的传记和一段写了 10 个事实的传记可能同分 —— 这正是 §4.4 里弃权的那笔账:claim 越少,precision 越容易高。报告事实性时要同时报告写了多少。

5.4 为什么要在 claim 级核对 · Why claim-level matters

代码 01 演示 2 走一遍完整流程。问题:“Write a short biography of Emil T. Lokafen.”检索到的 5 段里有 2 段讲的是同名的 Emil H. Lokafen。回答(简写):

Here is a short biography. Emil T. Lokafen was born in 1949. This researcher comes from Quell. This researcher works on desert hydrology and earned a doctorate at Harrow Institute. This researcher received the Talmur Medal.

claim(decontextualized)noisy-OR 支持分引用真相
Emil T. Lokafen was born in 1949.0.90p9grounded,真
Emil T. Lokafen comes from Quell.0.25—没有依据,假(记错)
… works on desert hydrology.0.88p8grounded,真
… earned a doctorate at Harrow Institute.0.92p9grounded,真
… received the Talmur Medal.0.24—没有依据,假(记错)

claim 分数的平均 0.639,接近真实的 grounded 比例 0.600;报告精确指出了哪两个 claim 有问题。按句子打分时,客套话 “Here is a short biography.” 得 0.24(不被任何来源蕴含),把平均拉到 0.505;复合句只得到一个分数。

演示 3 把这个比较放大到 300 段 RAG 回答(1531 个 claim,其中 425 个没有依据,比例 0.278,95% CI [0.256, 0.301])。同一个模拟 NLI,用在三种粒度上;“报警”指判定某个 claim 没有依据(句子级 / 整段级的报警落到它包含的所有 claim 上):

granularityprecisionrecallF1r(回答分数, 真实 grounded 比例)客套话被判”没有依据”
整段回答0.5260.5910.5570.646—
句子,宽松(γ = 0.5)0.8450.4610.5970.671145 / 145
句子,γ = 20.5650.8210.6690.567145 / 145
句子,严格(γ = 4)0.3890.8940.5420.443145 / 145
claim0.8880.8560.8720.887—
claim,抽取器漏掉 10%0.8790.7860.8300.861—

(γ 是模拟 NLI 对”部分支持”的宽松程度:一个含 2 个 claim、只有 1 个被支持的句子,P(entail) 的基准是 0.95×0.5γ0.95 \times 0.5^{\gamma}。)

读这张表:

  • 整段打分几乎没用:宽松的 NLI 给”大部分有依据”的回答一个及格分,长前提又让有依据的 claim 被漏看;而且一个数说不出是哪一句。
  • 句子级有一个躲不开的两难。 444 个复合句里 140 个是”一半有依据、一半没有”。宽松时这些句子拿到及格分,没有依据的那一半漏网(recall 0.461);严格时,被两段分别支持的复合句对每一段都只是”一半支持”,于是被冤枉(precision 0.389)—— 这正是 slides 列出的 recall issue:“the combination of claims is not entailed by any single source”,slides 建议的补救是”consider tuples of snippets”,而 claim 分解从根上绕开了它。
  • claim 级的上限由 claim 抽取器决定:漏掉 10% 的 claim,recall 就从 0.856 掉到 0.786 —— 被漏掉的 claim 永远不会被检查。

5.5 失败模式 · Failure patterns

Fall 2023 第 9 讲把 NLI 核对的失败分成 precision issues(不该高分的高分)和 recall issues(不该低分的低分)。代码 01 演示 4 在 600 段 RAG 回答上,按没有依据的 claim 的来历统计 claim 级检查把它们正确标出的比例:

没有依据的 claim 的来历n其中为真标出率(decontextualized)标出率(保留代词)
namesake(同名者的值)3490.0430.6990.026
misread,数字(年份抄错 1–2)420.0000.8330.738
misread,类别840.0000.9880.988
mem_wrong(记错)1150.0000.9740.948
fabricated(现编)1920.0420.9640.943
mem_known(凭记忆说对)1281.0000.9920.984

对应到 slides 的清单:

  1. Mixing quotes from multiple sources out of context(precision issue)。slides 的例子:“The 1 800 number for AT&T is 800-331-0500. This number is available 24/7.” 两句话都能在来源里找到,但第二句在来源里说的是另一个号码。模拟世界里的同名者是同一个问题:保留代词 “This researcher” 时,NLI 默认代词指前提里的那个人,同名者的段落就”支持”了 claim,标出率只有 0.026。Decontextualization(Choi et al. 2021:把句子改写成可以独立理解的形式,比如把代词换成全名)把它拉到 0.699;剩下的漏网来自”名字只差一个缩写”时 NLI 仍会混淆 —— 实体消歧不能全交给 NLI。
  2. Sentences that don’t require verification(precision issue):客套话不被任何来源蕴含(§5.4 表的最后一列)。补救:先用一个分类器判断句子”是否需要核对”。
  3. Multiple claims in one sentence(recall issue):§5.4。
  4. Long source snippets(recall issue):NLI 读长前提时会漏看。slides 的补救:检索时取多个短而相关的片段,而不是一个长片段。整段级打分的低 recall 有一部分来自这里。
  5. Numbers(不在 slides 的清单里,但在实践中很常见):年份差 1–2 年的读错只有 0.833 被标出。补救:把数字、日期、金额抽出来做精确比较。
  6. Decomposition errors:抽取器漏掉、合并或改写了 claim(§5.4 表的最后一行)。

还有一个汇总方式上的陷阱。noisy-OR 把每段的 entailment 当成独立的证据;可无关段落的 entailment 并不是 0(NLI 总有一点”杂音”:模拟 NLI 对”前提没提到的属性”平均给出 0.056,见 checkers.py 的自检输出)。演示 4(b) 用越来越多的段落核对同一批 claim:

用来核对的段落数 kfalse support(noisy-OR)false support(max)recall(noisy-OR / max)
20.0140.0140.954 / 0.940
40.0800.0800.949 / 0.931
80.1720.1670.954 / 0.939
160.9940.1871.000 / 0.938

k ≤ 8 时两种汇总差不多(两者都随 k 缓慢上升:段落越多,越可能碰到一段能骗过 NLI 的同名者段落);k = 16 时 noisy-OR 突然崩溃:1−0.948≈0.391 - 0.94^{8} \approx 0.39 还在 0.5 以下,1−0.9416≈0.631 - 0.94^{16} \approx 0.63 已经越过阈值,几乎每个没有依据的 claim 都被判成”有依据”。noisy-OR 的好处是能把几段”各支持一点”的证据合起来,代价是要控制 k 或者先校准 NLI 分数(练习 1)。

5.6 核对失败之后 · When a claim fails corroboration

slides 的提醒:一个 claim 没通过核对,可能是它真的没有依据,也可能是我们没检索到能支持它的段落。两个补救:临时检索更多段落再核对一次;或者看这个 claim 是否 self-consistent(§6.1)。§8 会看到,第二个补救能减少误报,但会放过一致的错误。


6. 无参考的检测 · Detection without a reference

有时没有可查的知识库(闭卷聊天、开放领域),或者检索太贵。能不能只靠模型自己发现幻觉?

6.1 SelfCheckGPT:采样一致性

Idea (Manakul et al. 2023, “SelfCheckGPT: Zero-Resource Black-Box Hallucination Detection for Generative Large Language Models”): if a model knows a fact, independently sampled responses will state it consistently; if it makes it up, samples will diverge and contradict each other. So: generate the main response, draw NN stochastic samples for the same prompt, and score each sentence of the main response by how much the samples disagree with it. The paper built a dataset of GPT-3-generated WikiBio passages with sentence-level human labels (the released version has 238 annotated passages) and tested several ways to measure agreement: BERTScore, question answering (MQAG), n-gram statistics, NLI, and prompting an LLM (“Is the sentence supported by the context? Yes/No”). The NLI variant scores each sample by P(contradict)/(P(entail)+P(contradict))P(\text{contradict}) / (P(\text{entail}) + P(\text{contradict})) and averages over samples. In the results table on the project’s GitHub page (AUC-PR for detecting non-factual sentences, where random guessing gets 72.96), the NLI variant reaches 92.50 and the LLM-prompt variant with gpt-3.5-turbo 93.42.

The Fall 2023 Lecture 9 slides describe the same hypothesis — “a claim that is supported by all top-k sampled responses is more likely to be factual” — and report from their experience that self-consistency “achieves high precision but relatively low recall”: self-consistent claims are usually grounded, but many grounded claims are not self-consistent. They add a caveat: self-consistent claims may be factual relative to the Web but not to your specific corpus.

代码 02 演示 1:闭卷传记,主回答用 greedy,再抽 20 个 T = 1.0 的采样,按 claim 的来历看 SelfCheck 分数(≥ 0.5 报警):

claim 类型n为真平均分被报警
mem_known,记得牢(strength ≥ 0.8)2021.0000.3040.010
mem_known,记不牢1851.0000.4260.211
mem_wrong,记得牢300.0000.3420.000
mem_wrong,记不牢1120.0000.4460.339
fabricated(编错了)2400.0000.5790.762
fabricated(碰巧编对)261.0000.5960.769

总体 AUC 0.791;阈值 0.5 时 precision 0.784 [0.732, 0.828]、recall 0.579 [0.528, 0.627]。用 slides 的说法:被判一致的 claim 里 68.6% 是真的,真的 claim 里 85.2% 被判一致。

这张表说明 SelfCheck 测的是什么:

  • 它测的是”模型有多确定”,不是”对不对”。 记得很牢的错误(mem_wrong, strong)和记得很牢的事实分数几乎一样(0.342 vs 0.304),一个都没被报警。被抓住的那部分 mem_wrong 是”记不牢”的 —— 有些采样没想起来那个错值,编了别的。
  • 反过来,记不牢的正确事实会被冤枉(21%);碰巧编对的 claim 被报警 77% —— 从”模型并不知道”的角度,这个报警其实没错。
  • 这和 slides 的结论一致:被判一致的 claim 大多是真的(precision 方向),但精度的上限由一致的错误决定。

演示 2 扫描采样温度 TT 和采样数 NN(AUC,检测错误的 claim):

N = 1N = 3N = 5N = 10N = 20fabricated 检出率(N = 20)mem_wrong 检出率正确 claim 的误报
T = 0.00.5070.4870.4680.4490.4590.0000.0000.000
T = 0.30.5170.5620.5690.5770.5880.2310.1640.100
T = 0.70.5820.6100.6550.6830.6960.5410.1880.129
T = 1.00.5980.6700.7470.7870.8150.7930.1840.103
T = 1.50.6260.6910.7470.7810.8150.8800.2000.122
  • T = 0 是噪声地板:greedy 采样和主回答一模一样 —— 连编造都取 argmax,变得”一致”。AUC 在 0.45–0.51 之间,一个错误也抓不到。一致性检测需要随机性。
  • N 降低噪声:T = 1 时从 0.598(N = 1)到 0.747(N = 5)再到 0.815(N = 20),前几个采样收益最大;成本线性增长(每个采样一次生成,外加每个 claim × 每个采样一次 NLI)。
  • mem_wrong 的检出率在 T ≥ 0.3 时一直停在 0.16–0.20:多采样、高温度都解决不了一致的错误。(T = 1.0 的 AUC 0.815 和演示 1 的 0.791 是同一设置、不同的随机种子 —— 这个差别就是抽样噪声的量级。)

Semantic entropy(Farquhar et al. 2024)把同一个想法做得更细:先按语义把采样聚类(“Paris” 和 “It’s Paris” 是一类),再算熵。作者把它能检测的那一类幻觉叫作 confabulation(任意的、每次不同的错误),并明确说它检测不了模型一致地犯的、从训练数据学来的错误 —— 和上表完全一致。第 13 讲会实现它。

6.2 幻觉的引用 · Hallucinated references

Agrawal, Suzgun, Mackey & Kalai (2023, “Do Language Models Know When They’re Hallucinating References?”) use book and paper references as a clean test case: a reference either exists or it doesn’t. Their insight: a model that cites a real paper should know things about it, such as its authors. Two kinds of black-box checks:

  • Direct queries: ask the model, several times, “Does this reference exist?” and use the fraction of “yes”.
  • Indirect queries: ask, in several independent sessions, “Who are the authors of this paper?” and measure how much the author lists agree. Real references get consistent author lists; hallucinated ones get different authors each time.

They found that indirect queries outperformed direct queries for ChatGPT and Llama-2-70B, the two were close for GPT-4 (AUC 0.887 for the best direct query vs 0.878 for indirect), and an ensemble of both was best for every model.

代码 02 演示 3 模拟了这个设定(450 条参考文献,56.4% 是编的;真实论文被答”存在”的概率设为 92%):

检测器AUC
direct,模型认可自己编的论文 60%0.947
direct,认可率 85%0.719
indirect(作者),T = 1.00.948
indirect(作者),T = 0.00.500
direct 60% + indirect(平均)0.992
direct 85% + indirect(平均)0.966

direct query 能分辨多少,完全取决于一个你事先不知道的量:模型多大程度上会认可自己编的东西(模拟里是一个假设)。indirect query 依赖的是编造细节的不稳定性 —— 所以温度降到 0 时它完全失效,和 §6.1 的噪声地板是同一个教训。两者的错误来源不同,所以合在一起最好。

6.3 三种 consistency 检查 · Three consistency checks

第 1 讲 §5.6 介绍过 Fall 2023 第 1 讲(致谢 Goekhan Bakir)的三个例子:

不一致例子
response–explanation“What is 2+2*4+5? Explain.” → “The answer is 17.” 解释却算到 15
generative–discriminative“Is 2+2*4+5 equal to 17?” → 算出 15,“The answer: no”
prompt“What is 2 + 2*4 + 5?”(多了空格)→ 13

slides 的结论:“An in-consistency is usually indicative of buggy reasoning.” 关键在于:三种检查都只比较模型自己的输出,不需要标准答案。Raj, Rosati & Majumdar(2022, “Measuring Reliability of Large Language Models through Semantic Consistency”)把第三种系统化:对同一问题的多个语义等价的改写,用语义(而不是字面)相似度衡量回答是否一致,在 TruthfulQA 的改写版本上发现这种语义一致性指标比字面一致性指标更符合人的判断。

代码 03 造了一个知道真相的算术世界:2000 道”优先级很重要”的四数运算题,四种写法(紧凑、加空格、文字、加括号);模拟模型先凭”直觉”给答案、再一步步写解释,两条路径各自可能忘记乘法优先或算错一步,乘法表里还有 3 个记错的乘积(所有路径共用)。模型在紧凑写法上答错 32.0%。演示 1 打印了模拟出的例子,和 slides 的三种不一致一一对应,外加一个哪种检查都抓不住的例子:

[全部一致,但是错的] 5-7-6*7 → -42;解释 6 * 7 = 40; 5 - 7 = -2; -2 - 40 = -42;判别式答 yes;改写 -42, -42, -42(真值 -44)

三个检测器(报警 = 发现不一致):

检测器额外调用precisionrecallF1
response–explanation00.6710.7430.705
generative–discriminative10.7070.6810.694
paraphrase(3 个改写里有 1 个不同就报警)30.5140.8470.639
paraphrase(≥ 2 个不同)30.8490.7570.801
RE 或 GD 或 PC(≥2)40.5420.8260.654
三者中至少两个报警40.9140.7610.830

按错误的成因拆开(成因对检测器不可见):

成因nREGDPC(≥2)任一
答对了(= 误报率)13610.1710.1320.0630.328
忘了乘法优先3130.9040.8340.9841.000
算错一步1760.9660.8810.9830.994
记错的乘积1500.1470.1270.0200.267
  • 偶然的、依赖路径的错误(这一次调用忘了优先级、算错一步)换一条路径或换一种写法大多不再出现,三种检查合起来几乎全抓住。
  • 系统性的错误(记错的乘积)每条路径都一样。它的 26.7% “任一报警”率和答对的题的误报率(32.8%)是同一个水平 —— 那些”抓住”只是别的路径恰好又出了别的错。
  • response–explanation 的误报大多是答案对、解释错 —— slides 说不一致指向 buggy reasoning,而不一定是错误的答案。在教育、评分这类应用里,“推理有 bug”本身就是要报告的问题(第 1 讲 §4.3 的作业评分例子)。
  • 合并检查是一个 precision / recall 的选择:“或”提高 recall,“至少两个”提高 precision。

这和 §6.1 是同一个结论,换了一个世界:consistency 检查找的是随机的错误;系统性的错误需要外部参考 —— 一张正确的乘法表,也就是 grounding。

6.4 看模型内部 · Probing internal states

Do LLMs have an intrinsic notion of factuality? The Fall 2024 slides answer “many works say yes”:

  • P(True) (Kadavath et al. 2022): simply asking a large model whether its own proposed answer is true gives a reasonably well-calibrated probability (Lecture 13).
  • Probes on hidden states. Azaria & Mitchell (2023, “The Internal State of an LLM Knows When It’s Lying”) train a classifier (SAPLMA) on an LLM’s hidden activations to predict whether a statement the model reads or generates is true, using a dataset of true and false statements across several topics and testing on a held-out topic; they report average accuracies of roughly 71%–83% depending on the base model. Burns et al. (2023, CCS) find a “truth direction” without labels, using the logical consistency of a statement and its negation; Eric Mitchell’s Fall 2023 slides note that such unsupervised probes can be more accurate than the model’s own zero-shot answers. Inference-Time Intervention (Li et al. 2023) then shifts activations along such a direction to make generation more truthful.
  • Why would there be a truth direction? The persona hypothesis (Joshi, Rando, Saparov, Kim & He, 2024 — the first author is the Fall 2024 guest speaker) proposes that pretraining text comes from many “agents”; models learn to infer which kind of agent (persona) is writing, and truthful sources share features, so “truthfulness” is represented as a persona. Their evidence includes predicting from activations whether an answer will be truthful before it is generated.

Two cautions, both visible in 代码 05 演示 1. 我们在模拟的 8 维隐藏状态上训练一个线性 probe。隐藏状态 = 主题方向 + 模型的信念 × 一个方向 + 熟悉度 × 另一个方向 + 噪声;“信念”对记错的事实是错的那个值。

probe 评估准确率
同主题,没见过的人0.756
换主题(按属性留一法,平均)0.744(最差 0.670,最好 0.800)
模型对这个 (人, 属性) 的记忆n准确率真陈述的平均 P(true)假陈述的平均 P(true)
known(记得对)3840.9870.7950.274
wrong(记错)1060.4340.2650.343
unknown(不知道)2100.4950.5820.585
  1. A probe reads the model’s belief, not the truth. On facts the model remembers wrongly, the probe calls the true statement false (mean P(true) 0.265) because the model believes something else. The overall 0.434 accuracy on this group looks merely “a bit below chance” and hides this systematic failure. On facts the model doesn’t know, the probe can only guess. Hence the paper’s title says the model knows when it is lying (saying something it doesn’t believe), which is different from knowing when it is wrong.
  2. Generalization is the question. Probes are trained on one distribution of statements and applied to another. In this simulation the topic shift costs little on average, but individual topics vary (0.670–0.800). Critics have argued that probes found so far do not generalize reliably enough to count as lie detectors (e.g., Levinstein & Herrmann, “Still No Lie Detector for Language Models”, 2024). And a probe requires white-box access to activations, which API users don’t have.

7. 修正:RARR、删除与拒答 · Repair: revise, filter, refuse

7.1 检测到之后怎么办 · Options

Fall 2024 第 3 讲列出三个选项,“choice will depend on your application policy”:

  • Abstain:返回 “I don’t know”(或 slides 的 canned response “Not answerable by context”)。
  • Rejection sampling / response selection:Fall 2023 第 9 讲:用较高温度(> 0.4)采样多个回答,选 grounding 分数最高的;但要平衡 grounding 和流畅度,而且可能要采很多次才能找到一个 grounded 的回答。
  • Rewriting:把 grounding 的反馈(哪些 claim 没有依据)交给 LLM,让它改写。slides 给的两个代表:RARR(Gao et al. 2023)和 Self-Refine(Madaan et al. 2023,模型自我反馈、迭代改进)。同类方法还有 Chain-of-Verification(Dhuliawala et al. 2023):让模型为自己的草稿列出核对问题、独立地回答这些问题(不看草稿,避免被草稿带偏),再据此修改。

7.2 RARR

RARR (“Retrofit Attribution using Research and Revision”; Gao et al. 2023, “RARR: Researching and Revising What Language Models Say, Using Language Models”) post-edits the output of any generator to make it attributable, while changing it as little as possible:

  • Research stage. Query generation: a few-shot prompted LLM writes questions covering every aspect of the passage that needs attribution (“When was X born?” rather than repeating the claim). Retrieval: each query goes to web search; candidate snippets are ranked and the top evidence per query is kept.
  • Revision stage. Agreement model: for each (query, evidence) pair, a chain-of-thought prompt asks whether the passage and the evidence imply the same answer to the query. Edit model: only on disagreement, minimally edit the passage to agree with the evidence; edits that are too large (more than 50 characters, or more than half the original length) are rejected.
  • Attribution report: at most five evidence snippets that together cover the queries.

It is evaluated on two axes that pull against each other: attribution (AIS — human judgments, plus an automatic NLI-based approximation) and preservation (did the revision keep the original intent, and how much text changed — a Levenshtein-based score). Deleting everything maximizes attribution and destroys preservation; doing nothing does the opposite. On PaLM outputs for Natural Questions, the paper reports automatic AIS rising from 45.6 to 54.9 and human AIS from 35.4 to 43.4, with 90% of revisions judged to preserve the original intent — and other editing methods preserving far less.

7.3 代码 04:修了多少,改坏了多少

代码 04 对 300 段闭卷传记做 RARR 式修正:每个 claim 以 95% 的概率生成一个 query,BM25 取 top-1 段落作为证据,模拟 NLI 判断矛盾(P(contradict) > 0.5)就把值换成证据里同一属性的值(edit model 有 5% 失败率),attribution report 最多 5 段。

策略claims / respattributedauto-AIStruePres_Lev保留的 claimLLM 调用搜索
原回答(闭卷)5.2630.3880.3830.5071.0001.00000
RARR,问句 query5.2630.6590.6580.7500.9321.0007.85.0
RARR,claim 原文当 query5.2630.6500.6350.6740.9681.0007.05.0
RARR + 删除没有依据的 claim3.4400.9610.9130.9330.6100.65013.05.0
RARR,仍有没依据的就拒答1.0000.983—0.960————
用 RAG 重新生成5.2270.698—0.7400.375—21

(attributed = 被 attribution report 里同一个人的段落陈述(oracle);auto-AIS = NLI 的估计;Pres_Lev = 1 − 词级编辑距离 / 原文词数,RARR 用字符级;拒答那一行只有 60 / 300 段通过,claims / resp 把拒答算作 0 个 claim。)

改写明细:

策略改写次数修对(假→真)改坏(真→假)错改错
RARR,问句 query4994193545
RARR,claim 原文当 query295265129
  • RARR 有效:true 从 0.507 到 0.750,attributed 从 0.388 到 0.659,同时保留了 93% 的文字、一个 claim 也没删。但它修不完:query 漏掉的方面、检索到别人的证据、NLI 判成”一致”的近似错误都留了下来。
  • 它也会改坏:35 / 499 = 7.0%(95% CI [5.1%, 9.6%])的改写把一个正确的 claim 改成了错误的 —— 证据讲的是同名者,或者是 1998 年的旧名录。
  • Confirmation bias 是双刃的。 用 claim 原文去搜,query 里带着回答给出的值:对错的 claim,常搜回”恰好也有这个值”的别人的段落 —— 演示 2 的检索诊断:错的 claim 用原文去搜,top-1 证据是本人相关段落的只有 43.3%(用问句 65.2%)—— NLI 判 neutral → 不改,所以修对的少(265 vs 419);对对的 claim,值帮它搜到了正确的段落(98.0%,问句 69.6%),几乎不改坏(1 vs 35)。RARR 用问句而不是复述 claim,是选择了”多修一些、也多改坏一些”。
  • 更激进的 guardrail 用 helpfulness 换 grounding:删除没有依据的 claim 把 attributed 推到 0.961,每段只剩 3.44 个 claim;拒答更极端,平均每个问题只交付 1 个 claim。
  • 重新生成(RAG) 的 true 和 RARR 差不多(0.740),但几乎另写了一段(Pres_Lev 0.375)。当原回答来自你不能改的系统(第三方 LLM、人写的草稿),或者原回答的结构本身有价值时,“先生成、再核对修正”是唯一的选项(§4.5 的 CAR)。

7.4 改坏从哪里来 · Where harmful edits come from

演示 3 按”这个人的知识库有没有陷阱”拆开:

人的类型claims正确 claim 被改坏错误 claim 被修对
没有同名者、没有过时段落7730.0000.689
没有同名者、有过时段落1820.0340.391
有同名者、没有过时段落5010.1250.362
有同名者、有过时段落1230.0570.300

知识库干净的人,RARR 一个正确的 claim 都没改坏;改坏集中在证据有陷阱的人身上。修正的质量上限是证据的质量:RARR 把”相信模型”换成了”相信检索”。降低改坏的办法是提高检索精度(实体消歧、时间过滤),或者在证据之间有冲突时不改、标出来交给人。

7.5 Guardrails 的设计与代价

把 §5–§7 组合起来,一个部署中的 grounding guardrail 通常是这样的流水线:生成 → 抽取 claim → 判断哪些需要核对 → decontextualize → 检索证据 → NLI(数字单独精确比较)→ 对每个 claim 决定:引用 / 改写 / 删除 / 标记”未核实” / 整段拒答。每一步都有代价:

  • Latency and cost:每个 claim 至少一次检索和几次 NLI;RARR 每段约 8 次 LLM 调用(§7.3)。
  • Helpfulness:删除和拒答让回答变短、变少;“unnecessary punting” 本身就是一种失败(§3.2)。第 15 讲会在安全的语境里看到同样的张力(过度拒绝)。
  • New failure modes:guardrail 自己会出错(改坏、误删),而且它的错误更隐蔽 —— 用户看到的是一段”已经核实过”的回答。所以 guardrail 也要像任何检测器一样被评估(§8)。

8. 评估检测器本身 · Evaluating the detectors

第 1 讲 §8.3 和第 11 讲的主题是 “who judges the judge”。幻觉检测器就是一个 judge:它给每个 claim 打”可疑”或”可信”。这一节把它当作一个测量工具来评估。

8.1 每种检测器的盲区 · Blind spots by hallucination type

代码 05 演示 2 在同一批 300 段闭卷传记(1561 个 claim,48.9% 是错的)上运行五种检测器:retrieval + NLI(每个 claim 用问句检索 top-3、max 汇总);SelfCheck(N = 10,T = 1);paraphrase consistency(4 种问法,T = 0,≥ 2 种不同才报警);内部状态 probe(§6.4);以及 cascade(先 retrieval + NLI,没被支持的再看 SelfCheck,按 Fall 2023 L9 的建议)。

按 claim 的来历看报警率:

claim 类型nretrieval + NLISelfCheckparaphraseprobecascade
mem_known,记得牢(真)4280.0610.0280.0000.0020.000
mem_known,记不牢(真)3180.0410.2010.0000.0130.006
mem_wrong,记得牢(假)680.8380.0440.0000.0150.029
mem_wrong,记不牢(假)2330.8670.2700.0000.0090.240
fabricated(假)4620.9370.6820.8330.3050.647
fabricated,碰巧对(真)520.0380.7120.7690.4230.019

这是本讲最重要的一张表:每种检测器都有盲区,而且盲区不一样。

  • Reference-based checking treats memorized errors and fabrications alike (0.84–0.94) because it only looks at evidence. Its misses come from retrieval failures (namesake passages, questions that retrieve the wrong passage), and it flags 4%–6% of correct claims whose evidence wasn’t retrieved — it detects unsupported, not false.
  • SelfCheck and paraphrase consistency catch fabrications (0.682 / 0.833) and are nearly blind to firmly memorized errors (0.044 / 0.000). Paraphrase consistency at T = 0 only sees prompt-induced variation: anything in memory, right or wrong, never changes — so it never flags a memorized error, but it also has the fewest false alarms.
  • The probe reads belief: memorized errors are almost never flagged (≤ 0.015), and fabrications only 0.305 of the time.
  • The cascade rescues correct-but-unretrieved claims (they are self-consistent) and also waves through consistent errors that weren’t retrieved: mem_wrong (weak) drops from 0.867 to 0.240.

8.2 总的数字、成本与访问权限

检测器precisionrecall (TPR)FPRF1AUC每个 claim 的成本需要什么
retrieval + NLI0.9440.9070.0510.9250.9331 次检索 + 3 次 NLI一个可信、覆盖完整的语料库
SelfCheck(N = 10)0.7710.4990.1420.6060.751约 1.9 次生成 + 10 次 NLI黑盒、可以采样
paraphrase(4)0.9060.5050.0500.6480.7564 次生成黑盒
probe0.8420.1890.0340.3080.709≈ 0白盒(激活值)+ 标注数据
cascade0.9920.4680.0040.6360.941检索 + NLI;47% 的 claim 再加 SelfCheck语料库 + 采样

在这个”知识库完整、检索还不错”的世界里,有参考的检测最好 —— 和 TRUE 的结论一致。但它的前提是你有这样一个语料库,而 §8.1 说明它的错误来源(检索)和无参考方法的错误来源(一致的错误)完全不同。选哪个,取决于你有什么(语料?权重?预算?)和你最怕哪种错误。

8.3 Precision 取决于 base rate

precision=π⋅TPRπ⋅TPR+(1−π)⋅FPR\text{precision} = \frac{\pi\cdot\text{TPR}}{\pi\cdot\text{TPR} + (1-\pi)\cdot\text{FPR}}

把演示 2 测得的 TPR、FPR 代入不同的 base rate π\pi(代码 05 演示 3):

检测器TPRFPRπ = 0.02π = 0.05π = 0.10π = 0.30π = 0.50
retrieval + NLI0.9070.0510.2650.4820.6620.8830.946
SelfCheck0.4990.1420.0670.1570.2820.6020.779
paraphrase0.5050.0500.1700.3460.5280.8120.910
probe0.1890.0340.1020.2270.3830.7050.848
cascade0.4680.0040.7180.8680.9330.9820.992

闭卷传记里错误约占一半,所以每个检测器的 precision 看起来都还行。把同一个检测器用在一个好得多的系统上(只剩 5% 的错误),retrieval + NLI 的 precision 从 0.946 掉到 0.482,SelfCheck 掉到 0.157 —— 大部分报警是误报,人工复核的成本被误报主导。FPR 极低的 cascade 在 2% 时仍有 0.718。这和第 9 讲强调”低 FPR 下的 TPR”是同一个道理:罕见事件的检测,FPR 决定一切。

两个提醒:

  1. 报告检测器的 precision 时,要同时报告它是在什么 base rate 下测的;比较两篇论文的数字时,先看它们的数据里幻觉占多少(SelfCheckGPT 的数据集里非事实句子约占 73% —— 这就是”随机猜”的 AUC-PR 有 72.96 的原因)。
  2. 这张表假设 TPR / FPR 不随 base rate 变化。实际上换一个系统,幻觉的类型构成也会变:RAG 之后剩下的多是同名者混淆和读错上下文(§4.2),而 §8.1 告诉我们不同类型的检出率差别很大。最终还是要在目标系统的输出上重新测。

8.4 检测器也是 judge

如果用一个 LLM 来做 claim 抽取、NLI 或改写,那它就是第 11 讲意义上的 LLM judge,第 1 讲 §8.3 的全部警告都适用:用少量人工标注验证它;按”被比较的系统之间不同的属性”(长度、领域、实体类型、数字的多少)分层检查它的 TPR / FPR;必要时用 Rogan–Gladen 修正;不要对着它优化到 Goodhart。一个具体的风险:如果你用 SelfCheck 分数作为训练信号去”减少幻觉”,模型学到的可能是更一致地说错话 —— 恰好是 SelfCheck 看不见的那一种。


9. 小结 · Summary

问题方法它看见什么它看不见什么
回答有依据吗?claim 分解 + decontextualize + NLI(§5)和来源矛盾、来源没有的 claim检索失败、实体混淆、数字近似、抽取器漏掉的 claim
模型确定吗?SelfCheck、indirect queries(§6.1–6.2)现编的、记不牢的内容一致的错误;T = 0 时什么都看不见
推理一致吗?三种 consistency(§6.3)偶然的、依赖路径的错误系统性的错误
模型相信吗?内部状态 probe(§6.4)说的和信的不一样模型自己记错的事
能修吗?RARR、删除、拒答、重新生成(§7)—证据错了就会改坏;guardrail 用 helpfulness 换 grounding

Seven takeaways:

  1. Grounding and factuality are different questions. Grounded-but-false (stale or conflicting sources) and ungrounded-but-true (correct memory) both exist; evaluate both, and decide per application which one matters.
  2. Consider LLMs hallucinatory unless proven otherwise. The objective rewards plausibility; long-tail facts can’t be learned from a few occurrences; memorized errors are as fluent as facts; evaluation that doesn’t reward abstention rewards guessing.
  3. RAG moves the problem, it doesn’t remove it. Retrieval losses (missing, stale, conflicting, wrong-entity passages) and generation losses (misreading, knowledge conflicts) remain; prompts help with the second, not the first.
  4. Check at the claim level. Whole-response and sentence-level scores blur partial support, punish filler, and can’t say which claim is wrong; decontextualize before NLI; compare numbers exactly; watch the aggregation (noisy-OR has a cliff).
  5. Consistency is not correctness. Every reference-free detector — sampling, paraphrases, explanation checks, discriminative checks, probes — misses errors the model makes consistently. Only an external reference catches those.
  6. Repair inherits the quality of its evidence. RARR fixes many errors and breaks some correct claims when retrieval returns the wrong entity or a stale source; deletion and refusal trade helpfulness for grounding.
  7. A detector is a measurement. Report precision and recall per hallucination type, at a stated base rate, with cost and access requirements; at low base rates, the false-positive rate dominates.

10. 常见误区 · Common pitfalls

  • “It cites a source, so it’s grounded.” Citations themselves need checking: in Liu et al.’s audit only about three quarters of citations supported their sentence (§3.3).
  • “We use RAG, so it doesn’t hallucinate.” RAG changes which errors you get (§4.2); in our simulator the largest remaining error was wrong-entity passages in the context, which no prompt can fix.
  • “The response scored 0.8 groundedness, so it’s fine.” An average over claims (or a single NLI call on the whole response) can hide the one unsupported claim that matters — a dosage, a date, an address. Look at claim-level reports.
  • “SelfCheck says it’s consistent, so it’s true.” Consistent errors pass every sampling-based check (§6.1, §8.1); and at temperature 0 everything looks consistent.
  • “The probe is 75% accurate, so we have a lie detector.” It reads the model’s belief; on facts the model remembers wrongly it is systematically wrong, and its accuracy depends on the topic (§6.4).
  • “Let’s just delete every unsupported claim.” Unsupported ≠ false (a correct claim may simply not have been retrieved), and deletion destroys helpfulness (§7.3).
  • “Our detector has 90% precision.” At what base rate? The same detector can drop to below 50% precision on a better system (§8.3).
  • “Fixing grounding means fixing the model.” Grounded-but-false answers come from the knowledge base; harmful edits come from retrieval. Often the fix is in the data or the retriever.

11. 练习 · Exercises

练习 1(noisy-OR 的悬崖). 一个 claim 被核对的 kk 段段落都与它无关,NLI 对每段给出相同的”杂音”entailment bb。(a) noisy-OR 汇总后的支持分是多少?(b) b=0.06b = 0.06、阈值 τ=0.5\tau = 0.5 时,kk 至少多大,这个无关的 claim 就会被判成”有依据”?和 §5.5 的表对照。(c) 提出两种修正,并说明各自的代价。

参考答案

(a) s=1−(1−b)ks = 1 - (1-b)^k。(b) 1−0.94k≥0.5  ⟺  k≥ln⁡0.5/ln⁡0.94≈11.21 - 0.94^k \ge 0.5 \iff k \ge \ln 0.5 / \ln 0.94 \approx 11.2,所以 k≥12k \ge 12。§5.5 的表里 k = 8 时 noisy-OR 的 false support 还是 0.172(主要来自真正骗过 NLI 的同名者段落),k = 16 时跳到 0.994 —— 正好跨过了 12。(c) 几种做法:① 用 max 汇总(不再累积杂音,代价是不能把”各支持一点”的多段证据合起来,即 slides 说的 tuples of snippets 问题要另想办法);② 先把 NLI 分数校准或减去背景值,比如用 max⁡(0,sij−b)\max(0, s_{ij} - b) 再做 noisy-OR(代价:需要估计 bb,它随领域和段落长度变化);③ 限制 kk 或只用检索分数最高的几段(代价:可能漏掉真正的证据);④ 用 support − contradiction 之类的组合分数。

练习 2(base rate 与复核成本). 一个检测器 TPR = 0.9、FPR = 0.05。(a) 在 base rate π = 0.02 的系统上,precision 是多少?每找到一个真正的幻觉,人工要复核几条报警?(b) 要在 π = 0.02 时达到 precision 0.8,FPR 要降到多少(TPR 不变)?(c) 为什么 §8.3 里 cascade 的 precision 在低 base rate 下仍然很高?它付出了什么?

参考答案

(a) precision = 0.018 / (0.018 + 0.98 × 0.05) = 0.018 / 0.067 ≈ 0.269;每找到一个真幻觉要复核约 1 / 0.269 ≈ 3.7 条报警。(b) 0.018 / (0.018 + 0.98·FPR) = 0.8 ⇒ 0.98·FPR = 0.0045 ⇒ FPR ≈ 0.0046,要降低一个数量级以上。(c) cascade 要求两个检测器都报警(检索不支持且采样不一致),FPR 只有 0.004;代价是 recall 从 0.907 降到 0.468 —— 一致的错误(mem_wrong)只要没被检索证据支持,就被 SelfCheck 放行了。这是”用 AND 组合换 precision”的通用规律,§6.3 的”至少两种检查同时报警”也是一样。

练习 3(SelfCheck 分数的期望). 设主回答里有一个 claim。每个采样以概率 mm 提到同一个属性;提到时以概率 qq 给出和主回答相同的值。NLI 对”相同”给出的比值 c/(e+c)≈ac/(e+c) \approx a,对”不同”给出 ≈1−a\approx 1 - a,对”没提到”给出 ≈1/2\approx 1/2。(a) 写出 SelfCheck 分数的期望。(b) 取 m=0.75m = 0.75、a=0.06a = 0.06,qq 为多少时期望分数等于 0.5?(c) 用 (a) 解释:为什么 mem_wrong(记得牢)和 mem_known(记得牢)的分数几乎一样?为什么”没提到”的采样会把所有分数往 0.5 压?

参考答案

(a) E=m[qa+(1−q)(1−a)]+(1−m)/2E = m[q a + (1-q)(1-a)] + (1-m)/2。(b) 0.75[0.06q+0.94(1−q)]+0.125=0.5⇒0.94−0.88q=0.5⇒q=0.50.75[0.06q + 0.94(1-q)] + 0.125 = 0.5 \Rightarrow 0.94 - 0.88q = 0.5 \Rightarrow q = 0.5。即一半以上的采样给出别的值时才会报警。(c) EE 只依赖 qq(一致的程度),不依赖这个值是不是真的:记得牢的错值 qq 接近 1,分数和记得牢的真值一样低(演示 1:0.342 vs 0.304)。“没提到”的采样贡献 (1−m)/2(1-m)/2,与 claim 无关,把分数的取值范围从 [a,1−a][a, 1-a] 压缩到 [ma+(1−m)/2, m(1−a)+(1−m)/2][ma + (1-m)/2,\ m(1-a) + (1-m)/2],阈值附近更拥挤 —— 这也是 SelfCheckGPT 要求采样覆盖相似内容的原因。

练习 4(context-aware decoding). 某一步只有两个候选 token:A 是上下文里写的答案,B 是模型记忆里的答案。有上下文时 p(A∣c,x)=0.4p(A \mid c, x) = 0.4、p(B∣c,x)=0.6p(B \mid c, x) = 0.6;没有上下文时 p(A∣x)=0.05p(A \mid x) = 0.05、p(B∣x)=0.95p(B \mid x) = 0.95。(a) 普通解码(greedy)选哪个?(b) 用 §4.3 的公式、α=1\alpha = 1(等价于 p∝p(⋅∣c,x)2/p(⋅∣x)p \propto p(\cdot \mid c, x)^{2} / p(\cdot \mid x)),重新归一化后的概率是多少?(c) 如果上下文是错的(过时段落),CAD 会怎样?这对 §1.3 的 grounded-but-false 意味着什么?

参考答案

(a) B(0.6 > 0.4):参数记忆压过了上下文(knowledge conflict)。(b) A:0.42/0.05=3.20.4^2 / 0.05 = 3.2;B:0.62/0.95≈0.3790.6^2 / 0.95 \approx 0.379;归一化后 A ≈ 0.894、B ≈ 0.106,改选 A。CAD 奖励”因为看到了上下文才变得可能”的 token。(c) CAD 会更坚定地跟随上下文 —— 包括错的上下文。它提高的是 grounding,不是 factuality:grounded-but-false 的比例会上升。这说明生成端的 grounding 手段只能和检索 / 知识库的质量一样好(§7.4 的同一个结论)。

练习 5(给幻觉分类). 上下文只有一段:“Mira J. Okafen was born in 1952 and comes from Tarsk. In 1998 she was listed as working at the Northfold Lab.”(假设她现在在 Bluecrest Lab 工作,出生于 1952 年。)回答:“Mira J. Okafen was born in 1953 in Tarsk. She works at the Northfold Lab and won the Halden Prize, which she received for her work on lattice cryptography.” (a) 拆出原子 claim;(b) 对每个 claim 标注 grounded / ungrounded、真 / 假(假设奖项和领域都是真的)、intrinsic / extrinsic;(c) 对每个有问题的 claim,§8.1 里哪种检测器最可能抓住它?

参考答案

(a) 出生年份 1953;出生地 Tarsk;雇主 Northfold Lab;获得 Halden Prize;研究领域 lattice cryptography(“for her work on” 还隐含一个因果 claim:奖是因为这项工作得的)。 (b) 1953:ungrounded、假、intrinsic(与上下文的 1952 矛盾,差 1 年 —— NLI 容易漏,应精确比较数字)。Tarsk:grounded、真。Northfold Lab:grounded(1998 年的名录)、假(过时)—— grounded-but-false。Halden Prize、lattice cryptography:ungrounded、真、extrinsic(上下文没有)—— ungrounded-but-true;那个因果 claim 同样是 extrinsic,真假未知。 (c) 1953:有参考的 NLI(若做了数字精确比较)最可靠;若是读错上下文的偶然错误,采样一致性也可能发现。Northfold Lab:所有检测器都看不见 —— 它有依据、模型也确定;只有知识库层面的时间过滤或冲突检测能发现。Halden Prize / 领域:有参考的检测会报”没有依据”(正确,但它们是真的);无参考检测在模型记得牢时不会报警。是否允许它们留在回答里,是应用的决定。

练习 6(设计一个 guardrail). 接第 1 讲练习 6 的应用 (i):医院用 LLM 把医生笔记整理成结构化表格(诊断、处方、检查)。设计它的 grounding guardrail:(a) 生成端用哪些手段?(b) 检测端:抽取什么粒度的 claim、用什么核对、数字怎么处理?(c) 检测到问题后怎么处理(引用 / 改写 / 删除 / 标记 / 拒答)?(d) 用什么指标评估这个 guardrail,在什么 base rate 下报告?

参考答案(一个示例)

(a) 来源就是这份笔记本身(权威来源是唯一的);prompt 要求每个字段附上笔记原文的引文(Fall 2023 医疗讲座的 quoted structured output),不允许推断笔记中没有的诊断(metformin → diabetes 的例子);温度 0。 (b) 每个”字段–值”对是一个 claim;先检查引文是否逐字出现在笔记中(字符串匹配,比 NLI 可靠),再用 NLI 检查引文是否蕴含字段值;剂量、频率、日期等数字精确比较;否定(“rule out diabetes”)单独处理 —— NLI 对否定也不可靠。 (c) 引文不存在 → 删除该字段并标记”未在笔记中找到”;数字不一致 → 不改写(医疗场景下自动改写的风险大于收益,§7.4),而是标红交给医生;整份笔记中有超过一定比例的字段失败 → 整份转人工。 (d) 字段级的 precision / recall(相对于医生标注),按字段类型分层(剂量和诊断的错误代价不同);guardrail 的漏报率(有问题但没被标出的字段)是首要指标;报告时说明 base rate(例如在这个模型上只有 3% 的字段有问题,那么 guardrail 的报警里有多少是误报,医生要复核多少条);再报告 helpfulness 的代价(被删除 / 转人工的比例)和延迟。

代码相关的练习(“动手改一改”)见 code/lecture12/README.md。


12. 延伸阅读 · Further reading

本讲的主要来源

  • CS329T Fall 2023 Lecture 1(trustworthiness dimensions)、Lecture 6(project design)、Lecture 9(Grounding)slides;Fall 2024 Lecture 5 “Grounding and Factuality: Part 1” slides 和 Lecture 3(evaluation)slides。
  • Kenthapadi, Sameki & Taly, “Grounding and Evaluation for Large Language Models: Practical Challenges and Lessons Learned (Survey)”, 2024(Fall 2024 两次 grounding 课的共同阅读材料)。
  • Ji et al., “Survey of Hallucination in Natural Language Generation”, ACM Computing Surveys 2023;Maynez et al., “On Faithfulness and Factuality in Abstractive Summarization”, ACL 2020。

定义与成因

  • Rashkin et al., “Measuring Attribution in Natural Language Generation Models”, Computational Linguistics 2023(AIS)。
  • Kalai & Vempala, “Calibrated Language Models Must Hallucinate”, STOC 2024;Kalai, Nachum, Vempala & Zhang, “Why Language Models Hallucinate”, 2025。
  • Kandpal et al., “Large Language Models Struggle to Learn Long-Tail Knowledge”, ICML 2023;Mallen et al., “When Not to Trust Language Models”, ACL 2023。
  • Zhang et al., “How Language Model Hallucinations Can Snowball”, 2023;Sharma et al., “Towards Understanding Sycophancy in Language Models”, 2023;Gekhman et al., “Does Fine-Tuning LLMs on New Knowledge Encourage Hallucinations?”, EMNLP 2024。

生成端

  • Lewis et al., “Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks”, NeurIPS 2020。
  • Shi et al., “Trusting Your Evidence: Hallucinate Less with Context-aware Decoding”, 2023;Longpre et al., “Entity-Based Knowledge Conflicts in Question Answering”, EMNLP 2021;Köksal et al., “Hallucination Augmented Recitations for Language Models”, 2023。
  • Chen et al., “Dense X Retrieval: What Retrieval Granularity Should We Use?”, 2023;Jeong et al., “Adaptive-RAG”, NAACL 2024。
  • Gao et al., “Enabling Large Language Models to Generate Text with Citations”(ALCE),EMNLP 2023;Menick et al., “Teaching Language Models to Support Answers with Verified Quotes”, 2022;Liu, Zhang & Liang, “Evaluating Verifiability in Generative Search Engines”, Findings of EMNLP 2023。
  • Lee et al., “Factuality Enhanced Language Models for Open-Ended Text Generation”, NeurIPS 2022;Yang & Klein, “FUDGE: Controlled Text Generation With Future Discriminators”, NAACL 2021。

检测

  • Honovich et al., “TRUE: Re-evaluating Factual Consistency Evaluation”, NAACL 2022;Wang, Cho & Lewis, “Asking and Answering Questions to Evaluate the Factual Consistency of Summaries”(QAGS),ACL 2020;Honovich et al., “Q²”, EMNLP 2021。
  • Min et al., “FActScore: Fine-grained Atomic Evaluation of Factual Precision in Long Form Text Generation”, EMNLP 2023;Wei et al., “Long-form Factuality in Large Language Models”(SAFE),2024。
  • Choi et al., “Decontextualization: Making Sentences Stand-Alone”, TACL 2021。
  • Manakul, Liusie & Gales, “SelfCheckGPT”, EMNLP 2023;Farquhar et al., “Detecting Hallucinations in Large Language Models Using Semantic Entropy”, Nature 2024(第 13 讲)。
  • Agrawal, Suzgun, Mackey & Kalai, “Do Language Models Know When They’re Hallucinating References?”, 2023。
  • Raj, Rosati & Majumdar, “Measuring Reliability of Large Language Models through Semantic Consistency”, NeurIPS 2022 ML Safety Workshop。
  • Azaria & Mitchell, “The Internal State of an LLM Knows When It’s Lying”, 2023;Burns et al., “Discovering Latent Knowledge in Language Models Without Supervision”, ICLR 2023;Li et al., “Inference-Time Intervention”, NeurIPS 2023;Kadavath et al., “Language Models (Mostly) Know What They Know”, 2022;Joshi et al., “Personas as a Way to Model Truthfulness in Language Models”, EMNLP 2024;Levinstein & Herrmann, “Still No Lie Detector for Language Models”, 2024。

修正

  • Gao et al., “RARR: Researching and Revising What Language Models Say, Using Language Models”, ACL 2023;Madaan et al., “Self-Refine”, NeurIPS 2023;Dhuliawala et al., “Chain-of-Verification Reduces Hallucination in Large Language Models”, 2023。
  • Tian, Mitchell, Yao, Manning & Finn, “Fine-tuning Language Models for Factuality”, 2023(第 13 讲)。

13. 下一讲预告 · Next lecture

Lecture 13:置信度、校准与不确定性(Confidence, Calibration & Uncertainty)。

本讲反复撞上同一堵墙:模型有多确定和它对不对是两回事 —— SelfCheck 测的是前者,弃权需要前者,而一致的错误是”很确定但错了”。第 13 讲把”确定”变成一个可以测量的量:一个 LLM 说”我 80% 确定”时,它在这类问题上是不是真的对 80%?我们会把第 1 讲 §5.5 的 reliability diagram 和 ECE 用到 LLM 上,比较三种黑盒的置信度 —— 让模型自己说(verbalized confidence,“Just Ask for Calibration”)、看采样是否一致(本讲 §6.1 的延续)、按语义聚类后算熵(semantic entropy)—— 讨论 RLHF 为什么会让校准变差、temperature scaling 怎么修,以及怎样用 selective prediction 和 conformal prediction 把”什么时候应该说我不知道”变成一个有保证的决策。Eric Mitchell 的 Fall 2023 客座讲座还会给本讲 §4.3 留下的一个问题一个答案:能不能直接训练模型少说错话(factuality tuning)。

← 返回课程目录