การเตรียมชุดข้อมูล 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 อยู่ที่ index0ของ 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'])