This repository contains code and experiments for fine-tuning a pretrained symbolic music generation model for solo jazz piano generation. The project uses a pretrained Aria model as the base model and adapts it to the PiJAMA solo jazz piano dataset using LoRA fine-tuning.
The goal of the project is to test whether parameter-efficient fine-tuning can shift a general symbolic piano generation model toward jazz-style outputs. Several LoRA configurations are compared, using different LoRA ranks and target modules. The generated MIDI outputs are evaluated using an audio-based music style classifier, with a focus on jazz and classical music scores.
.
├── data/ # Dataset files or dataset processing outputs
├── model/ # An example of a pretrained model
├── notebooks/ # Analysis and visualization notebooks
├── src/jazzgen # Utils for training, working with MIDIs, ...
├── src/hpc # Code for training on the HPC cluster
├── requirements.txt # Python dependencies
└── README.md
To reproduce the results, you need to download the midi_kong.zip file from the PiJAMA dataset website and put the extracted files in the data folder.
Create and activate a virtual environment:
python -m venv .venv
source .venv/bin/activate
Or with conda:
conda create -n jazzgen python=3.12
conda activate jazzgen
Install the required dependencies:
pip install -r requirements.txt
pip install -e .
For GPU support, make sure that the installed PyTorch version matches your CUDA version.
To allow for MIDI to audio conversion via command line, you must also install FluidSynth, add it to PATH and download a soundfont, for example from this website. In src/jazzgen/midi_utils.py change the SOUNDFONT_PATH to be the path to this file.
To ensure notebooks run as intended, run the following command first:
python src/prepare_dataset.py
Some notebooks may require training the models first, which you can do with:
python src/hpc/train.py
To create a MIDI file and audio rendering with an example fine-tuned model, call the following:
python src/generate.py
By default, this uses:
Input MIDI: data/custom/s-00.mid
Output MIDI: generated/midi/generated.midi
Output audio: generated/audio/generated.wav
Max length: 2000
Temperature: 1.1
Top-p: 0.95
First n tokens: None
You can override these values from the command line:
python src/generate.py \
--input-midi-path data/custom/s-00.mid \
--save-midi-path generated/midi/generated.midi \
--save-audio-path generated/audio/generated.wav \
--max-length 2000 \
--temperature 1.1 \
--top-p 0.95 \
--first-n-tokens 128
Arguments:
| Argument | Description | Default |
|---|---|---|
--input-midi-path | Path to the input MIDI file. | data/custom/s-00.mid |
--save-midi-path | Path where the generated MIDI file is saved. | generated/midi/generated.midi |
--save-audio-path | Path where the rendered audio file is saved. | generated/audio/generated.wav |
--max-length | Maximum generation length. | 2000 |
--temp, --temperature | Sampling temperature. | 1.1 |
--top-p | Nucleus sampling top-p value. | 0.95 |
--first-n-tokens | Number of initial tokens to condition on. | None |
19 commits
Jupyter Notebook
96.2%
Python
3.7%
This repository contains code and experiments for fine-tuning a pretrained symbolic music generation model for solo jazz piano generation. The project uses a pretrained Aria model as the base model and adapts it to the PiJAMA solo jazz piano dataset using LoRA fine-tuning.
The goal of the project is to test whether parameter-efficient fine-tuning can shift a general symbolic piano generation model toward jazz-style outputs. Several LoRA configurations are compared, using different LoRA ranks and target modules. The generated MIDI outputs are evaluated using an audio-based music style classifier, with a focus on jazz and classical music scores.
.
├── data/ # Dataset files or dataset processing outputs
├── model/ # An example of a pretrained model
├── notebooks/ # Analysis and visualization notebooks
├── src/jazzgen # Utils for training, working with MIDIs, ...
├── src/hpc # Code for training on the HPC cluster
├── requirements.txt # Python dependencies
└── README.md
To reproduce the results, you need to download the midi_kong.zip file from the PiJAMA dataset website and put the extracted files in the data folder.
Create and activate a virtual environment:
python -m venv .venv
source .venv/bin/activate
Or with conda:
conda create -n jazzgen python=3.12
conda activate jazzgen
Install the required dependencies:
pip install -r requirements.txt
pip install -e .
For GPU support, make sure that the installed PyTorch version matches your CUDA version.
To allow for MIDI to audio conversion via command line, you must also install FluidSynth, add it to PATH and download a soundfont, for example from this website. In src/jazzgen/midi_utils.py change the SOUNDFONT_PATH to be the path to this file.
To ensure notebooks run as intended, run the following command first:
python src/prepare_dataset.py
Some notebooks may require training the models first, which you can do with:
python src/hpc/train.py
To create a MIDI file and audio rendering with an example fine-tuned model, call the following:
python src/generate.py
By default, this uses:
Input MIDI: data/custom/s-00.mid
Output MIDI: generated/midi/generated.midi
Output audio: generated/audio/generated.wav
Max length: 2000
Temperature: 1.1
Top-p: 0.95
First n tokens: None
You can override these values from the command line:
python src/generate.py \
--input-midi-path data/custom/s-00.mid \
--save-midi-path generated/midi/generated.midi \
--save-audio-path generated/audio/generated.wav \
--max-length 2000 \
--temperature 1.1 \
--top-p 0.95 \
--first-n-tokens 128
Arguments:
| Argument | Description | Default |
|---|---|---|
--input-midi-path | Path to the input MIDI file. | data/custom/s-00.mid |
--save-midi-path | Path where the generated MIDI file is saved. | generated/midi/generated.midi |
--save-audio-path | Path where the rendered audio file is saved. | generated/audio/generated.wav |
--max-length | Maximum generation length. | 2000 |
--temp, --temperature | Sampling temperature. | 1.1 |
--top-p | Nucleus sampling top-p value. | 0.95 |
--first-n-tokens | Number of initial tokens to condition on. | None |
19 commits
Jupyter Notebook
96.2%
Python
3.7%