Lecture 11 · 评估 LLM 应用:RAG triad 与 LLM-as-a-judge · Evaluating LLM Applications

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

课程源码 ZIP ↓

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

本篇目录

对应 Maps to:Fall 2023 Lecture 2 “Build, Evaluate, Iterate on LLM Apps”(Anupam Datta & 客座 Jerry Liu:用 LlamaIndex 搭应用、用 TruLens 评估;HW1 = 搭一个回答城市问题的 RAG 并用 TruLens 找最好的配置)与 Lecture 9 “Grounding”(RAG triad、groundedness 的验证);Fall 2024 Lecture 2(同名更新版:LLM tech stack、RAG 的失败模式、evals with & without ground truth)、Lectures 3–4(model evaluation:grounded、aligned、consistent、calibrated、interpretable、fair;阅读 Kenthapadi, Sameki & Taly 2024;project directions)、Oct 31 客座 Xiang Lisa Li “Enhancing Evaluation Coverage and Validation with Language Models”(没有公开 slides,§6.3 根据她公开的论文 AutoBencher 与 generator–validator consistency 来写);Autumn 2025 Lecture 2(models, prompting and RAG;The Prompt Report;Survey of Hallucination in NLG)、Lecture 4(projects)、Lecture 7(deep dive into LLMs)、HW1(用 LangGraph + TruLens 搭建并评估一个 data agent,再拿自己的人工标注检验 LLM judge)。 配套代码 Code:code/lecture11/(只用 Python 标准库;4 个脚本 + 2 个模块,每个脚本 1–4 秒) 预计阅读时间:3 小时(含运行代码)


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

0.1 Learning goals

After this lecture you should be able to:

  1. Say precisely what is being evaluated when we evaluate an “LLM application” (not the model, but model + prompt + retrieval + data), and why generative applications are harder to evaluate than classifiers.
  2. 画出一个 RAG 应用的完整管线(chunking → indexing → retrieval → prompt assembly → generation),说出每一步的典型失败,以及它会在 RAG triad 的哪一条边上留下痕迹。
  3. Define the three feedback functions of the triad — context relevance, groundedness, answer relevance — and implement each in several ways (LLM judge with a rubric, NLI-style claim checking, embedding similarity, reference-based metrics), knowing how each one fails.
  4. 把 LLM judge 当作一个测量仪器来验证:一致率、Cohen’s κ、人与人的天花板、按切片的混淆矩阵、不需要标签的偏差压力测试、需要多少人工标签,以及用 prediction-powered inference 修正剩余偏差。
  5. 设计一个评估集:覆盖面与切片、无法回答的问题、合成题的坑、针对性搜索(AutoBencher 的思路)、数据污染。
  6. Run an evaluation-driven development loop without fooling yourself: paired comparisons, run-to-run variance, winner’s curse with a noise floor, held-out confirmation.

0.2 先修与本讲范围 Prerequisites & scope

默认你已经会 Assumed本讲不展开 Not covered here
第 1 讲 §6(LLM 应用栈、RAG triad 的一句话定义)和 §8(winner’s curse、有偏的 judge、Rogan–Gladen 修正)groundedness 检测的深入方法:claim 分解、decontextualization、SelfCheckGPT、RARR、内部状态探针(第 12 讲)
知道 LLM、prompt、embedding、RAG 是什么(CS224N / CS336 程度)LLM 的置信度、校准与弃权(第 13 讲)
二分类的混淆矩阵、AUC(第 1 讲 §5.5)多步 agent 的评估(Agent GPA,第 14 讲)
基本统计:置信区间、bootstrap、配对比较用评估结果自动优化 prompt / 程序(DSPy、GEPA,第 16 讲)
Python 基础(代码只用标准库)LLM judge 作为 reward model 的训练(CS329H)

第 1 讲 §6.3 已经介绍了 RAG triad 的三条边,§8.3 用一个有长度偏差的 judge 说明了”评估器本身要被评估”。本讲把这两件事展开成一套完整的方法:triad 的每条边怎么实现、各自骗不骗得过;judge 怎么验证、怎么修正;评估集怎么建;迭代时怎么不自欺。

0.3 本讲地图 Map

§1  评估的对象:模型 vs 应用;为什么生成式应用难评估;一个知道真相的模拟世界
§2  RAG 端到端:每一步的设计选择和失败模式                          ← 代码 01 演示 1
§3  RAG triad:定义、五个"只坏一处"的版本、triad 与正确性、弃权      ← 代码 01 演示 2–3
§4  实现 feedback functions:每条边的几种做法,各自被什么骗          ← 代码 02 演示 1–4
§5  LLM-as-a-judge:偏差、验证、压力测试、样本量、修正               ← 代码 03 演示 1–4
§6  评估集:覆盖面、针对性搜索、合成题、数据污染                      ← 代码 04 演示 1–3
§7  评估驱动的开发循环:leaderboard 与它的统计陷阱                   ← 代码 04 演示 4
§8  项目方法:frame → build → evaluate → assess trust
§9–13  小结、误区、练习、延伸阅读、下一讲预告

0.4 Notation

符号含义
qq用户的问题(query)
C=(c1,…,ck)C = (c_1, \dots, c_k)检索到、拼进 prompt 的 kk 个 chunk(上下文 context),按排名排列
rr应用的回答(response);claims(r)\text{claims}(r) 是它包含的事实陈述
CR(q,C)\text{CR}(q, C), G(r,C)\text{G}(r, C), AR(q,r)\text{AR}(q, r)RAG triad 的三条边:context relevance、groundedness、answer relevance,都在 [0,1][0, 1]
CR^\hat{\text{CR}} 等(代码里写作 CR^)某个 feedback function 对它的估计;没有帽子的是模拟器里的真相
h∈{0,1}h \in \{0, 1\}, j∈{0,1}j \in \{0, 1\}人工标签、judge 的判断
TPR, FPRjudge 在”真正可接受”和”真正不可接受”的回答上说 yes 的比例
κ\kappaCohen’s κ(§5.3)

0.5 关于数字 · About the numbers

本讲不调用任何真实的 LLM。所有数字来自 rag_world.py 里的一个模拟世界:一个虚构的岛屿 Varn 上有 40 个虚构的小镇,每个事实都确切已知;检索器是手写的 BM25 / 玩具 embedding;“LLM”是一个行为由显式旋钮决定的模拟器(照不照着上下文、会不会弃权、会不会张冠李戴、话多不多……);“LLM judge”和”NLI 模型”也是模拟的,它们的错误率是我们设定的,形式参照文献里报告过的错误模式。

所以:数字说明的是机制(为什么某种评估方法会在某种情况下出错、某种修正为什么有效),不代表任何真实模型或真实系统的性能。模拟的好处是每一个评估方法都可以和真相对照 —— 现实中你没有这个奢侈,这正是本讲要教的东西。所有脚本固定种子,在 Python 3.9 和 3.13 上输出逐字相同。


1. 评估的对象 · What exactly are we evaluating?

1.1 Model vs application

When a paper reports “GPT-x scores 85% on benchmark Y”, the object being evaluated is a model: a fixed set of weights, prompted in a fixed way, on someone else’s data. When you build a product, the object you need to trust is an application:

application = foundation model + prompt template + retrieval (index, chunking, top-k) + your data + post-processing (+ tools, for agents)

The Fall 2024 and Autumn 2025 second lectures describe the ways user text reaches a model: direct access (user text → model), predefined prompts triggered by the user, user text combined with a predefined prompt, and stateful chat (user text + a representation of the history). Each layer can introduce failures the model alone does not have — and fix failures the model alone has. 一个好模型可以组成一个坏应用(检索坏了、prompt 让它凭记忆回答),一个普通模型也可以组成一个可靠的应用(检索好、prompt 要求只用上下文、不知道就说不知道)。所以模型的 benchmark 分数不能代替应用的评估;Autumn 2025 第 7 讲深入 LLM 的预训练与后训练,目的也正是”理解它会把哪些失败模式带进应用”(例如 base model 会编造、后训练会让它更自信)。

Fall 2024 第 3 讲和 Autumn 2025 第 2 讲给出的”可信维度”清单,对模型和应用都适用:

维度问题本课
Grounded / factually correct每个 claim 都能归因到一个权威来源吗?本讲 §3–4(triad)、第 12 讲
Aligned遵守用户指定的安全策略吗?第 15 讲
Consistent换一种问法,答案一致吗?第 1 讲 §5.6、第 12 讲
Calibrated说”我很确定”时真的更可能对吗?第 13 讲
Interpretable回答来自 prompt 的哪一部分、哪些训练数据?第 2–4 讲
Fair and unbiased对不同群体一样好吗?第 5–6 讲

1.2 Why generative applications are hard to evaluate

Classic ML evaluation compares a prediction with a label. For an LLM application, almost every part of that sentence breaks:

  • No canonical label. “Summarize this doctor’s note” has many acceptable answers. Even for factual QA, a correct answer can be phrased in endless ways (the Fall 2023 project-design lecture makes this point and asks students to first spell out what a good response would look like).
  • Long outputs with many claims. A response can be 90% right and contain one fabricated sentence. Is that a pass? It depends on the application (§4.3).
  • Many dimensions at once. Relevance, groundedness, completeness, tone, safety, format — a single “score” hides trade-offs.
  • Intermediate steps matter. A wrong answer may come from retrieval, from generation, or from the question being misunderstood. The Fall 2023 slide on evaluation pitfalls warns that the intermediate steps need evaluating too, not only the final output.
  • Stochastic outputs. Run the same app twice and get different answers (§7.3 measures how much this moves your score).
  • The ground moves. The same slide points out that the underlying base model keeps changing even when your app does not — an API model update can silently change your app’s behaviour.

The Fall 2024 second lecture organizes the available evaluation methods along two axes — scalable vs meaningful:

方法优点缺点(slide 原意)
Traditional NLP evals(BLEU、ROUGE)便宜、可扩展too syntactic:只看字面重合
MLM evals(小模型打分,如 NLI 模型)便宜,适合线上监控需要 fine-tuning
LLM evals(LLM-as-a-judge)与人类判断一致性强资源消耗大,自身有偏差(§5)
Human evals最有意义昂贵、标注者之间有方差
Ground truth evals(有参考答案)有意义、可复现难以大规模收集,线上没有

