test_this out
Browse files- .gitignore +2 -1
- zenodo.py +100 -1
.gitignore
CHANGED
@@ -1 +1,2 @@
|
|
1 |
-
*.pyc
|
|
|
|
1 |
+
*.pyc
|
2 |
+
.venv/
|
zenodo.py
CHANGED
@@ -7,4 +7,103 @@ import os
|
|
7 |
|
8 |
import datasets
|
9 |
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
import datasets
|
9 |
|
10 |
+
_DESCRIPTION = """\
|
11 |
+
This dataset is for downloading a Zenodo dataset without extra packages.
|
12 |
+
"""
|
13 |
+
|
14 |
+
|
15 |
+
|
16 |
+
|
17 |
+
class NewDataset(datasets.GeneratorBasedBuilder):
|
18 |
+
"""This dataset downloads a zenodo dataset and returns its path."""
|
19 |
+
|
20 |
+
VERSION = datasets.Version("1.1.0")
|
21 |
+
|
22 |
+
# This is an example of a dataset with multiple configurations.
|
23 |
+
# If you don't want/need to define several sub-sets in your dataset,
|
24 |
+
# just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.
|
25 |
+
|
26 |
+
# If you need to make complex sub-parts in the datasets with configurable options
|
27 |
+
# You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
|
28 |
+
# BUILDER_CONFIG_CLASS = MyBuilderConfig
|
29 |
+
|
30 |
+
# You will be able to load one or the other configurations in the following list with
|
31 |
+
# data = datasets.load_dataset('my_dataset', 'first_domain')
|
32 |
+
# data = datasets.load_dataset('my_dataset', 'second_domain')
|
33 |
+
# BUILDER_CONFIGS = [
|
34 |
+
# datasets.BuilderConfig(name="first_domain", version=VERSION, description="This part of my dataset covers a first domain"),
|
35 |
+
# datasets.BuilderConfig(name="second_domain", version=VERSION, description="This part of my dataset covers a second domain"),
|
36 |
+
# ]
|
37 |
+
|
38 |
+
# DEFAULT_CONFIG_NAME = "first_domain" # It's not mandatory to have a default configuration. Just use one if it make sense.
|
39 |
+
|
40 |
+
def _info(self):
|
41 |
+
# TODO: This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset
|
42 |
+
# if self.config.name == "first_domain": # This is the name of the configuration selected in BUILDER_CONFIGS above
|
43 |
+
# features = datasets.Features(
|
44 |
+
# {
|
45 |
+
# "sentence": datasets.Value("string"),
|
46 |
+
# "option1": datasets.Value("string"),
|
47 |
+
# "answer": datasets.Value("string")
|
48 |
+
# # These are the features of your dataset like images, labels ...
|
49 |
+
# }
|
50 |
+
# )
|
51 |
+
# else: # This is an example to show how to have different features for "first_domain" and "second_domain"
|
52 |
+
# features = datasets.Features(
|
53 |
+
# {
|
54 |
+
# "sentence": datasets.Value("string"),
|
55 |
+
# "option2": datasets.Value("string"),
|
56 |
+
# "second_domain_answer": datasets.Value("string")
|
57 |
+
# # These are the features of your dataset like images, labels ...
|
58 |
+
# }
|
59 |
+
# )
|
60 |
+
|
61 |
+
features = datasets.Features(
|
62 |
+
{
|
63 |
+
"path": datasets.Value("string"),
|
64 |
+
}
|
65 |
+
)
|
66 |
+
|
67 |
+
return datasets.DatasetInfo(
|
68 |
+
# This is the description that will appear on the datasets page.
|
69 |
+
description=_DESCRIPTION,
|
70 |
+
# This defines the different columns of the dataset and their types
|
71 |
+
features=features, # Here we define them above because they are different between the two configurations
|
72 |
+
# If there's a common (input, target) tuple from the features, uncomment supervised_keys line below and
|
73 |
+
# specify them. They'll be used if as_supervised=True in builder.as_dataset.
|
74 |
+
# supervised_keys=("sentence", "label"),
|
75 |
+
# Homepage of the dataset for documentation
|
76 |
+
# homepage=_HOMEPAGE,
|
77 |
+
# License for the dataset if available
|
78 |
+
# license=_LICENSE,
|
79 |
+
# Citation for the dataset
|
80 |
+
# citation=_CITATION,
|
81 |
+
)
|
82 |
+
|
83 |
+
def _split_generators(self, dl_manager):
|
84 |
+
# TODO: This method is tasked with downloading/extracting the data and defining the splits depending on the configuration
|
85 |
+
# If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
|
86 |
+
|
87 |
+
# dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLS
|
88 |
+
# 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.
|
89 |
+
# By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
|
90 |
+
zenodo_id = self.config.name.split("/")[0]
|
91 |
+
filename = self.config.name.split("/")[1]
|
92 |
+
|
93 |
+
url = f"https://zenodo.org/record/{zenodo_id}/files/{filename}"
|
94 |
+
|
95 |
+
data_dir = dl_manager.download_and_extract([url])
|
96 |
+
return [
|
97 |
+
datasets.SplitGenerator(
|
98 |
+
name=datasets.Split.TRAIN,
|
99 |
+
data_dir=data_dir[0],
|
100 |
+
),
|
101 |
+
]
|
102 |
+
|
103 |
+
# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
|
104 |
+
def _generate_examples(self, data_dir):
|
105 |
+
# TODO: This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
|
106 |
+
# The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
|
107 |
+
|
108 |
+
yield "path", data_dir
|
109 |
+
|