初始化 PPO 訓練器
你在一家客服公司工作,該公司使用聊天機器人來處理顧客詢問。這個聊天機器人的回覆具備幫助性,但你最近收到回饋,指出內容深度不夠。你需要微調這個聊天機器人背後的模型,而你會先從建立一個 PPO 訓練器實例開始。
dataset_cs 已經載入完成。
本練習屬於課程
Reinforcement Learning from Human Feedback(RLHF)
練習說明
- 使用模型名稱
"gpt2"與學習率1.2e-5初始化 PPO 設定。 - 載入
AutoModelForCausalLMWithValueHead,也就是帶有 value head 的因果語言模型。 - 使用剛剛定義的模型、設定與 tokenizer,再加上已預先載入的資料集,建立
PPOTrainer()。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
from trl import PPOConfig, AutoModelForCausalLMWithValueHead, PPOTrainer
from transformers import AutoTokenizer
# Initialize PPO Configuration
gpt2_config = ____(model_name=____, learning_rate=____)
# Load the model
gpt2_model = ____(gpt2_config.model_name)
gpt2_tokenizer = AutoTokenizer.from_pretrained(gpt2_config.model_name)
# Initialize PPO Trainer
ppo_trainer = ____