การเตรียมข้อมูลสำหรับ RLHF

Reinforcement Learning from Human Feedback (RLHF)

Mina Parham

AI Engineer

Preference dataset กับ Prompt dataset

กระบวนการ RLHF แบบครบวงจร

Reinforcement Learning from Human Feedback (RLHF)

Preference dataset กับ Prompt dataset

กระบวนการ RLHF แบบครบวงจรพร้อม prompt dataset เริ่มต้น

Reinforcement Learning from Human Feedback (RLHF)

Preference dataset กับ Prompt dataset

กระบวนการ RLHF แบบครบวงจรพร้อม prompt dataset เริ่มต้นและ preference dataset ที่ป้อนเข้า reward model

Reinforcement Learning from Human Feedback (RLHF)

Prompt dataset

  • คำถามสำหรับโมเดล
  • หาได้จาก Hugging Face datasets
prompt_data = load_dataset("center-for-humans-and-machines/rlhf-hackathon-prompts", 
                           split="train")
prompt_data['prompt'][0]
'How important is climate change?'
  • อาจต้องดึง prompt ออกมา
  • มองหา marker เช่น Input=, {{Text}}:, ###Human:
Reinforcement Learning from Human Feedback (RLHF)

สำรวจ preference dataset

from datasets import load_dataset
preference_data = load_dataset("trl-internal-testing/hh-rlhf-helpful-base-trl-style", 
                               split="train")

ภาพหน้าจอของแพลตฟอร์ม Hugging Face แสดง hh-rlhf dataset

Reinforcement Learning from Human Feedback (RLHF)

ประมวลผล preference dataset

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'])}
)
  • วิธีดึง prompt แตกต่างกันในแต่ละ dataset
Reinforcement Learning from Human Feedback (RLHF)

preference dataset ฉบับสมบูรณ์

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 ...}]
Reinforcement Learning from Human Feedback (RLHF)

มาฝึกกันเถอะ!

Reinforcement Learning from Human Feedback (RLHF)

Preparing Video For Download...