Martin Wepner

Computer learns to generate music by LSTM-RNNs

Inspired by carykh’s Youtube channel, the purpose of this project was to generate music by Long short-term memory Neural Networks (LSTM). I play the piano since quite a few years, so I have at least an above average understanding of music notation. The cool thing about LSTMs is: It learns patterns in text and after a little bit of training it can imitate this patterns and output new text, that looks like the learned one.

So what I did was converting a midi file to a text file, that contains all the musical information needed. I then trained an LSTM using Torch on Ubuntu by feeding it with the text. Then I let the LSTM spit new text out, which I then converted back to a midi file. You can listen to some results in the gallery section.

Unfortunately, I did not know much about overfitting at the time I worked on this project. So the results may be overfitted.


  • generate music by a neural network!


  • Python (converting midi to text and back)
  • torch (training)


  • Martin Wepner


You can clearly hear, that it totally overfit. Also, the quality is pretty poor, because I recorded it with my smartphone, to show it some friends. Next time I start my Ubuntu partition, I will re-train the model and upload some better quality mp3s.

The training data was all Beethoven piano pieces I could find:

Here is some overfitted Amelié music:

Weiter Beitrag

Zurück Beitrag

© 2023 Martin Wepner

Thema von Anders Norén