Spaces:
Runtime error
Runtime error
Jeffrey Rathgeber Jr
commited on
test_pred
Browse files
app.py
CHANGED
@@ -17,12 +17,11 @@ option = st.selectbox('Which pre-trained model would you like for your sentiment
|
|
17 |
st.write('You selected:', option)
|
18 |
|
19 |
if option == 'MILESTONE 3':
|
20 |
-
|
21 |
-
#
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
# classifier_0 = pipeline(task="sentiment-analysis", model=model_0, tokenizer=tokenizer_0)
|
26 |
|
27 |
# model_name_1 = "Rathgeberj/milestone3_1"
|
28 |
# # model_1 = AutoModelForSequenceClassification.from_pretrained(model_name_1)
|
@@ -58,8 +57,18 @@ if option == 'MILESTONE 3':
|
|
58 |
# tokenizers = [tokenizer_0, tokenizer_1, tokenizer_2, tokenizer_3, tokenizer_4, tokenizer_5]
|
59 |
# classifiers = [classifier_0, classifier_1, classifier_2, classifier_3, classifier_4, classifier_5]
|
60 |
|
61 |
-
|
62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
col = ['Tweet', 'Highest_Toxicity_Class_Overall', 'Score_Overall', 'Highest_Toxicity_Class_Except_Toxic', 'Score_Except_Toxic']
|
64 |
df = pd.DataFrame(columns=col)
|
65 |
pre_populated_tweets = ['Yo bitch Ja Rule is more succesful then youll ever be whats up with you and hating you sad mofuckas...i should bitch slap ur pethedic white faces and get you to kiss my ass you guys sicken me. Ja rule is about pride in da music man. dont diss that shit on him. and nothin is wrong bein like tupac he was a brother too...fuckin white boys get things right next time.',
|
|
|
17 |
st.write('You selected:', option)
|
18 |
|
19 |
if option == 'MILESTONE 3':
|
20 |
+
model_name_0 = "Rathgeberj/milestone3_0"
|
21 |
+
# model_0 = AutoModelForSequenceClassification.from_pretrained(model_name_0)
|
22 |
+
model_0 = BertForMaskedLM.from_pretrained(model_name_0)
|
23 |
+
tokenizer_0 = AutoTokenizer.from_pretrained(model_name_0)
|
24 |
+
classifier_0 = pipeline(task="sentiment-analysis", model=model_0, tokenizer=tokenizer_0)
|
|
|
25 |
|
26 |
# model_name_1 = "Rathgeberj/milestone3_1"
|
27 |
# # model_1 = AutoModelForSequenceClassification.from_pretrained(model_name_1)
|
|
|
57 |
# tokenizers = [tokenizer_0, tokenizer_1, tokenizer_2, tokenizer_3, tokenizer_4, tokenizer_5]
|
58 |
# classifiers = [classifier_0, classifier_1, classifier_2, classifier_3, classifier_4, classifier_5]
|
59 |
|
60 |
+
X_train = [textIn]
|
61 |
+
batch = tokenizer(X_train, padding=True, truncation=True, max_length=512, return_tensors="pt")
|
62 |
+
|
63 |
+
with torch.no_grad():
|
64 |
+
outputs = model(**batch, labels=torch.tensor([1, 0]))
|
65 |
+
predictions = F.softmax(outputs.logits, dim=1)
|
66 |
+
labels = torch.argmax(predictions, dim=1)
|
67 |
+
labels = [model.config.id2label[label_id] for label_id in labels.tolist()]
|
68 |
+
|
69 |
+
st.write(outputs['label'])
|
70 |
+
|
71 |
+
|
72 |
col = ['Tweet', 'Highest_Toxicity_Class_Overall', 'Score_Overall', 'Highest_Toxicity_Class_Except_Toxic', 'Score_Except_Toxic']
|
73 |
df = pd.DataFrame(columns=col)
|
74 |
pre_populated_tweets = ['Yo bitch Ja Rule is more succesful then youll ever be whats up with you and hating you sad mofuckas...i should bitch slap ur pethedic white faces and get you to kiss my ass you guys sicken me. Ja rule is about pride in da music man. dont diss that shit on him. and nothin is wrong bein like tupac he was a brother too...fuckin white boys get things right next time.',
|