nlp-thedeep commited on
Commit
93140de
·
1 Parent(s): fa3a61d

Update humsetbias.py

Browse files
Files changed (1) hide show
  1. humsetbias.py +63 -5
humsetbias.py CHANGED
@@ -87,6 +87,58 @@ HUMSETBIAS_FEATURES = datasets.Features(
87
  "subpillars_2d": datasets.Sequence(datasets.Value("string"), length=-1),
88
  }
89
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90
  class HumsetConfig(datasets.BuilderConfig):
91
  """BuilderConfig for HumsetBias."""
92
 
@@ -140,33 +192,39 @@ class Humset(datasets.GeneratorBasedBuilder):
140
  datasets.SplitGenerator(
141
  name=datasets.Split.VALIDATION,
142
  gen_kwargs={
143
- "filepath": downloaded_files["dev"],
144
  },
145
  ),
146
  datasets.SplitGenerator(
147
  name="test_gender",
148
  gen_kwargs={
149
- "filepath": downloaded_files["gender"],
150
  },
151
  ),
152
  datasets.SplitGenerator(
153
  name="test_country",
154
  gen_kwargs={
155
- "filepath": downloaded_files["country"], "features": datasets.Features({"entry_id": datasets.Value("string")})
156
  }
157
  ),
158
  ]
159
 
160
  return splits
161
 
162
- def _generate_examples(self, filepath):
163
 
164
  """This function returns the examples in the raw (text) form."""
165
  with open(filepath, encoding="utf-8") as f:
166
  data = list(f)
167
  idx = 0
168
  for line in data:
169
- row = json.loads(line)
 
 
 
 
 
 
170
  #if self.config.name == "1.0.0":
171
  yield idx, row
172
  idx+=1
 
87
  "subpillars_2d": datasets.Sequence(datasets.Value("string"), length=-1),
88
  }
89
  )
90
+
91
+ HUMSETBIAS_GENERAL = [
92
+ 'entry_id',
93
+ 'excerpt',
94
+ "lang",
95
+ 'excerpt_type',
96
+ "gender_keywords",
97
+ "country_keywords",
98
+ "gender_kword_type",
99
+ "country_kword_type",
100
+ 'gender_context_falsing_kw',
101
+ "country_context_falsing_kw",
102
+ "sectors",
103
+ "pillars_1d",
104
+ "pillars_2d",
105
+ "subpillars_1d",
106
+ "subpillars_2d"
107
+ ]
108
+
109
+ HUMSETBIAS_FEATURES_GENDER = [
110
+ 'entry_id',
111
+ 'excerpt',
112
+ "lang",
113
+ 'keywords',
114
+ 'kword_type',
115
+ 'excerpt_type',
116
+ 'gender_context_falsing_kw',
117
+ "sectors",
118
+ "pillars_1d",
119
+ "pillars_2d",
120
+ "subpillars_1d",
121
+ "subpillars_2d"
122
+ ]
123
+
124
+ HUMSETBIAS_FEATURES_COUNTRY = [
125
+ 'entry_id',
126
+ 'excerpt',
127
+ "lang",
128
+ 'keywords',
129
+ 'kword_type',
130
+ 'excerpt_type',
131
+ 'country_context_falsing_kw',
132
+ "sectors",
133
+ "pillars_1d",
134
+ "pillars_2d",
135
+ "subpillars_1d",
136
+ "subpillars_2d"
137
+ ]
138
+ ]
139
+
140
+
141
+
142
  class HumsetConfig(datasets.BuilderConfig):
143
  """BuilderConfig for HumsetBias."""
144
 
 
192
  datasets.SplitGenerator(
193
  name=datasets.Split.VALIDATION,
194
  gen_kwargs={
195
+ "filepath": downloaded_files["dev"], "type": "normal"
196
  },
197
  ),
198
  datasets.SplitGenerator(
199
  name="test_gender",
200
  gen_kwargs={
201
+ "filepath": downloaded_files["gender"], "type": "gender"
202
  },
203
  ),
204
  datasets.SplitGenerator(
205
  name="test_country",
206
  gen_kwargs={
207
+ "filepath": downloaded_files["country"], "type": "country"
208
  }
209
  ),
210
  ]
211
 
212
  return splits
213
 
214
+ def _generate_examples(self, filepath, type):
215
 
216
  """This function returns the examples in the raw (text) form."""
217
  with open(filepath, encoding="utf-8") as f:
218
  data = list(f)
219
  idx = 0
220
  for line in data:
221
+ row = json.loads(line)
222
+ if type == "normal":
223
+ row = {k: v for k, v in row if k in HUMSETBIAS_GENERAL}
224
+ elif type == "gender":
225
+ row = {k: v for k, v in row if k in HUMSETBIAS_FEATURES_GENDER}
226
+ elif type == "country":
227
+ row = {k: v for k, v in row if k in HUMSETBIAS_FEATURES_COUNTRY}
228
  #if self.config.name == "1.0.0":
229
  yield idx, row
230
  idx+=1