pianistprogrammer commited on
Commit
5772aad
·
verified ·
1 Parent(s): 3ed6f4e

Add files using upload-large-folder tool

Browse files
Files changed (3) hide show
  1. .gitattributes +1 -0
  2. data.tar.gz +3 -0
  3. meter2800.py +23 -70
.gitattributes ADDED
@@ -0,0 +1 @@
 
 
1
+ data.tar.gz filter=lfs diff=lfs merge=lfs -text
data.tar.gz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6c4509dc14e7bff0cb02a9ee09676371c0cdaa4030445e358b846e38e9cee30d
3
+ size 9299442890
meter2800.py CHANGED
@@ -1,18 +1,4 @@
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
- """The Meter2800 dataset."""
15
-
16
  from pathlib import Path
17
  import datasets
18
  import pandas as pd
@@ -29,59 +15,35 @@ _CITATION = """\
29
 
30
  _DESCRIPTION = """\
31
  Meter2800 is a dataset of 2,800 music audio samples for automatic meter classification.
32
- Each audio file is annotated with a primary meter class label (e.g., 'two', 'three', 'four')
33
- and an alternative meter (numerical, e.g., 2, 3, 4, 6).
34
  It is split into training, validation, and test sets, each available in two class configurations:
35
  2-class and 4-class. All audio is 16-bit WAV format.
36
  """
37
-
38
  _HOMEPAGE = "https://huggingface.co/datasets/pianistprogrammer/Meter2800"
39
  _LICENSE = "mit"
40
 
41
- # Define the labels - adjust these based on your actual data
42
  LABELS_4 = ["three", "four", "five", "seven"]
43
- LABELS_2 = ["simple", "complex"] # or whatever your 2-class grouping actually is
44
 
45
  class Meter2800Config(datasets.BuilderConfig):
46
- """BuilderConfig for Meter2800."""
47
  def __init__(self, name, **kwargs):
48
- super(Meter2800Config, self).__init__(
49
- name=name,
50
- version=datasets.Version("1.0.0"),
51
- **kwargs
52
- )
53
 
54
  class Meter2800(datasets.GeneratorBasedBuilder):
55
- """Meter2800 dataset."""
56
-
57
  BUILDER_CONFIGS = [
58
- Meter2800Config(
59
- name="4_classes",
60
- description="4-class meter classification"
61
- ),
62
- Meter2800Config(
63
- name="2_classes",
64
- description="2-class meter classification"
65
- ),
66
  ]
67
-
68
  DEFAULT_CONFIG_NAME = "4_classes"
69
 
70
  def _info(self):
71
- if self.config.name == "4_classes":
72
- label_names = LABELS_4
73
- elif self.config.name == "2_classes":
74
- label_names = LABELS_2
75
- else:
76
- # Fallback - shouldn't happen with proper configs
77
- label_names = LABELS_4
78
-
79
  return datasets.DatasetInfo(
80
  description=_DESCRIPTION,
81
  features=datasets.Features({
82
  "filename": datasets.Value("string"),
83
- "audio": datasets.Audio(sampling_rate=22_050),
84
- "label": datasets.ClassLabel(names=label_names),
85
  "meter": datasets.Value("string"),
86
  "alt_meter": datasets.Value("string"),
87
  }),
@@ -92,44 +54,35 @@ class Meter2800(datasets.GeneratorBasedBuilder):
92
  )
93
 
94
  def _split_generators(self, dl_manager):
95
- # Get the data directory
96
- data_dir = dl_manager.download_and_extract("")
97
-
 
 
 
 
98
  return [
99
  datasets.SplitGenerator(
100
  name=datasets.Split.TRAIN,
101
- gen_kwargs={
102
- "csv_file": f"{data_dir}/data_train_{self.config.name}.csv",
103
- "data_dir": data_dir
104
- },
105
  ),
106
  datasets.SplitGenerator(
107
  name=datasets.Split.VALIDATION,
108
- gen_kwargs={
109
- "csv_file": f"{data_dir}/data_val_{self.config.name}.csv",
110
- "data_dir": data_dir
111
- },
112
  ),
113
  datasets.SplitGenerator(
114
  name=datasets.Split.TEST,
115
- gen_kwargs={
116
- "csv_file": f"{data_dir}/data_test_{self.config.name}.csv",
117
- "data_dir": data_dir
118
- },
119
  ),
120
  ]
121
 
122
- def _generate_examples(self, csv_file, data_dir):
123
- df = pd.read_csv(csv_file)
124
- df = df.dropna(subset=["filename", "label", "meter"]).reset_index(drop=True)
125
-
126
  for idx, row in df.iterrows():
127
- # Construct the full audio path
128
- audio_path = f"{data_dir}/{row['filename']}"
129
-
130
  yield idx, {
131
  "filename": row["filename"],
132
- "audio": audio_path,
133
  "label": row["label"],
134
  "meter": str(row["meter"]),
135
  "alt_meter": str(row.get("alt_meter", row["meter"])),
 
1
+ # meter2800.py
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  from pathlib import Path
3
  import datasets
4
  import pandas as pd
 
15
 
16
  _DESCRIPTION = """\
