-
Notifications
You must be signed in to change notification settings - Fork 0
/
ETHOS_Benchmark.py
36 lines (29 loc) · 1.09 KB
/
ETHOS_Benchmark.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
from datasets import load_dataset
from model import classify_text
from sklearn.metrics import accuracy_score, precision_recall_fscore_support
import os
import numpy as np
root = os.path.dirname(os.path.abspath(__file__))
test_texts_path = os.path.join(root, 'Split Data', 'text_test.npy')
# Load the test texts from the .npy file
test_texts = np.load(test_texts_path, allow_pickle=True)
# Load the Ethos dataset
ds_ethos = load_dataset('ethos', 'binary')
def compute_metrics(pred_labels, true_labels):
accuracy = accuracy_score(true_labels, pred_labels)
precision, recall, f1, _ = precision_recall_fscore_support(true_labels, pred_labels, average='binary')
return {
"accuracy": accuracy,
"precision": precision,
"recall": recall,
"f1": f1
}
preds = []
real = []
# Iterate over the 'train' split of the Ethos dataset
for example in ds_ethos['train']:
if example['text'] in test_texts:
preds.append(classify_text(example['text']))
real.append(example['label'])
metrics = compute_metrics(preds, real)
print(f'Validation Metrics: {metrics}')