Yacine Jernite commited on
Commit
0a10cf1
1 Parent(s): 88c7b12
posts/conclusion.py CHANGED
@@ -19,40 +19,52 @@ Next, please answer the following questions about the information presented in t
19
 
20
  def run_article():
21
  st.markdown(__KEY_TAKEAWAYS)
22
- st.text_area(
 
23
  "Did you click on any of the links provided in the **Hate Speech in ACM** page? If so, which one did you find most surprising?"
24
  )
25
- st.text_area(
26
  "Of the datasets presented in the **Dataset Exploration** page, which one did you think best represented content that should be moderated? Which worst?"
27
  )
28
- st.text_area(
29
  "Of the models presented in the **Model Exploration** page, which one did you think performed best? Which worst?"
30
  )
31
- st.text_area(
32
  "Any additional comments about the materials?"
33
  )
34
  # from paper
35
- st.text_area(
36
  "How would you describe your role? E.g. model developer, dataset developer, domain expert, policy maker, platform manager, community advocate, platform user, student"
37
  )
38
- st.text_area(
39
- "Why are you interested in content moderation?"
 
 
 
 
 
 
 
40
  )
41
- st.text_area(
42
- "Which modules did you use the most?"
 
 
 
 
 
 
43
  )
44
- st.text_area(
45
- "Which module did you find the most informative?"
46
  )
47
- st.text_area(
48
- "Which application were you most interested in learning more about?"
49
  )
50
- st.text_area(
51
- "What surprised you most about the datasets?"
52
  )
53
- st.text_area(
54
- "Which models are you most concerned about as a user?"
55
  )
56
- st.text_area(
57
- "Do you have any comments or suggestions?"
58
- )
 
19
 
20
  def run_article():
21
  st.markdown(__KEY_TAKEAWAYS)
22
+ res = {}
23
+ res["used_links"] = st.text_area(
24
  "Did you click on any of the links provided in the **Hate Speech in ACM** page? If so, which one did you find most surprising?"
25
  )
26
+ res["dataset_feedback"] = st.text_area(
27
  "Of the datasets presented in the **Dataset Exploration** page, which one did you think best represented content that should be moderated? Which worst?"
28
  )
29
+ res["model_feedback"] = st.text_area(
30
  "Of the models presented in the **Model Exploration** page, which one did you think performed best? Which worst?"
31
  )
32
+ res["additional_material"] = st.text_area(
33
  "Any additional comments about the materials?"
34
  )
35
  # from paper
36
+ res["role"] = st.text_area(
37
  "How would you describe your role? E.g. model developer, dataset developer, domain expert, policy maker, platform manager, community advocate, platform user, student"
38
  )
39
+ res["interest"] = st.text_area("Why are you interested in content moderation?")
40
+ res["modules_used"] = st.multiselect(
41
+ "Which modules did you use the most?",
42
+ options=[
43
+ "Welcome - Introduction",
44
+ "Hate Speech in ACM",
45
+ "Dataset Exploration",
46
+ "Model Exploration",
47
+ ],
48
  )
49
+ res["modules_informative"] = st.selectbox(
50
+ "Which module did you find the most informative?",
51
+ options=[
52
+ "Welcome - Introduction",
53
+ "Hate Speech in ACM",
54
+ "Dataset Exploration",
55
+ "Model Exploration",
56
+ ],
57
  )
58
+ res["application)interest"] = st.text_area(
59
+ "Which application were you most interested in learning more about?"
60
  )
61
+ res["dataset_surprise"] = st.text_area(
62
+ "What surprised you most about the datasets?"
63
  )
64
+ res["model_concern"] = st.text_area(
65
+ "Which models are you most concerned about as a user?"
66
  )
67
+ res["comments_suggestions"] = st.text_area(
68
+ "Do you have any comments or suggestions?"
69
  )
