laitselec commited on
Commit
ccd8701
·
1 Parent(s): 1a465ca
MuCUE.py DELETED
@@ -1,165 +0,0 @@
1
- import json
2
- import os
3
- import datasets
4
-
5
- # --- 1. 基本信息 (无改动) ---
6
- _CITATION = """\
7
- @misc{jiang2025advancingfoundationmodelmusic,
8
- title={Advancing the Foundation Model for Music Understanding},
9
- author={Yi Jiang and Wei Wang and Xianwen Guo and Huiyun Liu and Hanrui Wang and Youri Xu and Haoqi Gu and Zhongqian Xie and Chuanjiang Luo},
10
- year={2025},
11
- eprint={2508.01178},
12
- archivePrefix={arXiv},
13
- primaryClass={cs.SD},
14
- url={https://arxiv.org/abs/2508.01178},
15
- }
16
- """
17
- _DESCRIPTION = "MuCUE: A Comprehensive Benchmark for Music Understanding"
18
- _REPO_ID = "Yi3852/MuCUE"
19
-
20
- # --- 2. 关键部分:定义所有Split的名称 (无改动) ---
21
- ALL_SPLITS = [
22
- 'ballroom_genres', 'ballroom_tempo', 'fma_medium', 'fma_small',
23
- 'gs_key', 'gs_key_30s', 'gtzan', 'gtzan_key', 'gtzan_tempo',
24
- 'guitarset', 'ins_cls', 'mcaps', 'md4q', 'mmau_music',
25
- 'mtg_genre', 'mtg_ins', 'mtg_mood', 'mucho', 'nsyn_ins',
26
- 'nsyn_pitch', 'salami_cnt', 'salami_overall', 'salami_pred',
27
- 'salami_segd', 'tat'
28
- ]
29
-
30
-
31
- class MuCUEDataset(datasets.GeneratorBasedBuilder):
32
- """MuCUE数据集加载器,支持批量预下载音频并返回本地绝对路径。"""
33
-
34
- _AUDIO_BASE_URL = f"https://huggingface.co/datasets/{_REPO_ID}/resolve/main/audio/"
35
-
36
- BUILDER_CONFIGS = [
37
- datasets.BuilderConfig(
38
- name="default",
39
- version=datasets.Version("1.0.0"),
40
- description="默认配置,预下载所有音频文件。",
41
- )
42
- ]
43
-
44
- DEFAULT_CONFIG_NAME = "default"
45
-
46
- def _info(self):
47
- # 此方法无改动
48
- return datasets.DatasetInfo(
49
- description=_DESCRIPTION,
50
- features=datasets.Features(
51
- {
52
- "id": datasets.Value("string"),
53
- "question": datasets.Value("string"),
54
- "audio": datasets.Audio(sampling_rate=16_000),
55
- "time_seg": datasets.Sequence(datasets.Value("float32")),
56
- "choices": datasets.Sequence(datasets.Value("string")),
57
- "choices_text": datasets.Value("string"),
58
- "correct_choice": datasets.Value("string"),
59
- "answer": datasets.Value("string"),
60
- }
61
- ),
62
- citation=_CITATION,
63
- )
64
-
65
- def _split_generators(self, dl_manager):
66
- """
67
- 此方法负责下载数据、定义split,并为_generate_examples准备参数。
68
- """
69
- data_dir = self.base_path
70
-
71
- # 1. 扫描所有本地的jsonl文件,收集音频的相对路径并构造其下载URL (逻辑不变)
72
- relative_path_to_url = {}
73
- split_samples = {}
74
-
75
- print("步骤 1: 扫描本地jsonl文件,收集音频路径...")
76
- for split_name in ALL_SPLITS:
77
- filepath = os.path.join(data_dir, f"{split_name}.jsonl")
78
- if os.path.exists(filepath):
79
- samples = []
80
- with open(filepath, "r", encoding="utf-8") as f:
81
- for line in f:
82
- sample = json.loads(line)
83
- samples.append(sample)
84
-
85
- relative_path = sample.get("audio")
86
- if isinstance(relative_path, str) and not relative_path.startswith("http"):
87
- if relative_path not in relative_path_to_url:
88
- url_path = relative_path.replace('\\', '/')
89
- full_url = self._AUDIO_BASE_URL + url_path
90
- relative_path_to_url[relative_path] = full_url
91
- split_samples[split_name] = samples
92
-
93
- # --- 从这里开始是关键改动 ---
94
-
95
- # 2. 使用dl_manager批量下载所有音频LFS文件
96
- print(f"步骤 2: 找到 {len(relative_path_to_url)} 个唯一的音频文件,开始并行下载...")
97
-
98
- # 将所有唯一的URL收集到一个列表中
99
- urls_to_download = list(relative_path_to_url.values())
100
-
101
- # 【核心优化】一次性将整个URL列表传递给dl_manager.download()
102
- # datasets库会自动处理并行下载,并显示一个总的进度条。
103
- # 它返回一个本地路径的列表,顺序与urls_to_download完全对应。
104
- downloaded_local_paths = dl_manager.download(urls_to_download)
105
-
106
- # 创建一个从URL到其下载后本地路径的映射,方便后续查找
107
- url_to_local_path_map = dict(zip(urls_to_download, downloaded_local_paths))
108
-
109
- # 3. 创建从相对路径到本地绝对路径的最终映射
110
- relative_path_to_local_path = {}
111
- for relative_path, full_url in relative_path_to_url.items():
112
- local_path = url_to_local_path_map.get(full_url)
113
- if local_path:
114
- relative_path_to_local_path[relative_path] = local_path
115
- else:
116
- # 这种情况通常发生在某个文件下载失败时
117
- print(f"警告:未能下载或找到 {full_url} 的本地路径")
118
-
119
- print("步骤 3: 所有音频文件已下载并缓存。开始生成数据集 splits...")
120
-
121
- # --- 关键改动结束 ---
122
-
123
- # 4. 为每个split创建SplitGenerator (逻辑不变)
124
- split_generators = []
125
- for split_name in ALL_SPLITS:
126
- if split_name in split_samples:
127
- split_generators.append(
128
- datasets.SplitGenerator(
129
- name=split_name,
130
- gen_kwargs={
131
- "samples": split_samples[split_name],
132
- "path_map": relative_path_to_local_path,
133
- },
134
- )
135
- )
136
-
137
- return split_generators
138
-
139
- def _generate_examples(self, samples, path_map):
140
- """
141
- 生成样本。此部分逻辑不变,高效且正确。
142
- """
143
- for i, sample in enumerate(samples):
144
- key = f"{i}_{sample['id']}"
145
- relative_audio_path = sample.get("audio")
146
- if not isinstance(relative_audio_path, str):
147
- continue
148
-
149
- local_audio_path = path_map.get(relative_audio_path)
150
-
151
- if not local_audio_path:
152
- # 如果文件下载失败,可以选择跳过该样本
153
- # print(f"警告: 找不到样本 {sample['id']} 的本地音频路径: {relative_audio_path}")
154
- continue
155
-
156
- yield key, {
157
- "id": sample["id"],
158
- "question": sample["question"],
159
- "audio": local_audio_path, # 提供绝对路径
160
- "time_seg": sample["time_seg"],
161
- "choices": sample["choices"],
162
- "choices_text": sample["choices_text"],
163
- "correct_choice": sample["correct_choice"],
164
- "answer": sample["answer"],
165
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ballroom_genres.jsonl DELETED
The diff for this file is too large to render. See raw diff
 
ballroom_tempo.jsonl DELETED
The diff for this file is too large to render. See raw diff
 
fma_medium.jsonl DELETED
The diff for this file is too large to render. See raw diff
 
fma_small.jsonl DELETED
The diff for this file is too large to render. See raw diff
 
gs_key.jsonl DELETED
The diff for this file is too large to render. See raw diff
 
gs_key_30s.jsonl DELETED
The diff for this file is too large to render. See raw diff
 
gtzan.jsonl DELETED
The diff for this file is too large to render. See raw diff
 
gtzan_key.jsonl DELETED
The diff for this file is too large to render. See raw diff
 
gtzan_tempo.jsonl DELETED
The diff for this file is too large to render. See raw diff
 
guitarset.jsonl DELETED
The diff for this file is too large to render. See raw diff
 
ins_cls.jsonl DELETED
The diff for this file is too large to render. See raw diff
 
mcaps.jsonl DELETED
The diff for this file is too large to render. See raw diff
 
md4q.jsonl DELETED
The diff for this file is too large to render. See raw diff
 
mmau_music.jsonl DELETED
The diff for this file is too large to render. See raw diff
 
mtg_genre.jsonl DELETED
The diff for this file is too large to render. See raw diff
 
mtg_ins.jsonl DELETED
The diff for this file is too large to render. See raw diff
 
mtg_mood.jsonl DELETED
The diff for this file is too large to render. See raw diff
 
mucho.jsonl DELETED
The diff for this file is too large to render. See raw diff
 
nsyn_ins.jsonl DELETED
The diff for this file is too large to render. See raw diff
 
nsyn_pitch.jsonl DELETED
The diff for this file is too large to render. See raw diff
 
salami_cnt.jsonl DELETED
The diff for this file is too large to render. See raw diff
 
salami_overall.jsonl DELETED
The diff for this file is too large to render. See raw diff
 
salami_pred.jsonl DELETED
The diff for this file is too large to render. See raw diff
 
salami_segd.jsonl DELETED
The diff for this file is too large to render. See raw diff
 
tat.jsonl DELETED
The diff for this file is too large to render. See raw diff