Spaces:
Runtime error
Runtime error
Jeffrey Rathgeber Jr
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -10,12 +10,16 @@ import pandas as pd
|
|
10 |
|
11 |
# model = BertForMaskedLM.from_pretrained("remi/bertabs-finetuned-extractive-abstractive-summarization")
|
12 |
|
|
|
|
|
13 |
textIn = st.text_input("Input Text Here:", "I really like the color of your car!")
|
14 |
|
15 |
option = st.selectbox('Which pre-trained model would you like for your sentiment analysis?',('MILESTONE 3', 'Pipeline', 'TextBlob'))
|
16 |
|
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)
|
@@ -52,11 +56,13 @@ if option == 'MILESTONE 3':
|
|
52 |
model_5 = BertForMaskedLM.from_pretrained(model_name_5)
|
53 |
tokenizer_5 = AutoTokenizer.from_pretrained(model_name_5)
|
54 |
classifier_5 = pipeline(task="sentiment-analysis", model=model_5, tokenizer=tokenizer_5)
|
55 |
-
|
|
|
56 |
models = [model_0, model_1, model_2, model_3, model_4, model_5]
|
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 |
st.write('IF YOURE READING THIS: I was unable to complete a fully functioning milestone 3. \
|
61 |
If this message print, that means my program successfully loaded my pretrained models. \
|
62 |
They are fine tuned iterations of the Bert uncased model, trained on the given training data. \
|
@@ -75,7 +81,7 @@ if option == 'MILESTONE 3':
|
|
75 |
|
76 |
# st.write(predictions['label'])
|
77 |
|
78 |
-
|
79 |
col = ['Tweet', 'Highest_Toxicity_Class_Overall', 'Score_Overall', 'Highest_Toxicity_Class_Except_Toxic', 'Score_Except_Toxic']
|
80 |
df = pd.DataFrame(columns=col)
|
81 |
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.',
|
@@ -135,6 +141,7 @@ if option == 'MILESTONE 3':
|
|
135 |
|
136 |
# st.write(pred_data)
|
137 |
|
|
|
138 |
if option == 'Pipeline':
|
139 |
|
140 |
model_name = "distilbert-base-uncased-finetuned-sst-2-english"
|
@@ -145,6 +152,7 @@ if option == 'Pipeline':
|
|
145 |
preds = [{"score": round(pred["score"], 4), "label": pred["label"]} for pred in preds]
|
146 |
st.write('According to Pipeline, input text is ', preds[0]['label'], ' with a confidence of ', preds[0]['score'])
|
147 |
|
|
|
148 |
if option == 'TextBlob':
|
149 |
polarity = TextBlob(textIn).sentiment.polarity
|
150 |
subjectivity = TextBlob(textIn).sentiment.subjectivity
|
|
|
10 |
|
11 |
# model = BertForMaskedLM.from_pretrained("remi/bertabs-finetuned-extractive-abstractive-summarization")
|
12 |
|
13 |
+
# setup pre-popultaed text and drop down menu for model options
|
14 |
+
|
15 |
textIn = st.text_input("Input Text Here:", "I really like the color of your car!")
|
16 |
|
17 |
option = st.selectbox('Which pre-trained model would you like for your sentiment analysis?',('MILESTONE 3', 'Pipeline', 'TextBlob'))
|
18 |
|
19 |
st.write('You selected:', option)
|
20 |
|
21 |
+
# milestone 3 models, all loaded and pre-trained using "TrainingAlgo" and loaded into huggingface, but could not successfully use them on input text
|
22 |
+
# For my multi headed model, I trained 6 models each return a value between 0 and 1 with the confidence that input text is 'Toxic', 'Obscene', etc.
|
23 |
if option == 'MILESTONE 3':
|
24 |
model_name_0 = "Rathgeberj/milestone3_0"
|
25 |
# model_0 = AutoModelForSequenceClassification.from_pretrained(model_name_0)
|
|
|
56 |
model_5 = BertForMaskedLM.from_pretrained(model_name_5)
|
57 |
tokenizer_5 = AutoTokenizer.from_pretrained(model_name_5)
|
58 |
classifier_5 = pipeline(task="sentiment-analysis", model=model_5, tokenizer=tokenizer_5)
|
59 |
+
|
60 |
+
# list of models and associated tokenizers & classifiers
|
61 |
models = [model_0, model_1, model_2, model_3, model_4, model_5]
|
62 |
tokenizers = [tokenizer_0, tokenizer_1, tokenizer_2, tokenizer_3, tokenizer_4, tokenizer_5]
|
63 |
classifiers = [classifier_0, classifier_1, classifier_2, classifier_3, classifier_4, classifier_5]
|
64 |
+
|
65 |
+
# Note that pops up when milestone 3 is selected from drop down, indicating models were successfully loaded into the space
|
66 |
st.write('IF YOURE READING THIS: I was unable to complete a fully functioning milestone 3. \
|
67 |
If this message print, that means my program successfully loaded my pretrained models. \
|
68 |
They are fine tuned iterations of the Bert uncased model, trained on the given training data. \
|
|
|
81 |
|
82 |
# st.write(predictions['label'])
|
83 |
|
84 |
+
# table of 10 pre-populated tweets and where their toxicity labels and scores would go
|
85 |
col = ['Tweet', 'Highest_Toxicity_Class_Overall', 'Score_Overall', 'Highest_Toxicity_Class_Except_Toxic', 'Score_Except_Toxic']
|
86 |
df = pd.DataFrame(columns=col)
|
87 |
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.',
|
|
|
141 |
|
142 |
# st.write(pred_data)
|
143 |
|
144 |
+
# Pre trained distilbert model from huggingface
|
145 |
if option == 'Pipeline':
|
146 |
|
147 |
model_name = "distilbert-base-uncased-finetuned-sst-2-english"
|
|
|
152 |
preds = [{"score": round(pred["score"], 4), "label": pred["label"]} for pred in preds]
|
153 |
st.write('According to Pipeline, input text is ', preds[0]['label'], ' with a confidence of ', preds[0]['score'])
|
154 |
|
155 |
+
# pre trained model Textblob from huggingface
|
156 |
if option == 'TextBlob':
|
157 |
polarity = TextBlob(textIn).sentiment.polarity
|
158 |
subjectivity = TextBlob(textIn).sentiment.subjectivity
|