sander-wood
commited on
Commit
•
e9654c6
1
Parent(s):
08faf00
Update README.md
Browse files
README.md
CHANGED
@@ -1,124 +1,226 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
-
|
10 |
-
-
|
11 |
-
-
|
12 |
-
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
-
|
20 |
-
|
21 |
-
-
|
22 |
-
|
23 |
-
-
|
24 |
-
|
25 |
-
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: mit
|
3 |
+
language:
|
4 |
+
- af
|
5 |
+
- am
|
6 |
+
- ar
|
7 |
+
- as
|
8 |
+
- az
|
9 |
+
- be
|
10 |
+
- bg
|
11 |
+
- bn
|
12 |
+
- br
|
13 |
+
- bs
|
14 |
+
- ca
|
15 |
+
- cs
|
16 |
+
- cy
|
17 |
+
- da
|
18 |
+
- de
|
19 |
+
- el
|
20 |
+
- eo
|
21 |
+
- es
|
22 |
+
- et
|
23 |
+
- eu
|
24 |
+
- fa
|
25 |
+
- fi
|
26 |
+
- fr
|
27 |
+
- fy
|
28 |
+
- ga
|
29 |
+
- gd
|
30 |
+
- gl
|
31 |
+
- gu
|
32 |
+
- ha
|
33 |
+
- he
|
34 |
+
- hi
|
35 |
+
- hr
|
36 |
+
- hu
|
37 |
+
- hy
|
38 |
+
- id
|
39 |
+
- is
|
40 |
+
- it
|
41 |
+
- ja
|
42 |
+
- jv
|
43 |
+
- ka
|
44 |
+
- kk
|
45 |
+
- km
|
46 |
+
- kn
|
47 |
+
- ko
|
48 |
+
- ku
|
49 |
+
- ky
|
50 |
+
- la
|
51 |
+
- lo
|
52 |
+
- lt
|
53 |
+
- lv
|
54 |
+
- mg
|
55 |
+
- mk
|
56 |
+
- ml
|
57 |
+
- mn
|
58 |
+
- mr
|
59 |
+
- ms
|
60 |
+
- my
|
61 |
+
- ne
|
62 |
+
- nl
|
63 |
+
- no
|
64 |
+
- om
|
65 |
+
- or
|
66 |
+
- pa
|
67 |
+
- pl
|
68 |
+
- ps
|
69 |
+
- pt
|
70 |
+
- ro
|
71 |
+
- ru
|
72 |
+
- sa
|
73 |
+
- sd
|
74 |
+
- si
|
75 |
+
- sk
|
76 |
+
- sl
|
77 |
+
- so
|
78 |
+
- sq
|
79 |
+
- sr
|
80 |
+
- su
|
81 |
+
- sv
|
82 |
+
- sw
|
83 |
+
- ta
|
84 |
+
- te
|
85 |
+
- th
|
86 |
+
- tl
|
87 |
+
- tr
|
88 |
+
- ug
|
89 |
+
- uk
|
90 |
+
- ur
|
91 |
+
- uz
|
92 |
+
- vi
|
93 |
+
- xh
|
94 |
+
- yi
|
95 |
+
- zh
|
96 |
+
- yue
|
97 |
+
base_model:
|
98 |
+
- FacebookAI/xlm-roberta-base
|
99 |
+
pipeline_tag: feature-extraction
|
100 |
+
tags:
|
101 |
+
- music
|
102 |
+
---
|
103 |
+
# CLaMP 2: Multimodal Music Information Retrieval Across 101 Languages Using Large Language Models
|
104 |
+
|
105 |
+
![CLaMP 2 Overview](overview.jpg)
|
106 |
+
|
107 |
+
## Overview
|
108 |
+
CLaMP 2 is a music information retrieval model compatible with 101 languages, designed to support both ABC notation (a text-based musical notation format) and MIDI (Musical Instrument Digital Interface). This repository provides a comprehensive suite of scripts for training models, extracting features, converting various musical data formats, generating multilingual summaries of music metadata using GPT-4, and performing music classification and semantic search tasks. By leveraging the multilingual capabilities of GPT-4, CLaMP 2 aims to enhance the accuracy and inclusivity of music retrieval across diverse linguistic and musical modalities.
|
109 |
+
|
110 |
+
### Links
|
111 |
+
- [CLaMP 2 Code](https://github.com/sanderwood/clamp2)
|
112 |
+
- [CLaMP 2 Paper](https://arxiv.org/)
|
113 |
+
- [CLaMP 2 Model Weights](https://huggingface.co/sander-wood/clamp2/blob/main/weights_clamp2_h_size_768_lr_5e-05_batch_128_scale_1_t_length_128_t_model_FacebookAI_xlm-roberta-base_t_dropout_True_m3_True.pth)
|
114 |
+
- [M3 Model Weights](https://huggingface.co/sander-wood/clamp2/blob/main/weights_m3_p_size_64_p_length_512_t_layers_3_p_layers_12_h_size_768_lr_0.0001_batch_16_mask_0.45.pth)
|
115 |
+
|
116 |
+
Note: The model weights for both CLaMP 2 and M3 should be placed under the `code/` folder to ensure proper loading. Make sure the config hyperparameters are correctly set.
|
117 |
+
|
118 |
+
## Repository Structure
|
119 |
+
The repository is organized into the following main directories:
|
120 |
+
|
121 |
+
- **`code/`**: Includes scripts for training the CLaMP 2 and M3 models and extracting features from music and text data. You can modify hyperparameters and file paths in the configuration files to suit your training needs.
|
122 |
+
|
123 |
+
- **`music_classification/`**: Contains scripts for performing classification tasks via linear probe using the extracted features. This directory includes utilities for training linear classification models and making predictions on new feature data.
|
124 |
+
|
125 |
+
- **`process_data/`**: Provides tools to convert between various musical data formats (ABC notation, MusicXML, MIDI, and MTF) and to summarize music metadata with GPT-4. Before using CLaMP 2 or M3, you should use these scripts to convert your files into interleaved ABC notation or MTF compatible with these models.
|
126 |
+
|
127 |
+
- **`semantic_search/`**: Provides scripts for evaluating model performance, conducting semantic searches, and calculating similarity metrics based on extracted feature vectors.
|
128 |
+
|
129 |
+
## Getting Started
|
130 |
+
### Environment Setup
|
131 |
+
To set up the environment for CLaMP 2, run the following commands:
|
132 |
+
|
133 |
+
```bash
|
134 |
+
conda env create -f environment.yml
|
135 |
+
conda activate clamp2
|
136 |
+
```
|
137 |
+
|
138 |
+
### Data Preparation
|
139 |
+
1. **Convert Files**: Navigate to the `process_data/` folder and convert your music files to a compatible format (interleaved ABC notation or MTF) suitable for CLaMP 2 and M3.
|
140 |
+
- Use the conversion scripts in this folder for tasks like converting MusicXML to ABC and MIDI to MTF.
|
141 |
+
|
142 |
+
- After collecting MusicXML (sheet music) or MIDI (performance data), perform the following operations to convert them into interleaved ABC notation or MTF respectively for model training:
|
143 |
+
1. **Obtain Interleaved ABC Notation**:
|
144 |
+
- Convert MusicXML files to ABC using `batch_xml2abc.py`.
|
145 |
+
- Process the ABC files into interleaved notation using `batch_interleaved_abc.py`.
|
146 |
+
2. **Obtain MTF**:
|
147 |
+
- Convert MIDI files to MTF format using `batch_midi2mtf.py`.
|
148 |
+
3. **Convert Interleaved ABC Back to XML (Optional)**:
|
149 |
+
- Use `batch_xml2abc.py` to convert interleaved ABC files back to MusicXML.
|
150 |
+
4. **Convert MTF Back to MIDI (Optional)**:
|
151 |
+
- Use `batch_mtf2midi.py` to convert MTF files back to MIDI format.
|
152 |
+
|
153 |
+
2. **Generate Multilingual Metadata Summaries**: After converting the music files, the next step is to generate multilingual summaries of the music metadata. This is done using the `gpt4_summarize.py` script, which leverages the GPT-4 API to create structured summaries in both English and a randomly selected non-English language.
|
154 |
+
|
155 |
+
**Input Example**: The input to the summarization script consists of a JSON file representing the music metadata. Here’s an example of a music entry in JSON format:
|
156 |
+
|
157 |
+
```json
|
158 |
+
{
|
159 |
+
"title": "Hard Times Come Again No More",
|
160 |
+
"composer": "Stephen Foster",
|
161 |
+
"genres": ["Children's Music", "Folk"],
|
162 |
+
"description": "\"Hard Times Come Again No More\" (sometimes referred to as \"Hard Times\") is an American parlor song written by Stephen Foster, reflecting themes of sorrow and hope.",
|
163 |
+
"lyrics": "Let us pause in life's pleasures and count its many tears,\nWhile we all sup sorrow with the poor;\nThere's a song that will linger forever in our ears;\nOh! Hard times come again no more.\n\nChorus:\n'Tis the song, the sigh of the weary,\nHard Times, hard times, come again no more.\nMany days you have lingered around my cabin door;\nOh! Hard times come again no more.\n\nWhile we seek mirth and beauty and music light and gay,\nThere are frail forms fainting at the door;\nThough their voices are silent, their pleading looks will say\nOh! Hard times come again no more.\nChorus\n\nThere's a pale weeping maiden who toils her life away,\nWith a worn heart whose better days are o'er:\nThough her voice would be merry, 'tis sighing all the day,\nOh! Hard times come again no more.\nChorus\n\n'Tis a sigh that is wafted across the troubled wave,\n'Tis a wail that is heard upon the shore\n'Tis a dirge that is murmured around the lowly grave\nOh! Hard times come again no more.\nChorus",
|
164 |
+
"tags": ["folk", "traditional", "bluegrass", "nostalgic", "heartfelt", "acoustic", "melancholic", "storytelling", "American roots", "resilience"],
|
165 |
+
"ensembles": ["Folk Ensemble"],
|
166 |
+
"instruments": ["Vocal", "Violin", "Tin whistle", "Guitar", "Banjo", "Tambourine"],
|
167 |
+
"filepaths": [
|
168 |
+
"abc/American_Music/Folk_Traditions/19th_Century/Stephen_Foster/Hard_Times_Come_Again_No_More.abc",
|
169 |
+
"mtf/American_Music/Folk_Traditions/19th_Century/Stephen_Foster/Hard_Times_Come_Again_No_More.mtf"
|
170 |
+
]
|
171 |
+
}
|
172 |
+
```
|
173 |
+
|
174 |
+
**Output Example**: The output will be a JSON file containing the structured summary in both English and a selected non-English language. Here’s an example of the expected output:
|
175 |
+
|
176 |
+
```json
|
177 |
+
{
|
178 |
+
"title": "Hard Times Come Again No More",
|
179 |
+
"composer": "Stephen Foster",
|
180 |
+
"genres": ["Children's Music", "Folk"],
|
181 |
+
"description": "\"Hard Times Come Again No More\" (sometimes referred to as \"Hard Times\") is an American parlor song written by Stephen Foster, reflecting themes of sorrow and hope.",
|
182 |
+
"lyrics": "Let us pause in life's pleasures and count its many tears,\nWhile we all sup sorrow with the poor;\nThere's a song that will linger forever in our ears;\nOh! Hard times come again no more.\n\nChorus:\n'Tis the song, the sigh of the weary,\nHard Times, hard times, come again no more.\nMany days you have lingered around my cabin door;\nOh! Hard times come again no more.\n\nWhile we seek mirth and beauty and music light and gay,\nThere are frail forms fainting at the door;\nThough their voices are silent, their pleading looks will say\nOh! Hard times come again no more.\nChorus\n\nThere's a pale weeping maiden who toils her life away,\nWith a worn heart whose better days are o'er:\nThough her voice would be merry, 'tis sighing all the day,\nOh! Hard times come again no more.\nChorus\n\n'Tis a sigh that is wafted across the troubled wave,\n'Tis a wail that is heard upon the shore\n'Tis a dirge that is murmured around the lowly grave\nOh! Hard times come again no more.\nChorus",
|
183 |
+
"tags": ["folk", "traditional", "bluegrass", "nostalgic", "heartfelt", "acoustic", "melancholic", "storytelling", "American roots", "resilience"],
|
184 |
+
"ensembles": ["Folk Ensemble"],
|
185 |
+
"instruments": ["Vocal", "Violin", "Tin whistle", "Guitar", "Banjo", "Tambourine"],
|
186 |
+
"summary_en": "\"Hard Times Come Again No More,\" composed by Stephen Foster, is a poignant American parlor song that explores themes of sorrow and hope. The lyrics reflect on the contrast between life's pleasures and its hardships, inviting listeners to acknowledge both joy and suffering. With a heartfelt chorus that repeats the line \"Hard times come again no more,\" the song resonates with nostalgia and resilience. It is often performed by folk ensembles and features a variety of instruments, including vocals, violin, guitar, and banjo, encapsulating the spirit of American roots music.",
|
187 |
+
"summary_nen": {
|
188 |
+
"language": "Chinese (Simplified)",
|
189 |
+
"summary": "《艰难时光再无来临》是斯蒂芬·福斯特创作的一首感人至深的美国小歌厅歌曲,探讨了悲伤与希望的主题。歌词展现了生活的乐趣与艰辛之间的对比,邀请听众去感受快乐与痛苦的交织。歌曲中那句反复吟唱的“艰难时光再无来临”深情地表达了怀旧与坚韧。它常常由民谣乐队演奏,伴随着人声、小提琴、吉他和班卓琴等多种乐器,生动地展现了美国根源音乐的独特魅力。"
|
190 |
+
},
|
191 |
+
"filepaths": [
|
192 |
+
"abc/American_Music/Folk_Traditions/19th_Century/Stephen_Foster/Hard_Times_Come_Again_No_More.abc",
|
193 |
+
"mtf/American_Music/Folk_Traditions/19th_Century/Stephen_Foster/Hard_Times_Come_Again_No_More.mtf"
|
194 |
+
]
|
195 |
+
}
|
196 |
+
```
|
197 |
+
|
198 |
+
### Training and Feature Extraction
|
199 |
+
2. **Training Models**: If you want to train CLaMP 2 or M3 models, check the scripts in the `code/` folder.
|
200 |
+
- Modify the `config.py` files to set your training hyperparameters and paths.
|
201 |
+
|
202 |
+
3. **Extracting Features**: After training, or if you have pre-trained models, you can extract features from your data using the respective scripts in the `code/` folder.
|
203 |
+
|
204 |
+
### Classification and Retrieval
|
205 |
+
4. **Classification**: If you need to classify the extracted features, navigate to the `music_classification/` directory.
|
206 |
+
- Here, you'll find scripts to train linear classification models and perform inference on new data.
|
207 |
+
|
208 |
+
5. **Semantic Search**: To perform semantic searches using the extracted features, refer to the scripts in the `semantic_search/` folder.
|
209 |
+
|
210 |
+
## Benchmarks
|
211 |
+
Benchmark datasets related to the experiments conducted with CLaMP 2 and M3, including data used for classification and semantic search tasks, are available in the `benchmarks.zip` file. Note that the `benchmarks.z01` file is required for proper extraction of the contents from `benchmarks.zip`.
|
212 |
+
|
213 |
+
## Citation
|
214 |
+
|
215 |
+
If you use CLaMP 2 or M3 in your research, please cite the following paper:
|
216 |
+
|
217 |
+
```bibtex
|
218 |
+
@inproceedings{clamp2,
|
219 |
+
title={CLaMP 2: Multimodal Music Information Retrieval Across 101 Languages Using Large Language Models},
|
220 |
+
author={Author Name and Coauthor Name},
|
221 |
+
booktitle={Proceedings of the Conference on Music Information Retrieval},
|
222 |
+
year={2024},
|
223 |
+
publisher={Publisher Name},
|
224 |
+
address={Conference Location},
|
225 |
+
url={https://placeholder.url}
|
226 |
+
}
|