Create evaluate.py
Browse files- evaluate.py +21 -0
evaluate.py
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
def get_classification_report():
|
2 |
+
from sklearn.metrics import classification_report
|
3 |
+
import pandas as pd
|
4 |
+
|
5 |
+
# Load your test data
|
6 |
+
df = pd.read_csv("test.csv")
|
7 |
+
texts = df["text"].tolist()
|
8 |
+
true_labels = df["label"].tolist()
|
9 |
+
|
10 |
+
# Load tokenizer and model
|
11 |
+
tokenizer = AutoTokenizer.from_pretrained("Shrish/mbert-sentiment")
|
12 |
+
model = TFAutoModelForSequenceClassification.from_pretrained("Shrish/mbert-sentiment")
|
13 |
+
|
14 |
+
# Tokenize and predict
|
15 |
+
inputs = tokenizer(texts, padding=True, truncation=True, return_tensors="tf")
|
16 |
+
outputs = model(inputs)
|
17 |
+
predictions = tf.math.argmax(outputs.logits, axis=1).numpy()
|
18 |
+
|
19 |
+
# Generate report
|
20 |
+
report = classification_report(true_labels, predictions, target_names=["negative", "neutral", "positive"])
|
21 |
+
return report
|