Automatic music generation method based on dense network and multi-head attention mechanism

By using dense networks and multi-head attention mechanisms in automatic music generation, combined with long short-term memory networks and dense network layers, the problem of processing the temporal characteristics of music sequences is solved, the quality of music generation is improved, and the need for rapid generation is met.

CN115346502BInactive Publication Date: 2024-09-27SHAANXI NORMAL UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202210961565.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-08-11
Publication Date
2024-09-27
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

It is difficult for the existing technology to effectively handle the timing characteristics of music sequences, resulting in low quality of music in automatic music generation, and difficulty in meeting the demand for rapid generation.

Method used

An automatic music generation method based on dense network and multi-head attention mechanism is adopted, music features are extracted through long short-term memory network and dense network layer, binary beta distribution is introduced to replace the Sigmoid function of the gated unit, and the multi-head attention mechanism is combined to enhance the before and after dependence. processing power.

Benefits of technology

It achieves the effect of simple network structure and high quality of music generation, can effectively handle the timing characteristics of music sequences, and improves the effect of automatic music generation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115346502B
    Figure CN115346502B
Patent Text Reader

Abstract

A music automatic generation method based on a dense network and a multi-head attention mechanism, comprising the steps of obtaining a music data set, preprocessing the data set, dividing a training set and a test set, constructing a music automatic generation network, training the music automatic generation network, and automatically generating a music file. The present invention is based on a long short-term memory network, adds a dense network to extract the features of music, and alleviates the gradient vanishing problem that occurs during the training process to a certain extent, introduces a multi-head attention mechanism to focus on the proportion of different music features in the music sequence, introduces a binary beta distribution in the gate mechanism of the long short-term memory network, and strengthens the performance of the gate control unit in capturing the long-term dependency relationship between the information before and after the music sequence, which optimizes the performance of the neural network as a whole and improves the effect of computer automatic music generation. The present invention can be applied to the field of music automatic generation technology.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of computer technology, and in particular relates to a method for automatically generating music based on a dense network and a multi-head attention mechanism. Technical Background

[0002] Music is a complex form of artistic expression. Music creation requires not only relevant music theory knowledge, but also a good perception and appreciation of art. Music creation is a difficult task. Generally speaking, the cycle of manual music creation is long and the time cost is high, which makes it difficult to meet people's growing demand for music. How to achieve music generation efficiently, quickly and at low cost, and solve the problem of insufficient supply of music generation, is the main problem facing the current field of automatic music generation.

[0003] With the development of artificial intelligence and deep learning technology, deep learning methods have been widely used in image generation, natural language processing and other fields and have achieved great success. Since music is a data form with time series, the correlation between the previous and the next sequence is large, and general deep learning methods are difficult to process such time series data, so migrating these generation methods to the field of automatic music generation is still a challenging problem.

[0004] The emergence of recurrent neural networks has brought a good solution to the problem of processing time series data. Recurrent neural networks are used to process sequence data, such as a piece of text, a piece of sound, etc., so they are widely used in language modeling, sound recognition, machine translation, etc. As far as the standard recurrent neural network architecture is concerned, the range of contexts that can be used is extremely limited. In this case, the loop with recurrent connections will record the state of the output at each step, which will lead to error accumulation and cause the problem of gradient disappearance.

[0005] With the development of recurrent neural networks, an improved method of recurrent neural networks, namely long short-term memory networks, was proposed. It introduces a gate mechanism into the recurrent neural network to establish a long-term dependency relationship between the current information and the previous information.

[0006] The temporal characteristics of music sequences place higher demands on the ability of neural networks to memorize long-term information. It is necessary to enhance the performance of the two gating units in the long-term short-term memory network in inferring the long-term dependency relationship between information before and after. At the same time, the proportion of various musical features varies in different styles of music.

[0007] In the field of automatic music generation, a technical problem that needs to be urgently solved is to provide a music automatic generation method that enhances the contextual dependencies of music sequences and improves the ability to process important music event information. Summary of the invention

[0008] The technical problem to be solved by the present invention is to overcome the deficiencies of the above-mentioned prior art and provide a method for automatic music generation based on a dense network and a multi-head attention mechanism, which has a simple network structure and high generated music quality.

[0009] The technical solution adopted to solve the above technical problems consists of the following steps:

[0010] (1) Obtaining music dataset

[0011] Obtain music files of the Musical Instrument Digital Interface type as a dataset for training the automatic music generation network.

[0012] (2) Preprocessing the dataset