70
+ st.write(res)
 
 
posts/context.py CHANGED
@@ -86,6 +86,7 @@ __CRITIC_EXAMPLES = """
86
  - [Reddit Self Reflection on Lack of Content Policy](https://www.reddit.com/r/announcements/comments/gxas21/upcoming_changes_to_our_content_policy_our_board/)
87
  """
88
 
 
89
  def run_article():
90
  st.markdown("## Automatic Content Moderation (ACM)")
91
  with st.expander("ACM definition", expanded=False):
 
86
  - [Reddit Self Reflection on Lack of Content Policy](https://www.reddit.com/r/announcements/comments/gxas21/upcoming_changes_to_our_content_policy_our_board/)
87
  """
88
 
89
+
90
  def run_article():
91
  st.markdown("## Automatic Content Moderation (ACM)")
92
  with st.expander("ACM definition", expanded=False):
posts/dataset_exploration.py CHANGED
@@ -58,35 +58,82 @@ the labels for those examples, and the distribution of labels within the
58
  cluster. Note that cluster 0 will always be the full dataset.
59
  """
60
 
61
- DSET_OPTIONS = {'classla/FRENK-hate-en': {'binary': {'train': {('text',): {'label': {100000: {
62
- 'sentence-transformers/all-mpnet-base-v2': {'tree': {'dataset_name': 'classla/FRENK-hate-en',
63
- 'config_name': 'binary',
64
- 'split_name': 'train',
65
- 'input_field_path': ('text',),
66
- 'label_name': 'label',
67
- 'num_rows': 100000,
68
- 'model_name': 'sentence-transformers/all-mpnet-base-v2',
69
- 'file_name': 'tree'}}}}}}}},
70
- 'tweets_hate_speech_detection': {'default': {'train': {('tweet',): {'label': {100000: {
71
- 'sentence-transformers/all-mpnet-base-v2': {'tree': {'dataset_name': 'tweets_hate_speech_detection',
72
- 'config_name': 'default',
73
- 'split_name': 'train',
74
- 'input_field_path': ('tweet',),
75
- 'label_name': 'label',
76
- 'num_rows': 100000,
77
- 'model_name': 'sentence-transformers/all-mpnet-base-v2',
78
- 'file_name': 'tree'}}}}}}}},
79
- 'ucberkeley-dlab/measuring-hate-speech': {'default': {'train': {('text',): {'hatespeech': {100000: {
80
- 'sentence-transformers/all-mpnet-base-v2': {'tree': {'dataset_name': 'ucberkeley-dlab/measuring-hate-speech',
81
- 'config_name': 'default',
82
- 'split_name': 'train',
83
- 'input_field_path': ('text',),
84
- 'label_name': 'hatespeech',
85
- 'num_rows': 100000,
86
- 'model_name': 'sentence-transformers/all-mpnet-base-v2',
87
- 'file_name': 'tree'}}}}}}}},
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
  }
89
 
 
90
  @st.cache(allow_output_mutation=True)
91
  def download_tree(args):
92
  clusters = Clustering(**args)
@@ -115,7 +162,7 @@ def run_article():
115
 
116
  pre_args = DSET_OPTIONS[choose_dset]
117
  args = pre_args
118
- while not 'dataset_name' in args:
119
  args = list(args.values())[0]
120
 
121
  clustering = download_tree(args)
@@ -130,8 +177,12 @@ def run_article():
130
  "Visualize cluster node:",
131
  range(len(clustering.node_list)),
132
  )
133
- st.markdown(f"Node {show_node} has {clustering.node_list[show_node]['weight']} examples.")
134
- st.markdown(f"Node {show_node} was merged at {clustering.node_list[show_node]['merged_at']:.2f}.")
 
 
 
 
135
  examplars = clustering.get_node_examplars(show_node)
136
  st.markdown("---\n")
137
 
 
58
  cluster. Note that cluster 0 will always be the full dataset.
