Go to our Colab, we have a lot of cool examples. From generating creative musical ideas to continuing a song with a specified chord progression.
I am more serious about it
Install the musiclang-predict package :
pip install musiclang_predict
Then open your favourite notebook and start generating music in a few lines :
python
1from musiclang_predict import MusicLangPredictor
2nb_tokens =10243temperature =0.9# Don't go over 1.0, at your own risks !4top_p =1.0# <=1.0, Usually 1 best to get not too much repetitive music5seed =16# change here to change result, or set to 0 to unset seed67ml = MusicLangPredictor('musiclang/musiclang-v2')# Only available model for now89score = ml.predict(10 nb_tokens=nb_tokens,# 1024 tokens ~ 25s of music (depending of the number of instruments generated)11 temperature=temperature,12 topp=top_p,13 rng_seed=seed # change here to change result, or set to 0 to unset seed14)15score.to_midi('test.mid')# Open that file in your favourite DAW, score editor or even in VLC
You were talking about controlling the chord progression ?
You had a specific harmony in mind am I right ?
That's why we allow a fine control over the chord progression of the generated music.
Just specify it as a string like below, choose a time signature and let the magic happen.
python
1from musiclang_predict import MusicLangPredictor
23# Control the chord progression4# Chord qualities available : M, m, 7, m7b5, sus2, sus4, m7, M7, dim, dim0.5# You can also specify the bass if it belongs to the chord (eg : Bm/D)6chord_progression ="Am CM Dm E7 Am"# 1 chord = 1 bar7time_signature =(4,4)# 4/4 time signature, don't be too crazy here 8nb_tokens =10249temperature =0.810top_p =1.011seed =421213ml = MusicLangPredictor('musiclang/musiclang-v2')1415score = ml.predict_chords(16 chord_progression,17 time_signature=time_signature,18 temperature=temperature,19 topp=top_p,20 rng_seed=seed # set to 0 to unset seed21)22score.to_midi('test.mid', tempo=120, time_signature=(4,4))
Disclaimer : The chord progression is not guaranteed to be exactly the same as the one you specified. It's a generative model after all.
Usually it will happen when you use an exotic chord progression and if you set a high temperature.
That's cool but I have my music to plug in ...
Don't worry, we got you covered. You can use your music as a template to generate new music.
Let's continue some Bach music with a chord progression he could have used :
python
1from musiclang_predict import MusicLangPredictor
2from musiclang_predict import corpus
34song_name ='bach_847'# corpus.list_corpus() to get the list of available songs5chord_progression ="Cm C7/E Fm F#dim G7 Cm"6nb_tokens =10247temperature =0.88top_p =1.09seed =36661011ml = MusicLangPredictor('musiclang/musiclang-v2')1213score = ml.predict_chords(14 chord_progression,15 score=corpus.get_midi_path_from_corpus(song_name),16 time_signature=(4,4),17 nb_tokens=1024,18 prompt_chord_range=(0,4),19 temperature=temperature,20 topp=top_p,21 rng_seed=seed # set to 0 to unset seed22)2324score.to_midi('test.mid', tempo=110, time_signature=(4,4))
What's coming next ?
We are working on a lot of cool features, some are already encoded in the model :
A control over the instruments used in each bar and their properties (note density, pitch range, average velocity)
Some performances improvements over the inference C script
A faster distilled model for real-time generation that can be embedded in plugins or mobile applications
An integration into a DAW as a plugin
Some specialized smaller models depending on our user's needs
How does that work ?
If you want to learn more about how we are moving toward symbolic music generation, go to our technical blog.
The tokenization, the model are described in great details.
We are using a LLAMA2 architecture (many thanks to Andrej Karpathy awesome llama2.c), trained on a large dataset of midi files (The CC0 licensed LAKH).
We heavily rely on preprocessing the midi files to get an enriched tokenization that describe chords & scale for each bar.
The is also helpful for normalizing melodies relative to the current chord/scale.
Contributing & Contact us
We are looking for contributors to help us improve the model, the tokenization, the performances and the documentation.
If you are interested in this project, open an issue, a pull request, or even contact us directly.
License
Specific licenses applies to our models. If you would like to use the model in your product, please
contact us. We are looking forward to hearing from you !
MusicLang Predict is licensed under the GPL-3.0 License.
The MusicLang base language package on which the model rely (musiclang package) is licensed under the BSD 3-Clause License.