設定 Trainer
你的模型會將艱澀的片語替換成更簡單、容易理解的轉述,來提升翻譯的可讀性。例如,它可以把原句「The inclement weather conditions precipitated the postponement of the outdoor event」簡化為「The bad weather caused the outdoor event to be delayed.」。建立 Trainer,為訓練你的語言翻譯服務做好準備!這個練習在呼叫 trainer.train() 後需要一點時間執行。
部分資料已預先載入:
model是一個 Transformer 模型dataset包含句子轉述的 MRPC 資料集compute_metrics函式會回傳 accuracy 與 F1 分數- 你已在前一題定義好
training_args
本練習屬於課程
使用 PyTorch 高效訓練 AI 模型
練習說明
- 將
model傳入Trainer()類別。 - 在
Trainer()類別中輸入訓練參數。 - 將計算評估指標的函式傳入
Trainer()類別。 - 印出
trainer所選擇的裝置。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
trainer = Trainer(
# Pass in the model
model=____,
# Input the training arguments
args=____,
train_dataset=dataset["train"],
eval_dataset=dataset["validation"],
# Pass in a function to compute metrics
compute_metrics=____,
)
trainer.train()
# Print the device that the trainer chooses
print(trainer.args.____)