The BachGPT aims to explore the intersection of artificial intelligence and classical music composition. This project utilizes LSTM (Long Short-Term Memory) + attention neural networks, which are particularly suited for sequential data like music. The focus is on generating compositions in the style of Johann Sebastian Bach, a renowned composer known for his complex harmonies and counterpoint techniques.
This endeavor follows in the footsteps of previous works in AI-driven music generation, aiming to capture the essence of Bach's style while exploring the creative capacities of machine learning models in arts.
For this project, the dataset consists of MIDI files of various compositions by Bach. These files were processed to extract patterns and sequences characteristic of Bach's musical style. The pipeline involves converting MIDI files into a format suitable for training the LSTM model, ensuring the network learns to mimic the intricacies and nuances of Bach's compositions.
I have 4 sets of dataset
- Raw MIDI music
- Contrapunctus XIV
- JSB Chorales Dataset - A dataset with 4 voice midi files from bach
- JS Fake Chorales - A similar dataset to JSB Chorales, but fake, generated by AI and annotated by humans
I have used all 4 of these data sources, but when I finally trained the model with dataset 2. Finally, 3 pieces of music were output. The first and third pieces of music came from dataset 2, and the second piece of music came from dataset 3.
LSTM with Attention Our approach employs a Long Short-Term Memory (LSTM) network enhanced with an attention mechanism. LSTM networks are adept at handling sequences with long-range dependencies, making them ideal for music generation tasks.
- LSTM Overview: LSTMs are capable of learning order dependence in sequence prediction problems.
- Attention Mechanism: This feature allows the network to focus on specific parts of the input sequence, enhancing the quality and coherence of the generated music.
The model's performance was evaluated based on its ability to authentically replicate Bach's musical style. We conducted several experiments to optimize the model's architecture and parameters.
- Experiments and Results: The results of these experiments were quantified and are presented in tables and figures, demonstrating the model's accuracy in generating music that aligns with Bach's style.
- Comparison with Baselines: The model's performance was also compared against established baselines to ascertain its efficacy and uniqueness.
I highly recommend running the notebook in Colaboratory so you can view the results and change parameters in real-time. The jupyter notebook code is here. However, you can run Python code on your local machine.
python3 bachGPT.py
python3 bach_predict.py ./models/{your_model_name}.pth
python3 create_midi.py {your_model_name}.pth/output.txt
timidity output/output.midi -Ow -o - | ffmpeg -i - -acodec libmp3lame -ab 320k output/output.mp3
timidity output/complete.midi -Ow -o - | ffmpeg -i - -acodec libmp3lame -ab 320k output/complete.mp3
The final generated Bach-style music is in the output folder.
1.mov
2.mov
3.mov
- Generating Original Classical Music with an LSTM Neural Network and Attention
- Generating Long-Term Structure in Songs and Stories
- Neural Machine Translation by Jointly Learning to Align and Translate
- Baroque Music Generator
- Generating Music using LSTM
- Music Generation using Deep Learning
- How to Generate Music using a LSTM Neural Network in Keras
- Classical-Piano-Composer
- Classic_Music_Generation
- conversion-tool