-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmetrics.py
41 lines (34 loc) · 1 KB
/
metrics.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import numpy as np
from datasets import load_metric
def compute_metrics(eval_pred):
recall_metric = load_metric('recall')
f1_metric = load_metric('f1')
accuracy_metric = load_metric('accuracy')
precision_metric = load_metric('precision')
logits, labels = eval_pred
predictions = np.argmax(logits, axis=-1)
recall = recall_metric.compute(
predictions=predictions,
references=labels,
average='macro'
)['recall']
f1 = f1_metric.compute(
predictions=predictions,
references=labels,
average='macro'
)['f1']
accuracy = accuracy_metric.compute(
predictions=predictions,
references=labels
)['accuracy']
precision = precision_metric.compute(
predictions=predictions,
references=labels,
average='macro'
)['precision']
return {
'recall': recall,
'f1': f1,
'accuracy': accuracy,
'precision': precision
}