shrish191 commited on
Commit
61313a4
·
verified ·
1 Parent(s): cc1f22a

Create evaluate.py

Browse files
Files changed (1) hide show
  1. evaluate.py +26 -0
evaluate.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import AutoTokenizer, TFAutoModelForSequenceClassification
2
+ from sklearn.metrics import classification_report
3
+ import tensorflow as tf
4
+ import pandas as pd
5
+
6
+ def get_classification_report():
7
+ try:
8
+ # Load test data
9
+ df = pd.read_csv("test.csv")
10
+ texts = df["text"].tolist()
11
+ true_labels = df["label"].tolist()
12
+
13
+ # Load tokenizer and model
14
+ tokenizer = AutoTokenizer.from_pretrained("Shrish/mbert-sentiment")
15
+ model = TFAutoModelForSequenceClassification.from_pretrained("Shrish/mbert-sentiment")
16
+
17
+ # Tokenize
18
+ inputs = tokenizer(texts, padding=True, truncation=True, return_tensors="tf")
19
+ outputs = model(inputs)
20
+ preds = tf.math.argmax(outputs.logits, axis=1).numpy()
21
+
22
+ # Generate report
23
+ report = classification_report(true_labels, preds, target_names=["negative", "neutral", "positive"])
24
+ return report
25
+ except Exception as e:
26
+ return f"⚠️ Error occurred: {str(e)}"