Datasets:
Tasks:
Audio Classification
Modalities:
Audio
Languages:
English
Tags:
audio
music-classification
meter-classification
multi-class-classification
multi-label-classification
License:
Commit
·
ec015f3
1
Parent(s):
b577f77
Refactor Meter2800 dataset configuration and example generation logic
Browse files- meter2800.py +53 -18
meter2800.py
CHANGED
@@ -23,20 +23,44 @@ It is split into training, validation, and test sets, each available in two clas
|
|
23 |
_HOMEPAGE = "https://huggingface.co/datasets/pianistprogrammer/Meter2800"
|
24 |
_LICENSE = "mit"
|
25 |
|
26 |
-
# Define the labels
|
27 |
-
LABELS_4 = ["three", "four", "five"
|
28 |
-
LABELS_2 = ["
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
|
30 |
class Meter2800(datasets.GeneratorBasedBuilder):
|
|
|
|
|
31 |
BUILDER_CONFIGS = [
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
|
|
|
|
|
|
|
|
36 |
]
|
|
|
|
|
37 |
|
38 |
def _info(self):
|
39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
return datasets.DatasetInfo(
|
41 |
description=_DESCRIPTION,
|
42 |
features=datasets.Features({
|
@@ -53,34 +77,45 @@ class Meter2800(datasets.GeneratorBasedBuilder):
|
|
53 |
)
|
54 |
|
55 |
def _split_generators(self, dl_manager):
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
return [
|
60 |
datasets.SplitGenerator(
|
61 |
name=datasets.Split.TRAIN,
|
62 |
-
gen_kwargs={
|
|
|
|
|
|
|
63 |
),
|
64 |
datasets.SplitGenerator(
|
65 |
name=datasets.Split.VALIDATION,
|
66 |
-
gen_kwargs={
|
|
|
|
|
|
|
67 |
),
|
68 |
datasets.SplitGenerator(
|
69 |
name=datasets.Split.TEST,
|
70 |
-
gen_kwargs={
|
|
|
|
|
|
|
71 |
),
|
72 |
]
|
73 |
|
74 |
-
def _generate_examples(self, csv_file):
|
75 |
df = pd.read_csv(csv_file)
|
76 |
df = df.dropna(subset=["filename", "label", "meter"]).reset_index(drop=True)
|
77 |
|
78 |
for idx, row in df.iterrows():
|
79 |
-
|
|
|
|
|
80 |
yield idx, {
|
81 |
"filename": row["filename"],
|
82 |
-
"audio":
|
83 |
"label": row["label"],
|
84 |
"meter": str(row["meter"]),
|
85 |
"alt_meter": str(row.get("alt_meter", row["meter"])),
|
86 |
-
}
|
|
|
23 |
_HOMEPAGE = "https://huggingface.co/datasets/pianistprogrammer/Meter2800"
|
24 |
_LICENSE = "mit"
|
25 |
|
26 |
+
# Define the labels - adjust these based on your actual data
|
27 |
+
LABELS_4 = ["three", "four", "five", "seven"]
|
28 |
+
LABELS_2 = ["simple", "complex"] # or whatever your 2-class grouping actually is
|
29 |
+
|
30 |
+
class Meter2800Config(datasets.BuilderConfig):
|
31 |
+
"""BuilderConfig for Meter2800."""
|
32 |
+
def __init__(self, name, **kwargs):
|
33 |
+
super(Meter2800Config, self).__init__(
|
34 |
+
name=name,
|
35 |
+
version=datasets.Version("1.0.0"),
|
36 |
+
**kwargs
|
37 |
+
)
|
38 |
|
39 |
class Meter2800(datasets.GeneratorBasedBuilder):
|
40 |
+
"""Meter2800 dataset."""
|
41 |
+
|
42 |
BUILDER_CONFIGS = [
|
43 |
+
Meter2800Config(
|
44 |
+
name="4_classes",
|
45 |
+
description="4-class meter classification"
|
46 |
+
),
|
47 |
+
Meter2800Config(
|
48 |
+
name="2_classes",
|
49 |
+
description="2-class meter classification"
|
50 |
+
),
|
51 |
]
|
52 |
+
|
53 |
+
DEFAULT_CONFIG_NAME = "4_classes"
|
54 |
|
55 |
def _info(self):
|
56 |
+
if self.config.name == "4_classes":
|
57 |
+
label_names = LABELS_4
|
58 |
+
elif self.config.name == "2_classes":
|
59 |
+
label_names = LABELS_2
|
60 |
+
else:
|
61 |
+
# Fallback - shouldn't happen with proper configs
|
62 |
+
label_names = LABELS_4
|
63 |
+
|
64 |
return datasets.DatasetInfo(
|
65 |
description=_DESCRIPTION,
|
66 |
features=datasets.Features({
|
|
|
77 |
)
|
78 |
|
79 |
def _split_generators(self, dl_manager):
|
80 |
+
# Get the data directory
|
81 |
+
data_dir = dl_manager.download_and_extract("")
|
82 |
+
|
83 |
return [
|
84 |
datasets.SplitGenerator(
|
85 |
name=datasets.Split.TRAIN,
|
86 |
+
gen_kwargs={
|
87 |
+
"csv_file": f"{data_dir}/data_train_{self.config.name}.csv",
|
88 |
+
"data_dir": data_dir
|
89 |
+
},
|
90 |
),
|
91 |
datasets.SplitGenerator(
|
92 |
name=datasets.Split.VALIDATION,
|
93 |
+
gen_kwargs={
|
94 |
+
"csv_file": f"{data_dir}/data_val_{self.config.name}.csv",
|
95 |
+
"data_dir": data_dir
|
96 |
+
},
|
97 |
),
|
98 |
datasets.SplitGenerator(
|
99 |
name=datasets.Split.TEST,
|
100 |
+
gen_kwargs={
|
101 |
+
"csv_file": f"{data_dir}/data_test_{self.config.name}.csv",
|
102 |
+
"data_dir": data_dir
|
103 |
+
},
|
104 |
),
|
105 |
]
|
106 |
|
107 |
+
def _generate_examples(self, csv_file, data_dir):
|
108 |
df = pd.read_csv(csv_file)
|
109 |
df = df.dropna(subset=["filename", "label", "meter"]).reset_index(drop=True)
|
110 |
|
111 |
for idx, row in df.iterrows():
|
112 |
+
# Construct the full audio path
|
113 |
+
audio_path = f"{data_dir}/{row['filename']}"
|
114 |
+
|
115 |
yield idx, {
|
116 |
"filename": row["filename"],
|
117 |
+
"audio": audio_path,
|
118 |
"label": row["label"],
|
119 |
"meter": str(row["meter"]),
|
120 |
"alt_meter": str(row.get("alt_meter", row["meter"])),
|
121 |
+
}
|