musiclang-predict


Namemusiclang-predict JSON
Version 1.2.0 PyPI version JSON
download
home_pageNone
SummaryControllable symbolic music generation with generative AI
upload_time2024-03-20 16:38:14
maintainerNone
docs_urlNone
authorFlorian GARDIN
requires_python>=3.6
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ![MusicLang logo](https://github.com/MusicLang/musiclang/blob/main/documentation/images/MusicLang.png?raw=true "MusicLang")

<h1 align="center" weight='300' >MusicLang Predict, your controllable music copilot. </h1>

<h4 align="center">
  <a href="https://huggingface.co/musiclang/musiclang-v2"> πŸ€— HuggingFace</a> |
  <a href="https://discord.gg/2g7eA5vP">Discord</a> |
  <a href="https://www.linkedin.com/company/musiclang/">Follow us!</a>
</h4>
<br/>

<h4>☞ You want to generate music that you can export to your favourite DAW in MIDI ?</h4> 
<h4>☞ You want to control the chord progression of the generated music ?</h4> 
<h4>☞ You need to run it fast on your laptop without a gpu ?</h4> 

<br/>
<h2 align="center"><b>MusicLang is the contraction of β€œMusic” & β€œlanguage”: we bring advanced controllability features over music generation by manipulating symbolic music.</b></h2>
<br/>

<summary><kbd>Table of contents</kbd></summary>

- <a href="#quickstart">Quickstart πŸš€</a>
    - <a href="#colab">Try it quickly πŸ“™</a>
    - <a href="#install">Install MusicLang β™«</a>
- <a href="#examples">Examples 🎹</a>
    - <a href="#example_1">1. Generate your first music πŸ•Ί</a>
    - <a href="#example_2">2. Controlling chord progression generation πŸͺ©</a>
    - <a href="#example_3">3. Generation from an existing music πŸ’ƒ</a>
- <a href="#next">What's coming next at musiclang? πŸ‘€</a>
- <a href="#hdw">How does MusicLang work? πŸ”¬</a>
    - <a href="#article_1">1. Annotate chords and scales progression of MIDIs using MusicLang analysis</a>
    - <a href="#article_2">2. The MusicLang tokenizer : Toward controllable symbolic music generation</a>
- <a href="#share">Contributing & spread the word 🀝</a>
- <a href="#license">License βš–οΈ</a>

<h1 id="quickstart">Quickstart πŸš€</h1>
<h2 id="colab">Try it quickly πŸ“™</h2>
<br/>

[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/1MA2mek826c05BjbWk2nRkVv2rW7kIU_S?usp=sharing)
[![Open in Spaces](https://huggingface.co/datasets/huggingface/badges/resolve/main/open-in-hf-spaces-sm.svg)](https://huggingface.co/spaces/musiclang/musiclang-predict)

Go to our <a href="https://colab.research.google.com/drive/1MA2mek826c05BjbWk2nRkVv2rW7kIU_S?usp=sharing">β™ΎColab</a>, or to our <a href="https://huggingface.co/spaces/musiclang/musiclang-predict">πŸ€—HuggingFace space</a>, we have a lot of cool examples, from generating creative musical ideas to continuing a song with a specified chord progression.
<br/>

<h2 id="install">Install MusicLang β™«</h2> 
<br/>

Install the `musiclang-predict` package :

```bash
pip install musiclang_predict
```
<h2 id="examples">Examples 🎹</h2>

<h3 id="example_1">1. Generate your first music πŸ•Ί</h3> 
<br/>

Open your favourite notebook and start generating music in a few lines :

```python
from musiclang_predict import MusicLangPredictor
nb_tokens = 1024 
temperature = 0.9  # Don't go over 1.0, at your own risks !
top_p = 1.0 # <=1.0, Usually 1 best to get not too much repetitive music
seed = 16  # change here to change result, or set to 0 to unset seed

ml = MusicLangPredictor('musiclang/musiclang-v2') # Only available model for now

score = ml.predict(
    nb_tokens=nb_tokens,  # 1024 tokens ~ 25s of music (depending of the number of instruments generated)
    temperature=temperature,
    topp=top_p,
    rng_seed=seed # change here to change result, or set to 0 to unset seed
)
score.to_midi('test.mid') # Open that file in your favourite DAW, score editor or even in VLC
```

<h3 id="example_2">2. Controlling chord progression generation πŸͺ©</h3>
<br/>

You had a specific harmony in mind, right ? MusicLang allows 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
from musiclang_predict import MusicLangPredictor

# Control the chord progression
# Chord qualities available : M, m, 7, m7b5, sus2, sus4, m7, M7, dim, dim0.
# You can also specify the bass if it belongs to the chord (eg : Bm/D)
chord_progression = "Am CM Dm E7 Am" # 1 chord = 1 bar
time_signature = (4, 4) # 4/4 time signature, don't be too crazy here 
nb_tokens = 1024 
temperature = 0.8
top_p = 1.0
seed = 42

ml = MusicLangPredictor('musiclang/musiclang-v2')

score = ml.predict_chords(
    chord_progression,
    time_signature=time_signature,
    temperature=temperature,
    topp=top_p,
    rng_seed=seed # set to 0 to unset seed
)
score.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. This may occur more frequently when using an exotic chord progression or setting a high temperature.

<h3 id="example_3">3. Generation from an existing music πŸ’ƒ</h3>
<br/>

What if I want to use MusicLang from an existing music ? Don't worry, we got you covered. You can use your music as a template to generate new music.
Let's continue with some Bach music and explore a chord progression he might have used: 
```python
from musiclang_predict import MusicLangPredictor
from musiclang_predict import corpus

song_name = 'bach_847' # corpus.list_corpus() to get the list of available songs
chord_progression = "Cm C7/E Fm F#dim G7 Cm"
nb_tokens = 1024 
temperature = 0.8 
top_p = 1.0 
seed = 3666 

ml = MusicLangPredictor('musiclang/musiclang-v2')

score = ml.predict_chords(
    chord_progression,
    score=corpus.get_midi_path_from_corpus(song_name),
    time_signature=(4, 4),
    nb_tokens=1024,
    prompt_chord_range=(0,4),
    temperature=temperature,
    topp=top_p,
    rng_seed=seed # set to 0 to unset seed
)

score.to_midi('test.mid', tempo=110, time_signature=(4, 4))
```

<h2 id="next">What's coming next at MusicLang? πŸ‘€</h2>
<br/>

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;
- And more to come! 😎

<h2 id="hdw">How does MusicLang work? πŸ”¬</h2>
<br/>

If you want to learn more about how we are moving toward symbolic music generation, go to our [technical blog](https://musiclang.github.io/). The tokenization, the model are described in great details: 

<h4 id="article_1"><a href="https://musiclang.github.io/chord_parsing/"> 1. Annotate chords and scales progression of MIDIs using MusicLang analysis</a></h4>
<h4 id="article_2"><a href="https://musiclang.github.io/tokenizer/"> 2. The MusicLang tokenizer : Toward controllable symbolic music generation</a></h4>
<br/> 

We are using a LLAMA2 architecture (many thanks to Andrej Karpathy's awesome [llama2.c](https://github.com/karpathy/llama2.c)), trained on a large dataset of midi files (The CC0 licensed [LAKH](https://colinraffel.com/projects/lmd/)).
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.


<h2 id="share">Contributing & spread the word 🀝</h2> 
<br/>

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](https://www.musiclang.io/contact).

Whether you're contributing code or just saying hello, we'd love to hear about the work you are creating with MusicLang. Here's how you can reach out to us: 
* Join our [Discord](https://discord.gg/2g7eA5vP) to ask your questions and get support
* Follow us on [Linkedin](https://www.linkedin.com/company/musiclang/)
* Add your star on [GitHub](https://github.com/musiclang/musiclang_predict?tab=readme-ov-file) or [HuggingFace](https://huggingface.co/musiclang/musiclang-4k)

<h2 id="license">License βš–οΈ</h2>
<br/>

MusicLang Predict (This package) is licensed under the GPL-3.0 License.
However please note that specific licenses applies to our models. If you would like to use the model in your commercial product, please
[contact us](https://www.musiclang.io/contact). We are looking forward to hearing from you !

The MusicLang base language package on which the model rely ([musiclang package](https://github.com/musiclang/musiclang)) is licensed under the BSD 3-Clause License.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "musiclang-predict",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": null,
    "author": "Florian GARDIN",
    "author_email": "fgardin.pro@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/2d/e4/18cedf4a8ba55983c984a6ea514753a05ba09eac60d7caac0eeca7f4594c/musiclang-predict-1.2.0.tar.gz",
    "platform": null,
    "description": "![MusicLang logo](https://github.com/MusicLang/musiclang/blob/main/documentation/images/MusicLang.png?raw=true \"MusicLang\")\n\n<h1 align=\"center\" weight='300' >MusicLang Predict, your controllable music copilot. </h1>\n\n<h4 align=\"center\">\n  <a href=\"https://huggingface.co/musiclang/musiclang-v2\"> \ud83e\udd17 HuggingFace</a> |\n  <a href=\"https://discord.gg/2g7eA5vP\">Discord</a> |\n  <a href=\"https://www.linkedin.com/company/musiclang/\">Follow us!</a>\n</h4>\n<br/>\n\n<h4>\u261e You want to generate music that you can export to your favourite DAW in MIDI ?</h4> \n<h4>\u261e You want to control the chord progression of the generated music ?</h4> \n<h4>\u261e You need to run it fast on your laptop without a gpu ?</h4> \n\n<br/>\n<h2 align=\"center\"><b>MusicLang is the contraction of \u201cMusic\u201d & \u201clanguage\u201d: we bring advanced controllability features over music generation by manipulating symbolic music.</b></h2>\n<br/>\n\n<summary><kbd>Table of contents</kbd></summary>\n\n- <a href=\"#quickstart\">Quickstart \ud83d\ude80</a>\n    - <a href=\"#colab\">Try it quickly \ud83d\udcd9</a>\n    - <a href=\"#install\">Install MusicLang \u266b</a>\n- <a href=\"#examples\">Examples \ud83c\udfb9</a>\n    - <a href=\"#example_1\">1. Generate your first music \ud83d\udd7a</a>\n    - <a href=\"#example_2\">2. Controlling chord progression generation \ud83e\udea9</a>\n    - <a href=\"#example_3\">3. Generation from an existing music \ud83d\udc83</a>\n- <a href=\"#next\">What's coming next at musiclang? \ud83d\udc40</a>\n- <a href=\"#hdw\">How does MusicLang work? \ud83d\udd2c</a>\n    - <a href=\"#article_1\">1. Annotate chords and scales progression of MIDIs using MusicLang analysis</a>\n    - <a href=\"#article_2\">2. The MusicLang tokenizer : Toward controllable symbolic music generation</a>\n- <a href=\"#share\">Contributing & spread the word \ud83e\udd1d</a>\n- <a href=\"#license\">License \u2696\ufe0f</a>\n\n<h1 id=\"quickstart\">Quickstart \ud83d\ude80</h1>\n<h2 id=\"colab\">Try it quickly \ud83d\udcd9</h2>\n<br/>\n\n[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/1MA2mek826c05BjbWk2nRkVv2rW7kIU_S?usp=sharing)\n[![Open in Spaces](https://huggingface.co/datasets/huggingface/badges/resolve/main/open-in-hf-spaces-sm.svg)](https://huggingface.co/spaces/musiclang/musiclang-predict)\n\nGo to our <a href=\"https://colab.research.google.com/drive/1MA2mek826c05BjbWk2nRkVv2rW7kIU_S?usp=sharing\">\u267eColab</a>, or to our <a href=\"https://huggingface.co/spaces/musiclang/musiclang-predict\">\ud83e\udd17HuggingFace space</a>, we have a lot of cool examples, from generating creative musical ideas to continuing a song with a specified chord progression.\n<br/>\n\n<h2 id=\"install\">Install MusicLang \u266b</h2> \n<br/>\n\nInstall the `musiclang-predict` package :\n\n```bash\npip install musiclang_predict\n```\n<h2 id=\"examples\">Examples \ud83c\udfb9</h2>\n\n<h3 id=\"example_1\">1. Generate your first music \ud83d\udd7a</h3> \n<br/>\n\nOpen your favourite notebook and start generating music in a few lines :\n\n```python\nfrom musiclang_predict import MusicLangPredictor\nnb_tokens = 1024 \ntemperature = 0.9  # Don't go over 1.0, at your own risks !\ntop_p = 1.0 # <=1.0, Usually 1 best to get not too much repetitive music\nseed = 16  # change here to change result, or set to 0 to unset seed\n\nml = MusicLangPredictor('musiclang/musiclang-v2') # Only available model for now\n\nscore = ml.predict(\n    nb_tokens=nb_tokens,  # 1024 tokens ~ 25s of music (depending of the number of instruments generated)\n    temperature=temperature,\n    topp=top_p,\n    rng_seed=seed # change here to change result, or set to 0 to unset seed\n)\nscore.to_midi('test.mid') # Open that file in your favourite DAW, score editor or even in VLC\n```\n\n<h3 id=\"example_2\">2. Controlling chord progression generation \ud83e\udea9</h3>\n<br/>\n\nYou had a specific harmony in mind, right ? MusicLang allows fine control over the chord progression of the generated music.\nJust specify it as a string like below, choose a time signature and let the magic happen.\n\n```python\nfrom musiclang_predict import MusicLangPredictor\n\n# Control the chord progression\n# Chord qualities available : M, m, 7, m7b5, sus2, sus4, m7, M7, dim, dim0.\n# You can also specify the bass if it belongs to the chord (eg : Bm/D)\nchord_progression = \"Am CM Dm E7 Am\" # 1 chord = 1 bar\ntime_signature = (4, 4) # 4/4 time signature, don't be too crazy here \nnb_tokens = 1024 \ntemperature = 0.8\ntop_p = 1.0\nseed = 42\n\nml = MusicLangPredictor('musiclang/musiclang-v2')\n\nscore = ml.predict_chords(\n    chord_progression,\n    time_signature=time_signature,\n    temperature=temperature,\n    topp=top_p,\n    rng_seed=seed # set to 0 to unset seed\n)\nscore.to_midi('test.mid', tempo=120, time_signature=(4, 4))\n```\n\n> Disclaimer : The chord progression is not guaranteed to be exactly the same as the one you specified. It's a generative model after all. This may occur more frequently when using an exotic chord progression or setting a high temperature.\n\n<h3 id=\"example_3\">3. Generation from an existing music \ud83d\udc83</h3>\n<br/>\n\nWhat if I want to use MusicLang from an existing music ? Don't worry, we got you covered. You can use your music as a template to generate new music.\nLet's continue with some Bach music and explore a chord progression he might have used: \n```python\nfrom musiclang_predict import MusicLangPredictor\nfrom musiclang_predict import corpus\n\nsong_name = 'bach_847' # corpus.list_corpus() to get the list of available songs\nchord_progression = \"Cm C7/E Fm F#dim G7 Cm\"\nnb_tokens = 1024 \ntemperature = 0.8 \ntop_p = 1.0 \nseed = 3666 \n\nml = MusicLangPredictor('musiclang/musiclang-v2')\n\nscore = ml.predict_chords(\n    chord_progression,\n    score=corpus.get_midi_path_from_corpus(song_name),\n    time_signature=(4, 4),\n    nb_tokens=1024,\n    prompt_chord_range=(0,4),\n    temperature=temperature,\n    topp=top_p,\n    rng_seed=seed # set to 0 to unset seed\n)\n\nscore.to_midi('test.mid', tempo=110, time_signature=(4, 4))\n```\n\n<h2 id=\"next\">What's coming next at MusicLang? \ud83d\udc40</h2>\n<br/>\n\nWe are working on a lot of cool features, some are already encoded in the model :\n- A control over the instruments used in each bar and their properties (note density, pitch range, average velocity);\n- Some performances improvements over the inference C script;\n- A faster distilled model for real-time generation that can be embedded in plugins or mobile applications;\n- An integration into a DAW as a plugin;\n- Some specialized smaller models depending on our user's needs;\n- And more to come! \ud83d\ude0e\n\n<h2 id=\"hdw\">How does MusicLang work? \ud83d\udd2c</h2>\n<br/>\n\nIf you want to learn more about how we are moving toward symbolic music generation, go to our [technical blog](https://musiclang.github.io/). The tokenization, the model are described in great details: \n\n<h4 id=\"article_1\"><a href=\"https://musiclang.github.io/chord_parsing/\"> 1. Annotate chords and scales progression of MIDIs using MusicLang analysis</a></h4>\n<h4 id=\"article_2\"><a href=\"https://musiclang.github.io/tokenizer/\"> 2. The MusicLang tokenizer : Toward controllable symbolic music generation</a></h4>\n<br/> \n\nWe are using a LLAMA2 architecture (many thanks to Andrej Karpathy's awesome [llama2.c](https://github.com/karpathy/llama2.c)), trained on a large dataset of midi files (The CC0 licensed [LAKH](https://colinraffel.com/projects/lmd/)).\nWe heavily rely on preprocessing the midi files to get an enriched tokenization that describe chords & scale for each bar.\nThe is also helpful for normalizing melodies relative to the current chord/scale.\n\n\n<h2 id=\"share\">Contributing & spread the word \ud83e\udd1d</h2> \n<br/>\n\nWe are looking for contributors to help us improve the model, the tokenization, the performances and the documentation.\nIf you are interested in this project, open an issue, a pull request, or even [contact us directly](https://www.musiclang.io/contact).\n\nWhether you're contributing code or just saying hello, we'd love to hear about the work you are creating with MusicLang. Here's how you can reach out to us: \n* Join our [Discord](https://discord.gg/2g7eA5vP) to ask your questions and get support\n* Follow us on [Linkedin](https://www.linkedin.com/company/musiclang/)\n* Add your star on [GitHub](https://github.com/musiclang/musiclang_predict?tab=readme-ov-file) or [HuggingFace](https://huggingface.co/musiclang/musiclang-4k)\n\n<h2 id=\"license\">License \u2696\ufe0f</h2>\n<br/>\n\nMusicLang Predict (This package) is licensed under the GPL-3.0 License.\nHowever please note that specific licenses applies to our models. If you would like to use the model in your commercial product, please\n[contact us](https://www.musiclang.io/contact). We are looking forward to hearing from you !\n\nThe MusicLang base language package on which the model rely ([musiclang package](https://github.com/musiclang/musiclang)) is licensed under the BSD 3-Clause License.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Controllable symbolic music generation with generative AI",
    "version": "1.2.0",
    "project_urls": {
        "Documentation": "https://github.com/MusicLang/musiclang_predict",
        "Source": "https://github.com/MusicLang/musiclang_predict",
        "Tracker": "https://github.com/MusicLang/musiclang_predict/issues"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2de418cedf4a8ba55983c984a6ea514753a05ba09eac60d7caac0eeca7f4594c",
                "md5": "d6e17f31b04f96402d2711ffde623c08",
                "sha256": "9804964072bd2079b90dd1cb4a848cfdcb39d084ee2304f3115bad2e7978ff03"
            },
            "downloads": -1,
            "filename": "musiclang-predict-1.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "d6e17f31b04f96402d2711ffde623c08",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 146843,
            "upload_time": "2024-03-20T16:38:14",
            "upload_time_iso_8601": "2024-03-20T16:38:14.961129Z",
            "url": "https://files.pythonhosted.org/packages/2d/e4/18cedf4a8ba55983c984a6ea514753a05ba09eac60d7caac0eeca7f4594c/musiclang-predict-1.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-20 16:38:14",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "MusicLang",
    "github_project": "musiclang_predict",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "circle": true,
    "requirements": [],
    "lcname": "musiclang-predict"
}
        
Elapsed time: 1.51697s