没有哪一种方法同时满足两个轴。实际的评估体系是组合:小规模的人工 / 参考答案评估提供”真相”,大规模的自动评估(judge、NLI、embedding)提供覆盖面,而前者用来校验后者 —— 这就是 §4–§5 的主题。

1.3 一个知道真相的世界 · The simulated world

为了能检查每一个评估方法,代码搭了一个小世界(rag_world.py):

  • 知识库:虚构的岛屿 Varn 上 40 个小镇,每个镇 6 个属性(建镇年份、人口、河流、镇长、节日、主要出口)。其中 24 个镇两两名字相近(“Port Alder” 和 “Alder Falls”)。
  • 文档:每个镇一篇 7 句的介绍,只有第一句出现镇名,后面用 “It” / “The town” 指代;12 个镇另有一篇 2009 年的过时存档(旧的人口和镇长);还有 4 篇不含具体事实的”岛屿指南”。
  • 问题:600 道,分成 5 个切片(slice):simple 86、confusable 130(镇名有相近的邻居)、paraphrase 216(换了说法,例如问 residents 而文档写 population)、stale 48(存档里有过时值)、unanswerable 120(知识库里没有的属性,例如电话区号;正确行为是说”不知道”)。
  • 模拟 LLM 的旋钮(GenConfig):
旋钮含义对应的真实现象
p_follow上下文里有答案时照着用的概率prompt 是否要求 “only use the context”
p_abstain上下文里没有答案时说”不知道”的概率否则就是 hallucination
p_off_topic回答同一个镇的另一个属性query rewriting 出错、模板 bug
p_confuse把名字相近的镇的值安到本镇头上entity confusion
p_pick_stale新旧值并存时选旧值knowledge conflict
p_know参数记忆里恰好记得正确值“hallucinations can be correct”
n_extra, n_filler额外的 claim、客套话verbosity
middle_penalty, long_penalty中间位置的段落、很长的 chunk 更容易被忽略Liu et al. 2023 “Lost in the Middle”;Shi et al. 2023 “easily distracted by irrelevant context”
leaked某些事实的答案混进了预训练语料数据污染(§6.5)

每个回答都以结构化的 claim(实体, 属性, 值)保存,所以 triad 的三条边和正确性都可以精确计算。


2. RAG 端到端 · RAG end to end

2.1 Why retrieval, in one paragraph

第 1 讲 §6.3 讲过 Fall 2023 的那张 slide:LLM 被训练来泛化,记住事实只是副作用,所以不应该依赖它来”记忆”;让 LLM 做它擅长的通用任务(summarization、embedding、inference、planning),把记忆交给一个可以检索的知识库。这就是 RAG(Lewis et al. 2020)。The 2023 HW1 handout describes it with an analogy: instead of answering from memory, the model answers like a student allowed to look things up in the book, or holding a cue card with the key points. RAG has two phases: indexing (offline: split documents into chunks, embed / index them) and querying (online: retrieve relevant chunks, augment the prompt, generate).

2.2 The pipeline, step by step

代码 01 演示 1 把一个问题完整地走了一遍。

Step 1 — Chunking. 文档被切成 chunk(检索的最小单位)。我们每 2 句切一个。“Port Alder” 的介绍文档被切成 4 个 chunk:

title prefix?chunk 1chunk 2chunk 3chunk 4
不加“Port Alder is a small market town… It was founded in 1660…”“The town has a population of 47,600. The Wyst river…”“The current mayor is Yusra Kalder. Every year it hosts…”“Its main export is smoked herring.”
能归属的事实founded———
加标题“Port Alder (town profile): …”(每个 chunk 都加)
能归属的事实foundedpopulation, rivermayor, festivalexport

不加标题时,7 个事实里只有建镇年份还和镇名在同一个 chunk 里;其他 chunk 是”孤儿”—— 检索器不知道它属于哪个镇,LLM 读到 “The current mayor is Yusra Kalder” 也无法确定是哪个镇的镇长。给每个 chunk 加上文档标题(contextual chunk header)是最便宜的修复;Anthropic 2024 年的 “Contextual Retrieval” 更进一步,用 LLM 为每个 chunk 写一段上下文说明再建索引。Chunk 的大小是另一个旋钮:Fall 2024 第 3 讲推荐的阅读 “Dense X Retrieval”(Chen et al. 2023)讨论的正是检索粒度(句子、段落、命题)。

Step 2 — Indexing and retrieval. The classic lexical retriever is BM25 (Robertson & Zaragoza 2009):

score(q,d)=∑t∈qIDF(t)⋅tf(t,d) (k1+1)tf(t,d)+k1(1−b+b ∣d∣avgdl),IDF(t)=log⁡ ⁣(1+N−nt+0.5nt+0.5)\text{score}(q, d) = \sum_{t \in q} \text{IDF}(t)\cdot\frac{\text{tf}(t, d)\,(k_1 + 1)}{\text{tf}(t, d) + k_1\left(1 - b + b\,\frac{|d|}{\text{avgdl}}\right)},\qquad \text{IDF}(t) = \log\!\left(1 + \frac{N - n_t + 0.5}{n_t + 0.5}\right)

Three intuitions are built in: rare words carry more information (IDF); repeating a word helps but with diminishing returns (k1k_1); long documents are discounted because they contain more words by chance (bb). Dense retrievers instead embed query and chunk into vectors and compare them by cosine similarity — good at paraphrases, often worse at rare proper nouns. A hybrid combines both rankings, e.g. with reciprocal rank fusion (Cormack et al. 2009): RRF(d)=∑r1/(60+rankr(d))\text{RRF}(d) = \sum_r 1/(60 + \text{rank}_r(d)).

问 “Who is the mayor of Port Alder?” 时,BM25 的前 5 名(加标题的索引):

rankscorechunk
17.423Port Alder (town profile): Port Alder is a small market town… founded in 1660…
26.604Port Alder (town profile): Its main export is smoked herring.
36.566Port Alder (town profile): The current mayor is Yusra Kalder. …
45.412Port Alder (town profile): The town has a population of 47,600. …
54.895Port Lisk (archive, 2009): … In 2009 the mayor of Port Lisk was Ilse Tennant.

真正含答案的 chunk 只排第三。原因是 IDF:镇名是罕见词,权重最高;第一名的 chunk 里镇名出现了两次(标题 + 正文第一句),第二名很短(长度惩罚小)。“mayor” 这个词出现在几十个 chunk 里,权重低。这不是 bug,是 BM25 的设计 —— 但它解释了为什么某些切片会系统性地失败。

Step 3 — Prompt assembly and generation. 取 top-kk 拼进 prompt(“只根据以下内容回答;如果内容里没有答案,就说不知道”),模型生成回答。这一步的失败是:不照着上下文(凭记忆)、没找到答案却硬答、被上下文里的无关内容带偏、新旧信息冲突时选错。

2.3 设计旋钮与切片 · Design knobs, measured by slice

演示 1 统计了”当前正确值所在的 chunk 进入上下文的比例”(retrieval recall@k):

configsimpleconfusableparaphrasestaleallctx words
baseline: bm25, k = 3, 2 sents, title1.001.000.670.210.7735.5
no title prefix0.190.180.190.000.1732.7
1 sentence per chunk1.001.000.440.500.7026.1
whole doc per chunk1.001.001.001.001.0089.8
k = 10.570.660.130.000.3414.1
k = 51.001.000.950.900.9760.9
dense, k = 30.830.830.810.920.8336.5
hybrid (RRF), k = 31.001.001.001.001.0036.8

四个教训:

  1. 不带上下文的 chunking 是灾难性的(recall 0.17)。而且只看最终回答时它是隐形的 —— 模型只会礼貌地说”我不知道”。
  2. 字面检索在换说法的问题上失败(0.67);在 stale 切片上失败得更隐蔽(0.21):存档文档把镇名重复了三次,BM25 把它排在含当前值的 chunk 前面。
  3. 更多上下文用成本换 recall:k=5k = 5 或整篇文档一个 chunk 能把 recall 拉到 0.97 / 1.00,但上下文从 36 个词涨到 61 / 90 个 —— 更多 token、更高延迟,也有更多无关内容去干扰生成器。
  4. 没有一种检索器处处最好,除非把它们结合起来:玩具 dense 检索修好了 paraphrase(0.81),却在专有名词上变差(simple 切片 0.83);hybrid 处处 1.00。只有按切片评估才看得到这一点。

2.4 失败模式目录 · A catalog of failure modes

Fall 2024 第 2 讲的 slide 把 RAG 的失败模式画在管线上:query understanding、chunking strategies、data quality、embedding quality、retrieval quality、context overflow、hallucinations。Barnett et al.(2024)从三个真实项目里总结了七个 failure points(FP1 missing content … FP7 incomplete)。把它们和 triad 对应起来:

失败模式例子(本讲的世界)哪条边能看到文献
Missing content问电话区号(知识库里没有),模型硬答G 低(编造);正确行为是弃权,AR 反而记 0(§3.4)Barnett FP1
Chunking 丢了上下文不加标题,chunk 里没有镇名CR 低2024 slide “chunking strategies”
检索质量 / 排名paraphrase 题的答案排在 top-k 之外CR 低Barnett FP2 “missed top-ranked documents”
Data quality(过时、冲突)存档里的旧镇长三条边都看不到(§3.3)2024 slide “data quality”
Context overflow、干扰k 太大、chunk 太长,答案在中间被忽略CR 下降;正确率下降Barnett FP3;Liu et al. 2023
Not extracted / 实体混淆把邻居镇的年份安到本镇G 低(claim 不被支持)Barnett FP4
不看上下文(凭记忆)prompt 没要求只用上下文G 低2024 slide “hallucinations”
Query understanding / 答非所问问人口,答了河流AR 低2024 slide “query understanding”
Incomplete / wrong format多问题只答一半、格式不对AR(部分);需要专门的检查Barnett FP5–FP7

3. RAG triad

3.1 Definitions

The RAG triad (TruEra, now part of Snowflake; the course’s central evaluation framework since 2023) evaluates the three edges between query, context and response:

                 Query q
               ╱        ╲
  Context relevance      Answer relevance
  CR(q, C)                AR(q, r)
             ╱              ╲
      Context C ─────────── Response r
               Groundedness G(r, C)

