Datasets:

Modalities:
Audio
Text
Size:
< 1K
ArXiv:
Libraries:
Datasets
License:
SongFormBench / dataset.py
ASLP-lab's picture
add dataset
c4115a4
raw
history blame
3.34 kB
import os
import json
import numpy as np
import datasets
from datasets import Features, Value, Audio, Array2D, Sequence
from pathlib import Path
import librosa
_CITATION = """\
comming soon.
"""
_DESCRIPTION = """\
SongFormBench is a high-quality benchmark dataset for song structure analysis, consisting of 200 songs from HarmonixSet and 100 Chinese pop songs, aimed at establishing a unified evaluation standard in the MSA field, advancing the task, and addressing the lack of Chinese data.
"""
_HOMEPAGE = "https://huggingface.co/datasets/ASLP-lab/SongFormBench"
_LICENSE = "cc-by-4.0"
class SongFormBench(datasets.GeneratorBasedBuilder):
"""SongFormBench: A Benchmark for Song Structure Analysis (only test split)."""
BUILDER_CONFIGS = [
datasets.BuilderConfig(
name="default",
version=datasets.Version("1.0.0"),
description="MSA Benchmark Test Set",
),
]
DEFAULT_CONFIG_NAME = "default"
def _info(self):
features = Features(
{
"id": Value("string"),
"youtube_url": Value("string"),
"subset": Value("string"),
"language": Value("string"),
"audio": Audio(),
"mel_path": Value("string"),
"label_path": Value("string"),
"labels": {
"segments": Sequence(
{
"start": Value("float32"),
"label": Value("string"),
}
),
},
}
)
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=features,
citation=_CITATION,
license=_LICENSE,
homepage=_HOMEPAGE,
)
def _split_generators(self, dl_manager):
test_path = os.path.join(dl_manager.manual_dir, "data/SongFormBench.jsonl")
self.root_dir = dl_manager.manual_dir # 保存根目录以供后续使用
with open(test_path, "r", encoding="utf-8") as f:
items = [json.loads(line) for line in f]
self.items = items # 将数据存储为实例变量,供 _generate_examples 使用
return [
datasets.SplitGenerator(
name=datasets.Split.TEST,
gen_kwargs={"items": self.items}, # 将数据传递给生成器
),
]
def _generate_examples(self, items):
"""从内存数据生成样本"""
for entry in items:
raw_labels = entry.get("labels", [])
yield (
entry["id"],
{
"id": entry["id"],
"youtube_url": entry.get("youtube_url", ""),
"subset": entry.get("subset", ""),
"language": entry.get("language", ""),
"audio": str(Path(self.root_dir) / entry["audio_path"]),
"mel_path": str(Path(self.root_dir) / entry.get("mel_path", "")),
"label_path": str(
Path(self.root_dir) / entry.get("label_path", "")
),
"labels": {
"segments": raw_labels,
},
},
)