LLM 怎么评估?perplexity、benchmark、
LLM-as-a-judge、human eval 各管什么?
先弄清楚:每个概念是什么
- Perplexity
- 模型在每个真实 token 上,平均相当于在几个选项里犹豫。越小越好,全猜对是 1,在 \(V\) 个词里瞎猜就是 \(V\)。例:4 个 token 拿到的概率是 0.5、0.25、0.5、0.125 → PPL ≈ 3.36。
- BLEU / ROUGE
- 拿 reference 逐个 n-gram 对照。BLEU 是 1–4 gram 的 clipped precision 取几何平均,再乘 brevity penalty \(\min(1, e^{1-r/c})\),用于翻译。ROUGE-N 是 n-gram recall,用于摘要。换了说法也会扣分,所以不适合开放式回答。
- LLM-as-a-judge
- 请一个强模型当阅卷老师,便宜、快,但有 bias。pairwise 更稳,但模型多时对数按平方增长。单独打 1–10 分容易扩展,但分不出细微差别。
- Contamination
- benchmark 的题混进了 pretraining data,像考前背过原题,分数虚高。
30 秒回答
It depends on what we measure. For a base model I'd report perplexity, the exponential of the average per-token negative log-likelihood on held-out text, comparable only under the same tokenizer. With ground truth I'd use benchmarks: accuracy or exact match on MMLU and GSM8K, and pass@k with unit tests for code. Open-ended answers have no single reference, so BLEU and ROUGE work poorly; there I'd use pairwise human preference, aggregated with Elo or Bradley-Terry, or an LLM judge calibrated against human labels, with answer order swapped to cancel position bias. I'd check contamination with n-gram overlap and confirm with an online A/B test.
评什么用什么
| 评什么 | 用什么 | 坑 |
|---|---|---|
| base model | held-out perplexity | 只能同 tokenizer 比;PPL 低 ≠ 会做任务 |
| 有标准答案 | MMLU(accuracy)、GSM8K(exact match)、HumanEval(pass@k) | contamination、分数饱和 |
| 翻译、摘要 | BLEU、ROUGE | 只看字面重合 |
| 开放式回答 | LLM-as-a-judge(MT-Bench) | position、verbosity、self-enhancement bias |
| 真实偏好 | human pairwise(Chatbot Arena),见 标注规范 | 贵、慢、众包有噪声 |
| 上线效果 | A/B test:点赞率、acceptance rate | 要流量 |
推导 / 关键公式
Perplexity
\[ \mathrm{PPL} = \exp\Big(-\frac1n\sum_{t=1}^{n}\log p(x_t\mid x_{<t})\Big) \]平均 cross-entropy 取 exp,也就是每个 token 概率倒数的几何平均。上面的例子:
\[ \mathrm{PPL} = (2\cdot 4\cdot 2\cdot 8)^{1/4} = 128^{1/4} \approx 3.36 \]Elo 与 Bradley-Terry
\[ P(A \succ B) = \frac{1}{1+10^{(R_B-R_A)/400}} \]高 100 分对应预期胜率 64%,高 400 分对应 91%。Elo 每场后在线更新 \(R_A \leftarrow R_A + K(S_A - E_A)\),结果受对战顺序影响。Arena 后来改用 Bradley-Terry,同样的 logistic 形式,用全部对战做 MLE(就是一个 logistic regression)。
LLM judge 的 bias 和对策
- position:偏向某个位置。交换两份回答的顺序,GPT-4 只有 65% 判断不变。→ 两种顺序各判一次,都赢才算赢,否则算 tie。
- verbosity:偏向长的。把列表换个说法再重复一遍,Claude-v1 和 GPT-3.5 有 91% 判"变好了",GPT-4 是 8.7%。
- self-enhancement:偏向自己写的。→ 用别家模型当 judge,或多个 judge 投票。
- 数学判不准:被候选答案带偏。→ 先让 judge 自己解题当 reference,判错率从 70% 降到 15%。
上线前抽一批人工标注算 agreement。MT-Bench 上 GPT-4 和专家的 agreement 是 85%,专家之间是 81%。
Contamination 怎么查
GPT-3 把和训练集有 13-gram 重合的测试题标为"脏",去掉后得到 clean subset。clean subset 上分数明显更低,就说明被污染抬高了。拿不到训练数据时,用新出的题(live benchmark)或改写题目。
必答点
- 先问评什么:base model → perplexity;有标准答案 → benchmark;开放式 → human / LLM judge;上线 → A/B test
- PPL \(= \exp(\)平均 NLL\()\),只能同 tokenizer 比
- LLM judge 的 position / verbosity / self-enhancement bias,对策:交换顺序、reference、用人工标注 calibrate
- Chatbot Arena:匿名 pairwise 投票 → Elo / Bradley-Terry
- contamination:n-gram overlap 检测,clean subset 重评
追问
两个模型的 perplexity 能直接比吗?
tokenizer 不同就不能。PPL 按 token 平均,切得粗的模型每个 token 信息多,PPL 偏高。要比就按字节归一化(bits per byte)。
pass@k 怎么算?
每题生成 \(n \ge k\) 个样本,\(c\) 个通过 unit test,unbiased 估计 \(1 - \binom{n-c}{k}/\binom{n}{k}\)。例:\(n = 10\)、\(c = 3\):pass@1 = 0.3,pass@5 ≈ 0.92。直接用 \(1-(1-\hat p)^k\) 是有偏的。
来源d2l §9.3.2 eq. 9.3.7–9.3.8 · Zheng et al. 2023, MT-Bench §3.1、§3.3 Table 2–3(pp.4–5)、§3.4 Table 4(pp.5–6)、§4.2(p.7)· Chiang et al. 2024, Chatbot Arena §4 eq. 2(p.4)、§6.3(p.7)· LMSYS blog 2023(Elo)· Brown et al. 2020, GPT-3 §4(pp.29–31)· Chen et al. 2021, Codex §2.1 eq. 1(p.3)· Papineni et al. 2002, BLEU §2(pp.312–315)· Lin 2004, ROUGE §2