A feedback function (Fall 2023 lecture 2) is any function that reads an LLM app’s inputs, outputs, intermediate results and metadata, and returns a score. The triad uses three of them. Written as formulas — the way our simulator computes the truth:

CR(q,C)=1k∑j=1krel(q,cj),G(r,C)=1∣claims(r)∣∑a∈claims(r)1[∃ c∈C: c supports a],AR(q,r)=1[r addresses q]\text{CR}(q, C) = \frac{1}{k}\sum_{j=1}^{k} \text{rel}(q, c_j), \qquad \text{G}(r, C) = \frac{1}{|\text{claims}(r)|}\sum_{a \in \text{claims}(r)} \mathbb{1}\big[\exists\, c \in C:\ c \text{ supports } a\big], \qquad \text{AR}(q, r) = \mathbb{1}\big[r \text{ addresses } q\big]
  • CR is a precision: the fraction of retrieved chunks that are relevant. (RAGAS, Es et al. 2024, uses a sentence-level variant: relevant sentences / all sentences in the context.)
  • G uses the course’s definition of grounding (Rashkin et al. 2023, “attributable to identified sources”): a claim is supported if a human reading the context would affirm “according to C, a”. It says nothing about whether CC itself is true.
  • AR asks whether the response addresses the question — not whether it is correct.

The TruLens documentation states the promise: if all three are satisfactory, the app is free of hallucination up to the limits of its knowledge base. §3.3 tests the fine print.

3.2 Five versions, each broken in one place

演示 2:五个版本,每个相对 V0 只改一处,在全部 600 题上各跑一次。左边是真相,右边是 §4 的 reference-free feedback functions(模拟的 LLM judge + NLI)的估计:

version改了什么CRGARcorrectabstainCR^\hat{\text{CR}}G^\hat{\text{G}}AR^\hat{\text{AR}}
V0 baseline—0.230.880.700.6980.2800.430.790.72
V1 bad retrievalchunk 不加标题0.070.870.310.2850.6870.240.860.41
V2 ignores context模型大量凭记忆0.230.560.720.4400.2700.420.540.74
V3 off-topic常答非所问0.230.900.360.4000.3420.420.800.51
V4 fluent hallucinator从不弃权 + 附加记忆里的内容0.230.460.970.5480.0000.410.410.93

每种失败主要点亮一条边,这正是 triad 作为诊断工具的价值:它告诉你该修检索、修生成,还是修问题理解。几点细节:

  • CR 的绝对值不高(V0 只有 0.23),因为它是 precision:k=3k = 3 而通常只有一个 chunk 真正相关,上限约 1/3。CR 只适合在 kk 相同的版本之间比较(练习 1)。
  • 边与边不独立。 V1 检索失败后,模型多数时候老实地说”不知道”(弃权率 0.687),于是 AR 也跟着掉到 0.31。Read the triad in pipeline order: the most upstream broken edge is the root cause.
  • V4 是最危险的版本。 它的 AR 最高(0.97),回答最”完整”;可回答问题上的准确率(0.685)甚至高于 V0(0.652)—— 从不弃权,瞎猜偶尔也能猜中。但无法回答的问题全错(0.000),而且回答里夹带着没有依据的内容。只看 AR 或用户满意度会选中它。
  • 估计值的排序和真相一致(每个版本坏掉的那条边,估计值也明显下降),但数值有系统性偏差:CR^\hat{\text{CR}} ≈ 0.42,远高于真实的 0.23 —— judge 对”话题相近”的 chunk 偏宽松(§4.2)。

3.3 Triad vs correctness: what the triad cannot see

演示 3 把五个版本的回答放在一起。可回答的问题上给出了答案的 1847 个回答里,正确 1029 个。每个真实 triad 分数区分对错的 AUC:

scoreAUC
context relevance0.590
groundedness0.773
answer relevance0.612
CR × G × AR0.891

单独一条边都只看到一部分失败;三者合起来好得多。Fall 2023 的 slides 特别强调了两种反直觉的情形,代码数得出它们有多常见:

correctwrong
fully grounded736265
not fully grounded293553
  • Grounded but wrong (265). 148 are off-topic answers built from true facts in the context (“Or we might be answering the wrong question”), and 117 faithfully quote the outdated archive. Groundedness checks response ↔ context; it cannot check context ↔ world.
  • Not grounded but correct (293). Only 22 are the slide’s “sometimes hallucinations can be correct” — the model recalled the right value from parametric memory, which you cannot verify. The other 271 have a correct, supported main claim plus unsupported extra claims (mostly V4): misinformation mixed into a correct answer.

一个简单的规则”三条边都通过”(CR > 0、G = 1、AR = 1):通过 853 个,其中正确 736 个,precision 0.863、recall 0.715。通过了却错的 117 个全部是过时存档。 这是一个干净的结论:triad 对知识库本身的质量完全是盲的。Fall 2024 第 3 讲专门问过”一个 grounded 的回答还会是错的吗?“,slide 的回答是:会,只要上下文本身不相关、互相冲突或含糊;修复是改进检索与知识库 —— 需要另外的检查(文档的日期与版本、冲突检测、定期的人工抽查)。

3.4 弃权与 triad · Abstention

Fall 2024 第 2 讲的 TruLens quickstart 里有两张 slide:“Evaluate evidence only for substantive claims” 和 “Or the LLM can abstain from answering”。弃权在 triad 里的处境很尴尬:

  • 一个弃权的回答没有 claim,G 记为 1(没有没依据的内容);对可回答的问题它是错的。
  • 它没有回答问题,AR 记为 0;可对无法回答的问题,弃权恰恰是正确的行为。演示 3 里 394 个正确弃权的平均 AR 是 0.0。

所以评估集里一定要有无法回答的问题(否则”从不弃权”的 V4 看起来最好),而且要单独报告两个比例:该弃权时弃权了吗(V0 在无法回答的问题上 0.883)、不该弃权时弃权了吗(V1 在可回答问题上大量弃权)。这是 selective prediction 的语言,第 13 讲会把它和置信度联系起来。


4. 实现 feedback functions · Implementing feedback functions

4.1 The design space

Every feedback function makes four choices:

choiceoptionstrade-off
ScorerLLM judge with a rubric; NLI / small classifier; embedding similarity; lexical overlap; reference-based matchcost and latency vs fidelity; reference-based needs labels
Scalebinary; Likert (TruLens currently defaults to 0–3 for context relevance, normalized to [0, 1]; the 2023 HW1 describes groundedness “on a scale from 1 to 10”)finer scales carry more information but are less consistent across calls
Reasonsask for chain-of-thought reasons before the score (TruLens *_with_cot_reasons)reasons make the score auditable and usually more accurate; cost more tokens
Aggregationover chunks (mean), over claims (mean / min), over snippets (noisy-OR)determines what question the number answers (§4.3)

一个例子(python3 feedback.py 的自检输出):同一个问题 “Who is the mayor of Port Alder?”,三个回答:

回答真实 G词重叠 Gclaim 级 NLI GAR judgetoken F1
“The mayor of Port Alder is Yusra Kalder.”1.001.000.901.000.57
同上 + 两条凭记忆附加的 claim + “Great question!”0.330.620.301.000.22
“The mayor of Port Alder is Ilse Ruiz.”(凭记忆编的)0.000.600.061.000.00

三个回答的 AR 都是满分 —— 它们都在回答被问的问题;把它们分开的是 groundedness,而两种 groundedness 实现的区分能力差得很远。下面逐条边看。

4.2 Context relevance

演示 1(a) 取两个索引(加 / 不加标题)的 top-5,共 6000 个(问题, chunk)对,按 chunk 和问题的关系分类,看三种不需要标注的打分各给多少分:

scorerrelevantsame town, other attributeneighbour town, same attributeno town nameotherAUC
(count)64024461956372082
LLM judge (0–3 rubric)0.9400.2600.4170.3480.0580.965
bag-of-words cosine0.4060.2890.3410.3680.1710.759
toy embedding cosine0.4000.0980.3720.5430.1570.847
  • The LLM judge separates relevant from irrelevant best, and its errors sit exactly where you’d expect: topically similar chunks (same town, neighbour town, unattributed sentence about the same attribute) get roughly 1 point out of 3.
  • Bag-of-words cosine barely separates “relevant” (0.41) from “same town” (0.29): it counts shared words.
  • The toy embedding scores unattributed sentences (“The current mayor is …”, no town name) higher than truly relevant chunks (0.54 vs 0.40): they are short and full of attribute words. Embedding similarity measures “looks alike”, not “can answer this question”.

有参考标注时(知道哪个 chunk 含正确答案),检索可以用经典的 IR 指标评估:recall@k(前 kk 个里有没有 gold chunk)、MRR(第一个 gold chunk 排第 rr 位记 1/r1/r)。演示 1(b),三种检索器,k=3k = 3,可回答的 480 题:

retrieverrecall@3MRR@3true CRjudge CR^\hat{\text{CR}}end-to-end acc
bm250.7730.5180.2910.4450.669
dense0.8310.6980.3100.3720.715
hybrid1.0000.8650.3670.4420.856

recall、MRR 和端到端准确率都排成 hybrid > dense > bm25;有偏的 judge 却把 bm25 排在第一(0.445 ≈ 0.442 > 0.372)。原因正是上表:bm25 检索到的多是”同一个镇的其他段落”,judge 对它们偏宽松;dense 检索到的多是”别的镇的同一属性”,judge 给低分。一个有偏的 judge 不只让数值偏,排名也会错。所以在评估集上,能标 gold chunk 就标 —— recall@k、MRR 便宜、可靠、可复现;judge 给出的 CR 更适合线上监控和找个案。

4.3 Groundedness

Fall 2023 第 9 讲的 “corroboration workflow”(Autumn 2025 第 2 讲沿用):

response ─→ ① sentence / claim extractor ─→ ② "requires verification?" check ─→ ③ decontextualization
         ─→ ④ NLI model: s_ij = P(snippet j entails sentence i) ─→ report: sentence, score, citations

