Command Palette

Search for a command to run...

Orphia

archived

An experimental music-generation project that trains an RNN-LSTM model on symbolic music to generate new melodies.

Orphia mockup preview
Technologies & Frameworks
PythonJupyter NotebookTensorFlowKerasmusic21LibrosaNumPy

Orphia is a melody generator built around a recurrent neural network. It's trained on a collection of European folk songs and learns to predict, one note at a time, what should come next in a melody, the same way a language model predicts the next word. Once trained, it can be handed a short seed phrase and left to compose an original melody in the same style as the dataset it learned from, note by note, which then gets written out as a real, playable MIDI file.

The Idea

Music, at least monophonic melody, has a lot in common with language: a sequence of discrete symbols where what comes next depends heavily on what came before. I wanted to see how far a fairly standard sequence model, the same kind of architecture used for text generation, could get if you pointed it at music instead of words. Folk melodies were a good target for this: they're simple enough for a small model to actually learn patterns from, but structured enough that a good model's output should sound genuinely musical rather than random.

How It Works

Turning music into symbols. Every song in the dataset gets parsed with music21 and flattened into a sequence of symbols, one per note, chord, or rest. A single note becomes something like 60|1.0 (a middle C held for one quarter note), a chord becomes 60_64_67|0.5, and silence becomes R|2.0. That turns an entire folk song into a flat list a model can actually learn from.

Learning the patterns. Those symbol sequences get sliced into overlapping windows, 64 symbols at a time, and fed into a two-layer LSTM network. The model's whole job is simple to state and hard to do well: given the last 64 musical symbols, predict what comes next. Trained across the full dataset, it gradually picks up on the actual melodic and rhythmic habits of the folk tradition it was trained on, phrasing, common intervals, how melodies tend to resolve.

Composing something new. To generate a melody, you hand the trained model a short seed sequence and let it predict the next symbol, then feed that prediction back in as part of the new sequence and predict the one after that, over and over. A temperature parameter controls how adventurous this gets: low temperature sticks close to the model's most confident guesses, higher temperature lets it take more creative risks at the cost of coherence.

Turning predictions back into music. The generated symbol sequence gets converted back into a music21 stream, note by note, chord by chord, rest by rest, and written out as a standard MIDI file, ready to be opened in a DAW, played back, or rendered to audio with a soundfont.

What I Took Away From It

This was a college project built to actually understand sequence modeling by applying it somewhere other than text, and that swap was more informative than expected. Framing music generation as "next-symbol prediction" makes the LSTM's job identical to a language model's, but the failure modes look completely different: a text model repeating itself is a nuisance, a melody model repeating itself just sounds like a loop, and a model that's slightly under-confident produces something that's technically valid but has no discernible phrasing. Getting a feel for how temperature sampling trades off between "safe but boring" and "interesting but incoherent" translated directly into how I think about sampling in text generation too.