开始使用免费开始使用

设置 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 函数返回准确率和 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.____)
编辑并运行代码