File size: 4,805 Bytes
442eaea
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3df2755
 
 
442eaea
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
747f6d0
442eaea
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3df2755
442eaea
 
 
 
 
 
 
 
3df2755
de731d3
ec015f3
3df2755
 
442eaea
 
 
 
 
 
 
 
3df2755
442eaea
3df2755
 
 
442eaea
3df2755
 
 
442eaea
 
 
 
3df2755
 
 
442eaea
 
 
3df2755
 
 
442eaea
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3df2755
 
 
442eaea
3df2755
442eaea
 
3df2755
442eaea
 
 
3df2755
 
442eaea
de731d3
 
442eaea
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
Hugging Face's logo
Hugging Face
Models
Datasets
Spaces
Community
Docs
Enterprise
Pricing



Datasets:

pianistprogrammer
/
Meter2800 

like
0
Tasks:
Audio Classification
Modalities:
Audio
Languages:
English
Tags:
audio
music-classification
meter-classification
multi-class-classification
multi-label-classification
License:

mit
Dataset card
Files and versions
Community
Settings
Meter2800
/
meter2800.py

pianistprogrammer's picture
pianistprogrammer
Refactor Meter2800 dataset configuration and example generation logic
ec015f3
1 minute ago
raw

Copy download link
history
blame
edit
delete

4.2 kB
from pathlib import Path
import datasets
import pandas as pd

_CITATION = """\
@misc{meter2800_dataset,
  author       = {PianistProgrammer},
  title        = {{Meter2800}: A Dataset for Music Time signature detection / Meter Classification},
  year         = {2025},
  publisher    = {Hugging Face},
  url          = {https://huggingface.co/datasets/pianistprogrammer/Meter2800}
}
"""

_DESCRIPTION = """\
Meter2800 is a dataset of 2,800 music audio samples for automatic meter classification.
Each audio file is annotated with a primary meter class label (e.g., 'two', 'three', 'four') 
and an alternative meter (numerical, e.g., 2, 3, 4, 6). 
It is split into training, validation, and test sets, each available in two class configurations:
2-class and 4-class. All audio is 16-bit WAV format.
"""

_HOMEPAGE = "https://huggingface.co/datasets/pianistprogrammer/Meter2800"
_LICENSE = "mit"

# Define the labels - adjust these based on your actual data
LABELS_4 = ["three", "four", "five", "seven"]
LABELS_2 = ["simple", "complex"]  # or whatever your 2-class grouping actually is

class Meter2800Config(datasets.BuilderConfig):
    """BuilderConfig for Meter2800."""
    def __init__(self, name, **kwargs):
        super(Meter2800Config, self).__init__(
            name=name,
            version=datasets.Version("1.0.0"),
            **kwargs
        )

class Meter2800(datasets.GeneratorBasedBuilder):
    """Meter2800 dataset."""
    
    BUILDER_CONFIGS = [
        Meter2800Config(
            name="4_classes",
            description="4-class meter classification"
        ),
        Meter2800Config(
            name="2_classes", 
            description="2-class meter classification"
        ),
    ]
    
    DEFAULT_CONFIG_NAME = "4_classes"

    def _info(self):
        if self.config.name == "4_classes":
            label_names = LABELS_4
        elif self.config.name == "2_classes":
            label_names = LABELS_2
        else:
            # Fallback - shouldn't happen with proper configs
            label_names = LABELS_4
            
        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=datasets.Features({
                "filename": datasets.Value("string"),
                "audio": datasets.Audio(sampling_rate=None),
                "label": datasets.ClassLabel(names=label_names),
                "meter": datasets.Value("string"),
                "alt_meter": datasets.Value("string"),
            }),
            supervised_keys=("audio", "label"),
            homepage=_HOMEPAGE,
            license=_LICENSE,
            citation=_CITATION,
        )

    def _split_generators(self, dl_manager):
        # Get the data directory
        data_dir = dl_manager.download_and_extract("")
        
        return [
            datasets.SplitGenerator(
                name=datasets.Split.TRAIN,
                gen_kwargs={
                    "csv_file": f"{data_dir}/data_train_{self.config.name}.csv",
                    "data_dir": data_dir
                },
            ),
            datasets.SplitGenerator(
                name=datasets.Split.VALIDATION,
                gen_kwargs={
                    "csv_file": f"{data_dir}/data_val_{self.config.name}.csv",
                    "data_dir": data_dir
                },
            ),
            datasets.SplitGenerator(
                name=datasets.Split.TEST,
                gen_kwargs={
                    "csv_file": f"{data_dir}/data_test_{self.config.name}.csv",
                    "data_dir": data_dir
                },
            ),
        ]

    def _generate_examples(self, csv_file, data_dir):
        df = pd.read_csv(csv_file)
        df = df.dropna(subset=["filename", "label", "meter"]).reset_index(drop=True)

        for idx, row in df.iterrows():
            # Construct the full audio path
            audio_path = f"{data_dir}/{row['filename']}"
            
            yield idx, {
                "filename": row["filename"],
                "audio": audio_path,
                "label": row["label"],
                "meter": str(row["meter"]),
                "alt_meter": str(row.get("alt_meter", row["meter"])),
            }