admin commited on
Commit
48c3a99
·
1 Parent(s): d764928
Files changed (3) hide show
  1. .gitignore +1 -0
  2. CNPM.py +149 -0
  3. README.md +196 -1
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ rename.sh
CNPM.py ADDED
@@ -0,0 +1,149 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import random
3
+ import hashlib
4
+ import datasets
5
+ import pandas as pd
6
+ from datasets.tasks import AudioClassification
7
+
8
+
9
+ _SYSTEM_TONIC = [
10
+ "C",
11
+ "#C/bD",
12
+ "D",
13
+ "#D/bE",
14
+ "E",
15
+ "F",
16
+ "#F/bG",
17
+ "G",
18
+ "#G/bA",
19
+ "A",
20
+ "#A/bB",
21
+ "B",
22
+ ]
23
+
24
+ _PATTERN = [
25
+ "Gong",
26
+ "Shang",
27
+ "Jue",
28
+ "Zhi",
29
+ "Yu",
30
+ ]
31
+
32
+ _TYPE = [
33
+ "Pentatonic",
34
+ "Hexatonic_Qingjue",
35
+ "Hexatonic_Biangong",
36
+ "Heptatonic_Yayue",
37
+ "Heptatonic_Qingyue",
38
+ "Heptatonic_Yanyue",
39
+ ]
40
+
41
+ _DBNAME = os.path.basename(__file__).split(".")[0]
42
+
43
+ _DOMAIN = f"https://www.modelscope.cn/api/v1/datasets/ccmusic-database/{_DBNAME}/repo?Revision=master&FilePath=data"
44
+
45
+ _HOMEPAGE = f"https://www.modelscope.cn/datasets/ccmusic-database/{_DBNAME}"
46
+
47
+
48
+ _URLS = {
49
+ "audio": f"{_DOMAIN}/audio.zip",
50
+ "mel": f"{_DOMAIN}/mel.zip",
51
+ "label": f"{_DOMAIN}/label.csv",
52
+ }
53
+
54
+
55
+ class CNPM(datasets.GeneratorBasedBuilder):
56
+ def _info(self):
57
+ return datasets.DatasetInfo(
58
+ features=datasets.Features(
59
+ {
60
+ "audio": datasets.Audio(sampling_rate=44100),
61
+ "mel": datasets.Image(),
62
+ "title": datasets.Value("string"),
63
+ "artist": datasets.Value("string"),
64
+ "system": datasets.features.ClassLabel(names=_SYSTEM_TONIC),
65
+ "tonic": datasets.features.ClassLabel(names=_SYSTEM_TONIC),
66
+ "pattern": datasets.features.ClassLabel(names=_PATTERN),
67
+ "type": datasets.features.ClassLabel(names=_TYPE),
68
+ "mode_name": datasets.Value("string"),
69
+ "length": datasets.Value("string"),
70
+ }
71
+ ),
72
+ supervised_keys=("audio", "type"),
73
+ homepage=_HOMEPAGE,
74
+ license="CC-BY-NC-ND",
75
+ version="1.2.0",
76
+ task_templates=[
77
+ AudioClassification(
78
+ task="audio-classification",
79
+ audio_column="audio",
80
+ label_column="type",
81
+ )
82
+ ],
83
+ )
84
+
85
+ def _str2md5(self, original_string: str):
86
+ md5_obj = hashlib.md5()
87
+ md5_obj.update(original_string.encode("utf-8"))
88
+ return md5_obj.hexdigest()
89
+
90
+ def _val_of_key(self, labels: pd.DataFrame, key: str, col: str):
91
+ try:
92
+ return labels.loc[key][col]
93
+ except KeyError:
94
+ return ""
95
+
96
+ def _split_generators(self, dl_manager):
97
+ audio_files = dl_manager.download_and_extract(_URLS["audio"])
98
+ mel_files = dl_manager.download_and_extract(_URLS["mel"])
99
+ label_file = dl_manager.download(_URLS["label"])
100
+ labels = pd.read_csv(label_file, index_col="文件名/File Name", encoding="gbk")
101
+ files = {}
102
+ for fpath in dl_manager.iter_files([audio_files]):
103
+ fname: str = os.path.basename(fpath)
104
+ if fname.endswith(".wav") or fname.endswith(".mp3"):
105
+ song_id = self._str2md5(fname.split(".")[0])
106
+ files[song_id] = {"audio": fpath}
107
+
108
+ for fpath in dl_manager.iter_files([mel_files]):
109
+ fname = os.path.basename(fpath)
110
+ if fname.endswith(".png"):
111
+ song_id = self._str2md5(fname.split(".")[0])
112
+ files[song_id]["mel"] = fpath
113
+
114
+ dataset = []
115
+ for path in files.values():
116
+ fname = os.path.basename(path["audio"])
117
+ dataset.append(
118
+ {
119
+ "audio": path["audio"],
120
+ "mel": path["mel"],
121
+ "title": self._val_of_key(labels, fname, "曲名/Title"),
122
+ "artist": self._val_of_key(labels, fname, "演奏者/Artist"),
123
+ "system": _SYSTEM_TONIC[
124
+ int(self._val_of_key(labels, fname, "同宫系统/System"))
125
+ ],
126
+ "tonic": _SYSTEM_TONIC[
127
+ int(self._val_of_key(labels, fname, "主音音名/Tonic"))
128
+ ],
129
+ "pattern": _PATTERN[
130
+ int(self._val_of_key(labels, fname, "样式/Pattern"))
131
+ ],
132
+ "type": _TYPE[int(self._val_of_key(labels, fname, "种类/Type"))],
133
+ "mode_name": self._val_of_key(labels, fname, "调式全称/Mode Name"),
134
+ "length": self._val_of_key(labels, fname, "时长/Length"),
135
+ }
136
+ )
137
+
138
+ random.shuffle(dataset)
139
+
140
+ return [
141
+ datasets.SplitGenerator(
142
+ name=datasets.Split.TRAIN,
143
+ gen_kwargs={"files": dataset},
144
+ ),
145
+ ]
146
+
147
+ def _generate_examples(self, files):
148
+ for i, item in enumerate(files):
149
+ yield i, item
README.md CHANGED
@@ -1,3 +1,198 @@
1
  ---
