准备偏好数据集
在本练习中,您将使用一个包含人工反馈的数据集,反馈以 "chosen" 和 "rejected" 的输出形式给出。您的任务是从 "chosen" 列中提取提示(prompt),并为奖励模型的训练准备数据。
datasets 中的 load_dataset 函数已预先导入。
本练习是课程的一部分
来自人类反馈的强化学习(RLHF)
练习说明
- 从 Hugging Face 加载
trl-internal-testing/hh-rlhf-helpful-base-trl-style数据集。 - 编写一个函数,从
'content'字段中提取 prompt,假设该函数的输入中,prompt 位于索引0的位置。 - 将提取 prompt 的函数应用到
'chosen'数据集子集。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Load the dataset
preference_data = ____
# Define a function to extract the prompt
def extract_prompt(text):
____
return prompt
# Apply the function to the dataset
preference_data_with_prompt = ____(
lambda sample: {**sample, 'prompt': ____(sample['chosen'])}
)
sample = preference_data_with_prompt.select(range(1))
print(sample['prompt'])