Chuẩn bị dữ liệu cho RLHF

Reinforcement Learning from Human Feedback (RLHF)

Mina Parham

AI Engineer

Bộ dữ liệu Ưu tiên vs. Prompt

Quy trình RLHF đầy đủ.

Reinforcement Learning from Human Feedback (RLHF)

Bộ dữ liệu Ưu tiên vs. Prompt

Quy trình RLHF đầy đủ với bộ dữ liệu prompt ban đầu.

Reinforcement Learning from Human Feedback (RLHF)

Bộ dữ liệu Ưu tiên vs. Prompt

Quy trình RLHF đầy đủ với bộ dữ liệu prompt ban đầu và bộ dữ liệu ưu tiên dùng để huấn luyện mô hình phần thưởng.

Reinforcement Learning from Human Feedback (RLHF)

Bộ dữ liệu Prompt

  • Câu hỏi cho mô hình
  • Có trên Hugging Face Datasets
prompt_data = load_dataset("center-for-humans-and-machines/rlhf-hackathon-prompts", 
                           split="train")
prompt_data['prompt'][0]
'Tầm quan trọng của biến đổi khí hậu là gì?'
  • Có thể cần trích xuất prompt
  • Tìm các dấu như: Input=, {{Text}}:, ###Human:
Reinforcement Learning from Human Feedback (RLHF)

Khám phá bộ dữ liệu ưu tiên

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

Ảnh chụp nền tảng Hugging Face hiển thị bộ dữ liệu hh-rlhf.

Reinforcement Learning from Human Feedback (RLHF)

Xử lý bộ dữ liệu ưu tiên

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'])}
)
  • Cách trích xuất prompt khác nhau theo từng bộ dữ liệu
Reinforcement Learning from Human Feedback (RLHF)

Bộ dữ liệu ưu tiên cuối cùng

sample = preference_data_with_prompt.select(range(1))
sample['prompt']
'Những vitamin nào thiết yếu cho cơ thể hoạt động?'
sample['chosen']
[ { "content": "Những vitamin nào thiết yếu cho cơ thể hoạt động?", "role": 
   "user" }, { "content": "Có một số vitamin rất quan trọng đảm bảo cơ thể hoạt 
   động bình thường, gồm vitamin A, C, D, E và K cùng ...}]
Reinforcement Learning from Human Feedback (RLHF)

Ayo berlatih!

Reinforcement Learning from Human Feedback (RLHF)

Preparing Video For Download...