OptimusBach is an Artificial Intelligence model capable of harmonising a given melody into a four-part vocal music piece in the style of J. S. Bach's chorales.
In this project, a sequence-to-sequence Transformer model was trained on a dataset build from Bach's chorales. The dataset was constructed using the music21 Python library and the Transformer model was build using tensorflow's Keras API. The resulting trained model is capable of producing harmonisations for any melody that does not exceed 8 quarter notes in length.
The image below gives a visual represenation of how all the different files in this project work together.
You can use the trained model to produce a harmonisation for your melody. Everything you need to do that is contained in the trained model folder.
- You need to install a music notation software to be able to display the generated music (Musescore is free and works great).
- You need to install tensorflow with Keras.
- You need to install the music21 and numpy Python libraries.
- Save the model weights, input melody (you can find some example melodies here) and the encoding and decoding dictionaries in the same folder that you are going to run the MusicGeneration.py file.
- In the MusicGeneration.py file change the filepaths to where you have saved the above files and where you want your generated sequence to be saved.
- In the GeneratedSequenceDecoding.py file change the filepath to where you saved the generated sequence and the decoding dictionary.
- Make sure that the CreateSheetMusic.py file is saved in the same folder that you are going to run the GeneratedSequenceDecoding.py file.
- Run the GeneratedSequenceDecoding.py file to view the generated music in your music notation software.