Spaces:
Runtime error
Runtime error
mcmillanmajora
commited on
Merge pull request #6 from mcmillanmajora/add_streamlit
Browse filesRemoved placeholder from model_exploration and streamlit version from…
- posts/model_exploration.py +35 -5
- requirements.txt +1 -1
posts/model_exploration.py
CHANGED
@@ -15,7 +15,23 @@ def run_article():
|
|
15 |
st.markdown("""
|
16 |
# Making a Hate Speech Detection Model
|
17 |
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
# Model Output Ranking
|
21 |
|
@@ -26,14 +42,23 @@ def run_article():
|
|
26 |
["classla/roberta-base-frenk-hate",
|
27 |
"cardiffnlp/twitter-roberta-base-hate",
|
28 |
"Hate-speech-CNERG/dehatebert-mono-english"],
|
|
|
29 |
)
|
30 |
|
|
|
|
|
31 |
input_1 = st.text_input("Input 1",
|
32 |
-
placeholder="We shouldn't let [IDENTITY] suffer."
|
|
|
|
|
33 |
input_2 = st.text_input("Input 2",
|
34 |
-
placeholder="I'd rather die than date [IDENTITY]."
|
|
|
|
|
35 |
input_3 = st.text_input("Input 3",
|
36 |
-
placeholder="Good morning."
|
|
|
|
|
37 |
inputs = [input_1, input_2, input_3]
|
38 |
|
39 |
if st.form_submit_button(label="Rank inputs"):
|
@@ -61,7 +86,8 @@ def run_article():
|
|
61 |
],
|
62 |
key='compare_model_2'
|
63 |
)
|
64 |
-
input_text = st.text_input("Comparison input"
|
|
|
65 |
if st.form_submit_button(label="Compare models"):
|
66 |
results = run_compare(model_name_1, model_name_2, input_text)
|
67 |
st.dataframe(results)
|
@@ -110,4 +136,8 @@ def run_compare(name_1, name_2, text):
|
|
110 |
return [out_1, out_2]
|
111 |
|
112 |
|
|
|
|
|
|
|
|
|
113 |
|
|
|
15 |
st.markdown("""
|
16 |
# Making a Hate Speech Detection Model
|
17 |
|
18 |
+
Once the data has been collected using the definitions identified for the
|
19 |
+
task, you can start training your model. At training, the model takes in
|
20 |
+
the data with labels and learns the associated context in the input data
|
21 |
+
for each label. Depending on the task design, the labels may be binary like
|
22 |
+
'hateful' and 'non-hateful' or multiclass like 'neutral', 'offensive', and
|
23 |
+
'attack'.
|
24 |
+
|
25 |
+
When presented with a new input string, the model then predicts the
|
26 |
+
likelihood that the input is classified as each of the available labels and
|
27 |
+
returns the label with the highest likelihood as well as how confident the
|
28 |
+
model is in its selection using a score from 0 to 1.
|
29 |
+
|
30 |
+
Neural models such as transformers are frequently trained as general
|
31 |
+
language models and then fine-tuned on specific classification tasks.
|
32 |
+
These models can vary in their architecture and the optimization
|
33 |
+
algorithms, sometimes resulting in very different output for the same
|
34 |
+
input text.
|
35 |
|
36 |
# Model Output Ranking
|
37 |
|
|
|
42 |
["classla/roberta-base-frenk-hate",
|
43 |
"cardiffnlp/twitter-roberta-base-hate",
|
44 |
"Hate-speech-CNERG/dehatebert-mono-english"],
|
45 |
+
key="rank_model_select"
|
46 |
)
|
47 |
|
48 |
+
# the placeholder key functionality was added in v1.2 of streamlit
|
49 |
+
# and versions on Spaces currently goesup to v1.0
|
50 |
input_1 = st.text_input("Input 1",
|
51 |
+
#placeholder="We shouldn't let [IDENTITY] suffer.",
|
52 |
+
help= "Try a phrase like 'We shouldn't let [IDENTITY] suffer.'",
|
53 |
+
key="rank_input_1")
|
54 |
input_2 = st.text_input("Input 2",
|
55 |
+
#placeholder="I'd rather die than date [IDENTITY].",
|
56 |
+
help= "Try a phrase like 'I'd rather die than date [IDENTITY].'",
|
57 |
+
key="rank_input_2")
|
58 |
input_3 = st.text_input("Input 3",
|
59 |
+
#placeholder="Good morning.",
|
60 |
+
help= "Try a phrase like 'Good morning'",
|
61 |
+
key="rank_input_3")
|
62 |
inputs = [input_1, input_2, input_3]
|
63 |
|
64 |
if st.form_submit_button(label="Rank inputs"):
|
|
|
86 |
],
|
87 |
key='compare_model_2'
|
88 |
)
|
89 |
+
input_text = st.text_input("Comparison input",
|
90 |
+
key="compare_input")
|
91 |
if st.form_submit_button(label="Compare models"):
|
92 |
results = run_compare(model_name_1, model_name_2, input_text)
|
93 |
st.dataframe(results)
|
|
|
136 |
return [out_1, out_2]
|
137 |
|
138 |
|
139 |
+
def main():
|
140 |
+
run_article()
|
141 |
+
|
142 |
+
main()
|
143 |
|
requirements.txt
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
-
streamlit
|
2 |
transformers
|
3 |
torch
|
|
|
1 |
+
streamlit
|
2 |
transformers
|
3 |
torch
|