[0013] The music in the musical instrument digital interface file is represented in the form of pitch, intensity, note length, and chord events, wherein the pitch event contains 128 events, corresponding to numbers 0-127 as indexes; the intensity event contains 32 events, corresponding to numbers 0-31 as indexes; the note length event contains 100 events, corresponding to numbers 0-99 as indexes; the chord event contains 60 events, corresponding to numbers 0-59 as indexes, and the music data is subjected to data enhancement operations such as pitch adjustment, note addition and deletion, splitting and moving of notes, and the music event sequence is divided into music clips with a preset length of 30 seconds, and the music event sequence is converted into a corresponding digital sequence according to the digital index corresponding to the music event.

[0014] (3) Divide the training set and test set

[0015] The dataset is divided into a training set and a test set, with the ratio of the training set to the test set being 8:2.

[0016] (4) Building a music automatic generation network

[0017] The automatic music generation network model is composed of an input layer and an activation layer, a dense network layer, a long short-term memory network layer, a multi-head attention layer, and an output layer connected in series.

[0018] (5) Training the automatic music generation network

[0019] The training set is input into the music automatic generation network for training. The Adam optimizer is used to dynamically adjust the learning rate of the music automatic generation network. The output note sequence and the original note sequence are compared according to the cross entropy loss function L(a,b) as the loss function to obtain the loss value L(a,b):

[0020] L(a,b)=alnb+(1-a)ln(1-b)

[0021] Among them, a represents the original note sequence, and b represents the output note sequence; the batch size of the data during training is 1 to 8 times the sampling rate, and it is iterated until the cross entropy loss function converges to obtain a trained music automatic generation network.

[0022] (6) Automatically generate music files

[0023] The test set is input into the trained music automatic generation network, and the trained model is used to generate the corresponding MIDI type music file in the specified path.

[0024] In (4) constructing an automatic music generation network of the present invention, the dense network layer is composed of a first batch of normalized layers a1 and a first activation layer b1, a first convolutional layer c1, a second batch of normalized layers a2, a second activation layer b2, a second convolutional layer c2, and a dense network random inactivation layer d connected in series in sequence.

[0025] In (4) constructing an automatic music generation network of the present invention, the long short-term memory network layer is composed of a first long short-term memory layer f1 and a first random inactivation layer d1 of a long short-term memory network, a second long short-term memory layer f2, a second random inactivation layer d2 of a long short-term memory network, a third long short-term memory layer f3, and a fully connected layer m connected in series in sequence.

[0026] In the (4) construction of the music automatic generation network of the present invention, the activation function R(x) of the first activation layer b1 and the second activation layer b2 is as follows:

[0027]

[0028] Among them, x represents the input data, α is the coefficient, α∈(0,1).

[0029] In (4) constructing an automatic music generation network of the present invention, the convolution kernel size of the first convolution layer c1 and the second convolution layer c2 is 3×3.

[0030] In (4) constructing an automatic music generation network of the present invention, the dropout rate of the dense network random inactivation layer d is 0.3 to 0.5.

[0031] In the (4) construction of the music automatic generation network of the present invention, the binary beta distribution function is introduced into the first long short-term memory layer f1, the second long short-term memory layer f2, and the third long short-term memory layer f3 to replace the Sigmoid function of the input gate and the forget gate, and the input gate output value i at the tth moment is determined according to the following formula: t , determine the output value f of the forget gate at time t t :

[0032]

[0033]

[0034]

[0035]

[0036] in, represents a random variable that follows a gamma distribution function, Indicates that the parameter is The rate parameter is set to the gamma distribution function with a constant of 1. j represents the sequence number of the random variable, and the values ​​of j are 1, 2, and 3. Represents the shape parameter of the gamma distribution function, g j Represents the current input x t and the hidden state h at the previous moment t-1 Multilayer perceptron function.

[0037] In the method (4) of constructing the music automatic generation network of the present invention, the fully connected layer m is activated according to the following activation function S(z i )Sure:

[0038]

[0039] Among them, z i represents the output value of the i-th node in the fully connected layer, C represents the number of output nodes, and z c Represents the output value of the cth node.

[0040] In the present invention (4) of constructing an automatic music generation network, the multi-head attention layer (5) has N self-attention heads, where N is an integer from 2 to 8.

