奖励模型:分数学到的是比较,不是真理
Reward modeling
拟合偏好赔率,找出无法识别的分数,观察代理优化如何损害另一目标。
reward-modeling相同的比较,可以支持很不相同的分数
A在五次比较中四次胜过B,这是否说明A的奖励是0.8?未必。比较频率针对两个回答,奖励分数则属于某个提示下的一个回答。许多不同分数组合都能产生同样的比较概率;一个从未参与比较的回答,更缺乏约束。
奖励模型把输入及候选行为映射为用于评价或优化的标量。本文聚焦从偏好训练的奖励模型。Christiano等人第2.2.3节从轨迹比较学习分数;Rafailov等人第3节给出回答层面的偏好似然。这两种构造都不会自动让分数成为正确性、安全或人类福祉的客观刻度。
可运行实验先拟合三个表格奖励,再加入未见回答,最后优化一个故意不完善的代理目标。所有标签与效用都是合成的。
似然里只有分数差
对同一提示下的回答,Bradley–Terry模型使用:
这里假设存在标量偏好尺度,并采用特定噪声模型。分数差为零对应概率0.5,差为对应0.8。轨迹片段的分数可以是每步预测奖励之和;语境和片段定义仍是模型的一部分。
给定个比较及软目标,令。平均负对数似然可以稳定地计算为:
logaddexp(0, delta)不必直接算出巨大指数,就能得到第一项。如果数据来自真实重复二元判断,按次数加权的似然会保留观测数;给不同配对的频率一律等权,是另一种目标。本例三个原创配对频率等权,不能报成人类观测数据。
表格分数的梯度为:
每个比较都把同一个残差加到一边、从另一边减掉,因此梯度总和为零,零初始化会让分数均值保持为零。这只是选了一个方便约定,数据本身不能确定共同偏移:
比较图不连通时,每个分量都有自己的未约束偏移。正则化或初始化可以选出某个解,却没有补上缺失的证据。第四个回答没有参与任何比较,因此给它或,训练似然完全相同。
尺度与偏移不同。乘法通常会改变置信程度:
所以中心化不等于概率校准。用独立验证集拟合温度可以调整置信程度,却不能修复缺失特征或没有数据支持的行为。完全可分的硬偏好,还可能让无正则逻辑模型的分数无限增大;本例有限的软目标避免了这一情况。
标量分数差必须满足环上的一致性:
如果这三个有向比较的目标概率都为0.8,每一项都要求,就与恒等式矛盾。等权时,对称最优解为分数全部相同,损失。出现分歧未必是优化器出错,也可能是模型无法表示标签。
最后,用代理奖励选择策略,同时用另一个原创效用衡量期望结果:
它们是不同量。目标中没有任何条件保证代理奖励提高时,也提高。Gao等人第2.1节研究了相关的代理优化问题,用较大的奖励模型充当合成“gold”。这个gold模型并不等于直接取得了真实人类效用;本例明写的数值效用是另一项教学构造。
拟合、平移、遗漏,再优化
运行以下完整Python/NumPy程序。三个配对目标0.8,0.8,16/17恢复约的分数,损失为0.4081743077。所有分数加100后,损失在浮点精度内保持不变。
"""Original finite reward fitting: synthetic labels, no human or LLM ratings."""
import json
import numpy as np
def sigmoid(x):
x = np.asarray(x, dtype=float)
return np.exp(-np.logaddexp(0, -x))
def softmax(x):
x = np.asarray(x, dtype=float)
if x.ndim != 1 or not len(x) or not np.isfinite(x).all():
raise ValueError("Expected a nonempty finite vector")
e = np.exp(x - x.max())
return e / e.sum()
def preferences(scores, pairs):
return sigmoid(scores[pairs[:, 0]] - scores[pairs[:, 1]])
def pair_loss_grad(scores, pairs, targets):
scores = np.asarray(scores, dtype=float)
pairs = np.asarray(pairs, dtype=int)
targets = np.asarray(targets, dtype=float)
if (scores.ndim != 1 or pairs.ndim != 2 or pairs.shape[1] != 2
or len(pairs) == 0 or targets.shape != (len(pairs),)
or not np.isfinite(scores).all() or not np.isfinite(targets).all()
or np.any((targets < 0) | (targets > 1))
or pairs.min() < 0 or pairs.max() >= len(scores)):
raise ValueError("Invalid scores, pairs or soft labels")
delta = scores[pairs[:, 0]] - scores[pairs[:, 1]]
loss = np.mean(np.logaddexp(0, delta) - targets * delta)
residual = (sigmoid(delta) - targets) / len(pairs)
gradient = np.zeros_like(scores)
np.add.at(gradient, pairs[:, 0], residual)
np.add.at(gradient, pairs[:, 1], -residual)
return float(loss), gradient
def fit_scores(pairs, targets, size=3, steps=2000):
scores = np.zeros(size)
for _ in range(steps):
_, gradient = pair_loss_grad(scores, pairs, targets)
scores -= 0.5 * gradient
return scores
def policy_for_reward(reference, reward, beta):
reference = np.asarray(reference, dtype=float)
reward = np.asarray(reward, dtype=float)
if (reference.ndim != 1 or reference.shape != reward.shape
or not np.isfinite(reference).all() or not np.isfinite(reward).all()
or np.any(reference <= 0) or not np.isclose(reference.sum(), 1)
or not np.isfinite(beta) or beta <= 0):
raise ValueError("Positive normalized reference and beta are required")
return softmax(np.log(reference) + reward / beta)
PAIRS = np.array([[0, 1], [1, 2], [0, 2]])
def demo():
truth = np.array([np.log(4), 0., -np.log(4)])
target = preferences(truth, PAIRS)
learned = fit_scores(PAIRS, target)
cycle = np.array([[0, 1], [1, 2], [2, 0]])
cyclic = fit_scores(cycle, np.full(3, .8))
# Candidate 3 is never compared: both scores fit observed data equally.
low, high = np.r_[learned, -4.], np.r_[learned, 4.]
q = np.array([.8, .19, .01])
proxy, gold = np.array([0., 1., 3.]), np.array([0., 1., -1.])
optimization = []
for beta in [5., 1., .25]:
policy = policy_for_reward(q, proxy, beta)
optimization.append(dict(beta=beta, policy=policy.tolist(),
proxy=float(policy @ proxy), gold=float(policy @ gold)))
return dict(targets=target.tolist(), scores=learned.tolist(),
loss=pair_loss_grad(learned, PAIRS, target)[0],
shifted_loss=pair_loss_grad(learned+100, PAIRS, target)[0],
cycle_scores=cyclic.tolist(), cycle_loss=pair_loss_grad(cyclic, cycle, np.full(3,.8))[0],
unseen_losses=[pair_loss_grad(x, PAIRS, target)[0] for x in [low,high]],
unseen_probability=[float(policy_for_reward(np.full(4,.25),x,1)[3]) for x in [low,high]],
optimization=optimization)
if __name__ == "__main__":
print(json.dumps(demo(), indent=2))
采用四回答均匀参考分布、时,未见回答的分数为,其最优概率约0.003477;分数为,概率则约0.912278。两种分数对已有三个回答的比较拟合得一样好,训练损失无法替我们选择。
另一项代理实验的参考概率为(0.8,0.19,0.01),代理分数(0,1,3),期望效用(0,1,-1)。按5,1,0.25减小时,期望代理奖励约为0.2730,0.7375,2.9859,一路上升;效用则为0.2036,0.2080,-0.9869。强力优化找到了被代理高分奖励的失败行为。
对个比较、个分数,每次全量拟合更新需要工作量,闭式策略计算需要。程序检查输入有限、标签属于。它只拟合表格分数,没有表示学习、标注界面或Transformer奖励头。
预测偏好和评测策略面对不同分布
留出比较应检查与主张相匹配的提示、候选与评审者。只随机拆分配对,可能让同一提示或回答同时出现在训练和测试中。策略优化后还应评测实际生成回答,因为策略可能找到奖励模型很少见过的区域。
单一标量可能把冲突目标混在一起,掩盖取舍。应报告标注准则、分歧、弃权、覆盖与校准。人类比较能为一个明确判断任务提供信息,却不自动等于事实核验。偏爱漂亮措辞的模型,仍可能奖励错误回答。
合成反例证明某种失效可能发生,不代表任何部署系统的实测失败率。集成或更强的参考惩罚在某些条件下可能有用,但都不能单独证明代理优化安全或准确。
找出数据没有约束什么
- 偏好概率0.8,是否意味着奖励0.8?
答案:不是。在本模型中,它意味着分数差;(log4,0)与(log4+20,20)产生同样的比较概率。
- 为什么给第四个回答和,已有损失一样?
答案:它从未参与比较,其分数不出现在任何似然差值中,却会显著影响之后优化的策略。
- 奖励中心化能否修复概率过度自信?
答案:不能。中心化减去共同常数,差值和概率不变。校准针对尺度或更一般的失配,应使用合适的数据评估。
- 各优化设置下代理分数都提高了,例子中的什么额外数字揭示了失败?
答案:单独定义的期望效用在时降到约。只看代理改善会漏掉这一逆转;真实应用中的独立结果指标,也需要说明自己的证据与局限。
分别核验三个主张
用Christiano的方法节理解比较如何监督奖励,用DPO的预备知识理解回答层面似然,再用Gao的合成设置理解过度优化实验究竟测量了什么。分别检查:奖励能否预测标签、策略能否优化奖励,以及优化后的行为是否满足真正目标。
先判断,再看解释
两个奖励分数同时加相同常数会怎样?
学习目标
- 推导成对似然并识别数据覆盖边界。
- 验证教学计算并说明它不能证明什么。
先修与延伸
查看知识关联图 →参考文献
- Deep Reinforcement Learning from Human Preferences — v1
Paul F. Christiano; Jan Leike; Tom B. Brown; Miljan Martic; Shane Legg; Dario Amodei · 2017 - Direct Preference Optimization: Your Language Model is Secretly a Reward Model — v2
Rafael Rafailov; Archit Sharma; Eric Mitchell; Stefano Ermon; Christopher D. Manning; Chelsea Finn · 2023 - Scaling Laws for Reward Model Overoptimization — v1
Leo Gao; John Schulman; Jacob Hilton · 2022
版本1 · 编写状态: 已完成记录中的技术复核
查看技术检查记录(AI)
Codex · 2026-09-20 · Single AI author. Section2.2 through2.2.4 opening; PDF5 viewed: trajectory comparisons, soft labels, negative cross-entropy and actual recipe modifications. Sections3/4, PDF3/4 viewed; gradient and procedure text read. BT, KL objective, partition cancellation and DPO; v2 dated2023-12-13. Sections2.1/2.2 and preceding best-of-n text; PDF4 viewed. Synthetic gold RM versus proxy, deterministic comparisons and recalibration; no empirical scaling fit reproduced. Seven paired equations and four explained exercises. Pairwise likelihood gradients, offset invariance, known odds, cyclic preferences, unobserved score freedom and proxy/utility reversal; no objective human-utility claim.
- 核成对梯度、平移不变、赔率、循环偏好、未见分数自由度和代理/效用逆转,不冒充客观人类效用。
- 每题四张计算SVG,10数值/几何与30响应式组合通过;实看10张最终图,完整页面验收另记。
核对的来源位置:
- Deep Reinforcement Learning from Human Preferences — v1 · Section2.2 through2.2.4 opening; PDF5 viewed: trajectory comparisons, soft labels, negative cross-entropy and actual recipe modifications.
- Direct Preference Optimization: Your Language Model is Secretly a Reward Model — v2 · Sections3/4, PDF3/4 viewed; gradient and procedure text read. BT, KL objective, partition cancellation and DPO; v2 dated2023-12-13.
- Scaling Laws for Reward Model Overoptimization — v1 · Sections2.1/2.2 and preceding best-of-n text; PDF4 viewed. Synthetic gold RM versus proxy, deterministic comparisons and recalibration; no empirical scaling fit reproduced.
相关主题