File size: 3,726 Bytes
196b45d b102a7e 196b45d |
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 |
---
license: gpl-3.0
---
MusicLang Predict model
=======================
![MusicLang logo](https://github.com/MusicLang/musiclang/blob/main/documentation/images/MusicLang.png?raw=true "MusicLang")
MusicLang Predict is a model for creating original midi soundtracks with generative AI model.
It can be used for different use cases :
- Predict a new song from scratch (a fixed number of bars)
- Continue a song from a prompt
- Predict a new song from a template (see examples below)
- Continue a song from a prompt and a template
To solve template generation use cases,
we provide an interface to create a template from an existing midi file.
To make the prediction we have an inference package available here : [MusicLang Predit](https://github.com/MusicLang/musiclang_predict)
which is based on the musiclang language : [MusicLang](https://huggingface.co/MusicLang).
Installation
------------
Install the musiclang-predict package with pip :
```bash
pip install musiclang-predict
```
How to use ?
------------
1. Create a new 8 bars song from scratch :
```python
from musiclang_predict import predict, MusicLangTokenizer
from transformers import GPT2LMHeadModel
# Load model and tokenizer
model = GPT2LMHeadModel.from_pretrained('musiclang/musiclang-4k')
tokenizer = MusicLangTokenizer('musiclang/musiclang-4k')
soundtrack = predict(model, tokenizer, chord_duration=4, nb_chords=8)
soundtrack.to_midi('song.mid', tempo=120, time_signature=(4, 4))
```
2. Or use an existing midi song as a song structure template :
```python
from musiclang_predict import midi_file_to_template, predict_with_template, MusicLangTokenizer
from transformers import GPT2LMHeadModel
# Load model and tokenizer
model = GPT2LMHeadModel.from_pretrained('musiclang/musiclang-4k')
tokenizer = MusicLangTokenizer('musiclang/musiclang-4k')
template = midi_file_to_template('my_song.mid')
soundtrack = predict_with_template(template, model, tokenizer)
soundtrack.to_midi('song.mid', tempo=template['tempo'], time_signature=template['time_signature'])
```
See : [MusicLang templates](https://discovered-scabiosa-ea3.notion.site/Create-a-song-template-with-MusicLang-dfd8cad0a14b464fb3475c7fa19c1a82)
For a full description of our template format.
It's only a dictionary containing information for each chord of the song and some metadata like tempo.
You can even create your own without using a base midi file !
3. Or even use a prompt and a template to create a song
```python
from musiclang_predict import midi_file_to_template, predict_with_template, MusicLangTokenizer
from transformers import GPT2LMHeadModel
from musiclang import Score
# Load model and tokenizer
model = GPT2LMHeadModel.from_pretrained('musiclang/musiclang-4k')
tokenizer = MusicLangTokenizer('musiclang/musiclang-4k')
template = midi_file_to_template('my_song.mid')
# Take the first chord of the template as a prompt
prompt = Score.from_midi('my_prompt.mid', chord_range=(0, 4))
soundtrack = predict_with_template(template, model, tokenizer,
prompt=prompt, # Prompt the model with a musiclang score
prompt_included_in_template=True # To say the prompt score is included in the template
)
soundtrack.to_midi('song.mid', tempo=template['tempo'], time_signature=template['time_signature'])
```
Contact us
----------
If you want to help shape the future of open source music generation,
please contact [us](mailto:fgardin.pro@gmail.com)
License
-------
The MusicLang predict package (this package) and its associated models is licensed under the GPL-3.0 License.
The MusicLang base language (musiclang package) is licensed under the BSD 3-Clause License. |