File size: 1,139 Bytes
e503559
fa6d821
e43ac3d
e503559
 
fa6d821
 
 
 
 
 
 
e503559
 
e43ac3d
 
 
 
e503559
 
 
fa6d821
 
 
e503559
fa6d821
e503559
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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}