Update ccnews_split.py
Browse files- ccnews_split.py +11 -5
ccnews_split.py
CHANGED
@@ -24,12 +24,12 @@ from fnmatch import fnmatch
|
|
24 |
import datasets
|
25 |
|
26 |
|
27 |
-
def custom_iter_archive(path_or_buf):
|
28 |
def _iter_archive(f):
|
29 |
stream = tarfile.open(fileobj=f, mode="r|*")
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
file_path = tarinfo.name
|
34 |
if not tarinfo.isreg():
|
35 |
continue
|
@@ -118,9 +118,15 @@ class CCNews(datasets.GeneratorBasedBuilder):
|
|
118 |
|
119 |
def _split_generators(self, dl_manager):
|
120 |
archive = dl_manager.download(_DOWNLOAD_URL)
|
|
|
|
|
|
|
|
|
121 |
|
122 |
return [
|
123 |
-
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"files": custom_iter_archive(archive)}),
|
|
|
|
|
124 |
]
|
125 |
|
126 |
def _generate_examples(self, files):
|
|
|
24 |
import datasets
|
25 |
|
26 |
|
27 |
+
def custom_iter_archive(path_or_buf, _filter=lambda x: True):
|
28 |
def _iter_archive(f):
|
29 |
stream = tarfile.open(fileobj=f, mode="r|*")
|
30 |
+
for i, tarinfo in enumerate(stream):
|
31 |
+
if not _filter(i):
|
32 |
+
continue
|
33 |
file_path = tarinfo.name
|
34 |
if not tarinfo.isreg():
|
35 |
continue
|
|
|
118 |
|
119 |
def _split_generators(self, dl_manager):
|
120 |
archive = dl_manager.download(_DOWNLOAD_URL)
|
121 |
+
|
122 |
+
train_filter = lambda x : (x%10) < 8
|
123 |
+
val_filter = lambda x: (x%10) == 8
|
124 |
+
test_filter = lambda x: (x%10) == 9
|
125 |
|
126 |
return [
|
127 |
+
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"files": custom_iter_archive(archive, train_filter)}),
|
128 |
+
datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"files": custom_iter_archive(archive, val_filter)}),
|
129 |
+
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"files": custom_iter_archive(archive, test_filter)}),
|
130 |
]
|
131 |
|
132 |
def _generate_examples(self, files):
|