开始使用免费开始使用

定义评估指标

您正在为一款视频会议应用开发实时语言翻译服务。为便于监控训练过程,您将定义准确率和 F1 分数这两个评估指标,用于衡量模型的整体表现。

evaluatenumpynp)库已预先导入。

本练习是课程的一部分

使用 PyTorch 高效训练 AI 模型

查看课程

练习说明

  • 使用 evaluate 库加载 f1 分数;accuracy 已为您加载好。
  • eval_predictions 解包为两个变量,以提取 logitslabels
  • logits 转换为 predictions
  • 基于 predictionslabels 计算 f1 分数。

交互式实操练习

通过完成这段示例代码来试试这个练习。

def compute_metrics(eval_predictions):
    load_accuracy = evaluate.load("accuracy")
  	# Load the F1 score
    load_f1 = evaluate.load("____")
    # Extract logits and labels from eval_predictions
    logits, ____ = eval_predictions
    # Convert logits to predictions
    predictions = np.____(logits, axis=-1)
    accuracy = load_accuracy.compute(predictions=predictions, references=labels)["accuracy"]
    # Compute the F1 score
    f1 = ____.____(predictions=predictions, references=labels)["f1"]
    return {"accuracy": accuracy, "f1": f1}
编辑并运行代码