[0041] The present invention uses music files of the musical instrument digital interface data type as data sets to train a music automatic generation network. The music data is preprocessed, and events are used to represent the music files of the musical instrument digital interface data type. These events are divided into pitch, sound intensity, sound length, and chord. The music automatic generation network is a long short-term memory network as the basic network structure, and a dense network is added to extract music feature information to alleviate the gradient vanishing problem that occurs during the training process. The binary beta distribution is introduced to replace the Sigmoid function in the input gate and the forget gate of the long short-term memory network. The connection between the two gated units is established by sharing the gamma distribution function, and the performance of the input gate and the forget gate inferring the long-term dependency relationship before and after the information is enhanced. The multi-head attention mechanism is added so that the model can pay attention to more important music feature information during the training process, thereby improving the effect of music automatic generation. The present invention has the advantages of simple network structure and high quality of generated music, and can be applied to the field of music automatic generation technology. BRIEF DESCRIPTION OF THE DRAWINGS

[0042] Figure 1 This is a flow chart of Example 1 of the present invention.

[0043] Figure 2 It is a structural diagram of the music automatic generation network.

[0044] Figure 3 It is a schematic diagram of the structure of dense network layer 3.

[0045] Figure 4 It is a schematic diagram of the structure of the long short-term memory network layer 4. DETAILED DESCRIPTION

[0046] The present invention will be further described in detail below in conjunction with the accompanying drawings and examples, but the present invention is not limited to the following embodiments.

[0047] Example 1

[0048] Taking 400 American pop music piano pieces as an example, as a data set, the music automatic generation method based on dense network and multi-head attention mechanism in this embodiment consists of the following steps (see Figure 1 ):

[0049] (1) Obtaining music dataset

[0050] Obtain music files of the Musical Instrument Digital Interface type as a dataset for training the automatic music generation network.

[0051] (2) Preprocessing the dataset

[0052] The music in the musical instrument digital interface file is represented in the form of pitch, intensity, note length, and chord events, wherein the pitch event contains 128 events, corresponding to numbers 0-127 as indexes; the intensity event contains 32 events, corresponding to numbers 0-31 as indexes; the note length event contains 100 events, corresponding to numbers 0-99 as indexes; the chord event contains 60 events, corresponding to numbers 0-59 as indexes, and the music data is subjected to data enhancement operations such as pitch adjustment, note addition and deletion, splitting and moving of notes, and the music event sequence is divided into music clips with a preset length of 30 seconds, and the music event sequence is converted into a corresponding digital sequence according to the digital index corresponding to the music event.

[0053] (3) Divide the training set and test set

[0054] The dataset is divided into a training set and a test set, with the ratio of the training set to the test set being 8:2.

[0055] (4) Building a music automatic generation network

[0056] exist Figure 2In the figure, the automatic music generation network model of this embodiment is composed of an input layer 1 and an activation layer 2, a dense network layer 3, a long short-term memory network layer 4, a multi-head attention layer 5, and an output layer 6 connected in series in sequence.

[0057] exist Figure 3 In this embodiment, the dense network layer 3 is composed of the first batch of normalized layers a1 and the first activation layer b1, the first convolutional layer c1, the second batch of normalized layers a2, the second activation layer b2, the second convolutional layer c2, and the dense network random inactivation layer d in series. The activation function R(x) of the first activation layer b1 and the second activation layer b2 is as follows:

[0058]

[0059] Wherein, x represents input data, α is a coefficient, α∈(0,1), and the value of α in this embodiment is 0.5. The convolution kernel size of the first convolution layer c1 and the second convolution layer c2 in this embodiment is 3×3. The dropout rate of the dense network random inactivation layer d is 0.3-0.5, and the dropout rate in this embodiment is 0.4.

[0060] exist Figure 4 In the embodiment, the long short-term memory network layer 4 is composed of the first long short-term memory layer f1 and the first random inactivation layer d1 of the long short-term memory network, the second long short-term memory layer f2, the second random inactivation layer d2 of the long short-term memory network, the third long short-term memory layer f3, and the fully connected layer m in series. The binary beta distribution function is introduced into the first long short-term memory layer f1, the second long short-term memory layer f2, and the third long short-term memory layer f3 to replace the Sigmoid function of the input gate and the forget gate. The output value i of the input gate at the tth moment is determined by the following formula: t , determine the output value f of the forget gate at time t t :

[0061]

[0062]

[0063]

[0064]

[0065] in, represents a random variable that follows a gamma distribution function, Indicates that the parameter is The rate parameter is set to the gamma distribution function with a constant of 1. j represents the sequence number of the random variable, and the values ​​of j are 1, 2, and 3. Represents the shape parameter of the gamma distribution function, g j Represents the current input x t and the hidden state h at the previous momentt-1 The fully connected layer m has the following activation function S(z i )Sure:

