평가 메트릭 정의하기
화상 회의 애플리케이션에 실시간 언어 번역 서비스를 개발하고 있습니다. 학습 과정을 모니터링하기 위해 모델의 전반적인 성능을 측정하는 정확도(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}