| 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 |
|
|
| 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, |
| }, |
| }, |
| ) |
|
|