Each sentence is scored against every snippet and the scores are combined with a noisy-OR (“supported if any snippet supports it”), then averaged over sentences:

si=1−∏j=1k(1−sij),G^=1m∑i=1msis_i = 1 - \prod_{j=1}^{k}\big(1 - s_{ij}\big), \qquad \hat{\text{G}} = \frac{1}{m}\sum_{i=1}^{m} s_i

(The slide notes that a product over sentences can be used instead of the mean.) 第 12 讲会深入 claim 分解、decontextualization、NLI 模型(TRUE,Honovich et al. 2022)和不依赖检索的检测方法;这里只把它当作 triad 的一条边,和最便宜的替代品 —— 词重叠(回答里的内容词有多少出现在上下文里)—— 做对比。

演示 2,2759 个没有弃权的回答,按”主要特征”分类,表中是被判为 grounded(分数 ≥ 0.5)的比例。前四类确实 grounded(应接近 1),后两类不是(应接近 0):

scorerplainparaphrasedfillerstaleconfusedmemorycorr(G)AUC
(count)9755648617452908
token overlap1.0000.6681.0000.8450.9230.5020.5030.822
NLI, no filter, mean0.9500.8100.7670.9310.2880.0030.8830.986
NLI + filter, mean0.9500.8720.9880.9480.2880.1700.9150.977
NLI + filter, min0.9500.8160.7670.9310.2880.0030.8380.988

逐行读:

  • 词重叠在张冠李戴上全军覆没:92% 的 confused 回答被判为 grounded。“Port Alder was founded in 1721” —— “Port Alder” 在本镇的 chunk 里,“1721” 是邻居 Alder Falls 的建镇年份、在邻居的 chunk 里(Port Alder 其实建于 1660),每个词都”在上下文里”,组合起来的 claim 却是错的。它对改写措辞又过严(paraphrased 0.668)。
  • claim 级 NLI 把 claim 当作整体核对:confused 只有 0.288 通过(剩下的是 NLI 被几乎相同的名字骗过,2023 slide 列的 precision 问题)。
  • “Requires verification” 过滤器:客套话(“Great question!”)不被任何 chunk 蕴含;不过滤时它们拉低了平均分,filler 一类只有 0.767 通过,过滤后 0.988。代价:memory 一类的通过率从 0.003 升到 0.170 —— 分母里少了客套话,编造的那一句被”稀释”了。
  • 聚合方式决定了这个数在回答什么问题。 mean 问”多大比例的内容有依据”,min 问”有没有任何一句没依据”。min 把 memory 压回 0.003,但任何一句漏判都会拒掉整个回答(filler 回到 0.767)。医疗、法律类应用通常要 min(一句编造都不行);一般的问答助手 mean 也许就够了。这是一个规范性选择,应该写进评估文档。
  • 所有方法都让 stale 回答通过(0.85–0.95)。这不是 bug:groundedness 的定义就是”回答 ↔ 上下文”。

4.4 Answer relevance, and metrics that use references

Two reference-free ways to score answer relevance: an LLM judge with a rubric (TruLens relevance_with_cot_reasons), and the RAGAS approach (Es et al. 2024) — ask an LLM to generate questions from the answer and measure their similarity to the original question; if the answer is on topic, the back-generated question should mean the same thing. When references exist, the classic QA metrics apply: exact match / contains-match and SQuAD-style token F1 (Rajpurkar et al. 2016). 演示 3(可回答问题上的 2880 个回答):

scorerneeds reference?AUC vs ARAUC vs correct
AR LLM judgeno0.9800.711
AR RAGAS-style (embed)no1.0000.738
contains-matchyes0.8540.998
token F1yes0.8620.992
  • 两种 AR 打分都准确地测量了它们声称测量的东西(对真实 AR 的 AUC ≈ 1)—— 但那不是正确性:切题的回答里有 28.4% 是错的(461 个凭记忆编造、154 个引用过时存档、53 个张冠李戴)。张冠李戴的回答在 judge 上平均 0.934、在 RAGAS 式打分上 0.999 —— 它们确实切题,只是答错了。
  • 有参考答案时,contains-match 几乎就是正确性本身(0.998)。token F1 有两个坑:和一个很短的参考答案比,整句回答即使正确分数也低(简洁的正确回答平均只有 0.410 —— 应先抽取答案片段再算);而且它惩罚啰嗦(带额外内容的正确回答平均 0.110)。拿 F1 当优化目标,会把系统推向”只说答案”,不管用户想要什么。

4.5 有参考答案 vs 没有参考答案 · With vs without ground truth

演示 4:八个版本,比较三种排名:

versiontrue accref-matchCR^\hat{\text{CR}}G^\hat{\text{G}}AR^\hat{\text{AR}}product
V0 baseline0.7180.7180.4250.7880.7330.257
V1 bad retrieval0.2980.2980.2450.8330.4330.090
V2 ignores context0.4220.4220.4180.5420.7380.137
V3 off-topic0.4320.4320.4120.7950.5510.186
V4 fluent halluc.0.5570.5620.4210.3950.9510.169
V5 hybrid0.8330.8330.4160.7610.8170.260
V6 k = 50.8050.8050.3520.7700.8020.224
V7 hybrid + strict prompt0.8730.8730.4070.8040.7860.259

和真实准确率的 Spearman ρ:ref-match +1.000;CR^\hat{\text{CR}} +0.048;G^\hat{\text{G}} −0.048;AR^\hat{\text{AR}} +0.595;乘积 +0.929。

有参考答案时,一个简单的自动匹配就几乎复现了真实准确率 —— 只要可能,就为评估集写参考答案。没有参考答案时,单独一条边都排不对(AR^\hat{\text{AR}} 把从不弃权的 V4 排第一,G^\hat{\text{G}} 最高的是大量弃权的 V1);三者相乘好得多,但仍然不是准确率(V0 和 V5 的乘积几乎一样,0.257 vs 0.260,真实准确率差 0.115)。

实践中的分工正对应 §1.2 的那张表:开发阶段在有参考答案的评估集上测准确率,同时记录 triad 用来诊断;上线后没有参考答案,用 triad 这类 reference-free 信号做监控和报警,再定期抽样做人工标注,检查监控信号本身还准不准。


5. LLM-as-a-judge

5.1 Why judges, and the three protocols

Human evaluation is the gold standard and does not scale; references do not exist in production. So since 2023 a widespread practice is to let a strong LLM grade outputs. Zheng et al. (2023), who introduced MT-Bench and analyzed judges against Chatbot Arena votes, distinguish three protocols:

  • Pointwise / single-answer grading: the judge scores one response (on a rubric, e.g. 1–10 or yes/no). Scales to any number of systems, but scores drift across prompts and models.
  • Pairwise comparison: the judge sees two responses to the same question and picks the better one (or a tie). Often more sensitive to small differences, but costs grow with the number of systems, and it introduces position bias.
  • Reference-guided grading: the judge is given a reference answer. Much better on questions the judge itself might get wrong (math, facts).

Refinements of pointwise judging include rubrics with explicit criteria and chain-of-thought before the score (G-Eval, Liu et al. 2023, which also weights scores by the judge’s token probabilities), and open judge models trained to follow rubrics (Prometheus, Kim et al. 2024). TruLens’ feedback functions are pointwise rubric judges with CoT reasons; the Agent GPA judges of Autumn 2025 are too (L14).

5.2 Known biases

Zheng et al. (2023) measured, with GPT-4, Claude-v1 and GPT-3.5 as judges:

biaswhat they didwhat they found
Positionask for a verdict, swap the order of the two answers, ask againwith the default prompt, GPT-4 gave the same verdict in both orders only 65.0% of the time (biased toward the first in 30.0%); Claude-v1 23.8%, GPT-3.5 46.2%
Verbosity“repetitive list” attack: pad an answer by rephrasing its list items, adding no informationClaude-v1 and GPT-3.5 preferred the padded answer 91.3% of the time; GPT-4 8.7%
Self-enhancementcompare win rates when the judge’s own model wrote one answerGPT-4 favored itself by about 10% in win rate, Claude-v1 by 25% (the authors caution that their data are limited)
Limited reasoninggrading math answers the judge could solve itselfGPT-4 judged wrong answers correct in 70% of comparisons by default, 30% with CoT, 15% when given a reference answer

Later work sharpened these: Wang et al. (2023) showed position bias can flip rankings and proposed evaluating both orders and calibrating; Panickssery et al. (2024) found that LLM evaluators can recognize their own generations and that this ability correlates with self-preference; Dubois et al. (2024) built length-controlled AlpacaEval, which removes the length effect by regression.

本讲的模拟里还加了一种结构性的盲点:judge 只能看到你给它的东西。回答忠实地引用了过时存档时,只看上下文的 judge 没有办法知道它过时了(§3.3 的同一个问题,换到了 judge 身上)。

5.3 验证一个 judge · Validating a judge

代码 03 有两个模拟的 judge,判断”这个回答可以接受吗?“(正确,而且每条 claim 都有依据;无法回答的问题要弃权):

  • J-A:和被评估的 A 系列系统同一个模型家族,有上面三种偏差;
  • J-C:另一个家族、更仔细,偏差小得多。两者都有过时存档的盲点。

Step 1: a meta-evaluation set with a human ceiling. 随机抽 800 个回答,两位标注者独立标注(每人 5% 的标注噪声)。

比较一致率Cohen’s κ
human 1 vs human 2(天花板)0.9010.797
J-A vs human 10.7800.536
J-C vs human 10.8710.734

Why κ and not just agreement? Agreement rewards chance: if 90% of responses are acceptable, a judge that always says “yes” agrees 90% of the time. Cohen’s κ (Cohen 1960) subtracts the agreement expected if the two raters were independent but kept their own yes-rates:

κ=po−pe1−pe,pe=pyes(1) pyes(2)+(1−pyes(1))(1−pyes(2))\kappa = \frac{p_o - p_e}{1 - p_e}, \qquad p_e = p^{(1)}_{\text{yes}}\,p^{(2)}_{\text{yes}} + \big(1 - p^{(1)}_{\text{yes}}\big)\big(1 - p^{(2)}_{\text{yes}}\big)

