定義評估指標
你正在為視訊會議應用程式開發即時語言翻譯服務。為了監控訓練進度,你將定義 accuracy 與 F1 指標,用來衡量整體模型效能。
evaluate 與 numpy(np)函式庫已預先匯入。
本練習屬於課程
使用 PyTorch 高效訓練 AI 模型
練習說明
- 使用
evaluate函式庫載入f1指標;accuracy已替你載入。 - 將
eval_predictions解構為兩個變數,取得logits與labels。 - 將
logits轉換為predictions。 - 根據
predictions與labels計算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}