'mint autosave'
Browse files
app.py
CHANGED
@@ -19,9 +19,8 @@ labels = {'LABEL_0': 'toxic', 'LABEL_1': 'severe_toxic', 'LABEL_2': 'obscene', '
|
|
19 |
# make a dictionary of the labels and values
|
20 |
def unpack(result):
|
21 |
output = {}
|
22 |
-
|
23 |
-
|
24 |
-
output[labels[res['label']]] = res['score']
|
25 |
return output
|
26 |
|
27 |
def add_to_table(input, result, output):
|
@@ -44,16 +43,17 @@ option = st.selectbox(
|
|
44 |
('Default', 'Fine-Tuned' , 'Roberta'))
|
45 |
|
46 |
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
|
|
57 |
|
58 |
|
59 |
|
@@ -75,12 +75,18 @@ strings = [ "D'aww! He matches this background colour I'm seemingly stuck with.
|
|
75 |
|
76 |
|
77 |
if st.button('Analyze'):
|
78 |
-
result = classifier(input)
|
79 |
-
result = result[0]
|
80 |
if option == 'Fine-Tuned':
|
|
|
|
|
81 |
result = unpack(result)
|
82 |
add_to_table(input, result, output)
|
83 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
84 |
st.write(result)
|
85 |
else:
|
86 |
st.write('Excited to analyze!')
|
@@ -88,7 +94,7 @@ else:
|
|
88 |
|
89 |
|
90 |
for string in strings:
|
91 |
-
item =
|
92 |
item = item[0]
|
93 |
item = unpack(item)
|
94 |
add_to_table(string, item, output)
|
|
|
19 |
# make a dictionary of the labels and values
|
20 |
def unpack(result):
|
21 |
output = {}
|
22 |
+
for res in result:
|
23 |
+
output[labels[res['label']]] = res['score']
|
|
|
24 |
return output
|
25 |
|
26 |
def add_to_table(input, result, output):
|
|
|
43 |
('Default', 'Fine-Tuned' , 'Roberta'))
|
44 |
|
45 |
|
46 |
+
# init classifiers
|
47 |
+
|
48 |
+
model = AutoModelForSequenceClassification.from_pretrained(fine_tuned)
|
49 |
+
tokenizer = AutoTokenizer.from_pretrained("bert-base-uncased")
|
50 |
+
ft_classifier = pipeline('sentiment-analysis', model=model, tokenizer=tokenizer, top_k=None)
|
51 |
+
|
52 |
+
model = AutoModelForSequenceClassification.from_pretrained("cardiffnlp/twitter-roberta-base-sentiment")
|
53 |
+
tokenizer = AutoTokenizer.from_pretrained("cardiffnlp/twitter-roberta-base-sentiment")
|
54 |
+
rob_classifier = pipeline('sentiment-analysis', model=model, tokenizer=tokenizer)
|
55 |
+
|
56 |
+
def_classifier = pipeline('sentiment-analysis')
|
57 |
|
58 |
|
59 |
|
|
|
75 |
|
76 |
|
77 |
if st.button('Analyze'):
|
|
|
|
|
78 |
if option == 'Fine-Tuned':
|
79 |
+
result = ft_classifier(input)
|
80 |
+
result = result[0]
|
81 |
result = unpack(result)
|
82 |
add_to_table(input, result, output)
|
83 |
+
elif option == 'Roberta':
|
84 |
+
result = rob_classifier(input)
|
85 |
+
result = result[0]
|
86 |
+
st.write(result)
|
87 |
+
elif option == 'Default':
|
88 |
+
result = def_classifier(input)
|
89 |
+
result = result[0]
|
90 |
st.write(result)
|
91 |
else:
|
92 |
st.write('Excited to analyze!')
|
|
|
94 |
|
95 |
|
96 |
for string in strings:
|
97 |
+
item = ft_classifier(string)
|
98 |
item = item[0]
|
99 |
item = unpack(item)
|
100 |
add_to_table(string, item, output)
|