開始使用免費開始

準備偏好資料集

在這個練習中,你會使用一個包含人類回饋的資料集,形式為「chosen」與「rejected」輸出。你的目標是從「chosen」欄位中擷取提示(prompt),並為訓練獎勵模型準備資料。

datasetsload_dataset 函式已預先匯入。

本練習屬於課程

Reinforcement Learning from Human Feedback(RLHF)

檢視課程

練習說明

  • 從 Hugging Face 載入 trl-internal-testing/hh-rlhf-helpful-base-trl-style 資料集。
  • 撰寫一個函式,從 'content' 欄位中擷取提示(prompt),並假設提示位於該函式輸入的索引 0
  • 將這個擷取提示的函式套用到 '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'])
編輯並執行程式碼