開始使用免費開始

定義評估指標

你正在為視訊會議應用程式開發即時語言翻譯服務。為了監控訓練進度,你將定義 accuracy 與 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}
編輯並執行程式碼