59
  """
60
 
61
+ DSET_OPTIONS = {
62
+ "classla/FRENK-hate-en": {
63
+ "binary": {
64
+ "train": {
65
+ ("text",): {
66
+ "label": {
67
+ 100000: {
68
+ "sentence-transformers/all-mpnet-base-v2": {
69
+ "tree": {
70
+ "dataset_name": "classla/FRENK-hate-en",
71
+ "config_name": "binary",
72
+ "split_name": "train",
73
+ "input_field_path": ("text",),
74
+ "label_name": "label",
75
+ "num_rows": 100000,
76
+ "model_name": "sentence-transformers/all-mpnet-base-v2",
77
+ "file_name": "tree",
78
+ }
79
+ }
80
+ }
81
+ }
82
+ }
83
+ }
84
+ }
85
+ },
86
+ "tweets_hate_speech_detection": {
87
+ "default": {
88
+ "train": {
89
+ ("tweet",): {
90
+ "label": {
91
+ 100000: {
92
+ "sentence-transformers/all-mpnet-base-v2": {
93
+ "tree": {
94
+ "dataset_name": "tweets_hate_speech_detection",
95
+ "config_name": "default",
96
+ "split_name": "train",
97
+ "input_field_path": ("tweet",),
98
+ "label_name": "label",
99
+ "num_rows": 100000,
100
+ "model_name": "sentence-transformers/all-mpnet-base-v2",
101
+ "file_name": "tree",
102
+ }
103
+ }
104
+ }
105
+ }
106
+ }
107
+ }
108
+ }
109
+ },
110
+ "ucberkeley-dlab/measuring-hate-speech": {
111
+ "default": {
112
+ "train": {
113
+ ("text",): {
114
+ "hatespeech": {
115
+ 100000: {
116
+ "sentence-transformers/all-mpnet-base-v2": {
117
+ "tree": {
118
+ "dataset_name": "ucberkeley-dlab/measuring-hate-speech",
119
+ "config_name": "default",
120
+ "split_name": "train",
121
+ "input_field_path": ("text",),
122
+ "label_name": "hatespeech",
123
+ "num_rows": 100000,
124
+ "model_name": "sentence-transformers/all-mpnet-base-v2",
125
+ "file_name": "tree",
126
+ }
127
+ }
128
+ }
129
+ }
130
+ }
131
+ }
132
+ }
133
+ },
134
  }
135
 
136
+
137
  @st.cache(allow_output_mutation=True)
138
  def download_tree(args):
139
  clusters = Clustering(**args)
 
162
 
163
  pre_args = DSET_OPTIONS[choose_dset]
164
  args = pre_args
165
+ while not "dataset_name" in args:
166
  args = list(args.values())[0]
167
 
168
  clustering = download_tree(args)
 
177
  "Visualize cluster node:",
178
  range(len(clustering.node_list)),
179
  )
180
+ st.markdown(
181
+ f"Node {show_node} has {clustering.node_list[show_node]['weight']} examples."
182
+ )
183
+ st.markdown(
184
+ f"Node {show_node} was merged at {clustering.node_list[show_node]['merged_at']:.2f}."
185
+ )
186
  examplars = clustering.get_node_examplars(show_node)
187
  st.markdown("---\n")
188
 
posts/model_exploration.py CHANGED
@@ -1,10 +1,10 @@
1
- import streamlit as st
2
  import json
3
  import random
4
  import sys
5
 
6
  import numpy as np
7
  import pandas as pd
 
8
  # from transformers import AutoTokenizer, AutoModelForSequenceClassification
9
  from transformers import pipeline
10
 
@@ -95,31 +95,31 @@ sentence using the tool below.
95
  """
96
 
97
  __MODELS = [
98
- "classla/roberta-base-frenk-hate",
99
- "cardiffnlp/twitter-roberta-base-hate",
100
- "Hate-speech-CNERG/dehatebert-mono-english",
101
- "facebook/roberta-hate-speech-dynabench-r1-target",
102
- "facebook/roberta-hate-speech-dynabench-r2-target",
103
- "facebook/roberta-hate-speech-dynabench-r3-target",
104
- "facebook/roberta-hate-speech-dynabench-r4-target"
105
- ]
106
 
