Spaces:
Sleeping
Sleeping
Delete evaluate.py
Browse files- evaluate.py +0 -41
evaluate.py
DELETED
|
@@ -1,41 +0,0 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
from transformers import TFBertForSequenceClassification, BertTokenizer
|
| 3 |
-
import tensorflow as tf
|
| 4 |
-
import praw
|
| 5 |
-
import os
|
| 6 |
-
import pytesseract
|
| 7 |
-
from PIL import Image
|
| 8 |
-
import cv2
|
| 9 |
-
import numpy as np
|
| 10 |
-
import re
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 14 |
-
import torch
|
| 15 |
-
from scipy.special import softmax
|
| 16 |
-
import matplotlib.pyplot as plt
|
| 17 |
-
import pandas as pd
|
| 18 |
-
def get_classification_report():
|
| 19 |
-
from sklearn.metrics import classification_report
|
| 20 |
-
import pandas as pd
|
| 21 |
-
|
| 22 |
-
# Load your test data
|
| 23 |
-
df = pd.read_csv("test.csv")
|
| 24 |
-
texts = df["text"].tolist()
|
| 25 |
-
true_labels = df["label"].tolist()
|
| 26 |
-
|
| 27 |
-
# Load tokenizer and model
|
| 28 |
-
#tokenizer = AutoTokenizer.from_pretrained("Shrish/mbert-sentiment")
|
| 29 |
-
#model = TFAutoModelForSequenceClassification.from_pretrained("Shrish/mbert-sentiment")
|
| 30 |
-
fallback_model_name = "cardiffnlp/twitter-roberta-base-sentiment"
|
| 31 |
-
tokenizer = AutoTokenizer.from_pretrained(fallback_model_name)
|
| 32 |
-
model = AutoModelForSequenceClassification.from_pretrained(fallback_model_name)
|
| 33 |
-
|
| 34 |
-
# Tokenize and predict
|
| 35 |
-
inputs = tokenizer(texts, padding=True, truncation=True, return_tensors="tf")
|
| 36 |
-
outputs = model(inputs)
|
| 37 |
-
predictions = tf.math.argmax(outputs.logits, axis=1).numpy()
|
| 38 |
-
|
| 39 |
-
# Generate report
|
| 40 |
-
report = classification_report(true_labels, predictions, target_names=["negative", "neutral", "positive"])
|
| 41 |
-
return report
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|