File size: 8,027 Bytes
3b8b8ff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
819c229
 
3b8b8ff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15d82f4
3b8b8ff
 
 
 
 
 
 
 
 
 
 
 
 
 
93140de
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3b8b8ff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4582ca3
3b8b8ff
b638970
3b8b8ff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0dab569
3b8b8ff
 
819c229
 
 
 
 
 
 
 
 
 
 
 
3b8b8ff
 
 
 
42fc434
3b8b8ff
 
 
 
 
 
93140de
819c229
 
 
 
 
 
3b8b8ff
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
# coding=utf-8
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""HumSetBias"""

import json
import datasets


_CITATION = """"""
#@misc{https://doi.org/10.48550/arxiv.2210.04573,
#  doi = {10.48550/ARXIV.2210.04573},
#  url = {https://arxiv.org/abs/2210.04573},
#  author = {Fekih, Selim and Tamagnone, Nicolò and Minixhofer, Benjamin and Shrestha, Ranjan and Contla, Ximena and Oglethorpe, Ewan and Rekabsaz, Navid},
#  keywords = {Computation and Language (cs.CL), Machine Learning (cs.LG), FOS: Computer and information sciences, FOS: Computer and information sciences},
#  title = {HumSet: Dataset of Multilingual Information Extraction and Classification for Humanitarian Crisis Response},
#  publisher = {arXiv},
#  year = {2022},
#  copyright = {arXiv.org perpetual, non-exclusive license}
#}
#"""


_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",
        #"gender": "data/test_gender.jsonl",
        #"country": "data/test_country.jsonl"
    }
}


_SUPPORTED_VERSIONS = [
    # First version
    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(
                # This is the description that will appear on the datasets page.
                description=_DESCRIPTION_BIAS,
                # This defines the different columns of the dataset and their types
                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"]
                },
            ),
            #datasets.SplitGenerator(
            #    name="test_gender",
            #    gen_kwargs={
            #        "filepath": downloaded_files["gender"]
            #    },
            #),
            #datasets.SplitGenerator(
            #    name="test_country",
            #    gen_kwargs={
            #        "filepath": downloaded_files["country"]
            #    }
            #),
        ]

        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)
                #if "train" in filepath:
                #    row = {k: v for k, v in row.items() if k in HUMSETBIAS_GENERAL}
                #elif "gender" in filepath:
                #    row = {k: v for k, v in row.items() if k in HUMSETBIAS_FEATURES_GENDER}
                #elif "country" in filepath:
                #    row = {k: v for k, v in row.items() if k in HUMSETBIAS_FEATURES_COUNTRY}
                #if self.config.name == "1.0.0":
                yield idx, row
                idx+=1