sleeping4cat's picture
Update dataset.py
fa6d821 verified
raw
history blame
1.14 kB
import zipfile
import pickle
from datasets import GeneratorBasedBuilder, DatasetInfo, SplitGenerator, Split, Value
class MyDataset(GeneratorBasedBuilder):
"""Custom Dataset using a Zip Archive"""
_URL = "https://huggingface.co/datasets/sleeping-ai/arXiv-abstract-model2vec/resolve/main/"
_URLS = {
"train": _URL + "paper.zip",
}
def _info(self):
return DatasetInfo(
features={
"file_name": Value("string"),
"data": Value("binary"),
}
)
def _split_generators(self, dl_manager):
urls_to_download = self._URLS
downloaded_files = dl_manager.download_and_extract(urls_to_download)
return [
SplitGenerator(name=Split.TRAIN, gen_kwargs={"archive_path": downloaded_files["train"]}),
]
def _generate_examples(self, archive_path):
with zipfile.ZipFile(archive_path, "r") as z:
for file_name in z.namelist():
with z.open(file_name) as f:
data = pickle.load(f)
yield file_name, {"file_name": file_name, "data": data}