107
  autopop_ranking = [
108
  [
109
  "I don't hate black people.",
110
  "Black people should die.",
111
- "My friend likes pancakes."
112
  ],
113
  [
114
  "Those dirty redskins are all drunks.",
115
  "I can't stand Chinese food. It's too spicy.",
116
- "I lived near many Chinese people and I hated every single one of them."
117
  ],
118
  [
119
  "Stop saying that Mexicans don't belong in our country!",
120
  "We walked along the dyke down the road.",
121
- "Ah shit, I fucked up."
122
- ]
123
  ]
124
 
125
  # Creates the forms for receiving multiple inputs to compare for a single
@@ -130,22 +130,13 @@ def run_article():
130
  st.markdown(__HATE_DETECTION)
131
  hc_path = "posts/resources/"
132
  hc_pholders = json.load(
133
- open(
134
- hc_path + "template_placeholders.json",
135
- encoding="utf-8"
136
- )
137
  )
138
  hc_templates = json.load(
139
- open(
140
- hc_path + "hatecheck_category_templates.json",
141
- encoding="utf-8"
142
- )
143
  )
144
  hc_info = json.load(
145
- open(
146
- hc_path + "hatecheck_category_info.json",
147
- encoding="utf-8"
148
- )
149
  )
150
  hc_cats = [""] + list(hc_info.keys())
151
 
@@ -153,10 +144,8 @@ def run_article():
153
  with st.expander("HateCheck Examples", expanded=False):
154
  st.markdown(__HATECHECK)
155
  category = st.selectbox(
156
- "Select a category of examples from HateCheck",
157
- hc_cats,
158
- key="hc_cat_select"
159
- )
160
  if category:
161
  with st.form(key="hate_check"):
162
  hc_cat = hc_info[category]
@@ -166,24 +155,22 @@ def run_article():
166
  templates.append(hc_temp)
167
  names.append(hc_cat[hc_temp]["name"])
168
  selected_names = st.multiselect(
169
- "Select one or more HateCheck templates to generate examples for",
170
- names,
171
- key="hc_temp_multiselect"
172
  )
173
  num_exs = st.number_input(
174
- "Select a number of examples to generate for each selected template",
175
- min_value = 1,
176
- max_value = 5,
177
- value = 3
178
- )
179
  if st.form_submit_button(label="Generate Examples"):
180
  for name in selected_names:
181
  index = names.index(name)
182
  template = templates[index]
183
  examples = generate_hc_ex(
184
- hc_templates[template],
185
- hc_pholders,
186
- num_exs
187
  )
188
  st.header(name)
189
  st.subheader("Label: " + hc_cat[template]["value"])
@@ -215,12 +202,12 @@ def run_article():
215
  input_3 = st.text_input(
216
  "Input 3",
217
  help="Try a phrase like 'Good morning'",
218
- #placeholder="Good morning."
219
  )
220
  autopop = st.checkbox(
221
- 'Choose examples for me',
222
  key="rank_autopop_ckbx",
223
- help="Check this box to run the model with 3 preselected sentences."
224
  )
225
  if st.form_submit_button(label="Rank inputs"):
226
  if autopop:
@@ -246,9 +233,9 @@ def run_article():
246
  key="compare_model_2",
247
  )
248
  autopop = st.checkbox(
249
- 'Choose an example for me',
250
  key="comp_autopop_ckbx",
251
- help="Check this box to compare the models with a preselected sentence."
252
  )
253
  input_text = st.text_input("Comparison input")
254
  if st.form_submit_button(label="Compare models"):
@@ -257,16 +244,11 @@ def run_article():
257
  results = run_compare(model_name_1, model_name_2, input_text)
258
  st.write("### Showing results for: " + input_text)
259
  st.dataframe(results)
