









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!










Abstarct: In this paper, we build an application using long short-term memory neural network (NN) in generating music pieces and propose an approach to do so. The proposed approach takes đmidi files, converting them to song files and then encoding them to be as inputs for the NN. Before inputting the files into the NNs, an augmentation process which augments the file into different keys is performed then the file is fed into the NN for training. The last step is the music generation. The main objective is to provide the NN with an arbitrary note and then the NN starts amending it gradually until producing a good piece of music. Various experiments have been conducted to explore the best values of parameters that can be selected to obtain good music generations. The obtained generated music pieces are accepted in terms of rhythm and harmony; however, some other problems exist such as in certain cases the tone stops or in some other cases getting short melodies that do not change.
Music generation is very important nowadays. It can be used in many applications. Musicians or artists build on what is generated by the machine and produce their own original work. The music or art generated by software is also sometimes sold by the companies or individuals who designed them. They can be licensed to corporations and retail for use in advertising, shop music etc. An example of this is Aiva, an artificial intelligence music generator which has already released its own copyrighted albums filled with generated soundtracks in the electronic music genre (Travers, 2018). For generating art, a painting generated by a GAN network named Portrait of Edmond Belamy was auctioned for $432,500; this is an indication of the value in using neural networks (NNs) for generating art or music (Christies.com, 2018). Another example is Jukedeck which can produce music based on the genre and beats per minute specified by the user. These all of the tracks generated by these AI composer products can be licensed for corporate or personal use (Travers, 2018). Automating the creative process of the human means that companies can get multimedia products faster and cheaper. That is why the music generator is such an important application of machine learning techniques
Automated music composition has been a widely researched method of producing new music for many years now. Prior to machine learning the most popular approach to generate music was generative grammars. These previous methods produced simplified music pieces with noncomplex melodies and many inadequacies like predictable repeating melodies. Currently, the most recent (and arguably the best) tool for generating music is NNs (Agarwala, Inoue, & Sly, 2017). NNs can be trained with music like Bach’s in order to generate its own original music pieces; the network learns the pattern of the inputted music and then uses that to generate its own. A good example of this is DeepBach (Hadjeres, Pachet, & Nielsen, 2017) and the BachBot (Liang, 2016) that utilize recurrent NNs. These music generators were able to produce music similar to Bach’s musical style after being trained with hundreds of his chorales (Hadjeres et al., 2017). This article to implement a piano music generator based on Bach’s style using a long-short term memory (LSTM) NN. We limit ourselves to Bach’s musical style because Bach’s style is a well-known and famous style. Considering more than one style will make the learning process more complicated and the NN might lose a style or part of it during learning another style, this might happen because of the big variations in different musical styles. The obtained results will be later presented and discussed in lights of the results of other approaches. In this introduction, we introduce some basic concepts of music and principles of LSTM to pave our explanation for the proposed approach.
The focus for music composition and music generation in more recent times has shifted towards machine learning and artificial intelligence techniques. This is due to the capability of NNs and deep learning to produce less predictable and more melodically complex melodies than their random algorithm and grammar systems counterparts. The majority of music generators in the past few years have been created using LSTM networks. They differ, however, in the encoding of inputs from MIDI formats and some aspects of the NN structure. Eck and Schmidhuber (2002) were the first to switch from regular RNNs to LSTMs to generate blues music. Blues is a genre of music similar to jazz containing a lot of guitar solo note sequences known as riffs. The network was successful in generating music pieces with a proper structure resembling normal blues music. They did not map this to MIDI files but instead used their own format for
generated output is considered a sample or a fake result; it predicts the category of this generated output. The goal of this network structure is to generate outputs that are passable as part of the original dataset (Skymind, 2017). The main problem of GAN is the instability of training between the two networks. This was demonstrated by Agarwala et al. (2017) where the GAN network did not generate any meaningful output because the model was considered too unstable. It will only work if there is some kind of training balance (Tchircoff, 2017). Eck and Schmidhuber (2002) earlier demonstrated the suitability of an LSTM network by proving its capability to recognize chords. However, for simplifying the interface with the machine-learning library Tensorflow, Skuli (2017) demonstrated how Keras could be used to create a music generator with LSTMs. We follow Skuli (2017) technique because of the demonstrated quality of music produced. The network model for recognizing motifs by Walder and Kim (2018) would have been a logical next step for work because of its capability to produce more structured melodies. One of the major drawbacks of Skuli’s network was that the notes had no varying durations; the pieces had fixed time intervals and offsets. Our network, on the other hand, had varying note durations to increase musical depth and complexity. A major difference between our approach for encoding the MIDI data was the interpretation of chords. The models proposed by Skuli (2017) and Eck and Schmidhuber (2002) encode MIDI data into a sequence of note and chord objects before being inputted to the network. Our custom encoding method increased the complexity of the model by using a sliding window to capture given notes within a time interval without making a distinction between single notes or chords. Proposed Methodology : We propose the following flow:
All midi files have been converted into an intermediary format (Song Format) that we developed which helps us deal with the notes in a more natural way. While looping over the events of each file, notes being played in all the 16 MIDI channels are recorded into the Song Format. It is worth noting that sometimes MIDI files would use a ‘note_on’ message with ‘velocity’ 0 to indicate a ‘note_off’. Each MIDI event contains a ‘time’ attribute which holds a number corresponding to the time (in ticks) since that last message. The Song Format is a set of two classes that have the job of holding the note information and converting to and from MIDI files. So, the functionality of exporting and importing MIDI into the encoded format is done inside the Song Format class. Moreover, since MIDI has a note range of [0, 127], and we are only interested in the subset that is the piano keys (the subset [21, 21 + 88] in MIDI), the song format conversion process handles this shift from MIDI space to Piano space Song format conversion process:
Since there is no way to feed the network with midi values directly and be able to generate music, it becomes important to encode the music data into a format that is usable by the network. The output of the encoding method used is a matrix of binary vectors of size N × 89 for each MIDI file, where N is the number of vectors in the piece. The first 88 bits in the vector correspond to the state of the piano keyboards 88 notes. A zero indicates that a note is not being played at this instant, while a one indicates the opposite. The 89th bit in the vector is the repetition count. The repetition count tells us how many times this vector is repeated; that is, how long this current state of the keyboard is preserved until it changes. In our initial experiments, the repetition count was a natural number. However, having a natural number that is not normalized will mess up the loss calculation and convergence. So, at the end we used a real number in the range (0,1]. Where a number close to 0 meaning less repetitions, and 1 meaning it has the most inside it’s MIDI file. The intervals are half-open because no vector should have a repetition value of zero, since it is semantically wrong. The least repetition value for a file will be 1Maximum Repetition. We consciously chose to make the repetition count local instead of global; that is to have 1 be the largest note in the file and not in the whole dataset. Our reasoning is that the repetition count semantically answers ‘How long is this note being played relative to other notes in its file?’, and this number shouldn’t be affected by other vectors in other pieces, even though all these vectors will enter the training process. That is to say, a long note in a file of short notes should not have a value less than a long note in a file of long notes. Figure 8 shows the used encoding method and shows how repeated vectors (The colored vectors) are getting squashed together. The number gets recorded in the repetition count (grey). The repetition count is then normalized by dividing it by the largest repetition count. Neural Network : Having the windowed encoded dataset, it is fed into the NN. We separate the examples and labels such that we give an example at sample n with its timesteps in the range [n – w, n – 1] and let the NN to predict the sample at n + 1.
The figure uses a window from the data generated from the windowing in Figure 11 and shows how this window will be fed into the network. NN training Generating music At fixed intervals during the network training, the network generates music and then save it in MIDI format for the purpose of listening to it and analyzing it. Figure 13 shows how the music gets generated after training. To generate music, the network is fed with a matrix of either noise, or a random matrix from the dataset and ask it to predict the next vector. After predicting the next vector, we append this vector to the matrix as well as the list of generated vectors and pop the last vector from the matrix. Similarly, the
In this section, we present our used datasets, NN architecture and the experimentations.
Bach’s ‘Well-Tempered Clavier Book II’ has been chosen as our dataset (Classicalarchives.com, 2018). This is because of the systematic style of Bach’s music, as well as the special nature of this work in which Bach writes two pieces of music for every key. The dataset contains 24 files, each file containing two pieces. Figure 14 shows a normalized histogram of the count of the 12 keys in the dataset. Each occurrence of a key is counted regardless of the octave. This shows that all the keys occur with the same degree, that is there are no predominant keys in the dataset. The standard deviation of the normalized histogram is 0.02683. This shows that on average the difference in the number of occurrences between any two keys in the dataset is around 2.6%. Figure 15 shows the occurrences of each of the 88 notes. We can observe that most of the notes lie in the middle range of the piano which is usually expected in all music. Due to these characteristics, this dataset is well-balanced and suits our needs perfectly.
The tools used to implement the proposed approach are: Keras on the Tensorflow backend. Keras is a high-level library for machine learning with NN that allows us to prototype quickly and change parameters without rewriting a lot of code. It runs on Google’s tensorflow which is a library for computations on graphs that suits NN perfectly and executes efficiently on the GPU. TensorBoard. A utility from tensorflow to visualize learning. NumPy. NumPy is a scientific linear algebra library that deals efficiently with matrices and vectors. This library is used in Keras and the training and testing data have to be NumPy arrays before feeding them to any network. Moreover, we use NumPy in the encoding and decoding part to deal with matrices (e.g. adding a vector to multiple rows in a matrix). Mido. Mido is a python library that helps reading MIDI files and writing them. Jupyter Notebook. A web application for data visualization and statistical modelling. We use Jupyter Notebook in experimentation to be able to execute blocks of code in any sequence we choose. This helps to rapidly prototype experiments and NN models.
It has been found that the most optimal configuration for the proposed model is to have 4 LSTM layers, with 512 LSTM cells each, a dropout value of 0.6 after each LSTM layer, 3 fully connected layers after the LSTM layers, with 256 neurons each, each of the fully connected layers followed by 0.6 dropout, RMSProp as optimizer, 512 batch size and a window size of 16. Using this configuration, we got a training F-measure of 0.83 and a testing F-measure of 0.71. The problem with generating music is the difficulty of measurement of the quality of the music. Our generated pieces had several advantages and disadvantages compared to the other music generators mentioned before. One advantage of our model was that the notes had varying durations/offsets compared to LSTM-based generators like Skuli (2017), which increased the complexity of the music. Another is that it accounted for a much larger range of possible notes than Skuli (2017) or Chen (2001); Skuli had limited the range to the notes in his Final Fantasy dataset and Chen did not account for many chords. However, this increased complexity led to a lack of melodic structure. While there was a discernable melody in the generated pieces, there were a number of shortcomings compared to other generators. First, the generated pieces lacked the musical clarity (no cluttering of notes) generated by most other models like generated by Agarwala et al. (2017) or Skuli’s. Second, the quality of the melody and rhythm within the pieces was low compared to Walder and Kim’s (2018) model with its focus on recognizing motifs. Their generated pieces had far more rhythm and coherence because the model was capable of identifying motifs. Finally, while our generated pieces did have some note sequences which could be attributed or found to be related to the Bach dataset, they did not have the same level of fidelity to Bach’s musical style like the BachBot model by Liang (2016).
Agarwala, N., Inoue, Y., & Sly, A. (2017). Music composition using recurrent neural networks. [online]. Web.stanford.edu. Retrieved from https://web.stanford.edu/class/cs224n/reports/2762076.pdf. [Google Scholar] Bello, J. (2018). MIDI Code. [ebook]. NYU. Retrieved from https://www.nyu.edu/classes/bello/FMT_files/9_MIDI_code.pdf. [Google Scholar] Chen, C. (2001). Creating melodies with evolving recurrent neural networks. [ebook]. Washington, DC: IEEE. Retrieved from http://nn.cs.utexas.edu/downloads/papers/chen.ijcnn01.pdf. [Google Scholar]
Christies.com. (2018). Is artificial intelligence set to become art’s next medium? | Christie's. [online]. Retrieved from https://www.christies.com/features/A-collaboration-between-two-artists-one-human-one-a-machi ne-9332-1.aspx. [Google Scholar]