File size: 792 Bytes
9249e5d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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