260
- outside_ds = [
261
- "hatecheck",
262
- "dynabench",
263
- "hatefulmemes",
264
- "opensubtitles"
265
- ]
266
  name_1_short = model_name_1.split("/")[1]
267
  name_2_short = model_name_2.split("/")[1]
268
  for calib_ds in outside_ds:
269
- ds_loc = "posts/resources/charts/" + calib_ds + "/"
270
  images, captions = [], []
271
  for model in [name_1_short, name_2_short]:
272
  images.append(ds_loc + model + "_" + calib_ds + ".png")
@@ -274,6 +256,7 @@ def run_article():
274
  st.write("#### Model performance comparison on " + calib_ds)
275
  st.image(images, captions)
276
 
 
277
  # if model_name_1 == "Hate-speech-CNERG/dehatebert-mono-english":
278
  # st.image("posts/resources/dehatebert-mono-english_calibration.png")
279
  # elif model_name_1 == "cardiffnlp/twitter-roberta-base-hate":
@@ -303,11 +286,7 @@ def generate_hc_ex(template, placeholders, gen_num):
303
  # Runs the received input strings through the given model and returns the
304
  # all scores for all possible labels as a DataFrame
305
  def run_ranked(model, input_list):
306
- classifier = pipeline(
307
- "text-classification",
308
- model=model,
309
- return_all_scores=True
310
- )
311
  output = {}
312
  results = classifier(input_list)
313
  for result in results:
 
 
1
  import json
2
  import random
3
  import sys
4
 
5
  import numpy as np
6
  import pandas as pd
7
+ import streamlit as st
8
  # from transformers import AutoTokenizer, AutoModelForSequenceClassification
9
  from transformers import pipeline
