albertvillanova HF staff commited on
Commit
b13bb71
1 Parent(s): d376211

Support streaming (#2)

Browse files

- Support streaming (53ddc13ca7abebfaabe68697786e1ab6b978666e)

Files changed (1) hide show
  1. multi_eurlex.py +29 -30
multi_eurlex.py CHANGED
@@ -16,10 +16,17 @@
16
 
17
 
18
  import json
19
- import os
20
 
21
  import datasets
22
 
 
 
 
 
 
 
 
 
23
 
24
  _CITATION = """\
25
  @InProceedings{chalkidis-etal-2021-multieurlex,
@@ -35,13 +42,6 @@ _CITATION = """\
35
  location = {Punta Cana, Dominican Republic},
36
  }"""
37
 
38
- _DESCRIPTION = """\
39
- MultiEURLEX comprises 65k EU laws in 23 official EU languages (some low-ish resource).
40
- Each EU law has been annotated with EUROVOC concepts (labels) by the Publication Office of EU.
41
- As with the English EURLEX, the goal is to predict the relevant EUROVOC concepts (labels);
42
- this is multi-label classification task (given the text, predict multiple labels).
43
- """
44
-
45
  DATA_URL = "https://zenodo.org/record/5363165/files/multi_eurlex.tar.gz"
46
 
47
  _LANGUAGES = [
@@ -8255,49 +8255,48 @@ class MultiEURLEX(datasets.GeneratorBasedBuilder):
8255
  description=_DESCRIPTION,
8256
  features=features,
8257
  supervised_keys=None,
8258
- homepage="https://github.io/iliaschalkidis",
8259
  citation=_CITATION,
8260
  )
8261
 
8262
  def _split_generators(self, dl_manager):
8263
- data_dir = dl_manager.download_and_extract(DATA_URL)
8264
  return [
8265
  datasets.SplitGenerator(
8266
  name=datasets.Split.TRAIN,
8267
  # These kwargs will be passed to _generate_examples
8268
- gen_kwargs={"filepath": os.path.join(data_dir, "train.jsonl"), "split": "train"},
8269
  ),
8270
  datasets.SplitGenerator(
8271
  name=datasets.Split.TEST,
8272
  # These kwargs will be passed to _generate_examples
8273
- gen_kwargs={"filepath": os.path.join(data_dir, "test.jsonl"), "split": "test"},
8274
  ),
8275
  datasets.SplitGenerator(
8276
  name=datasets.Split.VALIDATION,
8277
  # These kwargs will be passed to _generate_examples
8278
- gen_kwargs={"filepath": os.path.join(data_dir, "dev.jsonl"), "split": "dev"},
8279
  ),
8280
  ]
8281
 
8282
- def _generate_examples(self, filepath, split):
8283
  """This function returns the examples in the raw (text) form."""
8284
-
8285
- if self.config.language == "all_languages":
8286
- with open(filepath, encoding="utf-8") as f:
8287
- for id_, row in enumerate(f):
8288
- data = json.loads(row)
8289
- yield id_, {
8290
- "celex_id": data["celex_id"],
8291
- "text": {lang: data["text"][lang] for lang in self.config.languages},
8292
- "labels": data["eurovoc_concepts"][self.config.label_level],
8293
- }
8294
- else:
8295
- with open(filepath, encoding="utf-8") as f:
8296
- for id_, row in enumerate(f):
8297
- data = json.loads(row)
8298
- if data["text"][self.config.language] is not None:
8299
  yield id_, {
8300
  "celex_id": data["celex_id"],
8301
- "text": data["text"][self.config.language],
8302
  "labels": data["eurovoc_concepts"][self.config.label_level],
8303
  }
 
 
 
 
 
 
 
 
 
 
16
 
17
 
18
  import json
 
19
 
20
  import datasets
21
 
22
+ _HOMEPAGE = "https://github.io/iliaschalkidis"
23
+
24
+ _DESCRIPTION = """\
25
+ MultiEURLEX comprises 65k EU laws in 23 official EU languages (some low-ish resource).
26
+ Each EU law has been annotated with EUROVOC concepts (labels) by the Publication Office of EU.
27
+ As with the English EURLEX, the goal is to predict the relevant EUROVOC concepts (labels);
28
+ this is multi-label classification task (given the text, predict multiple labels).
29
+ """
30
 
31
  _CITATION = """\
32
  @InProceedings{chalkidis-etal-2021-multieurlex,
 
42
  location = {Punta Cana, Dominican Republic},
43
  }"""
44
 
 
 
 
 
 
 
 
45
  DATA_URL = "https://zenodo.org/record/5363165/files/multi_eurlex.tar.gz"
46
 
47
  _LANGUAGES = [
 
8255
  description=_DESCRIPTION,
8256
  features=features,
8257
  supervised_keys=None,
8258
+ homepage=_HOMEPAGE,
8259
  citation=_CITATION,
8260
  )
8261
 
8262
  def _split_generators(self, dl_manager):
8263
+ data_dir = dl_manager.download(DATA_URL)
8264
  return [
8265
  datasets.SplitGenerator(
8266
  name=datasets.Split.TRAIN,
8267
  # These kwargs will be passed to _generate_examples
8268
+ gen_kwargs={"archive": dl_manager.iter_archive(data_dir), "filepath": "train.jsonl"},
8269
  ),
8270
  datasets.SplitGenerator(
8271
  name=datasets.Split.TEST,
8272
  # These kwargs will be passed to _generate_examples
8273
+ gen_kwargs={"archive": dl_manager.iter_archive(data_dir), "filepath": "test.jsonl"},
8274
  ),
8275
  datasets.SplitGenerator(
8276
  name=datasets.Split.VALIDATION,
8277
  # These kwargs will be passed to _generate_examples
8278
+ gen_kwargs={"archive": dl_manager.iter_archive(data_dir), "filepath": "dev.jsonl"},
8279
  ),
8280
  ]
8281
 
8282
+ def _generate_examples(self, archive, filepath):
8283
  """This function returns the examples in the raw (text) form."""
8284
+ for path, f in archive:
8285
+ if path == filepath:
8286
+ if self.config.language == "all_languages":
8287
+ for id_, row in enumerate(f):
8288
+ data = json.loads(row)
 
 
 
 
 
 
 
 
 
 
8289
  yield id_, {
8290
  "celex_id": data["celex_id"],
8291
+ "text": {lang: data["text"][lang] for lang in self.config.languages},
8292
  "labels": data["eurovoc_concepts"][self.config.label_level],
8293
  }
8294
+ else:
8295
+ for id_, row in enumerate(f):
8296
+ data = json.loads(row)
8297
+ if data["text"][self.config.language] is not None:
8298
+ yield id_, {
8299
+ "celex_id": data["celex_id"],
8300
+ "text": data["text"][self.config.language],
8301
+ "labels": data["eurovoc_concepts"][self.config.label_level],
8302
+ }