[0066]

[0067] Among them, z i represents the output value of the i-th node in the fully connected layer, C represents the number of output nodes, and z c Represents the output value of the cth node.

[0068] The multi-head attention layer 5 has N self-attention heads, where N is an integer from 2 to 8, and in this embodiment, N is 5.

[0069] (5) Training the automatic music generation network

[0070] The training set is input into the music automatic generation network for training. The Adam optimizer is used to dynamically adjust the learning rate of the music automatic generation network. The output note sequence and the original note sequence are compared according to the cross entropy loss function L(a,b) as the loss function to obtain the loss value L(a,b):

[0071] L(a,b)=alnb+(1-a)ln(1-b)

[0072] Among them, a represents the original note sequence, and b represents the output note sequence; the batch size of the data during training is 1 to 8 times the sampling rate. The specific parameters of the batch size should be determined according to the specific content of the piano music. Iterate until the cross entropy loss function converges to obtain a trained music automatic generation network;

[0073] (6) Automatically generate music files

[0074] The test set is input into the trained music automatic generation network, and the trained model is used to generate the corresponding MIDI type music file in the specified path.

[0075] Complete the automatic music generation method based on dense network and multi-head attention mechanism.

[0076] Example 2

[0077] Taking 400 American pop piano pieces as an example, as a data set, the automatic music generation method based on a dense network and a multi-head attention mechanism in this embodiment consists of the following steps:

[0078] (1) Obtaining music dataset

[0079] This step is the same as in Example 1.

[0080] (2) Preprocessing the dataset

[0081] This step is the same as in Example 1.

[0082] (3) Divide the training set and test set

[0083] This step is the same as in Example 1.

[0084] (4) Building a music automatic generation network

[0085] The automatic music generation network model is composed of an input layer 1 and an activation layer 2, a dense network layer 3, a long short-term memory network layer 4, a multi-head attention layer 5, and an output layer 6 connected in series.

[0086] The dense network layer 3 is composed of the first batch of normalized layers a1 and the first activation layer b1, the first convolutional layer c1, the second batch of normalized layers a2, the second activation layer b2, the second convolutional layer c2, and the dense network random inactivation layer d in series. The activation function R(x) of the first activation layer b1 and the second activation layer b2 is as follows:

[0087]

[0088] Wherein, x represents input data, α is a coefficient, α∈(0,1), and the value of α in this embodiment is 0.1. The convolution kernel size of the first convolution layer c1 and the second convolution layer c2 in this embodiment is 3×3. The dropout rate of the dense network random inactivation layer d is 0.3-0.5, and the dropout rate in this embodiment is 0.3.

[0089] The long short-term memory network layer 4 is composed of the first long short-term memory layer f1 and the first random inactivation layer d1 of the long short-term memory network, the second long short-term memory layer f2, the second random inactivation layer d2 of the long short-term memory network, the third long short-term memory layer f3, and the fully connected layer m in series. The binary beta distribution function is introduced into the first long short-term memory layer f1, the second long short-term memory layer f2, and the third long short-term memory layer f3 to replace the Sigmoid function of the input gate and the forget gate, and the output value i of the input gate at the tth time is determined according to the following formula t , determine the output value f of the forget gate at time t t :

[0090]

[0091]

[0092]

[0093]

[0094] in, represents a random variable that follows a gamma distribution function, Indicates that the parameter is The rate parameter is set to the gamma distribution function with a constant of 1. j represents the sequence number of the random variable, and the values ​​of j are 1, 2, and 3. Represents the shape parameter of the gamma distribution function, g j Represents the current input x t and the hidden state h at the previous moment t-1 The fully connected layer m has the following activation function S(z i )Sure:

[0095]

[0096] Among them, z i represents the output value of the i-th node in the fully connected layer, C represents the number of output nodes, and z c Represents the output value of the cth node.

[0097] The multi-head attention layer 5 has N self-attention heads, where N is an integer from 2 to 8, and in this embodiment, N is 2.

[0098] The other steps are the same as those in Example 1. The automatic music generation method based on dense network and multi-head attention mechanism is completed.

[0099] Example 3

[0100] Taking 400 American pop piano pieces as an example, as a data set, the automatic music generation method based on a dense network and a multi-head attention mechanism in this embodiment consists of the following steps:

[0101] (1) Obtaining music dataset

