A deep learning project exploring sequence modeling for symbolic music generation using Long Short-Term Memory (LSTM) recurrent networks. The model learns pitch, timing, and temporal patterns from classical MIDI piano performances in the MAESTRO dataset to generate new musical sequences.
Generating realistic music requires capturing long-term dependencies, rhythmic cadence, and structural harmony. This project approaches music generation as a sequential auto-regressive task:
- Input Representation: Extracts pitch, note duration, and step time from MIDI files.
- Architecture: Multi-layer LSTM network trained to predict the next note/event given a preceding sequence context.
- Sampling & Generation: Generates new MIDI files starting from a seed prompt or random initialization.
music-rnn/
├── data/
│ └── maestro-v1.0.0-midi/
│ └── maestro-v1.0.0/
│ ├── 2004/
│ ├── 2006/
│ ├── 2008/
│ ├── 2009/
│ ├── 2011/
│ └── ...
└── generate.py
└── music_lstm.pt
This project uses the MAESTRO Dataset (v1.0.0), a collection of over 200 hours of virtuosic piano performances captured with fine pitch and timing details:
- Download the MAESTRO v1.0.0 MIDI dataset.
- Extract the contents into
data/as shown in the directory structure above.
- Python 3.8+
- Recommended dependencies:
torch(ortensorflow)pretty_midiormido(for MIDI parsing)numpymatplotlib
Install dependencies:
pip install torch pretty_midi numpy
Run generate.py to sample a new sequence from a trained checkpoint and export it as a standard .mid file:
python generate.py --output output.mid --length 500 --temperature 1.0
--output: Output file path for the generated MIDI file.--length: Number of note events to generate.--temperature: Sampling temperature (higher = more experimental, lower = safer/more repetitive).
- MIDI Parsing: MIDI events are parsed into a numerical matrix where each event represents pitch, step time (delay between notes), and note duration.
- Sequential Windowing: Training data is split into sliding sequence windows (e.g., 100 timesteps) mapped to the immediate next event.
- Training: An LSTM processes these sequences, optimizing cross-entropy loss for pitch prediction and MSE loss for timing attributes.
-
Sampling Loop: The model predicts step
$N+1$ , appends it to the input window, and slides forward to generate the entire sequence iteratively.