off-load 0.3.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- off_load/__init__.py +2 -0
- off_load/loader.py +2242 -0
- off_load/preproc.py +175 -0
- off_load-0.3.0.dist-info/METADATA +108 -0
- off_load-0.3.0.dist-info/RECORD +8 -0
- off_load-0.3.0.dist-info/WHEEL +5 -0
- off_load-0.3.0.dist-info/licenses/LICENSE +9 -0
- off_load-0.3.0.dist-info/top_level.txt +1 -0
off_load/loader.py
ADDED
|
@@ -0,0 +1,2242 @@
|
|
|
1
|
+
|
|
2
|
+
import os
|
|
3
|
+
import re
|
|
4
|
+
import json
|
|
5
|
+
import pandas as pd
|
|
6
|
+
|
|
7
|
+
# data lake
|
|
8
|
+
# set DATALAKE_ADDR to load from gridfs by default, otherwise files are read from the local fs
|
|
9
|
+
from io import StringIO, BytesIO
|
|
10
|
+
DB_ADDR = os.environ.get('DATALAKE_ADDR', '127.0.0.1:27017')
|
|
11
|
+
DB_NAME = 'datalake'
|
|
12
|
+
LOCAL = 'DATALAKE_ADDR' not in os.environ
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def datalake(local=LOCAL):
|
|
16
|
+
"""
|
|
17
|
+
returns a gridfs handle, or None for local files
|
|
18
|
+
pymongo is only needed for the data lake
|
|
19
|
+
"""
|
|
20
|
+
if local:
|
|
21
|
+
return None
|
|
22
|
+
from pymongo import MongoClient
|
|
23
|
+
import gridfs
|
|
24
|
+
db = MongoClient(DB_ADDR)
|
|
25
|
+
return gridfs.GridFS(db[DB_NAME])
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
# general loading functions
|
|
29
|
+
|
|
30
|
+
def wordlist(files=None, local=LOCAL, silent=True):
|
|
31
|
+
"""
|
|
32
|
+
loader for various wordlists
|
|
33
|
+
takes one or more paths as input and outputs the parsed and concatenated data
|
|
34
|
+
|
|
35
|
+
arguments:
|
|
36
|
+
files: list of paths (local fs) or names (gridfs)
|
|
37
|
+
local: bool -> default: True, unless DATALAKE_ADDR is set
|
|
38
|
+
silent: bool -> default: True
|
|
39
|
+
"""
|
|
40
|
+
fs = datalake(local)
|
|
41
|
+
|
|
42
|
+
swear_list = []
|
|
43
|
+
for path in files:
|
|
44
|
+
if local == False:
|
|
45
|
+
|
|
46
|
+
query = {'filename': {'$regex': path+'$'}}
|
|
47
|
+
grid_out = fs.find_one(query)
|
|
48
|
+
f = StringIO(grid_out.read().decode())
|
|
49
|
+
else:
|
|
50
|
+
f = open(path,'r', encoding='utf-8')
|
|
51
|
+
|
|
52
|
+
for line in f:
|
|
53
|
+
swear_list.append(line.rstrip())
|
|
54
|
+
|
|
55
|
+
f.close()
|
|
56
|
+
return list(set(swear_list))
|
|
57
|
+
|
|
58
|
+
def augmentations(files=None, local=LOCAL, silent=True):
|
|
59
|
+
"""
|
|
60
|
+
loader for dataset-specific augmentations
|
|
61
|
+
|
|
62
|
+
files:
|
|
63
|
+
1. pfad zu backlog.json
|
|
64
|
+
2. path(s): muss dataset_name aus backlog enthalten, der in eine augmentation-uid übersetzt wird, anhand der die daten von gridfs bzw. lokalem fs geladen werden können
|
|
65
|
+
local: bool -> default: True, unless DATALAKE_ADDR is set
|
|
66
|
+
silent: bool -> default: True
|
|
67
|
+
"""
|
|
68
|
+
AUGS_BASEPATH = 'data/hexis/augmentations'
|
|
69
|
+
fs = datalake(local)
|
|
70
|
+
|
|
71
|
+
"""
|
|
72
|
+
TODO: backlog nicht in gridfs speichern -> siehe training.md/augmentation/NEU
|
|
73
|
+
if local == False:
|
|
74
|
+
query = {'filename': {'$regex': files[0]+'$'}}
|
|
75
|
+
grid_out = fs.find_one(query)
|
|
76
|
+
f = StringIO(grid_out.read().decode())
|
|
77
|
+
else:
|
|
78
|
+
f = open(files[0], 'r', encoding='utf-8')
|
|
79
|
+
"""
|
|
80
|
+
f = open(files[0], 'r', encoding='utf-8')
|
|
81
|
+
backlog = json.load(f)
|
|
82
|
+
f.close()
|
|
83
|
+
|
|
84
|
+
data = []
|
|
85
|
+
for uid, config in backlog.items():
|
|
86
|
+
for path in files[1:]:
|
|
87
|
+
if config['dataset_name'] in path:
|
|
88
|
+
print('%s (%s)' % (config['dataset_name'], uid))
|
|
89
|
+
|
|
90
|
+
if local == False:
|
|
91
|
+
data += de_germeval([uid+'.txt$'], local=False)
|
|
92
|
+
else:
|
|
93
|
+
data += de_germeval([AUGS_BASEPATH+'/'+uid+'.txt'], local=True)
|
|
94
|
+
|
|
95
|
+
return data
|
|
96
|
+
|
|
97
|
+
def relabel(files=None, local=LOCAL, silent=True):
|
|
98
|
+
"""
|
|
99
|
+
loader for files in aggression/re-labeling
|
|
100
|
+
takes one or more paths as input and outputs the parsed and concatenated data
|
|
101
|
+
anm: grundlage ist klasse abuse, die mit einem profanity detector in zwei klassen, profanity und insults, aufgeteilt wurde
|
|
102
|
+
|
|
103
|
+
arguments:
|
|
104
|
+
files: list of paths (local fs) or names (gridfs)
|
|
105
|
+
local: bool -> default: True, unless DATALAKE_ADDR is set
|
|
106
|
+
silent: bool -> default: True
|
|
107
|
+
"""
|
|
108
|
+
fs = datalake(local)
|
|
109
|
+
|
|
110
|
+
data = []
|
|
111
|
+
for path in files:
|
|
112
|
+
if local == False:
|
|
113
|
+
query = {'filename': {'$regex': path+'$'}}
|
|
114
|
+
grid_out = fs.find_one(query)
|
|
115
|
+
f = StringIO(grid_out.read().decode())
|
|
116
|
+
data_corr = pd.read_csv(f, delimiter=',', index_col=0) # index = tweet_id
|
|
117
|
+
f.close()
|
|
118
|
+
else:
|
|
119
|
+
data_corr = pd.read_csv(path, delimiter=',', index_col=0) # index = tweet_id
|
|
120
|
+
|
|
121
|
+
for i, row in data_corr.iterrows():
|
|
122
|
+
text = row.iloc[0].rstrip()
|
|
123
|
+
label_str = row.iloc[2]
|
|
124
|
+
|
|
125
|
+
if text == '':
|
|
126
|
+
if silent == False:
|
|
127
|
+
print('empty string')
|
|
128
|
+
continue
|
|
129
|
+
|
|
130
|
+
post={}
|
|
131
|
+
post['text'] = text
|
|
132
|
+
if label_str == 'PROF':
|
|
133
|
+
post['label'] = 'profanity'
|
|
134
|
+
elif label_str == 'NONE':
|
|
135
|
+
post['label'] = 'insult' # part of 'abuse' that is not 'profanity', is 'insult'
|
|
136
|
+
else:
|
|
137
|
+
if silent == False:
|
|
138
|
+
print('LABEL ERROR: %s' % (label_str))
|
|
139
|
+
continue
|
|
140
|
+
|
|
141
|
+
data.append(post)
|
|
142
|
+
|
|
143
|
+
return data
|
|
144
|
+
|
|
145
|
+
def debias_madlibs(files=None, local=LOCAL, silent=True):
|
|
146
|
+
"""
|
|
147
|
+
loader for files in unintended-ml-bias-analysis/unintended_ml_bias/eval_datasets
|
|
148
|
+
takes one or more paths as input and outputs the parsed and concatenated data
|
|
149
|
+
classes: BAD, NOT_BAD
|
|
150
|
+
anm: BAD entspricht identity hate
|
|
151
|
+
|
|
152
|
+
arguments:
|
|
153
|
+
files: list of paths (local fs) or names (gridfs)
|
|
154
|
+
local: bool -> default: True, unless DATALAKE_ADDR is set
|
|
155
|
+
silent: bool -> default: True
|
|
156
|
+
"""
|
|
157
|
+
fs = datalake(local)
|
|
158
|
+
|
|
159
|
+
data = []
|
|
160
|
+
for path in files:
|
|
161
|
+
if local == False:
|
|
162
|
+
query = {'filename': {'$regex': path+'$'}}
|
|
163
|
+
grid_out = fs.find_one(query)
|
|
164
|
+
f = StringIO(grid_out.read().decode())
|
|
165
|
+
else:
|
|
166
|
+
f = open(path, 'r', encoding='utf-8')
|
|
167
|
+
|
|
168
|
+
for line in f.readlines()[1:]:
|
|
169
|
+
try:
|
|
170
|
+
i, text, label_str = line.split(',')
|
|
171
|
+
except:
|
|
172
|
+
i, text, label_str = line.split('"')
|
|
173
|
+
|
|
174
|
+
post={}
|
|
175
|
+
post['text'] = text
|
|
176
|
+
if label_str == 'NOT_BAD':
|
|
177
|
+
post['label'] = 'normal'
|
|
178
|
+
elif label_str == 'BAD':
|
|
179
|
+
post['label'] = 'hate'
|
|
180
|
+
else:
|
|
181
|
+
if silent == False:
|
|
182
|
+
print('LABEL ERROR: %s' % (label_str))
|
|
183
|
+
continue
|
|
184
|
+
|
|
185
|
+
data.append(post)
|
|
186
|
+
f.close()
|
|
187
|
+
|
|
188
|
+
return data
|
|
189
|
+
|
|
190
|
+
def twint(files=None, local=LOCAL, silent=True):
|
|
191
|
+
"""
|
|
192
|
+
loads the output of twint scraper
|
|
193
|
+
takes one or more paths as input and outputs the parsed and concatenated data
|
|
194
|
+
anm: reads just the text content from column 'tweets'
|
|
195
|
+
|
|
196
|
+
arguments:
|
|
197
|
+
files: list of paths (local fs) or names (gridfs)
|
|
198
|
+
local: bool -> default: True, unless DATALAKE_ADDR is set
|
|
199
|
+
silent: bool -> default: True
|
|
200
|
+
"""
|
|
201
|
+
fs = datalake(local)
|
|
202
|
+
|
|
203
|
+
data = []
|
|
204
|
+
for path in files:
|
|
205
|
+
if local == False:
|
|
206
|
+
query = {'filename': {'$regex': path+'$'}}
|
|
207
|
+
grid_out = fs.find_one(query)
|
|
208
|
+
f = StringIO(grid_out.read().decode())
|
|
209
|
+
txts_df = pd.read_csv(f, delimiter=',', index_col=0)
|
|
210
|
+
f.close()
|
|
211
|
+
else:
|
|
212
|
+
txts_df = pd.read_csv(path, delimiter=',', index_col=0)
|
|
213
|
+
|
|
214
|
+
for i, row in txts_df.iterrows():
|
|
215
|
+
if isinstance(row['tweet'], float) or row['tweet'].isnumeric(): # twint scraper produces erroneuos lines sometiems
|
|
216
|
+
continue
|
|
217
|
+
post={}
|
|
218
|
+
post['text'] = row['tweet'].rstrip()
|
|
219
|
+
data.append(post)
|
|
220
|
+
|
|
221
|
+
return data
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
# multilingual
|
|
225
|
+
|
|
226
|
+
def conan(lang, files=None, local=LOCAL, silent=True):
|
|
227
|
+
"""
|
|
228
|
+
CONAN (en/fr/it)
|
|
229
|
+
collection von hate- und counterspeech beispielen
|
|
230
|
+
15k bsp, gefiltert nach id: IT + zu jeder HS ID jede augmentation nur 1x -> 2502 bsp
|
|
231
|
+
id layout: FR|T1|ST0014|HS0015|CN001238|T1 = Language | HS Type | HS SubTopic | HS ID | CN Count | augmentation type (P1: paraphrase 1 / P2: paraphrase 2 / T1: translation 1)
|
|
232
|
+
anm: returns label als int
|
|
233
|
+
"""
|
|
234
|
+
if lang not in ['it', 'fr', 'en']:
|
|
235
|
+
if silent == False:
|
|
236
|
+
print('unknown language code:', str(lang))
|
|
237
|
+
return []
|
|
238
|
+
|
|
239
|
+
if local == False:
|
|
240
|
+
fs = datalake(local)
|
|
241
|
+
if not files:
|
|
242
|
+
files = ['CONAN/CONAN.csv']
|
|
243
|
+
|
|
244
|
+
query = {'filename': {'$regex': files[0]+'$'}}
|
|
245
|
+
grid_out = fs.find_one(query)
|
|
246
|
+
f = StringIO(grid_out.read().decode())
|
|
247
|
+
df = pd.read_csv(f, delimiter=',')
|
|
248
|
+
f.close()
|
|
249
|
+
else:
|
|
250
|
+
if not files:
|
|
251
|
+
files = ['data/multi/en, fr, it/CONAN/CONAN/CONAN.csv']
|
|
252
|
+
df = pd.read_csv(files[0], delimiter=',')
|
|
253
|
+
|
|
254
|
+
data = []
|
|
255
|
+
sample_ids = []
|
|
256
|
+
for i, row in df.iterrows():
|
|
257
|
+
post_id = row['cn_id']
|
|
258
|
+
if post_id.startswith(lang.upper()):
|
|
259
|
+
post_id_begin, post_id_end = post_id.split('HS')
|
|
260
|
+
hs_id, _ = post_id_end.split('CN')
|
|
261
|
+
aug_type = post_id_end[-2:]
|
|
262
|
+
sample_id = hs_id + aug_type
|
|
263
|
+
if sample_id in sample_ids:
|
|
264
|
+
continue
|
|
265
|
+
else:
|
|
266
|
+
sample_ids.append(sample_id)
|
|
267
|
+
|
|
268
|
+
post = {}
|
|
269
|
+
post['text'] = row['hateSpeech'].rstrip()
|
|
270
|
+
post['label'] = 1
|
|
271
|
+
data.append(post)
|
|
272
|
+
|
|
273
|
+
post = {}
|
|
274
|
+
post['text'] = row['counterSpeech'].rstrip()
|
|
275
|
+
post['label'] = 0
|
|
276
|
+
data.append(post)
|
|
277
|
+
return data
|
|
278
|
+
|
|
279
|
+
def mlma_hate(lang, files=None, local=LOCAL, silent=True):
|
|
280
|
+
"""
|
|
281
|
+
MLMA_hate_speech (ar/en/fr)
|
|
282
|
+
fr: 4014 bsp, exkl. bsp die '…' enthalten -> 2808 bsp
|
|
283
|
+
ar: 4014 bsp, exkl. bsp die '…' enthalten -> 2449 bsp
|
|
284
|
+
classes: sentiment (Abusive, Hateful, Offensive, Disrespectful, Fearful, Normal) + andere: directness,annotator_sentiment,target,group
|
|
285
|
+
"""
|
|
286
|
+
if lang not in ['ar', 'fr', 'en']:
|
|
287
|
+
if silent == False:
|
|
288
|
+
print('unknown language code:', str(lang))
|
|
289
|
+
return []
|
|
290
|
+
|
|
291
|
+
if local == False:
|
|
292
|
+
fs = datalake(local)
|
|
293
|
+
if not files:
|
|
294
|
+
files = ['hate_speech_mlma/'+lang.lower()+'_dataset.csv']
|
|
295
|
+
|
|
296
|
+
query = {'filename': {'$regex': files[0]+'$'}}
|
|
297
|
+
grid_out = fs.find_one(query)
|
|
298
|
+
f = StringIO(grid_out.read().decode())
|
|
299
|
+
df = pd.read_csv(f, delimiter=',')
|
|
300
|
+
f.close()
|
|
301
|
+
else:
|
|
302
|
+
if not files:
|
|
303
|
+
files = ['data/multi/ar, en, fr/MLMA_hate_speech/hate_speech_mlma/'+lang.lower()+'_dataset.csv']
|
|
304
|
+
df = pd.read_csv(files[0], delimiter=',')
|
|
305
|
+
|
|
306
|
+
data = []
|
|
307
|
+
for i, row in df.iterrows():
|
|
308
|
+
label = row['sentiment']
|
|
309
|
+
text = row['tweet'].rstrip()
|
|
310
|
+
if '…' in text:
|
|
311
|
+
continue
|
|
312
|
+
|
|
313
|
+
post = {}
|
|
314
|
+
post['text'] = text
|
|
315
|
+
post['label'] = label
|
|
316
|
+
data.append(post)
|
|
317
|
+
return data
|
|
318
|
+
|
|
319
|
+
def largescale_hate(lang, files=None, local=LOCAL, silent=True):
|
|
320
|
+
"""
|
|
321
|
+
largescale-hatespeech (en/tr)
|
|
322
|
+
100k bsp, classes: Normal (0), Offensive (1), Hate (2)
|
|
323
|
+
20k je domain: Gender, Race, Politics, Sports
|
|
324
|
+
anm: returns label als int
|
|
325
|
+
"""
|
|
326
|
+
if lang not in ['tr', 'en']:
|
|
327
|
+
if silent == False:
|
|
328
|
+
print('unknown language code:', str(lang))
|
|
329
|
+
return []
|
|
330
|
+
|
|
331
|
+
if local == False:
|
|
332
|
+
fs = datalake(local)
|
|
333
|
+
if not files:
|
|
334
|
+
files = ['/multi/en, tr/largescale-hatespeech/hate_speech_dataset-tweets.jsonl',
|
|
335
|
+
'/multi/en, tr/largescale-hatespeech/hate_speech_dataset.csv']
|
|
336
|
+
|
|
337
|
+
query = {'filename': {'$regex': files[1]+'$'}}
|
|
338
|
+
grid_out = fs.find_one(query)
|
|
339
|
+
f = StringIO(grid_out.read().decode())
|
|
340
|
+
labels_df = pd.read_csv(f, delimiter=',', index_col=0) # index = tweet_id
|
|
341
|
+
f.close()
|
|
342
|
+
|
|
343
|
+
query = {'filename': {'$regex': files[0]+'$'}}
|
|
344
|
+
grid_out = fs.find_one(query)
|
|
345
|
+
f = StringIO(grid_out.read().decode())
|
|
346
|
+
else:
|
|
347
|
+
if not files:
|
|
348
|
+
files = ['data/multi/en, tr/largescale-hatespeech/hate_speech_dataset-tweets.jsonl',
|
|
349
|
+
'data/multi/en, tr/largescale-hatespeech/hate_speech_dataset.csv']
|
|
350
|
+
labels_df = pd.read_csv(files[1], delimiter=',', index_col=0) # index = tweet_id
|
|
351
|
+
f = open(files[0],'r', encoding='utf-8')
|
|
352
|
+
|
|
353
|
+
data = []
|
|
354
|
+
count_notfound = 0
|
|
355
|
+
for line in f:
|
|
356
|
+
item = json.loads(line)
|
|
357
|
+
if item['id'] not in labels_df.index:
|
|
358
|
+
if int(item['id_str']) not in labels_df.index:
|
|
359
|
+
count_notfound += 1
|
|
360
|
+
continue
|
|
361
|
+
else:
|
|
362
|
+
tweet_id = int(item['id_str'])
|
|
363
|
+
else:
|
|
364
|
+
tweet_id = item['id']
|
|
365
|
+
|
|
366
|
+
lang_id = labels_df.loc[tweet_id].values[0] # LangID is the first column
|
|
367
|
+
if lang_id != int(lang.lower() == 'en'): # 0-Turkish, 1-English
|
|
368
|
+
continue
|
|
369
|
+
|
|
370
|
+
post = {}
|
|
371
|
+
post['text'] = item['full_text'].strip()
|
|
372
|
+
post['label'] = labels_df.loc[tweet_id].values[-1] # HateLabel is the last column
|
|
373
|
+
data.append(post)
|
|
374
|
+
f.close()
|
|
375
|
+
#print(count_notfound, 'labels not found')
|
|
376
|
+
return data
|
|
377
|
+
|
|
378
|
+
def hateval2019(lang, files=None, local=LOCAL, silent=True):
|
|
379
|
+
"""
|
|
380
|
+
hateval2019 (en/es)
|
|
381
|
+
6600 bsp, classes: 0 (non-hate), 1 (hate) -> falls hate: Target Range (0/1), Aggressiveness (0/1)
|
|
382
|
+
anm: returns label als int
|
|
383
|
+
"""
|
|
384
|
+
if lang not in ['en', 'es']:
|
|
385
|
+
if silent == False:
|
|
386
|
+
print('unknown language code:', str(lang))
|
|
387
|
+
return []
|
|
388
|
+
|
|
389
|
+
if local == False:
|
|
390
|
+
fs = datalake(local)
|
|
391
|
+
if not files:
|
|
392
|
+
files = ['/multi/en, es/hateval2019/hateval2019_'+lang.lower()+'_train.csv',
|
|
393
|
+
'/multi/en, es/hateval2019/hateval2019_'+lang.lower()+'_dev.csv',
|
|
394
|
+
'/multi/en, es/hateval2019/hateval2019_'+lang.lower()+'_test.csv']
|
|
395
|
+
else:
|
|
396
|
+
if not files:
|
|
397
|
+
files = ['data/multi/en, es/hateval2019/hateval2019_'+lang.lower()+'_train.csv',
|
|
398
|
+
'data/multi/en, es/hateval2019/hateval2019_'+lang.lower()+'_dev.csv',
|
|
399
|
+
'data/multi/en, es/hateval2019/hateval2019_'+lang.lower()+'_test.csv']
|
|
400
|
+
|
|
401
|
+
data = []
|
|
402
|
+
for file in files:
|
|
403
|
+
if local == False:
|
|
404
|
+
query = {'filename': {'$regex': file+'$'}}
|
|
405
|
+
grid_out = fs.find_one(query)
|
|
406
|
+
f = StringIO(grid_out.read().decode())
|
|
407
|
+
df = pd.read_csv(f, delimiter=',', index_col=0)
|
|
408
|
+
f.close()
|
|
409
|
+
else:
|
|
410
|
+
df = pd.read_csv(file, delimiter=',', index_col=0)
|
|
411
|
+
|
|
412
|
+
for i, row in df.iterrows():
|
|
413
|
+
post = {}
|
|
414
|
+
post['text'] = row['text']
|
|
415
|
+
post['label'] = int(row['HS'])
|
|
416
|
+
data.append(post)
|
|
417
|
+
return data
|
|
418
|
+
|
|
419
|
+
def hasoc2020(lang, files=None, local=LOCAL, silent=True):
|
|
420
|
+
"""
|
|
421
|
+
hasoc-2020 (de/en/hi)
|
|
422
|
+
je ca. 3k bsp, classes: task 1 (NOT/HOF), task 2 (NONE/PRFN/OFFN/HATE)
|
|
423
|
+
"""
|
|
424
|
+
if lang not in ['de', 'en', 'hi']:
|
|
425
|
+
if silent == False:
|
|
426
|
+
print('unknown language code:', str(lang))
|
|
427
|
+
return []
|
|
428
|
+
|
|
429
|
+
if local == False:
|
|
430
|
+
fs = datalake(local)
|
|
431
|
+
if not files:
|
|
432
|
+
files = ['/multi/de, en, hi/hasoc-2020/hasoc_2020_'+lang.lower()+'_train_new.xlsx',
|
|
433
|
+
'/multi/de, en, hi/hasoc-2020/hasoc_2020_'+lang.lower()+'_test_new.xlsx']
|
|
434
|
+
else:
|
|
435
|
+
if not files:
|
|
436
|
+
files = ['data/multi/de, en, hi/hasoc-2020/hasoc_2020_'+lang.lower()+'_train_new.xlsx',
|
|
437
|
+
'data/multi/de, en, hi/hasoc-2020/hasoc_2020_'+lang.lower()+'_test_new.xlsx']
|
|
438
|
+
|
|
439
|
+
data = []
|
|
440
|
+
for file in files:
|
|
441
|
+
if local == False:
|
|
442
|
+
query = {'filename': {'$regex': file+'$'}}
|
|
443
|
+
grid_out = fs.find_one(query)
|
|
444
|
+
f = BytesIO(grid_out.read())
|
|
445
|
+
df = pd.read_excel(f)
|
|
446
|
+
f.close()
|
|
447
|
+
else:
|
|
448
|
+
df = pd.read_excel(file)
|
|
449
|
+
|
|
450
|
+
for i, row in df.iterrows():
|
|
451
|
+
label = row['task1']
|
|
452
|
+
text = row['text'].rstrip()
|
|
453
|
+
|
|
454
|
+
post = {}
|
|
455
|
+
post['text'] = text
|
|
456
|
+
post['label'] = label
|
|
457
|
+
data.append(post)
|
|
458
|
+
return data
|
|
459
|
+
|
|
460
|
+
|
|
461
|
+
# english
|
|
462
|
+
|
|
463
|
+
def en_hate1(files=None, local=LOCAL, silent=True):
|
|
464
|
+
"""
|
|
465
|
+
source: https://github.com/t-davidson/hate-speech-and-offensive-language
|
|
466
|
+
file: labeled_data.csv, len: 24783
|
|
467
|
+
classes: 0 = hate speech, 1 = offensive language, 2 = neither
|
|
468
|
+
|
|
469
|
+
arguments:
|
|
470
|
+
files: list of paths (local fs) or names (gridfs) -> default: see below
|
|
471
|
+
local: bool -> default: True, unless DATALAKE_ADDR is set
|
|
472
|
+
silent: bool -> default: True
|
|
473
|
+
"""
|
|
474
|
+
if local == False:
|
|
475
|
+
fs = datalake(local)
|
|
476
|
+
if not files:
|
|
477
|
+
files = ['/en/hate-speech-and-offensive-language/data/labeled_data.csv']
|
|
478
|
+
|
|
479
|
+
query = {'filename': {'$regex': files[0]+'$'}}
|
|
480
|
+
grid_out = fs.find_one(query)
|
|
481
|
+
f = StringIO(grid_out.read().decode())
|
|
482
|
+
else:
|
|
483
|
+
if not files:
|
|
484
|
+
files = ['data/en/hate-speech-and-offensive-language/data/labeled_data.csv']
|
|
485
|
+
f = open(files[0], 'r', encoding='utf-8')
|
|
486
|
+
|
|
487
|
+
data = []
|
|
488
|
+
df = pd.read_csv(f, dtype=str, keep_default_na=False) # tweets contain commas and line breaks
|
|
489
|
+
for i, row in df.iterrows():
|
|
490
|
+
text = row['tweet'].rstrip()
|
|
491
|
+
|
|
492
|
+
if text == '':
|
|
493
|
+
if silent == False:
|
|
494
|
+
print('empty string')
|
|
495
|
+
continue
|
|
496
|
+
|
|
497
|
+
post = {}
|
|
498
|
+
post['text'] = text
|
|
499
|
+
if row['class'] == '0':
|
|
500
|
+
post['label'] = 'hate_speech'
|
|
501
|
+
elif row['class'] == '1':
|
|
502
|
+
post['label'] = 'offensive_language'
|
|
503
|
+
elif row['class'] == '2':
|
|
504
|
+
post['label'] = 'neither'
|
|
505
|
+
else:
|
|
506
|
+
if silent == False:
|
|
507
|
+
print('LABEL ERROR: %s' % (row['class']))
|
|
508
|
+
continue
|
|
509
|
+
|
|
510
|
+
data.append(post)
|
|
511
|
+
|
|
512
|
+
f.close()
|
|
513
|
+
return data
|
|
514
|
+
|
|
515
|
+
def en_hate2(files=None, local=LOCAL, silent=True):
|
|
516
|
+
"""
|
|
517
|
+
https://github.com/zeerakw/hatespeech bzw. https://github.com/amyhemmeter/AutomaticDetectionofHateSpeech
|
|
518
|
+
text: hatespeech.csv, labels: NAACL_SRW_2016.csv, len: 16035
|
|
519
|
+
classes: racism, sexism, none
|
|
520
|
+
anm: die negative class (none) enthält schwierige beispiele (an der grenze zu offensive), die positive classes (racism, sexism) scheinen inkonsistent -> besser ausschließen
|
|
521
|
+
|
|
522
|
+
arguments:
|
|
523
|
+
files: list of paths (local fs) or names (gridfs) -> default: see below
|
|
524
|
+
local: bool -> default: True, unless DATALAKE_ADDR is set
|
|
525
|
+
silent: bool -> default: True
|
|
526
|
+
"""
|
|
527
|
+
if local == False:
|
|
528
|
+
fs = datalake(local)
|
|
529
|
+
if not files:
|
|
530
|
+
files = ['/en/AutomaticDetectionofHateSpeech/hatespeech.csv',
|
|
531
|
+
'/en/hatespeech/NAACL_SRW_2016.csv']
|
|
532
|
+
|
|
533
|
+
query = {'filename': {'$regex': files[0]+'$'}}
|
|
534
|
+
grid_out = fs.find_one(query)
|
|
535
|
+
f = StringIO(grid_out.read().decode())
|
|
536
|
+
txts_df = pd.read_csv(f, delimiter=',', index_col=0)
|
|
537
|
+
f.close()
|
|
538
|
+
|
|
539
|
+
query = {'filename': {'$regex': files[1]+'$'}}
|
|
540
|
+
grid_out = fs.find_one(query)
|
|
541
|
+
f = StringIO(grid_out.read().decode())
|
|
542
|
+
labels_df = pd.read_csv(f, delimiter=',', index_col=0) # index = tweet_id
|
|
543
|
+
f.close()
|
|
544
|
+
else:
|
|
545
|
+
if not files:
|
|
546
|
+
files = ['data/en/AutomaticDetectionofHateSpeech/hatespeech.csv',
|
|
547
|
+
'data/en/hatespeech/NAACL_SRW_2016.csv']
|
|
548
|
+
txts_df = pd.read_csv(files[0], delimiter=',', index_col=0)
|
|
549
|
+
labels_df = pd.read_csv(files[1], delimiter=',', index_col=0) # index = tweet_id
|
|
550
|
+
|
|
551
|
+
data = []
|
|
552
|
+
for i, row in txts_df.iterrows():
|
|
553
|
+
text = row.iloc[8].rstrip()
|
|
554
|
+
tweet_id = row.iloc[5]
|
|
555
|
+
label_str = labels_df.loc[tweet_id].values[0]
|
|
556
|
+
|
|
557
|
+
if label_str=='racism' or label_str=='sexism': # exclude noisy labels
|
|
558
|
+
continue
|
|
559
|
+
|
|
560
|
+
if text == '':
|
|
561
|
+
if silent == False:
|
|
562
|
+
print('empty string')
|
|
563
|
+
continue
|
|
564
|
+
|
|
565
|
+
post={}
|
|
566
|
+
post['text'] = text
|
|
567
|
+
post['label'] = label_str
|
|
568
|
+
|
|
569
|
+
data.append(post)
|
|
570
|
+
|
|
571
|
+
return data
|
|
572
|
+
|
|
573
|
+
def en_hate3(files=None, local=LOCAL, silent=True):
|
|
574
|
+
"""
|
|
575
|
+
source: https://github.com/aitor-garcia-p/hate-speech-dataset
|
|
576
|
+
labels: annotations_metadata.csv, text: all_files/*.txt, len: 10943
|
|
577
|
+
classes: noHate, hate
|
|
578
|
+
|
|
579
|
+
arguments:
|
|
580
|
+
files: list of paths (local fs) or names (gridfs) -> default: see below
|
|
581
|
+
local: bool -> default: True, unless DATALAKE_ADDR is set
|
|
582
|
+
silent: bool -> default: True
|
|
583
|
+
"""
|
|
584
|
+
if local == False:
|
|
585
|
+
fs = datalake(local)
|
|
586
|
+
if not files:
|
|
587
|
+
files = ['/en/hate-speech-dataset/annotations_metadata.csv',
|
|
588
|
+
'/en/hate-speech-dataset/all_files']
|
|
589
|
+
|
|
590
|
+
query = {'filename': {'$regex': files[0]+'$'}}
|
|
591
|
+
grid_out = fs.find_one(query)
|
|
592
|
+
f = StringIO(grid_out.read().decode())
|
|
593
|
+
labels_df = pd.read_csv(f, delimiter=',')
|
|
594
|
+
f.close()
|
|
595
|
+
else:
|
|
596
|
+
if not files:
|
|
597
|
+
files = ['data/en/hate-speech-dataset/annotations_metadata.csv',
|
|
598
|
+
'data/en/hate-speech-dataset/all_files']
|
|
599
|
+
labels_df = pd.read_csv(files[0], delimiter=',')
|
|
600
|
+
|
|
601
|
+
data = []
|
|
602
|
+
for i, row in labels_df.iterrows():
|
|
603
|
+
label_str = row.iloc[4]
|
|
604
|
+
|
|
605
|
+
if local == False:
|
|
606
|
+
text_path = files[1]+'/'+str(row.iloc[0])+'.txt'
|
|
607
|
+
query = {'filename': {'$regex': text_path+'$'}}
|
|
608
|
+
grid_out = fs.find_one(query)
|
|
609
|
+
f = StringIO(grid_out.read().decode())
|
|
610
|
+
text = f.readline()
|
|
611
|
+
f.close()
|
|
612
|
+
else:
|
|
613
|
+
text_path = files[1]+'/'+str(row.iloc[0])+'.txt'
|
|
614
|
+
with open(text_path, 'r', encoding='utf-8') as f:
|
|
615
|
+
text = f.readline()
|
|
616
|
+
|
|
617
|
+
# ANM: es gibt ein paar dokumente, die zw. 200-300 wörter lang sind -> evtl. hier in einzelne 100-wort-dokumente aufsplitten (ansonsten wird alles über 100 wörter nachher von der padding funktion rausgeworfen)
|
|
618
|
+
|
|
619
|
+
if text == '':
|
|
620
|
+
if silent == False:
|
|
621
|
+
print('empty string')
|
|
622
|
+
continue
|
|
623
|
+
|
|
624
|
+
if label_str not in ['hate', 'noHate']:
|
|
625
|
+
if silent == False:
|
|
626
|
+
print('LABEL ERROR: %s' % (label_str))
|
|
627
|
+
continue
|
|
628
|
+
|
|
629
|
+
post={}
|
|
630
|
+
post['text'] = text
|
|
631
|
+
post['label'] = label_str
|
|
632
|
+
|
|
633
|
+
data.append(post)
|
|
634
|
+
|
|
635
|
+
return data
|
|
636
|
+
|
|
637
|
+
def en_hate4(files=None, local=LOCAL, silent=True):
|
|
638
|
+
"""
|
|
639
|
+
source: https://dataverse.mpi-sws.org/dataset.xhtml?persistentId=doi:10.5072/FK2/ZDTEMN (founta-corpus)
|
|
640
|
+
text: hatespeechtwitter-tweets.csv, labels: hatespeechtwitter.tsv, len: 80000
|
|
641
|
+
classes: normal, abusive, hateful, spam
|
|
642
|
+
anm: abusive entspricht insult + profanity
|
|
643
|
+
|
|
644
|
+
arguments:
|
|
645
|
+
files: list of paths (local fs) or names (gridfs) -> default: see below
|
|
646
|
+
local: bool -> default: True, unless DATALAKE_ADDR is set
|
|
647
|
+
silent: bool -> default: True
|
|
648
|
+
"""
|
|
649
|
+
if local == False:
|
|
650
|
+
fs = datalake(local)
|
|
651
|
+
if not files:
|
|
652
|
+
files = ['/en/founta-corpus/hatespeechtwitter-tweets.csv',
|
|
653
|
+
'/en/founta-corpus/hatespeechtwitter.tsv',
|
|
654
|
+
'/en/re-labelings/founta-corpus-profanity-predicted-edit.csv']
|
|
655
|
+
|
|
656
|
+
query = {'filename': {'$regex': files[0]+'$'}}
|
|
657
|
+
grid_out = fs.find_one(query)
|
|
658
|
+
f = StringIO(grid_out.read().decode())
|
|
659
|
+
txts_df = pd.read_csv(f, delimiter=',', index_col=0)
|
|
660
|
+
f.close()
|
|
661
|
+
|
|
662
|
+
query = {'filename': {'$regex': files[1]+'$'}}
|
|
663
|
+
grid_out = fs.find_one(query)
|
|
664
|
+
f = StringIO(grid_out.read().decode())
|
|
665
|
+
labels_df = pd.read_csv(f, delimiter='\t', index_col=0)
|
|
666
|
+
f.close()
|
|
667
|
+
|
|
668
|
+
query = {'filename': {'$regex': files[2]+'$'}}
|
|
669
|
+
grid_out = fs.find_one(query)
|
|
670
|
+
f = StringIO(grid_out.read().decode())
|
|
671
|
+
data_corr = pd.read_csv(f, delimiter=',', index_col=0) # index = tweet_id
|
|
672
|
+
f.close()
|
|
673
|
+
else:
|
|
674
|
+
if not files:
|
|
675
|
+
files = ['data/en/founta-corpus/hatespeechtwitter-tweets.csv',
|
|
676
|
+
'data/en/founta-corpus/hatespeechtwitter.tsv',
|
|
677
|
+
'data/en/re-labelings/founta-corpus-profanity-predicted-edit.csv']
|
|
678
|
+
txts_df = pd.read_csv(files[0], delimiter=',', index_col=0)
|
|
679
|
+
labels_df = pd.read_csv(files[1], delimiter='\t', index_col=0)
|
|
680
|
+
data_corr = pd.read_csv(files[2], delimiter=',', index_col=0) # index = tweet_id
|
|
681
|
+
|
|
682
|
+
data = []
|
|
683
|
+
for i, row in txts_df.iterrows():
|
|
684
|
+
text = row.iloc[16].rstrip()
|
|
685
|
+
tweet_id = row.iloc[5]
|
|
686
|
+
label_str = labels_df.loc[tweet_id].values[0]
|
|
687
|
+
|
|
688
|
+
if not isinstance(label_str, str):
|
|
689
|
+
if isinstance(label_str, float): # value: nan
|
|
690
|
+
continue
|
|
691
|
+
label_str = label_str[0] # value in array
|
|
692
|
+
|
|
693
|
+
if label_str == 'abusive': # omit the abusive class, the corrected data is loaded seperately
|
|
694
|
+
continue
|
|
695
|
+
|
|
696
|
+
if text == '':
|
|
697
|
+
if silent == False:
|
|
698
|
+
print('empty string')
|
|
699
|
+
continue
|
|
700
|
+
|
|
701
|
+
if label_str not in ['normal', 'hateful', 'spam']:
|
|
702
|
+
if silent == False:
|
|
703
|
+
print('LABEL ERROR: %s' % (label_str))
|
|
704
|
+
continue
|
|
705
|
+
|
|
706
|
+
post={}
|
|
707
|
+
post['text'] = text
|
|
708
|
+
post['label'] = label_str
|
|
709
|
+
|
|
710
|
+
data.append(post)
|
|
711
|
+
|
|
712
|
+
for i, row in data_corr.iterrows():
|
|
713
|
+
text = row.iloc[0].rstrip()
|
|
714
|
+
label_str = row.iloc[2]
|
|
715
|
+
|
|
716
|
+
if text == '':
|
|
717
|
+
if silent == False:
|
|
718
|
+
print('empty string')
|
|
719
|
+
continue
|
|
720
|
+
|
|
721
|
+
post={}
|
|
722
|
+
post['text'] = text
|
|
723
|
+
post['label'] = label_str
|
|
724
|
+
data.append(post)
|
|
725
|
+
|
|
726
|
+
return data
|
|
727
|
+
|
|
728
|
+
"""
|
|
729
|
+
# not in use, data classes not mapping well to the rest + not updated for fine grained data classes
|
|
730
|
+
def en_delft(PATHS):
|
|
731
|
+
#https://github.com/kermitt2/delft/tree/master/data/sequenceLabelling/toxic
|
|
732
|
+
#files: train.csv + test: test.csv, test_labels.csv, len: 1114698
|
|
733
|
+
#PATHS (list): path to texts csv file, path to texts csv file, path to labels csv file
|
|
734
|
+
|
|
735
|
+
data = []
|
|
736
|
+
train_df = pd.read_csv(PATHS[0], delimiter=',', index_col=0)
|
|
737
|
+
test_df = pd.read_csv(PATHS[1], delimiter=',', index_col=0)
|
|
738
|
+
test_labels_df = pd.read_csv(PATHS[2], delimiter=',', index_col=0) # index = tweet_id
|
|
739
|
+
|
|
740
|
+
for i, row in train_df.iterrows():
|
|
741
|
+
post={}
|
|
742
|
+
text = row.iloc[0]
|
|
743
|
+
#text = clean_str(text)
|
|
744
|
+
#text = text.replace('\n\n\n', '|LBR|')
|
|
745
|
+
#text = text.replace('\n\n', '|LBR|')
|
|
746
|
+
#text = text.replace('\n', '|LBR|')
|
|
747
|
+
if text == '':
|
|
748
|
+
print('empty string')
|
|
749
|
+
continue
|
|
750
|
+
|
|
751
|
+
post['text'] = text
|
|
752
|
+
post['label'] = int(1 in row.values)
|
|
753
|
+
|
|
754
|
+
# debug
|
|
755
|
+
#if post['label'] == 1:
|
|
756
|
+
# print(post)
|
|
757
|
+
|
|
758
|
+
data.append(post)
|
|
759
|
+
|
|
760
|
+
for i, row in test_labels_df.iterrows():
|
|
761
|
+
post={}
|
|
762
|
+
text = test_df.loc[i].values[0]
|
|
763
|
+
#text = clean_str(text)
|
|
764
|
+
if text == '':
|
|
765
|
+
print('empty string')
|
|
766
|
+
continue
|
|
767
|
+
|
|
768
|
+
post['text'] = text
|
|
769
|
+
labels = labels = row.values
|
|
770
|
+
post['label'] = int(1 in labels)
|
|
771
|
+
|
|
772
|
+
# debug
|
|
773
|
+
#if post['label'] == 1:
|
|
774
|
+
# print(label)
|
|
775
|
+
# print(post)
|
|
776
|
+
|
|
777
|
+
data.append(post)
|
|
778
|
+
|
|
779
|
+
return data
|
|
780
|
+
"""
|
|
781
|
+
|
|
782
|
+
def en_offense19(files=None, local=LOCAL, silent=True):
|
|
783
|
+
"""
|
|
784
|
+
source: OffensEval 2019 (SemEval 2019 - Task 6)
|
|
785
|
+
files: offenseval-training-v1.tsv, re-lablings: OffensEval-2019-profanity-predicted-edit.csv, total len: 13240
|
|
786
|
+
classes: OFF, NOT
|
|
787
|
+
subtask b: TIN (targeted), UNT (untargeted)
|
|
788
|
+
subtask c: IND (individual), GRP (group), OTH (other)
|
|
789
|
+
|
|
790
|
+
arguments:
|
|
791
|
+
files: list of paths (local fs) or names (gridfs) -> default: see below
|
|
792
|
+
local: bool -> default: True, unless DATALAKE_ADDR is set
|
|
793
|
+
silent: bool -> default: True
|
|
794
|
+
"""
|
|
795
|
+
if local == False:
|
|
796
|
+
fs = datalake(local)
|
|
797
|
+
if not files:
|
|
798
|
+
files = ['/en/OffensEval-2019/offenseval-training-v1.tsv',
|
|
799
|
+
'/en/re-labelings/OffensEval-2019-profanity-predicted-edit.csv']
|
|
800
|
+
|
|
801
|
+
query = {'filename': {'$regex': files[0]+'$'}}
|
|
802
|
+
grid_out = fs.find_one(query)
|
|
803
|
+
f = StringIO(grid_out.read().decode())
|
|
804
|
+
txts_df = pd.read_csv(f, delimiter='\t', index_col=0)
|
|
805
|
+
|
|
806
|
+
query = {'filename': {'$regex': files[1]+'$'}}
|
|
807
|
+
grid_out = fs.find_one(query)
|
|
808
|
+
f = StringIO(grid_out.read().decode())
|
|
809
|
+
data_corr = pd.read_csv(f, delimiter=',', index_col=0) # index = tweet_id
|
|
810
|
+
else:
|
|
811
|
+
if not files:
|
|
812
|
+
files = ['data/en/OffensEval-2019/offenseval-training-v1.tsv',
|
|
813
|
+
'data/en/re-labelings/OffensEval-2019-profanity-predicted-edit.csv']
|
|
814
|
+
|
|
815
|
+
txts_df = pd.read_csv(files[0], delimiter='\t', index_col=0)
|
|
816
|
+
data_corr = pd.read_csv(files[1], delimiter=',', index_col=0) # index = tweet_id
|
|
817
|
+
|
|
818
|
+
data = []
|
|
819
|
+
for i, row in txts_df.iterrows():
|
|
820
|
+
text = row.iloc[0].rstrip()
|
|
821
|
+
label_str = row.iloc[1]
|
|
822
|
+
|
|
823
|
+
if label_str == 'OFF': # omit the offensive class, the corrected data is loaded seperately
|
|
824
|
+
continue
|
|
825
|
+
|
|
826
|
+
if text == '':
|
|
827
|
+
if silent == False:
|
|
828
|
+
print('empty string')
|
|
829
|
+
continue
|
|
830
|
+
|
|
831
|
+
post={}
|
|
832
|
+
post['text'] = text
|
|
833
|
+
post['label'] = 'NOT' # offensive class has been omitted
|
|
834
|
+
data.append(post)
|
|
835
|
+
|
|
836
|
+
for i, row in data_corr.iterrows():
|
|
837
|
+
text = row.iloc[0].rstrip()
|
|
838
|
+
label_str = row.iloc[2]
|
|
839
|
+
|
|
840
|
+
if text == '':
|
|
841
|
+
if silent == False:
|
|
842
|
+
print('empty string')
|
|
843
|
+
continue
|
|
844
|
+
|
|
845
|
+
if label_str not in ['PROF', 'NONE']:
|
|
846
|
+
if silent == False:
|
|
847
|
+
print('LABEL ERROR: %s' % (label_str))
|
|
848
|
+
continue
|
|
849
|
+
|
|
850
|
+
post={}
|
|
851
|
+
post['text'] = text
|
|
852
|
+
post['label'] = label_str
|
|
853
|
+
data.append(post)
|
|
854
|
+
|
|
855
|
+
return data
|
|
856
|
+
|
|
857
|
+
def en_offense20(files=None, local=LOCAL, silent=True):
|
|
858
|
+
"""
|
|
859
|
+
source: OffensEval 2020
|
|
860
|
+
classes: OFF, NOT
|
|
861
|
+
|
|
862
|
+
arguments:
|
|
863
|
+
files: list of paths (local fs) or names (gridfs) -> default: see below
|
|
864
|
+
local: bool -> default: True, unless DATALAKE_ADDR is set
|
|
865
|
+
silent: bool -> default: True
|
|
866
|
+
"""
|
|
867
|
+
if local == False:
|
|
868
|
+
fs = datalake(local)
|
|
869
|
+
if not files:
|
|
870
|
+
files = ['/en/SOLID/semeval_test/test_a_tweets.tsv',
|
|
871
|
+
'/en/SOLID/semeval_test/test_a_labels.csv',
|
|
872
|
+
'/en/SOLID/extended_test/test_a_tweets_all.tsv',
|
|
873
|
+
'/en/SOLID/extended_test/test_a_labels_all.csv',
|
|
874
|
+
'/en/re-labelings/SOLID-testdata-profanity-predicted-edit.csv']
|
|
875
|
+
|
|
876
|
+
query = {'filename': {'$regex': files[0]+'$'}}
|
|
877
|
+
grid_out = fs.find_one(query)
|
|
878
|
+
f = StringIO(grid_out.read().decode())
|
|
879
|
+
txts1_df = pd.read_csv(f, delimiter='\t', index_col=0)
|
|
880
|
+
|
|
881
|
+
query = {'filename': {'$regex': files[1]+'$'}}
|
|
882
|
+
grid_out = fs.find_one(query)
|
|
883
|
+
f = StringIO(grid_out.read().decode())
|
|
884
|
+
labels1_df = pd.read_csv(f, delimiter=',', index_col=0, header=None)
|
|
885
|
+
|
|
886
|
+
query = {'filename': {'$regex': files[2]+'$'}}
|
|
887
|
+
grid_out = fs.find_one(query)
|
|
888
|
+
f = StringIO(grid_out.read().decode())
|
|
889
|
+
txts2_df = pd.read_csv(f, delimiter='\t', index_col=0)
|
|
890
|
+
|
|
891
|
+
query = {'filename': {'$regex': files[3]+'$'}}
|
|
892
|
+
grid_out = fs.find_one(query)
|
|
893
|
+
f = StringIO(grid_out.read().decode())
|
|
894
|
+
labels2_df = pd.read_csv(f, delimiter=',', index_col=0, header=None)
|
|
895
|
+
|
|
896
|
+
query = {'filename': {'$regex': files[4]+'$'}}
|
|
897
|
+
grid_out = fs.find_one(query)
|
|
898
|
+
f = StringIO(grid_out.read().decode())
|
|
899
|
+
data_corr = pd.read_csv(f, delimiter=',', index_col=0)
|
|
900
|
+
else:
|
|
901
|
+
if not files:
|
|
902
|
+
files = ['data/en/OffensEval-2020/SOLID/semeval_test/test_a_tweets.tsv',
|
|
903
|
+
'data/en/OffensEval-2020/SOLID/semeval_test/test_a_labels.csv',
|
|
904
|
+
'data/en/OffensEval-2020/SOLID/extended_test/test_a_tweets_all.tsv',
|
|
905
|
+
'data/en/OffensEval-2020/SOLID/extended_test/test_a_labels_all.csv',
|
|
906
|
+
'data/en/re-labelings/SOLID-testdata-profanity-predicted-edit.csv']
|
|
907
|
+
|
|
908
|
+
txts1_df = pd.read_csv(files[0], delimiter='\t', index_col=0)
|
|
909
|
+
labels1_df = pd.read_csv(files[1], delimiter=',', index_col=0, header=None) # index = tweet_id
|
|
910
|
+
txts2_df = pd.read_csv(files[2], delimiter='\t', index_col=0)
|
|
911
|
+
labels2_df = pd.read_csv(files[3], delimiter=',', index_col=0, header=None) # index = tweet_id
|
|
912
|
+
data_corr = pd.read_csv(files[4], delimiter=',', index_col=0) # index = tweet_id
|
|
913
|
+
|
|
914
|
+
data = []
|
|
915
|
+
for txts_df, labels_df in [(txts1_df, labels1_df), (txts2_df, labels2_df)]:
|
|
916
|
+
for tweet_id, row in txts_df.iterrows():
|
|
917
|
+
text = row.iloc[0].rstrip()
|
|
918
|
+
label_str = labels_df.loc[tweet_id].values[0]
|
|
919
|
+
|
|
920
|
+
if label_str == 'OFF': # omit the offensive class, the corrected data is loaded seperately
|
|
921
|
+
continue
|
|
922
|
+
|
|
923
|
+
#print(tweet_id, '--', row, '\n')
|
|
924
|
+
if tweet_id == 'id':
|
|
925
|
+
continue
|
|
926
|
+
|
|
927
|
+
if text == '':
|
|
928
|
+
if silent == False:
|
|
929
|
+
print('empty string')
|
|
930
|
+
continue
|
|
931
|
+
|
|
932
|
+
post={}
|
|
933
|
+
post['text'] = text
|
|
934
|
+
post['label'] = 'NOT'
|
|
935
|
+
|
|
936
|
+
data.append(post)
|
|
937
|
+
|
|
938
|
+
for i, row in data_corr.iterrows():
|
|
939
|
+
text = row.iloc[0].rstrip()
|
|
940
|
+
label_str = row.iloc[2]
|
|
941
|
+
|
|
942
|
+
if text == '':
|
|
943
|
+
if silent == False:
|
|
944
|
+
print('empty string')
|
|
945
|
+
continue
|
|
946
|
+
|
|
947
|
+
if label_str not in ['PROF', 'NONE']:
|
|
948
|
+
if silent == False:
|
|
949
|
+
print('LABEL ERROR: %s' % (label_str))
|
|
950
|
+
continue
|
|
951
|
+
|
|
952
|
+
post={}
|
|
953
|
+
post['text'] = text
|
|
954
|
+
post['label'] = label_str
|
|
955
|
+
|
|
956
|
+
data.append(post)
|
|
957
|
+
|
|
958
|
+
return data
|
|
959
|
+
|
|
960
|
+
def en_olid(files=None, local=LOCAL, silent=True):
|
|
961
|
+
"""
|
|
962
|
+
OLID
|
|
963
|
+
|
|
964
|
+
arguments:
|
|
965
|
+
files: list of paths (local fs) or names (gridfs) -> default: see below
|
|
966
|
+
local: bool -> default: True, unless DATALAKE_ADDR is set
|
|
967
|
+
"""
|
|
968
|
+
if local == False:
|
|
969
|
+
fs = datalake(local)
|
|
970
|
+
if not files:
|
|
971
|
+
files = ['/en/OLIDv1.0/testset-levela.tsv',
|
|
972
|
+
'/en/OLIDv1.0/labels-levela.csv']
|
|
973
|
+
|
|
974
|
+
query = {'filename': {'$regex': files[0]+'$'}}
|
|
975
|
+
grid_out = fs.find_one(query)
|
|
976
|
+
f = StringIO(grid_out.read().decode())
|
|
977
|
+
txts_df = pd.read_csv(f, delimiter='\t', index_col=0)
|
|
978
|
+
|
|
979
|
+
query = {'filename': {'$regex': files[1]+'$'}}
|
|
980
|
+
grid_out = fs.find_one(query)
|
|
981
|
+
f = StringIO(grid_out.read().decode())
|
|
982
|
+
labels_df = pd.read_csv(f, delimiter=',', index_col=0, header=None) # index = tweet_id
|
|
983
|
+
else:
|
|
984
|
+
if not files:
|
|
985
|
+
files = ['data/en/OLIDv1.0/testset-levela.tsv',
|
|
986
|
+
'data/en/OLIDv1.0/labels-levela.csv']
|
|
987
|
+
|
|
988
|
+
txts_df = pd.read_csv(files[0], delimiter='\t', index_col=0)
|
|
989
|
+
labels_df = pd.read_csv(files[1], delimiter=',', index_col=0, header=None) # index = tweet_id
|
|
990
|
+
|
|
991
|
+
data = []
|
|
992
|
+
for tweet_id, row in txts_df.iterrows():
|
|
993
|
+
text = row.iloc[0].rstrip()
|
|
994
|
+
label_str = labels_df.loc[tweet_id].values[0]
|
|
995
|
+
|
|
996
|
+
#print(tweet_id, '--', row, '\n')
|
|
997
|
+
if tweet_id == 'id':
|
|
998
|
+
continue
|
|
999
|
+
|
|
1000
|
+
if text == '':
|
|
1001
|
+
if silent == False:
|
|
1002
|
+
print('empty string')
|
|
1003
|
+
continue
|
|
1004
|
+
|
|
1005
|
+
if label_str not in ['OFF', 'NOT']:
|
|
1006
|
+
if silent == False:
|
|
1007
|
+
print('LABEL ERROR: %s' % (label_str))
|
|
1008
|
+
continue
|
|
1009
|
+
|
|
1010
|
+
post={}
|
|
1011
|
+
post['text'] = text
|
|
1012
|
+
post['label'] = label_str
|
|
1013
|
+
|
|
1014
|
+
data.append(post)
|
|
1015
|
+
|
|
1016
|
+
return data
|
|
1017
|
+
|
|
1018
|
+
def en_hatexplain(files=None, local=LOCAL, silent=True):
|
|
1019
|
+
"""
|
|
1020
|
+
source: HateXplain
|
|
1021
|
+
file: dataset.json
|
|
1022
|
+
classes: hatespeech, offensive, normal
|
|
1023
|
+
anm: offensive entspricht profanity
|
|
1024
|
+
|
|
1025
|
+
arguments:
|
|
1026
|
+
files: list of paths (local fs) or names (gridfs) -> default: see below
|
|
1027
|
+
local: bool -> default: True, unless DATALAKE_ADDR is set
|
|
1028
|
+
silent: bool -> default: True
|
|
1029
|
+
"""
|
|
1030
|
+
if local == False:
|
|
1031
|
+
fs = datalake(local)
|
|
1032
|
+
if not files:
|
|
1033
|
+
files = ['/en/HateXplain/Data/dataset.json']
|
|
1034
|
+
|
|
1035
|
+
query = {'filename': {'$regex': files[0]+'$'}}
|
|
1036
|
+
grid_out = fs.find_one(query)
|
|
1037
|
+
f = StringIO(grid_out.read().decode())
|
|
1038
|
+
else:
|
|
1039
|
+
if not files:
|
|
1040
|
+
files = ['data/en/HateXplain/HateXplain/Data/dataset.json']
|
|
1041
|
+
f = open(files[0], 'r', encoding='utf-8')
|
|
1042
|
+
|
|
1043
|
+
txts_json = json.load(f)
|
|
1044
|
+
f.close()
|
|
1045
|
+
|
|
1046
|
+
data = []
|
|
1047
|
+
for k, item in txts_json.items():
|
|
1048
|
+
labels = [item['annotators'][0]['label'], item['annotators'][1]['label'], item['annotators'][2]['label']]
|
|
1049
|
+
majority_label = max(set(labels), key = labels.count)
|
|
1050
|
+
if labels.count(majority_label) < 2: # no majority, the label would depend on set order
|
|
1051
|
+
continue
|
|
1052
|
+
#print(labels, '--', majority_label, '\n') # debug
|
|
1053
|
+
|
|
1054
|
+
if majority_label not in ['hatespeech', 'offensive', 'normal']:
|
|
1055
|
+
if silent == False:
|
|
1056
|
+
print('LABEL ERROR: %s' % (label_str))
|
|
1057
|
+
continue
|
|
1058
|
+
|
|
1059
|
+
post={}
|
|
1060
|
+
post['text'] = ' '.join(item['post_tokens'])
|
|
1061
|
+
post['label'] = majority_label
|
|
1062
|
+
|
|
1063
|
+
data.append(post)
|
|
1064
|
+
|
|
1065
|
+
return data
|
|
1066
|
+
|
|
1067
|
+
def en_malignant(files=None, local=LOCAL, silent=True):
|
|
1068
|
+
"""
|
|
1069
|
+
MalignantCommentClassification
|
|
1070
|
+
|
|
1071
|
+
files: train.csv, len: 159571
|
|
1072
|
+
classes: malignant,highly_malignant,rude,threat,abuse,loathe
|
|
1073
|
+
anm:
|
|
1074
|
+
- threats sind gut annotiert, aber nur wenige (ca. 400)
|
|
1075
|
+
- profanity ('rude') alleine kommt selten vor (ca. 300)
|
|
1076
|
+
- malignant/highly_malignant sind eine art überkategorie
|
|
1077
|
+
- es gibt aber auch einige (ca. 5000) bsp die nur als 'malignant' annotiert sind
|
|
1078
|
+
|
|
1079
|
+
arguments:
|
|
1080
|
+
files: list of paths (local fs) or names (gridfs) -> default: see below
|
|
1081
|
+
local: bool -> default: True, unless DATALAKE_ADDR is set
|
|
1082
|
+
silent: bool -> default: True
|
|
1083
|
+
"""
|
|
1084
|
+
if local == False:
|
|
1085
|
+
fs = datalake(local)
|
|
1086
|
+
if not files:
|
|
1087
|
+
files = ['/en/MalignantCommentClassification/train.csv']
|
|
1088
|
+
|
|
1089
|
+
query = {'filename': {'$regex': files[0]+'$'}}
|
|
1090
|
+
grid_out = fs.find_one(query)
|
|
1091
|
+
f = StringIO(grid_out.read().decode())
|
|
1092
|
+
txts_df = pd.read_csv(f, delimiter=',', index_col=0)
|
|
1093
|
+
f.close()
|
|
1094
|
+
else:
|
|
1095
|
+
if not files:
|
|
1096
|
+
files = ['data/en/MalignantCommentClassification/train.csv']
|
|
1097
|
+
txts_df = pd.read_csv(files[0], delimiter=',', index_col=0)
|
|
1098
|
+
|
|
1099
|
+
data = []
|
|
1100
|
+
for i, row in txts_df.iterrows():
|
|
1101
|
+
text = row.iloc[0].rstrip()
|
|
1102
|
+
|
|
1103
|
+
# wikipedia talk pages-specific patterns
|
|
1104
|
+
lines = text.split('\n')
|
|
1105
|
+
lines_new = []
|
|
1106
|
+
for line in lines:
|
|
1107
|
+
for s in ['|', '!', '{|', ':', '[', '(']:
|
|
1108
|
+
if line.startswith(s):
|
|
1109
|
+
continue
|
|
1110
|
+
|
|
1111
|
+
line = re.sub(' *— Preceding.*$', '', line)
|
|
1112
|
+
line = re.sub(' *\(.*\) *$', '', line)
|
|
1113
|
+
line = re.sub('\[\[[\w :|]*\]\]|\[\[[^ ]*\]\]|\{\{[^ ]*\}\}', '', line)
|
|
1114
|
+
line = re.sub('\[\[.*$', '', line)
|
|
1115
|
+
line = re.sub('[^\w]?talk .*[^\w]?$|[^\w]?talk[^\w]? .*$| *talk *$', '', line)
|
|
1116
|
+
|
|
1117
|
+
line = line.replace('Wikipedia:', '').replace('WP:', '').replace('Wikipedia_talk:', '').replace('Image:', '').replace('User talk:', '').replace('contribs/talk', '').replace('++:', '').replace(' WP ', '').replace(' wp ', '').replace('WP:', '')
|
|
1118
|
+
|
|
1119
|
+
lines_new.append(line)
|
|
1120
|
+
|
|
1121
|
+
text = '\n'.join(lines_new)
|
|
1122
|
+
|
|
1123
|
+
if text == '':
|
|
1124
|
+
if silent == False:
|
|
1125
|
+
print('empty string')
|
|
1126
|
+
continue
|
|
1127
|
+
|
|
1128
|
+
post={}
|
|
1129
|
+
post['text'] = text
|
|
1130
|
+
if row.iloc[1] == 1:
|
|
1131
|
+
post['label'] = 'malignant'
|
|
1132
|
+
elif row.iloc[2] == 1:
|
|
1133
|
+
post['label'] = 'highly_malignant'
|
|
1134
|
+
elif row.iloc[3] == 1:
|
|
1135
|
+
post['label'] = 'rude'
|
|
1136
|
+
elif row.iloc[4] == 1:
|
|
1137
|
+
post['label'] = 'threat'
|
|
1138
|
+
elif row.iloc[5] == 1:
|
|
1139
|
+
post['label'] = 'malignant' # abuse: class not compatible with abuse in other datasets
|
|
1140
|
+
elif row.iloc[6] == 1:
|
|
1141
|
+
post['label'] = 'loathe'
|
|
1142
|
+
else:
|
|
1143
|
+
post['label'] = 'normal'
|
|
1144
|
+
|
|
1145
|
+
data.append(post)
|
|
1146
|
+
|
|
1147
|
+
return data
|
|
1148
|
+
|
|
1149
|
+
"""
|
|
1150
|
+
# not in use, data classes not mapping well to the rest
|
|
1151
|
+
def en_cad(files=None, local=LOCAL, silent=True):
|
|
1152
|
+
# ContextualAbuseDataset
|
|
1153
|
+
|
|
1154
|
+
# files: cad_v1_1_train.tsv, cad_v1_1_dev.tsv, cad_v1_1_test.tsv, len total: 23417
|
|
1155
|
+
# classes: Neutral, PersonDirectedAbuse, IdentityDirectedAbuse, AffiliationDirectedAbuse, CounterSpeech
|
|
1156
|
+
# anm:
|
|
1157
|
+
# - die 'abuse' klassen scheinen neutrale, insult und abuse/hate zu enthalten
|
|
1158
|
+
# - die neutralen bsp sind im kontext des threads evtl. abusive, der ist aber nicht abgebildet
|
|
1159
|
+
# - evtl. mit profanity clf trennen versuchen
|
|
1160
|
+
# - die 'neutral' klasse enthält wiederum sehr rohe/unkultivierte aussagen
|
|
1161
|
+
|
|
1162
|
+
# arguments:
|
|
1163
|
+
# files: list of paths (local fs) or names (gridfs) -> default: see below
|
|
1164
|
+
# local: bool -> default: True, unless DATALAKE_ADDR is set
|
|
1165
|
+
# silent: bool -> default: True
|
|
1166
|
+
|
|
1167
|
+
if local == False:
|
|
1168
|
+
if not files:
|
|
1169
|
+
files = ['ContextualAbuseDataset/data/cad_v1_1_train.tsv',
|
|
1170
|
+
'ContextualAbuseDataset/data/cad_v1_1_dev.tsv',
|
|
1171
|
+
'ContextualAbuseDataset/data/cad_v1_1_test.tsv']
|
|
1172
|
+
|
|
1173
|
+
fs = datalake(local)
|
|
1174
|
+
|
|
1175
|
+
query = {'filename': {'$regex': files[0]+'$'}}
|
|
1176
|
+
grid_out = fs.find_one(query)
|
|
1177
|
+
f = StringIO(grid_out.read().decode())
|
|
1178
|
+
train_df = pd.read_csv(f, delimiter='\t', index_col=0)
|
|
1179
|
+
f.close()
|
|
1180
|
+
|
|
1181
|
+
query = {'filename': {'$regex': files[1]+'$'}}
|
|
1182
|
+
grid_out = fs.find_one(query)
|
|
1183
|
+
f = StringIO(grid_out.read().decode())
|
|
1184
|
+
dev_df = pd.read_csv(f, delimiter='\t', index_col=0)
|
|
1185
|
+
f.close()
|
|
1186
|
+
|
|
1187
|
+
query = {'filename': {'$regex': files[2]+'$'}}
|
|
1188
|
+
grid_out = fs.find_one(query)
|
|
1189
|
+
f = StringIO(grid_out.read().decode())
|
|
1190
|
+
test_df = pd.read_csv(f, delimiter='\t', index_col=0)
|
|
1191
|
+
f.close()
|
|
1192
|
+
|
|
1193
|
+
else:
|
|
1194
|
+
if not files:
|
|
1195
|
+
files = ['data/ContextualAbuseDataset/data/cad_v1_1_train.tsv',
|
|
1196
|
+
'data/ContextualAbuseDataset/data/cad_v1_1_dev.tsv',
|
|
1197
|
+
'data/ContextualAbuseDataset/data/cad_v1_1_test.tsv']
|
|
1198
|
+
|
|
1199
|
+
train_df = pd.read_csv(files[0], delimiter='\t', index_col=0)
|
|
1200
|
+
dev_df = pd.read_csv(files[0], delimiter='\t', index_col=0)
|
|
1201
|
+
test_df = pd.read_csv(files[0], delimiter='\t', index_col=0)
|
|
1202
|
+
|
|
1203
|
+
data = []
|
|
1204
|
+
for df in [train_df, dev_tf, test_df]:
|
|
1205
|
+
for i, row in df.iterrows():
|
|
1206
|
+
text = row.iloc[1].rstrip()
|
|
1207
|
+
label_str = row.iloc[2]
|
|
1208
|
+
|
|
1209
|
+
post={}
|
|
1210
|
+
post['text'] = text
|
|
1211
|
+
post['label'] = label_str
|
|
1212
|
+
|
|
1213
|
+
data.append(post)
|
|
1214
|
+
|
|
1215
|
+
return data
|
|
1216
|
+
"""
|
|
1217
|
+
|
|
1218
|
+
def en_threat1(files=None, local=LOCAL, silent=True):
|
|
1219
|
+
"""
|
|
1220
|
+
Muschalik - Threatening in English. Appendix
|
|
1221
|
+
|
|
1222
|
+
files: hexis-english-threats.txt, len: 299
|
|
1223
|
+
classes: all bsp sind OFFENSE + THREAT
|
|
1224
|
+
|
|
1225
|
+
arguments:
|
|
1226
|
+
files: list of paths (local fs) or names (gridfs) -> default: see below
|
|
1227
|
+
local: bool -> default: True, unless DATALAKE_ADDR is set
|
|
1228
|
+
silent: bool -> default: True
|
|
1229
|
+
"""
|
|
1230
|
+
if local == False:
|
|
1231
|
+
fs = datalake(local)
|
|
1232
|
+
if not files:
|
|
1233
|
+
files = ['/hexis/hexis-english-threats/hexis-english-threats.txt']
|
|
1234
|
+
|
|
1235
|
+
query = {'filename': {'$regex': files[0]+'$'}}
|
|
1236
|
+
grid_out = fs.find_one(query)
|
|
1237
|
+
f = StringIO(grid_out.read().decode())
|
|
1238
|
+
else:
|
|
1239
|
+
if not files:
|
|
1240
|
+
files = ['data/hexis/hexis-english-threats/hexis-english-threats.txt']
|
|
1241
|
+
f = open(files[0], 'r', encoding='utf-8')
|
|
1242
|
+
|
|
1243
|
+
data = []
|
|
1244
|
+
for line in f:
|
|
1245
|
+
entry = line.split('\t')
|
|
1246
|
+
text = entry[0].rstrip()
|
|
1247
|
+
|
|
1248
|
+
if text == '':
|
|
1249
|
+
if silent == False:
|
|
1250
|
+
print('empty string')
|
|
1251
|
+
continue
|
|
1252
|
+
|
|
1253
|
+
post={}
|
|
1254
|
+
post['text'] = text
|
|
1255
|
+
post['label'] = entry[1].rstrip()
|
|
1256
|
+
post['label2'] = entry[2].rstrip()
|
|
1257
|
+
|
|
1258
|
+
data.append(post)
|
|
1259
|
+
|
|
1260
|
+
f.close()
|
|
1261
|
+
return data
|
|
1262
|
+
|
|
1263
|
+
def en_spam1(files=None, local=LOCAL, silent=True):
|
|
1264
|
+
"""
|
|
1265
|
+
source: smsspamcollection
|
|
1266
|
+
classes: spam, ham
|
|
1267
|
+
|
|
1268
|
+
arguments:
|
|
1269
|
+
files: list of paths (local fs) or names (gridfs) -> default: see below
|
|
1270
|
+
local: bool -> default: True, unless DATALAKE_ADDR is set
|
|
1271
|
+
silent: bool -> default: True
|
|
1272
|
+
"""
|
|
1273
|
+
if local == False:
|
|
1274
|
+
fs = datalake(local)
|
|
1275
|
+
if not files:
|
|
1276
|
+
files = ['smsspamcollection/SMSSpamCollection.txt']
|
|
1277
|
+
|
|
1278
|
+
query = {'filename': {'$regex': files[0]+'$'}}
|
|
1279
|
+
grid_out = fs.find_one(query)
|
|
1280
|
+
f = StringIO(grid_out.read().decode())
|
|
1281
|
+
else:
|
|
1282
|
+
if not files:
|
|
1283
|
+
files = ['data/spam/smsspamcollection/SMSSpamCollection.txt']
|
|
1284
|
+
f = open(files[0], 'r', encoding='utf-8')
|
|
1285
|
+
|
|
1286
|
+
data = []
|
|
1287
|
+
for line in f:
|
|
1288
|
+
entry = line.split('\t')
|
|
1289
|
+
text = entry[1].rstrip()
|
|
1290
|
+
label_str = entry[0]
|
|
1291
|
+
|
|
1292
|
+
if label_str=='ham': # we only want the spam messages
|
|
1293
|
+
continue
|
|
1294
|
+
|
|
1295
|
+
if text == '':
|
|
1296
|
+
if silent == False:
|
|
1297
|
+
print('empty string')
|
|
1298
|
+
continue
|
|
1299
|
+
|
|
1300
|
+
if len(text.split(' ')) < 4: # ignore very short messages
|
|
1301
|
+
continue
|
|
1302
|
+
|
|
1303
|
+
post = {}
|
|
1304
|
+
post['text'] = text
|
|
1305
|
+
if label_str=='spam':
|
|
1306
|
+
post['label'] = 'spam'
|
|
1307
|
+
else:
|
|
1308
|
+
if silent == False:
|
|
1309
|
+
print('LABEL ERROR: %s' % (label_str))
|
|
1310
|
+
continue
|
|
1311
|
+
|
|
1312
|
+
data.append(post)
|
|
1313
|
+
|
|
1314
|
+
f.close()
|
|
1315
|
+
return data
|
|
1316
|
+
|
|
1317
|
+
|
|
1318
|
+
# german
|
|
1319
|
+
|
|
1320
|
+
def de_germeval(files=None, local=LOCAL, silent=True):
|
|
1321
|
+
"""
|
|
1322
|
+
loader for various versions of the tab-separated germeval format
|
|
1323
|
+
takes one or more paths as input and outputs the parsed and concatenated data
|
|
1324
|
+
|
|
1325
|
+
arguments:
|
|
1326
|
+
files: list of paths (local fs) or names (gridfs)
|
|
1327
|
+
local: bool -> default: True, unless DATALAKE_ADDR is set
|
|
1328
|
+
silent: bool -> default: True
|
|
1329
|
+
"""
|
|
1330
|
+
fs = datalake(local)
|
|
1331
|
+
|
|
1332
|
+
data = []
|
|
1333
|
+
for path in files:
|
|
1334
|
+
if local == False:
|
|
1335
|
+
query = {'filename': {'$regex': path+'$'}}
|
|
1336
|
+
grid_out = fs.find_one(query)
|
|
1337
|
+
f = StringIO(grid_out.read().decode())
|
|
1338
|
+
else:
|
|
1339
|
+
f = open(path,'r', encoding='utf-8')
|
|
1340
|
+
|
|
1341
|
+
for line in f:
|
|
1342
|
+
post={}
|
|
1343
|
+
entry = line.split('\t')
|
|
1344
|
+
#print(entry)
|
|
1345
|
+
|
|
1346
|
+
if len(entry) == 2: # normal germeval format
|
|
1347
|
+
post['text'] = entry[0]
|
|
1348
|
+
post['label'] = entry[1].rstrip()
|
|
1349
|
+
elif len(entry) == 3:
|
|
1350
|
+
if entry[0].isnumeric() == True:
|
|
1351
|
+
post['id'] = entry[0]
|
|
1352
|
+
post['text'] = entry[1]
|
|
1353
|
+
post['label'] = entry[2].rstrip()
|
|
1354
|
+
else:
|
|
1355
|
+
post['text'] = entry[0]
|
|
1356
|
+
post['label'] = entry[1]
|
|
1357
|
+
post['label2'] = entry[2].rstrip()
|
|
1358
|
+
elif len(entry) == 4:
|
|
1359
|
+
if entry[0].isnumeric() == True:
|
|
1360
|
+
post['id'] = entry[0]
|
|
1361
|
+
post['text'] = entry[1]
|
|
1362
|
+
post['label'] = entry[2]
|
|
1363
|
+
post['label2'] = entry[3].rstrip()
|
|
1364
|
+
else:
|
|
1365
|
+
post['text'] = entry[0]
|
|
1366
|
+
post['label'] = entry[1]
|
|
1367
|
+
post['label2'] = entry[2]
|
|
1368
|
+
post['label3'] = entry[3].rstrip()
|
|
1369
|
+
elif len(entry) == 5:
|
|
1370
|
+
post['id'] = entry[0]
|
|
1371
|
+
post['text'] = entry[1]
|
|
1372
|
+
post['label'] = entry[2]
|
|
1373
|
+
post['label2'] = entry[3]
|
|
1374
|
+
post['label3'] = entry[4].rstrip()
|
|
1375
|
+
else:
|
|
1376
|
+
if silent == False:
|
|
1377
|
+
print('FORMAT ERROR:', line)
|
|
1378
|
+
continue
|
|
1379
|
+
|
|
1380
|
+
data.append(post)
|
|
1381
|
+
|
|
1382
|
+
f.close()
|
|
1383
|
+
return data
|
|
1384
|
+
|
|
1385
|
+
"""
|
|
1386
|
+
# not in use, toxic language task not mapping well to the rest
|
|
1387
|
+
def de_germeval2021(paths):
|
|
1388
|
+
# germeval 2021
|
|
1389
|
+
# files: GermEval21_TrainData.csv, GermEval21_TestData.csv
|
|
1390
|
+
# 4190 bsp, classes: Sub1_Toxic (0/1) - andere: Sub2_Engaging, Sub3_FactClaiming
|
|
1391
|
+
|
|
1392
|
+
data = []
|
|
1393
|
+
for path in paths:
|
|
1394
|
+
df = pd.read_csv(path, delimiter=',')
|
|
1395
|
+
for i, row in df.iterrows():
|
|
1396
|
+
post = {}
|
|
1397
|
+
post['text'] = row['comment_text'].rstrip()
|
|
1398
|
+
post['label'] = int(row['Sub1_Toxic'])
|
|
1399
|
+
data.append(post)
|
|
1400
|
+
return data
|
|
1401
|
+
"""
|
|
1402
|
+
|
|
1403
|
+
# spanish
|
|
1404
|
+
|
|
1405
|
+
def es_hate1(files=None, local=LOCAL, silent=True):
|
|
1406
|
+
"""
|
|
1407
|
+
haternet: https://zenodo.org/record/2592149
|
|
1408
|
+
6k bsp, classes: 0 (no-offense), 1 (offense)
|
|
1409
|
+
anm: returns label als int
|
|
1410
|
+
"""
|
|
1411
|
+
if local == False:
|
|
1412
|
+
fs = datalake(local)
|
|
1413
|
+
if not files:
|
|
1414
|
+
files = ['/es/HaterNet/labeled_corpus_6K.txt']
|
|
1415
|
+
query = {'filename': {'$regex': files[0]+'$'}}
|
|
1416
|
+
grid_out = fs.find_one(query)
|
|
1417
|
+
f = StringIO(grid_out.read().decode())
|
|
1418
|
+
else:
|
|
1419
|
+
if not files:
|
|
1420
|
+
files = ['data/es/HaterNet/labeled_corpus_6K.txt']
|
|
1421
|
+
f = open(files[0], 'r', encoding='utf-8')
|
|
1422
|
+
|
|
1423
|
+
data = []
|
|
1424
|
+
for line in f:
|
|
1425
|
+
entry = line.split(';||;')
|
|
1426
|
+
post = {}
|
|
1427
|
+
post['text'] = entry[1].rstrip()
|
|
1428
|
+
post['label'] = int(entry[2].rstrip())
|
|
1429
|
+
data.append(post)
|
|
1430
|
+
return data
|
|
1431
|
+
|
|
1432
|
+
def es_hate2(files=None, local=LOCAL, silent=True):
|
|
1433
|
+
"""
|
|
1434
|
+
violentometro-online
|
|
1435
|
+
4100 bsp (facebook comments: 1969 bsp + mex-a3t auszug: 793+1145+215=2153 bsp), classes: 0 (no-offense), 1 (offense)
|
|
1436
|
+
anm: returns label als int
|
|
1437
|
+
"""
|
|
1438
|
+
if local == False:
|
|
1439
|
+
fs = datalake(local)
|
|
1440
|
+
if not files:
|
|
1441
|
+
files = ['/es/violentometro-online/clean_comentarios_facebook.csv',
|
|
1442
|
+
'/es/violentometro-online/comentarios1.csv',
|
|
1443
|
+
'/es/violentometro-online/comentarios2.csv',
|
|
1444
|
+
'/es/violentometro-online/comentarios3.csv']
|
|
1445
|
+
else:
|
|
1446
|
+
if not files:
|
|
1447
|
+
files = ['data/es/violentometro-online/clean_comentarios_facebook.csv',
|
|
1448
|
+
'data/es/violentometro-online/comentarios1.csv',
|
|
1449
|
+
'data/es/violentometro-online/comentarios2.csv',
|
|
1450
|
+
'data/es/violentometro-online/comentarios3.csv']
|
|
1451
|
+
|
|
1452
|
+
data = []
|
|
1453
|
+
for file in files:
|
|
1454
|
+
if local == False:
|
|
1455
|
+
query = {'filename': {'$regex': file+'$'}}
|
|
1456
|
+
grid_out = fs.find_one(query)
|
|
1457
|
+
f = StringIO(grid_out.read().decode())
|
|
1458
|
+
df = pd.read_csv(f, delimiter=',')
|
|
1459
|
+
f.close()
|
|
1460
|
+
else:
|
|
1461
|
+
df = pd.read_csv(file, delimiter=',')
|
|
1462
|
+
|
|
1463
|
+
for i, row in df.iterrows():
|
|
1464
|
+
if not pd.isna(row['Text']):
|
|
1465
|
+
post = {}
|
|
1466
|
+
post['text'] = row['Text'].rstrip()
|
|
1467
|
+
post['label'] = int(row['Category'])
|
|
1468
|
+
data.append(post)
|
|
1469
|
+
return data
|
|
1470
|
+
|
|
1471
|
+
|
|
1472
|
+
# italian
|
|
1473
|
+
|
|
1474
|
+
def it_hate1(files=None, local=LOCAL, silent=True):
|
|
1475
|
+
"""
|
|
1476
|
+
Italian Hate Speech Corpus (IHSC): https://github.com/msang/hate-speech-corpus
|
|
1477
|
+
6928 bsp, classes: hs (yes/no), aggressiveness (weak/strong/no), offensiveness (weak/strong/no), irony (yes/no), stereotype (yes/no)
|
|
1478
|
+
"""
|
|
1479
|
+
|
|
1480
|
+
if local == False:
|
|
1481
|
+
fs = datalake(local)
|
|
1482
|
+
if not files:
|
|
1483
|
+
files = ['/it/Italian Hate Speech Corpus (IHSC)/IHSC-tweets.csv',
|
|
1484
|
+
'/it/Italian Hate Speech Corpus (IHSC)/IHSC_ids.tsv']
|
|
1485
|
+
|
|
1486
|
+
query = {'filename': {'$regex': files[0]+'$'}}
|
|
1487
|
+
grid_out = fs.find_one(query)
|
|
1488
|
+
f = StringIO(grid_out.read().decode())
|
|
1489
|
+
txts_df = pd.read_csv(f, delimiter=',', index_col=0)
|
|
1490
|
+
f.close()
|
|
1491
|
+
|
|
1492
|
+
query = {'filename': {'$regex': files[1]+'$'}}
|
|
1493
|
+
grid_out = fs.find_one(query)
|
|
1494
|
+
f = StringIO(grid_out.read().decode())
|
|
1495
|
+
labels_df = pd.read_csv(f, delimiter='\t', index_col=0)
|
|
1496
|
+
f.close()
|
|
1497
|
+
else:
|
|
1498
|
+
if not files:
|
|
1499
|
+
files = ['data/it/Italian Hate Speech Corpus (IHSC)/IHSC-tweets.csv',
|
|
1500
|
+
'data/it/Italian Hate Speech Corpus (IHSC)/IHSC_ids.tsv']
|
|
1501
|
+
txts_df = pd.read_csv(files[0], delimiter=',', index_col=0)
|
|
1502
|
+
labels_df = pd.read_csv(files[1], delimiter='\t', index_col=0)
|
|
1503
|
+
|
|
1504
|
+
data = []
|
|
1505
|
+
for i, row in txts_df.iterrows():
|
|
1506
|
+
text = row.iloc[16].rstrip()
|
|
1507
|
+
tweet_id = row.iloc[5]
|
|
1508
|
+
labels = labels_df.loc[tweet_id]
|
|
1509
|
+
post={}
|
|
1510
|
+
post['text'] = text
|
|
1511
|
+
post['label'] = labels.values[0]
|
|
1512
|
+
post['label2'] = labels.values[1]
|
|
1513
|
+
post['label3'] = labels.values[2]
|
|
1514
|
+
data.append(post)
|
|
1515
|
+
return data
|
|
1516
|
+
|
|
1517
|
+
# haspeede 2020
|
|
1518
|
+
# 6839 bsp, classes: non-hate (0), hate (1) - auch vorhanden: stereotype (0/1)
|
|
1519
|
+
it_hate2 = de_germeval
|
|
1520
|
+
|
|
1521
|
+
|
|
1522
|
+
# russian
|
|
1523
|
+
|
|
1524
|
+
def ru_hate1(files=None, local=LOCAL, silent=True):
|
|
1525
|
+
"""
|
|
1526
|
+
russian-inappropriate-messages
|
|
1527
|
+
umfang (human_labeled): 7064 (train.csv), 937 (test.csv), 839 (val.csv)
|
|
1528
|
+
classes (alle floats bis auf human_labeled): inappropriate,offline_crime,online_crime,drugs,gambling,pornography,prostitution,
|
|
1529
|
+
slavery,suicide,terrorism,weapons,body_shaming,health_shaming,politics,racism,religion,sexual_minorities,sexism,social_injustice,human_labeled
|
|
1530
|
+
anm: returns label als int
|
|
1531
|
+
"""
|
|
1532
|
+
if local == False:
|
|
1533
|
+
fs = datalake(local)
|
|
1534
|
+
if not files:
|
|
1535
|
+
files = ['/ru/russian-inappropriate-messages/train.csv',
|
|
1536
|
+
'/ru/russian-inappropriate-messages/test.csv',
|
|
1537
|
+
'/ru/russian-inappropriate-messages/val.csv']
|
|
1538
|
+
else:
|
|
1539
|
+
if not files:
|
|
1540
|
+
files = ['data/ru/russian-inappropriate-messages/train.csv',
|
|
1541
|
+
'data/ru/russian-inappropriate-messages/test.csv',
|
|
1542
|
+
'data/ru/russian-inappropriate-messages/val.csv']
|
|
1543
|
+
|
|
1544
|
+
data = []
|
|
1545
|
+
for file in files:
|
|
1546
|
+
if local == False:
|
|
1547
|
+
query = {'filename': {'$regex': file+'$'}}
|
|
1548
|
+
grid_out = fs.find_one(query)
|
|
1549
|
+
f = StringIO(grid_out.read().decode())
|
|
1550
|
+
df = pd.read_csv(f, delimiter=',')
|
|
1551
|
+
f.close()
|
|
1552
|
+
else:
|
|
1553
|
+
df = pd.read_csv(file, delimiter=',')
|
|
1554
|
+
|
|
1555
|
+
for i, row in df.iterrows():
|
|
1556
|
+
if row['human_labeled'] == 1:
|
|
1557
|
+
text = row['text']
|
|
1558
|
+
label = int(row['inappropriate'] > 0.0) # if inappropriate > 0.0 then label=1 else label=0
|
|
1559
|
+
post={}
|
|
1560
|
+
post['text'] = text
|
|
1561
|
+
post['label'] = label
|
|
1562
|
+
data.append(post)
|
|
1563
|
+
return data
|
|
1564
|
+
|
|
1565
|
+
def ru_hate2(files=None, local=LOCAL, silent=True):
|
|
1566
|
+
"""
|
|
1567
|
+
Russian Language Toxic Comments
|
|
1568
|
+
27857 bsp, classes: non-toxic (0.0), toxic (1.0)
|
|
1569
|
+
anm: returns label als int
|
|
1570
|
+
"""
|
|
1571
|
+
if local == False:
|
|
1572
|
+
fs = datalake(local)
|
|
1573
|
+
if not files:
|
|
1574
|
+
files = ['/ru/Russian Language Toxic Comments/labeled.csv']
|
|
1575
|
+
|
|
1576
|
+
query = {'filename': {'$regex': files[0]+'$'}}
|
|
1577
|
+
grid_out = fs.find_one(query)
|
|
1578
|
+
f = StringIO(grid_out.read().decode())
|
|
1579
|
+
df = pd.read_csv(f, delimiter=',')
|
|
1580
|
+
else:
|
|
1581
|
+
if not files:
|
|
1582
|
+
files = ['data/ru/Russian Language Toxic Comments/labeled.csv']
|
|
1583
|
+
df = pd.read_csv(files[0], delimiter=',')
|
|
1584
|
+
|
|
1585
|
+
data = []
|
|
1586
|
+
for i, row in df.iterrows():
|
|
1587
|
+
post={}
|
|
1588
|
+
post['text'] = row.iloc[0].rstrip()
|
|
1589
|
+
post['label'] = int(row.iloc[1])
|
|
1590
|
+
data.append(post)
|
|
1591
|
+
return data
|
|
1592
|
+
|
|
1593
|
+
def ru_hate3(files=None, local=LOCAL, silent=True):
|
|
1594
|
+
"""
|
|
1595
|
+
RuEthnoHate
|
|
1596
|
+
5594 bsp, classes: -1 (negative), 0 (neutral), 1 (positive)
|
|
1597
|
+
"""
|
|
1598
|
+
if local == False:
|
|
1599
|
+
fs = datalake(local)
|
|
1600
|
+
if not files:
|
|
1601
|
+
files = ['/ru/RuEthnoHate/RuEthnoHate.json']
|
|
1602
|
+
|
|
1603
|
+
query = {'filename': {'$regex': files[0]+'$'}}
|
|
1604
|
+
grid_out = fs.find_one(query)
|
|
1605
|
+
f = StringIO(grid_out.read().decode())
|
|
1606
|
+
else:
|
|
1607
|
+
if not files:
|
|
1608
|
+
files = ['data/ru/RuEthnoHate/RuEthnoHate.json']
|
|
1609
|
+
f = open(files[0], 'r', encoding='utf-8')
|
|
1610
|
+
|
|
1611
|
+
texts = json.loads(f.read())
|
|
1612
|
+
data = []
|
|
1613
|
+
for item in texts:
|
|
1614
|
+
post={}
|
|
1615
|
+
post['text'] = item['text'].rstrip()
|
|
1616
|
+
post['label'] = int(item['class'])
|
|
1617
|
+
data.append(post)
|
|
1618
|
+
return data
|
|
1619
|
+
|
|
1620
|
+
|
|
1621
|
+
# french
|
|
1622
|
+
|
|
1623
|
+
def fr_hate1(files=None, local=LOCAL, silent=True):
|
|
1624
|
+
"""
|
|
1625
|
+
help_dicrah
|
|
1626
|
+
4k bsp, classes: N (neutral), S/H/SH (violent/racist), ENG (nicht weiter kategorisiertes englisch), PUB (spam)
|
|
1627
|
+
"""
|
|
1628
|
+
if local == False:
|
|
1629
|
+
fs = datalake(local)
|
|
1630
|
+
if not files:
|
|
1631
|
+
files = ['/fr/help_dicrah/data/tweets_labeled_4k_cleaned.csv']
|
|
1632
|
+
|
|
1633
|
+
query = {'filename': {'$regex': files[0]+'$'}}
|
|
1634
|
+
grid_out = fs.find_one(query)
|
|
1635
|
+
f = StringIO(grid_out.read().decode())
|
|
1636
|
+
df = pd.read_csv(f, delimiter=',')
|
|
1637
|
+
else:
|
|
1638
|
+
if not files:
|
|
1639
|
+
files = ['data/fr/help_dicrah/data/tweets_labeled_4k_cleaned.csv']
|
|
1640
|
+
df = pd.read_csv(files[0], delimiter=',')
|
|
1641
|
+
|
|
1642
|
+
data = []
|
|
1643
|
+
for i, row in df.iterrows():
|
|
1644
|
+
label = row['Label']
|
|
1645
|
+
text = row['Texte'].rstrip()
|
|
1646
|
+
|
|
1647
|
+
if label in ['ENG', 'PUB']:
|
|
1648
|
+
continue
|
|
1649
|
+
|
|
1650
|
+
post = {}
|
|
1651
|
+
post['text'] = text
|
|
1652
|
+
post['label'] = label
|
|
1653
|
+
data.append(post)
|
|
1654
|
+
return data
|
|
1655
|
+
|
|
1656
|
+
|
|
1657
|
+
# arabic
|
|
1658
|
+
|
|
1659
|
+
def ar_hate1(files=None, local=LOCAL, silent=True):
|
|
1660
|
+
"""
|
|
1661
|
+
Aljazeera Deleted Comments
|
|
1662
|
+
32k bsp, classes: 0 (clean), -1 (offensive), -2 (obscene)
|
|
1663
|
+
anm: returns label als int
|
|
1664
|
+
"""
|
|
1665
|
+
if local == False:
|
|
1666
|
+
fs = datalake(local)
|
|
1667
|
+
if not files:
|
|
1668
|
+
files = ['/ar/Aljazeera Deleted Comments/AJCommentsClassification-CF.xlsx']
|
|
1669
|
+
|
|
1670
|
+
query = {'filename': {'$regex': files[0]+'$'}}
|
|
1671
|
+
grid_out = fs.find_one(query)
|
|
1672
|
+
f = BytesIO(grid_out.read()) #.decode(encoding='cp1256')
|
|
1673
|
+
df = pd.read_excel(f)
|
|
1674
|
+
else:
|
|
1675
|
+
if not files:
|
|
1676
|
+
files = ['data/ar/Aljazeera Deleted Comments/AJCommentsClassification-CF.xlsx']
|
|
1677
|
+
df = pd.read_excel(files[0])
|
|
1678
|
+
|
|
1679
|
+
data = []
|
|
1680
|
+
for i, row in df.iterrows():
|
|
1681
|
+
label = int(row['languagecomment'] != 0) # if label != 0 -> label = 1
|
|
1682
|
+
text = row['body'].rstrip()
|
|
1683
|
+
|
|
1684
|
+
post = {}
|
|
1685
|
+
post['text'] = text
|
|
1686
|
+
post['label'] = label
|
|
1687
|
+
data.append(post)
|
|
1688
|
+
return data
|
|
1689
|
+
|
|
1690
|
+
def ar_hate2(files=None, local=LOCAL, silent=True):
|
|
1691
|
+
"""
|
|
1692
|
+
Corpus_of_offensive_language_in_Arabic
|
|
1693
|
+
15k bsp, classes: N (negative = non-offense), P (positive = offense)
|
|
1694
|
+
"""
|
|
1695
|
+
if local == False:
|
|
1696
|
+
fs = datalake(local)
|
|
1697
|
+
if not files:
|
|
1698
|
+
files = ['/ar/Corpus_of_offensive_language_in_Arabic/LabeledDataset.xlsx']
|
|
1699
|
+
|
|
1700
|
+
query = {'filename': {'$regex': files[0]+'$'}}
|
|
1701
|
+
grid_out = fs.find_one(query)
|
|
1702
|
+
f = BytesIO(grid_out.read())
|
|
1703
|
+
df = pd.read_excel(f)
|
|
1704
|
+
else:
|
|
1705
|
+
if not files:
|
|
1706
|
+
files = ['data/ar/Corpus_of_offensive_language_in_Arabic/LabeledDataset.xlsx']
|
|
1707
|
+
df = pd.read_excel(files[0])
|
|
1708
|
+
|
|
1709
|
+
data = []
|
|
1710
|
+
for i, row in df.iterrows():
|
|
1711
|
+
if not pd.isna(row['commentText']):
|
|
1712
|
+
text = row['commentText'].rstrip()
|
|
1713
|
+
if text == '':
|
|
1714
|
+
text = row['replies.commentText'].rstrip()
|
|
1715
|
+
if text == '':
|
|
1716
|
+
continue
|
|
1717
|
+
else:
|
|
1718
|
+
text = row['replies.commentText'].rstrip()
|
|
1719
|
+
if text == '':
|
|
1720
|
+
continue
|
|
1721
|
+
|
|
1722
|
+
labels = [row['annotator1'], row['annotator2'], row['annotator3']]
|
|
1723
|
+
label = max(set(labels), key=labels.count) # most frequent item in list
|
|
1724
|
+
|
|
1725
|
+
post = {}
|
|
1726
|
+
post['text'] = text
|
|
1727
|
+
post['label'] = label
|
|
1728
|
+
data.append(post)
|
|
1729
|
+
|
|
1730
|
+
return data
|
|
1731
|
+
|
|
1732
|
+
|
|
1733
|
+
# portuguese
|
|
1734
|
+
|
|
1735
|
+
def pt_hate1(files=None, local=LOCAL, silent=True):
|
|
1736
|
+
"""
|
|
1737
|
+
OffComBR
|
|
1738
|
+
2290 bsp, classes: offense (yes), non-offense (no)
|
|
1739
|
+
anm: returns label als int
|
|
1740
|
+
"""
|
|
1741
|
+
if local == False:
|
|
1742
|
+
fs = datalake(local)
|
|
1743
|
+
if not files:
|
|
1744
|
+
files = ['/pt/OffComBR/OffComBR2.csv',
|
|
1745
|
+
'/pt/OffComBR/OffComBR3.csv']
|
|
1746
|
+
else:
|
|
1747
|
+
if not files:
|
|
1748
|
+
files = ['data/pt/OffComBR/OffComBR2.csv',
|
|
1749
|
+
'data/pt/OffComBR/OffComBR3.csv']
|
|
1750
|
+
|
|
1751
|
+
data = []
|
|
1752
|
+
for file in files:
|
|
1753
|
+
if local == False:
|
|
1754
|
+
query = {'filename': {'$regex': file+'$'}}
|
|
1755
|
+
grid_out = fs.find_one(query)
|
|
1756
|
+
f = StringIO(grid_out.read().decode())
|
|
1757
|
+
df = pd.read_csv(f, delimiter=',')
|
|
1758
|
+
f.close()
|
|
1759
|
+
else:
|
|
1760
|
+
df = pd.read_csv(file, delimiter=',')
|
|
1761
|
+
|
|
1762
|
+
for i, row in df.iterrows():
|
|
1763
|
+
post = {}
|
|
1764
|
+
post['text'] = row['document'].strip()
|
|
1765
|
+
post['label'] = int(row['@@class'] == 'yes')
|
|
1766
|
+
data.append(post)
|
|
1767
|
+
return data
|
|
1768
|
+
|
|
1769
|
+
def pt_hate2(files=None, local=LOCAL, silent=True):
|
|
1770
|
+
"""
|
|
1771
|
+
Portuguese-Hate-Speech-Dataset
|
|
1772
|
+
7479 bsp, classes: hate (1), non-hate (0)
|
|
1773
|
+
anm: returns label als int
|
|
1774
|
+
"""
|
|
1775
|
+
if local == False:
|
|
1776
|
+
fs = datalake(local)
|
|
1777
|
+
if not files:
|
|
1778
|
+
files = ['/pt/Portuguese-Hate-Speech-Dataset/2019-05-28_portuguese_hate_speech_binary_classification.csv']
|
|
1779
|
+
|
|
1780
|
+
query = {'filename': {'$regex': files[0]+'$'}}
|
|
1781
|
+
grid_out = fs.find_one(query)
|
|
1782
|
+
f = StringIO(grid_out.read().decode())
|
|
1783
|
+
df = pd.read_csv(f, delimiter=',')
|
|
1784
|
+
else:
|
|
1785
|
+
if not files:
|
|
1786
|
+
files = ['data/pt/Portuguese-Hate-Speech-Dataset/2019-05-28_portuguese_hate_speech_binary_classification.csv']
|
|
1787
|
+
df = pd.read_csv(files[0], delimiter=',')
|
|
1788
|
+
|
|
1789
|
+
data = []
|
|
1790
|
+
for i, row in df.iterrows():
|
|
1791
|
+
post = {}
|
|
1792
|
+
post['text'] = row['text'].strip()
|
|
1793
|
+
post['label'] = int(row['hatespeech_comb'])
|
|
1794
|
+
data.append(post)
|
|
1795
|
+
return data
|
|
1796
|
+
|
|
1797
|
+
def pt_hate3(files=None, local=LOCAL, silent=True):
|
|
1798
|
+
"""
|
|
1799
|
+
ToLD-Br
|
|
1800
|
+
21k bsp, classes: text, homophobia, obscene, insult, racism, misogyny, xenophobia
|
|
1801
|
+
Each column has a value (float) from 0 to 3 representing the number of times this example got flagged as toxic
|
|
1802
|
+
anm: returns label als int
|
|
1803
|
+
"""
|
|
1804
|
+
if local == False:
|
|
1805
|
+
fs = datalake(local)
|
|
1806
|
+
if not files:
|
|
1807
|
+
files = ['/pt/ToLD-Br/ToLD-BR.csv']
|
|
1808
|
+
|
|
1809
|
+
query = {'filename': {'$regex': files[0]+'$'}}
|
|
1810
|
+
grid_out = fs.find_one(query)
|
|
1811
|
+
f = StringIO(grid_out.read().decode())
|
|
1812
|
+
df = pd.read_csv(f, delimiter=',')
|
|
1813
|
+
else:
|
|
1814
|
+
if not files:
|
|
1815
|
+
files = ['data/pt/ToLD-Br/ToLD-Br.csv']
|
|
1816
|
+
df = pd.read_csv(files[0], delimiter=',')
|
|
1817
|
+
|
|
1818
|
+
data = []
|
|
1819
|
+
for i, row in df.iterrows():
|
|
1820
|
+
post = {}
|
|
1821
|
+
post['text'] = row['text'].strip()
|
|
1822
|
+
post['label'] = int(row['homophobia'] > 1 or row['obscene'] > 1 or row['insult'] > 1 or row['racism'] > 1 or row['misogyny'] > 1 or row['xenophobia'] > 1)
|
|
1823
|
+
data.append(post)
|
|
1824
|
+
return data
|
|
1825
|
+
|
|
1826
|
+
|
|
1827
|
+
# turkish
|
|
1828
|
+
|
|
1829
|
+
def tr_troff(files=None, local=LOCAL, silent=True):
|
|
1830
|
+
"""
|
|
1831
|
+
troff
|
|
1832
|
+
36k bsp, classes: non-offensive (non), offensive (prof, grp, ind, oth)
|
|
1833
|
+
"""
|
|
1834
|
+
if local == False:
|
|
1835
|
+
fs = datalake(local)
|
|
1836
|
+
if not files:
|
|
1837
|
+
files = ['/tr/troff/troff-v1.0.tsv']
|
|
1838
|
+
|
|
1839
|
+
query = {'filename': {'$regex': files[0]+'$'}}
|
|
1840
|
+
grid_out = fs.find_one(query)
|
|
1841
|
+
f = StringIO(grid_out.read().decode())
|
|
1842
|
+
df = pd.read_csv(f, delimiter='\t')
|
|
1843
|
+
else:
|
|
1844
|
+
if not files:
|
|
1845
|
+
files = ['data/tr/troff/troff-v1.0.tsv']
|
|
1846
|
+
df = pd.read_csv(files[0], delimiter='\t')
|
|
1847
|
+
|
|
1848
|
+
data = []
|
|
1849
|
+
for i, row in df.iterrows():
|
|
1850
|
+
post = {}
|
|
1851
|
+
post['text'] = row['text'].strip()
|
|
1852
|
+
post['label'] = row['label'].strip()
|
|
1853
|
+
data.append(post)
|
|
1854
|
+
return data
|
|
1855
|
+
|
|
1856
|
+
|
|
1857
|
+
# korean
|
|
1858
|
+
|
|
1859
|
+
def ko_hatescore(files=None, local=LOCAL, silent=True):
|
|
1860
|
+
"""
|
|
1861
|
+
hatescore-korean-hate-speech
|
|
1862
|
+
11k bsp, classes: 혐오발언 (= hate speech), Clean
|
|
1863
|
+
"""
|
|
1864
|
+
if local == False:
|
|
1865
|
+
fs = datalake(local)
|
|
1866
|
+
if not files:
|
|
1867
|
+
files = ['/ko/hatescore-korean-hate-speech/HateScore.csv']
|
|
1868
|
+
|
|
1869
|
+
query = {'filename': {'$regex': files[0]+'$'}}
|
|
1870
|
+
grid_out = fs.find_one(query)
|
|
1871
|
+
f = StringIO(grid_out.read().decode())
|
|
1872
|
+
df = pd.read_csv(f, delimiter=',', index_col=0)
|
|
1873
|
+
else:
|
|
1874
|
+
if not files:
|
|
1875
|
+
files = ['data/ko/hatescore-korean-hate-speech/HateScore.csv']
|
|
1876
|
+
df = pd.read_csv(files[0], delimiter=',', index_col=0)
|
|
1877
|
+
|
|
1878
|
+
data = []
|
|
1879
|
+
for i, row in df.iterrows():
|
|
1880
|
+
post = {}
|
|
1881
|
+
post['text'] = row['comment'].strip()
|
|
1882
|
+
post['label'] = row['macrolabel'].strip()
|
|
1883
|
+
data.append(post)
|
|
1884
|
+
return data
|
|
1885
|
+
|
|
1886
|
+
|
|
1887
|
+
# hindi
|
|
1888
|
+
|
|
1889
|
+
def hi_constraint(files=None, local=LOCAL, silent=True):
|
|
1890
|
+
"""
|
|
1891
|
+
Constraint_AAAI2021
|
|
1892
|
+
8k bsp, classes: non-offensive ('non-hostile'), offensive ('hate', 'offensive'), other ('fake', 'defamation')
|
|
1893
|
+
"""
|
|
1894
|
+
if local == False:
|
|
1895
|
+
fs = datalake(local)
|
|
1896
|
+
if not files:
|
|
1897
|
+
files = ['/hi/Constraint_AAAI2021/constraint_Hindi_Train.xlsx',
|
|
1898
|
+
'/hi/Constraint_AAAI2021/Constraint_Hindi_Valid.xlsx',
|
|
1899
|
+
'/hi/Constraint_AAAI2021/Test Set Complete.xlsx']
|
|
1900
|
+
else:
|
|
1901
|
+
if not files:
|
|
1902
|
+
files = ['data/hi/Constraint_AAAI2021/constraint_Hindi_Train.xlsx',
|
|
1903
|
+
'data/hi/Constraint_AAAI2021/Constraint_Hindi_Valid.xlsx',
|
|
1904
|
+
'data/hi/Constraint_AAAI2021/Test Set Complete.xlsx']
|
|
1905
|
+
|
|
1906
|
+
data = []
|
|
1907
|
+
for file in files:
|
|
1908
|
+
if local == False:
|
|
1909
|
+
query = {'filename': {'$regex': file+'$'}}
|
|
1910
|
+
grid_out = fs.find_one(query)
|
|
1911
|
+
f = BytesIO(grid_out.read())
|
|
1912
|
+
df = pd.read_excel(f)
|
|
1913
|
+
f.close()
|
|
1914
|
+
else:
|
|
1915
|
+
df = pd.read_excel(file)
|
|
1916
|
+
|
|
1917
|
+
for i, row in df.iterrows():
|
|
1918
|
+
post = {}
|
|
1919
|
+
post['text'] = row['Post'].strip()
|
|
1920
|
+
post['label'] = row['Labels Set'].strip()
|
|
1921
|
+
data.append(post)
|
|
1922
|
+
return data
|
|
1923
|
+
|
|
1924
|
+
|
|
1925
|
+
# greek
|
|
1926
|
+
|
|
1927
|
+
def el_offense20(files=None, local=LOCAL, silent=True):
|
|
1928
|
+
"""
|
|
1929
|
+
greek offenseval 2020
|
|
1930
|
+
10k bsp, classes: OFF, NOT
|
|
1931
|
+
"""
|
|
1932
|
+
if local == False:
|
|
1933
|
+
fs = datalake(local)
|
|
1934
|
+
if not files:
|
|
1935
|
+
files = ['/el/offenseval2020-greek/offenseval-gr-training-v1/offenseval-gr-training-v1.tsv',
|
|
1936
|
+
'/el/offenseval2020-greek/offenseval-gr-testsetv1/offenseval-gr-test-v1-combined.tsv']
|
|
1937
|
+
else:
|
|
1938
|
+
if not files:
|
|
1939
|
+
files = ['data/el/offenseval2020-greek/offenseval-gr-training-v1/offenseval-gr-training-v1.tsv',
|
|
1940
|
+
'data/el/offenseval2020-greek/offenseval-gr-testsetv1/offenseval-gr-test-v1-combined.tsv']
|
|
1941
|
+
|
|
1942
|
+
data = []
|
|
1943
|
+
for file in files:
|
|
1944
|
+
if local == False:
|
|
1945
|
+
query = {'filename': {'$regex': file+'$'}}
|
|
1946
|
+
grid_out = fs.find_one(query)
|
|
1947
|
+
f = StringIO(grid_out.read().decode())
|
|
1948
|
+
df = pd.read_csv(f, delimiter='\t', index_col=0)
|
|
1949
|
+
f.close()
|
|
1950
|
+
else:
|
|
1951
|
+
df = pd.read_csv(file, delimiter='\t', index_col=0)
|
|
1952
|
+
|
|
1953
|
+
for i, row in df.iterrows():
|
|
1954
|
+
post = {}
|
|
1955
|
+
post['text'] = row['tweet'].strip()
|
|
1956
|
+
post['label'] = row['subtask_a'].strip()
|
|
1957
|
+
data.append(post)
|
|
1958
|
+
return data
|
|
1959
|
+
|
|
1960
|
+
|
|
1961
|
+
# indonesian
|
|
1962
|
+
|
|
1963
|
+
def id_hate1(files=None, local=LOCAL, silent=True):
|
|
1964
|
+
"""
|
|
1965
|
+
id-hatespeech-detection
|
|
1966
|
+
700 bsp, classes: HS, Non_HS
|
|
1967
|
+
"""
|
|
1968
|
+
if local == False:
|
|
1969
|
+
fs = datalake(local)
|
|
1970
|
+
if not files:
|
|
1971
|
+
files = ['/id/id-hatespeech-detection/IDHSD_RIO_unbalanced_713_2017.txt']
|
|
1972
|
+
|
|
1973
|
+
query = {'filename': {'$regex': files[0]+'$'}}
|
|
1974
|
+
grid_out = fs.find_one(query)
|
|
1975
|
+
f = StringIO(grid_out.read().decode(encoding='cp1252'))
|
|
1976
|
+
df = pd.read_csv(f, delimiter='\t', index_col=False)
|
|
1977
|
+
else:
|
|
1978
|
+
if not files:
|
|
1979
|
+
files = ['data/id/id-hatespeech-detection/IDHSD_RIO_unbalanced_713_2017.txt']
|
|
1980
|
+
df = pd.read_csv(files[0], delimiter='\t', index_col=False)
|
|
1981
|
+
|
|
1982
|
+
data = []
|
|
1983
|
+
for i, row in df.iterrows():
|
|
1984
|
+
post = {}
|
|
1985
|
+
post['text'] = row['Tweet'].strip()
|
|
1986
|
+
post['label'] = row['Label'].strip()
|
|
1987
|
+
data.append(post)
|
|
1988
|
+
return data
|
|
1989
|
+
|
|
1990
|
+
def id_hate2(files=None, local=LOCAL, silent=True):
|
|
1991
|
+
"""
|
|
1992
|
+
id-multi-label-hate-speech-and-abusive-language-detection
|
|
1993
|
+
13k bsp, classes: 0, 1
|
|
1994
|
+
columns: Tweet,HS,Abusive,HS_Individual,HS_Group,HS_Religion,HS_Race,HS_Physical,HS_Gender,HS_Other,HS_Weak,HS_Moderate,HS_Strong
|
|
1995
|
+
"""
|
|
1996
|
+
if local == False:
|
|
1997
|
+
fs = datalake(local)
|
|
1998
|
+
if not files:
|
|
1999
|
+
files = ['/id/id-multi-label-hate-speech-and-abusive-language-detection/re_dataset.csv']
|
|
2000
|
+
|
|
2001
|
+
query = {'filename': {'$regex': files[0]+'$'}}
|
|
2002
|
+
grid_out = fs.find_one(query)
|
|
2003
|
+
f = StringIO(grid_out.read().decode(encoding='cp1252'))
|
|
2004
|
+
df = pd.read_csv(f, delimiter=',', index_col=False)
|
|
2005
|
+
else:
|
|
2006
|
+
if not files:
|
|
2007
|
+
files = ['data/id/id-multi-label-hate-speech-and-abusive-language-detection/re_dataset.csv']
|
|
2008
|
+
df = pd.read_csv(files[0], delimiter=',', index_col=False)
|
|
2009
|
+
|
|
2010
|
+
data = []
|
|
2011
|
+
for i, row in df.iterrows():
|
|
2012
|
+
post = {}
|
|
2013
|
+
post['text'] = row['Tweet'].strip()
|
|
2014
|
+
post['label'] = int(row['HS'] == 1 or row['Abusive'] == 1)
|
|
2015
|
+
data.append(post)
|
|
2016
|
+
return data
|
|
2017
|
+
|
|
2018
|
+
|
|
2019
|
+
# maharati
|
|
2020
|
+
|
|
2021
|
+
def mr_mahahate(files=None, local=LOCAL, silent=True):
|
|
2022
|
+
"""
|
|
2023
|
+
L3Cube-MahaHate
|
|
2024
|
+
37k bsp, classes: HOF, NOT
|
|
2025
|
+
"""
|
|
2026
|
+
if local == False:
|
|
2027
|
+
fs = datalake(local)
|
|
2028
|
+
if not files:
|
|
2029
|
+
files = ['/mr/L3Cube-MahaHate/2-class/hate_bin_train.xlsx',
|
|
2030
|
+
'/mr/L3Cube-MahaHate/2-class/hate_bin_valid.xlsx',
|
|
2031
|
+
'/mr/L3Cube-MahaHate/2-class/hate_bin_test.xlsx']
|
|
2032
|
+
else:
|
|
2033
|
+
if not files:
|
|
2034
|
+
files = ['data/mr/L3Cube-MahaHate/2-class/hate_bin_train.xlsx',
|
|
2035
|
+
'data/mr/L3Cube-MahaHate/2-class/hate_bin_valid.xlsx',
|
|
2036
|
+
'data/mr/L3Cube-MahaHate/2-class/hate_bin_test.xlsx']
|
|
2037
|
+
|
|
2038
|
+
data = []
|
|
2039
|
+
for file in files:
|
|
2040
|
+
if local == False:
|
|
2041
|
+
query = {'filename': {'$regex': file+'$'}}
|
|
2042
|
+
grid_out = fs.find_one(query)
|
|
2043
|
+
f = BytesIO(grid_out.read())
|
|
2044
|
+
df = pd.read_excel(f)
|
|
2045
|
+
f.close()
|
|
2046
|
+
else:
|
|
2047
|
+
df = pd.read_excel(file)
|
|
2048
|
+
|
|
2049
|
+
for i, row in df.iterrows():
|
|
2050
|
+
post = {}
|
|
2051
|
+
post['text'] = row['text'].strip()
|
|
2052
|
+
post['label'] = row['label'].strip()
|
|
2053
|
+
data.append(post)
|
|
2054
|
+
return data
|
|
2055
|
+
|
|
2056
|
+
|
|
2057
|
+
# polish
|
|
2058
|
+
|
|
2059
|
+
def pl_poleval19(files=None, local=LOCAL, silent=True):
|
|
2060
|
+
"""
|
|
2061
|
+
PolEval_2019
|
|
2062
|
+
11k bsp, classes: 0, 1 + multiclass: 0 (non-harmful), 1 (cyberbullying), 2 (hate-speech)
|
|
2063
|
+
"""
|
|
2064
|
+
if local == False:
|
|
2065
|
+
fs = datalake(local)
|
|
2066
|
+
if not files:
|
|
2067
|
+
files = ['/pl/PolEval_2019/data/training_set_texts.txt',
|
|
2068
|
+
'/pl/PolEval_2019/data/training_set_tags.txt']
|
|
2069
|
+
|
|
2070
|
+
query = {'filename': {'$regex': files[0]+'$'}}
|
|
2071
|
+
grid_out = fs.find_one(query)
|
|
2072
|
+
f = StringIO(grid_out.read().decode())
|
|
2073
|
+
texts = f.readlines()
|
|
2074
|
+
f.close()
|
|
2075
|
+
|
|
2076
|
+
query = {'filename': {'$regex': files[1]+'$'}}
|
|
2077
|
+
grid_out = fs.find_one(query)
|
|
2078
|
+
f = StringIO(grid_out.read().decode())
|
|
2079
|
+
labels = f.readlines()
|
|
2080
|
+
f.close()
|
|
2081
|
+
else:
|
|
2082
|
+
if not files:
|
|
2083
|
+
files = ['data/pl/PolEval_2019/data/training_set_texts.txt',
|
|
2084
|
+
'data/pl/PolEval_2019/data/training_set_tags.txt']
|
|
2085
|
+
with open(files[0], 'r') as f:
|
|
2086
|
+
texts = f.readlines()
|
|
2087
|
+
with open(files[1], 'r') as f:
|
|
2088
|
+
labels = f.readlines()
|
|
2089
|
+
|
|
2090
|
+
data = []
|
|
2091
|
+
for text, label in zip(texts, labels):
|
|
2092
|
+
post = {}
|
|
2093
|
+
post['text'] = text.strip().replace('@anonymized_account', '@USER')
|
|
2094
|
+
post['label'] = label.strip()
|
|
2095
|
+
data.append(post)
|
|
2096
|
+
return data
|
|
2097
|
+
|
|
2098
|
+
|
|
2099
|
+
# vietnamese
|
|
2100
|
+
|
|
2101
|
+
def vi_vihsd(files=None, local=LOCAL, silent=True):
|
|
2102
|
+
"""
|
|
2103
|
+
vihsd
|
|
2104
|
+
33k bsp, classes: 0 (clean), 1 (offensive), 2 (hate)
|
|
2105
|
+
"""
|
|
2106
|
+
if local == False:
|
|
2107
|
+
fs = datalake(local)
|
|
2108
|
+
if not files:
|
|
2109
|
+
files = ['/vi/vihsd/data/train.csv',
|
|
2110
|
+
'/vi/vihsd/data/dev.csv',
|
|
2111
|
+
'/vi/vihsd/data/test.csv']
|
|
2112
|
+
else:
|
|
2113
|
+
if not files:
|
|
2114
|
+
files = ['data/vi/vihsd/data/train.csv',
|
|
2115
|
+
'data/vi/vihsd/data/dev.csv',
|
|
2116
|
+
'data/vi/vihsd/data/test.csv']
|
|
2117
|
+
|
|
2118
|
+
data = []
|
|
2119
|
+
for file in files:
|
|
2120
|
+
if local == False:
|
|
2121
|
+
query = {'filename': {'$regex': file+'$'}}
|
|
2122
|
+
grid_out = fs.find_one(query)
|
|
2123
|
+
f = StringIO(grid_out.read().decode())
|
|
2124
|
+
df = pd.read_csv(f, delimiter=',', index_col=False)
|
|
2125
|
+
f.close()
|
|
2126
|
+
else:
|
|
2127
|
+
df = pd.read_csv(file, delimiter=',', index_col=False)
|
|
2128
|
+
|
|
2129
|
+
for i, row in df.iterrows():
|
|
2130
|
+
if pd.isna(row['free_text']):
|
|
2131
|
+
continue
|
|
2132
|
+
post = {}
|
|
2133
|
+
post['text'] = row['free_text'].strip()
|
|
2134
|
+
post['label'] = row['label_id']
|
|
2135
|
+
data.append(post)
|
|
2136
|
+
return data
|
|
2137
|
+
|
|
2138
|
+
|
|
2139
|
+
# danish
|
|
2140
|
+
|
|
2141
|
+
def da_dkhate(files=None, local=LOCAL, silent=True):
|
|
2142
|
+
"""
|
|
2143
|
+
dkhate
|
|
2144
|
+
3k bsp, classes: OFF, NOT
|
|
2145
|
+
"""
|
|
2146
|
+
if local == False:
|
|
2147
|
+
fs = datalake(local)
|
|
2148
|
+
if not files:
|
|
2149
|
+
files = ['/da/dkhate/oe20da_data/offenseval-da-training-v1.tsv',
|
|
2150
|
+
'/da/dkhate/oe20da_data/offenseval-da-test-v1.tsv']
|
|
2151
|
+
else:
|
|
2152
|
+
if not files:
|
|
2153
|
+
files = ['data/da/dkhate/oe20da_data/offenseval-da-training-v1.tsv',
|
|
2154
|
+
'data/da/dkhate/oe20da_data/offenseval-da-test-v1.tsv']
|
|
2155
|
+
|
|
2156
|
+
data = []
|
|
2157
|
+
for file in files:
|
|
2158
|
+
if local == False:
|
|
2159
|
+
query = {'filename': {'$regex': file+'$'}}
|
|
2160
|
+
grid_out = fs.find_one(query)
|
|
2161
|
+
f = StringIO(grid_out.read().decode())
|
|
2162
|
+
df = pd.read_csv(f, delimiter='\t', index_col=False)
|
|
2163
|
+
f.close()
|
|
2164
|
+
else:
|
|
2165
|
+
df = pd.read_csv(file, delimiter='\t', index_col=False)
|
|
2166
|
+
|
|
2167
|
+
for i, row in df.iterrows():
|
|
2168
|
+
if pd.isna(row['tweet']):
|
|
2169
|
+
continue
|
|
2170
|
+
post = {}
|
|
2171
|
+
post['text'] = row['tweet'].strip()
|
|
2172
|
+
post['label'] = row['subtask_a'].strip()
|
|
2173
|
+
data.append(post)
|
|
2174
|
+
return data
|
|
2175
|
+
|
|
2176
|
+
|
|
2177
|
+
# dutch
|
|
2178
|
+
|
|
2179
|
+
def nl_dalc(files=None, local=LOCAL, silent=True):
|
|
2180
|
+
"""
|
|
2181
|
+
DALC
|
|
2182
|
+
11k bsp, classes: NOT, EXPLICIT, IMPLICIT
|
|
2183
|
+
columns: id,abusive,offensive_aggregated,target_aggregated,abusive_offensive_not,offense_a1,offense_a2,offense_a3,offense_a4,target_a1,target_a2,target_a3,target_a4
|
|
2184
|
+
"""
|
|
2185
|
+
if local == False:
|
|
2186
|
+
fs = datalake(local)
|
|
2187
|
+
if not files:
|
|
2188
|
+
files = ['/nl/DALC/v2.0/data/DALC-2_train-tweets.jsonl',
|
|
2189
|
+
'/nl/DALC/v2.0/data/DALC-2_train.csv']
|
|
2190
|
+
|
|
2191
|
+
query = {'filename': {'$regex': files[1]+'$'}}
|
|
2192
|
+
grid_out = fs.find_one(query)
|
|
2193
|
+
f = StringIO(grid_out.read().decode())
|
|
2194
|
+
labels_df = pd.read_csv(f, delimiter=',', index_col=0) # index = tweet_id
|
|
2195
|
+
f.close()
|
|
2196
|
+
|
|
2197
|
+
query = {'filename': {'$regex': files[0]+'$'}}
|
|
2198
|
+
grid_out = fs.find_one(query)
|
|
2199
|
+
f = StringIO(grid_out.read().decode())
|
|
2200
|
+
else:
|
|
2201
|
+
if not files:
|
|
2202
|
+
files = ['data/nl/DALC/v2.0/data/DALC-2_train-tweets.jsonl',
|
|
2203
|
+
'data/nl/DALC/v2.0/data/DALC-2_train.csv']
|
|
2204
|
+
labels_df = pd.read_csv(files[1], delimiter=',', index_col=0) # index = tweet_id
|
|
2205
|
+
f = open(files[0],'r', encoding='utf-8')
|
|
2206
|
+
|
|
2207
|
+
data = []
|
|
2208
|
+
count_notfound = 0
|
|
2209
|
+
for line in f:
|
|
2210
|
+
item = json.loads(line)
|
|
2211
|
+
if item['id'] not in labels_df.index:
|
|
2212
|
+
if int(item['id_str']) not in labels_df.index:
|
|
2213
|
+
count_notfound += 1
|
|
2214
|
+
continue
|
|
2215
|
+
else:
|
|
2216
|
+
tweet_id = int(item['id_str'])
|
|
2217
|
+
else:
|
|
2218
|
+
tweet_id = item['id']
|
|
2219
|
+
|
|
2220
|
+
post = {}
|
|
2221
|
+
post['text'] = item['full_text'].strip()
|
|
2222
|
+
post['label'] = int(labels_df.loc[tweet_id].values[0] != 'NOT' or labels_df.loc[tweet_id].values[1] != 'NOT') # col 0 = abusive, col 1 = offensive_aggregated
|
|
2223
|
+
data.append(post)
|
|
2224
|
+
f.close()
|
|
2225
|
+
#print(count_notfound, 'labels not found')
|
|
2226
|
+
return data
|
|
2227
|
+
|
|
2228
|
+
|
|
2229
|
+
# backwards compatibility for autofit v1
|
|
2230
|
+
|
|
2231
|
+
hate1 = en_hate1
|
|
2232
|
+
hate2 = en_hate2
|
|
2233
|
+
hate3 = en_hate3
|
|
2234
|
+
hate4 = en_hate4
|
|
2235
|
+
offense19 = en_offense19
|
|
2236
|
+
offense20 = en_offense20
|
|
2237
|
+
olid = en_olid
|
|
2238
|
+
hatexplain = en_hatexplain
|
|
2239
|
+
malignant = en_malignant
|
|
2240
|
+
threat1 = en_threat1
|
|
2241
|
+
spam1 = en_spam1
|
|
2242
|
+
germeval = de_germeval
|