Spaces:
Sleeping
Sleeping
Commit
·
e631481
1
Parent(s):
6e15199
require
Browse files- scripts/evaluate.py +4 -4
scripts/evaluate.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
import torch
|
2 |
-
from transformers import pipeline, AutoModelForSequenceClassification
|
3 |
from datasets import load_dataset
|
4 |
from sklearn.metrics import accuracy_score, f1_score
|
5 |
|
@@ -15,14 +15,14 @@ classifier = pipeline("text-classification", model=model_path, tokenizer=model_p
|
|
15 |
|
16 |
# Load model to get dynamic label mapping
|
17 |
model = AutoModelForSequenceClassification.from_pretrained(model_path)
|
18 |
-
label_map =
|
19 |
|
20 |
# Get predictions
|
21 |
predictions = [classifier(text["review"], truncation=True, max_length=512)[0]["label"] for text in dataset]
|
22 |
labels = dataset["label"]
|
23 |
|
24 |
-
# Convert labels
|
25 |
-
predictions = [
|
26 |
|
27 |
# Compute metrics
|
28 |
accuracy = accuracy_score(labels, predictions)
|
|
|
1 |
import torch
|
2 |
+
from transformers import pipeline, AutoModelForSequenceClassification
|
3 |
from datasets import load_dataset
|
4 |
from sklearn.metrics import accuracy_score, f1_score
|
5 |
|
|
|
15 |
|
16 |
# Load model to get dynamic label mapping
|
17 |
model = AutoModelForSequenceClassification.from_pretrained(model_path)
|
18 |
+
label_map = model.config.label2id # Correct direct mapping {LABEL_X: int}
|
19 |
|
20 |
# Get predictions
|
21 |
predictions = [classifier(text["review"], truncation=True, max_length=512)[0]["label"] for text in dataset]
|
22 |
labels = dataset["label"]
|
23 |
|
24 |
+
# Convert labels (direct mapping)
|
25 |
+
predictions = [label_map[p] for p in predictions]
|
26 |
|
27 |
# Compute metrics
|
28 |
accuracy = accuracy_score(labels, predictions)
|