The always-yes judge has κ=0\kappa = 0. Landis & Koch’s (1977) conventional labels call 0.41–0.60 “moderate” and 0.61–0.80 “substantial” — but the more meaningful comparison is with human–human agreement on the same items: Zheng et al. report GPT-4–human agreement of 66% (85% excluding ties) against human–human 63% (81%), and that comparison is what licenses using the judge at all.

Step 2: per-slice confusion matrices. 总体数字说 J-A “中等”;拆开看才知道它在哪里出错(以标注者 1 为准):

slicenhuman yesjudge TPRjudge FPRκ
simple1210.6200.9330.4130.553
confusable1790.6540.8890.3390.567
paraphrase2980.4560.8900.2960.582
stale490.2240.7270.6840.025
unanswerable1530.7910.8930.4060.486
short responses6530.6480.8870.2830.614
long responses1470.2520.9730.5640.265
style A (judge’s own family)3890.5190.9110.5030.414
style B4110.6280.8800.2160.666

三种偏差和一个盲点一目了然:stale 切片 κ ≈ 0.03(几乎是瞎猜);长回答的 FPR 是短回答的两倍;自家风格的 FPR 是别家的两倍多。注意 n:stale 只有 49 条,这些数字本身的误差不小(§5.5)。

Step 3: does the bias change decisions? 用两个 judge 给四个系统打分:

systemtrueJ-A saysJ-C says
A1 faithful0.7130.7960.712
A2 verbose0.3230.6770.413
B1 faithful0.7030.7130.706
B2 memory-heavy0.4780.5110.496

J-A 把 A2 高估了 0.35,排到了 B2 前面;J-C 的排名和金标准一致。偏差落在被比较的系统之间不同的属性上(这里是长度和风格)时,排名就会被弄反 —— 第 1 讲 §8.3 的教训,这里有三种偏差同时作用。

5.4 不需要标签的压力测试 · Stress tests without labels

Before collecting any human labels, you can test a judge with counterfactual (metamorphic) perturbations — changes that should not change the verdict. 演示 2 用 A1、B1 的 2400 个回答,每个回答只抽一个随机数,原版和改动版共用(相当于一个 temperature = 0 的 judge),所以差别只来自改动本身 —— 和第 1 讲 §5.3、第 7 讲的”翻转率”是同一个想法:

judgeyes rate+ 2 fillersrestyle as Arestyle as B
J-A0.750+0.045(4.5% 翻转)+0.040−0.042
J-C0.717+0.013+0.000+0.000

Position bias needs pairs. On the 482 A1–B1 pairs whose two answers have the same gold label, an unbiased judge should pick the first answer half the time: J-A picks it 65.6%, J-C 54.3%. Across all 600 pairs, asking twice with the order swapped gives the same verdict only 55.7% (J-A) / 60.8% (J-C) of the time.

Now use the pairwise judge to compare A2 verbose (gold 0.322) with B1 faithful (gold 0.693), under three protocols:

judge / protocolA2 winsB1 winsties
J-A: A2 always shown first0.6780.322—
J-A: random order0.5330.467—
J-A: both orders, win only if consistent0.3320.2570.412
J-C: A2 always shown first0.3930.607—
J-C: random order0.3400.660—
J-C: both orders, win only if consistent0.1920.4700.338

Zheng et al.’s conservative protocol — call both orders, declare a win only if the verdicts agree, otherwise a tie — removes position bias, at the price of many ties. It does not remove other biases: J-A still prefers A2 because of self-preference and verbosity. Each bias needs its own control: swap for position, length control or length-stratified correction for verbosity, a judge from a different model family for self-preference, and the right context (e.g., document dates) for blind spots.

5.5 需要多少人工标签? · How many human labels?

演示 3 把整个池子(4800 条)当作总体,J-A、J-C 的”真实” κ 是 0.540 和 0.734。每次随机抽 nn 条有标签的记录估计 κ,重复 1000 次:

n labelsκ(J-A): 5%–95%κ(J-C): 5%–95%P(J-C correctly ranked above J-A)
250.262–0.8030.483–0.9200.858
500.320–0.7250.560–0.8800.945
1000.408–0.6780.619–0.8430.989
2000.437–0.6370.654–0.8100.997
4000.471–0.6090.675–0.7891.000
8000.493–0.5870.695–0.7721.000

两个结论:

  1. 估计一个 judge 的 κ 需要几百条标签。 25 条时 J-A 的 κ 可以测出 0.26 到 0.80 之间的任何值 —— “κ = 0.8,可以用”可能只是运气好。误差大致按 1/n1/\sqrt{n} 缩小。
  2. 比较两个 judge 要容易得多,因为是在同一批样本上配对比较:50 条已有 94.5% 的概率选对,100 条 98.9%。

实践建议:先用 50–100 条标签筛掉明显差的 judge / prompt;为选中的那个收集几百条,分层抽样保证每个重要切片(stale、long、各系统的风格)都有足够的样本,再按切片报告。Autumn 2025 HW1 要求的正是这个流程的缩小版:先自己标注 trace 的失败,再检查 LLM judge 的指标和你的标注是否一致。

5.6 修正与校准 · Correcting the judge

Options, from cheapest to most general:

  • Fix the protocol: swap positions (§5.4); give the judge a reference answer when one exists; give it the information it is blind to (document dates); use a judge from a different model family than the systems being compared.
  • Fix the judge: refine the rubric with examples from the disagreements you found. Shankar et al. (2024, “Who Validates the Validators?”) observe criteria drift: graders refine their criteria while grading, so the rubric and the labels should be developed together, iteratively.
  • Correct the numbers statistically. Length control by regression (Dubois et al. 2024); stratified Rogan–Gladen inversion of the judge’s TPR/FPR (L1 §8.3), which assumes the judge’s errors depend only on the attributes you stratify on; or prediction-powered inference (PPI; Angelopoulos et al. 2023), which needs no such assumption — only a random human-labeled sample:
