Datasets:
Tasks:
Audio Classification
Modalities:
Audio
Languages:
English
Tags:
audio
music-classification
meter-classification
multi-class-classification
multi-label-classification
License:
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 used in the "label" and "meter"/"alt_meter" columns | |
LABELS_4 = ["three", "four", "five" , "seven"] | |
LABELS_2 = ["three", "four"] # Example if using a binary grouping | |
class Meter2800(datasets.GeneratorBasedBuilder): | |
BUILDER_CONFIGS = [ | |
datasets.BuilderConfig(name="4_classes", version=datasets.Version("1.0.0"), | |
description="4-class meter classification"), | |
datasets.BuilderConfig(name="2_classes", version=datasets.Version("1.0.0"), | |
description="2-class meter classification"), | |
] | |
def _info(self): | |
label_names = LABELS_4 if self.config.name == "4_classes" else LABELS_2 | |
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): | |
root = Path(__file__).parent | |
suffix = "4_classes" if self.config.name == "4_classes" else "2_classes" | |
return [ | |
datasets.SplitGenerator( | |
name=datasets.Split.TRAIN, | |
gen_kwargs={"csv_file": root / f"data_train_{suffix}.csv"}, | |
), | |
datasets.SplitGenerator( | |
name=datasets.Split.VALIDATION, | |
gen_kwargs={"csv_file": root / f"data_val_{suffix}.csv"}, | |
), | |
datasets.SplitGenerator( | |
name=datasets.Split.TEST, | |
gen_kwargs={"csv_file": root / f"data_test_{suffix}.csv"}, | |
), | |
] | |
def _generate_examples(self, csv_file): | |
df = pd.read_csv(csv_file) | |
df = df.dropna(subset=["filename", "label", "meter"]).reset_index(drop=True) | |
for idx, row in df.iterrows(): | |
audio_path = Path(__file__).parent / row["filename"].lstrip("/") | |
yield idx, { | |
"filename": row["filename"], | |
"audio": str(audio_path), | |
"label": row["label"], | |
"meter": str(row["meter"]), | |
"alt_meter": str(row.get("alt_meter", row["meter"])), | |
} | |