In this project I have taken a Machine Learning framework, trained it using a number of MIDI files and used it to generate a new piece of music. My premise was that if all pieces come from a single composer, the output of the neural network should resemble chosen composer’s style of writing the music.
Recurrent neural network (RNN) has been successfully used to generate temporal dependent data. Such data could be for example: text, hand writing or speech. The process rely on analysis of what is the most probable to come after a specific value in a sequence. Learning process is conducted on a number of training sequences where the system makes a prediction of the next step. It then compares it with the actual next step and stores the outcome of such comparison in its internal memory for future reference.
A variant of RNN called long short term memory (LSTM) is proved to be more reliable when utilised with longer sequences. Its main difference in comparison to the regular RNN resides in a series of functions that work similarly to a weight system. They are accessing how much the newly measured values will affect what the system has already learned previously.
I have decided to use 20 sonatas composed by Wolfgang Amadeus Mozart for my project. They are all written for a single instrument – piano. By using such input I was hoping that the result should be more meaningful than if I have used music composed for ensembles. The system would then have trouble correctly interpreting relation between multiple melody lines progression.
I have used for this project neural network code that I have adopted from Will Gomolka with minor adjustments. The implementation comes in a form of Jupiter notebook and is based on Music21 and Keras dependencies.
The output of the system had a form of a MIDI file. I have used one of my Pure Data made FM piano instruments to turn it into a sound file. Below are 10 example outputs created by the neural network.
I believe that the outcome melody is pleasant but limited in quality. The system tends to occasionally get ‘stuck’ on a single note or two. The machine learning model I have chosen can only analyse and create monophonic melody. It is also not sensitive to rhythmical aspects of the music.
My goal was to create a new melodic sequence based on the given examples. The result successfully accomplishes that goal. I came to a conclusion that improving the outcome would take me a significantly longer time before I could determine the most optimal parameters. In my opinion it was an interesting experiment to conduct.
Leave a Reply