Create dataset.py
Browse files- dataset.py +23 -0
dataset.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import pickle
|
| 3 |
+
import zipfile
|
| 4 |
+
from datasets import GeneratorBasedBuilder, DatasetInfo, SplitGenerator, Split
|
| 5 |
+
|
| 6 |
+
class MyDataset(GeneratorBasedBuilder):
|
| 7 |
+
def _info(self):
|
| 8 |
+
return DatasetInfo(
|
| 9 |
+
features=self.config.features
|
| 10 |
+
)
|
| 11 |
+
|
| 12 |
+
def _split_generators(self, dl_manager):
|
| 13 |
+
archive_path = dl_manager.download_and_extract(self.config.data_files["train"])
|
| 14 |
+
return [
|
| 15 |
+
SplitGenerator(name=Split.TRAIN, gen_kwargs={"archive_path": archive_path}),
|
| 16 |
+
]
|
| 17 |
+
|
| 18 |
+
def _generate_examples(self, archive_path):
|
| 19 |
+
with zipfile.ZipFile(archive_path, "r") as z:
|
| 20 |
+
for file_name in z.namelist():
|
| 21 |
+
with z.open(file_name) as f:
|
| 22 |
+
data = pickle.load(f)
|
| 23 |
+
yield file_name, {"file_name": file_name, "data": data}
|