θ^PPI=1N∑i=1Nji⏟judge on N unlabeled+1n∑l=1n(hl−jl)⏟rectifier: judge’s bias, estimated on n labeled,Var(θ^PPI)=Var(j)N+Var(h−j)n\hat\theta_{\text{PPI}} = \underbrace{\frac{1}{N}\sum_{i=1}^{N} j_i}_{\text{judge on } N \text{ unlabeled}} + \underbrace{\frac{1}{n}\sum_{l=1}^{n}\big(h_l - j_l\big)}_{\text{rectifier: judge's bias, estimated on } n \text{ labeled}}, \qquad \text{Var}\big(\hat\theta_{\text{PPI}}\big) = \frac{\text{Var}(j)}{N} + \frac{\text{Var}(h - j)}{n}

ARES (Saad-Falcon et al. 2024) uses PPI to turn lightweight fine-tuned judges plus a small human-annotated set into confidence intervals for RAG metrics.

演示 4:估计 A2 verbose 的可接受率(金标准 0.323),N = 2000 个 judge 标签,n 个人工标签,重复 500 次:

judgenestimatormean estbiasCI widthcoverage
J-A50judge only0.673+0.3500.0410.000
J-A50human only0.328+0.0040.2600.942
J-A50PPI0.327+0.0040.2880.936
J-A200PPI0.322−0.0010.1490.944
J-C50judge only0.406+0.0820.0430.000
J-C50human only0.323−0.0010.2590.950
J-C50PPI0.326+0.0030.1830.924
J-C200human only0.324+0.0010.1300.960
J-C200PPI0.323−0.0010.1010.956
  • Judge only gives tight, confidently wrong intervals: more judge labels cannot fix bias; coverage is 0 for both judges.
  • PPI is unbiased for both judges and covers the truth about 95% of the time.
  • With a good judge (J-C), PPI saves labels: at n = 50 the interval shrinks from 0.259 to 0.183, at n = 200 from 0.130 to 0.101 — in variance terms the human labels count 1.7–2 times.
  • With a bad judge (J-A), PPI is worse than humans alone (0.288 vs 0.260): Var(h−j)\text{Var}(h - j) exceeds Var(h)\text{Var}(h) when the judge is wrong a lot (练习 6). Classical PPI has no automatic fallback; PPI++ (Angelopoulos, Duchi & Zrnic 2023) adds a tuning weight to address this.

修正不能代替验证:先用 §5.3–5.5 选一个好的 judge,再用 PPI 把它剩下的偏差扣掉。


6. 评估集 · Building evaluation sets

6.1 Where questions come from

来源优点风险
真实用户日志代表真实的使用分布隐私(第 9–10 讲);冷启动时没有;罕见但重要的情形太少
专家手写质量高,能覆盖边界情形贵;容易只写自己想得到的问题
合成(LLM 从文档出题)便宜、规模大坏题、覆盖面歪斜(§6.4)
对抗 / 针对性搜索集中暴露弱点不代表真实分布(§6.3)

The Autumn 2025 HW1 describes the typical workflow for reliable agents: curate a small dataset first, let the system run, annotate the errors, then explore where improvements are needed. Whatever the source, design the set around slices: question types, entity types, difficulty, answerable vs unanswerable, user groups (L5’s lesson: averages hide subgroups). Our 600 questions have 5 slices on purpose; §2.3 showed that one retriever’s 0.77 overall recall is 1.00 on two slices and 0.21 on another.

6.2 覆盖面的要点 · Coverage checklist

  • 无法回答的问题:没有它们,“从不弃权”的系统看起来最好(§3.2 的 V4)。
  • 相近实体、过时 / 冲突的文档:triad 看不见知识库的问题,评估集要专门放这类题。
  • 换说法的问题:用户不会照着文档的用词提问。
  • 多跳、比较类问题:“Compare and contrast Uber and Lyft revenues in 2020–2021”(Fall 2023 第 2 讲的例子)需要 query planning:拆成子问题、分别检索、再合并。这类题在朴素 RAG 上通常失败,slides 也指出 query planning 提高质量的代价是更多 token 和延迟 —— 所以 leaderboard 上要同时放质量和成本(§7.2)。

6.3 Targeted search: AutoBencher

The Oct 31, 2024 guest lecture (Xiang Lisa Li, “Enhancing Evaluation Coverage and Validation with Language Models”) has no public slides; this section follows her public papers. AutoBencher (Li, Kaiyom, Liu, Mai, Liang & Hashimoto; ICLR 2025) treats benchmark construction as optimization: an LM proposes and refines dataset descriptions (e.g. a topic), each description is turned into questions and answers, and the descriptions are optimized for declared objectives such as difficulty and salience (and, in a safety setting, eliciting harmful compliance). The paper reports that its datasets elicited 22% more model errors than existing benchmarks and surfaced specific knowledge gaps. A related paper on generator–validator consistency (Li et al., ICLR 2024) uses the model’s own answers in two roles — generating, then validating — to find inconsistencies without labels, an instance of L1 §5.6’s “inconsistency can be detected without ground truth”.

演示 1 模拟了其中”按难度搜索”的部分:把”切片 × 属性”的 23 个区域当作 23 条数据集描述;先每个区域问 2 题,之后每轮选乐观估计的失败率最高的区域再问 3 题(UCB 的思路)。V0 的失败高度集中:4 个区域错误率 ≥ 0.5(paraphrase 问镇长 0.99、问节日 0.98;stale 问镇长 0.90、问人口 0.89),整体错误率 0.285。

budget Bstrategyfailures foundhard regions hit (of 4)failing examples per hard regionerror rate on the set
60random16.83.722.70.280
60targeted24.23.984.90.404
120random34.03.965.50.283
120targeted82.53.9619.40.687
240random68.04.0010.90.283
240targeted201.03.9749.10.837
  • 预算 B ≥ 120 时,targeted 找到的失败是随机的 2.4–3 倍(B = 60 时只有 1.4 倍,因为探索阶段就用掉了 46 题);每个困难区域有足够多的失败样例,才看得清模式、验证得了修复。
  • 我原本以为 targeted 的主要优势是发现困难区域;结果是 B ≥ 120 时随机抽样也几乎都能碰到(这 4 个区域共 116 题,并不罕见)。只有预算小(B = 60:3.98 vs 3.72)或困难区域罕见时,“发现”上的优势才明显。
  • targeted 集合上的错误率(0.40–0.84)不是系统的错误率(真实 0.285,随机集合测出 0.28)。targeted 集合用来找 bug、做回归测试;报告”系统有多好”必须用代表使用分布的随机样本 —— 或者用已知的抽样概率加权。

6.4 合成评估集的坑 · Synthetic test sets

Tools like RAGAS and LlamaIndex can generate (question, reference) pairs from your documents. 演示 2 模拟一个出题 LLM:随机挑一个 chunk、挑其中一个事实、写一道题。然后用一个 round-trip 过滤器:另一个更强的模型读完整的最新文档回答这道题,答案和参考答案一致才保留(这个核对模型在名字相近的镇上有 15% 的概率出错,其他 3%)。

pipeline400 道题的构成过滤后V0 bm25: raw / filtered / truthV5 hybrid: raw / filtered / truth
naive(chunk 不加标题)ok 85, ambiguous 282, stale_ref 29, copy_error 475 道,全是建镇年份0.247 / 0.933 / 0.8120.225 / 0.880 / 0.849
chunk 加标题ok 348, stale_ref 31, copy_error 21311 道(export 79、founded 75、mayor 37…)0.760 / 0.849 / 0.8120.780 / 0.846 / 0.849

(truth = 240 道人工写的同类题上的真实准确率。)

  • 坏题在朴素流水线里把原始分数压得很低:400 道题里有 282 道只能写成 “the town”(chunk 里没有镇名),脱离原文就无法回答;存档 chunk 产生过时的参考答案,抄写错误产生错的参考答案。
  • 过滤修好了”题目对不对”,修不了”题目覆盖了什么”。 朴素流水线过滤后剩下的 75 道题全是建镇年份(唯一和镇名在同一个 chunk 里的属性);在这些题上 V0 胜过 V5(0.933 vs 0.880)—— 和真相相反。
  • 即使加了标题,“先随机挑 chunk、再随机挑事实”的出题方式也会过度代表只含一个事实的 chunk(export 79、founded 75,而 mayor 只有 37)。过滤后的集合把 V0 高估了约 0.04,把 V5 真实的 0.037 优势变成了平手。

合成评估集需要三件事:逐题验证;分层控制题目的构成;再拿一小份人工写的题对照,确认系统之间的排名没有被改变。

6.5 数据污染 · Contamination

If benchmark questions and answers leak into a model’s pre-training data, the benchmark measures memorization. 演示 3:一个 120 题的”公开”评估集的答案进了模型 llm-new 的预训练语料。

settingmodelpublicprivate-Qprivate-Fpublic − F
closed-bookllm-old0.2080.1380.130+0.078
closed-bookllm-new0.9070.3050.150+0.757
RAG, baseline promptllm-old0.6970.6870.640+0.057
RAG, baseline promptllm-new0.7750.7220.648+0.127

(private-Q:和公开集没有相同的题目;private-F:没有相同的事实。)

  • Even the clean model shows a public–private gap (+0.078 closed-book, +0.057 with RAG): the two sets simply differ in difficulty. Evidence of contamination is the difference in differences.
  • String-level deduplication is not enough: 21 private-Q questions ask about a leaked fact in different words, which lifts llm-new to 0.305 there. Deduplicate at the level of facts / semantics.
  • RAG masks most of the effect (+0.127 vs +0.057): answers mostly come from retrieval, memory only matters when retrieval fails. Contamination hurts closed-book benchmarks far more than RAG apps — but not zero.
  • 常见的防护:保留一个从不公开的私有集;按时间切分(只用模型训练截止之后的新内容);在公开数据里放 canary 字符串(BIG-bench 的做法),事后检查模型是否”背得出来”(Sainz et al. 2023 呼吁对每个 benchmark 测量污染)。

7. 评估驱动的开发循环 · The evaluation-driven development loop

7.1 The loop

Fall 2023 第 2 讲的 slide “Getting this right requires experimentation”:build an initial version → manually test and eyeball → iterate with prompts, parameters, fine-tuning;TruLens 填补的是”跟踪和评估实验”的工具空白。The workflow: instrument the app (retriever, LLM calls) → log traces → compute feedback functions on the spans → compare versions on a leaderboard → iterate. 2023 HW1 的三问正是这个循环:搭一个原型 RAG、初始化 triad 指标、用评估找出最好的配置。

同一讲的另一张 slide(Evaluation Pitfalls & Best Practices)列出了四个陷阱,每一个在本讲都有对应:

pitfall(slide)含义本讲
Overfitting to single examplesprompt engineering 只盯着几个例子,牺牲了整体§7.3 的 winner’s curse
Not testing performance periodicallybase model 在变,即使你的应用没变§1.2;上线后的监控
Not setting up comprehensive evaluations没有 ground truth 时只能”看几眼”§4–§6
Not evaluating intermediate steps只看最终回答§3 的 triad

7.2 A leaderboard

演示 4:24 个变体(检索器 bm25 / dense / hybrid × top-k 2–5 × prompt plain / strict),真实准确率 0.527–0.873(最好的是 hybrid k=3 strict),baseline(bm25 k=3 plain)0.644。在一个 60 题的 dev 集上每个变体跑一次,TruLens 式 leaderboard(前 8 名 + baseline):

rankvariantdev accCR^\hat{\text{CR}}G^\hat{\text{G}}AR^\hat{\text{AR}}ctx wordstrue acc
1hybrid k=5 strict0.9330.2700.8270.73961.10.855
2hybrid k=3 strict0.8830.3720.8290.75035.90.873
3hybrid k=4 strict0.8830.2760.7260.80048.50.859
4bm25 k=5 strict0.8670.3490.8110.82860.40.814
5hybrid k=2 strict0.8500.4890.8080.78324.00.865
6bm25 k=3 strict0.8330.4070.8210.67235.40.748
7hybrid k=4 plain0.8330.2900.6430.86148.50.750
8hybrid k=5 plain0.8170.2790.7780.81161.10.755
19bm25 k=3 plain (baseline)0.7000.4560.6820.80635.40.644

dev 上的第一名不是真正最好的(hybrid k=3 strict 用少 40% 的上下文得到更高的真实准确率)。在 540 题的 held-out 集上,第一名比 baseline 好 +0.233,95% CI [+0.186, +0.281](真实差距 0.211)—— 改进是真的,只是 dev 分数把它夸大了。A good leaderboard shows quality, diagnostics (the triad) and cost (context length, latency, tokens) side by side.

7.3 Statistical pitfalls

Winner’s curse, with a noise floor. 重复 300 次:抽一个 dev 集,24 个变体各跑一次,挑 dev 分数最高的。噪声地板:把中位数变体(hybrid k=4 plain,真实 0.750)复制 24 份,每份独立重跑(同样的题、不同的生成随机性),也挑最高的。

n_devdev acc of picktrue acc of pickoptimismregretnoise-floor optimism
300.9280.8410.0860.0320.129
600.9070.8570.0510.0160.088
1500.8910.8640.0280.0090.061
3000.8810.8660.0150.0060.041
  • 被挑中的变体的 dev 分数在 30 题时虚高 0.086、60 题时 0.051 —— 和第 1 讲 §8.2 是同一个效应,只是对象换成了 LLM 应用的变体。regret 小得多(0.032 → 0.006):挑选大体是对的,被夸大的是数字。
  • 噪声地板比真实的虚高还大:如果你的 24 个”改进”其实什么都没改,在 60 题上挑出来的那个也会显得高 0.088。真实的变体之间有好有坏,最大值多半落在真正好的那几个上,虚高反而小一些(练习 5 用期望最大值的公式解释 0.088 从哪来)。

Run-to-run variance. The same variant on the same 60 questions, rerun: standard deviation 0.042 from generation randomness alone; a fresh set of 60 questions each time: 0.063. A “+3 points” change on 60 questions is inside the noise of simply rerunning.

So the rules (they repeat L1 §8.2 because they matter more here, where variants are cheap and eval sets small):

  1. Compare on the same questions (paired), and average several runs per question when the generator is stochastic.
  2. Report intervals, and compare improvements with the noise floor of your selection procedure.
  3. Correct for multiple comparisons when you test many variants against a baseline (e.g. Bonferroni: with 23 comparisons, use α = 0.05/23 per test), or better, confirm only the final pick.
  4. Keep a test set that took no part in any selection, and use it once. Reusing a holdout adaptively overfits it too; Dwork et al. (2015, “The reusable holdout”) give a principled way to reuse one with limited, noisy access.
  5. Remember Goodhart (L1 §8.3): when the judge’s score becomes the target, verbose or self-styled outputs win. L16 optimizes prompts automatically against evaluation signals — every pitfall here gets amplified there.

8. 项目方法 · A project recipe

Fall 2023 第 6 讲给出了任何 “LLM for X” 项目的四步:

  1. Frame the task. What is the application, what functionality is needed, what are the inputs and outputs?
  2. Prompt / tune the model. Prompt design with few-shot examples; fine-tuning if you have training data; RAG for supplying relevant context.
  3. Evaluate the model. Gather evaluation datasets and define metrics — which the slide flags as tricky for generative tasks, because there may be no single correct output and you must first decide what a good response looks like.
  4. Assess reliability and trustworthiness. Grounding, confidence, interpretability, robustness.

Fall 2024 第 3 讲把项目组织成一张矩阵:行是应用领域(教育、医疗、安全……),列是可信维度(grounding、interpretability、confidence、consistency、alignment),“至少选一行、两列”。Autumn 2025 第 4 讲的项目示例(例如一个研究 Reddit 个人理财讨论的 agent)也都先写出评估指标:选中样本的相关性、对评论的排序能力、摘要相对于所用样本的准确性与完整性 —— 正是 triad 的三条边换了名字。

把本讲的方法装进第 3、4 步,一个最小的评估计划是:

项目内容
评估集100–300 道题,按切片分层(含无法回答、相近实体、换说法、过时 / 冲突文档);尽量有参考答案;一部分专家手写,一部分合成并逐题验证
指标有参考答案:contains / exact match 或 claim 级 precision–recall;检索:recall@k、MRR;triad 用于诊断;弃权单独报告;成本(token、延迟)
judge写 rubric + CoT;在 100–200 条人工标注上验证(κ、人与人天花板、按切片的混淆矩阵);先跑无标签的压力测试(长度、风格、顺序)
迭代dev / test 分开;配对比较;多次运行取平均;报告区间和噪声地板;最终数字只在 test 上测一次
上线reference-free 的 triad 监控 + 定期抽样人工标注(必要时用 PPI 合成估计);模型版本变化时重跑全部评估

9. 小结 · Summary

问题方法本讲的数字主要陷阱
失败发生在管线的哪一步?RAG triad,按管线顺序读五个版本各点亮一条边;三条边相乘 AUC 0.891triad 看不见过时的知识库(通过三条边的错误 100% 是过时存档);弃权在 AR 上记 0
每条边怎么打分?judge rubric、NLI、embedding、词重叠、参考答案词重叠放过 92% 的张冠李戴;有偏的 judge 把检索器排错embedding 衡量”像”不衡量”能回答”;F1 惩罚啰嗦;聚合方式是规范性选择
judge 可信吗?meta-eval、κ、人与人天花板、按切片、压力测试J-A κ 0.536 vs 人与人 0.797;stale 切片 κ ≈ 0.03总体一致率掩盖切片;swap 只修 position;κ 需要几百条标签
怎样修正 judge?协议、rubric、分层修正、PPIPPI 无偏;好 judge 下等效标签 ×1.7–2,坏 judge 下反而更宽只用 judge:窄而错的区间
评估集够好吗?切片、针对性搜索、合成 + 验证、防污染B ≥ 120 时 targeted 找到 2.4–3 倍失败;过滤后的合成集把排名弄反targeted 集合不代表分布;合成集覆盖面歪斜;字符串去重不够
迭代时有没有自欺?配对比较、重复运行、噪声地板、held-out60 题 dev 集:虚高 0.051,噪声地板 0.088,重跑 sd 0.042在小 dev 集上挑最大值;反复使用 test 集

Six takeaways:

  1. Evaluate the application, not just the model — and evaluate the intermediate steps, because the final answer hides where the failure happened.
  2. The triad is a diagnostic, not a correctness score. Each edge sees a different failure; none of them sees an outdated knowledge base; abstention needs its own accounting.
  3. Every feedback function is a measurement with its own failure modes. Lexical overlap is fooled by recombined words; embeddings by look-alikes; judges by topical similarity. Validate each against ground truth on a slice-aware sample.
  4. A judge is an instrument to be calibrated: compare with the human ceiling, break agreement down by slice, stress-test with label-free perturbations, and correct what remains (PPI) — in that order.
  5. Evaluation sets need design: slices, unanswerable questions, targeted search for weaknesses, validated synthetic items, and protection against contamination.
  6. Iterating against small eval sets inflates scores. Pair, repeat, compare against a noise floor, and keep a clean test set.

10. 常见误区 · Common pitfalls

  • “Our triad scores are all high, so the app doesn’t hallucinate.” Only up to the limits of the knowledge base: grounded answers can quote outdated or conflicting documents (§3.3).
  • “Context relevance went from 0.30 to 0.25 when we increased k, so retrieval got worse.” CR is a precision; it falls as kk grows even when recall rises (§3.2, 练习 1).
  • “The answer-relevance score is 0.95, so the answers are good.” AR measures being on topic, not being right; it is highest for the never-abstaining fabricator (§3.2, §4.4).
  • “Embedding similarity is a cheap relevance judge.” It measures resemblance; unattributed sentences can outscore truly relevant chunks (§4.2).
  • “Our judge agrees with humans 78% of the time.” Compare with human–human agreement, report κ, and break it down by slice — that is where self-preference, verbosity and blind spots show up (§5.3).
  • “We swap positions, so the pairwise judge is unbiased.” Swapping fixes position bias only (§5.4).
  • “We validated the judge on 30 examples: κ = 0.8.” With 25 labels, κ estimates span 0.26–0.80 for a judge whose true κ is 0.54 (§5.5).
  • “The adversarial set shows 70% errors, so the system is bad.” Targeted sets are built to find failures; they do not estimate deployment error (§6.3).
  • “We filtered the synthetic questions, so the set is clean.” Clean items, skewed coverage: the filtered set can reverse rankings (§6.4).
  • “Variant 17 beats the baseline by 5 points on our 60-question dev set.” The noise floor of picking the best of 24 is 8.8 points there (§7.3).

11. 练习 · Exercises

练习 1(CR 是一个 precision). 一个问题只有一个 chunk 含答案。(a) 检索器 A 用 k=3k = 3 检索到了它,检索器 B 用 k=5k = 5 也检索到了它。两者的 CR 各是多少?(b) 再定义一个 “context recall” = 含答案的 chunk 是否在上下文里。两个检索器的 recall 是多少?(c) 为什么 §3.2 里 V0 的 CR 只有 0.23,而 §2.3 里同样配置的 recall 是 0.77?(d) 比较不同 kk 的版本时应该报告什么?

参考答案

(a) A:1/3 ≈ 0.33;B:1/5 = 0.20。(b) 都是 1。(c) CR 的分母是 k=3k = 3,而大多数问题只有一个相关 chunk(stale 切片可能有两个:当前值和旧值),所以检索成功时 CR 也只有 1/3,检索失败时是 0;平均下来约 0.77 × 1/3 ≈ 0.26,再加上少数有两个相关 chunk 的题、减去 recall 失败的题,就是 0.23 左右。(d) 同时报告 precision 型(CR)和 recall 型(recall@k、MRR)指标;kk 不同时只比较 recall 型指标和端到端准确率,并报告上下文长度(成本)。CR 的价值在于发现”塞进了大量无关内容”,比如 V6(k = 5)的 CR^\hat{\text{CR}} 从 0.425 降到 0.352。

练习 2(noisy-OR 聚合). A sentence is scored against kk snippets, each giving a weak entailment score sij=ss_{ij} = s. (a) Write sis_i as a function of ss and kk. (b) With s=0.2s = 0.2, how many snippets are needed for si≥0.5s_i \ge 0.5? (c) What does this imply for groundedness scores as kk grows, and what aggregation over snippets would avoid it?

参考答案

(a) si=1−(1−s)ks_i = 1 - (1 - s)^k。(b) (0.8)k≤0.5⇒k≥ln⁡0.5/ln⁡0.8≈3.1(0.8)^k \le 0.5 \Rightarrow k \ge \ln 0.5 / \ln 0.8 \approx 3.1,所以 4 个 snippet。(c) noisy-OR 把多个弱证据累积成一个强结论 —— 如果这些弱分数是 NLI 模型在无关段落上的噪声,k 越大,没有依据的句子越容易”通过”。noisy-OR 隐含的假设是各 snippet 的证据相互独立,但同一个错误的 claim 往往对多个相似段落给出相关的弱分数。替代方案:取 max⁡jsij\max_j s_{ij}(“至少有一个 snippet 强支持”),或者把阈值随 kk 调整;也可以像 slides 建议的那样,在单个 snippet 都不够时再考虑 snippet 的组合。本讲的模拟里无关 snippet 的分数只有 0–0.05,所以这个效应很小;真实的 NLI 模型未必如此。

练习 3(κ 的直觉). 一个 meta-eval 集有 200 条,人工标为 acceptable 的有 160 条。(a) 一个永远说 yes 的 judge,一致率和 κ 各是多少?(b) 另一个 judge 的混淆矩阵(以人工为准):TP = 150,FN = 10,FP = 20,TN = 20。算一致率和 κ。(c) 为什么 (b) 的一致率很高、κ 却只是”中等”?这个 judge 的哪类错误最多?

参考答案

(a) 一致率 0.80;pe=1×0.8+0×0.2=0.8p_e = 1 \times 0.8 + 0 \times 0.2 = 0.8,κ = (0.8 − 0.8)/(1 − 0.8) = 0。(b) po=170/200=0.85p_o = 170/200 = 0.85;judge 说 yes 的比例 170/200 = 0.85,人工 0.80;pe=0.85×0.8+0.15×0.2=0.68+0.03=0.71p_e = 0.85 \times 0.8 + 0.15 \times 0.2 = 0.68 + 0.03 = 0.71;κ = (0.85 − 0.71)/(1 − 0.71) = 0.14/0.29 ≈ 0.48。(c) 正例占 80%,“碰巧一致”的基线就很高,一致率的大部分来自基线。这个 judge 的 FPR = 20/40 = 0.5 —— 不可接受的回答它放过了一半,而这正是评估最关心的那一半。所以除了 κ,还要看 FPR(以及按切片的 FPR)。

练习 4(两个顺序都赢才算赢). 一个 pairwise judge 在两个回答质量相同时以概率 pp 选第一个,两次调用相互独立。(a) 用 Zheng et al. 的协议(交换顺序各问一次,一致才算赢),A 赢、B 赢、平局的概率各是多少?(b) p=0.656p = 0.656(§5.4 的 J-A)时代入。(c) 如果 A 其实更好、judge 不论顺序都以 0.7 的概率选 A、再叠加同样的位置偏向,这个协议还能看出 A 更好吗?

参考答案

(a) A 赢 = 第一次(A 在前)选了第一个,第二次(B 在前)选了第二个:p(1−p)p(1 - p);B 赢同理 p(1−p)p(1-p);平局 p2+(1−p)2p^2 + (1 - p)^2。(b) A 赢 = B 赢 = 0.656 × 0.344 ≈ 0.226,平局 ≈ 0.430 + 0.118 = 0.548。质量相同时这个协议是对称的 —— position bias 被消掉了,代价是一半以上的比较变成平局。(c) 一个简单的模型:A 在前时选 A 的概率 p1>0.7p_1 > 0.7,B 在前时选 A 的概率 p2<0.7p_2 < 0.7(例如在 logit 上加减同一个偏移)。A 赢 = p1⋅p2p_1 \cdot p_2,B 赢 = (1−p1)(1−p2)(1 - p_1)(1 - p_2)。只要 p1,p2>0.5p_1, p_2 > 0.5,A 赢的概率就大于 B 赢,所以方向还看得出来,只是有效样本变少了。但如果偏差不是位置而是 self-preference 或 verbosity(§5.4 的 J-A 对 A2),交换顺序完全不起作用。

练习 5(噪声地板从哪里来). §7.3 测得 baseline 在同一组 60 题上重跑的标准差是 0.042;假设中位数变体(真实准确率 0.750)也差不多。(a) 如果 24 个”完全相同”的变体的 dev 分数近似独立、同分布于 N(0.75,0.0422)\mathcal{N}(0.75, 0.042^2),被挑中者的期望虚高是多少?(提示:24 个独立标准正态的最大值的期望约为 1.95。)(b) 和表中的 0.088 比较。(c) 为什么真实的 24 个变体的虚高(0.051)反而更小?

参考答案

(a) 1.95×0.042≈0.0821.95 \times 0.042 \approx 0.082。(b) 和实测的 0.088 很接近。剩下的差别可能来自:0.042 是用 baseline 估计的(准确率不同,二项分布的方差也不同);每题只有 6 个预先算好的运行结果可以重抽;正态近似本身也不精确。(c) 真实变体的准确率分布很宽(0.527–0.873),dev 分数的最大值大多落在少数真正好的变体上;它们之间的差距比噪声大,“靠运气胜出”的空间就小。这和第 1 讲练习 4 的道理一样:候选越接近、越多,虚高越严重。实践中的含义:如果你的改动都很小(真实差别 < 噪声),dev 上的”冠军”几乎完全是噪声挑出来的。

练习 6(PPI 什么时候帮倒忙). 设真实可接受率 θ=0.32\theta = 0.32,judge 的 TPR = 0.92、FPR = 0.55(一个被长回答严重骗过的 judge,类似 §5.6 的 J-A 在 A2 上)。(a) judge 说 yes 的比例是多少?只用 judge 的估计偏多少?(b) 计算 Var(h−j)\text{Var}(h - j) 和 Var(h)\text{Var}(h)。(c) 忽略 NN 那一项(NN 很大),PPI 的方差比只用人工标签大还是小?(d) 如果 FPR 降到 0.10 呢?

参考答案

(a) P(j=1)=0.92×0.32+0.55×0.68=0.294+0.374=0.668P(j = 1) = 0.92 \times 0.32 + 0.55 \times 0.68 = 0.294 + 0.374 = 0.668,偏高 0.348(和 §5.6 表中 J-A 的 +0.350 一致)。(b) h−jh - j 取 +1(h=1,j=0h = 1, j = 0)的概率 0.32×0.08=0.02560.32 \times 0.08 = 0.0256,取 −1(h=0,j=1h = 0, j = 1)的概率 0.68×0.55=0.3740.68 \times 0.55 = 0.374。均值 =−0.348= -0.348,E[(h−j)2]=0.3996E[(h-j)^2] = 0.3996,方差 =0.3996−0.121=0.278= 0.3996 - 0.121 = 0.278。Var(h)=0.32×0.68=0.218\text{Var}(h) = 0.32 \times 0.68 = 0.218。(c) PPI 的方差约 0.278/n0.278/n,比只用人工的 0.218/n0.218/n 大约 28%,区间宽约 13%(§5.6:0.288 vs 0.260,宽 11%)。(d) FPR = 0.10:P(h=0,j=1)=0.068P(h=0, j=1) = 0.068,P(h=1,j=0)=0.0256P(h=1, j=0) = 0.0256,均值 −0.042,E[(h−j)2]=0.094E[(h-j)^2] = 0.094,方差 ≈ 0.092,远小于 0.218 —— PPI 的等效样本量约为人工标签的 2.4 倍。结论:PPI 的收益取决于 judge 的错误率;先验证、再修正。

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


12. 延伸阅读 · Further reading

本讲的主要来源

  • CS329T slides:Fall 2023 Lecture 2(Build, Evaluate, Iterate on LLM Apps)、Lecture 6(Project Design and Planning)、Lecture 9(Grounding)、HW1 intro;Fall 2024 Lectures 2–4;Autumn 2025 Lectures 1, 2, 4, 7 与 HW1。
  • Kenthapadi, Sameki & Taly, “Grounding and Evaluation for Large Language Models: Practical Challenges and Lessons Learned (Survey)”, KDD 2024 tutorial.
  • TruLens 文档(RAG triad、feedback functions);LlamaIndex 文档(evaluation modules)。

RAG

  • Lewis et al., “Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks”, NeurIPS 2020.
  • Robertson & Zaragoza, “The Probabilistic Relevance Framework: BM25 and Beyond”, 2009;Cormack, Clarke & Büttcher, “Reciprocal Rank Fusion…”, SIGIR 2009.
  • Barnett et al., “Seven Failure Points When Engineering a Retrieval Augmented Generation System”, 2024.
  • Liu et al., “Lost in the Middle: How Language Models Use Long Contexts”, TACL 2024;Shi et al., “Large Language Models Can Be Easily Distracted by Irrelevant Context”, ICML 2023;Chen et al., “Dense X Retrieval: What Retrieval Granularity Should We Use?”, 2023.

RAG evaluation

  • Es et al., “RAGAs: Automated Evaluation of Retrieval Augmented Generation”, EACL 2024 (demos).
  • Saad-Falcon, Khattab, Potts & Zaharia, “ARES: An Automated Evaluation Framework for Retrieval-Augmented Generation Systems”, NAACL 2024.
  • Rashkin et al., “Measuring Attribution in Natural Language Generation Models”, Computational Linguistics 2023;Honovich et al., “TRUE: Re-evaluating Factual Consistency Evaluation”, NAACL 2022(第 12 讲详细讲)。

LLM-as-a-judge

  • Zheng et al., “Judging LLM-as-a-Judge with MT-Bench and Chatbot Arena”, NeurIPS 2023 (Datasets & Benchmarks).
  • Liu et al., “G-Eval: NLG Evaluation using GPT-4 with Better Human Alignment”, EMNLP 2023;Kim et al., “Prometheus: Inducing Fine-grained Evaluation Capability in Language Models”, ICLR 2024.
  • Wang et al., “Large Language Models are not Fair Evaluators”, 2023;Panickssery, Bowman & Feng, “LLM Evaluators Recognize and Favor Their Own Generations”, NeurIPS 2024;Dubois et al., “Length-Controlled AlpacaEval: A Simple Way to Debias Automatic Evaluators”, 2024.
  • Shankar et al., “Who Validates the Validators? Aligning LLM-Assisted Evaluation of LLM Outputs with Human Preferences”, UIST 2024.
  • Angelopoulos et al., “Prediction-Powered Inference”, Science 2023;Angelopoulos, Duchi & Zrnic, “PPI++: Efficient Prediction-Powered Inference”, 2023.
  • Cohen, “A Coefficient of Agreement for Nominal Scales”, 1960;Landis & Koch, 1977.

Evaluation sets

  • Li, Kaiyom, Liu, Mai, Liang & Hashimoto, “AutoBencher: Towards Declarative Benchmark Construction”, ICLR 2025;Li et al., “Benchmarking and Improving Generator-Validator Consistency of Language Models”, ICLR 2024.
  • Sainz et al., “NLP Evaluation in Trouble: On the Need to Measure LLM Data Contamination for Each Benchmark”, Findings of EMNLP 2023.
  • Dwork et al., “The Reusable Holdout: Preserving Validity in Adaptive Data Analysis”, Science 2015.

Autumn 2025 第 2 讲的阅读材料

  • Schulhoff et al., “The Prompt Report: A Systematic Survey of Prompting Techniques”, 2024;Ji et al., “Survey of Hallucination in Natural Language Generation”, ACM Computing Surveys 2023.

13. 下一讲预告 · Next lecture

Lecture 12:Grounding、事实性与幻觉(Grounding, Factuality & Hallucination)。

本讲把 groundedness 当作 triad 的一条边,用一个”claim 级 NLI + noisy-OR”的简化版本实现它,并看到了它的几种失败:改写过的 claim 被漏判、近似的名字骗过 NLI、过时的上下文让”有依据”不等于”正确”。第 12 讲专门讲这一条边:幻觉的分类;“可归因”(AIS)的定义;把回答拆成 claim、去上下文化(decontextualization)、用 NLI 核对(TRUE);不依赖检索的检测方法 —— 采样一致性(SelfCheckGPT)和模型内部状态;以及检测到之后怎么修:检索–改写(RARR)、拒答、guardrails 的设计与代价。

← 返回课程目录