2
- license: mit
 
 
 
 
 
 
 
 
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ license: cc-by-nc-nd-4.0
3
+ task_categories:
4
+ - audio-classification
5
+ language:
6
+ - zh
7
+ - en
8
+ tags:
9
+ - music
10
+ - art
11
+ pretty_name: Chinese National Pentatonic Mode Dataset
12
+ size_categories:
13
+ - n<1K
14
+ viewer: false
15
  ---
16
+
17
+ # Dataset Card for Chinese National Pentatonic Mode Dataset
18
+ The original dataset is sourced from the [Chinese National Pentatonic Mode Database](https://ccmusic-database.github.io/en/database/csmtd.html#shou10), which combines manual labeling with computer-based methods in the construction of the World Music Database. It collects and annotates audio of the five modes (including pentatonic, hexatonic, and heptatonic) of "Gong, Shang, Jue, Zhi, and Yu". It also provides a detailed analysis of the judgment of Chinese national pentatonic modes and identifies application scenarios and technical models, offering raw data for the analysis and retrieval of characteristics of Chinese national music.
19
+
20
+ Based on the aforementioned original data, after data processing, we have constructed the `default subset` of this integrated version of the dataset, and its data structure can be viewed in the [viewer](https://www.modelscope.cn/datasets/ccmusic-database/CNPM/dataPeview). As this dataset has been cited and used in published articles, no further `eval subset` need to be constructed for evaluation. Because the default subset is multi-labelled, it is difficult to maintain the integrity of labels in the split for all label columns, hence only a single split for the training set is provided. Users can perform their own splits on specified columns according to their specific downstream tasks.
21
+
22
+ ## Viewer
23
+ <https://www.modelscope.cn/datasets/ccmusic-database/CNPM/dataPeview>
24
+
25
+ ## Dataset Structure
26
+ <style>
27
+ .cnpm td {
28
+ vertical-align: middle !important;
29
+ text-align: center;
30
+ }
31
+ .cnpm th {
32
+ text-align: center;
33
+ }
34
+ </style>
35
+ <table class="cnpm">
36
+ <tr>
37
+ <td>audio</td>
38
+ <td>mel</td>
39
+ <td>system</td>
40
+ <td>tonic</td>
41
+ <td>pattern</td>
42
+ <td>type</td>
43
+ <td>mode_name</td>
44
+ <td>length</td>
45
+ </tr>
46
+ <tr>
47
+ <td>.wav, 44100Hz</td>
48
+ <td>.jpg, 44100Hz</td>
49
+ <td>12-class</td>
50
+ <td>12-class</td>
51
+ <td>5-class</td>
52
+ <td>6-class</td>
53
+ <td>string</td>
54
+ <td>string</td>
55
+ </tr>
56
+ <tr>
57
+ <td>...</td>
58
+ <td>...</td>
59
+ <td>...</td>
60
+ <td>...</td>
61
+ <td>...</td>
62
+ <td>...</td>
63
+ <td>...</td>
64
+ <td>...</td>
65
+ </tr>
66
+ </table>
67
+
68
+ ### Data Instances
69
+ .zip(.wav), .csv
70
+
71
+ ### Data Fields
72
+ Mode type, Name, Performer, Album Name, National Mode Name, Tonggong System, Audio Links
73
+
74
+ ### Data Splits
75
+ train / validation / test
76
+
77
+ ## Labels
78
+ ### System
79
+ | 同宫系统/TongGong System | Label |
80
+ | :----------------------: | :---: |
81
+ | C | 0 |
82
+ | #C/bD | 1 |
83
+ | D | 2 |
84
+ | #D/bE | 3 |
85
+ | E | 4 |
86
+ | F | 5 |
87
+ | #F/bG | 6 |
88
+ | G | 7 |
89
+ | #G/bA | 8 |
90
+ | A | 9 |
91
+ | #A/bB | 10 |
92
+ | B | 11 |
93
+
94
+ ### Mode
95
+ 主音音高/Pitch of Tonic:(规则与同宫系统相同/The rules are the same as the TongGong system)
96
+ #### Pattern
97
+ | 调式样式/Mode Pattern | Label |
98
+ | :-------------------: | :---: |
99
+ | 宫/Gong | 0 |
100
+ | 商/Shang | 1 |
101
+ | 角/Jue | 2 |
102
+ | 徵/Zhi | 3 |
103
+ | 羽/Yu | 4 |
104
+
105
+ #### Mode
106
+ | 调式种类/Mode Type | Label |
107
+ | :-------------------------------: | :---: |
108
+ | 五声/Pentatonic | 0 |
109
+ | 六声(清角)/Hexatonic (Qingjue) | 1 |
110
+ | 六声(变宫)/Hexatonic (Biangong) | 2 |
111
+ | 七声雅乐/Heptatonic Yayue | 3 |
112
+ | 七声清乐/Heptatonic Qingyue | 4 |
113
+ | 七声燕乐/Heptatonic Yanyue | 5 |
114
+
115
+ ## Dataset Description
116
+ - **Homepage:** <https://ccmusic-database.github.io>
117
+ - **Repository:** <https://huggingface.co/datasets/ccmusic-database/CNPM>
118
+ - **Paper:** <https://doi.org/10.5281/zenodo.5676893>
119
+ - **Leaderboard:** <https://www.modelscope.cn/datasets/ccmusic-database/CNPM>
120
+ - **Point of Contact:** Chinese Ethnic Pentatonic Scale; Database; Music Information Retrieval; Pentatonic Therapy
121
+
122
+ ### Dataset Summary
123
+ The expanded dataset is integrated into our database, and each data entry consists of seven columns: the first column denotes the audio recording in .wav format, sampled at 22,050 Hz. The second and third presents the name of the piece and artist. The subsequent columns represent the system, tonic, pattern, and type of the musical piece, respectively. The eighth column contains an additional Chinese name of the mode, while the final column indicates the duration of the audio in seconds.
124
+
125
+ ### Supported Tasks and Leaderboards
126
+ MIR, audio classification
127
+
128
+ ### Languages
129
+ Chinese, English
130
+
131
+ ## Usage
132
+ ```python
133
+ from datasets import load_dataset
134
+
135
+ dataset = load_dataset("ccmusic-dabase/CNPM", split='train')
136
+ for data in dataset:
137
+ print(data)
138
+ ```
139
+
140
+ ## Maintenance
141
+ ```bash
142
+ GIT_LFS_SKIP_SMUDGE=1 git clone [email protected]:datasets/ccmusic-database/CNPM
143
+ cd CNPM
144
+ ```
145
+
146
+ ## Dataset Creation
147
+ ### Curation Rationale
148
+ Lack of a dataset for Chinese National Pentatonic Mode
149
+
150
+ ### Source Data
151
+ #### Initial Data Collection and Normalization
152
+ Weixin Ren, Mingjin Che, Zhaowen Wang, Qinyu Li, Jiaye Hu, Fan Xia, Wei Li, Monan Zhou
153
+
154
+ #### Who are the source language producers?
155
+ Teachers & students from FD-LAMT, CCOM, SCCM
156
+
157
+ ### Annotations
158
+ #### Annotation process
159
+ Based on the working idea of combining manual labeling with a computer in the construction of the World Music Database, this database collects and labels the audio of five modes (including five tones, six tones and seven tones) of "Gong, Shang, Jue, Zhi and Yu". At the same time, it makes a detailed analysis of the judgment of Chinese national pentatonic modes and finds application scenarios and technical models, which can provide raw data for the analysis and retrieval of Chinese national music characteristics.
160
+
161
+ #### Who are the annotators?
162
+ Teachers & students from FD-LAMT, CCOM, SCCM
163
+
164
+ ### Personal and Sensitive Information
165
+ Due to copyright reasons, only some of the audio can be released directly. This part of the audio is the Shang mode and Jue mode tracks performed by professional performers. The rest of the audio needs to be searched and downloaded by the dataset user from music platforms such as Kugou Music, NetEase Cloud Music and QQ Music, based on song titles, artists and album names.
166
+
167
+ ## Considerations for Using the Data
168
+ ### Social Impact of Dataset
169
+ Promoting the development of the music AI industry
170
+
171
+ ### Discussion of Biases
172
+ Only for Traditional Chinese Instruments
173
+
174
+ ### Other Known Limitations
175
+ Only for Pentatonic Mode
176
+
177
+ ## Additional Information
178
+ ### Dataset Curators
179
+ Weixin Ren, Mingjin Che, Zhaowen Wang, Qinyu Li, Jiaye Hu, Fan Xia, Wei Li.
180
+
181
+ ### Evaluation
182
+ [任伟鑫,车明锦,汪照文,孟文武,李沁雨,胡佳弋,夏凡,李伟.CNPM Database:一个用于计算音乐学的中国民族五声调式数据库[J].复旦学报(自然科学版),2022,61(05):555-563.DOI:10.15943/j.cnki.fdxb-jns.20221017.008.](https://kns.cnki.net/kcms2/article/abstract?v=lD5CuVSaeOtw0E2oWliKSMrLiLDt9iwvkwoTgSclPspwUECyt4uNZ6T7DCLlfwMqohXCQXkFzf_XjAUOQ3CAkhPqNj20H8eG9UfUVuHEey0x7Kqp32fMlJiM9xuPtdVMvC1PB2qW0qI=&uniplatform=NZKPT&src=copy)
183
+
184
+ ### Citation Information
185
+ ```bibtex
186
+ @dataset{zhaorui_liu_2021_5676893,
187
+ author = {Monan Zhou, Shenyang Xu, Zhaorui Liu, Zhaowen Wang, Feng Yu, Wei Li and Baoqiang Han},
188
+ title = {CCMusic: an Open and Diverse Database for Chinese and General Music Information Retrieval Research},
189
+ month = {mar},
190
+ year = {2024},
191
+ publisher = {HuggingFace},
192
+ version = {1.2},
193
+ url = {https://huggingface.co/ccmusic-database}
194
+ }
195
+ ```
196
+
197
+ ### Contributions
198
+ Provide a dataset for the Chinese National Pentatonic Mode