17
  Meter2800 is a dataset of 2,800 music audio samples for automatic meter classification.
18
+ Each audio file is annotated with a primary meter class label and an alternative meter.
 
19
  It is split into training, validation, and test sets, each available in two class configurations:
20
  2-class and 4-class. All audio is 16-bit WAV format.
21
  """
 
22
  _HOMEPAGE = "https://huggingface.co/datasets/pianistprogrammer/Meter2800"
23
  _LICENSE = "mit"
24
 
 
25
  LABELS_4 = ["three", "four", "five", "seven"]
26
+ LABELS_2 = ["three", "four"]
27
 
28
  class Meter2800Config(datasets.BuilderConfig):
 
29
  def __init__(self, name, **kwargs):
30
+ super().__init__(name=name, version=datasets.Version("1.0.0"), **kwargs)
 
 
 
 
31
 
32
  class Meter2800(datasets.GeneratorBasedBuilder):
 
 
33
  BUILDER_CONFIGS = [
34
+ Meter2800Config(name="4_classes", description="4‑class meter classification"),
35
+ Meter2800Config(name="2_classes", description="2‑class meter classification"),
 
 
 
 
 
 
36
  ]
 
37
  DEFAULT_CONFIG_NAME = "4_classes"
38
 
39
  def _info(self):
40
+ labels = LABELS_4 if self.config.name == "4_classes" else LABELS_2
 
 
 
 
 
 
 
41
  return datasets.DatasetInfo(
42
  description=_DESCRIPTION,
43
  features=datasets.Features({
44
  "filename": datasets.Value("string"),
45
+ "audio": datasets.Audio(sampling_rate=22050),
46
+ "label": datasets.ClassLabel(names=labels),
47
  "meter": datasets.Value("string"),
48
  "alt_meter": datasets.Value("string"),
49
  }),
 
54
  )
55
 
56
  def _split_generators(self, dl_manager):
57
+ # download CSVs and tarball
58
+ csv_files = dl_manager.download({
59
+ split: f"https://huggingface.co/datasets/pianistprogrammer/Meter2800/resolve/main/data_{split}_{self.config.name}.csv"
60
+ for split in ["train", "val", "test"]
61
+ })
62
+ archive = dl_manager.download_and_extract("https://huggingface.co/datasets/pianistprogrammer/Meter2800/resolve/main/data.tar.gz")
63
+
64
  return [
65
  datasets.SplitGenerator(
66
  name=datasets.Split.TRAIN,
67
+ gen_kwargs={"csv_path": csv_files["train"], "root": archive}
 
 
 
68
  ),
69
  datasets.SplitGenerator(
70
  name=datasets.Split.VALIDATION,
71
+ gen_kwargs={"csv_path": csv_files["val"], "root": archive}
 
 
 
72
  ),
73
  datasets.SplitGenerator(
74
  name=datasets.Split.TEST,
75
+ gen_kwargs={"csv_path": csv_files["test"], "root": archive}
 
 
 
76
  ),
77
  ]
78
 
79
+ def _generate_examples(self, csv_path, root):
80
+ df = pd.read_csv(csv_path).dropna(subset=["filename", "label", "meter"]).reset_index(drop=True)
 
 
81
  for idx, row in df.iterrows():
82
+ path = Path(root) / row["filename"]
 
 
83
  yield idx, {
84
  "filename": row["filename"],
85
+ "audio": str(path),
86
  "label": row["label"],
87
  "meter": str(row["meter"]),
88
  "alt_meter": str(row.get("alt_meter", row["meter"])),