[0102] This step is the same as in Example 1.

[0103] (2) Preprocessing the dataset

[0104] This step is the same as in Example 1.

[0105] (3) Divide the training set and test set

[0106] This step is the same as in Example 1.

[0107] (4) Building a music automatic generation network

[0108] The automatic music generation network model is composed of an input layer 1 and an activation layer 2, a dense network layer 3, a long short-term memory network layer 4, a multi-head attention layer 5, and an output layer 6 connected in series.

[0109] The dense network layer 3 is composed of the first batch of normalized layers a1 and the first activation layer b1, the first convolutional layer c1, the second batch of normalized layers a2, the second activation layer b2, the second convolutional layer c2, and the dense network random inactivation layer d in series. The activation function R(x) of the first activation layer b1 and the second activation layer b2 is as follows:

[0110]

[0111] Wherein, x represents input data, α is a coefficient, α∈(0,1), and the value of α in this embodiment is 0.9. The convolution kernel size of the first convolution layer c1 and the second convolution layer c2 in this embodiment is 3×3. The dropout rate of the dense network random inactivation layer d is 0.3-0.5, and the dropout rate in this embodiment is 0.5.

[0112] The long short-term memory network layer 4 is composed of the first long short-term memory layer f1 and the first random inactivation layer d1 of the long short-term memory network, the second long short-term memory layer f2, the second random inactivation layer d2 of the long short-term memory network, the third long short-term memory layer f3, and the fully connected layer m in series. The binary beta distribution function is introduced into the first long short-term memory layer f1, the second long short-term memory layer f2, and the third long short-term memory layer f3 to replace the Sigmoid function of the input gate and the forget gate, and the output value i of the input gate at the tth time is determined according to the following formula t , determine the output value f of the forget gate at time t t :

[0113]

[0114]

[0115]

[0116]

[0117] in, represents a random variable that follows a gamma distribution function, Indicates that the parameter is The rate parameter is set to the gamma distribution function with a constant of 1. j represents the sequence number of the random variable, and the values ​​of j are 1, 2, and 3. Represents the shape parameter of the gamma distribution function, g j Represents the current input x t and the hidden state h at the previous moment t-1 The fully connected layer m has the following activation function S(z i )Sure:

[0118]

[0119] Among them, zi represents the output value of the i-th node in the fully connected layer, C represents the number of output nodes, and z c Represents the output value of the cth node.

[0120] The multi-head attention layer 5 has N self-attention heads, where N is an integer from 2 to 8, and in this embodiment, N is 8.

[0121] The other steps are the same as those in Example 1. The automatic music generation method based on dense network and multi-head attention mechanism is completed.

[0122] In order to verify the beneficial effects of the present invention, the inventors conducted a comparative experiment using the method of Example 1 of the present invention (hereinafter referred to as the present invention method). The comparative method (hereinafter referred to as the comparative method) is from the paper (Yu Y, Si X, Hu C, et al. A review of recurrent neural networks: LSTM cells and network architectures [J]. Neural computation, 2019, 31 (7): 1235-1270.), and the experimental results are as follows:

[0123] 1. Simulation conditions

[0124] The hardware requirements are: 1 personal computer and 1 Nvidia 1080Ti graphics card.

[0125] The software platform is: Pytorch framework.

[0126] Other third-party libraries: Numpy, pretty_midi, math.

[0127] 2. Simulation content and results

[0128] The method of Example 1 and the comparative method were used to conduct experiments under the above simulation conditions. Taking 400 American pop music piano pieces as an example, as a data set, the method of the present invention and the comparative method were used to conduct comparative experiments to automatically generate music. The similarity between the two methods and the music in the training set was evaluated from five dimensions: pitch histogram entropy, rhythm pattern similarity, long-term structure index, medium-term structure index, and short-term structure index. The difference between the indicators of each dimension of the music generated by the two methods and the indicators of each dimension of the music in the training set is shown in Table 1.

[0129] Table 1 Comparative experimental results of the method of the present invention and the comparative experimental method

[0130]

[0131] As can be seen from Table 1, the music generated by the method of the present invention has a higher similarity to the training set, which proves that the effect of generating music by the method of the present invention is significant.

Claims

