floriangardin commited on
Commit
cb4e1e2
·
1 Parent(s): 937ae1f

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +101 -0
README.md CHANGED
@@ -1,3 +1,104 @@
1
  ---
2
  license: gpl-3.0
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: gpl-3.0
3
  ---
4
+ ---
5
+ license: gpl-3.0
6
+ ---
7
+ MusicLang Predict model
8
+ =======================
9
+
10
+ ![MusicLang logo](https://github.com/MusicLang/musiclang/blob/main/documentation/images/MusicLang.png?raw=true "MusicLang")
11
+
12
+
13
+ This is the ONNX version (compatible with transformers.js) of MusicLang-4k.There is a unquantized and quantized version.
14
+ MusicLang Predict is a model for creating original midi soundtracks with generative AI model.
15
+
16
+ It can be used for different use cases :
17
+ - Predict a new song from scratch (a fixed number of bars)
18
+ - Continue a song from a prompt
19
+ - Predict a new song from a template (see examples below)
20
+ - Continue a song from a prompt and a template
21
+
22
+ To solve template generation use cases,
23
+ we provide an interface to create a template from an existing midi file.
24
+
25
+ To make the prediction we have an inference package available here : [MusicLang Predict](https://github.com/MusicLang/musiclang_predict)
26
+ which is based on the musiclang language : [MusicLang](https://huggingface.co/MusicLang).
27
+
28
+
29
+ Installation
30
+ ------------
31
+
32
+ Install the musiclang-predict package with pip :
33
+
34
+ ```bash
35
+ pip install musiclang-predict
36
+ ```
37
+
38
+
39
+ How to use ?
40
+ ------------
41
+
42
+ 1. Create a new 8 bars song from scratch :
43
+
44
+ ```python
45
+ from musiclang_predict import predict, MusicLangTokenizer
46
+ from transformers import GPT2LMHeadModel
47
+
48
+ # Load model and tokenizer
49
+ model = GPT2LMHeadModel.from_pretrained('musiclang/musiclang-4k')
50
+ tokenizer = MusicLangTokenizer('musiclang/musiclang-4k')
51
+ soundtrack = predict(model, tokenizer, chord_duration=4, nb_chords=8)
52
+ soundtrack.to_midi('song.mid', tempo=120, time_signature=(4, 4))
53
+ ```
54
+
55
+ 2. Or use an existing midi song as a song structure template :
56
+ ```python
57
+ from musiclang_predict import midi_file_to_template, predict_with_template, MusicLangTokenizer
58
+ from transformers import GPT2LMHeadModel
59
+
60
+ # Load model and tokenizer
61
+ model = GPT2LMHeadModel.from_pretrained('musiclang/musiclang-4k')
62
+ tokenizer = MusicLangTokenizer('musiclang/musiclang-4k')
63
+
64
+ template = midi_file_to_template('my_song.mid')
65
+ soundtrack = predict_with_template(template, model, tokenizer)
66
+ soundtrack.to_midi('song.mid', tempo=template['tempo'], time_signature=template['time_signature'])
67
+ ```
68
+
69
+ See : [MusicLang templates](https://discovered-scabiosa-ea3.notion.site/Create-a-song-template-with-MusicLang-dfd8cad0a14b464fb3475c7fa19c1a82)
70
+ For a full description of our template format.
71
+ It's only a dictionary containing information for each chord of the song and some metadata like tempo.
72
+ You can even create your own without using a base midi file !
73
+
74
+ 3. Or even use a prompt and a template to create a song
75
+
76
+ ```python
77
+ from musiclang_predict import midi_file_to_template, predict_with_template, MusicLangTokenizer
78
+ from transformers import GPT2LMHeadModel
79
+ from musiclang import Score
80
+
81
+ # Load model and tokenizer
82
+ model = GPT2LMHeadModel.from_pretrained('musiclang/musiclang-4k')
83
+ tokenizer = MusicLangTokenizer('musiclang/musiclang-4k')
84
+ template = midi_file_to_template('my_song.mid')
85
+ # Take the first chord of the template as a prompt
86
+ prompt = Score.from_midi('my_prompt.mid', chord_range=(0, 4))
87
+ soundtrack = predict_with_template(template, model, tokenizer,
88
+ prompt=prompt, # Prompt the model with a musiclang score
89
+ prompt_included_in_template=True # To say the prompt score is included in the template
90
+ )
91
+ soundtrack.to_midi('song.mid', tempo=template['tempo'], time_signature=template['time_signature'])
92
+ ```
93
+
94
+ Contact us
95
+ ----------
96
+
97
+ If you want to help shape the future of open source music generation,
98
+ please contact [us](mailto:[email protected])
99
+
100
+ License
101
+ -------
102
+
103
+ The MusicLang predict package (this package) and its associated models is licensed under the GPL-3.0 License.
104
+ The MusicLang base language (musiclang package) is licensed under the BSD 3-Clause License.