10
 
 
95
  """
96
 
97
  __MODELS = [
98
+ "classla/roberta-base-frenk-hate",
99
+ "cardiffnlp/twitter-roberta-base-hate",
100
+ "Hate-speech-CNERG/dehatebert-mono-english",
101
+ "facebook/roberta-hate-speech-dynabench-r1-target",
102
+ "facebook/roberta-hate-speech-dynabench-r2-target",
103
+ "facebook/roberta-hate-speech-dynabench-r3-target",
104
+ "facebook/roberta-hate-speech-dynabench-r4-target",
105
+ ]
106
 
107
  autopop_ranking = [
108
  [
109
  "I don't hate black people.",
110
  "Black people should die.",
111
+ "My friend likes pancakes.",
112
  ],
113
  [
114
  "Those dirty redskins are all drunks.",
115
  "I can't stand Chinese food. It's too spicy.",
116
+ "I lived near many Chinese people and I hated every single one of them.",
117
  ],
118
  [
119
  "Stop saying that Mexicans don't belong in our country!",
120
  "We walked along the dyke down the road.",
121
+ "Ah shit, I fucked up.",
122
+ ],
123
  ]
124
 
125
  # Creates the forms for receiving multiple inputs to compare for a single
 
130
  st.markdown(__HATE_DETECTION)
131
  hc_path = "posts/resources/"
132
  hc_pholders = json.load(
133
+ open(hc_path + "template_placeholders.json", encoding="utf-8")
 
 
 
134
  )
135
  hc_templates = json.load(
136
+ open(hc_path + "hatecheck_category_templates.json", encoding="utf-8")
 
 
 
137
  )
138
  hc_info = json.load(
139
+ open(hc_path + "hatecheck_category_info.json", encoding="utf-8")
 
 
 
140
  )
141
  hc_cats = [""] + list(hc_info.keys())
142
 
 
144
  with st.expander("HateCheck Examples", expanded=False):
145
  st.markdown(__HATECHECK)
146
  category = st.selectbox(
147
+ "Select a category of examples from HateCheck", hc_cats, key="hc_cat_select"
148
+ )
 
 
149
  if category:
150
  with st.form(key="hate_check"):
151
  hc_cat = hc_info[category]
 
155
  templates.append(hc_temp)
156
  names.append(hc_cat[hc_temp]["name"])
157
  selected_names = st.multiselect(
158
+ "Select one or more HateCheck templates to generate examples for",
159
+ names,
160
+ key="hc_temp_multiselect",
161
  )
162
  num_exs = st.number_input(
163
+ "Select a number of examples to generate for each selected template",
164
+ min_value=1,
165
+ max_value=5,
166
+ value=3,
167
+ )
168
  if st.form_submit_button(label="Generate Examples"):
169
  for name in selected_names:
170
  index = names.index(name)
171
  template = templates[index]
172
  examples = generate_hc_ex(
173
+ hc_templates[template], hc_pholders, num_exs
 
 
174
  )
175
  st.header(name)
176
  st.subheader("Label: " + hc_cat[template]["value"])
 
202
  input_3 = st.text_input(
203
  "Input 3",
204
  help="Try a phrase like 'Good morning'",
205
+ # placeholder="Good morning."
206
  )
207
  autopop = st.checkbox(
208
+ "Choose examples for me",
209
  key="rank_autopop_ckbx",
210
+ help="Check this box to run the model with 3 preselected sentences.",
211
  )
212
  if st.form_submit_button(label="Rank inputs"):
213
  if autopop:
 
233
  key="compare_model_2",
234
  )
235
  autopop = st.checkbox(
236
+ "Choose an example for me",
237
  key="comp_autopop_ckbx",
238
+ help="Check this box to compare the models with a preselected sentence.",
239
  )
240
  input_text = st.text_input("Comparison input")
241
  if st.form_submit_button(label="Compare models"):
 
244
  results = run_compare(model_name_1, model_name_2, input_text)
245
  st.write("### Showing results for: " + input_text)
246
  st.dataframe(results)
247
+ outside_ds = ["hatecheck", "dynabench", "hatefulmemes", "opensubtitles"]
 
 
 
 
 
248
  name_1_short = model_name_1.split("/")[1]
249
  name_2_short = model_name_2.split("/")[1]
250
  for calib_ds in outside_ds:
251
+ ds_loc = "posts/resources/charts/" + calib_ds + "/"
252
  images, captions = [], []
253
  for model in [name_1_short, name_2_short]:
254
  images.append(ds_loc + model + "_" + calib_ds + ".png")
 
256
  st.write("#### Model performance comparison on " + calib_ds)
257
  st.image(images, captions)
258
 
259
+
260
  # if model_name_1 == "Hate-speech-CNERG/dehatebert-mono-english":
261
  # st.image("posts/resources/dehatebert-mono-english_calibration.png")
262
  # elif model_name_1 == "cardiffnlp/twitter-roberta-base-hate":
 
286
  # Runs the received input strings through the given model and returns the
287
  # all scores for all possible labels as a DataFrame
288
  def run_ranked(model, input_list):
289
+ classifier = pipeline("text-classification", model=model, return_all_scores=True)
 
 
 
 
290
  output = {}
291
  results = classifier(input_list)
292
  for result in results:
posts/welcome.py CHANGED
@@ -55,6 +55,7 @@ __MODEL_LIST = """
55
  - [RoBERTa trained on 11 English hate speech datasets and Rounds 1, 2, and 3 of the Dynamically Generated Hate Speech Dataset](https://huggingface.co/facebook/roberta-hate-speech-dynabench-r4-target)
56
  """
57
 
 
58
  def run_article():
59
  st.markdown("# Welcome!")
60
  st.markdown(__INTRO_TEXT)
 
55
  - [RoBERTa trained on 11 English hate speech datasets and Rounds 1, 2, and 3 of the Dynamically Generated Hate Speech Dataset](https://huggingface.co/facebook/roberta-hate-speech-dynabench-r4-target)
56
  """
57
 
58
+
59
  def run_article():
60
  st.markdown("# Welcome!")
61
  st.markdown(__INTRO_TEXT)