A neural network that learns musical structure from classical MIDI recordings and generates new note sequences in a similar style. Trained separately on works by Beethoven and Schubert.
- Parsing — MIDI files are read with
music21, which extracts the notes and chords played by the piano part of each piece. - Preprocessing — notes that appear fewer than 50 times across the corpus are dropped, and the remaining sequence is split into overlapping 32-timestep windows. Each unique note/chord is mapped to an integer ID.
- Model — a 1D dilated convolutional network (WaveNet-style): an embedding layer feeds three
Conv1Dlayers with increasing dilation and filter counts (64 → 128 → 256), each followed by dropout and max-pooling, then aGlobalMaxPool1D, a dense layer, and a softmax output over the note vocabulary. - Training — an 80/20 train/test split (scikit-learn), trained for 50 epochs with a
ModelCheckpointcallback that saves the best model by validation loss. - Generation — starting from a random sequence pulled from the validation set, the model predicts the next notes one at a time and the result is written back out as a standalone MIDI file (
music.mid).
Python · TensorFlow/Keras · music21 · NumPy · scikit-learn · matplotlib
pip install tensorflow music21 numpy scikit-learn matplotlib musicalbeeps
python main.pyPlace a folder of .mid files (e.g. Beethoven/) alongside main.py before running — the script trains on whatever MIDI corpus is in that directory and writes its output to music.mid.
- Add a script/notebook that plays back
music.midinline for anyone browsing the repo. - Report a validation loss curve or a few generated samples in this README so results are visible without running the code.