Methods, devices, readable media, and electronic devices for generating melodies
By introducing multiple music theory labels as constraints into the melody generation model and using a conditional variational autoencoder for training, the problems of uncontrollable and poor-quality melody generation in existing technologies are solved, achieving higher-quality and more stable melody generation.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-19
- Publication Date
- 2026-03-10
AI Technical Summary
Existing automatic composition methods generate melodies of poor quality and uncontrollable quality, especially those generated by the EC2-VAE algorithm, which have low quality and stability.
By obtaining the latent vector of the target melody and multiple target music theory labels, and inputting them into a pre-trained melody generation model, the model is trained using the encoder and decoder in the conditional variational autoencoder. The melody generation model is constrained by multiple music theory labels, thereby improving the quality and stability of the generated melody.
By using multiple music theory tags as constraints, uncontrollable situations in the melody generation process are avoided, improving the quality and stability of the generated melody, and making the generated melody more in line with the expected music theory requirements.
Smart Images

Figure CN114944142B_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of computer technology, and more specifically, to a method, apparatus, readable medium, and electronic device for generating melodies. Background Technology
[0002] The creative process of contemporary pop music includes melody creation, lyrics writing, arrangement and accompaniment production, mixing, and mastering. Automatic composition, on the other hand, utilizes computer algorithms to program and automatically generate musical scores. Within the aforementioned process, automatic composition has the potential to handle primarily melody creation and arrangement.
[0003] This method involves collecting a large dataset of melodies using an algorithm, then feeding this dataset into a neural network model to learn its data distribution. Once the neural network model converges, it can randomly generate samples with the same distribution as the melodic dataset. However, the generation process is uncontrollable, resulting in relatively poor quality melodies. Summary of the Invention
[0004] This section is provided to briefly introduce the concepts, which will be described in detail in the Detailed Description section later. This section is not intended to identify key or essential features of the claimed technical solution, nor is it intended to limit the scope of the claimed technical solution.
[0005] In a first aspect, this disclosure provides a method for generating a melody, the method comprising:
[0006] Obtain the latent vector of the target melody and multiple target music theory labels;
[0007] The target melody latent vector and multiple target music theory labels are input into a pre-trained melody generation model to obtain the target melody output by the melody generation model; wherein, the melody generation model is trained by a first sample set including a first sample melody and multiple first sample music theory labels corresponding to the first sample melody.
[0008] Secondly, this disclosure provides an apparatus for generating a melody, the apparatus comprising:
[0009] The acquisition module is used to acquire the latent vector of the target melody and multiple target music theory labels;
[0010] The generation module is used to input the target melody latent vector and multiple target music theory labels into a pre-trained melody generation model to obtain the target melody output by the melody generation model; wherein, the melody generation model is trained by a first sample set including a first sample melody and multiple first sample music theory labels corresponding to the first sample melody.
[0011] Thirdly, this disclosure provides a computer-readable medium having a computer program stored thereon, which, when executed by a processing device, implements the steps of the method described in the first aspect of this disclosure.
[0012] Fourthly, this disclosure provides an electronic device, comprising:
[0013] A storage device having at least one computer program stored thereon;
[0014] At least one processing means is configured to execute the at least one computer program in the storage device to implement the steps of the method described in the first aspect of this disclosure.
[0015] The above technical solution involves obtaining a latent vector of the target melody and multiple target music theory labels; inputting the latent vector and the multiple target music theory labels into a pre-trained melody generation model to obtain the target melody output by the melody generation model; wherein, the melody generation model is trained using a first sample set including a first sample melody and multiple first sample music theory labels corresponding to the first sample melody. In other words, this disclosure constrains the melody generation model using multiple music theory labels, which can avoid uncontrollable situations during the melody generation process, thus improving the quality of the generated melody.
[0016] Other features and advantages of this disclosure will be described in detail in the following detailed description section. Attached Figure Description
[0017] The above and other features, advantages, and aspects of the embodiments of this disclosure will become more apparent from the accompanying drawings and the following detailed description. Throughout the drawings, the same or similar reference numerals denote the same or similar elements. It should be understood that the drawings are schematic, and the originals and elements are not necessarily drawn to scale. In the drawings:
[0018] Figure 1 This is a flowchart illustrating a method for generating a melody according to an exemplary embodiment of the present disclosure;
[0019] Figure 2 This is a flowchart illustrating a first model training step according to an exemplary embodiment of the present disclosure;
[0020] Figure 3 This is a schematic diagram illustrating a melody generation according to an exemplary embodiment of the present disclosure;
[0021] Figure 4 This is a schematic diagram of a classifier model according to an exemplary embodiment of the present disclosure;
[0022] Figure 5This is a flowchart illustrating another method for generating a melody according to an exemplary embodiment of the present disclosure;
[0023] Figure 6 This is a flowchart illustrating a method for obtaining music theory tag vectors according to an exemplary embodiment of this disclosure;
[0024] Figure 7 This is a flowchart illustrating a second model training step according to an exemplary embodiment of the present disclosure;
[0025] Figure 8 This is a schematic diagram illustrating a melody contrast according to an exemplary embodiment of the present disclosure;
[0026] Figure 9 This is a block diagram illustrating an apparatus for generating a melody according to an exemplary embodiment of the present disclosure;
[0027] Figure 10 This is a block diagram illustrating an electronic device according to an exemplary embodiment of the present disclosure. Detailed Implementation
[0028] Embodiments of this disclosure will now be described in more detail with reference to the accompanying drawings. While some embodiments of this disclosure are shown in the drawings, it should be understood that this disclosure can be implemented in various forms and should not be construed as limited to the embodiments set forth herein. Rather, these embodiments are provided to provide a more thorough and complete understanding of this disclosure. It should be understood that the accompanying drawings and embodiments of this disclosure are for illustrative purposes only and are not intended to limit the scope of protection of this disclosure.
[0029] It should be understood that the steps described in the method embodiments of this disclosure may be performed in different orders and / or in parallel. Furthermore, the method embodiments may include additional steps and / or omit the steps shown. The scope of this disclosure is not limited in this respect.
[0030] The term "comprising" and its variations as used herein are open-ended inclusions, meaning "including but not limited to". The term "based on" means "at least partially based on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one additional embodiment"; the term "some embodiments" means "at least some embodiments". Definitions of other terms will be given in the description below.
[0031] It should be noted that the concepts of "first" and "second" mentioned in this disclosure are used only to distinguish different devices, modules or units, and are not used to limit the order of functions performed by these devices, modules or units or their interdependencies.
[0032] It should be noted that the terms "a" and "a plurality of" used in this disclosure are illustrative rather than restrictive, and those skilled in the art should understand that, unless otherwise expressly indicated in the context, they should be understood as "one or more".
[0033] The names of messages or information exchanged between multiple devices in the embodiments of this disclosure are for illustrative purposes only and are not intended to limit the scope of such messages or information.
[0034] All actions involving the acquisition of signals, information, or data in this disclosure are carried out in accordance with the relevant data protection laws and policies of the country where the location is situated, and with the authorization granted by the owner of the relevant device.
[0035] It is understood that before using the technical solutions disclosed in the various embodiments of this disclosure, users should be informed of the types, scope of use, and usage scenarios of the personal information involved in this disclosure in an appropriate manner in accordance with relevant laws and regulations, and user authorization should be obtained.
[0036] For example, upon receiving a user's active request, a prompt message is sent to the user to explicitly inform them that the requested operation will require the acquisition and use of the user's personal information. This allows the user to independently choose whether to provide personal information to the software or hardware, such as the electronic device, application, server, or storage medium performing the operations of this disclosed technical solution, based on the prompt message.
[0037] As an optional but non-limiting implementation, in response to a user's active request, sending a prompt message to the user can be done via a pop-up window, where the prompt message can be presented in text format. Furthermore, the pop-up window can also include a selection control allowing the user to choose "agree" or "disagree" to provide personal information to the electronic device.
[0038] It is understood that the above notification and user authorization process are merely illustrative and do not constitute a limitation on the implementation of this disclosure. Other methods that comply with relevant laws and regulations may also be applied to the implementation of this disclosure.
[0039] Meanwhile, it is understood that the data involved in this technical solution (including but not limited to the data itself, the acquisition or use of the data) shall comply with the requirements of relevant laws, regulations and related provisions.
[0040] First, let's explain the application scenarios of this disclosure. Early automatic music composition used rule-based or expert system methods, where music theory knowledge was manually extracted and then programmed to compose music. This method was relatively stable, but limited by human intervention, resulting in poor melodic generalization and a limited stylistic diversity. Melodies generated through neural networks can solve these problems. These algorithms collect large datasets of melodies and train a neural network model. The trained model can then randomly generate samples with the same distribution as the training data. This approach requires less human intervention, but because the generation process is relatively uncontrollable, the quality of the generated melodies is relatively poor.
[0041] In related technologies, melodies are generated using the EC2-VAE algorithm. However, this algorithm has relatively few constraints, and the controllability of the melody generation process is still not high, resulting in poor quality and stability of the generated melodies.
[0042] To address the aforementioned problems, this disclosure provides a method, apparatus, readable medium, and electronic device for generating melodies. This method constrains the melody generation model through multiple music theory tags, which can avoid uncontrollable situations during the melody generation process, thereby improving the quality of the generated melodies.
[0043] The present disclosure will now be described in conjunction with specific embodiments.
[0044] Figure 1 This is a flowchart illustrating a method for generating a melody according to an exemplary embodiment of the present disclosure, such as... Figure 1 As shown, the method may include:
[0045] S101. Obtain the latent vector of the target melody and multiple target music theory labels.
[0046] The target melody latent vector can be a randomly set melody latent vector or a melody latent vector obtained based on a preset melody; this disclosure does not limit its use. The music theory label can include music theory-related elements such as melody curves, chords, rhythms, and melodies; this disclosure does not limit its use either. The music theory label can be represented by a preset data table; for example, the preset data format can be numbers.
[0047] In this step, when a melody needs to be generated randomly, multiple target music theory labels for the melody to be generated can be determined first, and then a target melody latent vector can be randomly set. When a melody similar to a preset melody needs to be generated, the target melody latent vector corresponding to the preset melody can be determined first, and then multiple target music theory labels can be determined. The target music theory labels can be music theory labels set by the user according to their needs, or music theory labels obtained by the user after adjusting the music theory labels corresponding to the preset melody. This disclosure does not limit the method of obtaining the target music theory labels.
[0048] S102. Input the latent vector of the target melody and multiple target music theory labels into the pre-trained melody generation model to obtain the target melody output by the melody generation model.
[0049] The melody generation model can be trained using a first sample set that includes a first sample melody and multiple first sample music theory labels corresponding to the first sample melody.
[0050] Accordingly, multiple first sample sets can be obtained. Based on these first sample sets, the first target neural network model is iteratively trained using a first loss function to obtain the melody generation model. This first loss function is used to constrain the multiple first sample music theory labels as constraints on the first target neural network model. The first target neural network model can be the encoder in a conditional variational autoencoder.
[0051] In one possible implementation, after acquiring multiple first sample sets, the first model training step can be executed cyclically until the trained first target neural network model satisfies the first preset stopping iteration condition based on the first target sample melody and the first generated sample melody. The trained first target neural network model is then used as the melody generation model. The first target sample melody is any one of the multiple first sample melodies, and the first generated sample melody is the melody output by the trained first target neural network model.
[0052] Figure 2 This is a flowchart illustrating a first model training step according to an exemplary embodiment of the present disclosure, such as... Figure 2 As shown, the first model training step may include:
[0053] S21. Obtain the melody of the first target sample and the music theory labels of the interference samples.
[0054] The interference sample music theory label includes multiple first sample music theory labels corresponding to any first sample melody in the first remaining sample melody, and the first remaining sample melody includes first sample melodies other than the first target sample melody among the multiple first sample melodies.
[0055] After obtaining multiple first sample sets, a first sample melody is randomly selected from the multiple first sample melodies in the multiple first sample sets as the first target sample melody. Then, any first sample melody is determined from the first remaining sample melodies, and the multiple first sample music theory labels corresponding to the any first sample melody are used as the interference sample music theory labels.
[0056] S22. Based on the first target sample melody, the interference sample music theory label, and multiple first sample music theory labels corresponding to the first target sample melody, the first generated sample melody is obtained through the first target neural network model.
[0057] In one possible implementation, after obtaining the first target sample melody and the interference sample music theory label, the latent vector of the first target sample melody corresponding to the first target sample melody can be obtained; the latent vector of the first target sample melody and the interference sample music theory label are input into the first target neural network model to obtain the undetermined sample melody output by the first target neural network model; the latent vector of the undetermined sample melody corresponding to the undetermined sample melody is obtained; the latent vector of the undetermined sample melody and the multiple first sample music theory labels corresponding to the first target sample melody are input into the first target neural network model to obtain the first generated sample melody output by the first target neural network model.
[0058] For example, the first target sample melody can be input into a pre-trained melody latent vector acquisition model to obtain the first target sample melody latent vector output by the melody latent vector acquisition model. The first target sample melody latent vector and the music theory label of the interference sample can be input into the first target neural network model to obtain the undetermined sample melody output by the first target neural network model. Then, the undetermined sample melody can be input into the melody latent vector acquisition model to obtain the undetermined sample melody latent vector output by the melody latent vector acquisition model. Finally, the undetermined sample melody latent vector and the multiple first sample music theory labels corresponding to the first target sample melody can be input into the first target neural network model to obtain the first generated sample melody output by the first target neural network model.
[0059] Figure 3 This is a schematic diagram illustrating a melody generation according to an exemplary embodiment of the present disclosure, such as... Figure 3As shown, after inputting the first target sample melody x into the melody latent vector acquisition model, the first target sample melody latent vector z is obtained. After inputting the first target sample melody latent vector z and the interference sample music theory label y2 into the first target neural network model, the undetermined sample melody x2 is obtained. After inputting the undetermined sample melody x2 into the melody latent vector acquisition model, the undetermined sample melody latent vector z2 is obtained. After inputting the undetermined sample melody latent vector z2 and the multiple first sample music theory labels y1 corresponding to the first target sample melody into the first target neural network model, the first generated sample melody x3 is obtained.
[0060] S23. If it is determined that the first target neural network model does not meet the first preset stopping iteration condition based on the first target sample melody and the first generated sample melody, determine the first loss value corresponding to the first loss function, update the parameters of the first target neural network model according to the first loss value, obtain the trained first target neural network model, and use the trained first target neural network model as the new first target neural network model.
[0061] The first loss function may include a first reconstruction loss function and a first classification loss function. The first reconstruction loss function may be a reconstruction loss function of the prior art, and the first classification loss function may be a classification loss function of the prior art, which will not be elaborated here.
[0062] In one possible implementation, after obtaining the first generated sample melody, the first reconstruction loss value corresponding to the first reconstruction loss function can be determined based on the first target sample melody and the first generated sample melody; the first classification loss value corresponding to the first classification loss function can be determined based on the undetermined sample melody and the music theory label of the interference sample; and the sum of the first reconstruction loss value and the first classification loss value can be used as the first loss value.
[0063] For example, after obtaining the undetermined sample melody, multiple undetermined music theory labels corresponding to the undetermined sample melody can be determined. Based on the multiple undetermined music theory labels and the music theory labels of the interfering samples, the first classification loss value corresponding to the first classification loss function is determined. The first classification loss value can characterize the similarity between the multiple undetermined music theory labels corresponding to the undetermined sample melody and the music theory labels of the interfering samples. The higher the similarity, the more the undetermined sample melody satisfies the music theory labels of the interfering samples. Then, after obtaining the first generated sample melody, the first reconstruction loss value can be calculated based on the first target sample melody and the first generated sample melody. Finally, the sum of the first classification loss value and the first reconstruction loss value is calculated, and this sum is used as the first loss value.
[0064] like Figure 3As shown, after obtaining the melody of the undetermined sample, the first classification loss value can be determined by a pre-trained classifier model. The classifier model can be trained by referring to the model training methods of existing technologies, which will not be elaborated here. Figure 4 This is a schematic diagram of a classifier model according to an exemplary embodiment of the present disclosure, such as... Figure 4 As shown, after inputting the undetermined sample melody into the classifier model, multiple undetermined music theory labels (label 1, label 2, label 3, label 4, ...) corresponding to the undetermined sample melody can be obtained.
[0065] Furthermore, after obtaining the first loss value, the parameters of the first target neural network model can be updated through backpropagation to obtain the trained first target neural network model, and the trained first target neural network model can be used as the new first target neural network model.
[0066] The first target neural network model is optimized by the first loss value. The first classification loss function can enhance the constraint effect of the music theory label of the interference sample on the first target neural network model. The first reconstruction loss function can make the first generated sample melody output by the first target neural network model as similar as possible to the first sample melody under the action of the first classification loss function.
[0067] In one possible implementation, the parameters of the melody latent vector acquisition model and the label vector acquisition model can be updated using the first loss function. For example, the parameters of the melody latent vector acquisition model and the label vector acquisition model can be updated using the first loss value.
[0068] By using the above method to constrain the melody generation model with multiple music theory labels, we can avoid the uncontrollable situation in the melody generation process, thus improving the quality of the generated melody.
[0069] Figure 5 This is a flowchart illustrating another method for generating a melody according to an exemplary embodiment of the present disclosure, such as... Figure 5 As shown, the method may include:
[0070] S501, Get the preset melody.
[0071] The preset melody can be a base melody used to generate more melodies.
[0072] S502. Input the preset melody into the pre-trained melody latent vector acquisition model to obtain the target melody latent vector output by the melody latent vector acquisition model.
[0073] The melody latent vector acquisition model is trained in the following way:
[0074] Multiple second sample sets are obtained, each including a second sample melody and multiple corresponding music theory labels. Based on these second sample sets, the second target neural network model is iteratively trained using its second loss function to obtain the melody latent vector acquisition model. This second target neural network model can be a decoder within a conditional variational autoencoder.
[0075] Before iteratively training the second-target neural network model using the second loss function of the second-target neural network model based on multiple second sample sets, for each second sample set, second-target music theory label vectors corresponding to multiple second sample music theory labels of that second sample set are obtained. Then, based on the multiple second sample melodies and multiple second-target music theory label vectors, the second-target neural network model is iteratively trained using the second loss function of the second-target neural network model to obtain the melody latent vector acquisition model. This label vector acquisition model may include a random mask layer and a linear layer.
[0076] For example, after obtaining multiple second sample sets, for the multiple second sample music theory labels of each second sample set, the second music theory label vector corresponding to each second music theory label can be obtained first. After inputting the multiple second sample music theory label vectors into a pre-trained label vector acquisition model, the combination of music theory labels corresponding to the multiple second sample music theory labels can be obtained through the random mask layer of the label vector acquisition model. The label vector acquisition model can be trained with reference to the model training method of the existing technology, which will not be elaborated here. Figure 6 This is a flowchart illustrating a method for obtaining music theory label vectors according to an exemplary embodiment of this disclosure, such as... Figure 6 As shown, multiple second-sample music theory labels include label 1, label 2, label 3, label 4, ... First, obtain the second music theory label vector corresponding to each label (vector 1, vector 2, vector 3, vector 4, vector n in the figure). The music theory label combination obtained after obtaining the random mask layer of the model through this label vector can include label 2 and label 4 (label 1 and label 4 are identified as 1). Then, the second music theory label vectors corresponding to multiple second-sample music theory labels in this music theory label combination can be added together to obtain the second target music theory label vector corresponding to multiple second-sample music theory labels. This results in a more diverse second target music theory label vector, leading to higher accuracy in obtaining the melody latent vector from the model generated based on the second target music theory label vector.
[0077] In one possible implementation, after acquiring multiple second sample sets, the second model training step can be executed cyclically until the trained second target neural network model satisfies the second preset stopping iteration condition based on the second sample melody and the second target sample melody. The trained second target neural network model is then used as the latent vector acquisition model for the melody. The second target sample melody is acquired through the first target neural network model and the trained second target neural network model.
[0078] Figure 7 This is a flowchart illustrating the second model training step according to an exemplary embodiment of the present disclosure, such as... Figure 7 As shown, the second model training step may include:
[0079] S71. Input multiple second sample melodies into the second target neural network model to obtain the second sample melody latent vector corresponding to each second sample melody output by the second target neural network model.
[0080] S72. Input multiple second sample melody latent vectors into the first target neural network model to obtain the second target sample melody corresponding to each second sample melody latent vector output by the first target neural network model.
[0081] S73. If it is determined that the second target neural network model does not meet the second preset stopping iteration condition based on the second sample melody and the second target sample melody, the second loss value corresponding to the second loss function is determined based on multiple second target sample melodies and multiple second sample melodies. The parameters of the second target neural network model are updated based on the second loss value to obtain the trained second target neural network model. The trained second target neural network model is then used as the new second target neural network model.
[0082] The second loss function can be the reconstruction loss function.
[0083] S503, Obtain multiple target music theory tags.
[0084] In this step, after obtaining the preset melody, multiple preset music theory labels corresponding to the preset melody can be determined. The user can adjust these multiple preset music theory labels to obtain multiple target music theory labels. These multiple target music theory labels can be music theory labels obtained by adjusting each of the preset music theory labels, or they can be music theory labels obtained by adjusting some of the preset music theory labels. For example, if the multiple preset music theory labels include a melody curve, chords, and rhythm, the multiple target music theory labels can be music theory labels obtained by adjusting all of the melody curve, chords, and rhythm; in this case, the multiple target music theory labels can also be music theory labels obtained by adjusting only the chords and rhythm, in which case the multiple target music theory labels include both chords and rhythm.
[0085] S504. Input the latent vector of the target melody and multiple target music theory labels into the pre-trained melody generation model to obtain the target melody output by the melody generation model.
[0086] By employing the aforementioned method and constraining the model with multiple music theory labels, the decoupling ability of the model to conditional constraints and melody generation is improved during the training of the melody generation model and the latent vector acquisition model. This avoids uncontrollable situations during melody generation, thus improving the quality of the generated melody. Furthermore, since the number of music theory labels introduced in this disclosure is not limited to chords and rhythms, the constraints of more music theory labels result in a more refined granularity of the generated melody, further improving the quality and stability of melody generation.
[0087] Figure 8 This is a schematic diagram illustrating a melody contrast according to an exemplary embodiment of the present disclosure, such as... Figure 8 As shown, lines 1, 3, 5, 7, and 9 represent melodies generated by the disclosed melody generation model under the constraints of the same chords and melodic direction but different numbers of notes. It can be seen that the number of generated melody MIDI sequences increases, but the melodic direction does not change significantly. Figure 8 It can be seen that the melodies generated by the melody generation model disclosed in this paper have relatively high stability.
[0088] Figure 9 This is a block diagram illustrating an apparatus for generating a melody according to an exemplary embodiment of the present disclosure, such as... Figure 9 As shown, the device may include:
[0089] Module 901 is used to acquire the latent vector of the target melody and multiple target music theory labels;
[0090] The generation module 902 is used to input the latent vector of the target melody and multiple target music theory labels into a pre-trained melody generation model to obtain the target melody output by the melody generation model; wherein, the melody generation model is trained by a first sample set including a first sample melody and multiple first sample music theory labels corresponding to the first sample melody.
[0091] Optionally, the generation module 902 is also used for:
[0092] Obtain multiple first sample sets;
[0093] Based on multiple first sample sets, the first target neural network model is iteratively trained using the first loss function of the first target neural network model to obtain the melody generation model. The first loss function is used to take the music theory labels of multiple first samples as constraints on the first target neural network model.
[0094] Optionally, the generation module 902 is also used for:
[0095] The first model training step is executed repeatedly until the trained first target neural network model satisfies the first preset stopping iteration condition based on the first target sample melody and the first generated sample melody. The trained first target neural network model is then used as the melody generation model. The first target sample melody is any one of the multiple first sample melodies, and the first generated sample melody is the melody output by the trained first target neural network model.
[0096] The first model training steps include:
[0097] Obtain the first target sample melody and the interference sample music theory label. The interference sample music theory label includes multiple first sample music theory labels corresponding to any first sample melody in the first remaining sample melody. The first remaining sample melody includes multiple first sample melodies other than the first target sample melody.
[0098] Based on the first target sample melody, the interference sample music theory label, and multiple first sample music theory labels corresponding to the first target sample melody, the first generated sample melody is obtained through the first target neural network model;
[0099] If, based on the first target sample melody and the first generated sample melody, it is determined that the first target neural network model does not meet the first preset stopping iteration condition, the first loss value corresponding to the first loss function is determined, the parameters of the first target neural network model are updated according to the first loss value, the trained first target neural network model is obtained, and the trained first target neural network model is used as the new first target neural network model.
[0100] Optionally, the generation module 902 is also used for:
[0101] Obtain the latent vector of the first target sample melody corresponding to the first target sample melody;
[0102] The latent vector of the first target sample melody and the music theory label of the interference sample are input into the first target neural network model to obtain the undetermined sample melody output by the first target neural network model;
[0103] Obtain the latent vector of the undetermined sample melody;
[0104] The latent vector of the undetermined sample melody and the multiple music theory labels corresponding to the first target sample melody are input into the first target neural network model to obtain the first generated sample melody output by the first target neural network model.
[0105] Optionally, the first loss function includes a first reconstruction loss function and a first classification loss function, and the generation module 902 is further configured to:
[0106] Based on the first target sample melody and the first generated sample melody, determine the first reconstruction loss value corresponding to the first reconstruction loss function;
[0107] Based on the melody of the undetermined sample and the music theory label of the interference sample, determine the first classification loss value corresponding to the first classification loss function;
[0108] The sum of the first reconstruction loss value and the first classification loss value is taken as the first loss value.
[0109] Optionally, the acquisition module 901 is also used for:
[0110] Get the preset melody;
[0111] The preset melody is input into a pre-trained melody latent vector acquisition model to obtain the target melody latent vector output by the melody latent vector acquisition model.
[0112] Optionally, the acquisition module 901 is also used for:
[0113] Obtain multiple second sample sets, which include second sample melodies and multiple second sample music theory labels corresponding to each second sample melody;
[0114] Based on multiple sets of the second sample, the second target neural network model is iteratively trained using the second loss function of the second target neural network model to obtain the melody latent vector acquisition model.
[0115] Optionally, the acquisition module 901 is also used for:
[0116] The second model training step is executed repeatedly until the trained second target neural network model satisfies the second preset stopping iteration condition based on the second sample melody and the second target sample melody. The trained second target neural network model is then used as the latent vector acquisition model for the melody. The second target sample melody is acquired through the first target neural network model and the trained second neural network model.
[0117] The training steps for the second model include:
[0118] Multiple second sample melodies are input into the second target neural network model to obtain the second sample melody latent vector corresponding to each second sample melody output by the second target neural network model.
[0119] Multiple latent vectors of the second sample melody are input into the first target neural network model to obtain the second target sample melody corresponding to each latent vector of the second sample melody output by the first target neural network model.
[0120] If the second target neural network model does not meet the second preset stopping iteration condition based on the second sample melody and the second target sample melody, the second loss value corresponding to the second loss function is determined based on multiple second target sample melodies and multiple second sample melodies. The parameters of the second target neural network model are updated based on the second loss value to obtain the trained second target neural network model. The trained second target neural network model is then used as the new second target neural network model.
[0121] Optionally, the acquisition module 901 is also used for:
[0122] For each of the second sample sets, obtain the second target music theory label vector corresponding to multiple music theory labels of the second sample in the second sample set;
[0123] Based on multiple sets of the second sample, the second target neural network model is iteratively trained using its second loss function to obtain the melody latent vector acquisition model, which includes:
[0124] Based on multiple second sample melodies and multiple second target music theory label vectors, the second target neural network model is iteratively trained using the second loss function of the second target neural network model to obtain the melody latent vector acquisition model.
[0125] Optionally, the generation module 902 is also used for:
[0126] The parameters of the melody latent vector acquisition model and the label vector acquisition model are updated using the first loss function.
[0127] By using the aforementioned device and constraining the melody generation model with multiple music theory labels, the uncontrollable situation during the melody generation process can be avoided, thereby improving the quality of the generated melody.
[0128] Regarding the apparatus in the above embodiments, the specific manner in which each module performs its operation has been described in detail in the embodiments related to the method, and will not be elaborated upon here.
[0129] The following is for reference. Figure 10 The diagram illustrates a structural schematic of an electronic device 1000 suitable for implementing embodiments of the present disclosure. The terminal devices in the embodiments of the present disclosure may include, but are not limited to, mobile terminals such as mobile phones, laptops, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), in-vehicle terminals (e.g., in-vehicle navigation terminals), and fixed terminals such as digital TVs and desktop computers. Figure 10 The electronic device shown is merely an example and should not be construed as limiting the functionality and scope of the embodiments disclosed herein.
[0130] like Figure 10 As shown, the electronic device 1000 may include a processing unit (e.g., a central processing unit, a graphics processor, etc.) 1001, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 1002 or a program loaded from a storage device 1008 into a random access memory (RAM) 1003. The RAM 1003 also stores various programs and data required for the operation of the electronic device 1000. The processing unit 1001, ROM 1002, and RAM 1003 are interconnected via a bus 1004. An input / output (I / O) interface 1005 is also connected to the bus 1004.
[0131] Typically, the following devices can be connected to the I / O interface 1005: input devices 1006 including, for example, a touchscreen, touchpad, keyboard, mouse, camera, microphone, accelerometer, gyroscope, etc.; output devices 1007 including, for example, a liquid crystal display (LCD), speaker, vibrator, etc.; storage devices 1008 including, for example, magnetic tape, hard disk, etc.; and communication devices 1009. Communication device 1009 allows electronic device 1000 to communicate wirelessly or wiredly with other devices to exchange data. Although Figure 10 An electronic device 1000 with various devices is shown; however, it should be understood that it is not required to implement or possess all of the devices shown. More or fewer devices may be implemented or possessed alternatively.
[0132] In particular, according to embodiments of this disclosure, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments of this disclosure include a computer program product comprising a computer program carried on a non-transitory computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via communication device 1009, or installed from storage device 1008, or installed from ROM 1002. When the computer program is executed by processing device 1001, it performs the functions defined in the methods of embodiments of this disclosure.
[0133] It should be noted that the computer-readable medium described in this disclosure can be a computer-readable signal medium or a computer-readable storage medium, or any combination thereof. A computer-readable storage medium can be, for example,—but not limited to—an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this disclosure, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in connection with an instruction execution system, apparatus, or device. In this disclosure, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A computer-readable signal medium can be any computer-readable medium other than a computer-readable storage medium, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to: wires, optical fibers, RF (radio frequency), etc., or any suitable combination thereof.
[0134] In some implementations, clients and servers can communicate using any currently known or future-developed network protocol such as HTTP (Hypertext Transfer Protocol) and can interconnect with digital data communication (e.g., communication networks) of any form or medium. Examples of communication networks include local area networks (“LANs”), wide area networks (“WANs”), the Internet (e.g., the Internet of Things), and peer-to-peer networks (e.g., ad hoc peer-to-peer networks), as well as any currently known or future-developed networks.
[0135] The aforementioned computer-readable medium may be included in the aforementioned electronic device; or it may exist independently and not assembled into the electronic device.
[0136] The aforementioned computer-readable medium carries one or more programs, which, when executed by the electronic device, cause the electronic device to: acquire a target melody latent vector and multiple target music theory labels; input the target melody latent vector and multiple target music theory labels into a pre-trained melody generation model to obtain a target melody output by the melody generation model; wherein the melody generation model is trained using a first sample set including a first sample melody and multiple first sample music theory labels corresponding to the first sample melody.
[0137] Computer program code for performing the operations of this disclosure can be written in one or more programming languages or a combination thereof, including but not limited to object-oriented programming languages such as Java, Smalltalk, and C++, as well as conventional procedural programming languages such as the "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including a local area network (LAN) or a wide area network (WAN)—or can be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0138] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this disclosure. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.
[0139] The modules described in the embodiments of this disclosure can be implemented in software or in hardware. The names of the modules are not necessarily limiting in certain circumstances; for example, an acquisition module can also be described as "a module for acquiring the latent vector of a target melody and multiple target music theory labels".
[0140] The functions described above in this document can be performed, at least in part, by one or more hardware logic components. For example, exemplary types of hardware logic components that can be used, without limitation, include: Field Programmable Gate Arrays (FPGAs), Application-Specific Integrated Circuits (ASICs), Application Standard Products (ASSPs), System-on-Chip (SoCs), Complex Programmable Logic Devices (CPLDs), and so on.
[0141] In the context of this disclosure, a machine-readable medium can be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, apparatus, or device. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can be, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
[0142] According to one or more embodiments of this disclosure, Example 1 provides a method for generating a melody, the method comprising: obtaining a target melody latent vector and a plurality of target music theory labels; inputting the target melody latent vector and the plurality of target music theory labels into a pre-trained melody generation model to obtain a target melody output by the melody generation model; wherein the melody generation model is trained by a first sample set including a first sample melody and a plurality of first sample music theory labels corresponding to the first sample melody.
[0143] According to one or more embodiments of this disclosure, Example 2 provides the method of Example 1, wherein the melody generation model is trained by a first sample set including a first sample melody and a plurality of first sample music theory labels corresponding to the first sample melody, comprising: acquiring a plurality of first sample sets; iteratively training the first target neural network model using a first loss function of the first target neural network model based on the plurality of first sample sets to obtain the melody generation model, wherein the first loss function is used to use the plurality of first sample music theory labels as constraints on the first target neural network model.
[0144] According to one or more embodiments of this disclosure, Example 3 provides the method of Example 2, wherein the step of iteratively training the first target neural network model using a first loss function of the first target neural network model based on a plurality of first sample sets to obtain the melody generation model includes: repeatedly executing a first model training step until the trained first target neural network model satisfies a first preset stopping iteration condition based on the first target sample melody and the first generated sample melody, and using the trained first target neural network model as the melody generation model; the first target sample melody is any one of a plurality of first sample melody, and the first generated sample melody is the melody output by the trained first target neural network model; the first model training step includes: obtaining the first target sample melody and interference sample music theory labels, wherein the interference sample music theory labels include a first remaining sample melody. The system includes multiple first sample music theory labels corresponding to any first sample melody in the law, and the first remaining sample melody includes first sample melodies other than the first target sample melody among the multiple first sample melodies; based on the first target sample melody, the interference sample music theory labels, and the multiple first sample music theory labels corresponding to the first target sample melody, the first generated sample melody is obtained through the first target neural network model; if it is determined that the first target neural network model does not meet the first preset stopping iteration condition based on the first target sample melody and the first generated sample melody, the first loss value corresponding to the first loss function is determined, the parameters of the first target neural network model are updated according to the first loss value, the trained first target neural network model is obtained, and the trained first target neural network model is used as the new first target neural network model.
[0145] According to one or more embodiments of this disclosure, Example 4 provides the method of Example 3, wherein obtaining the first generated sample melody through the first target neural network model based on the first target sample melody, the interference sample music theory labels, and a plurality of first sample music theory labels corresponding to the first target sample melody includes: obtaining the first target sample melody latent vector corresponding to the first target sample melody; inputting the first target sample melody latent vector and the interference sample music theory labels into the first target neural network model to obtain the undetermined sample melody output by the first target neural network model; obtaining the undetermined sample melody latent vector corresponding to the undetermined sample melody; inputting the undetermined sample melody latent vector and the plurality of first sample music theory labels corresponding to the first target sample melody into the first target neural network model to obtain the first generated sample melody output by the first target neural network model.
[0146] According to one or more embodiments of this disclosure, Example 5 provides the method of Example 4, wherein the first loss function includes a first reconstruction loss function and a first classification loss function, and the step of determining the first loss value corresponding to the first loss function includes: determining the first reconstruction loss value corresponding to the first reconstruction loss function based on the first target sample melody and the first generated sample melody; determining the first classification loss value corresponding to the first classification loss function based on the undetermined sample melody and the interference sample music theory label; and taking the sum of the first reconstruction loss value and the first classification loss value as the first loss value.
[0147] According to one or more embodiments of this disclosure, Example 6 provides a method for any of Examples 2-5, wherein obtaining the target melody latent vector includes: obtaining a preset melody; inputting the preset melody into a pre-trained melody latent vector acquisition model to obtain the target melody latent vector output by the melody latent vector acquisition model.
[0148] According to one or more embodiments of this disclosure, Example 7 provides the method of Example 6, wherein the melody latent vector acquisition model is trained by: acquiring a plurality of second sample sets, the second sample sets including second sample melodies and a plurality of second sample music theory labels corresponding to each second sample melodies; and iteratively training the second target neural network model using a second loss function of the second target neural network model based on the plurality of second sample sets to obtain the melody latent vector acquisition model.
[0149] According to one or more embodiments of this disclosure, Example 8 provides the method of Example 7, wherein the step of iteratively training the second target neural network model using a second loss function of the second target neural network model based on a plurality of second sample sets to obtain the melody latent vector acquisition model includes: repeatedly executing the second model training step until it is determined that the trained second target neural network model meets a second preset stopping iteration condition based on the second sample melody and the second target sample melody, and using the trained second target neural network model as the melody latent vector acquisition model; the second target sample melody is obtained through the first target neural network model and the trained second target neural network model; the second model training step includes: inputting a plurality of second sample melodies into the second target neural network model to obtain the second target melody. The neural network model outputs a second sample melody hidden vector corresponding to each second sample melody; multiple second sample melody hidden vectors are input into the first target neural network model to obtain the second target sample melody corresponding to each second sample melody hidden vector output by the first target neural network model; if the second target neural network model does not meet the second preset stopping iteration condition based on the second sample melody and the second target sample melody, the second loss value corresponding to the second loss function is determined based on the multiple second target sample melodies and the multiple second sample melodies, and the parameters of the second target neural network model are updated based on the second loss value to obtain the trained second target neural network model, and the trained second target neural network model is used as the new second target neural network model.
[0150] According to one or more embodiments of this disclosure, Example 9 provides the method of Example 7, which, before iteratively training the second target neural network model using a second loss function of the second target neural network model based on a plurality of second sample sets to obtain the melody latent vector acquisition model, further includes: for each second sample set, obtaining second target music theory label vectors corresponding to a plurality of second sample music theory labels of the second sample set; the iterative training of the second target neural network model using a second loss function of the second target neural network model based on a plurality of second sample sets to obtain the melody latent vector acquisition model includes: iteratively training the second target neural network model using a second loss function of the second target neural network model based on a plurality of second sample melodies and a plurality of second target music theory label vectors to obtain the melody latent vector acquisition model.
[0151] According to one or more embodiments of this disclosure, Example 10 provides the method of Example 9, the method further comprising: updating the parameters of the melody latent vector acquisition model and the label vector acquisition model through the first loss function.
[0152] According to one or more embodiments of this disclosure, Example 11 provides an apparatus for generating a melody, the apparatus comprising: an acquisition module for acquiring a target melody latent vector and a plurality of target music theory labels; and a generation module for inputting the target melody latent vector and the plurality of target music theory labels into a pre-trained melody generation model to obtain a target melody output by the melody generation model; wherein the melody generation model is trained using a first sample set including a first sample melody and a plurality of first sample music theory labels corresponding to the first sample melody.
[0153] According to one or more embodiments of this disclosure, Example 12 provides the apparatus of Example 11, wherein the generation module is further configured to: acquire a plurality of first sample sets; and iteratively train the first target neural network model using a first loss function of the first target neural network model based on the plurality of first sample sets to obtain the melody generation model, wherein the first loss function is used to use the music theory labels of the plurality of first samples as constraints on the first target neural network model.
[0154] According to one or more embodiments of this disclosure, Example 13 provides the apparatus of Example 12, wherein the generation module is further configured to: cyclically execute a first model training step until a trained first target neural network model is determined to satisfy a first preset stopping iteration condition based on a first target sample melody and a first generated sample melody, and use the trained first target neural network model as the melody generation model; the first target sample melody is any one of a plurality of first sample melodies, and the first generated sample melody is the melody output by the trained first target neural network model; the first model training step includes: acquiring the first target sample melody and interference sample music theory labels, wherein the interference sample music theory labels include a plurality of first sample music theory labels corresponding to any one of the first remaining sample melodies, and so on. The first remaining sample melody includes a plurality of first sample melodies other than the first target sample melody; based on the first target sample melody, the interference sample music theory labels, and the plurality of first sample music theory labels corresponding to the first target sample melody, the first generated sample melody is obtained through the first target neural network model; if it is determined that the first target neural network model does not meet the first preset stopping iteration condition based on the first target sample melody and the first generated sample melody, the first loss value corresponding to the first loss function is determined, the parameters of the first target neural network model are updated according to the first loss value, the trained first target neural network model is obtained, and the trained first target neural network model is used as the new first target neural network model.
[0155] According to one or more embodiments of this disclosure, Example 14 provides the apparatus of Example 13, wherein the generation module is further configured to: obtain a first target sample melody latent vector corresponding to the first target sample melody; input the first target sample melody latent vector and the interference sample music theory labels into the first target neural network model to obtain a pending sample melody output by the first target neural network model; obtain a pending sample melody latent vector corresponding to the pending sample melody; input the pending sample melody latent vector and a plurality of first sample music theory labels corresponding to the first target sample melody into the first target neural network model to obtain the first generated sample melody output by the first target neural network model.
[0156] According to one or more embodiments of this disclosure, Example 15 provides an apparatus of Example 14, wherein the first loss function includes a first reconstruction loss function and a first classification loss function, and the generation module is further configured to: determine a first reconstruction loss value corresponding to the first reconstruction loss function based on the first target sample melody and the first generated sample melody; determine a first classification loss value corresponding to the first classification loss function based on the undetermined sample melody and the interference sample music theory label; and take the sum of the first reconstruction loss value and the first classification loss value as the first loss value.
[0157] According to one or more embodiments of this disclosure, Example 16 provides an apparatus of any of Examples 12-14, wherein the acquisition module is further configured to: acquire a preset melody; input the preset melody into a pre-trained melody latent vector acquisition model to acquire the target melody latent vector output by the melody latent vector acquisition model.
[0158] According to one or more embodiments of this disclosure, Example 17 provides the apparatus of Example 16, wherein the acquisition module is further configured to: acquire a plurality of second sample sets, the second sample sets including second sample melodies and a plurality of second sample music theory labels corresponding to each second sample melodies; and iteratively train the second target neural network model using a second loss function of the second target neural network model based on the plurality of second sample sets to obtain the melody latent vector acquisition model.
[0159] According to one or more embodiments of this disclosure, Example 18 provides the apparatus of Example 17, wherein the acquisition module is further configured to: cyclically execute a second model training step until it is determined, based on the second sample melody and the second target sample melody, that the trained second target neural network model satisfies a second preset stopping iteration condition, and use the trained second target neural network model as the melody latent vector acquisition model; the second target sample melody is acquired through the first target neural network model and the trained second target neural network model; the second model training step includes: inputting multiple second sample melodies into the second target neural network model to obtain a second sample melody latent vector corresponding to each second sample melody output by the second target neural network model; inputting multiple second sample melody latent vectors into the first target neural network model to obtain a second target sample melody corresponding to each second sample melody latent vector output by the first target neural network model; if it is determined, based on the second sample melody and the second target sample melody, that the second target neural network model does not satisfy the second preset stopping iteration condition, determining a second loss value corresponding to the second loss function based on the multiple second target sample melodies and the multiple second sample melodies, updating the parameters of the second target neural network model based on the second loss value, obtaining a trained second target neural network model, and using the trained second target neural network model as a new second target neural network model.
[0160] According to one or more embodiments of this disclosure, Example 19 provides the apparatus of Example 17, wherein the acquisition module is further configured to: for each second sample set, acquire a second target music theory label vector corresponding to a plurality of second sample music theory labels of the second sample set; the step of iteratively training the second target neural network model using a second loss function of the second target neural network model based on the plurality of second sample sets to obtain the melody latent vector acquisition model includes: iteratively training the second target neural network model using a second loss function of the second target neural network model based on a plurality of second sample melodies and a plurality of second target music theory label vectors to obtain the melody latent vector acquisition model.
[0161] According to one or more embodiments of this disclosure, Example 20 provides the apparatus of Example 19, wherein the generation module is further configured to: update the parameters of the melody latent vector acquisition model and the label vector acquisition model through the first loss function.
[0162] According to one or more embodiments of the present disclosure, Example 21 provides a computer-readable medium having a computer program stored thereon that, when executed by a processing device, implements the steps of the method described in any of Examples 1-10.
[0163] According to one or more embodiments of this disclosure, Example 22 provides an electronic device including: a storage device having at least one computer program stored thereon; and at least one processing device for executing the at least one computer program in the storage device to implement the steps of the method described in any of Examples 1-10.
[0164] The above description is merely a preferred embodiment of this disclosure and an explanation of the technical principles employed. Those skilled in the art should understand that the scope of this disclosure is not limited to technical solutions formed by specific combinations of the above-described technical features, but should also cover other technical solutions formed by arbitrary combinations of the above-described technical features or their equivalents without departing from the above-described concept. For example, technical solutions formed by substituting the above features with (but not limited to) technical features disclosed in this disclosure that have similar functions.
[0165] Furthermore, while the operations are described in a specific order, this should not be construed as requiring these operations to be performed in the specific order shown or in a sequential order. In certain environments, multitasking and parallel processing may be advantageous. Similarly, while several specific implementation details are included in the above discussion, these should not be construed as limiting the scope of this disclosure. Certain features described in the context of individual embodiments may also be implemented in combination in a single embodiment. Conversely, various features described in the context of a single embodiment may also be implemented individually or in any suitable sub-combination in multiple embodiments.
[0166] Although the subject matter has been described using language specific to structural features and / or methodological logic, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or actions described above. Rather, the specific features and actions described above are merely illustrative forms of implementing the claims. Regarding the apparatus in the above embodiments, the specific manner in which the various modules perform their operations has been described in detail in the embodiments relating to the method, and will not be elaborated upon here.
Claims
1. A method of generating a melody, characterized by, The method comprises: obtaining a target melody hidden vector and a plurality of target music theory labels; inputting the target melody hidden vector and the plurality of target music theory labels into a pre-trained melody generation model to obtain a target melody output by the melody generation model; wherein the melody generation model is trained by a first sample set comprising a first sample melody and a plurality of first sample music theory labels corresponding to the first sample melody; The melody generation model is trained by a first sample set comprising a first sample melody and a plurality of first sample music theory labels corresponding to the first sample melody, comprising: obtaining a plurality of first sample sets; iteratively training the first target neural network model according to the plurality of first sample sets through a first loss function of the first target neural network model until the trained first target neural network model meets a first preset stopping iteration condition according to a first target sample melody and a first generated sample melody, and taking the trained first target neural network model as the melody generation model, wherein the first loss function is used to take the plurality of first sample music theory labels as a constraint condition of the first target neural network model, the first target sample melody is any first sample melody in the plurality of first sample melodies, and the first generated sample melody is a melody output by the trained first target neural network model according to the first target sample melody, an interference sample music theory label, and the plurality of first sample music theory labels corresponding to the first target sample melody; the interference sample music theory label comprises a plurality of first sample music theory labels corresponding to any first sample melody in a first remaining sample melody, and the first remaining sample melody comprises first sample melodies other than the first target sample melody in the plurality of first sample melodies.
2. The method of claim 1, wherein, The iteratively training the first target neural network model according to the plurality of first sample sets through a first loss function of the first target neural network model comprises: recursively performing a first model training step, the first model training step comprising: obtaining the first target sample melody and the interference sample music theory label; obtaining the first generated sample melody through the first target neural network model according to the first target sample melody, the interference sample music theory label, and the plurality of first sample music theory labels corresponding to the first target sample melody; in a case where it is determined that the first target neural network model does not meet the first preset stopping iteration condition according to the first target sample melody and the first generated sample melody, determining a first loss value corresponding to the first loss function, updating parameters of the first target neural network model according to the first loss value to obtain a trained first target neural network model, and taking the trained first target neural network model as a new first target neural network model.
3. The method of claim 2, wherein, The obtaining the first generated sample melody through the first target neural network model according to the first target sample melody, the interference sample music theory label, and the plurality of first sample music theory labels corresponding to the first target sample melody comprises: obtaining a first target sample melody hidden vector corresponding to the first target sample melody; inputting the first target sample melody hidden vector and the interference sample music notation label into the first target neural network model to obtain a pending sample melody output by the first target neural network model; obtaining a pending sample melody hidden vector corresponding to the pending sample melody; inputting the pending sample melody hidden vector and the plurality of first sample music notation labels corresponding to the first target sample melody into the first target neural network model to obtain the first generated sample melody output by the first target neural network model.
4. The method of claim 3, wherein, The first loss function includes a first reconstruction loss function and a first classification loss function, and the determination of the first loss value corresponding to the first loss function includes: determining a first reconstruction loss value corresponding to the first reconstruction loss function according to the first target sample melody and the first generated sample melody; determining a first classification loss value corresponding to the first classification loss function according to the pending sample melody and the interference sample music notation label; taking the sum of the first reconstruction loss value and the first classification loss value as the first loss value.
5. The method according to any one of claims 1 to 4, characterized in that, The target melody hidden vector includes: obtaining a preset melody; inputting the preset melody into a pre-trained melody hidden vector obtaining model to obtain the target melody hidden vector output by the melody hidden vector obtaining model.
6. The method of claim 5, wherein, The melody hidden vector obtaining model is trained in the following way: obtaining a plurality of second sample sets, each second sample set including a second sample melody and a plurality of second sample music notation labels corresponding to each second sample melody; iteratively training the second target neural network model through a second loss function of the second target neural network model according to a plurality of second sample sets to obtain the melody hidden vector obtaining model.
7. The method of claim 6, wherein, The iteratively training the second target neural network model through a second loss function of the second target neural network model according to a plurality of second sample sets to obtain the melody hidden vector obtaining model includes: performing a second model training step in a loop until a trained second target neural network model meets a second preset stop iteration condition according to the second sample melody and a second target sample melody obtained by the first target neural network model and the trained second target neural network model, and taking the trained second target neural network model as the melody hidden vector obtaining model; The second model training step includes: inputting a plurality of second sample melodies into the second target neural network model to obtain a second sample melody hidden vector corresponding to each second sample melody output by the second target neural network model; inputting a plurality of second sample melody hidden vectors into the first target neural network model to obtain a second target sample melody corresponding to each second sample melody hidden vector output by the first target neural network model; In a case where it is determined that the second target neural network model does not meet the second preset stop iteration condition according to the second sample melody and the second target sample melody, a second loss value corresponding to the second loss function is determined according to a plurality of the second target sample melodies and a plurality of the second sample melodies, parameters of the second target neural network model are updated according to the second loss value, a trained second target neural network model is obtained, and the trained second target neural network model is taken as a new second target neural network model.
8. The method of claim 6, wherein, Before the step of iteratively training the second target neural network model according to a plurality of the second sample sets by using the second loss function of the second target neural network model to obtain the melody hidden vector obtaining model, the method further includes: For each of the second sample sets, a second target musical notation label vector corresponding to a plurality of the second sample musical notation labels of the second sample set is obtained. The step of iteratively training the second target neural network model according to a plurality of the second sample sets by using the second loss function of the second target neural network model to obtain the melody hidden vector obtaining model includes: The second target neural network model is iteratively trained by using the second loss function of the second target neural network model according to a plurality of the second sample melodies and a plurality of the second target musical notation label vectors to obtain the melody hidden vector obtaining model.
9. The method of claim 8, wherein, The method further includes: Parameters of the melody hidden vector obtaining model and a label vector obtaining model are updated by using the first loss function, and the label vector obtaining model is used to determine a corresponding second target musical notation label vector according to a plurality of the second sample musical notation labels of the second sample set.
10. An apparatus for generating a melody, characterized by The apparatus includes: The obtaining module is configured to obtain a target melody hidden vector and a plurality of target musical notation labels. The generating module is configured to input the target melody hidden vector and the plurality of target musical notation labels into a pre-trained melody generation model to obtain a target melody output by the melody generation model, wherein the melody generation model is trained by using a first sample set including a first sample melody and a plurality of first sample musical notation labels corresponding to the first sample melody. The generating module is further configured to: Obtain a plurality of first sample sets. According to a plurality of the first sample sets, a first loss function of a first target neural network model is used to iteratively train the first target neural network model until the trained first target neural network model meets a first preset stop iteration condition according to a first target sample melody and a first generated sample melody, the trained first target neural network model is used as the melody generation model, the first loss function is used to take a plurality of the first sample music notation labels as a constraint condition of the first target neural network model, the first target sample melody is any first sample melody in the plurality of the first sample melodies, the first generated sample melody is a melody output by the trained first target neural network model according to the first target sample melody, an interference sample music notation label, and a plurality of the first sample music notation labels corresponding to the first target sample melody, and the interference sample music notation label includes a plurality of the first sample music notation labels corresponding to any first sample melody in a first remaining sample melody, and the first remaining sample melody includes first sample melodies in the plurality of the first sample melodies except the first target sample melody.
11. A computer readable medium having stored thereon a computer program, characterized in that The program, when executed by a processing device, implements the steps of the method of any one of claims 1-9.
12. An electronic device, comprising: comprising: a storage device having stored thereon at least one computer program; at least one processing device configured to execute the at least one computer program stored in the storage device to implement the steps of the method of any one of claims 1-9.
Citation Information
Patent Citations
Music generation method and device
CN113763910A