Juncheng Li 1.3*, Shuhui Qu 2 *, Yun Wang 1 , Xinjian Li 1 , Samarjit Das 3 , Florian Metze 1 1 Carnegie Mellon University ²Stanford University 3Bosch Research Technology Center junchenl@cs.cmu.edu, shuhuiq@stanford.edu
Abstract
This paper presents a novel approach for transcribing polyphonic piano music to a symbolic form by incorporating reward rules based on classical music theory using Reinforcement Learning (RL). We use convolutional recurrent neural networks (CRNNs) to predict both the onset and the pitch of piano notes. Our RL transcriber model predicts pitch onset events and utilizes a policy gradient method that incor- porates rewards based on music theory. Our pitch prediction is conditioned on the onset of notes and also incorporates music theory based rewards. We believe that good piano music conforms to rules from classical music theory. Thus, penalized heavily according to these rules in the inference procedure, the RL transcriber can be significantly less susceptible to noises that come with the audio recordings. As a result, our technique achieved a 10% relative improvement compared with the state-of-the-art methods on the MAPS dataset [8].
1
Introduction
Piano music transcription is a historically challenging task due to its polyphonic nature. We use CRNN as the base model, suggested by [12, 26] as very effective neural architecture to detect onset events. Although it worked well for clean recordings, it would inevitably be affected by the noises in less perfect environments. Our RL Transcriber is motivated to improve the robustness of the base model against noise, and it is inspired by works [13] that successfully used the Q-learning algorithm to learn policies for sequential generation tasks [13]. Different from sequential generation tasks, our transcription system is faced with two additional major challenges: 1)handling changing size of the action space: our predicted chord can contain multiple notes. 2) assigning rewards to the sequentially generated notes requires huge efforts, and could be cumbersome to implement in practice, i.e. credit assignment problem. To address these problems, we present a framework that adopts two CRNN networks trained by REINFORCE algorithm. One network predicts whether a pitch is on or off, while the second network is used to perform the frame-wise note detection. We train the CRNN network by using REINFORCE algorithm with classical music theory based reward term on top of the original supervised loss functions, to prevent it being 'fooled' by the noise. More specifically, there is one CRNN network performs onset event detection. Conditioned on the detection of onset events, another CRNN model is used to perform the frame-wise note detection. We then apply the Monte Carlo sampling method to sample the frame-wise note from the output of the CRNN as a generated MIDI map. The generated MIDI map is then evaluated by the music theory inspired reward function. The network is then updated by the REINFORCE algorithm using the evaluation. We update the network with the original supervised loss function as well. This is effective based on the assumption that good piano musics generally follow the rules of classical music theory. We demonstrate our RL Transcriber could further improve upon the most recent state-of-the-art performance reported in [12] on MAPS dataset [8] for all 3 metrics measuring transcription quality: frame, note, and note with offset.

