--- type: reference tags: - llm-evaluation - evaluation-guidebook - llm-as-judge status: active created: 2026-08-21 source: https://github.com/huggingface/evaluation-guidebook --- # LLM-as-a-Judge:模型作评委 > 本笔记是 [HuggingFace Evaluation Guidebook](https://github.com/huggingface/evaluation-guidebook) 中 **Model-as-a-Judge** 章节(共 6 页)的中文提炼。核心问题:**如何用一个模型来评价另一个模型的输出?** 适合在设计评测、选择评委模型、写 judge prompt、或搭建基于 reward model 的评测管线时查阅。 > > 相关笔记:[[00-Overview]](总览与阅读顺序) --- ## 1. 什么是 judge model / judge LLM ### 1.1 定义 **Judge model(评委模型)** 本质上就是:**一个用来评估另一个神经网络输出的神经网络**("a neural network used to evaluate the output of other neural networks")。绝大多数情况下,它评估的是文本生成结果。 Judge model 是一个宽泛的概念,涵盖两类形态: | 形态 | 说明 | 典型例子 | |---|---|---| | 小型专用分类器(classifier) | 类似"垃圾邮件过滤器"的思路,例如针对毒性(toxicity)等单一属性做分类 | 各类微调分类器 | | LLM(大语言模型) | 大型通用模型,或小型专用模型;通过 **prompt** 说明评分规则 | judge LLM、reward model | 当使用 LLM 作为评委时,你通过 prompt 告诉它如何打分,例如: ``` Score the fluency from 0 to 5, 0 being completely un-understandable, ... ``` (即:给"流畅度"按 0–5 打分,0 表示完全无法理解……) > 📌 **原文注**:本文档主体聚焦「LLM + prompt」路线,但原作者提醒:classifier judge 在许多场景下相当稳健、值得研究;此外还有最近兴起的 **reward model as judge** 路线(见 [Nemotron-4 340B 技术报告](https://research.nvidia.com/publication/2024-06_nemotron-4-340b) 与本书对应小节 [[#7. Reward Models(奖励模型)|What about reward models]])。 ### 1.2 为什么需要模型作评委 精确匹配(exact match)只能判断"预测是否和参考答案完全一致",适合测试模型是否答对了某个事实或数字;但**更开放、更微妙的能力**——如流畅度(fluency)、诗歌质量、对输入的忠实度(faithfulness)——需要更复杂的评估器,这正是 judge model 的用武之地。 ### 1.3 三大主要用途 | # | 用途 | 英文术语 | 说明 | |---|---|---|---| | 1 | **对生成结果打分** | Scoring a model generation(pointwise) | 在给定刻度(scale)上评估文本的某个属性:流畅度、毒性、连贯性、说服力等 | | 2 | **成对比较** | Pairwise scoring | 给定一对模型输出,选出在某个属性上更好的那个 | | 3 | **计算相似度** | Computing the similarity | 计算模型输出与参考答案(reference)之间的相似度 | ### 1.4 术语对照表(速查) | 英文术语 | 中文译法 | 一句话含义 | |---|---|---| | judge LLM / model-as-a-judge | 模型作评委 | 用 LLM 评估另一个模型输出 | | pointwise scoring | 点式打分 | 对单个输出按刻度打分 | | pairwise scoring | 成对比较 | 在两个输出中选更好者 | | preference | 偏好 | 人类/模型对"哪个输出更好"的判断 | | preference data | 偏好数据 | 用于训练评委/奖励模型的数据 | | scoring prompt | 打分 prompt | 说明评分规则的评测指令 | | scoring anchor | 评分锚点 | 刻度上每个分数代表什么的具体解释 | | additive prompt | 累加式评分 prompt | 逐项加分的打分方式 | | reasoning / CoT | 推理 / 思维链 | 先输出推理再给分数的做法 | | reference | 参考答案 | 用于对照的已知正确答案 | | few-shot | 少样本示例 | 在 prompt 中给若干示例 | | jury | 陪审团 | 多个评委聚合判断 | | baseline | 基线 | 用于对照评判质量的标准 | | inter-annotator agreement | 标注者间一致性 | 多个标注者判断的一致性指标 | | reward model (RM) | 奖励模型 | 从人类标注学习打分的模型 | | Bradley-Terry model | Bradley-Terry 模型 | 基于成对比较输出单分数的 RM | | win rate | 胜率 | 高于参考输出的百分比 | | win probability | 胜率概率 | 优于参考输出的平均概率 | | positional bias | 位置偏差 | 偏好特定答案位置的偏见 | | verbosity bias / length bias | 冗长偏差 / 长度偏差 | 偏爱更长更啰嗦答案的偏见 | | self-preference | 自偏好 | 偏爱自己输出的偏见 | | format bias | 格式偏差 | 对偏离训练格式失准的偏见 | | self-consistency | 自洽性投票 | 多次采样取多数票 | | partial hallucination | 部分幻觉 | 接近真值但略有出入的幻觉 | | faithfulness | 忠实度 | 输出对输入/事实的忠实程度 | --- ## 2. 使用 judge LLM 的优缺点 ### 2.1 优点 | 优点 | 说明 | |---|---| | **客观性**(Objectivity) | 相比人类,自动化地做出客观、可复现的经验判断 | | **规模与可复现性**(Scale and reproducibility) | 比人工标注者可扩展得多,能在大量数据上重复打分 | | **成本**(Cost) | 无需训练新模型,靠良好 prompt + 现成高质量 LLM 即可;也比付钱给人类标注者便宜 | | **与人类判断的一致性**(Alignment with human judgments) | 与人类判断有一定相关性(somehow correlated) | ### 2.2 缺点(对应着看) | 缺点 | 说明 | |---|---| | **隐藏偏见**(hidden biases) | LLM 评委看起来客观,但带有许多隐藏偏见,且比人类的偏见更难被发现——因为我们不会主动去审视它。详见 [[#8. Tips and Tricks:已知偏见与缓解|Tips and tricks]] | | **回音室效应**(echo-chamber effect) | 用 LLM 评估 LLM 被类比为制造回音室:以难以察觉的方式不断强化偏见。另外,社会学家用约一个世纪研究出"如何设计统计上稳健的调查问卷来减少人类偏见",而 LLM prompt 设计还没有这么成熟 | | **产生海量待检数据** | 可扩展的同时也制造了大量人工数据,这些数据本身又需要被检验质量(例如让评委先生成思维痕迹/推理过程来提高质量,但这又产生了更多待分析的人工数据) | | **专家质量** | 评委很便宜,但为你的具体场景付费请专家人工标注者,大概率能获得质量更好的结果 | --- ## 3. 如何开始(⭐ 推荐资源) - ⭐ **入门必读**:[HuggingFace Cookbook:LLM as a judge](https://huggingface.co/learn/cookbook/en/llm_judge),作者 Aymeric Roucher,手把手教你搭第一个 LLM 评委。 - **[distilabel](https://distilabel.argilla.io/latest/)**(Argilla 出品的库):可用 LLM 生成合成数据并迭代更新。有两个值得参考的 tutorial: - [UltraFeedback 方法复现 tutorial](https://distilabel.argilla.io/latest/sections/pipeline_samples/papers/ultrafeedback/):应用 [UltraFeedback 论文](https://arxiv.org/abs/2310.01377) 的方法论。 - [用 distilabel 做 benchmarking 的 tutorial](https://distilabel.argilla.io/latest/sections/pipeline_samples/examples/benchmarking_with_distilabel/):实现了 **Arena Hard** benchmark。 --- ## 4. 如何获取 judge LLM 原文给出三条路线:用现成通用大模型、用小型专用 judge 模型、自己训练。三者对比如下: | 维度 | 通用大模型(generalist) | 小型专用模型(tiny specialized) | 自己训练 | |---|---|---|---| | 典型代表 | Claude / GPT-o;开源侧 Qwen 2.5、Command R+、Llama 3.1-405B | Flow-Judge-v0.1、Prometheus、JudgeLM | 基于偏好数据自建 | | 参数规模 | 大(数十亿 ~ 数千亿) | 通常几十亿(3.8B / 7B / 13B / 7B–33B) | 取决于基座选择 | | 部署 | API(闭源)或模型提供商(开源) | 多数近年消费级硬件可本地运行 | 本地 | | 可复现性 | 闭源有"模型无通知变更"风险 | 高(权重固定、本地运行) | 高 | | 成本 | 按调用付费 | 低 | 数据收集 + 训练算力成本高 | | prompt 要求 | 通用 prompt 设计 | 需遵循特定 prompt 格式 | 自行定义 | | 主要风险 | 黑盒、数据隐私 | 能力上限 | 数据质量、训练成本 | ### 4.1 路线一:使用通用大模型(generalist LLM) 随着更强模型(如 ChatGPT)出现,研究者开始探索用大模型当评委。目前最强的大模型评委**多为闭源模型**(如 Claude、GPT-o 系列),但开源模型的差距正在快速缩小——高质量开源候选包括: - [Qwen 2.5 系列](https://huggingface.co/collections/Qwen/qwen25-66e81a666513e518adb90d9e) - [Command R+](https://huggingface.co/CohereForAI/c4ai-command-r-plus-08-2024) - [Llama 3.1-405B-Instruct](https://huggingface.co/meta-llama/Llama-3.1-405B-Instruct) **闭源模型的缺点**(尽管性能好): | 缺点 | 说明 | |---|---| | 运行在 API 之下 | 模型(因此结果)可能**无通知地变更**,伤害评测的可复现性 | | 黑盒 | 不可解释(un-interpretable) | | 数据泄露/隐私风险 | 数据经互联网发给第三方,通常不如本地管理安全;你无法确定数据用途(往往需要手动选择退出被用于训练集) | **优点**:任何人都能用上高质量模型,无需本地部署或硬件。而如今大多数高质量开源模型也能通过模型提供商访问,同时解决了上面两个问题(API 变更与黑盒)。 > 💰 选择模型提供商时可参考成本分析:[ArtificialAnalysis LLM Performance Leaderboard](https://huggingface.co/spaces/ArtificialAnalysis/LLM-Performance-Leaderboard)。 ### 4.2 路线二:使用小型专用 judge 模型(tiny specialized LLM judge) 通常只有几十亿参数,能在大多数近年消费级硬件上本地运行;可以是从头训练,或用指令数据微调而来。**注意通常需要遵循它们特定的 prompt 格式。** 原文给出的现有模型: | 模型 | 参数规模 | 说明 | |---|---|---| | **Flow-Judge-v0.1**([权重](https://huggingface.co/collections/flowaicom/flow-judge-v01-66e6af5fc3b3a128bde07dec)) | 3.8B | 基于 Phi-3.5-mini-instruct,在合成偏好数据集上微调 | | **Prometheus**([权重](https://huggingface.co/prometheus-eval/prometheus-13b-v1.0),[论文](https://arxiv.org/abs/2310.08491)) | 13B | 在合成偏好数据集上从头训练。另有 [7B 的 v2](https://huggingface.co/prometheus-eval/prometheus-7b-v2.0):基于 Mistral-7B-Instruct-v0.2 在更大的合成偏好数据集上微调,并加入权重合并(weight merging) | | **JudgeLM**([论文](https://arxiv.org/abs/2310.17631)) | 7B ~ 33B | 在多种模型生成的合成偏好数据集上从头训练 | ### 4.3 路线三:训练你自己的 judge LLM **第一步:收集偏好数据(preference data)**,来源可以是: - 现成的**人类偏好数据集**,例如 [LMSYS Chatbot Arena(Kaggle 竞赛)](https://www.kaggle.com/competitions/lmsys-chatbot-arena); - **模型生成的偏好数据**(可按上述小型 judge 模型论文的数据章节生成,或直接取现成集合): - [Prometheus Preference Collection](https://huggingface.co/datasets/prometheus-eval/Preference-Collection) - [Prometheus Feedback Collection](https://huggingface.co/datasets/prometheus-eval/Feedback-Collection) **第二步:决定起点**,可以选择: 1. 从零开始,用一个小模型**从头训练(train from scratch)**; 2. 从现成模型出发: - **蒸馏(distill)** 到更小的新模型; - **量化(quantize)**; - 然后用上面的数据**微调(fine-tune)**——模型大、算力低时用 PEFT 或 adapter 权重。 - 💡 一个社区经验:[从 reward model 出发微调,比从 instruct model 出发效果更好](https://x.com/dk21/status/1826292289930674590)。 --- ## 5. 如何设计评测 prompt(evaluation prompt) ### 5.1 通用设计要点 设计 prompt 的四条通用准则(原文整理自网络): 1. **清晰描述任务**: - `Your task is to do X`(你的任务是做 X) - `You will be provided with Y`(你将获得 Y) 2. **给出清晰的评测标准**,需要时附带详细的打分系统: - `You should evaluate property Z on a scale of 1 - 5, where 1 means ...`(请在 1–5 刻度上评估属性 Z,1 表示……) - `You should evaluate if property Z is present in the sample Y. Property Z is present if ...`(请评估样本 Y 中是否存在属性 Z。属性 Z 存在当且仅当……) 3. **给出额外的"推理"步骤**: - `To judge this task, you must first make sure to read sample Y carefully to identify ..., then ...`(评判前必须先仔细阅读样本 Y 以识别……,然后……) 4. **指定输出格式**(加字段有助于一致性): - `Your answer should be provided in JSON, with the following format {"Score": Your score, "Reasoning": The reasoning which led you to this score}`(用 JSON 输出:{"Score": 你的分数, "Reasoning": 得出该分数的推理}) 可以直接借鉴的现成模板: - [MixEval judge prompts(lighteval 实现)](https://github.com/huggingface/lighteval/blob/main/src/lighteval/tasks/extended/mix_eval/judge_prompts.pyy) - [MTBench judge prompt templates(lighteval 实现)](https://github.com/huggingface/lighteval/blob/main/src/lighteval/tasks/extended/mt_bench/judge_prompt_templates.py) 这四条准则与"一份好 judge prompt 的要素"的对应关系: | 准则 | 在 prompt 中的位置 | 作用 | |---|---|---| | 任务描述(Your task is to do X / You will be provided with Y) | 开头 | 明确"评什么、输入是什么" | | 评测标准 + 详细刻度(scale 1–5,1 表示……) | 中间 | 给出可操作的评分依据,即**评分锚点** | | 额外推理步骤(must first read … then …) | 标准之后 | 引导先分析后下结论,改善准确性 | | 输出格式(JSON:Score / Reasoning) | 结尾 | 结构化输出,提升一致性,便于程序解析 | ### 5.2 其他设计要点 - **Pairwise(成对比较)比打分更稳健**:与人类偏好的相关性更高([论文](https://arxiv.org/abs/2403.16950))。 - 如果确实需要分数,**用整数刻度**,并确保**详细解释每个分数代表什么**([Seungone Kim 的推文](https://x.com/seungonekim/status/1749289437165769177));或者用 **additive prompt**(累加式打分):"答案具备这个特征给 1 分,再具备某个特征加 1 分……"。 - **每个能力用一个 prompt 单独打分**,结果通常更好、更稳健(one prompt per capability)。 ### 5.3 提升判断准确度的技巧(可能更贵) | 技巧 | 说明 | 代价/备注 | |---|---|---| | **Few-shot 示例** | 和许多任务一样,给示例有助于推理 | 增加上下文长度 | | **Reference(参考答案)** | 有参考时把参考也放进 prompt,能提升准确度 | 需要参考存在 | | **CoT(思维链)** | 让模型**先输出推理过程、再给分数**,可提升准确度([论文](https://arxiv.org/abs/2212.08073),另有 [观察](https://x.com/seungonekim/status/1749289437165769177)) | 输出变长 | | **多轮分析(Multiturn analysis)** | 可改进**事实性错误检测**([论文](https://arxiv.org/abs/2305.13281)) | 上下文更长 | | **陪审团(Jury)** | 用多个评委并聚合答案,比单个模型效果好([论文](https://arxiv.org/abs/2404.18796)) | 成本可通过"多个小模型替代一个大模型"大幅降低;也可试同一个模型、变化 temperature | | **加筹码(stakes)** | 社区意外发现:在 prompt 里加"答对了给你一只小猫"(`answer correctly and you'll get a kitten`)能提高正确率 | 效果因人而异,按需调整 | ### 5.4 Prompt 模板示例 以下模板示例是根据本节指南要点组合而成(非原文逐字内容),演示 pointwise 打分、pairwise 比较、累加式评分与 CoT 的结构: **① 点式打分 + 详细刻度锚点 + JSON 输出(pointwise scoring prompt)** ```text Your task is to evaluate the fluency of a model-generated answer. You will be provided with the answer below. Evaluation criteria: You should evaluate the property "fluency" on an integer scale of 1 to 5: - 1: completely un-understandable - 2: many errors, hard to follow - 3: understandable with some errors - 4: mostly fluent, minor issues - 5: perfectly fluent Reasoning steps: To judge this task, you must first read the answer carefully, identify any grammatical or coherence issues, then decide on a final score. Output format: Your answer should be provided in JSON, with the following format: {"Score": Your score, "Reasoning": The reasoning which led you to this score} ``` **② 成对比较(pairwise comparison prompt)** ```text Your task is to compare two model answers A and B for the property "helpfulness". You will be provided with both answers. You should decide which answer is better with respect to helpfulness, or whether they are tied. Reasoning steps: First read both answers carefully and list the strengths/weaknesses of each with respect to helpfulness, then give your verdict. Output format: {"Verdict": "A" | "B" | "Tie", "Reasoning": ...} ``` **③ 累加式评分(additive scoring prompt,适合不信任笼统刻度的场景)** ```text Score the answer by adding points: - The answer directly addresses the question: +1 point - The answer includes concrete examples: +1 additional point - The answer is free of factual errors: +1 additional point Report the total as the final score. ``` **④ 先推理后打分(CoT before the score)** ```text Before providing the score, explain step by step how the answer performs on each evaluation criterion. Only after this reasoning, output the final score in the requested JSON format. ``` **⑤ 带参考答案(reference)的打分**(有 reference 时增强准确度) ```text Your task is to evaluate the answer against a reference answer. You will be provided with the candidate answer and the reference. The reference answer represents the ground truth for this prompt. Evaluation criteria: You should evaluate whether the candidate answer is faithful to the reference, on an integer scale of 1 to 5 (1 = completely unrelated, 5 = fully faithful). Output format: {"Score": Your score, "Reasoning": The reasoning which led you to this score} ``` **⑥ Few-shot 示例**(给 1–2 个"已评好分"的例子帮助推理;代价是上下文变长) ```text Your task is to score answers on the property "fluency" (scale 1-5). Example 1: Answer: "The cat sat on the mat." Score: 5 Example 2: Answer: "Cat sat mat." Score: 3 Now score the following answer, following the same criteria and output format as above. ``` **⑦ 属性是否存在(二分类风格)**——适合"该属性在样本 Y 中是否出现"式评测 ```text Your task is to evaluate if the property "toxicity" is present in the sample Y. Property "toxicity" is present if the text contains insults, threats, or harmful language. Reasoning steps: Read the sample carefully, check each phrase against the definition above, then decide. Output format: {"Toxicity": "present" | "absent", "Reasoning": ...} ``` **⑧ 陪审团(jury)聚合示意**(多评委 → 聚合,效果优于单个模型;可多个小模型,或同模型多 temperature) ```text # 伪代码(非 prompt): judges = [judge_model_1, judge_model_2, ..., judge_model_N] verdicts = [j(prompt) for j in judges] final = aggregate(verdicts) # 多数票 / 平均分 ``` **模板选型速查**: | 场景 | 推荐模板 | |---|---| | 需要一个绝对分数 | ① 点式打分 + 详细刻度锚点(整数刻度) | | 刻度不可信 / 想拆分评分标准 | ③ 累加式评分(additive) | | 选"哪个更好" | ② 成对比较(含 Tie) | | 有参考答案可用 | ⑤ 带 reference 的打分 | | 模型理解不了抽象标准 | ⑥ few-shot 示例 | | 只关心属性有无(如毒性) | ⑦ 属性存在性判断 | | 追求稳健、成本允许 | ⑧ 陪审团聚合 | ### 5.5 一个方法论提醒(社会学视角) 如果**高风险场景**、且把 evaluator 当作人类标注者的替代品,应当参考社会学里"如何设计好问卷"的研究成果,并计算类似的指标(如**标注者间一致性 inter-annotator agreement**),用正确的调查设计方法减少偏见。 但原文也坦率指出:**大多数人不追求可复现、高质量、无偏的评测**,一个"差不多能用的 prompt + 快速粗糙的评测"就够用了——这完全 OK,取决于后果的严重程度。 --- ## 6. 如何评估你的 evaluator(evaluating your evaluator) 在把 judge-LLM 投入生产或大规模使用前,先评估它在**你的任务**上的质量。 > ⚠️ 提醒:如果 evaluator 输出**二分类**结果,可以用可解释的分类指标(accuracy / recall / precision);如果输出**刻度分数**,评估它与参考的相关性会**困难得多**。 ### 6.1 第一步:挑选 baseline(基线) 把你的 evaluator 判断与某个基线比较。基线可以是: - 人类标注(human annotations) - 另一个你确信在你任务上高质量的 judge 模型 - 金标准(gold truth) - 同一个模型配另一个 prompt **样本量不需要很大(50 条可能就够),但样本必须**: - 对你任务**极具代表性**; - **有判别力**(尤其要覆盖边缘情况 edge cases); - 质量**尽可能高**。 ### 6.2 第二步:挑选 metric(指标) 用指标比较你的 judge 评价与参考(reference): - **二分类(binary)**:计算 precision、recall——最易解释。 - **成对比较(pairwise)**:计算 accuracy——很易解释。 - **分数相关性(score correlation)**:难做。为何难、如何做,推荐阅读 [Eugene Yan 的博客章节](https://eugeneyan.com/writing/llm-evaluators/#key-considerations-before-adopting-an-llm-evaluator)。 > ⭐ 不知道什么时候该用哪个模型/指标?看 [Eugene Yan 博客](https://eugeneyan.com/writing/llm-evaluators/) 里的这张[决策树图(llm-eval-tree)](https://eugeneyan.com/assets/llm-eval-tree.jpg)。 ### 6.3 第三步:评估并设定接受阈值 用你的模型 + prompt 在测试样本上打分,再用 metric 与 baseline 算分,然后决定**接受阈值**。原文给出的经验值: | 评测类型 | 常见接受阈值 | |---|---| | 成对比较 accuracy | 视任务难度,**80% ~ 95%** | | 分数相关性(Pearson) | 文献里人们通常对 **0.8** 满意;但也见过论文宣称 **0.3** 就算与人类标注者"良好相关"(所以"视情况而定") | ### 6.4 把三步骤串起来:一个最小评估流程示例 把上面三步落地的最小闭环(以"成对比较 + 人类基线"为例): ```text Step 1 收集基线(baseline) → 从你的任务里挑 ~50 条高代表性样本(含边缘情况), 请人类(或你信赖的 judge)给出成对判断,作为 reference。 Step 2 让 evaluator 跑分 → 用你的 judge LLM + 设计好的 pairwise prompt 对同一批样本判断。 Step 3 算指标 → 计算 evaluator 与 reference 的 accuracy。 (二分类则算 precision / recall;分数型则算 Pearson 相关性。) Step 4 对照阈值决定去留 → pairwise accuracy 低于 80%?换 judge 模型 / 改 prompt / 加 CoT, 重复 Step 2-4;达到 80%–95%(视任务难度)即可放行。 ``` 要点回顾: - 样本少没关系(50 条够用),但**代表性 > 数量**; - evaluator 输出**二分类或成对比较**时最容易被评估(accuracy / precision / recall); - 输出**刻度分数**时,"分数与参考的相关性"评估难度明显上升——这是选择输出形式时就要想好的权衡; - 阈值不是铁律:文献对相关性高低的接受范围从 0.3 到 0.8 都有,按你的任务与后果定。 --- ## 7. Reward Models(奖励模型) ### 7.1 什么是 Reward Model **Reward model(奖励模型,RM)**:从给定 prompt/completion 对的人类标注中学习预测一个分数,最终目标是让预测与**人类偏好**对齐。训练好后,它可以作为**人类判断的代理(proxy)——即 reward function**,用来改进其他模型(如用于强化学习)。 它与 judge LLM 的关键区别(对比表): | 维度 | Judge LLM | Reward Model | |---|---|---| | 输出 | 长文本(分数 + 推理) | 一个(或一对)分数 | | 使用方式 | 靠 prompt 工程 | 前向传播(forward pass)即出分,免 prompt | | 成本 | 调用大模型生成 | 小模型单次前向,很快 | | 训练 | 通常不训练 | 需要专门微调 | ### 7.2 两类打分方式 **① 成对分数(pairwise score)——最常见的类型** 最典型的是 **Bradley-Terry 模型**,输出单个分数,遵循: ``` p(completion b is better than completion a) = sigmoid(score_b − score_a) ``` 即:完成 b 优于完成 a 的概率 = sigmoid(b 的分数 − a 的分数)。 - 只用**成对比较**训练——比收集分数更容易; - 局限:只能比较**同一 prompt 下的多个 completion**,无法跨 prompt 比较。 其他模型在此基础上扩展,预测"一个完成优于另一个"的更细致概率(如 [RLHFlow/pair-preference-model-LLaMA3-8B](https://huggingface.co/RLHFlow/pair-preference-model-LLaMA3-8B)): - 理论上能判别完成之间的细微差异; - 代价:不易保存、比较同一测试集上跨 prompt 的许多分数; - 另外,比较过长的 completion 时上下文长度与内存会成为问题。 **② 绝对分数(absolute score)** - 例如 [SteerLM](https://arxiv.org/abs/2311.09528) 直接输出绝对分数,无需成对比较即可评估 completion; - 评测时**更易用**,但**数据更难收集**——人类偏好中绝对分数往往不如成对分数稳定。 - 近期还出现了**同时输出绝对与相对分数**的模型,如 [HelpSteer2-Preference](https://arxiv.org/abs/2410.01257) 与 [ArmoRM](https://arxiv.org/abs/2406.12845)。 ### 7.3 如何用 Reward Model 做评测 流程:给定 prompt 数据集 → 从语言模型生成 completions → 让 reward model 打分。 - **绝对分数模型**:对多个分数取平均,得到合理的汇总分数。 - **相对分数模型(更常见)**:直接平均 reward 会**被离群值(outliers)偏置**——因为不同 prompt 天生就有不同的 reward 刻度(有些 prompt 难、有些简单)。替代方案: - **Win rates(胜率)**:取一个参考 completion 集合,计算"模型输出排在参考输出之上"的百分比。粒度略细。 - **Win probabilities(胜率概率)**:模型输出优于参考输出的平均概率,能给出更细粒度、更平滑的信号。 完整流程示意: ```text prompt 数据集 │ ▼ 语言模型生成 completions(被测模型) │ ▼ reward model 打分 │ ├── 绝对分数型 → 取平均 → 汇总分数 │ └── 相对分数型 → win rates(胜率)/ win probabilities(胜率概率) │ └── 与参考 completions 集合对比 ``` | 汇总方式 | 定义 | 特点 | |---|---|---| | 直接平均 reward(相对分数型) | 把所有分数的均值当汇总 | **会被离群值偏置**——不同 prompt 有不同 reward 刻度(有的 prompt 天生更难/更易) | | win rates | 模型输出高于参考集合的**百分比** | 比平均更稳健,粒度略细 | | win probabilities | 优于参考集合的**平均概率** | 更细粒度、更平滑的信号 | ### 7.4 Reward Model 的优缺点 | 优点 | 缺点 | |---|---| | **非常快**:打分 = 对小模型做一次前向传播(只出分数,不像 judge-LLM 出长文本) | **需要专门微调**:这一步可能相当贵;虽继承基座模型许多能力,但在训练分布之外的任务上可能表现差 | | **确定性**:同一前向传播必然复现同样分数 | **RL 与评测复用时的效率损失**:语言模型可能过拟合到 reward model 的偏好上(当 RL 或直接对齐算法用的数据与 RM 训练数据相似时尤甚) | | **不易受位置偏差影响**:多数 RM 只吃一个 completion,不受顺序影响;成对模型只要训练数据在"最优答案是第一/第二个"上均衡,位置偏差通常也极小 | | | **免 prompt 工程**:直接按训练时的偏好数据输出分数 | | ### 7.5 使用 Reward Model 做评测的 Tips - 找高性能模型的好去处:**[RewardBench Leaderboard](https://huggingface.co/spaces/allenai/reward-bench)** ⭐。 - 参考 [Nemotron 论文](https://arxiv.org/abs/2406.11704) 中 RM 的使用方式。 - 对"单 prompt + completion"打分的 RM:可以**缓存许多参考模型的分数**,之后轻松对比新模型的表现。 - **训练过程中跟踪 win rate / win probability**(如[这篇近期论文](https://arxiv.org/abs/2410.11677v1)),可用来**检测模型退化(degradation)并挑选最优 checkpoint**。 --- ## 8. Tips and Tricks:已知偏见与缓解 LLM 评委的**已知偏见清单**(原文逐条整理,含缓解方法): | 偏见 | 现象 | 缓解方法 | |---|---|---| | **缺乏内部一致性**(Lack of internal consistency) | 温度不为 0 时,同一 judge 多次 prompt 会给出不同判断 | **self-consistency prompting**:多次 prompt,取多数票(majority output) | | **自偏好**(Self-preference) | 打分时倾向于[偏爱自己的输出](https://arxiv.org/abs/2404.13076) | 使用**陪审团(jury)** | | **对输入扰动不敏感**(Blindness to input perturbation) | 模型不擅长识别[被扰动的输入](https://arxiv.org/abs/2406.13439);顺带[不擅长给出一致的分数范围](https://twitter.com/aparnadhinak/status/1748368364395721128)([更完整的实验](https://github.com/LeonEricsson/llmjudge/blob/main/README.md))。例如按一致刻度给文本加噪声后要求排序,预测分数并不会反映该刻度 | ① 让模型**先解释推理、再给分数**([推文](https://twitter.com/seungonekim/status/1749289437165769177));② 在 prompt 中提供**连贯的评分刻度** | | **位置偏差**(Position-bias) | 倾向[偏爱特定答案位置](https://arxiv.org/abs/2306.05685):如 Claude 与 GPT-3.5 在成对比较时相当系统性地偏好第一个或第二个选项 | ① **随机交换**答案位置;② 计算所有可能选项的 **log-probability** 得到归一化答案 | | **冗长/长度偏差**(Verbosity-bias / length-bias) | 更偏爱更啰嗦(verbose)的答案 | 在评估中[考虑答案长度的差异](https://arxiv.org/abs/2404.04475) | | **与人类一致性存疑**(Debatable consistency with humans) | 与人类答案的一致性[存疑](https://arxiv.org/abs/2308.15812) | 反向提醒:**[非专家人类也未必是所有评估的好基线](https://arxiv.org/abs/2202.06935)**——在医学、法律、数学等特定领域,用非专家人类标注者和直接用 LLM 一样不靠谱 | | **格式偏差**(Format bias) | 若 prompt 格式[偏离训练时的格式太远](https://arxiv.org/abs/2310.17631),评估会失准。例:训练为"成对比较 + 附参考答案"的模型,不提供参考就失败;反之亦然 | **注意训练 prompt 格式**(若模型做过指令微调),确保严格遵循 | ### 8.1 哪些任务不适合交给 LLM judge - **幻觉检测整体很弱**,尤其**部分幻觉(partial hallucinations)**——看起来接近真值、其实略有出入的幻觉(见[论文 1](https://arxiv.org/abs/2305.11747)、[论文 2](https://arxiv.org/abs/2303.08896))。 - 与人类标注者在以下任务上相关性只有 **低 ~ 中等**: - **摘要(summarization)**([论文 1](https://arxiv.org/abs/2304.02554)、[论文 2](https://arxiv.org/abs/2303.16634)); - **忠实度(faithfulness)**([论文](https://arxiv.org/abs/2307.16877)); - 更广地看,跨[一系列任务](https://arxiv.org/abs/2406.18403)与人类判断并非持续相关。 ### 8.2 设计"少偏见"评测的检查清单 把上一节的缓解方法汇总成一张实操清单,上线评测前逐项核对: - [ ] **一致性**:固定 seed / 温度设为 0;或对同一 judge 多次采样、取多数票(self-consistency) - [ ] **位置偏差**:成对比较时随机交换答案位置;必要时计算所有选项的 log-probability 归一化 - [ ] **自偏好**:使用陪审团(多个评委聚合),而不是单一模型 - [ ] **扰动盲区**:要求"先推理、后给分";prompt 中提供连贯的评分刻度锚点 - [ ] **冗长偏差**:比较时考虑双方答案的长度差异 - [ ] **格式偏差**:严格遵循所选模型(尤其指令微调模型)训练时的 prompt 格式 - [ ] **任务适配**:对幻觉(尤其部分幻觉)、摘要、忠实度等已知弱项任务谨慎使用 - [ ] **方法论**:高风险场景按社会调查标准设计——如计算标注者间一致性(inter-annotator agreement) --- ## 9. 常见误区与 FAQ **Q1:用 LLM 当评委,是不是就一定客观、无偏?** 不是。它看起来客观,但隐藏偏见更难被发现(我们不会主动审视它);用 LLM 评估 LLM 还被类比为制造回音室效应。详见第 2、8 节。 **Q2:打分(pointwise)是不是比成对比较(pairwise)更好用?** 原文给出的证据恰恰相反:**pairwise 与人类偏好的相关性更高、更稳健**。如果你确实需要绝对分数,务必用整数刻度 + 详细解释每个分数代表什么,或改用 additive 累加式评分。 **Q3:大模型评委是不是永远比小模型好?** 最强评委目前多为闭源大模型,但它们是黑盒、运行在 API 下且结果可能无通知变更,还涉及数据隐私。开源大模型的差距正在快速缩小;小型专用模型(Flow-Judge-v0.1、Prometheus、JudgeLM)可本地运行、可复现、便宜,且 jury 场景下"多个小模型"能大幅降低比"一个大模型"的成本。 **Q4:我能直接用 reward model 的平均分做汇总吗?** 只有**绝对分数型** RM 可以直接取平均。**相对分数型**(如 Bradley-Terry)直接平均会被离群值偏置(不同 prompt 的 reward 刻度不同),应当改用 win rates(胜率)或 win probabilities(胜率概率)。 **Q5:LLM judge 是不是什么任务都能评?** 不是。它在幻觉检测上整体很弱(尤其部分幻觉),在摘要、忠实度上对人类的相关性只有低~中等,跨任务也并非持续与人类判断相关。选任务前先看第 8.1 节。 **Q6:分数相关性 0.3 算不算合格?** 看文献:有人对 0.8 的 Pearson 相关才满意,也有人宣称 0.3 就算与人类标注者"良好相关"。阈值取决于你的任务难度与后果——这正是"评估你的 evaluator"这一步的意义。 **Q7:用小型 judge 模型时,prompt 格式重要吗?** 重要。格式偏差(format bias)会导致评估失准:例如训练为"成对比较 + 附参考答案"的模型,不提供参考就失败,反之亦然。务必遵循模型训练时的 prompt 格式。 --- ## 10. 速查表:全章要点一页纸 1. **Judge LLM = 用 LLM + prompt 评估其他模型输出**;三大任务:打分(pointwise)、成对比较(pairwise)、相似度。 2. **优点**:客观、可扩展、便宜、与人类判断相关;**缺点**:隐藏偏见、回音室效应、数据质量负担、专家质量不如真人。 3. **获取路线**:通用大模型(闭源最强但黑盒/API 不稳,开源差距快速缩小)→ 小型专用模型(Flow-Judge-v0.1 3.8B / Prometheus 13B·7B / JudgeLM 7B–33B)→ 自己训练(人类或合成偏好数据;蒸馏/量化/微调;从 reward model 出发更佳)。 4. **Prompt 设计**:任务描述 + 详细标准/刻度 + 推理步骤 + 指定 JSON 输出格式;pairwise 优于打分;整数刻度要配"每分代表什么"或 additive prompt;一能力一 prompt。 5. **提升准确度**:few-shot、reference、CoT(先推理后分数)、multiturn、jury(多评委聚合)、加 stakes("答对给小猫")。 6. **评估你的 evaluator**:50 条高代表性样本作 baseline;二分类/pairwise 用 accuracy/precision/recall,分数用相关性(Pearson);阈值参考:pairwise 80–95%,相关性 0.8(0.3 也有人接受)。 7. **Reward Model**:Bradley-Terry 成对评分 vs SteerLM 绝对评分(HelpSteer2-Preference / ArmoRM 双输出);相对分数用 win rates / win probabilities 而非平均;快、确定性、少位置偏差、免 prompt,但需专门微调、RL 复用有 overfit 风险;模型找 RewardBench,用法参考 Nemotron。 8. **已知偏见**:内部不一致 → self-consistency;自偏好 → jury;扰动盲 → 先推理后评分 + 连贯刻度;位置偏差 → 随机换位 + log-prob 归一化;冗长偏差 → 控制长度差异;格式偏差 → 严格遵循训练格式。 9. **慎用场景**:幻觉(尤其部分幻觉)、摘要、忠实度——相关性低或一般。 --- ## 11. 参考资料 ### 原文(本笔记对应源文件) - [basics.md](https://github.com/huggingface/evaluation-guidebook/blob/main/contents/model-as-a-judge/basics.md) - [getting-a-judge-llm.md](https://github.com/huggingface/evaluation-guidebook/blob/main/contents/model-as-a-judge/getting-a-judge-llm.md) - [designing-your-evaluation-prompt.md](https://github.com/huggingface/evaluation-guidebook/blob/main/contents/model-as-a-judge/designing-your-evaluation-prompt.md) - [evaluating-your-evaluator.md](https://github.com/huggingface/evaluation-guidebook/blob/main/contents/model-as-a-judge/evaluating-your-evaluator.md) - [what-about-reward-models.md](https://github.com/huggingface/evaluation-guidebook/blob/main/contents/model-as-a-judge/what-about-reward-models.md) - [tips-and-tricks.md](https://github.com/huggingface/evaluation-guidebook/blob/main/contents/model-as-a-judge/tips-and-tricks.md) ### ⭐ 推荐阅读 - [HuggingFace Cookbook:LLM as a judge(Aymeric Roucher)](https://huggingface.co/learn/cookbook/en/llm_judge) ⭐ - [Eugene Yan:LLM Evaluators 博客](https://eugeneyan.com/writing/llm-evaluators/) ⭐(含 [决策树图](https://eugeneyan.com/assets/llm-eval-tree.jpg)) - [RewardBench Leaderboard](https://huggingface.co/spaces/allenai/reward-bench) ### 论文 - [UltraFeedback(2310.01377)](https://arxiv.org/abs/2310.01377) - [Prometheus(2310.08491)](https://arxiv.org/abs/2310.08491) - [JudgeLM(2310.17631)](https://arxiv.org/abs/2310.17631) - [MT-Bench / Chatbot Arena:Judging LLM-as-a-Judge(2306.05685v4,通用大模型评委与位置偏差)](https://arxiv.org/abs/2306.05685v4) - [小模型偏好判别(2405.01535)](https://arxiv.org/abs/2405.01535) - [Pairwise 优于打分(2403.16950)](https://arxiv.org/abs/2403.16950) - [CoT 提升准确度(2212.08073)](https://arxiv.org/abs/2212.08073) - [多轮分析提升事实错误检测(2305.13281)](https://arxiv.org/abs/2305.13281) - [Jury(多评委聚合,2404.18796)](https://arxiv.org/abs/2404.18796) - [Self-preference(2404.13076)](https://arxiv.org/abs/2404.13076) - [输入扰动盲区(2406.13439)](https://arxiv.org/abs/2406.13439) - [位置偏差(2306.05685)](https://arxiv.org/abs/2306.05685) - [Verbosity bias 与长度控制(2404.04475)](https://arxiv.org/abs/2404.04475) - [Judge 与人类一致性存疑(2308.15812)](https://arxiv.org/abs/2308.15812) - [非专家人类标注者作为基线的争议(2202.06935)](https://arxiv.org/abs/2202.06935) - [格式偏差(2310.17631,同 JudgeLM)](https://arxiv.org/abs/2310.17631) - [部分幻觉检测(2305.11747 / 2303.08896)](https://arxiv.org/abs/2305.11747) - [摘要相关性(2304.02554 / 2303.16634)](https://arxiv.org/abs/2304.02554) - [忠实度相关性(2307.16877)](https://arxiv.org/abs/2307.16877) - [跨任务与人类一致性(2406.18403)](https://arxiv.org/abs/2406.18403) - [Nemotron-4 340B 技术报告(reward model as judge,NVIDIA)](https://research.nvidia.com/publication/2024-06_nemotron-4-340b) - [Nemotron 用 RM 做评测(2406.11704)](https://arxiv.org/abs/2406.11704) - [SteerLM(2311.09528)](https://arxiv.org/abs/2311.09528) - [HelpSteer2-Preference(2410.01257)](https://arxiv.org/abs/2410.01257) - [ArmoRM(2406.12845)](https://arxiv.org/abs/2406.12845) - [训练中跟踪 win rate 检测退化(2410.11677v1)](https://arxiv.org/abs/2410.11677v1) ### 模型与数据集 - [Flow-Judge-v0.1 权重集合](https://huggingface.co/collections/flowaicom/flow-judge-v01-66e6af5fc3b3a128bde07dec) - [Prometheus-13B-v1.0](https://huggingface.co/prometheus-eval/prometheus-13b-v1.0) / [Prometheus-7B-v2.0](https://huggingface.co/prometheus-eval/prometheus-7b-v2.0) - [Prometheus Preference Collection](https://huggingface.co/datasets/prometheus-eval/Preference-Collection) / [Feedback Collection](https://huggingface.co/datasets/prometheus-eval/Feedback-Collection) - [RLHFlow pair-preference-model-LLaMA3-8B](https://huggingface.co/RLHFlow/pair-preference-model-LLaMA3-8B) - [Qwen 2.5 系列](https://huggingface.co/collections/Qwen/qwen25-66e81a666513e518adb90d9e) / [Command R+](https://huggingface.co/CohereForAI/c4ai-command-r-plus-08-2024) / [Llama 3.1-405B-Instruct](https://huggingface.co/meta-llama/Llama-3.1-405B-Instruct) - [LMSYS Chatbot Arena 人类偏好数据集(Kaggle)](https://www.kaggle.com/competitions/lmsys-chatbot-arena) ### 工具与教程 - [distilabel](https://distilabel.argilla.io/latest/)([UltraFeedback tutorial](https://distilabel.argilla.io/latest/sections/pipeline_samples/papers/ultrafeedback/) / [benchmarking with distilabel(Arena Hard)](https://distilabel.argilla.io/latest/sections/pipeline_samples/examples/benchmarking_with_distilabel/)) - [lighteval:MixEval judge prompts](https://github.com/huggingface/lighteval/blob/main/src/lighteval/tasks/extended/mix_eval/judge_prompts.pyy) / [MTBench judge prompt templates](https://github.com/huggingface/lighteval/blob/main/src/lighteval/tasks/extended/mt_bench/judge_prompt_templates.py) - [ArtificialAnalysis LLM Performance Leaderboard(成本对比)](https://huggingface.co/spaces/ArtificialAnalysis/LLM-Performance-Leaderboard) - [LeonEricsson/llmjudge(扰动敏感度扩展实验)](https://github.com/LeonEricsson/llmjudge/blob/main/README.md) ### 社区推文 - [Seungone Kim:先推理后打分 / 分数刻度锚点](https://x.com/seungonekim/status/1749289437165769177) - [Aparna Dhinakaran:分数范围一致性](https://twitter.com/aparnadhinak/status/1748368364395721128) - [从 reward model 出发微调 judge 更好](https://x.com/dk21/status/1826292289930674590)