C.W.K.
Stream
Lesson 03 of 08 · published

Eval Metric 과 evaluate 라이브러리

~24 min · training, eval, metrics

Level 0스카우트
0 XP0/50 lessons0/10 achievements
0/120 XP to next level120 XP to go0% complete

compute_metrics 시그니처

Trainer 가 eval_steps 마다 compute_metrics(pred) 호출. pred.predictions 가 raw logit/예측; pred.label_ids 가 gold. dict 돌려주면 Trainer 가 로깅 + 추적.

evaluate 라이브러리

HF evaluate 라이브러리가 표준 metric wrap: accuracy, F1, BLEU, ROUGE, METEOR, BERTScore, perplexity, exact_match, 수십 개. 각각 데이터셋처럼 Hub 에서 로드: evaluate.load("accuracy"). metric 객체가 one-shot eval 엔 compute(), streaming aggregation 엔 add_batch() expose.

loss 표면에 매치되는 metric 골라

Accuracy 는 균형 분류용. 불균형 클래스엔 F1. translation/summarization 엔 BLEU/ROUGE 지만 짧은 응답에 human judgment 와 weakly correlate — 의미적 유사도 metric (BERTScore, embedding cosine) 과 페어해 챗 eval.

Code

evaluate 와 compute_metrics·python
import evaluate
import numpy as np

f1 = evaluate.load("f1")
acc = evaluate.load("accuracy")

def metrics(pred):
    preds = pred.predictions.argmax(-1)
    return {
        "accuracy": acc.compute(predictions=preds, references=pred.label_ids)["accuracy"],
        "f1_macro": f1.compute(predictions=preds, references=pred.label_ids, average="macro")["f1"],
    }
큰 eval 셋의 streaming aggregation·python
import evaluate
acc = evaluate.load("accuracy")

# 100k eval set 가정; pred 한 번에 다 materialize 원치 않음.
for batch in eval_loader:
    with torch.no_grad():
        preds = model(**batch).logits.argmax(-1)
    acc.add_batch(predictions=preds.cpu().numpy(), references=batch["labels"].cpu().numpy())

print(acc.compute())

External links

Exercise

0 번 레슨의 IMDB run 에 compute_metrics 추가. accuracy, F1 macro, F1 weighted 추적. TensorBoard 가 셋 다 보이는지 검증. 어떤 게 끝에 가장 높은가? 어떤 게 가장 fluctuate? 샘플 리뷰 몇 개에 human-perceived quality 가장 잘 예측?

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.