Update files from the datasets library (from 1.16.0)
Browse filesRelease notes: https://github.com/huggingface/datasets/releases/tag/1.16.0
- README.md +1 -0
- md_gender_bias.py +62 -38
README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
---
|
|
|
2 |
annotations_creators:
|
3 |
convai2_inferred:
|
4 |
- machine-generated
|
|
|
1 |
---
|
2 |
+
pretty_name: Multi-Dimensional Gender Bias Classification
|
3 |
annotations_creators:
|
4 |
convai2_inferred:
|
5 |
- machine-generated
|
md_gender_bias.py
CHANGED
@@ -16,7 +16,6 @@
|
|
16 |
|
17 |
|
18 |
import json
|
19 |
-
import os
|
20 |
|
21 |
import datasets
|
22 |
|
@@ -299,7 +298,8 @@ class MdGenderBias(datasets.GeneratorBasedBuilder):
|
|
299 |
|
300 |
def _split_generators(self, dl_manager):
|
301 |
"""Returns SplitGenerators."""
|
302 |
-
|
|
|
303 |
if self.config.name == "gendered_words":
|
304 |
return [
|
305 |
datasets.SplitGenerator(
|
@@ -307,9 +307,10 @@ class MdGenderBias(datasets.GeneratorBasedBuilder):
|
|
307 |
gen_kwargs={
|
308 |
"filepath": None,
|
309 |
"filepath_pair": (
|
310 |
-
|
311 |
-
|
312 |
),
|
|
|
313 |
},
|
314 |
)
|
315 |
]
|
@@ -318,8 +319,9 @@ class MdGenderBias(datasets.GeneratorBasedBuilder):
|
|
318 |
datasets.SplitGenerator(
|
319 |
name=f"yob{yob}",
|
320 |
gen_kwargs={
|
321 |
-
"filepath":
|
322 |
"filepath_pair": None,
|
|
|
323 |
},
|
324 |
)
|
325 |
for yob in range(1880, 2019)
|
@@ -329,8 +331,9 @@ class MdGenderBias(datasets.GeneratorBasedBuilder):
|
|
329 |
datasets.SplitGenerator(
|
330 |
name=datasets.Split.TRAIN,
|
331 |
gen_kwargs={
|
332 |
-
"filepath":
|
333 |
"filepath_pair": None,
|
|
|
334 |
},
|
335 |
)
|
336 |
]
|
@@ -339,8 +342,9 @@ class MdGenderBias(datasets.GeneratorBasedBuilder):
|
|
339 |
datasets.SplitGenerator(
|
340 |
name=spl,
|
341 |
gen_kwargs={
|
342 |
-
"filepath":
|
343 |
"filepath_pair": None,
|
|
|
344 |
},
|
345 |
)
|
346 |
for spl, fname in _CONF_FILES[self.config.name].items()
|
@@ -352,45 +356,62 @@ class MdGenderBias(datasets.GeneratorBasedBuilder):
|
|
352 |
gen_kwargs={
|
353 |
"filepath": None,
|
354 |
"filepath_pair": (
|
355 |
-
|
356 |
-
|
357 |
),
|
|
|
358 |
},
|
359 |
)
|
360 |
for spl, (fname_1, fname_2) in _CONF_FILES[self.config.name].items()
|
361 |
]
|
362 |
|
363 |
-
def _generate_examples(self, filepath, filepath_pair):
|
364 |
if self.config.name == "gendered_words":
|
365 |
-
|
366 |
-
|
367 |
-
|
|
|
|
|
|
|
|
|
|
|
368 |
yield id_, {
|
369 |
"word_masculine": l_m.strip(),
|
370 |
"word_feminine": l_f.strip(),
|
371 |
}
|
|
|
372 |
elif self.config.name == "name_genders":
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
"name": name,
|
378 |
-
"assigned_gender": g,
|
379 |
-
"count": int(ct),
|
380 |
-
}
|
381 |
-
elif "_inferred" in self.config.name:
|
382 |
-
with open(filepath_pair[0], encoding="utf-8") as f_b:
|
383 |
-
if "yelp" in self.config.name:
|
384 |
-
for id_, line_b in enumerate(f_b):
|
385 |
-
text_b, label_b, score_b = line_b.split("\t")
|
386 |
yield id_, {
|
387 |
-
"
|
388 |
-
"
|
389 |
-
"
|
390 |
}
|
391 |
-
|
392 |
-
|
393 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
394 |
text_b, label_b, score_b = line_b.split("\t")
|
395 |
text_t, label_t, score_t = line_t.split("\t")
|
396 |
yield id_, {
|
@@ -400,10 +421,13 @@ class MdGenderBias(datasets.GeneratorBasedBuilder):
|
|
400 |
"ternary_label": label_t,
|
401 |
"ternary_score": float(score_t.strip()),
|
402 |
}
|
|
|
403 |
else:
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
example["turker_gender"]
|
409 |
-
|
|
|
|
|
|
16 |
|
17 |
|
18 |
import json
|
|
|
19 |
|
20 |
import datasets
|
21 |
|
|
|
298 |
|
299 |
def _split_generators(self, dl_manager):
|
300 |
"""Returns SplitGenerators."""
|
301 |
+
archive = dl_manager.download(_URL)
|
302 |
+
data_dir = "data_to_release"
|
303 |
if self.config.name == "gendered_words":
|
304 |
return [
|
305 |
datasets.SplitGenerator(
|
|
|
307 |
gen_kwargs={
|
308 |
"filepath": None,
|
309 |
"filepath_pair": (
|
310 |
+
data_dir + "/" + "word_list/male_word_file.txt",
|
311 |
+
data_dir + "/" + "word_list/female_word_file.txt",
|
312 |
),
|
313 |
+
"files": dl_manager.iter_archive(archive),
|
314 |
},
|
315 |
)
|
316 |
]
|
|
|
319 |
datasets.SplitGenerator(
|
320 |
name=f"yob{yob}",
|
321 |
gen_kwargs={
|
322 |
+
"filepath": data_dir + "/" + f"names/yob{yob}.txt",
|
323 |
"filepath_pair": None,
|
324 |
+
"files": dl_manager.iter_archive(archive),
|
325 |
},
|
326 |
)
|
327 |
for yob in range(1880, 2019)
|
|
|
331 |
datasets.SplitGenerator(
|
332 |
name=datasets.Split.TRAIN,
|
333 |
gen_kwargs={
|
334 |
+
"filepath": data_dir + "/" + "new_data/data.jsonl",
|
335 |
"filepath_pair": None,
|
336 |
+
"files": dl_manager.iter_archive(archive),
|
337 |
},
|
338 |
)
|
339 |
]
|
|
|
342 |
datasets.SplitGenerator(
|
343 |
name=spl,
|
344 |
gen_kwargs={
|
345 |
+
"filepath": data_dir + "/" + fname,
|
346 |
"filepath_pair": None,
|
347 |
+
"files": dl_manager.iter_archive(archive),
|
348 |
},
|
349 |
)
|
350 |
for spl, fname in _CONF_FILES[self.config.name].items()
|
|
|
356 |
gen_kwargs={
|
357 |
"filepath": None,
|
358 |
"filepath_pair": (
|
359 |
+
data_dir + "/" + fname_1,
|
360 |
+
data_dir + "/" + fname_2,
|
361 |
),
|
362 |
+
"files": dl_manager.iter_archive(archive),
|
363 |
},
|
364 |
)
|
365 |
for spl, (fname_1, fname_2) in _CONF_FILES[self.config.name].items()
|
366 |
]
|
367 |
|
368 |
+
def _generate_examples(self, filepath, filepath_pair, files):
|
369 |
if self.config.name == "gendered_words":
|
370 |
+
male_data, female_data = None, None
|
371 |
+
for path, f in files:
|
372 |
+
if path == filepath_pair[0]:
|
373 |
+
male_data = f.read().decode("utf-8").splitlines()
|
374 |
+
elif path == filepath_pair[1]:
|
375 |
+
female_data = f.read().decode("utf-8").splitlines()
|
376 |
+
if male_data is not None and female_data is not None:
|
377 |
+
for id_, (l_m, l_f) in enumerate(zip(male_data, female_data)):
|
378 |
yield id_, {
|
379 |
"word_masculine": l_m.strip(),
|
380 |
"word_feminine": l_f.strip(),
|
381 |
}
|
382 |
+
break
|
383 |
elif self.config.name == "name_genders":
|
384 |
+
for path, f in files:
|
385 |
+
if path == filepath:
|
386 |
+
for id_, line in enumerate(f):
|
387 |
+
name, g, ct = line.decode("utf-8").strip().split(",")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
388 |
yield id_, {
|
389 |
+
"name": name,
|
390 |
+
"assigned_gender": g,
|
391 |
+
"count": int(ct),
|
392 |
}
|
393 |
+
break
|
394 |
+
elif "_inferred" in self.config.name:
|
395 |
+
if "yelp" in self.config.name:
|
396 |
+
for path, f in files:
|
397 |
+
if path == filepath_pair[0]:
|
398 |
+
for id_, line_b in enumerate(f):
|
399 |
+
text_b, label_b, score_b = line_b.decode("utf-8").split("\t")
|
400 |
+
yield id_, {
|
401 |
+
"text": text_b,
|
402 |
+
"binary_label": label_b,
|
403 |
+
"binary_score": float(score_b.strip()),
|
404 |
+
}
|
405 |
+
break
|
406 |
+
else:
|
407 |
+
binary_data, ternary_data = None, None
|
408 |
+
for path, f in files:
|
409 |
+
if path == filepath_pair[0]:
|
410 |
+
binary_data = f.read().decode("utf-8").splitlines()
|
411 |
+
elif path == filepath_pair[1]:
|
412 |
+
ternary_data = f.read().decode("utf-8").splitlines()
|
413 |
+
if binary_data is not None and ternary_data is not None:
|
414 |
+
for id_, (line_b, line_t) in enumerate(zip(binary_data, ternary_data)):
|
415 |
text_b, label_b, score_b = line_b.split("\t")
|
416 |
text_t, label_t, score_t = line_t.split("\t")
|
417 |
yield id_, {
|
|
|
421 |
"ternary_label": label_t,
|
422 |
"ternary_score": float(score_t.strip()),
|
423 |
}
|
424 |
+
break
|
425 |
else:
|
426 |
+
for path, f in files:
|
427 |
+
if path == filepath:
|
428 |
+
for id_, line in enumerate(f):
|
429 |
+
example = json.loads(line.decode("utf-8").strip())
|
430 |
+
if "turker_gender" in example and example["turker_gender"] is None:
|
431 |
+
example["turker_gender"] = "no answer"
|
432 |
+
yield id_, example
|
433 |
+
break
|