danielle2003 commited on
Commit
4939d74
·
1 Parent(s): 24cc0f4
Files changed (1) hide show
  1. scripts/evaluate.py +10 -5
scripts/evaluate.py CHANGED
@@ -1,19 +1,24 @@
1
- from transformers import pipeline
2
  from datasets import load_dataset
3
  from sklearn.metrics import accuracy_score, f1_score
4
 
5
  # Load dataset
6
  dataset = load_dataset("allocine")["test"]
 
7
 
8
- # Load model
9
- classifier = pipeline("text-classification", model="./models")
 
 
 
 
 
10
 
11
  # Get predictions
12
- predictions = [classifier(text["review"])[0]["label"] for text in dataset]
13
  labels = dataset["label"]
14
 
15
  # Convert labels
16
- label_map = {"LABEL_0": 0, "LABEL_1": 1, "LABEL_2": 2}
17
  predictions = [label_map[p] for p in predictions]
18
 
19
  # Compute metrics
 
1
+ from transformers import pipeline, AutoModelForSequenceClassification
2
  from datasets import load_dataset
3
  from sklearn.metrics import accuracy_score, f1_score
4
 
5
  # Load dataset
6
  dataset = load_dataset("allocine")["test"]
7
+ dataset["test"] = dataset["test"].select(range(5)) # Test on 200 samples
8
 
9
+ # Load model and tokenizer
10
+ model_path = "./models"
11
+ classifier = pipeline("text-classification", model=model_path, tokenizer=model_path)
12
+
13
+ # Get actual model labels
14
+ model = AutoModelForSequenceClassification.from_pretrained(model_path)
15
+ label_map = {v: k for k, v in model.config.label2id.items()} # Adjust dynamically
16
 
17
  # Get predictions
18
+ predictions = [classifier(text["review"], truncation=True, max_length=512)[0]["label"] for text in dataset]
19
  labels = dataset["label"]
20
 
21
  # Convert labels
 
22
  predictions = [label_map[p] for p in predictions]
23
 
24
  # Compute metrics