nlp-thedeep commited on
Commit
3b8b8ff
·
1 Parent(s): df5513a

Create humsetbias.py

Browse files
Files changed (1) hide show
  1. humsetbias.py +171 -0
humsetbias.py ADDED
@@ -0,0 +1,171 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ """HumSetBias"""
17
+
18
+ import json
19
+ import datasets
20
+
21
+
22
+ _CITATION = """"""
23
+ #@misc{https://doi.org/10.48550/arxiv.2210.04573,
24
+ # doi = {10.48550/ARXIV.2210.04573},
25
+ # url = {https://arxiv.org/abs/2210.04573},
26
+ # author = {Fekih, Selim and Tamagnone, Nicolò and Minixhofer, Benjamin and Shrestha, Ranjan and Contla, Ximena and Oglethorpe, Ewan and Rekabsaz, Navid},
27
+ # keywords = {Computation and Language (cs.CL), Machine Learning (cs.LG), FOS: Computer and information sciences, FOS: Computer and information sciences},
28
+ # title = {HumSet: Dataset of Multilingual Information Extraction and Classification for Humanitarian Crisis Response},
29
+ # publisher = {arXiv},
30
+ # year = {2022},
31
+ # copyright = {arXiv.org perpetual, non-exclusive license}
32
+ #}
33
+ #"""
34
+
35
+
36
+ _DESCRIPTION_BIAS = """\
37
+ 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
38
+ 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.
39
+ """
40
+
41
+ _HOMEPAGE = "https://huggingface.co/datasets/nlp-thedeep/humsetbias"
42
+
43
+ _LICENSE = "The GitHub repository which houses this dataset has an Apache License 2.0."
44
+
45
+
46
+ _URLs = {
47
+ "1.0.0": {
48
+ "train": "data/humset_bias_train.jsonl",
49
+ "dev": "data/humset_bias_val.jsonl",
50
+ "gender": "data/test_gender.jsonl",
51
+ "country": "data/test_country.jsonl"
52
+ }
53
+ }
54
+
55
+
56
+ _SUPPORTED_VERSIONS = [
57
+ # First version
58
+ datasets.Version("1.0.0", "Gender and Country bias extension of HumSet")
59
+ ]
60
+
61
+
62
+ """
63
+ from: https://huggingface.co/docs/datasets/v2.9.0/en/package_reference/main_classes#datasets.Sequence
64
+ a python list or a Sequence specifies that the field contains a list of objects.
65
+ The python list or Sequence should be provided with a single sub-feature as an example of the feature type hosted in this list.
66
+ """
67
+
68
+
69
+ HUMSETBIAS_FEATURES = datasets.Features(
70
+ {
71
+ "entry_id": datasets.Value("string"),
72
+ "excerpt": datasets.Value("string"),
73
+ "lang": datasets.Value("string"),
74
+ "keywords": datasets.Sequence(datasets.Value("string"), length=-1),
75
+ "gender_keywords": datasets.Sequence(datasets.Value("string"), length=-1),
76
+ "country_keywords": datasets.Sequence(datasets.Value("string"), length=-1),
77
+ "gender_kword_type": datasets.Sequence(datasets.Value("string"), length=-1),
78
+ "country_kword_type": datasets.Sequence(datasets.Value("string"), length=-1),
79
+ "gender_context_falsing_kw": datasets.Sequence(datasets.Value("string"), length=-1),
80
+ "country_context_falsing_kw": datasets.Sequence(datasets.Value("string"), length=-1),
81
+ "excerpt_type": datasets.Value("string"),
82
+ "sectors": datasets.Sequence(datasets.Value("string"), length=-1),
83
+ "pillars_1d": datasets.Sequence(datasets.Value("string"), length=-1),
84
+ "pillars_2d": datasets.Sequence(datasets.Value("string"), length=-1),
85
+ "subpillars_1d": datasets.Sequence(datasets.Value("string"), length=-1),
86
+ "subpillars_2d": datasets.Sequence(datasets.Value("string"), length=-1),
87
+ }
88
+ )
89
+ class HumsetConfig(datasets.BuilderConfig):
90
+ """BuilderConfig for HumsetBias."""
91
+
92
+ def __init__(self, **kwargs):
93
+ """BuilderConfig for HumsetBias SelfRC.
94
+ Args:
95
+ **kwargs: keyword arguments forwarded to super.
96
+ """
97
+ super(HumsetConfig, self).__init__(**kwargs)
98
+
99
+
100
+ class Humset(datasets.GeneratorBasedBuilder):
101
+
102
+ BUILDER_CONFIGS = [
103
+ HumsetConfig(
104
+ name=str(version),
105
+ description=f"version {str(version)}",
106
+ version=version
107
+ )
108
+ for version in _SUPPORTED_VERSIONS
109
+ ]
110
+
111
+ DEFAULT_CONFIG_NAME = "1.0.0"
112
+
113
+ def _info(self):
114
+
115
+ if self.config.name == "1.0.0":
116
+ return datasets.DatasetInfo(
117
+ # This is the description that will appear on the datasets page.
118
+ description=_DESCRIPTION,
119
+ # This defines the different columns of the dataset and their types
120
+ features=FIRST_FEATURES,
121
+ homepage=_HOMEPAGE,
122
+ license=_LICENSE,
123
+ citation=_CITATION,
124
+ )
125
+
126
+ def _split_generators(self, dl_manager):
127
+
128
+ """Returns SplitGenerators."""
129
+
130
+ my_urls = _URLs[self.config.name]
131
+ downloaded_files = dl_manager.download_and_extract(my_urls)
132
+ splits = [
133
+ datasets.SplitGenerator(
134
+ name=datasets.Split.TRAIN,
135
+ gen_kwargs={
136
+ "filepath": downloaded_files["train"],
137
+ },
138
+ ),
139
+ datasets.SplitGenerator(
140
+ name=datasets.Split.VALIDATION,
141
+ gen_kwargs={
142
+ "filepath": downloaded_files["dev"],
143
+ },
144
+ ),
145
+ datasets.SplitGenerator(
146
+ name=datasets.Split.TEST,
147
+ gen_kwargs={
148
+ "filepath": downloaded_files["gender"],
149
+ },
150
+ ),
151
+ datasets.SplitGenerator(
152
+ name=datasets.Split.TEST,
153
+ gen_kwargs={
154
+ "filepath": downloaded_files["country"],
155
+ },
156
+ ),
157
+ ]
158
+
159
+ return splits
160
+
161
+ def _generate_examples(self, filepath):
162
+
163
+ """This function returns the examples in the raw (text) form."""
164
+ with open(filepath, encoding="utf-8") as f:
165
+ data = list(f)
166
+ idx = 0
167
+ for line in data:
168
+ row = json.loads(line)
169
+ #if self.config.name == "1.0.0":
170
+ yield idx, row
171
+ idx+=1