lynn-miller commited on
Commit
4500aa4
·
verified ·
1 Parent(s): bf9c692

Upload WISDM.py

Browse files
Files changed (1) hide show
  1. WISDM.py +40 -25
WISDM.py CHANGED
@@ -36,6 +36,7 @@ year={2020}
36
  # TODO: Add description of the dataset here
37
  # You can copy an official description
38
  _DATASET = "WISDM"
 
39
  _DESCRIPTION = """\
40
  This new dataset is designed to solve this great NLP task and is crafted with a lot of care.
41
  """
@@ -50,6 +51,15 @@ _LICENSE = ""
50
  # The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
51
  # This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
52
  _URL = [f"https://huggingface.co/datasets/lynn-miller/{_DATASET}"]
 
 
 
 
 
 
 
 
 
53
 
54
 
55
  # TODO: Name of the dataset usually matches the script name with CamelCase instead of snake_case
@@ -82,19 +92,19 @@ class Monster(datasets.GeneratorBasedBuilder):
82
 
83
  def _info(self):
84
  # TODO: This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset
85
- data_dir = f"G:\My Drive\Postdoc\Other papers\Time Series Archive\{_DATASET}"
86
- data_dir = _URL[0]
87
- metadata_file = os.path.join(data_dir, "metadata", f"{_DATASET}_metadata.txt")
88
- try:
89
- metadata = np.loadtxt(metadata_file, delimiter=',', dtype=str)
90
- shape = (int(metadata[1,1]), int(metadata[2,1]))
91
- print(shape)
92
- except:
93
- print("Error reading metadata")
94
- shape = (3, 100)
95
  features = datasets.Features(
96
  {
97
- "X": datasets.Array2D(shape, "float32"),
98
  "y": datasets.Value("int64")
99
  # These are the features of your dataset like images, labels ...
100
  }
@@ -124,27 +134,31 @@ class Monster(datasets.GeneratorBasedBuilder):
124
  # By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
125
  # urls = _URLS[self.config.name]
126
  # data_dir = f"G:\My Drive\Postdoc\Other papers\Time Series Archive\{_DATASET}"
127
- data_dir = dl_manager.download_and_extract(_URL[0])
 
128
  if self.config.name == "full":
129
  return [
130
  datasets.SplitGenerator(
131
  name=datasets.Split.TRAIN,
132
  # These kwargs will be passed to _generate_examples
133
  gen_kwargs={
134
- "filepath": data_dir,
135
- "fold": self.config.name,
 
136
  "split": "train",
137
  },
138
  ),
139
  ]
140
- else:
 
141
  return [
142
  datasets.SplitGenerator(
143
  name=datasets.Split.TRAIN,
144
  # These kwargs will be passed to _generate_examples
145
  gen_kwargs={
146
- "filepath": data_dir,
147
- "fold": self.config.name,
 
148
  "split": "train",
149
  },
150
  ),
@@ -152,7 +166,8 @@ class Monster(datasets.GeneratorBasedBuilder):
152
  name=datasets.Split.TEST,
153
  # These kwargs will be passed to _generate_examples
154
  gen_kwargs={
155
- "filepath": data_dir,
 
156
  "fold": self.config.name,
157
  "split": "test"
158
  },
@@ -160,19 +175,19 @@ class Monster(datasets.GeneratorBasedBuilder):
160
  ]
161
 
162
  # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
163
- def _generate_examples(self, filepath, fold, split):
164
  # TODO: This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
165
  # The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
166
- X_file = f'{_DATASET}_X.npy' #os.path.join(filepath, f'{_DATASET}_X.npy')
167
- y_file = f'{_DATASET}_y.npy' #os.path.join(filepath, f'{_DATASET}_y.npy')
168
- X = np.load(X_file) #, 'r')
169
- y = np.load(y_file) #, 'r')
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
- indices_file = os.path.join(filepath, f"test_indices_{fold}.txt")
175
- test_indices = np.loadtxt(indices_file, dtype='int')
176
  if split == "test":
177
  for row in test_indices:
178
  yield(int(row), {"X": X[row], "y": y[row]})
 
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
  """
 
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
  _URL = [f"https://huggingface.co/datasets/lynn-miller/{_DATASET}"]
54
+ _URLS = {
55
+ 'data': f"{_DATASET}_X.npy",
56
+ 'labels': f"{_DATASET}_y.npy",
57
+ 'fold_0': "test_indices_fold_0.txt",
58
+ 'fold_1': "test_indices_fold_1.txt",
59
+ 'fold_2': "test_indices_fold_2.txt",
60
+ 'fold_3': "test_indices_fold_3.txt",
61
+ 'fold_4': "test_indices_fold_4.txt",
62
+ }
63
 
64
 
65
  # TODO: Name of the dataset usually matches the script name with CamelCase instead of snake_case
 
92
 
93
  def _info(self):
94
  # TODO: This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset
95
+ # data_dir = f"G:\My Drive\Postdoc\Other papers\Time Series Archive\{_DATASET}"
96
+ # data_dir = _URL[0]
97
+ # metadata_file = os.path.join(data_dir, "metadata", f"{_DATASET}_metadata.txt")
98
+ # try:
99
+ # metadata = np.loadtxt(metadata_file, delimiter=',', dtype=str)
100
+ # shape = (int(metadata[1,1]), int(metadata[2,1]))
101
+ # print(shape)
102
+ # except:
103
+ # print("Error reading metadata")
104
+ # shape = (3, 100)
105
  features = datasets.Features(
106
  {
107
+ "X": datasets.Array2D(_SHAPE, "float32"),
108
  "y": datasets.Value("int64")
109
  # These are the features of your dataset like images, labels ...
110
  }
 
134
  # By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
135
  # urls = _URLS[self.config.name]
136
  # data_dir = f"G:\My Drive\Postdoc\Other papers\Time Series Archive\{_DATASET}"
137
+ data = dl_manager.download_and_extract(_URLS['data'])
138
+ labels = dl_manager.download_and_extract(_URLS['labels'])
139
  if self.config.name == "full":
140
  return [
141
  datasets.SplitGenerator(
142
  name=datasets.Split.TRAIN,
143
  # These kwargs will be passed to _generate_examples
144
  gen_kwargs={
145
+ "data": data,
146
+ "labels": labels,
147
+ "fold": None,
148
  "split": "train",
149
  },
150
  ),
151
  ]
152
+ else:
153
+ fold = dl_manager.download_and_extract(_URLS[self.config.name])
154
  return [
155
  datasets.SplitGenerator(
156
  name=datasets.Split.TRAIN,
157
  # These kwargs will be passed to _generate_examples
158
  gen_kwargs={
159
+ "data": data,
160
+ "labels": labels,
161
+ "fold": fold,
162
  "split": "train",
163
  },
164
  ),
 
166
  name=datasets.Split.TEST,
167
  # These kwargs will be passed to _generate_examples
168
  gen_kwargs={
169
+ "data": data,
170
+ "labels": labels,
171
  "fold": self.config.name,
172
  "split": "test"
173
  },
 
175
  ]
176
 
177
  # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
178
+ def _generate_examples(self, data, labels, fold, split):
179
  # TODO: This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
180
  # The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
181
+ # X_file = f'{_DATASET}_X.npy' #os.path.join(filepath, f'{_DATASET}_X.npy')
182
+ # y_file = f'{_DATASET}_y.npy' #os.path.join(filepath, f'{_DATASET}_y.npy')
183
+ X = np.load(data) #, 'r')
184
+ y = np.load(labels) #, 'r')
185
  if self.config.name == "full":
186
  for row in range(y.shape[0]):
187
  yield(row, {"X": X[row], "y": y[row]})
188
  else:
189
+ # indices_file = os.path.join(filepath, f"test_indices_{fold}.txt")
190
+ test_indices = np.loadtxt(fold, dtype='int')
191
  if split == "test":
192
  for row in test_indices:
193
  yield(int(row), {"X": X[row], "y": y[row]})