eduagarcia commited on
Commit
41b694a
1 Parent(s): 7fcc229

Add Assin2 STS task

Browse files
Files changed (1) hide show
  1. portuguese_benchmark.py +43 -11
portuguese_benchmark.py CHANGED
@@ -86,6 +86,11 @@ _ASSIN2_RTE_KWARGS = dict(
86
  label_classes=["NONE", "ENTAILMENT"],
87
  **_ASSIN2_BASE_KWARGS
88
  )
 
 
 
 
 
89
 
90
 
91
  class PTBenchmarkConfig(datasets.BuilderConfig):
@@ -138,7 +143,7 @@ def _get_ner_dataset_info(config):
138
  citation=config.citation,
139
  features=datasets.Features(
140
  {
141
- "id": datasets.Value("string"),
142
  "tokens": datasets.Sequence(datasets.Value("string")),
143
  "ner_tags": datasets.Sequence(
144
  datasets.features.ClassLabel(names=bio_labels)
@@ -154,7 +159,7 @@ def _get_rte_dataset_info(config):
154
  citation=config.citation,
155
  features=datasets.Features(
156
  {
157
- "id": datasets.Value("int32"),
158
  "sentence1": datasets.Value("string"),
159
  "sentence2": datasets.Value("string"),
160
  "label": datasets.features.ClassLabel(names=config.label_classes),
@@ -162,6 +167,21 @@ def _get_rte_dataset_info(config):
162
  )
163
  )
164
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
165
  def _conll_ner_generator(file_path):
166
  with open(file_path, encoding="utf-8") as f:
167
 
@@ -173,7 +193,7 @@ def _conll_ner_generator(file_path):
173
  if line == "" or line == "\n":
174
  if tokens:
175
  yield guid, {
176
- "id": str(guid),
177
  "tokens": tokens,
178
  "ner_tags": ner_tags,
179
  }
@@ -187,12 +207,12 @@ def _conll_ner_generator(file_path):
187
 
188
  # last example
189
  yield guid, {
190
- "id": str(guid),
191
  "tokens": tokens,
192
  "ner_tags": ner_tags,
193
  }
194
 
195
- def _assin2_rte_generator(file_path):
196
  """Yields examples."""
197
  id_ = 0
198
 
@@ -203,14 +223,17 @@ def _assin2_rte_generator(file_path):
203
 
204
  for pair in root:
205
 
206
- yield id_, {
207
- "id": int(pair.attrib.get("id")),
208
  "sentence1": pair.find(".//t").text,
209
- "sentence2": pair.find(".//h").text,
210
- #"relatedness_score": float(pair.attrib.get("similarity")),
211
- "label": pair.attrib.get("entailment").upper(),
212
  }
 
 
 
 
213
 
 
214
  id_ += 1
215
 
216
 
@@ -221,6 +244,9 @@ class PTBenchmark(datasets.GeneratorBasedBuilder):
221
  ),
222
  PTBenchmarkConfig(
223
  **_ASSIN2_RTE_KWARGS
 
 
 
224
  )
225
  ]
226
 
@@ -229,6 +255,8 @@ class PTBenchmark(datasets.GeneratorBasedBuilder):
229
  return _get_ner_dataset_info(self.config)
230
  elif self.config.task_type == "rte":
231
  return _get_rte_dataset_info(self.config)
 
 
232
 
233
  def _split_generators(self, dl_manager: datasets.DownloadManager):
234
  file_paths = dl_manager.download_and_extract(self.config.data_urls)
@@ -256,4 +284,8 @@ class PTBenchmark(datasets.GeneratorBasedBuilder):
256
  yield from _conll_ner_generator(file_path)
257
  elif self.config.task_type == "rte":
258
  if "assin2" in self.config.name:
259
- yield from _assin2_rte_generator(file_path)
 
 
 
 
 
86
  label_classes=["NONE", "ENTAILMENT"],
87
  **_ASSIN2_BASE_KWARGS
88
  )
89
+ _ASSIN2_STS_KWARGS = dict(
90
+ name = "assin2-sts",
91
+ task_type="sts",
92
+ **_ASSIN2_BASE_KWARGS
93
+ )
94
 
95
 
96
  class PTBenchmarkConfig(datasets.BuilderConfig):
 
143
  citation=config.citation,
144
  features=datasets.Features(
145
  {
146
+ "idx": datasets.Value("int32"),
147
  "tokens": datasets.Sequence(datasets.Value("string")),
148
  "ner_tags": datasets.Sequence(
149
  datasets.features.ClassLabel(names=bio_labels)
 
159
  citation=config.citation,
160
  features=datasets.Features(
161
  {
162
+ "idx": datasets.Value("int32"),
163
  "sentence1": datasets.Value("string"),
164
  "sentence2": datasets.Value("string"),
165
  "label": datasets.features.ClassLabel(names=config.label_classes),
 
167
  )
168
  )
169
 
170
+ def _get_sts_dataset_info(config):
171
+ return datasets.DatasetInfo(
172
+ description=config.description,
173
+ homepage=config.url,
174
+ citation=config.citation,
175
+ features=datasets.Features(
176
+ {
177
+ "idx": datasets.Value("int32"),
178
+ "sentence1": datasets.Value("string"),
179
+ "sentence2": datasets.Value("string"),
180
+ "label": datasets.Value("float32"),
181
+ }
182
+ )
183
+ )
184
+
185
  def _conll_ner_generator(file_path):
186
  with open(file_path, encoding="utf-8") as f:
187
 
 
193
  if line == "" or line == "\n":
194
  if tokens:
195
  yield guid, {
196
+ "idx": guid,
197
  "tokens": tokens,
198
  "ner_tags": ner_tags,
199
  }
 
207
 
208
  # last example
209
  yield guid, {
210
+ "idx": guid,
211
  "tokens": tokens,
212
  "ner_tags": ner_tags,
213
  }
214
 
215
+ def _assin2_generator(file_path, type):
216
  """Yields examples."""
217
  id_ = 0
218
 
 
223
 
224
  for pair in root:
225
 
226
+ example = {
227
+ "idx": int(pair.attrib.get("id")),
228
  "sentence1": pair.find(".//t").text,
229
+ "sentence2": pair.find(".//h").text
 
 
230
  }
231
+ if type == "rte":
232
+ example["label"] = pair.attrib.get("entailment").upper()
233
+ elif type == "sts":
234
+ example["label"] = float(pair.attrib.get("similarity"))
235
 
236
+ yield id_, example
237
  id_ += 1
238
 
239
 
 
244
  ),
245
  PTBenchmarkConfig(
246
  **_ASSIN2_RTE_KWARGS
247
+ ),
248
+ PTBenchmarkConfig(
249
+ **_ASSIN2_STS_KWARGS
250
  )
251
  ]
252
 
 
255
  return _get_ner_dataset_info(self.config)
256
  elif self.config.task_type == "rte":
257
  return _get_rte_dataset_info(self.config)
258
+ elif self.config.task_type == "sts":
259
+ return _get_sts_dataset_info(self.config)
260
 
261
  def _split_generators(self, dl_manager: datasets.DownloadManager):
262
  file_paths = dl_manager.download_and_extract(self.config.data_urls)
 
284
  yield from _conll_ner_generator(file_path)
285
  elif self.config.task_type == "rte":
286
  if "assin2" in self.config.name:
287
+ yield from _assin2_generator(file_path, "rte")
288
+ elif self.config.task_type == "sts":
289
+ if "assin2" in self.config.name:
290
+ yield from _assin2_generator(file_path, "sts")
291
+