Datasets:

ArXiv:
Tags:
HAR
lynn-miller commited on
Commit
8e6652d
·
verified ·
1 Parent(s): 4f78754

Upload WISDM.py

Browse files
Files changed (1) hide show
  1. WISDM.py +181 -0
WISDM.py ADDED
@@ -0,0 +1,181 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ # TODO: Address all TODOs and remove all explanatory comments
15
+ """TODO: Add a description here."""
16
+
17
+
18
+ import numpy as np
19
+ #import json
20
+ import os
21
+
22
+ import datasets
23
+
24
+
25
+ # TODO: Add BibTeX citation
26
+ # Find for instance the citation on arxiv or on the dataset repo/website
27
+ _CITATION = """\
28
+ @InProceedings{huggingface:dataset,
29
+ title = {A great new dataset},
30
+ author={huggingface, Inc.
31
+ },
32
+ year={2020}
33
+ }
34
+ """
35
+
36
+ # TODO: Add description of the dataset here
37
+ # You can copy an official description
38
+ _DATASET = "WISDM"
39
+ _SHAPE = (3, 100)
40
+ _DESCRIPTION = """\
41
+ This new dataset is designed to solve this great NLP task and is crafted with a lot of care.
42
+ """
43
+
44
+ # TODO: Add a link to an official homepage for the dataset here
45
+ _HOMEPAGE = ""
46
+
47
+ # TODO: Add the licence for the dataset here if you can find it
48
+ _LICENSE = ""
49
+
50
+ # TODO: Add link to the official dataset URLs here
51
+ # The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
52
+ # This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
53
+ _URLS = {
54
+ 'data': f"{_DATASET}_X.npy",
55
+ 'labels': f"{_DATASET}_y.npy",
56
+ 'fold_0': "test_indices_fold_0.txt",
57
+ 'fold_1': "test_indices_fold_1.txt",
58
+ 'fold_2': "test_indices_fold_2.txt",
59
+ 'fold_3': "test_indices_fold_3.txt",
60
+ 'fold_4': "test_indices_fold_4.txt",
61
+ }
62
+
63
+
64
+ # TODO: Name of the dataset usually matches the script name with CamelCase instead of snake_case
65
+ class Monster(datasets.GeneratorBasedBuilder):
66
+ """TODO: Short description of my dataset."""
67
+
68
+ VERSION = datasets.Version("1.1.0")
69
+
70
+ # This is an example of a dataset with multiple configurations.
71
+ # If you don't want/need to define several sub-sets in your dataset,
72
+ # just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.
73
+
74
+ # If you need to make complex sub-parts in the datasets with configurable options
75
+ # You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
76
+ # BUILDER_CONFIG_CLASS = MyBuilderConfig
77
+
78
+ # You will be able to load one or the other configurations in the following list with
79
+ # data = datasets.load_dataset('my_dataset', 'first_domain')
80
+ # data = datasets.load_dataset('my_dataset', 'second_domain')
81
+ BUILDER_CONFIGS = [
82
+ datasets.BuilderConfig(name="full", version=VERSION, description="All data"),
83
+ datasets.BuilderConfig(name="fold_0", version=VERSION, description="Cross-validation fold 0"),
84
+ datasets.BuilderConfig(name="fold_1", version=VERSION, description="Cross-validation fold 1"),
85
+ datasets.BuilderConfig(name="fold_2", version=VERSION, description="Cross-validation fold 2"),
86
+ datasets.BuilderConfig(name="fold_3", version=VERSION, description="Cross-validation fold 3"),
87
+ datasets.BuilderConfig(name="fold_4", version=VERSION, description="Cross-validation fold 4"),
88
+ ]
89
+
90
+ DEFAULT_CONFIG_NAME = "full" # It's not mandatory to have a default configuration. Just use one if it make sense.
91
+
92
+ def _info(self):
93
+ # TODO: This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset
94
+ features = datasets.Features(
95
+ {
96
+ "X": datasets.Array2D(_SHAPE, "float32"),
97
+ "y": datasets.Value("int64")
98
+ # These are the features of your dataset like images, labels ...
99
+ }
100
+ )
101
+ return datasets.DatasetInfo(
102
+ # This is the description that will appear on the datasets page.
103
+ description=_DESCRIPTION,
104
+ # This defines the different columns of the dataset and their types
105
+ features=features, # Here we define them above because they are different between the two configurations
106
+ # If there's a common (input, target) tuple from the features, uncomment supervised_keys line below and
107
+ # specify them. They'll be used if as_supervised=True in builder.as_dataset.
108
+ supervised_keys=("X", "y"),
109
+ # Homepage of the dataset for documentation
110
+ homepage=_HOMEPAGE,
111
+ # License for the dataset if available
112
+ license=_LICENSE,
113
+ # Citation for the dataset
114
+ citation=_CITATION,
115
+ )
116
+
117
+ def _split_generators(self, dl_manager):
118
+ # TODO: This method is tasked with downloading/extracting the data and defining the splits depending on the configuration
119
+ # If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
120
+
121
+ # dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLS
122
+ # 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.
123
+ # By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
124
+ data = dl_manager.download_and_extract(_URLS['data'])
125
+ labels = dl_manager.download_and_extract(_URLS['labels'])
126
+ if self.config.name == "full":
127
+ return [
128
+ datasets.SplitGenerator(
129
+ name=datasets.Split.TRAIN,
130
+ # These kwargs will be passed to _generate_examples
131
+ gen_kwargs={
132
+ "data": data,
133
+ "labels": labels,
134
+ "fold": None,
135
+ "split": "all",
136
+ },
137
+ ),
138
+ ]
139
+ else:
140
+ fold = dl_manager.download_and_extract(_URLS[self.config.name])
141
+ return [
142
+ datasets.SplitGenerator(
143
+ name=datasets.Split.TRAIN,
144
+ # These kwargs will be passed to _generate_examples
145
+ gen_kwargs={
146
+ "data": data,
147
+ "labels": labels,
148
+ "fold": fold,
149
+ "split": "train",
150
+ },
151
+ ),
152
+ datasets.SplitGenerator(
153
+ name=datasets.Split.TEST,
154
+ # These kwargs will be passed to _generate_examples
155
+ gen_kwargs={
156
+ "data": data,
157
+ "labels": labels,
158
+ "fold": fold,
159
+ "split": "test"
160
+ },
161
+ ),
162
+ ]
163
+
164
+ # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
165
+ def _generate_examples(self, data, labels, fold, split):
166
+ # TODO: This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
167
+ # The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
168
+ X = np.load(data)
169
+ y = np.load(labels)
170
+ if self.config.name == "full":
171
+ for row in range(y.shape[0]):
172
+ yield(row, {"X": X[row], "y": y[row]})
173
+ else:
174
+ test_indices = np.loadtxt(fold, dtype='int')
175
+ if split == "test":
176
+ for row in test_indices:
177
+ yield(int(row), {"X": X[row], "y": y[row]})
178
+ elif split == "train":
179
+ train_indices = np.delete(np.arange(y.shape[0]), test_indices)
180
+ for row in train_indices:
181
+ yield(int(row), {"X": X[row], "y": y[row]})