sander-wood commited on
Commit
d838576
1 Parent(s): 820667c

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +74 -0
README.md CHANGED
@@ -1,3 +1,77 @@
1
  ---
2
  license: mit
 
 
 
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: mit
3
+ datasets:
4
+ - sander-wood/wikimusictext
5
+ language:
6
+ - en
7
+ pipeline_tag: feature-extraction
8
+ tags:
9
+ - music
10
  ---
11
+
12
+ # CLaMP: Contrastive Language-Music Pre-training for Cross-Modal Symbolic Music Information Retrieval
13
+
14
+ ## Model description
15
+
16
+ In [CLaMP: Contrastive Language-Music Pre-training for Cross-Modal Symbolic Music Information Retrieval](https://ai-muzic.github.io/clamp/), we introduce a solution for cross-modal symbolic MIR that utilizes contrastive learning and pre-training. The proposed approach, CLaMP: Contrastive Language-Music Pre-training, which learns cross-modal representations between natural language and symbolic music using a music encoder and a text encoder trained jointly with a contrastive loss. To pre-train CLaMP, we collected a large dataset of 1.4 million music-text pairs. It employed text dropout as a data augmentation technique and bar patching to efficiently represent music data which reduces sequence length to less than 10%. In addition, we developed a masked music model pre-training objective to enhance the music encoder's comprehension of musical context and structure. CLaMP integrates textual information to enable semantic search and zero-shot classification for symbolic music, surpassing the capabilities of previous models. To support the evaluation of semantic search and music classification, we publicly release [WikiMusicText](https://huggingface.co/datasets/sander-wood/wikimusictext) (WikiMT), a dataset of 1010 lead sheets in ABC notation, each accompanied by a title, artist, genre, and description. In comparison to state-of-the-art models that require fine-tuning, zero-shot CLaMP demonstrated comparable or superior performance on score-oriented datasets.
17
+
18
+ Two variants of CLaMP are introduced: [CLaMP-S/512](https://huggingface.co/sander-wood/clamp-small-512) and [CLaMP-S/1024](https://huggingface.co/sander-wood/clamp-small-1024). Both models consist of a 6-layer music encoder and a 6-layer text encoder with a hidden size of 768. While CLaMP-S/512 accepts input music sequences of up to 512 tokens in length, CLaMP-S/1024 allows for up to 1024 tokens. The maximum input length for the text encoder in both models is 128 tokens. These models are part of [Muzic](https://github.com/microsoft/muzic), a research initiative on AI music that leverages deep learning and artificial intelligence to enhance music comprehension and generation.
19
+
20
+ ## Cross-Modal Symbolic MIR
21
+
22
+ CLaMP is capable of aligning symbolic music and natural language, which can be used for various cross-modal retrieval tasks, including semantic search and zero-shot classification for symbolic music.
23
+
24
+ Semantic search is a technique for retrieving music by open-domain queries, which differs from traditional keyword-based searches that depend on exact matches or meta-information. This involves two steps: 1) extracting music features from all scores in the library, and 2) transforming the query into a text feature. By calculating the similarities between the text feature and the music features, it can efficiently locate the score that best matches the user's query in the library.
25
+
26
+ Zero-shot classification refers to the classification of new items into any desired label without the need for training data. It involves using a prompt template to provide context for the text encoder. For example, a prompt such as "<i>This piece of music is composed by {composer}.</i>" is utilized to form input texts based on the names of candidate composers. The text encoder then outputs text features based on these input texts. Meanwhile, the music encoder extracts the music feature from the unlabelled target symbolic music. By calculating the similarity between each candidate text feature and the target music feature, the label with the highest similarity is chosen as the predicted one.
27
+
28
+ ## Intended uses:
29
+
30
+ 1. Semantic search and zero-shot classification for score-oriented symbolic music datasets.
31
+ 2. Cross-modal representation learning between natural language and symbolic music.
32
+ 3. Enabling research in music analysis, retrieval, and generation.
33
+ 4. Building innovative systems and applications that integrate music and language.
34
+
35
+ ## Limitations:
36
+
37
+ 1. CLaMP's current version has limited comprehension of performance MIDI.
38
+ 2. The model may not perform well on tasks outside its pre-training scope.
39
+ 3. It may require fine-tuning for some specific tasks.
40
+
41
+ ### How to use
42
+
43
+ To use CLaMP, you can follow these steps:
44
+
45
+ 1. Clone the CLaMP repository by running the following command in your terminal:
46
+ ```
47
+ git clone https://github.com/microsoft/muzic.git
48
+ ```
49
+ This will create a local copy of the repository on your computer.
50
+
51
+ 2. Navigate to the CLaMP directory by running the following command:
52
+ ```
53
+ cd muzic/clamp
54
+ ```
55
+
56
+ 3. Install the required dependencies by running the following command:
57
+ ```
58
+ pip install -r requirements.txt
59
+ ```
60
+
61
+ 4. If you are performing a music query, save your query as `inference/music_query.mxl`. For music keys, ensure that all the music files are in the MusicXML (.mxl) format, and are saved in the `inference/music_keys` folder.
62
+
63
+ 5. If you are performing a text query, save your query as `inference/text_query.txt`. For text keys, save all the keys in the `inference/text_keys.txt` file, where each line corresponds to a key.
64
+
65
+ 6. Run the following command to perform the query:
66
+ ```
67
+ python clamp.py -clamp_model_name [MODEL NAME] -query_modal [QUERY MODAL] -key_modal [KEY MODAL] -top_n [NUMBER OF RESULTS]
68
+ ```
69
+ Replace [MODEL NAME] with the name of the CLaMP model you want to use (either `sander-wood/clamp-small-512` or `sander-wood/clamp-small-1024`), [QUERY MODAL] with either `music` or `text` to indicate the type of query you want to perform, [KEY MODAL] with either `music` or `text` to indicate the type of key modal you want to use, and [NUMBER OF RESULTS] with the number of top results you want to return.
70
+
71
+ For example, to perform semantic music search with the `sander-wood/clamp-small-512` model and return the top 5 results, run:
72
+ ```
73
+ python clamp.py -clamp_model_name sander-wood/clamp-small-512 -query_modal text -key_modal music -top_n 5
74
+ ```
75
+ Note that the first time you run the CLaMP script, it will automatically download the model checkpoint from Hugging Face. This may take a few minutes, depending on your internet speed.
76
+
77
+ 7. After running the command, the script will generate a list of the top results for the given query. Each result correspond to a music file in the `music_keys` folder or a line in the `text_keys.txt` file, depending on the type of key modal you used.