SteamSHP-XL是一个偏好模型,能预测人类认为更有帮助的回应,可用于NLG评估或作为RLHF奖励模型,基于Reddit和Anthropic HH-RLHF数据集训练,准确性达72.8%。【此简介由AI生成】
| 文件 | 最后提交记录 | 最后更新时间 |
|---|---|---|
| 3 年前 | ||
| 2 年前 | ||
| 3 年前 | ||
| 3 年前 | ||
| 3 年前 | ||
| 3 年前 | ||
| 3 年前 | ||
spiece.modelLFS | 3 年前 | |
| 3 年前 | ||
| 3 年前 |
license: apache-2.0 datasets:
- stanfordnlp/SHP language:
- en metrics:
- accuracy tags:
- human feedback
- rlhf
- preferences
- preference model
- RL
- NLG
- evaluation
💨🚢 SteamSHP-XL
若提及此模型,请引用论文: Understanding Dataset Difficulty with V-Usable Information (ICML 2022)
SteamSHP-XL 是一个经过训练的偏好模型,能够根据给定上下文和两种可能的回应,预测人类认为哪种回应更有帮助。该模型可用于自然语言生成评估,或作为强化学习人类反馈(RLHF)的奖励模型。
该模型基于 FLAN-T5-xl(30亿参数)进行微调,训练数据包括:
- 斯坦福人类偏好数据集(SHP),包含来自 Reddit 上 18 个不同社区(如
askculinary、legaladvice等)的集体人类偏好数据 - Anthropic 的 HH-RLHF 数据集中的帮助性数据
另有一个小型变体 SteamSHP-Large,基于 FLAN-T5-large(7.8亿参数)微调而成。尽管体积仅为四分之一,其在 SHP + Anthropic 测试数据(跨所有领域)上的平均准确率仅低 0.75 个百分点。
使用方法
常规使用
输入文本格式应为:
POST: { the context, such as the 'history' column in SHP (not containing any newlines \n) }
RESPONSE A: { first possible continuation (not containing any newlines \n) }
RESPONSE B: { second possible continuation (not containing any newlines \n) }
Which response is better? RESPONSE
SteamSHP-XL 生成的输出结果将是 A 或 B 中的一种。
以下是该模型的使用方法:
>> from transformers import T5ForConditionalGeneration, T5Tokenizer
>> device = 'cuda' # if you have a GPU
>> tokenizer = T5Tokenizer.from_pretrained('stanfordnlp/SteamSHP-flan-t5-xl')
>> model = T5ForConditionalGeneration.from_pretrained('stanfordnlp/SteamSHP-flan-t5-xl').to(device)
>> input_text = "POST: Instacart gave me 50 pounds of limes instead of 5 pounds... what the hell do I do with 50 pounds of limes? I've already donated a bunch and gave a bunch away. I'm planning on making a bunch of lime-themed cocktails, but... jeez. Ceviche? \n\n RESPONSE A: Lime juice, and zest, then freeze in small quantities.\n\n RESPONSE B: Lime marmalade lol\n\n Which response is better? RESPONSE"
>> x = tokenizer([input_text], return_tensors='pt').input_ids.to(device)
>> y = model.generate(x, max_new_tokens=1)
>> tokenizer.batch_decode(y, skip_special_tokens=True)
['A']
如果输入内容超出512个标记的限制,您可以使用pybsd将输入内容拆分成句子,并仅保留符合512标记限制的部分。 在尝试将示例压缩至512个标记时,我们建议尽可能截断上下文内容,并尽量保持响应部分完整无改动。
奖励模型使用方法
若欲将SteamSHP-XL作为奖励模型使用——即获取单个响应的评分——则需要按以下方式组织输入内容:将待评分的响应置于"RESPONSE A"位置,而"RESPONSE B"保持为空输入:
(注:根据项目信息要求,专业名词"SteamSHP-XL"、"RESPONSE A"、"RESPONSE B"及技术工具名称"pybsd/pySBD"均保留原文未翻译,符合技术文档惯例)
POST: { the context, such as the 'history' column in SHP (not containing any newlines \n) }
RESPONSE A: { continuation (not containing any newlines \n) }
RESPONSE B: .
Which response is better? RESPONSE
然后计算分配给标签A的概率。
该概率(或根据您需求的对数几率)即为该响应的得分:
>> input_text = "POST: Instacart gave me 50 pounds of limes instead of 5 pounds... what the hell do I do with 50 pounds of limes? I've already donated a bunch and gave a bunch away. I'm planning on making a bunch of lime-themed cocktails, but... jeez. Ceviche? \n\n RESPONSE A: Lime juice, and zest, then freeze in small quantities.\n\n RESPONSE B: .\n\n Which response is better? RESPONSE"
>> x = tokenizer([input_text], return_tensors='pt').input_ids.to(device)
>> outputs = model.generate(x, return_dict_in_generate=True, output_scores=True, max_new_tokens=1)
>> torch.exp(outputs.scores[0][:, 71]) / torch.exp(outputs.scores[0][:,:]).sum(axis=1).item() # index 71 corresponds to the token for 'A'
0.819
由于 RESPONSE B 仅作为空输入,其概率几乎总是会很高(通常在 0.8 到 1.0 的范围内)。 因此您可能需要对概率进行归一化处理。
您还可以通过比较在相同上下文条件下分别赋予两个响应的独立概率值,来推断偏好标签。 例如,若某个响应概率为 0.95,另一个为 0.80,则前者将被判定为更受偏好。 采用这种方式推断偏好标签,在 SHP + HH-RLHF 测试数据的所有领域平均仅导致准确率下降 0.006,这意味着使用 SteamSHP-XL 作为奖励模型而非偏好模型仅会产生极小的性能损失。
训练与评估
SteamSHP-XL 仅使用了 392K 个可用训练样本中的 125K 进行微调,原因如下:
- 当输入总长度超过限制(512 个词元)时,损失函数无法收敛 我们通过尽可能截断上下文,将样本压缩至 500 个词元以内(尽管部分样本仍会超出限制)。选择 500 而非 512 作为限制阈值,是为了在确保不突破实际 512 限制的前提下,允许对输入结构进行微调
- 使用信号更强的少量偏好数据训练,比使用全部偏好数据能获得更好性能
从 SHP 数据集中,我们仅选取更受偏好评论的偏好度是另一条两倍以上的样本(即
score_ratio>= 2),且每个上下文最多使用 5 条偏好数据(即每个唯一post_id对应 5 个样本)以防止过拟合。对于 HH-RLHF 训练数据则未进行此类子采样
我们在 SHP 和 HH-RLHF 测试数据上采用准确率进行评估,但仅针对可截断至 500 词元以内的数据(总计 20753 个测试样本中的 18621 个)。 SteamSHP-XL 在所有领域的平均准确率达到 72.8%:
| 领域 | 准确率 |
|---|---|
| 烹饪咨询 | 0.7199 |
| 人力资源咨询 | 0.7743 |
| 医疗咨询 | 0.7210 |
| 人类学咨询 | 0.7594 |
| 科幻咨询 | 0.7283 |
| 学术咨询 | 0.7442 |
| 工程咨询 | 0.7183 |
| 法律咨询 | 0.8068 |
| 通俗解释 | 0.7392 |
| 烘焙咨询 | 0.6741 |
| 物理咨询 | 0.8000 |
| 科学咨询 | 0.7114 |
| 哲学咨询 | 0.6907 |
| 兽医咨询 | 0.7742 |
| 观点辩论 | 0.7043 |
| 汽车咨询 | 0.7568 |
| 历史咨询 | 0.7476 |
| 社会科学咨询 | 0.7308 |
| Anthropic(帮助性) | 0.7310 |
| 全体(未加权) | 0.7278 |
如前所述,若将 SteamSHP 作为奖励模型,并基于各自独立的响应概率推断偏好标签,该方法同样有效! 但这样做会使测试数据准确率平均下降 0.006(所有领域平均值),意味着需要承担轻微的性能损失。
偏见与局限性
SteamSHP 的训练目标是预测人类认为哪两个回应中更有帮助的一个,而非判断哪个回应危害更小。
该模型不应用于检测毒性内容、进行道德评判或类似用途。
用于训练 SteamSHP 的数据集中存在的偏见和错误信息可能会向下游传递至模型预测中。
尽管 SHP 过滤了包含 NSFW(18岁以上)内容的帖子,并选择了管理规范、反对骚扰和偏见的 subreddit 社区,但部分数据仍可能包含歧视性或有害言论。
人类普遍认为更有帮助的回应也未必更具事实准确性。
SHP 和 HH-RLHF 所捕捉的偏好数据并不能代表更广泛的人群特征。
虽然具体人口统计信息尚未公开,但总体而言,SHP 中记录的 Reddit 用户偏好数据存在明显偏差:男性用户、发达国家用户以及英语国家用户占比过高(据皮尤研究中心数据)。
Anthropic 的既往研究发现,针对人类偏好优化的模型可能会为迎合偏好而牺牲事实准确性。
联系我们
如有关于模型的疑问,请联系 kawin@stanford.edu。
本模型由 Kawin Ethayarajh、Heidi (Chenyu) Zhang、Yizhong Wang 和 Dan Jurafsky 共同开发。
引用规范
SHP 基于以下论文提出的技术构建。若使用 SHP 或 SteamSHP 系列模型,请引用该研究成果:
@InProceedings{pmlr-v162-ethayarajh22a,
title = {Understanding Dataset Difficulty with $\mathcal{V}$-Usable Information},
author = {Ethayarajh, Kawin and Choi, Yejin and Swayamdipta, Swabha},
booktitle = {Proceedings of the 39th International Conference on Machine Learning},
pages = {5988--6008},
year = {2022},
editor = {Chaudhuri, Kamalika and Jegelka, Stefanie and Song, Le and Szepesvari, Csaba and Niu, Gang and Sabato, Sivan},
volume = {162},
series = {Proceedings of Machine Learning Research},
month = {17--23 Jul},
publisher = {PMLR},
}