system HF staff commited on
Commit
f315d37
1 Parent(s): bc7749a

Update files from the datasets library (from 1.16.0)

Browse files

Release notes: https://github.com/huggingface/datasets/releases/tag/1.16.0

Files changed (2) hide show
  1. README.md +1 -0
  2. exams.py +22 -26
README.md CHANGED
@@ -1,4 +1,5 @@
1
  ---
 
2
  annotations_creators:
3
  - found
4
  language_creators:
 
1
  ---
2
+ pretty_name: EXAMS
3
  annotations_creators:
4
  - found
5
  language_creators:
exams.py CHANGED
@@ -16,7 +16,6 @@
16
 
17
 
18
  import json
19
- import os
20
 
21
  import datasets
22
 
@@ -196,14 +195,12 @@ class Exams(datasets.GeneratorBasedBuilder):
196
 
197
  def _split_generators(self, dl_manager):
198
  """Returns SplitGenerators."""
199
- data_dir = dl_manager.download_and_extract(_URLs)
200
  if self.config.name == "alignments":
201
  return [
202
  datasets.SplitGenerator(
203
  name="full",
204
- gen_kwargs={
205
- "filepath": data_dir["alignments"],
206
- },
207
  ),
208
  ]
209
  elif self.config.name in ["multilingual", "multilingual_with_para"]:
@@ -211,9 +208,8 @@ class Exams(datasets.GeneratorBasedBuilder):
211
  datasets.SplitGenerator(
212
  name=spl_enum,
213
  gen_kwargs={
214
- "filepath": os.path.join(
215
- data_dir[f"{self.config.name}_{spl}"], f"{spl}{self.config.with_para}.jsonl"
216
- ),
217
  },
218
  )
219
  for spl, spl_enum in [
@@ -227,9 +223,8 @@ class Exams(datasets.GeneratorBasedBuilder):
227
  datasets.SplitGenerator(
228
  name=datasets.Split.TEST,
229
  gen_kwargs={
230
- "filepath": os.path.join(
231
- data_dir[f"{self.config.name}"], f"test{self.config.with_para}.jsonl"
232
- ),
233
  },
234
  ),
235
  ]
@@ -238,10 +233,8 @@ class Exams(datasets.GeneratorBasedBuilder):
238
  datasets.SplitGenerator(
239
  name=spl_enum,
240
  gen_kwargs={
241
- "filepath": os.path.join(
242
- data_dir[f"{self.config.name}_{spl}"],
243
- f"{spl}_{self.config.lang}{self.config.with_para}.jsonl",
244
- )
245
  },
246
  )
247
  for spl, spl_enum in [
@@ -250,16 +243,19 @@ class Exams(datasets.GeneratorBasedBuilder):
250
  ]
251
  ]
252
 
253
- def _generate_examples(self, filepath):
254
- f = open(filepath, encoding="utf-8")
255
  if self.config.name == "alignments":
256
- for id_, line in enumerate(f):
257
- line_dict = json.loads(line.strip())
258
- in_id, out_list = list(line_dict.items())[0]
259
- yield id_, {"source_id": in_id, "target_id_list": out_list}
 
260
  else:
261
- for id_, line in enumerate(f):
262
- line_dict = json.loads(line.strip())
263
- for choice in line_dict["question"]["choices"]:
264
- choice["para"] = choice.get("para", "")
265
- yield id_, line_dict
 
 
 
 
16
 
17
 
18
  import json
 
19
 
20
  import datasets
21
 
 
195
 
196
  def _split_generators(self, dl_manager):
197
  """Returns SplitGenerators."""
198
+ archives = dl_manager.download(_URLs)
199
  if self.config.name == "alignments":
200
  return [
201
  datasets.SplitGenerator(
202
  name="full",
203
+ gen_kwargs={"filepath": archives["alignments"]},
 
 
204
  ),
205
  ]
206
  elif self.config.name in ["multilingual", "multilingual_with_para"]:
 
208
  datasets.SplitGenerator(
209
  name=spl_enum,
210
  gen_kwargs={
211
+ "filepath": f"{spl}{self.config.with_para}.jsonl",
212
+ "files": dl_manager.iter_archive(archives[f"{self.config.name}_{spl}"]),
 
213
  },
214
  )
215
  for spl, spl_enum in [
 
223
  datasets.SplitGenerator(
224
  name=datasets.Split.TEST,
225
  gen_kwargs={
226
+ "filepath": f"test{self.config.with_para}.jsonl",
227
+ "files": dl_manager.iter_archive(archives[self.config.name]),
 
228
  },
229
  ),
230
  ]
 
233
  datasets.SplitGenerator(
234
  name=spl_enum,
235
  gen_kwargs={
236
+ "filepath": f"{spl}_{self.config.lang}{self.config.with_para}.jsonl",
237
+ "files": dl_manager.iter_archive(archives[f"{self.config.name}_{spl}"]),
 
 
238
  },
239
  )
240
  for spl, spl_enum in [
 
243
  ]
244
  ]
245
 
246
+ def _generate_examples(self, filepath, files=None):
 
247
  if self.config.name == "alignments":
248
+ with open(filepath, encoding="utf-8") as f:
249
+ for id_, line in enumerate(f):
250
+ line_dict = json.loads(line.strip())
251
+ in_id, out_list = list(line_dict.items())[0]
252
+ yield id_, {"source_id": in_id, "target_id_list": out_list}
253
  else:
254
+ for path, f in files:
255
+ if path == filepath:
256
+ for id_, line in enumerate(f):
257
+ line_dict = json.loads(line.strip())
258
+ for choice in line_dict["question"]["choices"]:
259
+ choice["para"] = choice.get("para", "")
260
+ yield id_, line_dict
261
+ break