evaluate 라이브러리

Python으로 배우는 LLM 입문

Jasmin Ludolf

Senior Data Science Content Developer, DataCamp

evaluate 라이브러리

import evaluate

accuracy = evaluate.load("accuracy")
print(accuracy.description)
정확도(Accuracy)는 처리된 전체 사례 중
정답 예측의 비율입니다. 계산식:
Accuracy = (TP + TN) / (TP + TN + FP + FN)
용어:
TP: 실제 양성(참양성)
TN: 실제 음성(참음성)
FP: 거짓 양성(위양성)
FN: 거짓 음성(위음성)

 

  • 지표: 정답 기준으로 모델 성능 평가

 

  • 비교: 두 모델 성능 비교

 

  • 측정: 데이터셋 특성 파악에 도움
Python으로 배우는 LLM 입문

Features 속성

print(accuracy.features)
{'predictions': Value(dtype='int32', id=None),
 'references': Value(dtype='int32', id=None)}

지표에 필요한 입력 확인

  • 'predictions': 모델 출력
  • 'references': 정답(ground truth)
  • .features: 클래스 라벨 지원 타입 표시, 예: 'int32', 'float32'
f1 = evaluate.load("f1")
print(f1.features)
{'predictions': Value(dtype='int32', id=None),
 'references': Value(dtype='int32', id=None)}
pearson_corr = evaluate.load("pearsonr")
print(pearson_corr.features)
{'predictions': Value(dtype='float32', id=None),
'references': Value(dtype='float32', id=None)}
Python으로 배우는 LLM 입문

LLM 작업과 지표

 

언어 작업의 평가 지표

Python으로 배우는 LLM 입문

LLM 작업과 지표

 

언어 작업의 평가 지표

Python으로 배우는 LLM 입문

분류 지표

accuracy = evaluate.load("accuracy")
precision = evaluate.load("precision")
recall = evaluate.load("recall")
f1 = evaluate.load("f1")
from transformers import pipeline

classifier = pipeline("text-classification", model=model, tokenizer=tokenizer)

predictions = classifier(evaluation_text)

predicted_labels = [1 if pred["label"] == "POSITIVE" else 0 for pred in predictions]
Python으로 배우는 LLM 입문

지표 출력

real_labels = [0,1,0,1,1]
predicted_labels = [0,0,0,1,1]

print(accuracy.compute(references=real_labels, predictions=predicted_labels))
print(precision.compute(references=real_labels, predictions=predicted_labels))
print(recall.compute(references=real_labels, predictions=predicted_labels))
print(f1.compute(references=real_labels, predictions=predicted_labels))
{'accuracy': 0.8}
{'precision': 1.0}
{'recall': 0.6666666666666666}
{'f1': 0.8}
Python으로 배우는 LLM 입문

파인튜닝 모델 평가

# 저장된 모델과 토크나이저를 
# .from_pretrained("my_finetuned_files")로 로드


new_data = ["This is movie was disappointing!", "This is the best movie ever!"] new_input = tokenizer(new_data, return_tensors="pt", padding=True, truncation=True, max_length=64) with torch.no_grad(): outputs = model(**new_input) predicted = torch.argmax(outputs.logits, dim=1).tolist()
real = [0,1]
print(accuracy.compute(references=real,
                       predictions=predicted))
print(precision.compute(references=real,
                        predictions=predicted))
print(recall.compute(references=real,
                     predictions=predicted))
print(f1.compute(references=real, 
                 predictions=predicted))
{'accuracy': 1.0}
{'precision': 1.0}
{'recall': 1.0}
{'f1': 1.0}
Python으로 배우는 LLM 입문

올바른 지표 선택

 

  • 유의: 각 지표는 고유한 인사이트와 _한계_가 있습니다

 

  • 종합: 여러 지표와 가능하면 도메인 KPI를 함께 사용하십시오

인식, 사고, 의사결정을 상징하는 전구가 있는 두뇌 일러스트.

Python으로 배우는 LLM 입문

연습해 봅시다!

Python으로 배우는 LLM 입문

Preparing Video For Download...