DeepBach implementation for harmonization
Project description
DeepBach
This repository contains implementations of the DeepBach model described in
DeepBach: a Steerable Model for Bach chorales generation
Gaëtan Hadjeres, François Pachet, Frank Nielsen
ICML 2017 arXiv:1612.01010
The code uses python 3.6 together with PyTorch v1.0 and music21 libraries.
For the original Keras version, please checkout the original_keras branch.
Examples of music generated by DeepBach are available on this website
Installation
You can clone this repository, install dependencies using Anaconda and download a pretrained
model together with a dataset
with the following commands:
git clone git@github.com:Ghadjeres/DeepBach.git
cd DeepBach
conda env create --name deepbach_pytorch -f environment.yml
bash dl_dataset_and_models.sh
This will create a conda env named deepbach_pytorch.
music21 editor
You might need to Open a four-part chorale. Press enter on the server address, a list of computed models should appear. Select and (re)load a model. Configure properly the music editor called by music21. On Ubuntu you can eg. use MuseScore:
sudo apt install musescore
python -c 'import music21; music21.environment.set("musicxmlPath", "/usr/bin/musescore")'
For usage on a headless server (no X server), just set it to a dummy command:
python -c 'import music21; music21.environment.set("musicxmlPath", "/bin/true")'
Usage
Usage: deepBach.py [OPTIONS]
Options:
--note_embedding_dim INTEGER size of the note embeddings
--meta_embedding_dim INTEGER size of the metadata embeddings
--num_layers INTEGER number of layers of the LSTMs
--lstm_hidden_size INTEGER hidden size of the LSTMs
--dropout_lstm FLOAT amount of dropout between LSTM layers
--linear_hidden_size INTEGER hidden size of the Linear layers
--batch_size INTEGER training batch size
--num_epochs INTEGER number of training epochs
--train train or retrain the specified model
--num_iterations INTEGER number of parallel pseudo-Gibbs sampling
iterations
--sequence_length_ticks INTEGER
length of the generated chorale (in ticks)
--help Show this message and exit.
Examples
You can generate a four-bar chorale with the pretrained model and display it in MuseScore by simply running
python deepBach.py
You can train a new model from scratch by adding the --train flag.
Usage with NONOTO
The command
python flask_server.py
starts a Flask server listening on port 5000. You can then use NONOTO to compose with DeepBach in an interactive way.
This server can also been started using Docker with:
docker run -p 5000:5000 -it --rm ghadjeres/deepbach
(CPU version), with or
docker run --runtime=nvidia -p 5000:5000 -it --rm ghadjeres/deepbach
(GPU version, requires nvidia-docker.
Usage within MuseScore
Deprecated
Put deepBachMuseScore.qml file in your MuseScore plugins directory, and run
python musescore_flask_server.py
Open MuseScore and activate deepBachMuseScore plugin using the Plugin manager. You can then click on the Compose button without any selection to create a new chorale from scratch. You can then select a region in the chorale score and click on the Compose button to regenerated this region using DeepBach.
Issues
Music21 editor not set
music21.converter.subConverters.SubConverterException: Cannot find a valid application path for format musicxml. Specify this in your Environment by calling environment.set(None, '/path/to/application')
Either set it to MuseScore or similar (on a machine with GUI) to to a dummy command (on a server). See the installation section.
Citing
Please consider citing this work or emailing me if you use DeepBach in musical projects.
@InProceedings{pmlr-v70-hadjeres17a,
title = {{D}eep{B}ach: a Steerable Model for {B}ach Chorales Generation},
author = {Ga{\"e}tan Hadjeres and Fran{\c{c}}ois Pachet and Frank Nielsen},
booktitle = {Proceedings of the 34th International Conference on Machine Learning},
pages = {1362--1371},
year = {2017},
editor = {Doina Precup and Yee Whye Teh},
volume = {70},
series = {Proceedings of Machine Learning Research},
address = {International Convention Centre, Sydney, Australia},
month = {06--11 Aug},
publisher = {PMLR},
pdf = {http://proceedings.mlr.press/v70/hadjeres17a/hadjeres17a.pdf},
url = {http://proceedings.mlr.press/v70/hadjeres17a.html},
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file deepbach_pytorch-0.1.6.tar.gz.
File metadata
- Download URL: deepbach_pytorch-0.1.6.tar.gz
- Upload date:
- Size: 32.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.10.0 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/1.0.0 urllib3/1.26.20 tqdm/4.64.1 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5cabb323872aa888820468a70d834ab4b828ec04de9fd8d082994ecd3fdde80c
|
|
| MD5 |
97ebebea91850528422574333ef4f2bd
|
|
| BLAKE2b-256 |
17847e363c7a1759cebf972df0b49ed415e41bac0d370a374c39b494614a7d2c
|
File details
Details for the file deepbach_pytorch-0.1.6-py3-none-any.whl.
File metadata
- Download URL: deepbach_pytorch-0.1.6-py3-none-any.whl
- Upload date:
- Size: 40.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.10.0 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/1.0.0 urllib3/1.26.20 tqdm/4.64.1 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
da832b5d0e7aa88a26e2903f4c6711f9606866e74f24de4ca607075641125489
|
|
| MD5 |
74e433a568145a635d5176be381cb331
|
|
| BLAKE2b-256 |
10dc3c499c36e5a08fe6e7883169d192a2e72bcd42c1bc8cee65196a7f7db8a9
|