shrish191's picture
Create evaluate.py
9249e5d verified
raw
history blame
792 Bytes
def get_classification_report():
from sklearn.metrics import classification_report
import pandas as pd
# Load your test data
df = pd.read_csv("test.csv")
texts = df["text"].tolist()
true_labels = df["label"].tolist()
# Load tokenizer and model
tokenizer = AutoTokenizer.from_pretrained("Shrish/mbert-sentiment")
model = TFAutoModelForSequenceClassification.from_pretrained("Shrish/mbert-sentiment")
# Tokenize and predict
inputs = tokenizer(texts, padding=True, truncation=True, return_tensors="tf")
outputs = model(inputs)
predictions = tf.math.argmax(outputs.logits, axis=1).numpy()
# Generate report
report = classification_report(true_labels, predictions, target_names=["negative", "neutral", "positive"])
return report