Spaces:
Sleeping
Sleeping
File size: 686 Bytes
2b3de4f |
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 |
from transformers import pipeline
from datasets import load_dataset
from sklearn.metrics import accuracy_score, f1_score
# Load dataset
dataset = load_dataset("allocine")["test"]
# Load model
classifier = pipeline("text-classification", model="./models")
# Get predictions
predictions = [classifier(text["review"])[0]["label"] for text in dataset]
labels = dataset["label"]
# Convert labels
label_map = {"LABEL_0": 0, "LABEL_1": 1, "LABEL_2": 2}
predictions = [label_map[p] for p in predictions]
# Compute metrics
accuracy = accuracy_score(labels, predictions)
f1 = f1_score(labels, predictions, average="weighted")
print(f"Accuracy: {accuracy:.4f}")
print(f"F1-score: {f1:.4f}")
|