A method for automatic notation of piano polyphonic music based on multi-task learning based on local attention
By introducing efficient relative position coding and adaptive attention range into the Transformer network, the problems of high computational complexity and poor notation flexibility in the existing technology are solved, and more efficient automatic piano notation performance is achieved.
Patent Information
- Application Number
- CN202310557794.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-05-18
- Publication Date
- 2024-09-20
- Estimated Expiration
- 2043-05-18
AI Technical Summary
The existing automatic piano notation method based on Transformer network has high computational space complexity, which limits the flexibility of notation length, and absolute position encoding causes the model to pay attention to short-term changes in attack and stop frame information.
Use an efficient relative position encoding method to improve the Transformer network, combine matrix reshaping, zero padding and slicing operations to reduce computational complexity, and use a learnable adaptive relative position attention range to improve the model's ability to deal with short-term dependencies. Attention.
It improves the flexibility and calculation efficiency of automatic notation, enhances the estimation ability of attack and stop targets, reduces the computational space complexity, enables the model to process audio of any length, and significantly improves the calculation speed and notation performance.
Smart Images

Figure CN116665704B
Abstract
Description
Technical Field
[0001] The present invention is based on deep learning technology and studies a method for automatic notation of piano polyphonic music based on multi-task learning. First, the CNN network is used to extract the deep features required for multiple note attribute targets in the music time-frequency spectrum; then, in the attack and stop estimation branch, the Transformer network is used to model the short-term local time-varying features of the notes to obtain the attack and stop time estimates of the notes; in the frame level and note intensity estimation branch, the GRU network is used to model the long-term global evolution features of the notes to obtain the note intensity size estimate, and the GRU network is used to fuse the attack and stop time estimates to obtain the frame level estimate of the notes; finally, the threshold division and note event integration post-processing method are used to integrate the network output into a complete notation result. The technology of the present invention belongs to the field of computer hearing, and specifically relates to deep learning, automatic music notation and other technologies. Background Art
[0002] Automatic Music Transcription (AMT) is one of the key technologies for music information retrieval. It can be roughly regarded as making computers "understand" music. Specifically, the goal of automatic music notation is to use computers to automatically realize the processing process from music audio signals to music symbol representation by designing a certain signal processing algorithm. Automatic music notation includes multiple subtasks, such as multi-pitch estimation (MPE), note start and stop detection, instrument identification and melody tracking. At present, the cost of manual music notation is high, and it can only be done by trained music professionals. It is necessary to listen to the recorded notes repeatedly to confirm the content. The notation process is complicated, mechanical and repetitive, and requires a lot of time and energy. The emergence of automatic music notation will greatly simplify and improve this process. In addition, automatic music notation itself has a wide range of economic and social application value. A large number of music information retrieval tasks can benefit from this automated music "understanding" process, such as chord search, score tracking, music theme classification, automatic music generation, music teaching, music-assisted creation, music copyright protection, and musicology research.
[0003] Conducting targeted research on piano as a typical instrument for polyphonic music notation is a key breakthrough in solving various difficulties of this technology. Recently, with the rapid development of deep learning technology, deep neural networks have shown great advantages in frame-level and note-level notation tasks. Among them, the more mature ones are automatic notation methods based on multi-task learning. This type of method uses the time-frequency spectrum of polyphonic piano music as the input of the deep neural network, and uses multiple deep neural network acoustic models to model the multiple attributes of the notes to be estimated, and estimates multiple note attribute outputs at the same time. Finally, the note integration post-processing method is used to obtain the complete notation result. In addition, among the automatic notation methods using deep neural networks, the implementation method based on the Transformer network has achieved the latest results. However, compared with other network structures, the automatic notation system based on the original Transformer network has higher requirements for computational space complexity; and this method uses absolute position encoding with fixed encoding length, which limits the flexibility of notation length; in addition, the attention mechanism based on the absolute position encoding method causes the model to pay attention to all audio frames uniformly, confusing the attention to the short-term changing start and stop frame information. In summary, there is an urgent need to solve the problems related to the existing Transformer network-based notation method and improve the performance of this framework in the automatic piano notation task. Summary of the invention
[0004] Using an efficient relative position encoding method, a Transformer network is embedded in the multi-task learning framework, and a multi-task learning piano polyphonic music automatic notation system based on local attention is proposed. The system consists of the following deep neural networks:
[0005] (1) CNN-Transformer feature extraction network
[0006] For local short-term time-varying note onset and pause targets, we first use the CNN network to extract features in the time-spectrum graph, and then use the improved Transformer network to model the temporal information of the deep features in the CNN network. The structural diagram of the Transformer network is shown in the attached figure. Figure 2 As shown in the figure, the local relative position encoding method is used in the improved Transformer network. In order to save computing space, matrix reshaping, zero padding and slicing operations are used to replace the original direct matrix operation process in the calculation process of self-attention. In order to meet the attention range requirements of different notation subtasks, a learnable adaptive relative position attention range is used in the local relative position encoding.
[0007] (2) CNN-GRU feature extraction network
[0008] For the global long-term evolving frame-level targets and note-level velocity targets, we first use a CNN network to extract features from the time-spectrogram, and then use a bidirectional GRU network to model the temporal information of the deep features in the CNN network.
[0009] (3) GRU feature fusion network
[0010] In order to improve the performance of frame-level target notation, the GRU network is used to model the temporal information of feature fusion of the notation outputs of the start branch, stop branch and frame-level branch.
[0011] Compared with the prior art, the present invention has the following obvious advantages and beneficial effects:
[0012] (1) In the improved Transformer network, the local relative position encoding method limits the maximum self-attention range, so that it can be used to transcribe audio of any length, improving the flexibility of automatic notation based on the Transformer method. (2) The local relative position encoding method prompts the Transformer to pay attention to the short-term dependencies between frames, which is conducive to the estimation of start and stop targets. (3) The matrix reorganization, zero padding and slicing operations used in the self-attention calculation process greatly reduce the spatial complexity of the position encoding required for the original matrix calculation, reducing the spatial complexity from the exponential level of the number of audio frames to the linear level of the number of audio frames, speeding up the calculation speed, increasing the audio length that can be processed at a time, and improving the computational efficiency of the automatic notation algorithm. BRIEF DESCRIPTION OF THE DRAWINGS
[0013] Figure 1 Schematic diagram of the overall model of the method for automatic notation of polyphonic piano music based on multi-task learning based on local attention proposed by the present invention
[0014] Figure 2 Schematic diagram of the improved Transformer network structure
[0015] Figure 3 The local relative position encoding related to Q and E in the improved Transformer network module N Schematic diagram of the processing steps of the global calculation method
[0016] Figure 4 The local relative position encoding related to Q and E in the improved Transformer network module N Schematic diagram of the processing steps of the block calculation method DETAILED DESCRIPTION
[0017] According to the above description, the following is a specific implementation process, but the scope of protection of the present invention is not limited to this implementation process.
[0018] Step 1: Data preprocessing settings
[0019] The training set, validation set and test set provided in the MAESTRO V1.0.0 data set are used to train and evaluate the performance of the deep neural network proposed in the present invention. In this step, the librosa audio processing library is used to perform the following pre-processing operations on the original audio in the MAESTRO data set. First, the average value of the sampling points on all channels of the original stereo audio is converted to mono audio, and the sampling frequency of the mono audio is downsampled from the original 44.1-48kHz to 16kHz. Next, the downsampled mono audio is framed, windowed and processed by short-time Fourier transform (STFT). The mono audio is framed with a length of 128ms per frame, and the frame shift is 32ms, then each frame contains 2048 sampling points, and the frame shift contains 512 sampling points. For all framing, a 2048-point STFT with a window type of Hanning window is used to obtain the time-frequency spectrum of the audio, and the frames less than 2048 points after framing are filled with 0 before and after the frame. Next, the obtained STFT time-frequency spectrum is filtered using a set of equal-height Mel filter banks containing 229 frequency bands. The minimum and maximum cutoff frequencies of the filter bank are set to 26Hz and 8000Hz respectively to ensure that the filter bank completely covers all piano pitch fundamental frequencies from A0 (27.5Hz) to C8 (4186Hz). The Mel spectrum obtained after filtering is then converted into a logarithmic Mel spectrum expressed in dB. During the conversion process, the highest energy time-frequency point in each piano audio is used as the 0dB reference. The information with a dynamic range of 80dB in the logarithmic Mel spectrum is retained based on this reference point. Finally, the logarithmic Mel spectrum with a dynamic range of [-80dB, 0dB] is shifted to the interval of [-40dB, +40dB] to complete the data preprocessing step. In the actual training and testing process, the preprocessed logarithmic Mel spectrum needs to be segmented. During the training process, the deep neural network proposed in the present invention performs notation prediction on the 640×229 logarithmic Mel spectrum each time, which means that the sample contains 640 frames and 229 Mel frequency points; during the testing process, the deep neural network proposed in the present invention performs notation prediction on the 20480×229 logarithmic Mel spectrum each time, which means that the sample contains 20480 frames and 229 Mel frequency points.
[0020] In addition, in order to supervise the training and evaluation test of the deep neural network in the present invention, the correct notation target corresponding to the piano audio data obtained by preprocessing is converted from the MIDI file contained in the MAESTRO data set. The preprocessing steps of this part are specifically as follows: First, each note event in the MIDI file is continuously annotated with its corresponding key start frame and key end frame in the frame-level piano roll score containing 88 key categories to obtain the frame-level target annotation. The piano roll score is a two-dimensional matrix, one dimension of which represents the time frame sequence, and the other dimension represents the pitch size. In the annotated piano roll score, a value of 0 is used to indicate that no note appears, and a value of 1 is used to indicate that a note appears. Here, the frame-level target annotation indicates that a certain pitch appears at a certain moment. If the note event contains a sustain pedal event, the stop time of the note with a sustain pedal value not less than 64 is extended until the note with the same pitch is pressed again or the sustain pedal value is less than 64 to end the note, and the time frame corresponding to the stop time at this time is recorded as the correct note end frame. In the following description, the note end frame and the key end frame when there is no sustain pedal event are collectively referred to as the note end frame. Next, based on the frame-level target annotation, all key-onset frames are extracted as the onset target annotation, and all note-end frames are extracted as the stop target annotation. Here, the onset target annotation and the stop target annotation respectively indicate the event that a note of a certain pitch starts to appear at a certain moment, and the event that a note of a certain pitch stops to appear at a certain moment. Finally, the dynamic range of the note velocity target value is proportionally mapped from [0,127] to [0,1]. Based on the frame-level target annotation, the note interval corresponding to each note event is re-annotated with the corresponding note velocity value to obtain the note velocity target annotation. Here, the note velocity target annotation indicates the sound intensity of the note when a note of a certain pitch appears at a certain moment. Among the four correct notation targets, the frame-level target, the note onset target, and the note stop target are binary targets, including two categories of 0 and 1; the note velocity target is a multi-category target, including 128 categories of values corresponding to 0 to 127 mapped in the range of [0,1].
[0021] Step 2: Model structure parameters and model training settings
[0022] Step 2.1: Model structure parameter setting
[0023] The present invention proposes a multi-task learning structure for multiple attributes of notes. Each subtask is extracted by a subtask module, which are the four note targets described in step 1, namely, frame level target, note onset target, note off target and note intensity target. The four subtask modules use the same logarithmic Mel spectrum sample to extract the corresponding note attribute target. The logarithmic Mel spectrum is passed to the four subtask modules for subsequent processing after passing through a batch-norm layer. The schematic diagram of the complete deep neural network structure proposed by the present invention is shown in the attached figure. Figure 1 As shown in the figure, Melspectrum in the figure represents the above-mentioned logarithmic Mel spectrum, the direction of the arrow in the figure represents the transmission direction of the feature map, the solid arrow in the figure represents the feature map transmission path that will calculate the model parameter update gradient during back propagation, and the dotted arrow in the figure represents the feature map transmission path that will not calculate the model parameter update gradient during back propagation. The Frame, Onset, Offset and Velocity in the figure respectively represent the frame level target, note start target, note stop target and note intensity target of the model output.
[0024] Each subtask module includes a feature extraction layer based on a convolutional neural network (CNN) and a temporal feature modeling layer based on a gated recurrent unit (GRU) or a Transformer network. Figure 1ConvBlocks in the figure represents a feature extraction layer based on a convolutional neural network, GRUs represents a temporal feature modeling layer based on a gated recurrent unit network, and Transformers represents a temporal feature modeling layer based on a Transformer network. The CNN in all subtask modules is composed of four convolutional blocks. Each convolutional block contains two convolutional layers with a convolution kernel size of 3×3. The convolution kernel has a moving step size of 1×1. A single layer of zero padding is used around the feature map. The number of input feature map channels of the first convolutional layer is 1, and the number of output feature map channels is 48. The number of input and output feature map channels of the second convolutional layer is both 48. In the two convolutional layers, batch normalization (batch-norm) layer and rectified linear unit (ReLU) nonlinearization layer are used in turn after each convolution operation. Then, an average pooling layer is used to calculate the average value along the frequency axis, so that the dimension of the frequency axis of the feature map is reduced to half of the original one. No pooling operation is performed on the time axis, and the pooling step is 1×2 on the time axis-frequency axis. Finally, a dropout layer with a dropout rate of 0.2 is added after the pooling layer. In each CNN network, after the logarithmic Mel spectrum of the input data passes through four convolution blocks, its corresponding feature map is expanded from the initial mono channel, that is, the number of channels is 1, to 48, 64, 96 and 128 respectively. The expansion method of the channels in each convolution block follows the setting method of the convolution block described above, that is, the number of channels is expanded only in the first convolution layer of each convolution block, and the number of expanded channels is kept unchanged in the second convolution layer.
[0025] In the CNN-Transformer feature extraction network of the subtask modules for the note-onset target and the note-off target, the fully connected layer is first used to map the product of the frequency and channel dimension of the CNN output from 1792 dimensions to 512 dimensions. Next, the feature map is sent to the Transformer network after the batch-norm layer, the ReLU nonlinear layer and the dropout layer with a dropout rate of 0.5. The Transformer network contains two stacked Transformer network modules. Each Transformer network module contains two sub-networks in turn. The first sub-network is an adaptive relative position encoding multi-head self-attention layer. The output of this layer will be summed with the input of this layer and pass through the layer normalization (layer-norm) layer to form a residual connection. After the residual connection, there is a dropout layer with a dropout rate of 0.2. The second sublayer is a multi-layer perceptron (MLP) composed of two layers of fully connected networks. The first fully connected layer expands the feature dimension from 512 to 2048, and passes through the ReLU layer and the dropout layer with a dropout rate of 0.2 in sequence before being sent to the second fully connected layer. The second fully connected layer compresses the feature dimension from 2048 to 512, and passes through the ReLU layer and the dropout layer with a dropout rate of 0.2 in sequence. The output of the MLP will be summed with the input of this layer and pass through the layer-norm layer to form a residual connection. After the feature map passes through two Transformer modules in sequence, it needs to pass through a dropout layer with a dropout rate of 0.5, and then a fully connected layer is used to compress the feature dimension of the Transformer network output from 512 to 88, and then pass through the sigmoid layer before output. Appendix Figure 1 The FC of each subtask module in the above Transformer network module represents the fully connected layer that compresses the feature dimension from 512 to 88, and the Sigmoid of each subtask module represents the above sigmoid layer. Figure 2 As shown in the figure, Multi-HeadAttention and RelativePositionEmbedding represent adaptive relative position encoding multi-head self-attention layers, Add and Norm represent the summation and layer-norm operations of feature maps, and FeedForward represents an MLP composed of two layers of fully connected networks.
[0026] In the CNN-GRU feature extraction network of the subtask module for frame-level targets and note-force targets, the fully connected layer is first used to map the product of the frequency and channel dimension of the CNN output from 1792 dimensions to 768 dimensions. Next, the feature map is sent to the GRU network after passing through the batch-norm layer, the ReLU nonlinear layer, and the dropout layer with a dropout rate of 0.5. The GRU network contains two stacked bidirectional GRU network modules. Each bidirectional GRU network module contains 256 hidden units. Finally, the output feature map of the GRU network passes through a dropout layer with a dropout rate of 0.5, and the feature dimension of the GRU network output is compressed from 512 to 88 using a fully connected layer, and then output after passing through a sigmoid layer.
[0027] In addition, the subtask module for frame-level targets also includes a GRU feature fusion network. This fusion network is connected to the frame-level CNN-GRU feature extraction network, and uses two layers of stacked bidirectional GRU networks to perform feature fusion temporal modeling on the output feature maps of the start branch, stop branch, and frame-level branch spliced along the key category axis. The dimension of the input feature map is 264, and each bidirectional GRU network contains 256 hidden units. Finally, the output feature map of the GRU network is passed through a dropout layer with a dropout rate of 0.5, and the feature dimension of the GRU network output is compressed from 512 to 88 using a fully connected layer, and then output after passing through a sigmoid layer. Figure 1 In the above GRU feature fusion network, Concat represents the tensor operation of splicing the output feature maps of the start branch, the stop branch and the frame level branch along the key category axis.
[0028] Step 2.2: Setting the calculation method of relative position encoding in the Transformer network module
[0029] For the adaptive relative position encoding multi-head self-attention layer in the Transformer network module in step 2.1, the calculation method of the relative position encoding is explained as follows. The relative attention calculation process is as shown in formula (1).
[0030]
[0031] In this formula, Q, K, V, S represent tensor matrices, T represents the transpose of the matrix, and d h is a scalar, Q and K T The multiplication sign used in matrix multiplication is omitted between matrices, and the multiplication sign is omitted before the matrix V. The softmax function represents each item x of the last dimension of the tensor matrix involved in the calculation i Calculate the proportion of exponential scaling. Calculate each item x in the matrix iThe softmax scaling transformation is specifically given by Equation (2). In Equation (2), the denominator of the function is the sum of the exponential scalings of all terms in the last dimension of the tensor matrix participating in the softmax calculation.
[0032]
[0033] In Equation (1), Q, K, and V are the query tensor matrix, key tensor matrix, and value tensor matrix obtained by linearly transforming the model input X. S is the relative position weight tensor matrix. X is a tensor matrix feature map of shape L×512 input to the Transformer network module. L is a scalar representing the number of time frames of the audio segment, and 512 represents the feature dimension of X. The specific steps of this linear transformation are as follows: After X enters the adaptive relative position encoding multi-head self-attention layer, it passes through a fully connected layer to map the feature dimension from 512 to 1536. Next, the feature dimension of this feature map is evenly divided into three parts, each containing a feature map with a dimension of 512. Thereafter, the feature dimensions of the three feature maps are evenly divided into 8 attention heads, so each head contains a feature map with a dimension of 64. At this time, the three groups of multi-head feature map tensors are respectively denoted as the query tensor group, key tensor group, and value tensor group. The query tensor, key tensor, and value tensor corresponding to one head are the Q, K, and V tensors, all representing feature maps with a tap feature dimension of d h = 64. The dimension of the query tensor Q of each feature map sample X in a single head is (1, L, d h ), where the first dimension represents a single sample, and the shapes of the key tensor K and value tensor V are the same as Q.
[0034] For different relative position encoding attention ranges, one of the following two relative position encoding calculation methods will be used to obtain the relative position weight matrix S. The shape of the relative position weight matrix S used by each feature map sample X in a single head to calculate relative attention is (1, L, L). Let N represent the maximum relative position encoding attention range. Then the specific calculation method selection rule is: use the global calculation method when 2N≥L, and use the block calculation method when 2N<L.
[0035] In the above relative attention calculation, the query tensor matrix, key tensor matrix, and value tensor matrix are all obtained by linearly transforming the model input X. Then QK T represents the degree of correlation between the d h -dimensional query vectors of each frame in a matrix of dimension (1, L, L) with respect to all d h -dimensional key vectors. Thereafter, S introduces position-related correlation information into each term in QK T . Finally, after After the linear scaling and softmax scaling transformation, the total correlation size is matrix multiplied with V, indicating that each frame d is scaled with different correlation sizes. h The dimension value vector is weighted, and each frame d in the weighted value tensor matrix h The difference between the dimensional vector and the original value tensor matrix reflects the attention size of the model for different time frames, so that the model achieves the effect of paying attention to certain key frames in the input X.
[0036] a Global calculation method for local relative position encoding
[0037] Now construct the relative position encoding tensor E N , E N The dimension is (N,d h ), which means all d h dimensional vector, the maximum value of N is L. Since a bidirectional non-causal self-attention method needs to be implemented, N needs to be an odd number, that is, in addition to the current frame, there are P = (N-1) / 2 frames before and after that will participate in the attention calculation. N The left concatenation dimension of the first dimension is (LN,d h ) to obtain a virtual tensor with dimension (L,d h )’s global relative position encoding tensor E. At this point, all the required position information in S is already in QE T Specifically, QE T The dimension of the tensor is (1, L, L), and each index is (i q ,t),r∈{-L+1,-L+2,…,-P,-P+1,…0,…,P-1,P}, since each item in S must be consistent with QK T Each item (i q ,j k ) corresponds to the relative position of the two, then r = j k -i q , that is, QE needs to be T The elements in each row of the tensor that use relative position indices are translated to the corresponding correct absolute position indices. q ,r) is converted to an absolute position index (i q ,j k ), we need to q The items on the row are shifted, for example, the item at position r = 0 needs to be shifted to all j k =i q The complete element translation process includes the following steps, related to Q and E N A schematic diagram of the processing steps is shown in the attached Figure 3 As shown in:
[0038] 1) In QE T The right side of the first dimension of is concatenated with a virtual tensor of dimension (1,L,N+1) to obtain a tensor of dimension (1,L,L+N+1).
[0039] 2) Reshape the tensor into a one-dimensional vector, discard the first LP-1 elements, and record the number of all elements in the current vector as W. It should be noted that this step corresponds to the row-first sorting method in PyTorch or NumPy.
[0040] 3) Fill the end of the vector with (L+N)-Wmod(L+N) zero-valued elements, where mod means the remainder, that is, the remainder of W that is not divisible by (L+N) is calculated.
[0041] 4) Reshape the vector into a tensor of dimension (1, L+1, L+N), and use matrix slicing to take the first L rows and L columns of the tensor to obtain the absolute position (i q ,j k ) The required S matrix corresponding to the index has a shape of (1,L,L).
[0042] b Block calculation method of local relative position coding
[0043] Now construct the relative position encoding tensor E N , whose dimension is (N,d h ), which means all d h dimensional vector, N is an odd number, and the maximum value is L. The block calculation of the complete local relative position encoding includes the following steps, related to Q and E N A schematic diagram of the processing steps is shown in the attached Figure 4 As shown in:
[0044] 1) Q, K, V are respectively the dimensions of (1, L, d h ), the Q, K, V tensors of the sequence with a length of L need to be extended, and the virtual tensor is spliced on the right side of its second dimension to a length that is not less than a multiple of N of L. The length of the new sequence is L′, and the dimension is (1, L′, d h ), denoted as Q′, K′, V′ respectively. Divide the new sequence into M blocks with each block length of N, The three tensor dimensions are reshaped into (1, M, N, d h ), denoted as Q″, K″, V″, what is obtained is the non-overlapping block division of the original sequence.
[0045] 2) In order to avoid the influence of block division on the transmission of sequence information, each sequence block should at least contain the feature vectors of the previous and next P frames. For the convenience of calculation, the length of each block in the overlapping division is set to 3N. Except for the 1st block and the Mth block, each sequence block is spliced with its previous and subsequent sequence blocks into a sequence block with a total length of 3N, the 1st block and the 2nd block are spliced into a sequence block with a total length of 2N, and the M-1th block and the Mth block are spliced into a sequence block with a total length of 2N. So far, the overlapping block division of the original sequence is obtained, and the dimensions of K″, V″ from the 2nd block to the M-1th block in the sequence are reorganized to (1, M-2, 3N, d h ), the dimensions of the first block and the Mth block are reorganized to (1,1,2N,d h ), the dimension of Q″ is still (1,M,N,d h ).
[0046] 3) Analogous to the global calculation method of local relative position encoding, in this case Q′E N T The required position information in S is already included in Q′E N T The dimension is (1, L′, N). Similarly, for Q′E N T The block division S″ of S can be obtained by performing the element translation operation corresponding to the global calculation method. All element translation operations are performed inside each sequence block. In order to make the dimensions of S″ after element translation consistent with K″ and V″, the virtual tensor spliced during the element translation process should be (1, M, N, 2N+1). Finally, the relative position information tensor S″ of the block division with the dimension of (1, M, N, 3N) is obtained.
[0047] 4) Calculate the relative attention weights and attention output values according to the corresponding block numbers, reshape the tensor and merge all the partitioned blocks, truncate the virtual elements introduced by the zero-padding operation in the element translation, and obtain the complete self-attention output.
[0048] Step 2.3: Setting the adaptive attention range implementation method in the Transformer network module
[0049] For the adaptive relative position encoding multi-head self-attention layer in the Transformer network module in step 2.1, the implementation method of the adaptive attention range is as follows. The adaptive attention range is implemented using a truncated edge decreasing attention weight mask function, which is based on the expression of the real number z:
[0050]
[0051] In formula (3) The function takes the smaller of a or b. The function means taking the larger of a or b, and |·| means taking the absolute value of the terms contained therein. In formula (3), m z ∈[0,1] represents the mask function, P is the maximum range of unilateral self-attention, G is a settable hyperparameter that controls the size of the linear decreasing weight interval, z is a trainable network parameter that controls the adaptive attention range, and x represents the relative distance between any two frame vectors. Among them, it is consistent with the maximum range N of bidirectional non-causal self-attention described in step 2.2. Here, N=2P+1, and N=639, P=319 are set; the larger G is, the larger the decreasing interval of the mask function from 1 value to 0 value, the smaller the slope of linear decrease, and the smoother the transition of relative attention at its edge. Here, G=1 is set to limit the decreasing interval to 1 frame; the larger z is, the larger the interval of the mask function with a value of 1, and the model can pay attention to more frames near each frame when calculating relative attention, so as to achieve modeling of longer time series features. Here, z is a trainable parameter, which is set by the model in the training process. When the model is initialized, z=PG=318 is set. In order to make the trainable parameter z converge effectively, we added the following regularization loss function l in model training: z , this loss function is added to the joint loss function in step 2.4 and participates in the loss calculation of the model together.
[0052]
[0053] In formula (4), z i It refers to the parameter z in the mask function used in the adaptive attention range in different Transformer network modules, Σ represents the sum of all parameters z, λ>0 is the regularization hyperparameter, and λ=0.0001 is set. Loss function l z It means that additional training constraints are added to the parameter z that controls the adaptive attention range, that is, as the model is trained, the relative attention range will gradually decrease, so that the model pays more attention to several frames adjacent to each frame. In addition, during model training, after each back propagation, all z values in the model will be clipped to the [0,1] interval to assist model convergence.
[0054] Step 2.4: Model training settings
[0055] The complete deep neural network set in step 2.1 contains a total of 26914886 trainable parameters. When training the model, for each subtask module branch, binary cross entropy is used as the loss function between the piano roll score output by the model and the correct annotated target, as follows:
[0056]
[0057] In formula (5), lframe / onset / offset Indicates that the loss function belongs to the frame level branch, the note onset branch, and the note off branch, T represents the total number of time frames, K represents the total number of pitches, and I frame / onset / offset The piano roll with the correct annotations showing the various branches, P frame / onset / offset Represents the piano roll spectra of each branch output by the model, l bce (·,·) represents the calculation of the binary cross entropy of two of the two items, Σ represents the sum of the binary cross entropy for each position (t,k) in the piano roll spectrum, and the binary cross entropy l bce The calculation of (·,·) is as follows:
[0058] l bce (y,p)=-ylnp-(1-y)ln(1-p)#(6)
[0059] In formula (6), y and p represent the piano roll spectrum matrix I frame / onset / offset With P frame / onset / offset For each item in the same position (t,k) in This means that the natural logarithm of the terms contained therein is calculated.
[0060] It should be noted that the binary cross entropy of the note-level velocity target is only calculated at the non-zero point of the attack target, as shown in the following formula:
[0061]
[0062] In formula (7), I velocity A correctly labeled piano roll showing the dynamic branches of the notes, P velocity represents the output of the note velocity branch of the model, ⊙ represents the product of the corresponding elements of two matrices of the same shape, and the shape of the matrix obtained by this operation is consistent with the shape of the two matrices involved in the operation. Finally, combined with the regularized loss function in step 2.3, the total joint loss function is shown as follows.
[0063] l note = l frame +l onset +l offset +l velocity +l z #(8)
[0064] When testing the model, the post-processing method set in step 3 is required to obtain complete note events, and the performance evaluation method set in step 4 is used to obtain the performance index results of the model.
[0065] The model was trained using the Adam optimizer algorithm. The coefficients β1 and β2 used to calculate the back-propagation gradient and its running average of the square of each parameter of the model were set to 0.9 and 0.999 respectively. The initial learning rate in the optimizer algorithm was set to 0.0006, and after every 5000 back-propagations, the learning rate was adjusted to 0.98 times the learning rate of the previous back-propagation. The model was iteratively trained for 100 rounds using the training set in the MAESTROV1.0.0 dataset. The iteration round of the model with the highest F1 score at both the frame level and the note level on the validation set of the MAESTROV1.0.0 dataset was taken as the final training round, and the model obtained by this round of training was the final training result. The calculation method of the F1 score is shown in step 4.
[0066] Step 3: Model output post-processing settings
[0067] In order to obtain complete note events, the output results of each subtask branch module of the model need to be post-processed, which specifically includes the following post-processing steps:
[0068] 1) Binarize the piano roll spectrum estimation result output by the model, and convert the output P onset ,P offset ,P frame Using the threshold θ onset ,θ offset ,θ frame The output of each branch is not less than the corresponding threshold θ onset ,θ offset ,θ frame The item is recorded as 1, otherwise it is 0. The estimated result after binarization is recorded as P′ onset ,P′ offset ,P′ frame , P′ onset After single-step difference, we get P re-onset , the single-step differential operation is specifically P re-onset =P′ onset (t)-P′ onset (t-1), where t represents the index of the time frame.
[0069] 2) For P re-onset Every non-zero value P in re-onset (t, k), record the event of a note starting at pitch k in the frame at time t, and set P velocity The value of (t, k) is restored to a value in the dynamic range of [0, 127] and recorded as the velocity of the note event.
[0070] 3) P′ at the pitch k of the frame at time r frame(t,k) is the starting point, and several subsequent time frames with the same pitch are traversed until the last frame of the audio segment, or when the following conditions are met:
[0071]
[0072] It is recorded that there is a note stop event at the pitch k of the frame at time t′, where t′ represents a time other than time t.
[0073] 4) Record a complete note event, including the above-mentioned start event, stop event and note intensity. Repeat steps (2) to (4) until all complete note events are recorded.
[0074] The above post-processing process can extract note events from the output of the model, and can also extract note events from the correct rolling spectrum annotation. By comparing the note events of the two, the performance evaluation method in step 4 can be used to evaluate the model performance. The binarization thresholds used in the post-processing are: onset is 0.3, the frame level threshold θ frame is 0.4, the pause threshold θ offset is 0.8.
[0075] Step 4: Performance Evaluation Setup
[0076] The performance of the complete note events processed in step 3 is evaluated using the standard frame-level and note-level indicators in the mir_eval library. The evaluation indicators include frame-level and note-level accuracy (Precision), recall (Recall) and F1 score (F-measure). The total number of correct notes estimated by the model is recorded as TP, the total number of correct notes not estimated by the model compared to the correct annotations is recorded as FN, and the total number of notes estimated incorrectly by the model compared to the correct annotations is recorded as FP. The accuracy, recall and F1 score can be expressed as follows:
[0077]
[0078] Note attack evaluation includes a tolerance of ±50ms, which means that the estimated attack time is considered correct if it is within ±50ms relative to the correctly marked note attack time. Note pause evaluation includes a tolerance of ±50ms and 20% of the note length, which means that the estimated pause time is considered correct if it is within ±50ms or 20% of the note length relative to the correctly marked note pause time. Note velocity evaluation includes a tolerance of ±0.1 between the predicted value and the true value after mapping the velocity value to [0,1].
Claims
1. A method for automatic notation of polyphonic piano music based on multi-task learning of local attention, characterized in that: The following steps are involved: Step 1: Data preprocessing settings The librosa audio processing library is used to perform the following preprocessing operations on the original audio in the MAESTRO dataset. First, the average value of the sampling points on all channels of the original stereo audio is taken to convert it into mono audio, and the sampling frequency of the mono audio is downsampled from the original 44.1-48kHz to 16kHz. Next, the downsampled mono audio is framed, windowed, and processed by short-time Fourier transform (STFT). The mono audio is framed with a length of 128ms per frame, and the frame shift is 32ms, so each frame contains 2048 sampling points, and the frame shift contains 512 sampling points. For all frames, a 2048-point STFT with a Haning window is used to obtain the audio time-frequency spectrum. After framing, frames with less than 2048 points are filled with 0 before and after the frame. Next, the obtained STFT time-frequency spectrum is filtered using a set of equal-height Mel filter banks containing 229 frequency bands. The minimum and maximum cutoff frequencies of the filter bank are set to 26Hz and 8000Hz respectively to ensure filtering. The filter group completely covers all piano pitch fundamental frequencies from A0 (27.5Hz) to C8 (4186Hz); then the Mel spectrum obtained after filtering is converted into a logarithmic Mel spectrum expressed in dB. During the conversion process, the time-frequency point with the highest energy in each piano audio is used as the 0dB reference point. The information with a dynamic range of 80dB in the logarithmic Mel spectrum is retained based on this reference point. Finally, the logarithmic Mel spectrum with a dynamic range of [-80dB, 0dB] is translated to the interval of [-40dB, +40dB] to complete the data preprocessing step; in the actual training and testing process, the preprocessed logarithmic Mel spectrum needs to be segmented. During the training process, the deep neural network predicts the 640×229 logarithmic Mel spectrum each time, indicating that the sample contains 640 frames and 229 Mel frequency points; during the testing process, the deep neural network predicts the 20480×229 logarithmic Mel spectrum each time, indicating that the sample contains 20480 frames and 229 Mel frequency points; The deep neural network is supervised for training and evaluation tests. The correct notation target corresponding to the piano audio data obtained by preprocessing is converted from the MIDI file contained in the MAESTRO dataset. The specific preprocessing steps of this part are as follows: First, each note event in the MIDI file is continuously annotated with its corresponding key start frame and key end frame in a frame-level piano roll score containing 88 key categories to obtain a frame-level target annotation. The piano roll score is a two-dimensional matrix, one dimension of which represents the time frame sequence and the other dimension represents the pitch size. In the annotated piano roll score, a value of 0 is used to indicate that no note appears, and a value of 1 is used to indicate that a note appears. Here, the frame-level target annotation indicates that a certain pitch appears at a certain moment. If the note event contains a sustain pedal event, the pause time of the note with a sustain pedal value of not less than 64 is extended until the note with the same pitch is pressed again or the sustain pedal value is less than 64 to end the note, and the time frame corresponding to the pause time at this time is recorded as the correct note end frame. In the subsequent description, the note end frame is referred to as The key-pressing end frames without sustain pedal events are collectively referred to as note-ending frames; next, based on the frame-level target annotation, all key-pressing start frames are extracted as the attack target annotation, and all note-ending frames are extracted as the stop target annotation; here, the attack target annotation and the stop target annotation respectively indicate the event that a note of a certain pitch starts to appear at a certain moment, and the event that a note of a certain pitch stops to appear at a certain moment; finally, the dynamic range of the note velocity target value is proportionally mapped from [0,127] to [0,1], and based on the frame-level target annotation, the note interval corresponding to each note event is re-annotated with the corresponding note velocity value to obtain the note velocity target annotation; here, the note velocity target annotation indicates the sound intensity of the note when a note of a certain pitch appears at a certain moment; among the four correct notation targets, the frame-level target, the note-pressing target and the note-stop target are binary targets, including two categories of 0 and 1; the note velocity target is a multi-category target, including 128 categories of values corresponding to 0 to 127 mapped in the range of [0,1]; Step 2: Model structure parameters and model training settings Step 2.1: Model structure parameter setting A multi-task learning structure for multiple attributes of notes is proposed. Each subtask is composed of a subtask module to extract the corresponding note attribute target, which are four note targets, namely frame level target, note onset target, note off target and note intensity target. The four subtask modules use the same logarithmic Mel spectrum sample to extract the corresponding note attribute target. The logarithmic Mel spectrum is passed to the four subtask modules for subsequent processing after passing through a batch-norm layer. Each subtask module includes a feature extraction layer based on a convolutional neural network (CNN) and a temporal feature modeling layer based on a gated recurrent unit network or a Transformer network. The CNN in all subtask modules is composed of four convolution blocks, each of which contains two convolution layers with a convolution kernel size of 3×3 and a movement step of 1×1. A single layer of zero padding is used around the feature map. The number of input feature map channels of the first convolution layer is 1, and the number of output feature map channels is 48. The number of input and output feature map channels of the second convolution layer is both 48. In the two convolution layers, a batch normalization layer and a rectified linear unit (ReLU) nonlinearization layer are used in turn after each convolution operation. Then, an average pooling layer is used to calculate the average value along the frequency axis, so that the dimension of the frequency axis of the feature map is reduced to half of the original one. No pooling operation is performed on the time axis, and the pooling step size is 1×2 on the time axis-frequency axis. Finally, a dropout layer with a dropout rate of 0.2 is added after the pooling layer. In each CNN network, after the logarithmic Mel spectrum of the input data passes through four convolution blocks, its corresponding feature map is expanded from the initial mono channel, that is, the number of channels is 1, to 48, 64, 96 and 128 respectively. The expansion method of the channels in each convolution block follows the setting method of the above convolution blocks, that is, the number of channels is expanded only in the first convolution layer of each convolution block, and the number of expanded channels is kept unchanged in the second convolution layer. In the CNN-Transformer feature extraction network of the subtask modules for the note-onset target and the note-off target, the fully connected layer is first used to map the product of the frequency and channel dimension of the CNN output from 1792 dimensions to 512 dimensions; then the feature map is sent to the Transformer network through the batch-norm layer, the ReLU nonlinear layer and the dropout layer with a dropout rate of 0.5; the Transformer network contains two stacked Transformer network modules; each Transformer network module contains two sub-networks in turn, the first sub-network is an adaptive relative position encoding multi-head self-attention layer, the output of this layer will be summed with the input of this layer and pass through the layer normalization layer to form a residual connection, and the residual connection is a dr with a dropout rate of 0.2 opout layer; the second sublayer is a multi-layer perceptron MLP composed of two layers of fully connected networks. The first fully connected layer expands the feature dimension from 512 to 2048, and passes through the ReLU layer and the dropout layer with a dropout rate of 0.2 in sequence before being sent to the second fully connected layer. The second fully connected layer compresses the feature dimension from 2048 to 512, and passes through the ReLU layer and the dropout layer with a dropout rate of 0.2 in sequence; the output of the MLP will be summed with the input of this layer and pass through the layer-norm layer to form a residual connection; after the feature map passes through two Transformer modules in sequence, it needs to pass through a dropout layer with a dropout rate of 0.5, and then use a fully connected layer to compress the feature dimension of the Transformer network output from 512 to 88, and then pass through the sigmoid layer before output; In the CNN-GRU feature extraction network of the subtask module for frame-level targets and note-force targets, the fully connected layer is first used to map the product of the frequency and channel dimension of the CNN output from 1792 dimensions to 768 dimensions; then the feature map is sent to the GRU network after passing through the batch-norm layer, the ReLU nonlinear layer and the dropout layer with a dropout rate of 0.5; the GRU network contains two stacked bidirectional GRU network modules; each bidirectional GRU network module contains 256 hidden units; finally, the output feature map of the GRU network passes through a dropout layer with a dropout rate of 0.5, and the feature dimension of the GRU network output is compressed from 512 to 88 using a fully connected layer, and then output after passing through a sigmoid layer; In addition, a GRU feature fusion network is also included in the sub-task module for frame-level targets. This fusion network is connected after the frame-level CNN-GRU feature extraction network. It uses a two-layer stacked bidirectional GRU network to perform feature fusion time series modeling on the onset branch, offset branch, and frame-level branch output feature maps concatenated along the key category axis. The dimension of the input feature map is 264, and each bidirectional GRU network contains 256 hidden units. Finally, the output feature map of the GRU network passes through a dropout layer with a dropout rate of 0.5, and a fully connected layer is used to compress the feature dimension output by the GRU network from 512 to 88, and then outputs after passing through a sigmoid layer. Step 2.2: Setting the calculation method of relative position encoding in the Transformer network module For the adaptive relative position encoding multi-head self-attention layer in the Transformer network module in Step 2.1, the calculation method of the relative position encoding is described as follows; the relative attention calculation process is shown in Equation (1). In this formula, Q, K, V, S represent tensor matrices, T represents the transpose of the matrix, and d h is a scalar, Q and K T The multiplication sign used in matrix multiplication is omitted between matrices, and the multiplication sign is omitted before the matrix V. The softmax function represents each item x of the last dimension of the tensor matrix involved in the calculation i Calculate the proportion of exponential scaling; calculate each item x in the matrix i The softmax scaling transformation is specifically expressed as formula (2); in formula (2), the denominator of the function is the sum of the exponential scaling of all items of the last dimension of the tensor matrix involved in the softmax calculation; In formula (1), Q, K, V are the query tensor matrix, keyword tensor matrix and value tensor matrix obtained by linear transformation of the model input X, S is the relative position weight tensor matrix; X is the tensor matrix feature map of the input Transformer network module with a shape of L×512, L is a scalar representing the number of time frames of the audio clip, and 512 represents the feature dimension of X; the specific steps of the linear transformation are: after X enters the adaptive relative position encoding multi-head self-attention layer, it passes through a fully connected layer to map the feature dimension from 512 to 1536, and then the feature dimension of the feature map is divided into three parts, each containing a feature map with a dimension of 512; thereafter, the feature dimensions of the three feature maps are evenly divided into 8 attention taps, and each tap contains a feature map with a dimension of 64; at this time, the three groups of multi-head feature map tensors are respectively recorded as the query tensor group, the keyword tensor group and the value tensor group, and the query tensor, keyword tensor and value tensor corresponding to one tap are Q, K, V tensors, all of which represent the tap feature dimension d h = 64 feature maps; the dimension of the query tensor Q for each feature map sample X in a single tap is (1, L, d h ), where the first dimension represents a single sample, and the shape of the keyword tensor K and the value tensor V is the same as Q; For different relative position encoding attention ranges, one of the following two relative position encoding calculation methods will be adopted to obtain the relative position weight matrix S. The shape of the relative position weight matrix S used by each feature map sample X in a single head to calculate relative attention is (1, L, L). Let N represent the maximum relative position encoding attention range, then the specific calculation method selection rule is: use the global calculation method when 2N ≥ L, and use the block calculation method when 2N < L. In the above relative attention calculation, the query tensor matrix, keyword tensor matrix and value tensor matrix are all obtained by linear transformation of the model input X, so QK T Indicates that in a matrix of dimension (1, L, L), the d of each frame h dimensional query vector about all d h The relevance of the keyword vector of dimension S; thereafter, S to QK T Each item in introduces the relevant information about the location; finally, after After the linear scaling and softmax scaling transformation, the total correlation size is matrix multiplied with V, indicating that each frame d is scaled with different correlation sizes. h The dimension value vector is weighted, and each frame d in the weighted value tensor matrix h The difference between the dimensional vector and the original value tensor matrix reflects the attention of the model to different time frames, so that the model can focus on some key frames in the input X. a Global calculation method of local relative position encoding Now construct the relative position encoding tensor E N , E N The dimension is (N,d h ), which means all d h dimensional vector, the maximum value of N is L; because a bidirectional non-causal self-attention method needs to be implemented, N needs to be an odd number, that is, in addition to the current frame, there are P = (N-1) / 2 frames before and after that will participate in the attention calculation; in E N The left concatenation dimension of the first dimension is (LN,d h ) to obtain a virtual tensor with dimension (L,d h )’s global relative position encoding tensor E; at this point, all the required position information in S is already in QE T QE T The dimension of the tensor is (1, L, L), and each index is (i q ,r),r∈{-L+1,-L+2,…,-P,-P+1,…0,…,P-1,P}, since each item in S must be consistent with QK T Each item (i q ,j k ) corresponds to the relative position of the two, then r = j k -i q , that is, QE T The elements in each row of the tensor that use relative position indices are translated to the corresponding correct absolute position indices in turn; to convert the relative position index (i q ,r) is converted to an absolute position index (i q ,j k ), we need to q The items on the row are shifted, and the item at position r = 0 needs to be shifted to all j k =i q The complete element translation process includes the following steps: 1) In QE T The right side of the first dimension of is concatenated with a virtual tensor of dimension (1, L, N+1) to obtain a tensor of dimension (1, L, L+N+1); 2) Reshape this tensor into a one-dimensional vector and discard the first L - P - 1 elements. Denote the total number of all elements in the current vector as W. It should be noted that this step corresponds to the row-first sorting method in PyTorch or NumPy. 3) Pad (L + N) - W mod (L + N) zero-valued elements at the end of the vector, where mod represents taking the remainder, that is, calculate the remainder part when W is not divisible by (L + N). 4) Reshape the vector into a tensor of dimension (1, L+1, L+N), and use matrix slicing to take the first L rows and L columns of the tensor to obtain the absolute position (i q ,j k ) The required S matrix corresponding to the index has a shape of (1, L, L); b Block calculation method of local relative position encoding Now construct the relative position encoding tensor E N , whose dimension is (N,d h ), which means all d h dimensional vector, N is an odd number, and the maximum value is L; the block calculation of the complete local relative position encoding includes the following steps: 1) Q, K, V are respectively the dimensions of (1, L, d h ), the Q, K, V tensors of the sequence with a length of L need to be extended, and the virtual tensor is spliced on the right side of its second dimension to a length that is not less than a multiple of N of L. The length of the new sequence is L′, and the dimension is (1, L′, d h ), respectively denoted as Q′, K′, V′; divide the new sequence into M blocks with each block length of N, The three tensor dimensions are reshaped into (1, M, N, d h ), recorded as Q″, K″, V″, at this time, the original sequence is divided into blocks without overlap; 2) To avoid the influence of block division on the transmission of sequence information, each sequence block should at least contain the feature vectors of the previous and next P frames; the length of each block in the overlapping division is set to 3N; except for the 1st block and the Mth block, each sequence block is spliced with its previous and next sequence blocks to form a sequence block with a total length of 3N, the 1st block and the 2nd block are spliced into a sequence block with a total length of 2N, and the M-1st block and the Mth block are spliced into a sequence block with a total length of 2N; thus, the overlapping block division of the original sequence is obtained, and the dimensions of K″, V″ from the 2nd block to the M-1th block in the sequence are reorganized to (1, M-2, 3N, d h ), the dimensions of the first block and the Mth block are reorganized to (1,1,2N,d h ), the dimension of Q″ is still (1,M,N,d h ); 3) Analogous to the global calculation method of local relative position encoding, in this case Q′E N T The required position information in S is already included in Q′E N T The dimension is (1, L′, N). By analogy with the above block calculation, the dimension is reorganized to (1, M, N, N). Similarly, for Q′E N T The block division S″ of S can be obtained by performing the element translation operation corresponding to the global calculation method. All element translation operations are performed inside each sequence block. In order to make the dimensions of S″ after element translation consistent with K″ and V″, the virtual tensor spliced during the element translation process should be (1, M, N, 2N+1). Finally, the relative position information tensor S″ of the block division with the dimension of (1, M, N, 3N) is obtained. 4) Calculate the relative attention weights and attention output values respectively according to the corresponding block numbers, reshape the tensor and merge all divided blocks, and truncate the virtual elements introduced by the zero-padding operation during element translation to obtain the complete self-attention output. Step 2.3: Setting the implementation method of adaptive attention range in the Transformer network module For the adaptive relative position encoding multi-head self-attention layer in the Transformer network module in Step 2.1, the implementation method of the adaptive attention range is described as follows; the adaptive attention range is implemented using an attention weight masking function with truncated edge decay. The expression of this masking function based on the real number z is: In formula (3), the min(a,b) function means taking the smaller of a or b, the max(a,b) function means taking the larger of a or b, and |·| means taking the absolute value of the terms contained therein; in formula (3), m z ∈[0,1] represents the mask function, P is the maximum range of unilateral self-attention, G is a settable hyperparameter that controls the size of the linear decreasing weight interval, z is a trainable network parameter that controls the adaptive attention range, and x represents the relative distance between any two frame vectors; where it is consistent with the maximum range N of bidirectional non-causal self-attention described in step 2.2, where N=2P+1, and N=639, P=319 are set; the larger G is, the larger the decreasing interval of the mask function from 1 to 0, the smaller the slope of the linear decrease, and the smoother the transition of relative attention at its edge. Here, G=1 is set to limit the decreasing interval to 1 frame; the larger z is, the larger the interval of the mask function with a value of 1, and the model can pay attention to more frames near each frame when calculating relative attention, so as to achieve modeling of longer time series features. Here, z is a trainable parameter, which is set by the model during training. When the model is initialized, z=PG=318 is set; in order to make the trainable parameter z converge effectively, the following regularization loss function l is added to the model training z , this loss function is added to the joint loss function in step 2.4 and participates in the loss calculation of the model together; In formula (4), z i It refers to the parameter z in the mask function used in the adaptive attention range in different Transformer network modules, Σ represents the sum of all parameters z, λ>0 is the regularization hyperparameter, set λ=0.0001; loss function l z It means that additional training constraints are added to the parameter z that controls the adaptive attention range, that is, as the model training progresses, the relative attention range will gradually decrease, so that the model pays more attention to several frames adjacent to each frame; in addition, during model training, after each back propagation, all z values in the model will be clipped to the [0,1] interval to assist model convergence; Step 2.4: Model training settings The complete deep neural network set in Step 2.1 contains a total of 26914886 trainable parameters; when training the model, binary cross-entropy is used as the loss function between the piano roll score output by the model and the correct annotation target for each sub-task module branch, specifically as follows: In formula (5), l frame / onset / offset Indicates that the loss function belongs to the frame level branch, the note onset branch, and the note off branch, T represents the total number of time frames, K represents the total number of pitches, and I frame / onset / offset The piano roll with the correct annotations showing the various branches, P frame / onset / offset Represents the piano roll spectra of each branch output by the model, l bce (·,·) represents the calculation of the binary cross entropy of two of the two items, Σ represents the sum of the binary cross entropy for each position (t,k) in the piano roll spectrum, and the binary cross entropy l bce The calculation of (·,·) is as follows: l bce (y,p)=-ylnp-(1-y)ln(1-p)(6) In formula (6), y and p represent the piano roll spectrum matrix I frame / onset / offset With P frame / onset / offset For each term in the same position (t, k) in , ln(·) means calculating the natural logarithm of the term contained therein; It should be noted that the binary cross entropy of the note-level velocity target is only calculated at the non-zero point of the attack target, as shown in the following formula: In formula (7), I velocity A correctly labeled piano roll showing the dynamic branches of the notes, P velocity represents the output of the note velocity branch of the model, ⊙ represents the product of the corresponding elements of two matrices of the same shape, and the shape of the matrix obtained by the operation is consistent with the shape of the two matrices involved in the operation; finally, combined with the regularized loss function in step 2.3, the total joint loss function is shown as follows; l note =l frame +l onset +l offset +l velocity +l z (8) When testing the model, the post-processing method set in step 3 is required to obtain complete note events, and the performance evaluation method based on frame-level and note-level accuracy, recall rate and F1 score is used to obtain the performance index results of the model; The Adam optimizer algorithm was used to train the model. The coefficients β1 and β2 used to calculate the back-propagation gradient of each parameter of the model and its running average of the square were set to 0.9 and 0.999 respectively. The initial learning rate in the optimizer algorithm was set to 0.0006, and after every 5000 back-propagations, the learning rate was adjusted to 0.98 times the learning rate of the previous back-propagation. The training set in the MAESTROV1.0.0 dataset was used to iterate the model for 100 rounds in total. The iteration round of the model with the highest F1 score at both the frame level and the note level on the validation set of the MAESTROV1.0.0 dataset was taken as the final training round, and the model obtained by this round of training was the final training result. The calculation method of the F1 score was based on the accuracy and recall rate at the frame level and the note level. Step 3: Model output post-processing settings In order to obtain complete note events, the output results of each subtask branch module of the model need to be post-processed, which specifically includes the following post-processing steps: 1) Binarize the piano roll spectrum estimation result output by the model, and convert the output P onset ,P offset ,P frame Using the threshold θ onset ,θ offset ,θ frame The output of each branch is not less than the corresponding threshold θ onset ,θ offset ,θ frame The item is recorded as 1, otherwise it is 0; the estimated result after binarization is recorded as P′ onset ,P′ offset ,P′ frame , P′ onset After single-step difference, we get P re-onset , the single-step differential operation is specifically P re-onset =P′ onset (t)-P′ onset (t-1), where t represents the index of the time frame; 2) For P re-onset Every non-zero value P in re-onset (t, k), record the event of a note starting at pitch k in the frame at time t, and set P velocity The value of (t, k) is restored to a value in the dynamic range of [0, 127], which is recorded as the intensity of the note event; 3) P′ at the pitch k of the frame at time t frame (t,k) is the starting point, and several subsequent time frames with the same pitch are traversed until the last frame of the audio segment, or when the following conditions are met: It is recorded that there is a note stop event at the pitch k of the frame at time t′, where t′ represents a time other than time t; 4) Record a complete note event, including the above-mentioned start event, stop event and note intensity; repeat steps 2) to 4) until all complete note events are recorded; The above post-processing process can not only extract note events from the output of the model, but also extract note events from the correct rolling spectrum annotation; by comparing the note events of the two, the performance of the model can be evaluated using the performance evaluation method based on accuracy, recall rate and F1 score at the frame level and note level; the binarization thresholds used in the post-processing are: the attack threshold θ onset is 0.3, the frame level threshold θ frame is 0.4, the pause threshold θ offset is 0.8.