1. A method for automatic music generation based on dense network and multi-head attention mechanism, characterized in that It consists of the following steps: (1) Obtaining music dataset Obtaining music files of the Musical Instrument Digital Interface type as a data set for training a music automatic generation network; (2) Preprocessing the dataset The music in the MIDI file is represented in the form of pitch, intensity, duration, and chord events, wherein the pitch event contains 128 events, corresponding to numbers 0-127 as indexes; the intensity event contains 32 events, corresponding to numbers 0-31 as indexes; the duration event contains 100 events, corresponding to numbers 0-99 as indexes; the chord event contains 60 events, corresponding to numbers 0-59 as indexes, and the music data is subjected to data enhancement operations such as pitch adjustment, adding and deleting notes, splitting and moving notes, cutting the music event sequence into music clips of a preset length of 30 seconds, and converting the music event sequence into a corresponding digital sequence according to the digital index corresponding to the music event; (3) Divide the training set and test set The data set is divided into a training set and a test set, with the ratio of the training set to the test set being 8:2; (4) Building a music automatic generation network The music automatic generation network model is composed of an input layer (1), an activation layer (2), a dense network layer (3), a long short-term memory network layer (4), a multi-head attention layer (5), and an output layer (6) connected in series. (5) Training the automatic music generation network The training set is input into the music automatic generation network for training. The Adam optimizer is used to dynamically adjust the learning rate of the music automatic generation network. The output note sequence and the original note sequence are compared according to the cross entropy loss function L(a,b) as the loss function to obtain the loss value L(a,b): L(a,b)=alnb+(1-a)ln(1-b) Among them, a represents the original note sequence, and b represents the output note sequence; the batch size of the data during training is 1 to 8 times the sampling rate, and it is iterated until the cross entropy loss function converges to obtain the trained music automatic generation network; (6) Automatically generate music files The test set is input into the trained music automatic generation network, and the trained model is used to generate the corresponding MIDI type music file in the specified path.

2. The method for automatic music generation based on dense network and multi-head attention mechanism according to claim 1, characterized in that: In (4) constructing the automatic music generation network, the dense network layer (3) is composed of a first batch of normalized layers a1 and a first activation layer b1, a first convolutional layer c1, a second batch of normalized layers a2, a second activation layer b2, a second convolutional layer c2, and a dense network random inactivation layer d connected in series in sequence.

3. The method for automatic music generation based on dense network and multi-head attention mechanism according to claim 1, characterized in that: In (4) constructing the automatic music generation network, the long short-term memory network layer (4) is composed of a first long short-term memory layer f1 and a first random inactivation layer d1 of the long short-term memory network, a second long short-term memory layer f2, a second random inactivation layer d2 of the long short-term memory network, a third long short-term memory layer f3, and a fully connected layer m connected in series in sequence.

4. The method for automatic music generation based on dense network and multi-head attention mechanism according to claim 2, characterized in that: The activation function R(x) of the first activation layer b1 and the second activation layer b2 is as follows: Among them, x represents the input data, α is the coefficient, α∈(0,1).

5. The method for automatic music generation based on dense network and multi-head attention mechanism according to claim 2, characterized in that: The convolution kernel sizes of the first convolution layer c1 and the second convolution layer c2 are 3×3.

6. The method for automatic music generation based on dense network and multi-head attention mechanism according to claim 2, characterized in that: The dropout rate of the dense network random dropout layer d is 0.3-0.

5.

7. The method for automatic music generation based on dense network and multi-head attention mechanism according to claim 3, characterized in that: The binary beta distribution function is introduced into the first long short-term memory layer f1, the second long short-term memory layer f2, and the third long short-term memory layer f3 to replace the Sigmoid function of the input gate and the forget gate. The output value i of the input gate at the tth moment is determined by the following formula: t , determine the output value f of the forget gate at time t t : in, represents a random variable that follows a gamma distribution function, Indicates that the parameter is The rate parameter is set to the gamma distribution function with a constant of 1. j represents the sequence number of the random variable, and the values ​​of j are 1, 2, and 3. Represents the shape parameter of the gamma distribution function, g j Represents the current input x t and the hidden state h at the previous moment t-1 Multilayer perceptron function.

8. The method for automatic music generation based on dense network and multi-head attention mechanism according to claim 3, characterized in that: The fully connected layer m is activated by the following activation function S(z i )Sure: Among them, z i represents the output value of the i-th node in the fully connected layer, C represents the number of output nodes, and z c Represents the output value of the cth node.

9. The method for automatic music generation based on dense network and multi-head attention mechanism according to claim 1, characterized in that: In the step (4) of constructing an automatic music generation network, the multi-head attention layer (5) has N self-attention heads, where N is an integer ranging from 2 to 8.