|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"""HumSetBias""" |
|
|
|
import json |
|
import datasets |
|
|
|
|
|
_CITATION = """""" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_DESCRIPTION_BIAS = """\ |
|
HUMSETBIAS is a subset of the English part of the HumSet dataset, created by searching for specific sensitive English keywords related to genders and countries within the annotated text. In addition, we extended this |
|
subset by incorporating targeted counterfactual samples, generated by modifying the original entries in order to create the altered versions of each text with gender/country information. The purpose of HUMSETBIAS is to provide a more targeted resource for analyzing and addressing potential biases in humanitarian data and to enable the development of accurate and bias-aware NLP applications in the humanitarian sector. |
|
""" |
|
|
|
_HOMEPAGE = "https://huggingface.co/datasets/nlp-thedeep/humsetbias" |
|
|
|
_LICENSE = "The GitHub repository which houses this dataset has an Apache License 2.0." |
|
|
|
|
|
_URLs = { |
|
"1.0.0": { |
|
"train": "data/humset_bias_train.jsonl", |
|
"dev": "data/humset_bias_val.jsonl", |
|
|
|
|
|
} |
|
} |
|
|
|
|
|
_SUPPORTED_VERSIONS = [ |
|
|
|
datasets.Version("1.0.0", "Gender and Country bias extension of HumSet") |
|
] |
|
|
|
|
|
""" |
|
from: https://huggingface.co/docs/datasets/v2.9.0/en/package_reference/main_classes#datasets.Sequence |
|
a python list or a Sequence specifies that the field contains a list of objects. |
|
The python list or Sequence should be provided with a single sub-feature as an example of the feature type hosted in this list. |
|
""" |
|
|
|
|
|
HUMSETBIAS_FEATURES = datasets.Features( |
|
{ |
|
"entry_id": datasets.Value("string"), |
|
"excerpt": datasets.Value("string"), |
|
"lang": datasets.Value("string"), |
|
"keywords": datasets.Sequence(datasets.Value("string"), length=-1), |
|
"kword_type": datasets.Sequence(datasets.Value("string"), length=-1), |
|
"gender_keywords": datasets.Sequence(datasets.Value("string"), length=-1), |
|
"country_keywords": datasets.Sequence(datasets.Value("string"), length=-1), |
|
"gender_kword_type": datasets.Sequence(datasets.Value("string"), length=-1), |
|
"country_kword_type": datasets.Sequence(datasets.Value("string"), length=-1), |
|
"gender_context_falsing_kw": datasets.Sequence(datasets.Value("string"), length=-1), |
|
"country_context_falsing_kw": datasets.Sequence(datasets.Value("string"), length=-1), |
|
"excerpt_type": datasets.Value("string"), |
|
"sectors": datasets.Sequence(datasets.Value("string"), length=-1), |
|
"pillars_1d": datasets.Sequence(datasets.Value("string"), length=-1), |
|
"pillars_2d": datasets.Sequence(datasets.Value("string"), length=-1), |
|
"subpillars_1d": datasets.Sequence(datasets.Value("string"), length=-1), |
|
"subpillars_2d": datasets.Sequence(datasets.Value("string"), length=-1), |
|
} |
|
) |
|
|
|
"""" |
|
HUMSETBIAS_GENERAL = [ |
|
'entry_id', |
|
'excerpt', |
|
"lang", |
|
'excerpt_type', |
|
"gender_keywords", |
|
"country_keywords", |
|
"gender_kword_type", |
|
"country_kword_type", |
|
'gender_context_falsing_kw', |
|
"country_context_falsing_kw", |
|
"sectors", |
|
"pillars_1d", |
|
"pillars_2d", |
|
"subpillars_1d", |
|
"subpillars_2d" |
|
] |
|
|
|
HUMSETBIAS_FEATURES_GENDER = [ |
|
'entry_id', |
|
'excerpt', |
|
"lang", |
|
'keywords', |
|
'kword_type', |
|
'excerpt_type', |
|
'gender_context_falsing_kw', |
|
"sectors", |
|
"pillars_1d", |
|
"pillars_2d", |
|
"subpillars_1d", |
|
"subpillars_2d" |
|
] |
|
|
|
HUMSETBIAS_FEATURES_COUNTRY = [ |
|
'entry_id', |
|
'excerpt', |
|
"lang", |
|
'keywords', |
|
'kword_type', |
|
'excerpt_type', |
|
'country_context_falsing_kw', |
|
"sectors", |
|
"pillars_1d", |
|
"pillars_2d", |
|
"subpillars_1d", |
|
"subpillars_2d" |
|
] |
|
""" |
|
|
|
|
|
class HumsetConfig(datasets.BuilderConfig): |
|
"""BuilderConfig for HumsetBias.""" |
|
|
|
def __init__(self, **kwargs): |
|
"""BuilderConfig for HumsetBias SelfRC. |
|
Args: |
|
**kwargs: keyword arguments forwarded to super. |
|
""" |
|
super(HumsetConfig, self).__init__(**kwargs) |
|
|
|
|
|
class Humset(datasets.GeneratorBasedBuilder): |
|
|
|
BUILDER_CONFIGS = [ |
|
HumsetConfig( |
|
name=str(version), |
|
description=f"version {str(version)}", |
|
version=version |
|
) |
|
for version in _SUPPORTED_VERSIONS |
|
] |
|
|
|
DEFAULT_CONFIG_NAME = "1.0.0" |
|
|
|
def _info(self): |
|
|
|
if self.config.name == "1.0.0": |
|
return datasets.DatasetInfo( |
|
|
|
description=_DESCRIPTION_BIAS, |
|
|
|
features=HUMSETBIAS_FEATURES, |
|
homepage=_HOMEPAGE, |
|
license=_LICENSE, |
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
|
|
"""Returns SplitGenerators.""" |
|
|
|
my_urls = _URLs[self.config.name] |
|
downloaded_files = dl_manager.download_and_extract(my_urls) |
|
splits = [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
gen_kwargs={ |
|
"filepath": downloaded_files["train"], |
|
}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.VALIDATION, |
|
gen_kwargs={ |
|
"filepath": downloaded_files["dev"] |
|
}, |
|
) |
|
] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return splits |
|
|
|
def _generate_examples(self, filepath): |
|
|
|
"""This function returns the examples in the raw (text) form.""" |
|
with open(filepath, encoding="utf-8") as f: |
|
data = list(f) |
|
idx = 0 |
|
for line in data: |
|
row = json.loads(line) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
yield idx, row |
|
idx+=1 |
|
|