Gaëtan Caillaut
commited on
Commit
·
a6fa8fb
1
Parent(s):
9acb001
fix dataset loading in streaming mode
Browse files- frwiki_el.py +4 -8
frwiki_el.py
CHANGED
@@ -176,9 +176,6 @@ class FrwikiElDataset(datasets.GeneratorBasedBuilder):
|
|
176 |
# TODO: This method is tasked with downloading/extracting the data and defining the splits depending on the configuration
|
177 |
# If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
|
178 |
|
179 |
-
# dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLs
|
180 |
-
# It can accept any type or nested list/dict and will give back the same structure with the url replaced with path to local files.
|
181 |
-
# By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
|
182 |
filepath = _URLs[self.config.name]
|
183 |
path = dl_manager.download(filepath)
|
184 |
return [
|
@@ -196,13 +193,12 @@ class FrwikiElDataset(datasets.GeneratorBasedBuilder):
|
|
196 |
# This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
|
197 |
# The `key` is here for legacy reason (tfds) and is not important in itself.
|
198 |
|
199 |
-
# entities_path = Path(data_dir, "entities.jsonl.gz")
|
200 |
-
# corpus_path = Path(data_dir, "corpus.jsonl.gz")
|
201 |
-
|
202 |
def _identiy(x):
|
203 |
return x
|
204 |
|
205 |
-
|
206 |
-
|
|
|
|
|
207 |
item = json.loads(line, parse_int=_identiy, parse_float=_identiy, parse_constant=_identiy)
|
208 |
yield id, item
|
|
|
176 |
# TODO: This method is tasked with downloading/extracting the data and defining the splits depending on the configuration
|
177 |
# If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
|
178 |
|
|
|
|
|
|
|
179 |
filepath = _URLs[self.config.name]
|
180 |
path = dl_manager.download(filepath)
|
181 |
return [
|
|
|
193 |
# This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
|
194 |
# The `key` is here for legacy reason (tfds) and is not important in itself.
|
195 |
|
|
|
|
|
|
|
196 |
def _identiy(x):
|
197 |
return x
|
198 |
|
199 |
+
# We need to use open before gzip.open in case the dataset is streamed
|
200 |
+
# https://github.com/huggingface/datasets/issues/2607#issuecomment-883219727
|
201 |
+
with gzip.open(open(path, 'rb'), "rt", encoding="UTF-8") as datafile:
|
202 |
+
for id, line in enumerate(datafile):
|
203 |
item = json.loads(line, parse_int=_identiy, parse_float=_identiy, parse_constant=_identiy)
|
204 |
yield id, item
|