# Generating Music with Data: Application of Deep Learning Models for Symbolic Music Composition
## 2 Materials and Methods
### Data
#### 2.1.2 Data Wrangling  
Data wrangling techniques were also applied to refine the data in order to optimize processing and maximize model assertiveness. The MIDI file pre-processing approach for music generation implemented by [PERSON] et al. [9] and later replicated by [PERSON] et al. [10] aims to transform MIDI musical elements into a sequence of tokens, which, in turn, form the vocabulary of the problem. This vocabulary consists of the following:  
* A total of 128 possible types of **note_on** events representing the start of a note with one of 128 possible MIDI tones. * A total of 128 possible types of **note_off** events that represent the ending of a note with one of 128 possible MIDI tones. * A total of 32 possible types of intensity events defined as **velocity**. The pitch precedes a **note_on** event, thus defining the pitch dynamics of the future note. * A total of 100 possible types of **time_shift** events, representing a temporal shift in sets of 10 ms increments, having a temporal possibility space between 1 (10 ms) and 100 (1 s). * A **piece_start** token as the starting token of each sequence, symbolizing the beginning of the performance. * A **piece_end** token as the final token of each sequence, symbolizing the end of the performance. Figure 1 illustrates the translation of a C major scale into tokens derived from the defined musical language vocabulary. The sum of all elements made up a vocabulary of 390 tokens. It is worth mentioning that the last two transformations (adding **piece_start** and **piece_end** tokens) were inspired by the work of [PERSON] [11]. It is also interesting to detail the approaches adopted in the elements of \"velocity\" (intensity) and time shift. Intensity Quantization  
The intensity (\"velocity\") of a note is perceived as how loud or soft the note must be articulated. The common notation adopted in classical music has 8 levels of dynamic marking, ranging from _ppp_ (pianissimo) to _ffff_ (fortissimo). However, the intensity component of the MIDI protocol has 128 levels of variation, ranging from 0 to 127. The strategy adopted by [PERSON] et al. [9] and later replicated by [PERSON] et al. [12] was to quantize the 128 possible MIDI intensity levels into 32 \"bins\". Considering that the original classical music notation has 8 levels of variation, 32 levels would be enough to reduce the sparsity of the model, leading to the intensity component being represented within a smaller space. Quantization of Time Shifts  
Time shift events are calculated as the difference between the temporal distance from the end of a note to the beginning of the next note in the sequence. The time difference calculation in its raw form takes place in a continuous space at the microsecond level. Thus,  
Figure 1: Plot of a C major scale followed by its tokenized sequence. Note: On the left, we visualize the performance of a scale in C major in a two-dimensional plot of note (pitch) as a function of time (piano roll). On the right, we can see the token representation of this performance. tokenizing the difference of all temporal possibilities would leave the model calculation unnecessarily sparse since, as noted by [PERSON] and [PERSON] [13], the perceptible difference in the temporal displacement of a single tone in a sequence was not less than approximately 10 ms in average. Because of this, to reduce the scope of temporal possibilities, each temporal displacement between one note and another was quantized in a range from 1 (10 ms) to 100 (1 s) in 10 ms increments. As a result, we obtained the space continuum quantization of the temporal displacement in a discrete space of 100 possibilities. It is also noteworthy that the duration of the note was extended, referring to the fact that the piano pedal was considered in the total duration of the note. Dataset Processing and Technologies Used  
The tokenization process takes place in the entire augmented training and validation dataset, with a text file containing the concatenation of sequences of tokens as output.