A GPT-2-style piano model
GPT-2 Piano MPS 12k is a symbolic music generator. Instead of natural-language prompts, it reads short piano MIDI prompts, turns them into token sequences, and generates a continuation.
Symbolic piano continuation
A small machine-learning music project that trains a GPT-2-style model to continue symbolic piano MIDI.
Overview
GPT-2 Piano MPS 12k is a symbolic music generator. Instead of natural-language prompts, it reads short piano MIDI prompts, turns them into token sequences, and generates a continuation.
The repo includes scripts for splitting MIDI data, augmenting training files, tokenizing with Miditok REMI, training the model, generating samples, and comparing checkpoints.
Training targets Apple Silicon MPS. Large artifacts such as datasets and checkpoints stay local, so the public repo keeps the code and one tracked example MIDI.
This project does not take written prompts. It continues short MIDI or token prompts, so the input is musical context rather than natural language.
Demo
The model generates a continuation from a short piano MIDI prompt. This repo includes one tracked
sample output at examples/generated-example.mid.
No MP3 file is included, so this page links to the MIDI directly. Browser MIDI playback may depend on the user's system or installed software.
Pipeline
The workflow keeps the music symbolic from start to finish: MIDI files become REMI tokens, the transformer learns token continuations, and generated tokens are written back to MIDI.
Start with piano MIDI files stored locally.
data/raw/source_midis
Create train, validation, and test splits.
prepare_12k_split.py
Add bounded piano transpositions for augmentation.
augment_train_transpose.py
Convert MIDI into compact token arrays.
tokenize_12k_augmented.py
Train a transformer on 2048-token windows.
train_gpt2_piano_12k.py
Run prompt profiles over saved epochs.
generation_pipeline.py
Save generated continuations as MIDI files.
generate_piano_sample.py
Model
The current run uses a compact GPT-2-style configuration for symbolic music tokens. It is prompt-conditioned by MIDI or token prefixes, not by text.
Checkpoint comparison
The repo includes a small batch script for comparing checkpoints by generating MIDI continuations from the same prompt profiles. Checkpoint files are local only and are not included in the repo.
Saved as checkpoints/best on the local training machine.
Used for side-by-side continuation checks against the earlier checkpoint.
Writes generated MIDI files, token arrays, metadata JSON, and a pipeline manifest.
Local use
The code is set up for local experiments. Training and generation need local MIDI data and local checkpoints.
python3 -m pip install -r requirements-smoke.txt
python3 -m unittest tests.test_dependency_smoke
python3 scripts/prepare_12k_split.py
python3 scripts/augment_train_transpose.py
python3 scripts/tokenize_12k_augmented.py
python3 scripts/train_gpt2_piano_12k.py --train-from-scratch
python3 scripts/generate_piano_sample.py \
--checkpoint checkpoints/best
Side experiment
This side experiment explores controlling the density and energy of generated phrases with an intensity value from 0.0 to 1.0.
Notes
Datasets and checkpoints are not included in the repo.
Output quality depends on the MIDI prompt and the checkpoint being sampled.
This is MIDI continuation, not text-to-music generation from written prompts.
The Melody Intensity Editor is still a side experiment.
Next step