Define evaluation metrics
You're developing a real-time language translation service in a video conferencing application. To monitor training, you'll define evaluation metrics for accuracy and F1 score, which measure overall model performance.
The evaluate and numpy (np) libraries have been pre-imported.
本练习是课程的一部分
Efficient AI Model Training with PyTorch
练习说明
- Load the
f1score using theevaluatelibrary;accuracyhas been loaded for you. - Extract
logitsandlabelsby unpackingeval_predictionsinto two variables. - Convert
logitstopredictions. - Compute the
f1score based on thepredictionsandlabels.
交互式实操练习
通过完成这段示例代码来试试这个练习。
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}