system HF staff commited on
Commit
1b7f1de
1 Parent(s): 31610bf

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. mocha.py +30 -26
README.md CHANGED
@@ -1,4 +1,5 @@
1
  ---
 
2
  annotations_creators:
3
  - crowdsourced
4
  language_creators:
1
  ---
2
+ pretty_name: MOCHA
3
  annotations_creators:
4
  - crowdsourced
5
  language_creators:
mocha.py CHANGED
@@ -18,7 +18,6 @@
18
 
19
 
20
  import json
21
- import os
22
 
23
  import datasets
24
 
@@ -93,37 +92,42 @@ class Mocha(datasets.GeneratorBasedBuilder):
93
  )
94
 
95
  def _split_generators(self, dl_manager):
96
- dl_path = os.path.join(dl_manager.download_and_extract(_URL), "mocha")
97
 
98
  return [
99
  datasets.SplitGenerator(
100
  name=split,
101
- gen_kwargs={"filepath": os.path.join(dl_path, SPLIT_FILENAMES[split]), "split": split},
 
 
 
 
102
  )
103
  for split in SPLIT_FILENAMES
104
  ]
105
 
106
- def _generate_examples(self, filepath, split):
107
  """This function returns the examples in the raw (text) form."""
108
- logger.info("Generating examples from = %s", filepath)
109
- with open(filepath, encoding="utf-8") as f:
110
- mocha = json.load(f)
111
- for constituent_dataset, samples in mocha.items():
112
- for id_, sample in samples.items():
113
- sample["id"] = id_
114
- sample["constituent_dataset"] = constituent_dataset
115
-
116
- # Add default values
117
- if split == _MINIMAL_PAIRS_SPLIT:
118
- sample["candidate"] = sample["candidate1"]
119
- sample["score"] = sample["score1"]
120
- del sample["candidate1"], sample["score1"]
121
- sample["metadata"] = {"scores": [], "source": ""}
122
- else:
123
- if "score" not in sample:
124
- sample["score"] = -1.0
125
- sample["metadata"]["scores"] = []
126
- sample["candidate2"] = ""
127
- sample["score2"] = -1.0
128
-
129
- yield id_, sample
 
18
 
19
 
20
  import json
 
21
 
22
  import datasets
23
 
92
  )
93
 
94
  def _split_generators(self, dl_manager):
95
+ archive = dl_manager.download(_URL)
96
 
97
  return [
98
  datasets.SplitGenerator(
99
  name=split,
100
+ gen_kwargs={
101
+ "filepath": "mocha/" + SPLIT_FILENAMES[split],
102
+ "split": split,
103
+ "files": dl_manager.iter_archive(archive),
104
+ },
105
  )
106
  for split in SPLIT_FILENAMES
107
  ]
108
 
109
+ def _generate_examples(self, filepath, split, files):
110
  """This function returns the examples in the raw (text) form."""
111
+ for path, f in files:
112
+ if path == filepath:
113
+ mocha = json.load(f)
114
+ for constituent_dataset, samples in mocha.items():
115
+ for id_, sample in samples.items():
116
+ sample["id"] = id_
117
+ sample["constituent_dataset"] = constituent_dataset
118
+
119
+ # Add default values
120
+ if split == _MINIMAL_PAIRS_SPLIT:
121
+ sample["candidate"] = sample["candidate1"]
122
+ sample["score"] = sample["score1"]
123
+ del sample["candidate1"], sample["score1"]
124
+ sample["metadata"] = {"scores": [], "source": ""}
125
+ else:
126
+ if "score" not in sample:
127
+ sample["score"] = -1.0
128
+ sample["metadata"]["scores"] = []
129
+ sample["candidate2"] = ""
130
+ sample["score2"] = -1.0
131
+
132
+ yield id_, sample
133
+ break