AI反馈:换了评审者,也就换了学习信号
Learning from AI feedback
量出顺序与风格偏差,再区分奖励蒸馏和直接评分。
rlai-feedback交换回答顺序,可能只修好一种偏差
设想一个评审者总偏爱排在前面的回答。两种顺序都评一次,似乎是自然的修正。再假设它还偏爱华丽措辞,即使内容错误也如此。交换位置针对的是第一种偏好,不会自动解决第二种。
AI反馈强化学习(RLAIF)使用AI生成的判断作为学习信号。评审者、奖励模型与策略可以是不同模型。Lee等人第2节区分蒸馏路径与直接路径:前者从AI比较拟合奖励模型,后者在强化学习中直接使用AI评分作为奖励。Bai等人第4节展示了宪法式AI中由原则引导的AI比较,但并非所有RLAIF都必须采用那套包含监督修订的两阶段配方。
本程序使用明写的数值评审器,不调用AI服务。它把位置偏差、与内容有关的偏好,以及从反馈到策略的数值路径分开。这里的“期望效用”是为例子构造的,不是真实人类偏好的测量。
平均之前,先对齐候选身份
设候选的期望效用为,但评审者额外给出风格加分,其实际依据的分数为:
如果第一选项有位置优势,当排在前面时,概率为:
交换回答后,第一选项的概率就属于。先把它转换回候选的概率,再平均:
这展示了Lee第2.1.1节的顺序平衡思路。分数相同时结果为0.5,并满足。在这个合成加性偏差模型里,它保留的是的排序,不一定是的排序;其置信程度通常也不同于,因此“平衡”不等于完美校准。真实评审者的位置效应也未必是固定加性常数。
蒸馏路径中,标量奖励模型拟合平衡后的软标签。记:
策略再按明确的参考模型与正则设置优化这些分数。奖励拟合在评审者与策略之间引入另一层近似;去掉这一层,也不等于去掉评审误差。
Lee的直接变体让评审模型给出1至10分各档的概率。归一化后,计算期望评分并映射到:
本例用平滑的手工曲线提供十个logit,没有语言模型分词或评分提示。真实实现中,要说明多词元评分字符串怎样计分,以及究竟归一化了哪部分概率质量。
两种奖励路径都使用有限策略的精确KL正则解:
它是三个回答的优化参照,不是当前策略上的强化学习训练循环。直接与蒸馏奖励可能具有不同尺度,采用同一个,不意味着正则强度可比。
评审一致性与策略质量是不同评测。相对于明确给定的排序,一种简单的严格一致率为:
本例把评审平局算作没有严格一致。Lee第2.3节定义AI标签一致率时使用二元argmax约定,并另用人类判断评估策略胜率与无害率。本例平局规则已明确,不能把自己的统计量标成论文基准分数。
顺序平衡后的评审者,仍可能偏爱错误特征
以下完整程序需要Python与NumPy。效用为(1,0.4,-0.5),风格加分为(0,0,1.5),于是评审分数变成(1,0.4,1)。第三个回答的风格掩盖了较差效用,第一位置的优势为1.2。
"""Authored synthetic judge: order bias, style bias and two reward routes; no AI calls."""
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 ordered_preference(left_score, right_score, position_bias=1.2):
return float(sigmoid(left_score-right_score+position_bias))
def symmetrized(left_score,right_score,position_bias=1.2):
ab=ordered_preference(left_score,right_score,position_bias)
ba=ordered_preference(right_score,left_score,position_bias)
return (ab+1-ba)/2
def direct_reward(score_logits):
# Teaching analogue of normalized probabilities of rating categories 1..10.
probabilities=softmax(score_logits)
if len(probabilities)!=10:raise ValueError("Ten rating logits are required")
mean=float(probabilities@np.arange(1,11))
return 2*(mean-1)/9-1
def demo():
utility=np.array([1.,.4,-.5])
style_bonus=np.array([0.,0.,1.5])
judged=utility+style_bonus
original=np.array([ordered_preference(judged[i],judged[j]) for i,j in PAIRS])
balanced=np.array([symmetrized(judged[i],judged[j]) for i,j in PAIRS])
reward=fit_scores(PAIRS,balanced)
reference=np.array([.4,.4,.2])
distilled=policy_for_reward(reference,reward,.7)
centers=np.array([8.,6.,8.])
direct=np.array([direct_reward(-.5*(np.arange(1,11)-c)**2) for c in centers])
online=policy_for_reward(reference,direct,.7)
return dict(utility=utility.tolist(), style_bonus=style_bonus.tolist(),
unbalanced=original.tolist(), balanced=balanced.tolist(),
# A tie is not an agreement with a strict underlying utility order.
strict_agreements=int(np.sum(balanced>.5)), comparisons=len(PAIRS),
learned_reward=reward.tolist(), distilled_policy=distilled.tolist(),
direct_scores=direct.tolist(), direct_policy=online.tolist(),
reference_utility=float(reference@utility),
distilled_utility=float(distilled@utility), direct_utility=float(online@utility),
note="Rewards have different scales; equal beta is not a controlled method comparison.")
if __name__ == "__main__":
print(json.dumps(demo(), indent=2))
对(A,B),(B,C),(A,C)三对,未平衡的第一选项概率约为(0.858149,0.645656,0.768525);交换并对齐身份后,变为(0.606246,0.393754,0.5)。只有一个比较与期望效用严格同序。A与C平局尤其值得看:评审者把一个好回答,与一个风格讨好但较差的回答看成相同。
蒸馏奖励拟合这三个概率后,在参考(0.4,0.4,0.2)、下得到约(0.490239,0.264642,0.245119)的策略。直接路径使用以(8,6,8)为中心的评分曲线,产生略有差别的策略。期望效用的小差异或相同beta,都不能证明某条路径普遍更好,因为奖励尺度和手工判断不同。
对个配对,顺序平衡每对需要两次数值评审;真实标注流程中,通常也意味着两次而非一次评审调用。教学奖励拟合每步为,十档直接评分为,策略参照为。这些计数都不是实测API价格、延迟或语言模型浮点运算量。
标签来源便宜了,评测目标仍要明确
AI评审者可能因顺序、风格、冗长程度、知识缺口或共同训练偏差,而偏离期望准则。本例只实现两种明确效应,无法估计它们在现实中的发生率。应按任务与群体检查一致性,而不是假设一个平均数覆盖所有用途。
当实验主张要求独立性时,应分开评审者选择、校准和最终评测数据。用同一个评审者造标签,再宣告策略成功,可能掩盖共同错误。新的人工评测也应说明指南、不确定性与分歧,不是不犯错的神谕。
Gao等人第2.1节用大型奖励模型作为合成gold信号,研究代理优化。保留其合成性质,才有助于理解这个设置。AI生成标签、模型gold分数与人类偏好是不同证据来源。
评审之前,先把身份对齐
- 两种候选顺序下,评审者都给第一选项0.8概率。候选A的平衡概率是多少?
答案:。交换后,第二个0.8属于B。直接平均0.8与0.8,就没有对齐候选身份。
- 顺序平衡会消除第三个回答的风格加分吗?
答案:不会。两种顺序中,加分仍是的一部分。例子里A与C的期望效用不同,却仍被判平局。
- 1至10各档评分均匀分布,对应多大的直接奖励?
答案:期望评分5.5,映射后为零。全部质量放在1分映射为,全部放在10分映射为1。
- 两条流程参考与beta相同,但其中一条把奖励都乘十,正则强度是否等价?
答案:不等价。指数中的奖励与beta之比变了。若beta也乘十,这个有限最优策略才保持不变;beta固定时,奖励的影响增强。
追踪每个判断来自谁
Lee第2.1—2.3节解释顺序处理、反馈路径与不同评测指标;Bai第4节加入原则和混合监督来源;Gao的合成设置说明为何gold模型分数必须保留来源。记录评审者、提示或准则、模型版本、候选顺序与评测来源,才能解释一个AI反馈结果。
先判断,再看解释
两种候选顺序取平均,能消除评审者的全部偏差吗?
学习目标
- 区分标签一致率、策略质量,以及直接与蒸馏反馈。
- 验证教学计算并说明它不能证明什么。
先修与延伸
查看知识关联图 →参考文献
- RLAIF: Scaling Reinforcement Learning from Human Feedback with AI Feedback — v2
Harrison Lee; Samrat Phatale; Hassan Mansoor; Thomas Mesnard; Johan Ferret; Kellie Lu; Colton Bishop; Ethan Hall; Victor Carbune; Abhinav Rastogi; Sushant Prakash · 2023 - Constitutional AI: Harmlessness from AI Feedback — v1
Yuntao Bai and coauthors · 2022 - Scaling Laws for Reward Model Overoptimization — v1
Leo Gao; John Schulman; Jacob Hilton · 2022
版本1 · 编写状态: 已完成记录中的技术复核
查看技术检查记录(AI)
Codex · 2026-09-20 · Single AI author. Sections2.1.1/2.1.2/2.2,2.3 opening and4.3/4.4 text; PDF3/4 viewed. Order balancing, distilled/direct feedback and separate evaluation metrics; v2 dated2023-12-01. Sections3.1/3.2 and4.1/4.2 opening; PDF7/10/11 viewed. Critique/revision, supervised stage, AI harmlessness plus human helpfulness labels and soft preference targets. 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. Order probabilities aligned by candidate identity; style bias survives; direct rating endpoints and distilled likelihood verified. Strict-tie convention and unequal reward scales explicit; no AI calls.
- 核按候选身份对齐顺序、风格偏差保留、直接评分端点及蒸馏似然;平局约定与奖励尺度差明示,未调用AI。
- 每题四张计算SVG,10数值/几何与30响应式组合通过;实看10张最终图,完整页面验收另记。
核对的来源位置:
- RLAIF: Scaling Reinforcement Learning from Human Feedback with AI Feedback — v2 · Sections2.1.1/2.1.2/2.2,2.3 opening and4.3/4.4 text; PDF3/4 viewed. Order balancing, distilled/direct feedback and separate evaluation metrics; v2 dated2023-12-01.
- Constitutional AI: Harmlessness from AI Feedback — v1 · Sections3.1/3.2 and4.1/4.2 opening; PDF7/10/11 viewed. Critique/revision, supervised stage, AI harmlessness plus human helpfulness labels and soft preference targets.
- 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.
相关主题