An AI for Music Generation
It has been shown recently that convolutional generative adversarial networks (GANs) are able to capture the temporal-pitch patterns in music using the piano-roll representation, which represents music by binary-valued time-pitch matrices. However, existing models can only generate real-valued piano-rolls and require further post-processing (e.g. hard thresholding, Bernoulli sampling) at test time to obtain the final binary-valued results. In this work, we first investigate how the real-valued predictions generated by the generator may lead to difficulties in training the discriminator. To overcome the binarization issue, we propose to append to the generator an additional refiner network, which uses binary neurons at the output layer. The whole network can be trained in a two-stage training setting: the generator and the discriminator are pretrained in the first stage; the refiner network is then trained along with the discriminator in the second stage to refine the real-valued piano-rolls generated by the pretrained generator to binary-valued ones. The proposed model is able to directly generate binary-valued piano-rolls at test time. Experimental results show improvements to the existing models in most of the evaluation metrics. All source code, training data and audio samples can be found at https://salu133445.github.io/bmusegan/ .READ FULL TEXT VIEW PDF
We propose the BinaryGAN, a novel generative adversarial network (GAN) t...
Latest Generative Adversarial Networks (GANs) are gathering outstanding
Recent improvements in generative adversarial network (GAN) training
Thanks to their remarkable generative capabilities, GANs have gained gre...
Generative Adversarial Networks (GANs) are a powerful framework for deep...
Two recently introduced criteria for estimation of generative models are...
In a recent paper, we have presented a generative adversarial network
An AI for Music Generation
Code for “Convolutional Generative Adversarial Networks with Binary Neurons for Polyphonic Music Generation”
Recent years have seen increasing research on symbolic-domain music generation and composition using deep neural networks. Notable progress has been made to generate monophonic melodies [25, 27], lead sheets (i.e., melody and chords) [11, 8, 26], or four-part chorales . To add something new to the table and to increase the polyphony and the number of instruments of the generated music, we attempt to generate piano-rolls in this paper, a music representation that is more general (e.g., comparing to leadsheets) yet less studied in recent work on music generation. As fig:training_data shows, we can consider an -track piano-roll as a collection of binary time-pitch matrices indicating the presence of pitches per time step for each track.
Generating piano-rolls is challenging because of the large number of possible active notes per time step and the involvement of multiple instruments. Unlike a melody or a chord progression, which can be viewed as a sequence of note/chord events and be modeled by a recurrent neural network (RNN)[21, 24]
, the musical texture in a piano-roll is much more complicated (see fig:training_data). While RNNs are good at learning the temporal dependency of music, convolutional neural networks (CNNs) are usually considered better at learning local patterns.
For this reason, in our previous work , we used a convolutional generative adversarial network (GAN)  to learn to generate piano-rolls of five tracks. We showed that the model generates music that exhibit drum patterns and plausible note events. However, musically the generated result is still far from satisfying to human ears, scoring around on average on a five-level Likert scale in overall quality in a user study .111Another related work on generating piano-rolls, as presented by Boulanger-Lewandowski et al.  , replaced the output layer of an RNN with conditional restricted Boltzmann machines (RBMs) to model high-dimensional sequences and applied the model to generate piano-rolls sequentially (i.e. one time step after another).
, replaced the output layer of an RNN with conditional restricted Boltzmann machines (RBMs) to model high-dimensional sequences and applied the model to generate piano-rolls sequentially (i.e. one time step after another).
There are several ways to improve upon this prior work. The major topic we are interested in is the introduction of the binary neurons (BNs) [1, 4] to the model. We note that conventional CNN designs, also the one adopted in our previous work , can only generate real-valued predictions and require further postprocessing at test time to obtain the final binary-valued piano-rolls.222Such binarization is typically not needed for an RNN or an RBM in polyphonic music generation, since an RNN is usually used to predict pre-defined note events  and an RBM is often used with binary visible and hidden units and sampled by Gibbs sampling [6, 20]. This can be done by either applying a hard threshold (HT) on the real-valued predictions to binarize them (which was done in 
), or by treating the real-valued predictions as probabilities and performingBernoulli sampling (BS).
However, we note that such naïve methods for binarizing a piano-roll can easily lead to overly-fragmented notes. For HT, this happens when the original real-valued piano-roll has many entries with values close to the threshold. For BS, even an entry with low probability can take the value 1, due to the stochastic nature of probabilistic sampling.
The use of BNs can mitigate the aforementioned issue, since the binarization is part of the training process. Moreover, it has two potential benefits:
In , binarization of the output of the generator in GAN is done only at test time not at training time (see sec:gan for a brief introduction of GAN). This makes it easy for the discriminator in GAN to distinguish between the generated piano-rolls (which are real-valued in this case) and the real piano-rolls (which are binary). With BNs, the binarization is done at training time as well, so can focus on extracting musically relevant features.
Due to BNs, the input to the discriminator in GAN at training time is binary instead of real-valued. This effectively reduces the model space from to , where is the product of the number of time steps and the number of possible pitches. Training may be easier as the model space is substantially smaller, as fig:theory illustrates.
Specifically, we propose to append to the end of a refiner network that uses either deterministic BNs (DBNs) or stocahstic BNs (SBNs) at the output layer. In this way, makes real-valued predictions and binarizes them. We train the whole network in two stages: in the first stage we pretrain and and then fix ; in the second stage, we train and fine-tune . We use residual blocks  in to make this two-stage training feasible (see Section 3.3).
As minor contributions, we use a new shared/private design of and that cannot be found in . Moreover, we add to two streams of layers that provide onset/offset and chroma information (see Sections 3.2 and 3.4).
The proposed model is able to directly generate binary-valued piano-rolls at test time. Our analysis shows that the generated results of our model with DBNs features fewer overly-fragmented notes as compared with the result of using HT or BS. Experimental results also show the effectiveness of the proposed two-stage training strategy compared to either a joint or an end-to-end training strategy.
A generative adversarial network (GAN)  has two core components: a generator and a discriminator
. The former takes as input a random vectorsampled from a prior distribution and generates a fake sample . takes as input either real data or fake data generated by . During training time, learns to distinguish the fake samples from the real ones, whereas learns to fool .
An alternative form called WGAN was later proposed with the intuition to estimate the Wasserstein distance between the real and the model distributions by a deep neural network and use it as a critic for the generator. The objective function for WGAN can be formulated as:
where denotes the real data distribution. In order to enforce Lipschitz constraints on the discriminator, which is required in the training of WGAN, Gulrajani et al.  proposed to add to the objective function of a gradient penalty (GP) term: , where is defined as sampling uniformly along straight lines between pairs of points sampled from and the model distribution . Empirically they found it stabilizes the training and alleviates the mode collapse issue, compared to the weight clipping strategy used in the original WGAN. Hence, we employ WGAN-GP  as our generative framework.
Binary neurons (BNs) are neurons that output binary-valued predictions. In this work, we consider two types of BNs: deterministic binary neurons (DBNs) and stochastic binary neurons (SBNs). DBNs act like neurons with hard thresholding
functions as their activation functions. We define the output of a DBN for a real-valued inputas:
where denotes the unit step function and
is the logistic sigmoid function. SBNs, in contrast, binarize an inputaccording to a probability, defined as:
denotes a uniform distribution.
Computing the exact gradients for either DBNs or SBNs, however, is intractable. For SBNs, it requires the computation of the average loss over all possible binary samplings of all the SBNs, which is exponential in the total number of SBNs. For DBNs, the threshold function in Eq. (2
) is non-differentiable. Therefore, the flow of backpropagation used to train parameters of the network would be blocked.
A few solutions have been proposed to address this issue [1, 4]. One strategy is to replace the non-differentiable functions, which are used in the forward pass, by differentiable functions (usually called the estimators) in the backward pass. An example is the straight-through (ST) estimator proposed by Hinton . In the backward pass, ST simply treats BNs as identify functions and ignores their gradients. A variant of the ST estimator is the sigmoid-adjusted ST estimator , which multiplies the gradients in the backward pass by the derivative of the sigmoid function. Such estimators were originally proposed as regularizers  and later found promising for conditional computation . We use the sigmoid-adjusted ST estimator in training neural networks with BNs and found it empirically works well for our generation task as well.
Following , we use the multi-track piano-roll representation. A multi-track piano-roll is defined as a set of piano-rolls for different tracks (or instruments). Each piano-roll is a binary-valued score-like matrix, where its vertical and horizontal axes represent note pitch and time, respectively. The values indicate the presence of notes over different time steps. For the temporal axis, we discard the tempo information and therefore every beat has the same length regardless of tempo.
As fig:generator shows, the generator consists of a “s”hared network followed by “p”rivate network , , one for each track. The shared generator first produces a high-level representation of the output musical segments that is shared by all the tracks. Each private generator then turns such abstraction into the final piano-roll output for the corresponding track. The intuition is that different tracks have their own musical properties (e.g., textures, common-used patterns), while jointly they follow a common, high-level musical idea. The design is different from  in that the latter does not include a shared in early layers.
|Dr. [10pt]Pi. [10pt]Gu. [10pt]Ba. [10pt]En. [4pt]|
|(a) raw predictions||(b) pretrained (+BS)||(c) pretrained (+HT)||(d) proposed (+SBNs)||(d) proposed (+DBNs)|
The refiner is composed of private networks , , again one for each track. The refiner aims to refine the real-valued outputs of the generator, , into binary ones, , rather than learning a new mapping from to the data space. Hence, we draw inspiration from residual learning and propose to construct the refiner with a number of residual units , as shown in fig:refiner. The output layer (i.e. the final layer) of the refiner is made up of either DBNs or SBNs.
Similar to the generator, the discriminator consists of private network , , one for each track, followed by a shared network , as shown in fig:discriminator. Each private network first extracts low-level features from the corresponding track of the input piano-roll. Their outputs are concatenated and sent to the shared network to extract higher-level abstraction shared by all the tracks. The design differs from  in that only one (shared) discriminator was used in  to evaluate all the tracks collectively. We intend to evaluate such a new shared/private design in sec:discriminator_design_exp.
As a minor contribution, to help the discriminator extract musically-relevant features, we propose to add to the discriminator two more streams, shown in the lower half of fig:discriminator. In the first onset/offset stream, the differences between adjacent elements in the piano-roll along the time axis are first computed, and then the resulting matrix is summed along the pitch axis, which is finally fed to .
In the second chroma stream, the piano-roll is viewed as a sequence of one-beat-long frames. A chroma vector is then computed for each frame and jointly form a matrix, which is then be fed to . Note that all the operations involved in computing the chroma and onset/offset features are differentiable, and thereby we can still train the whole network by backpropagation.
Finally, the features extracted from the three streams are concatenated and fed toto make the final prediction.
We propose to train the model in a two-stage manner: and are pretrained in the first stage; is then trained along with (fixing ) in the second stage. Other training strategies are discussed and compared in Section 4.4.
The Lakh Pianoroll Dataset (LPD) 333https://salu133445.github.io/lakh-pianoroll-dataset/ contains 174,154 multi-track piano-rolls derived from the MIDI files in the Lakh MIDI Dataset (LMD) .444http://colinraffel.com/projects/lmd/ In this paper, we use a cleansed subset (LPD-cleansed) as the training data, which contains 21,425 multi-track piano-rolls that are in 4/4 time and have been matched to distinct entries in Million Song Dataset (MSD) . To make the training data cleaner, we consider only songs with an alternative tag. We randomly pick six four-bar phrases from each song, which leads to the final training set of 13,746 phrases from 2,291 songs.
We set the temporal resolution to 24 time steps per beat to cover common temporal patterns such as triplets and 32th notes. An additional one-time-step-long pause is added between two consecutive (i.e. without a pause) notes of the same pitch to distinguish them from one single note. The note pitch has 84 possibilities, from C1 to B7.
We categorize all instruments into drums and sixteen instrument families according to the specification of General MIDI Level 1.555https://www.midi.org/specifications/item/gm-level-1-sound-set We discard the less popular instrument families in LPD and use the following eight tracks: Drums, Piano, Guitar, Bass, Ensemble, Reed, Synth Lead and Synth Pad
. Hence, the size of the target output tensor is(bar) (time step) (pitch) (track).
(Underlined and bold font indicate respectively the top and top-three entries with values closest to those shown in the ‘training data’ column.)
Both and are implemented as deep CNNs (see Appendix A for the detailed network architectures). The length of the input random vector is . consists of two residual units  shown in fig:resblock. Following , we use the Adam optimizer 
and only apply batch normalization toand . We apply the slope annealing trick  to networks with BNs, where the slope of the sigmoid function in the sigmoid-adjusted ST estimator is multiplied by
after each epoch. The batch size isexcept for the first stage in the two-stage training setting, where the batch size is .
We generate 800 samples for each model (see Appendix C for sample generated results) and use the following metrics proposed in  for evaluation. We consider a model better if the average metric values of the generated samples are closer to those computed from the training data.
Qualified note rate (QN) computes the ratio of the number of the qualified notes (notes no shorter than three time steps, i.e., a 32th note) to the total number of notes. Low QN implies overly-fragmented music.
Polyphonicity (PP) is defined as the ratio of the number of time steps where more than two pitches are played to the total number of time steps.
Tonal distance (TD) measures the distance between the chroma features (one for each beat) of a pair of tracks in the tonal space proposed in . In what follows, we only report the TD between the piano and the guitar, for they are the two most used tracks.
We compare the proposed model with two common test-time binarization strategies: Bernoulli sampling (BS) and hard thresholding (HT). Some qualitative results are provided in Figures 7 and 8. Moreover, we present in tab:score a quantitative comparison among them.
Both qualitative and quantitative results show that the two test-time binarization strategies can lead to overly-fragmented piano-rolls (see the “pretrained” ones). The proposed model with DBNs is able to generate piano-rolls with a relatively small number of overly-fragmented notes (a QN of ; see tab:score) and to better capture the statistical properties of the training data in terms of PP. However, the proposed model with SBNs produces a number of random-noise-like artifacts in the generated piano-rolls, as can be seen in fig:closeup(d), leading to a low QN of . We attribute to the stochastic nature of SBNs. Moreover, we can also see from fig:exp1 that only the proposed model with DBNs keeps improving after the second-stage training starts in terms of QN and PP.
We consider two alternative training strategies:
joint: pretrain and in the first stage, and then train and (like viewing as part of ) jointly with in the second stage.
end-to-end: train , and jointly in one stage.
As shown in tab:score, the models with DBNs trained using the joint and end-to-end training strategies receive lower scores as compared to the two-stage training strategy in terms of QN and PP. We can also see from fig:exp1(a) that the model with DBNs trained using the joint training strategy starts to degenerate in terms of QN at about 10,000 steps after the second-stage training begins.
fig:end2end shows some qualitative results for the end-to-end
models. It seems that the models learn the proper pitch ranges for different tracks. We also see some chord-like patterns in the generated piano-rolls. From tab:score and fig:end2end, in the end-to-end training setting SBNs are not inferior to DBNs, unlike the case in the two-stage training. Although the generated results appear preliminary, to our best knowledge this represents the first attempt to generate such high dimensional data with BNs from scratch (see remarks in AppendixD).
We compare the proposed model with two ablated versions: the ablated-I model, which removes the onset/offset and chroma streams, and the ablated-II model, which uses only a shared discriminator without the shared/private and multi-stream design (i.e., the one adopted in ).666The number of parameters for the proposed, ablated-I and ablated-II models is 3.7M, 3.4M and 4.6M, respectively. Note that the comparison is done by applying either BS or HT (not BNs) to the first-stage pretrained models.
As shown in tab:score, the proposed model (see “pretrained”) outperforms the two ablated versions in all three metrics. A lower QN for the proposed model as compared to the ablated-I model suggests that the onset/offset stream can alleviate the overly-fragmented note problem. Lower TD for the proposed and ablated-I models as compared to the ablated-II model indicates that the shared/private design better capture the intertrack harmonicity. fig:exp2 also shows that the proposed and ablated-I models learn faster and better than the ablated-II model in terms of QN.
Finally, we conduct a user study involving 20 participants recruited from the Internet. In each trial, each subject is asked to compare two pieces of four-bar music generated from scratch by the proposed model using SBNs and DBNs, and vote for the better one in four measures. There are five trials in total per subject. We report in tab:userstudy the ratio of votes each model receives. The results show a preference to DBNs for the proposed model.
|with SBNs||with DBNs|
*We asked, “Are there many overly-fragmented notes?”
We have presented a novel convolutional GAN-based model for generating binary-valued piano-rolls by using binary neurons at the output layer of the generator. We trained the model on an eight-track piano-roll dataset. Analysis showed that the generated results of our model with deterministic binary neurons features fewer overly-fragmented notes as compared with existing methods. Though the generated results appear preliminary and lack musicality, we showed the potential of adopting binary neurons in a music generation system.
In future work, we plan to further explore the end-to-end models and add recurrent layers to the temporal model. It might also be interesting to use BNs for music transcription , where the desired outputs are also binary-valued.
Binary stochastic neurons in tensorflow, 2016.Blog post on R2RT blog. [Online] https://r2rt.com/binary-stochastic-neurons-in-tensorflow.html.
Neural networks for machine learning—using noise as a regularizer (lecture 9c), 2012.Coursera, video lectures. [Online] https://www.coursera.org/lecture/neural-networks/using-noise-as-a-regularizer-7-min-wbw7b.
Music transcription modelling and composition using deep learning.In Proc. CSMS, 2016.
We show in app:tab:arch the network architectures for the generator , the discriminator , the onset/offset feature extractor , the chroma feature extractor and the discriminator for the ablated-II model.
app:fig:sample_train shows some sample eight-track piano-rolls seen in the training data.
After several trials, we found that the claim in the main text that an end-to-end training strategy cannot work well is not true with the following modifications to the network. However, a thorough analysis of the end-to-end models are beyond the scope of this paper.
remove the refiner network ()
use binary neurons (either DBNs or SBNs) in the last layer of the generator ()
reduce the temporal resolution by half to time steps per beat
use five-track (Drums, Piano, Guitar, Bass and Ensemble) piano-rolls as the training data
We show in app:fig:sample_end2end some sample five-track piano-rolls generated by the modified end-to-end models with DBNs and SBNs.
|reshape to channels|
|substream I||substream II|
|concatenate along the channel axis|
|stack along the track axis|
|split along the track axis||
|substream I||substream II|
|concatenate along the channel axis|
|concatenate along the channel axis|
|concatenate along the channel axis|
), the values represent (from left to right): the number of filters, the kernel size and the strides. For the dense layers (dense), the value represents the number of nodes. Each transposed convolutional layer in is followed by a batch normalization layer and then activated by ReLUs except for the last layer, which is activated by sigmoid functions. The convolutional layers in are activated by LeakyReLUs except for the last layer, which has no activation function.