为 RLHF 准备数据

来自人类反馈的强化学习(RLHF)

Mina Parham

AI Engineer

偏好数据集 vs. 提示数据集

完整的 RLHF 流程。

来自人类反馈的强化学习(RLHF)

偏好数据集 vs. 提示数据集

包含初始提示数据集的完整 RLHF 流程。

来自人类反馈的强化学习(RLHF)

偏好数据集 vs. 提示数据集

包含初始提示数据集与馈入奖励模型的偏好数据集的完整 RLHF 流程。

来自人类反馈的强化学习(RLHF)

提示数据集

  • 面向模型的问题
  • 可在 Hugging Face 数据集上找到
prompt_data = load_dataset("center-for-humans-and-machines/rlhf-hackathon-prompts", 
                           split="train")
prompt_data['prompt'][0]
'How important is climate change?'
  • 可能需要提取提示
  • 查找如下标记:Input=、{{Text}}:、###Human:
来自人类反馈的强化学习(RLHF)

探索偏好数据集

from datasets import load_dataset
preference_data = load_dataset("qgallouedec/hh-rlhf-helpful-base-trl-style", 
                               split="train")
来自人类反馈的强化学习(RLHF)

处理偏好数据集

def extract_prompt(text):
    # Extract the prompt as the first element in the list
    prompt = text[0]["content"]
    return prompt
# Apply the extraction function to the dataset
preference_data_with_prompt = preference_data.map(
    lambda example: {**example, 'prompt': extract_prompt(example['chosen'])}
)
  • 不同数据集的提示提取方式各不相同
来自人类反馈的强化学习(RLHF)

最终的偏好数据集

sample = preference_data_with_prompt.select(range(1))
sample['prompt']
'What vitamins are essential for the body to function?'
sample['chosen']
[ { "content": "What vitamins are essential for the body to function?", "role": 
   "user" }, { "content": "There are some very important vitamins that ensure the 
   proper functioning of the body, including Vitamins A, C, D, E, and K along ...}]
来自人类反馈的强化学习(RLHF)

让我们一起练习吧!

来自人类反馈的强化学习(RLHF)

Preparing Video For Download...