เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

การเตรียมชุดข้อมูล preference

ในแบบฝึกหัดนี้ คุณจะทำงานกับชุดข้อมูลที่มี feedback จากมนุษย์ในรูปแบบของ output ที่ "chosen" และ "rejected" โดยมีเป้าหมายคือดึง prompt จากคอลัมน์ "chosen" และเตรียมข้อมูลสำหรับการเทรน reward model

ฟังก์ชัน load_dataset จากไลบรารี datasets ได้ถูก import ไว้ให้แล้ว

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

Reinforcement Learning from Human Feedback (RLHF)

ดูคอร์ส

คำแนะนำการฝึกหัด

  • โหลดชุดข้อมูล trl-internal-testing/hh-rlhf-helpful-base-trl-style จาก Hugging Face
  • เขียนฟังก์ชันที่ดึง prompt จากฟิลด์ 'content' โดยสมมติว่า prompt อยู่ที่ index 0 ของ input ที่รับเข้ามา
  • นำฟังก์ชันที่ดึง prompt ไปใช้กับ subset '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'])
แก้ไขและรันโค้ด