2
RL Transcriber Design
The  RL transcriber framework takes the raw-wave as input and output the generated MIDI map. It is consisted of four parts: 1) a feature extractor that translates the raw-wave file into the MFCC feature. 2) a CRNN based onset detector which takes in the MFCC feature and generate the probability map of onset events for the whole melody. 3) a CRNN based frame predictor that takes in the probability map of onset events, and the MFCC feature to generate the probability of the MIDI map as output. 4) a music theory module that provides feedback reward to sampled onset events and a sampled MIDI map separately. The frame predictor and onset detector are updated by the REINFORCE algorithm using the feedback reward of the music theory module. They are also updated with the supervised loss function. The overall framework is shown in Figure 1.
3
Results
We trained our RL transcriber model on the MAPS dataset as described in Section 7.1. Results from these methods are presented in Table 1. Our RL transcriber model not only produces better note-based performance, it also produces the best frame-level scores and note-based scores that include offsets. We can clearly see the improvement by using music theory based reward over other traditional methods. By including the music theory based reward, the "Note with offset", "Frame" and "Note" metrics get significant boost. This shows our hand-crafted rewards might be better at tackling notes' offset cases.
4
Future Work
Inspired by our current achievement, we will attempt to leverage existing large-scale music dataset such as the AudioSet [10] to create a new dataset that is much larger and more representative of various piano recording environments and music genres for both training and evaluation. On the other hand, injecting more realistic music theory to the reward shaping step could be a natural next step. [1] Samer Abdallah, Emmanouil Benetos, Nicolas Gold, Steven Hargreaves, Tillman Weyde, and Daniel Wolff. The digital music lab: A big data infrastructure for digital musicology. Journal on Computing and Cultural Heritage (JOCCH), 10(1):2, 2017. [2] Juan Bello. Towards the automated analysis of simple polyphonic music: A knowledge-based approach (Ph.D. Thesis). PhD thesis, Queen Mary, University of London, 2003. [3] Juan Pablo Bello, Laurent Daudet, Samer Abdallah, Chris Duxbury, Mike Davies, and Mark B Sandler. A tutorial on onset detection in music signals. IEEE Transactions on speech and audio processing , 13(5):1035–1047, 2005. [4] Nancy Bertin, Roland Badeau, and Emmanuel Vincent. Enforcing harmonicity and smoothness in bayesian non-negative matrix factorization applied to polyphonic music transcription. IEEE Transactions on Audio, Speech, and Language Processing , 18(3):538–549, 2010. [5] Tian Cheng, Simon Dixon, and Matthias Mauch.  Improving piano note tracking by hmm smoothing. In Signal Processing Conference (EUSIPCO), 2015 23rd European , pages 2009– 2013. IEEE, 2015. [6] Tian Cheng, Matthias Mauch, Emmanouil Benetos, Simon Dixon, et al. An attack decay model for piano transcription.  In ISMIR, 2016. [7] Arshia Cont. Realtime multiple pitch observation using sparse non-negative constraints. In International Symposium on Music Information Retrieval (ISMIR), pages 206–211, 2006. [8] Valentin Emiya, Nancy Bertin, Bertrand David, and Roland Badeau. Maps - a piano database for multipitch estimation and automatic transcription of music. IEEE Transactions on Audio, Speech, and Language Processing, 18:1643–1654, 07 2010. [9] Robert Gauldin. A Practical Approach to Eighteenth-Century Counterpoint. Waveland Pr Inc, 1995. [10] Jort F Gemmeke, Daniel PW Ellis, Dylan Freedman, Aren Jansen, Wade Lawrence, R Channing Moore, Manoj Plakal, and Marvin Ritter. Audio set: An ontology and human-labeled dataset for audio events.  In Acoustics, Speech and Signal Processing (ICASSP), 2017 IEEE International Conference on , pages 776–780. IEEE, 2017. [11] David Gerhard. Pitch extraction and fundamental frequency: History and current techniques. Department of Computer Science, University of Regina Regina, 2003. [12] Curtis Hawthorne, Erich Elsen, Jialin Song, Adam Roberts, Ian Simon, Colin Raffel, Jesse Engel, Sageev Oore, and Douglas Eck. Onsets and frames: Dual-objective piano transcription. arXiv preprint arXiv:1710.11153 , 2017. [13] Natasha Jaques, Shixiang Gu, Richard E Turner, and Douglas Eck. Tuning recurrent neural networks with reinforcement learning. ICLR Workshop , 2017. [14] Rainer Kelz, Matthias Dorfer, Filip Korzeniowski, Sebastian Böck, Andreas Arzt, and Gerhard Widmer.  On the potential of simple framewise approaches to piano transcription.  CoRR, abs/1612.05153, 2016. [15] Rainer Kelz and Gerhard Widmer. An experimental analysis of the entanglement problem in neural-network-based music transcription systems. arXiv preprint arXiv:1702.00025 , 2017. [16] Matija Marolt, Alenka Kavcic, and Marko Privosnik. Neural networks for note onset detection in piano music. In Proceedings of the 2002 International Computer Music Conference , 2002. [17] Keith D Martin and Youngmoo E Kim. Musical instrument identification: A pattern-recognition approach. The Journal of the Acoustical Society of America , 104(3):1768–1768, 1998. [18] Brian McFee, Colin Raffel, Dawen Liang, Daniel P. W. Ellis, Matt McVicar, Eric Battenberg, and Oriol Nieto. librosa: Audio and music signal analysis in python. 2015. [19] Juhan Nam, Jiquan Ngiam, Honglak Lee, and Malcolm Slaney. A classification-based poly- phonic piano transcription approach using learned feature representations. In ISMIR , pages 175–180, 2011. [20] Christopher Raphael. A hybrid graphical model for rhythmic parsing. Artificial Intelligence , 137(1-2):217–238, 2002. [21] Siddharth Sigtia, Emmanouil Benetos, Nicolas Boulanger-Lewandowski, Tillman Weyde, Artur S d'Avila Garcez, and Simon Dixon. A hybrid recurrent neural network for music transcription. In Acoustics, Speech and Signal Processing (ICASSP), 2015 IEEE International Conference on , pages 2061–2065. IEEE, 2015. [22] Siddharth Sigtia, Emmanouil Benetos, and Simon Dixon. An end-to-end neural network for polyphonic piano music transcription. IEEE/ACM Transactions on Audio, Speech and Language Processing (TASLP), 24(5):927–939, 2016. [23] Paris Smaragdis and Judith C Brown. Non-negative matrix factorization for polyphonic music transcription. In Applications of Signal Processing to Audio and Acoustics, 2003 IEEE Workshop on. , pages 177–180. IEEE, 2003. [24] Charlotte Truchet and Gerard Assayag. Constraint Programming in Music . ISTE Ltd and John Wiley & Sons, Inc, 2011. [25] Tuomas Virtanen. Monaural sound source separation by nonnegative matrix factorization with temporal continuity and sparseness criteria. IEEE transactions on audio, speech, and language processing, 15(3):1066–1074, 2007. [26] Qi Wang, Ruohua Zhou, and Yonghong Yan. A two-stage approach to note-level transcription of a specific piano. Applied Sciences , 7(9):901, 2017. Automatic music transcription is the task of transcribing a raw audio into a symbolic representation such as MIDI or sheet music. In this paper, we focus on the sub-task of transcribing piano music, which could be an enabling technology for a variety of applications ranging from music information retrieval to musicology study.  For instance, accurate transcription would directly enable melody, chord progression or short motif to be searchable in a tremendous scale. A trained human expert still outperforms the state-of-the-art transcription systems in accuracy, and even human experts sometimes struggle because polyphonic piano sounds are hard to capture at once.  There are several major difficulties faced by all transcription models. First, a piano note is not merely a fixed-duration sine. wave at a certain frequency, but rather a harmony that spans across the full frequency band with fluctuating energy. Moreover, each piano has a unique sound signature, so is the compound harmonic span of it, that generalization could not be made between different pianos. Also, as mentioned above, piano music is almost always polyphonic, which results in superimposition of notes in recordings and makes the colliding harmonics even a more difficult problem. Lastly, ambient noises such as background sounds, human speech or singing could severely impair the note transcription since they smear the transcription input. In our approach, we describe the transcribed piano's timbral properties with a set of rich spectral features. The energy of every piano note always decays after an onset, and thus, onset detection is widely known as a solved problem for monophonic music [16] by using peak detection algorithm in the amplitude envelope. However, for polyphonic piano music, this approach fails since the amplitude envelope does not contain information of individual frequency regions of the signal, where note onsets and offsets may coincide. Classical studies [16] also showed that implicit onset detection schemes of deducing the onset time of a note using heuristics does not perform well, so we tackle the transcriptions problem by two steps: detecting notes onset and predicting the frames. Since modern pianos have 88 keys, we can simplify the transcription problem into one of predicting a binary indicator of 88 notes for each frame throughout the time. End-to-end piano music transcription systems were usually built similarly to speech recognition systems, which typically comprise an acoustic model and a music language model. The acoustic model is used for predicting the pitch of a frame and the language model is used for correlation modeling in between a sequence of notes. The predictions of acoustic model and language model predictions are integrated by probabilistic graphical model [22]. Convolutional neural network (CNN) is believed to work most suitably for the acoustic models due to its lighter computational cost compared with fully connected DNN and also its capability to learn spacial invariant low-level features along both the time and frequency axes, which is similar to windowing operation. Recurrent neural network (RNN) is commonly used in music language models for its ability to model long term correlation. Predictions from the CNN acoustic model and RNN language model are later combined by with a graphic model that is similar to HMM; beam search is then used to decode the output. In this work, we focus on the acoustic model and do not consider the complementary language model for now. Since transcribing music is a complicated task which requires many trials and errors, and has large state space with only partial observable information, formulating the transcription problem just as supervised learning could be very limiting. We formulate the music transcription problem in the framework of RL to allow machine to augment human analysts and domain experts by optimizing operational efficiency and providing decision support. In RL, let A be a set of action sequences, and p θ ( a ) be a distribution over action a ∈ A which is parameterized by θ . The objective of the REINFORCE algorithm is as following:
where r(a) is the reward signal assigned to each possible action sequence (note transcription), and J(θ) is the expected reward under the distribution of possible action sequences. Here, our action sequence is assigning values to each note. The gradient of the objective J is as following:
Due to the high-dimensional sequential action space, the optimization problem is non-trivial. We thus approximate the gradient by sampling. We sample the overall note transcription a k from ρ θ ( α ). We can calculate the reward function of α k . The approximate gradient is then computed by averaging the gradient of K sampled actions.
To reduce the variance of the gradient estimate, we introduce a baseline reward b. The gradient function is as following:
In general, REINFORCE algorithm learns model parameters θ according to this approximate gradient. The log-probability of actions that lead to high reward are increased, and those lead to low reward are decreased. Automatic music transcription (AMT) is a task to transcribe the music audio signal into some form of music notation such as sheet music and MIDI file. Automatic music transcription have several typical sub-tasks such as pitch detection [11], instrument identification [17], rhythm parsing [20] and onset detection [3]. There are multiple applications that use AMT as an underlying component such as music information retrieval [1] and musicology analysis [2]. While monophonic AMT is considered a solved task, polyphonic AMT still remains open because multiple notes overlap in both time domain and frequency domain. Traditionally, AMT exploits Non-negative Matrix Factorization (NMF) to decompose music audio into known pitch templates of an instrument [23]. Multiple constraints such as sparseness [7] and temporal continuity [25] and harmony [4] were shown to improve the transcription quality. Additionally, exploiting instrument specific features also proved to be helpful.  In the case of piano transcription, models of various note stages:  Attack, Decay, Sustain, and Release leads to improvement of the transcription [6] [5]. In recent years, with promising progress in deep learning models, AMT community also tries to propose approaches with deep neural network to tackle the task. For example, Nam proposed a model to use deep belief network to learn representations from spectrum [19]. Sigtia Using RNN as music language model to predict next note [21]. Keltz investigated a glass ceiling problem with convolutional neural network [15]. Most of those works, however, treated the AMT task as a single stack neural network problem, for which a single neural network would generate all necessary music information such as onset, offset and pitch. In contrast to these models, researchers recently proposed a new model to predict onsets and frames with two stacks of neural networks [12]. One stack is to predict onsets, and the other is to classify labels for each frame.  As a result, the accuracy of frame classification was improved by conditioning the onset results. Analogous to this work, explicit modeling of onset classification have also been proven to be useful with NMF [6] and CNN [26]. One known issue for generating long-step sequences in such a supervised learning method is that it fails to generate a globally coherent structure. This had caused the character RNN to fail to generate sentences with a coherent topic and note RNN to generate coherent melodies. One approach to tackle this problem in note RNN was to adding some other criterion to evaluate if the generated melodies sounds nice. One prior work  [13] formulate the music generation task as a reinforcement learning task to learn a coherent structure by using music theory. Instead of optimizing the probability of next note directly with supervised learning, they proposed a reward neural network that sequentially generate a note value for each frame. However, in practice, most melodies have multiple notes in one frame, as well as harmonic span. To tackle these problems, in this work, we proposes a framework with two CRNN networks and exploits the reinforcement learning with the music theory reward. Our RL transcriber's frame prediction draw inspiration from [12]. For spectral feature extraction, we use librosa [18] to compute the log mel-spectrum. We adopted the parameters suggested in [14], and used a filter-bank with 48 bins per octave on the input raw audio which results in 229 logarithmically-spaced frequency bins with a hop length of 512. Our FFT window size is 2048, and we sampled at 16kHz. We build both our onset detector and frame in a CRNN architecture.  We feed the CNN with a sequence of instead of a single frame and then feed the output of the convolution layers to the RNN layer as input. This architecture is sketched in Fig. 1. Our onset detector's CRNN follows the CNN architecture in [14], which is followed by a bidirectional LSTM with 128 units in both forward and backward directions. The prediction is done by a fully connected sigmoid layer with 88 outputs which represent the probability of an onset for each piano key. The threshold is set at 0.5 for the sigmoid layer. The separate frame activation detector uses the same CRNN architecture as above, but it takes the onset detector's output and feed it into the activation detector's bi-directional LSTM layer. The activation detector also uses a fully connected sigmoid layer with 88 outputs to predict whether the frame is on or off. Training with the REINFORCE algorithm requires a well-designed reward function. We designed two different rewards to facilitate the learning process:1) metrics driven reward and 2) music theory reward. Our goal is to learn policies that could transcribe notes with high evaluation Metrics driven reward performance. In essence, the metrics- driven reward is the F1 score on which both the model's frames and onsets will be evaluated on. Applying this reward enables the model to directly optimize the evaluation metrics.
where ˆ γ = fo(x) is the output vector (logits) of the network, ˆ γ is the onset note and frame note prediction sampled from ŷ , and y the ground truth of notes. Music theory reward    In practice, we do not want the transcription to only optimize toward the evaluation metrics, but also to generate pleasant-sounding transcribed notes that follow rules of basic music theory. Thus, we further develop several music rules based on the principles stated on page 42 of A Practical Approach to Eighteenth-Century Counterpoint [9] and the principles stated in Constraint Programming in Music [24]. Specifically we have 7 rules in total and designed rewards accordingly: Tduration( a ): Note duration may only change slowly across a voice, neighbouring notes are either of equal length or differ by 50% at maximum. Notes that don't follow the rule would be penalized by -0.0001. • T start-end( α ): The first and last note of the entire piece must start and end with the root chord c. Notes that don't follow the rule would be penalized by -0.01. • Tpitch(a) : The maximum and minimum pitch in a phrase occurs exactly once and it is not the first or last note of the phrase. Here we consider half of a melody a phrase. Notes in a phrase that don't follow the pitch rule would be penalized by -0.0001. • Tkey( a ): All notes should belong to the same key. e.g. If the key is C-major, notes in the piece should all be middle C. Notes that don't follow the rule would be penalized by -0.001. • Trepeat( a ): Unless a note is held, a single tone should not be repeated more than four times in a row. Repeating notes that are more than 5 times get a penalty of -0.00001. • T correlate( α ): We penalize the model by -0.01 if the auto-correlation coefficient is greater than .15. • Tinterval( a ): Good music should move by a mixture of small steps and larger harmonic intervals, large leaps more than a fifth receives negative rewards of 0.001. From our experience, the music theory might be too specific or restrictive in some cases and might cause the result to fluctuate; the system stability is also very sensitive to the hand crafted penalty amount. The numbers we report here are from the best empirical results that we have acquired.
The combination of reward is as following: r(a) = γ r onseLf1 ( ˆ γ ) + γ r frame,f1 (ˆ γ ) + δι where γ and δ are the weight parameter of the reward function.
Given the probability of the midi map of the frame Q f , we sample a set of MIDI map A = { α 1 , α 2 , ..., α K } from the probability of midi map, where each sample a ～ Q f , M ∈ 0 , 1 c t , where 0 denotes off and 1 denotes on. The generated midi map a is then evaluated by the reward module r . Given the P(a|Q f ) and r(a) . The loss function is as follow:
Meanwhile, we also update the parameter by a supervised loss function. The basic loss function for our RL transcriber are the binary cross-entropy applied framewise and element-wise:
where ˆ y t is the output vector of the network at time t , and  y t the ground truth at time t . Thus, the overall objective function is as following:
During inference, we simply use the threshold of 0.5. During inference, the frame predictor does not start unless the onset predictor predicts positive. We use the MAPS dataset[8] which contains 31 GB of CD-quality recordings and corresponding annotations of isolated notes, chords, and complete piano pieces. Full piano pieces in the dataset consist of both pieces rendered by software synthesizers and recordings of pieces played on a Yamaha Disklavier player piano.  We use the set of synthesized pieces (the MUS set: "pieces of piano music"[8]) as the training split and the set of pieces played on the Disklavier as the test split, as proposed in [12] because we often do not have the admission to the actual recording in the real-world testing environment. When constructing these datasets, we carefully ensure that training set does not mix with testing set. We do not include the the Disklavier recordings, individual notes, or chords in the training set. Since that we often do not have the admission to the actual recording in the real-world testing environment. It is also more realistic to test on the Disklavier recordings because it is more interesting to transcribe the music played on real musical instruments. We trained our RL transcriber model on the MAPS dataset with processing process described in Section 7.1 using the Adam optimizer, a batch size of 8, a learning rate of 0.0006, and a gradient clipping L2-norm of 3. The same hyper-parameters were used to train all models, including those in the ablation study to ensure evaluation consistency. We compare three different reward combinations for implementing our RL transcriber : ● The reward weight for metrics driven reward is γ = 0.02 ● The reward weight for music theory reward is δ = 0.5 ● The reward weight for metrics driven reward is γ = 0.015, music theory reward is δ = 0.3.
We also re-implement the model described in "onset of frame"[12], Sigtia [22], and Kelz [14] using their default hyperparameters. We compare our method to the performance of these approaches to ensure evaluation consistency. The metrics used to evaluate a model are frame-level, note-level, and note-level with offset metrics including precision, recall, and F1 score. We use the MIR eval library to calculate note-based precision, recall, and F1 scores. The note-level metrics requires that onsets be within ±50ms of ground truth but ignoring offsets. The note-level with offset metrics further requires offsets resulting in note durations within 20% of the ground truth. Frame-based scores are calculated using the standard metrics as defined in [12]. Both frame and note scores are calculated per piece and the mean of these per-piece scores is presented as the final metric for a given collection of pieces. Results from these methods are presented in Table 1. Our RL transcriber model not only produces better note-based performance, it also produces the best frame-level scores and note-based scores that include offsets. We can clearly see the improvement by using music theory based reward over the metrics driven reward and other traditional methods. The model with metrics driven reward only have a high precision score while the recall is slightly below the performance of the "onset and frame" method. The overall F1 score of the model is slightly improved by providing with metrics driven reward than the onset and frame method. By including the music theory based reward, while we don't see major improvement on the "Frame" or "Note" metric, we can see the "Note with offset" metric gets significant boost. This shows our hand crafted rewards might be better at tackling notes' offset cases. To understand the individual importance of each piece in our model, we conduct an ablation study. We consider using different combination of reward function, and training with or without baseline: ● we set γ = 0.1, δ = 0.0, and train REINFORCE with baseline, ● γ = 0.02, δ = 0, w/ baseline; γ = 0.1, δ = 0, w/o baseline; ● γ = 0.02, δ = 0, w/o baseline; γ = 0, δ = 0.5, w/ baseline; γ = 0, δ = 0.3, w/ baseline; ● γ = 0, δ = 0.5, w/o baseline; ● γ = 0, δ = 0.3, w/o baseline; ● γ = 0.015, δ = 0.3, w/ baseline; ● γ = 0.015, δ = 0.3, w/o baseline;
These result shows the importance of each component of the reward function. Adding minimum metrics driven reward results in the improvement of in both note and note with offset score while maintaining the frame score. Adding music theory driven rewards did not improve Frame or Note performance as expected, this might be due to the fact that the baseline accuracy is already high, and handcrafted rewards might be biased towards only limited musical phenomenon. While we do see the NoteWithOffset metric was improved by the music theory reward with a good margin. This indicates that our handcrafted rewards is effective at detecting the offset of notes. Training the model using REINFORCE with baseline improves the final score by 8%. To our ears, the perceptual decrease in audio quality is best tracked by using both metric driven reward and music theory reward.