Method, device, equipment and medium for generating symbolic music based on random forest
Through the symbolic music generation method based on random forest, the note and style consistency model is trained, combined with the autocorrelation function and Gini impurity, to solve the problem that the existing technology cannot handle pitch, length, loudness and style consistency, and achieve Generate symbolic music whose style meets user requirements, with strong expressiveness and accuracy.
Patent Information
- Application Number
- CN202410713493.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-04
- Publication Date
- 2024-08-30
- Estimated Expiration
- 2044-06-04
AI Technical Summary
Existing technology cannot process music from aspects such as pitch, length, loudness, and style consistency, and it is difficult to automatically generate a continuous and beautiful audio signal.
The symbolic music generation method based on random forest is adopted to obtain sample data sets, extract audio waveforms, identify notes, and train the note random forest model and style consistency model, and combine the autocorrelation function and Gini impurity to classify and generate music features. , forming a symbolic music model.
It captures the detailed characteristics of music more accurately, and the generated symbolic music has strong expressiveness and accuracy in note rules and musical styles, solving the problem of the existing technology being difficult to automatically generate beautiful audio signals.
Smart Images

Figure CN118280325B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of artificial intelligence technology, and in particular to a method, device, equipment and medium for generating symbolic music based on random forest. Background Art
[0002] With the help of deep learning technology, symbolic music generation has made significant progress. However, due to the high complexity and abstractness of music, it is difficult to have an exact method to automatically generate a continuous and beautiful audio signal.
[0003] Random Forest is an ensemble learning method, especially ensemble learning based on decision trees. It builds multiple decision trees and combines their prediction results to improve the stability and accuracy of predictions. This method was first proposed by Leo Breiman and Adele Cutler. Its basic principle is to build multiple decision trees and vote or average the prediction results of these decision trees to obtain the final prediction result. The random forest algorithm has the advantages of high accuracy, the ability to handle a large number of input variables, the ability to evaluate the importance of variables, and easy parallelization.
[0004] However, the existing algorithms for analyzing and generating musical features are relatively simple and only process musical notes. There is no algorithm that can process and learn from aspects such as pitch, duration, loudness and style consistency to generate symbolic music.
[0005] In view of this, the applicant filed this application after studying the existing technology. Summary of the invention
[0006] The present invention aims to provide a method, device, equipment and medium for generating symbolic music based on random forest, so as to solve the problems that the existing methods are unable to process music from aspects such as pitch, duration, loudness and style consistency, and are unable to accurately capture the detailed characteristics of music in different areas.
[0007] In order to solve the above technical problems, the present invention is implemented through the following technical solutions:
[0008] A symbolic music generation method based on random forest, comprising:
[0009] 1. A symbolic music generation method based on random forest, characterized by comprising:
[0010] S1, obtaining a sample data set, wherein the sample data set includes pure music files of various styles, and the format of the pure music files includes MP3 format;
[0011] S2, processing the pure music file to obtain a time domain signal, and using FFT to convert the time domain signal into a frequency domain signal, and extracting an audio waveform;
[0012] S3, processing and analyzing the audio waveform, identifying the notes, and obtaining a music symbol file, wherein the notes include pitch, duration and loudness;
[0013] S4, inputting the music symbol file of the sample data set into the symbolic music model for training, and obtaining a trained symbolic music model; wherein the symbolic music model includes a note random forest model for generating notes and a style consistency model for judging the music style; the note random forest model and the style consistency model respectively generate decision trees through the random forest algorithm, and use the autocorrelation function and Gini impurity to extract features and classify the music symbol file;
[0014] S5, inputting the music description data into the trained symbolic music model to generate a new symbolic music work, wherein the music description data includes a music clip and a text description.
[0015] Preferably, the note random forest model is created by RandomForestClassifier, and its training steps are as follows:
[0016] A1, preprocessing the input music notation file to distinguish the pitch, tone length and loudness data, and marking each music notation file with a style tag to obtain a preprocessed music notation file, wherein the style tags include classical, pop, rock and electronic;
[0017] A2, dividing the preprocessed music notation file into a training set and a test set, wherein the number of style labels in the training set and the test set are evenly distributed;
[0018] A3, inputting the training set into a random forest model for training;
[0019] A4, input the test set into the random forest model for evaluation, and when the evaluation score is greater than the set threshold, a trained random forest model is obtained.
[0020] Preferably, the A3 specifically comprises the following steps:
[0021] A31, using the boostrap sampling method, sampling each sample in the training set every 50ms of music length, and using the autocorrelation function to calculate the audio features of a single audio data block. The calculation formula of the autocorrelation function is:
[0022] ;
[0023] Among them, R(i) represents the similarity, is the value of the tth data in the audio data block, is the mean value of the audio data block, i represents the number of steps of audio data block delay, i=0-K, K is the order of the model, the larger the value of K, the more accurate the feature parameters;
[0024] A32, based on the decision tree of random forest, the audio features are classified by Gini impurity into left and right subtrees until the Gini impurity is less than the threshold or the iteration reaches the maximum tree depth, and a leaf node is generated. The leaf node stores the current audio feature value and the corresponding pitch, tone length and loudness data. The formula of the Gini impurity is:
[0025] ;
[0026] in, represents Gini impurity, P(D) represents the probability of a random sample corresponding to a category, and D is the category number;
[0027] A33, determine whether the number of current decision trees has reached the threshold. If so, complete the training of the random forest model, otherwise return to step A31.
[0028] Preferably, the calculation formula for the evaluation score in step A4 is:
[0029] ;
[0030] The evaluation score F1 represents the harmonic mean of precision and recall, with a maximum value of 1 and a minimum value of 0. The larger the F1 value, the better the model performance.
[0031] , represents the precision rate, x represents the current model number, n represents the number of individuals that are truly positive and predicted to be positive, and N represents the number of individuals predicted to be positive by the model;
[0032] C , represents the recall rate, and M represents the number of truly positive individuals.
[0033] Preferably, the training step of the style consistency model includes:
[0034] B1, sample each sample in the input training set according to the set sample sampling requirements;
[0035] B2, according to each sample, the audio feature of each sample is calculated using the autocorrelation function, and the audio feature is divided into left and right subtrees using Gini impurity, until the Gini impurity is less than a threshold or the iteration reaches the maximum tree depth, and a style leaf node is generated, and the style leaf node stores the audio feature value of the current sample and the corresponding style data;
[0036] B3, determine whether the number of current decision trees reaches the set threshold. If it has reached it, add up the results of all decision trees. If the number of labels in the summed result that are consistent with the original data exceeds half, the style classification is considered correct and the training of the style consistency model is completed. Otherwise, return to step B1.
[0037] Preferably, the sample sampling requirements include short-term style sample sampling requirements and long-term style sample sampling requirements, so as to calculate the mean square error of music rhythm and pitch and judge the quality of music; wherein,
[0038] The short-time style sample sampling requirement is to take the original sample data every Sampling, where [50ms,200ms];
[0039] The long-term style sample sampling requirement is to take the original sample data every Sampling, and the sampled data are the starting 5-10 seconds, the middle 5-10 seconds and the ending 5-10 seconds of the original sample data, [500ms,1000ms].
[0040] The present invention also provides a symbolic music generation device based on random forest, comprising:
[0041] A sample data set construction unit, used to obtain a sample data set, wherein the sample data set includes pure music files of various styles, and the format of the pure music files includes MP3 format;
[0042] An audio waveform analysis unit, used to process the pure music file to obtain a time domain signal, and convert the time domain signal into a frequency domain signal using FFT to extract the audio waveform;
[0043] A note recognition unit, used to process and analyze the audio waveform, recognize notes, and obtain a music notation file, wherein the notes include pitch, duration, and loudness;
[0044] A model training unit is used to obtain a trained symbolic music model, input the music symbol file of the sample data set into the symbolic music model for training, and obtain the trained symbolic music model; wherein the symbolic music model includes a note random forest model for generating notes and a style consistency model for judging the music style; the note random forest model and the style consistency model respectively generate decision trees through the random forest algorithm, and use the autocorrelation function and Gini impurity to extract features and classify the music symbol file;
[0045] The music generation unit is used to obtain a new symbolic music work, acquire music description data, input the music description data into a trained symbolic music model, and generate a new symbolic music work, wherein the music description data includes a music clip and a text description.
[0046] The present invention also provides a symbolic music generation device based on random forest, including a processor and a memory, wherein the memory stores a computer program, and the computer program can be executed by the processor to implement a symbolic music generation method based on random forest as described above.
[0047] The present invention also provides a computer-readable storage medium, on which computer-readable instructions are stored. When the computer-readable instructions are executed by a processor of a device where the computer-readable storage medium is located, a symbolic music generation method based on random forest is implemented as described above.
[0048] In summary, compared with the prior art, the present invention has the following beneficial effects:
[0049] (1) The present invention captures the note and style features by learning a large number of existing music works, performs random forest algorithm learning on the feature values, short-term style and long-term style consistency of the notes, uses Gini impurity and decision trees to classify audio features, trains multiple decision trees to process the pitch, duration, loudness and style consistency features of the music, and generates a fusion model of the note random forest model and the style consistency model, namely, a symbolic music model, and finally uses the symbolic music model to generate symbolic music with a style that meets the user's requirements. The method of the present invention can more accurately capture the detailed features of music in different areas, and the generated symbolic music has strong expressiveness and accuracy in terms of note rules and music style consistency, solving the problem that the existing technology is difficult to automatically generate a continuous and beautiful audio signal.
[0050] (2) The present invention judges the short-term style and long-term style of the generated music respectively to ensure that the generated music work not only has a consistent rhythm and tone style within the music segment, but also the style between the music segments meets the user's needs, so as to optimize the generation of symbolic music works with better overall style. BRIEF DESCRIPTION OF THE DRAWINGS
[0051] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings required for use in the embodiments will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present invention and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.
[0052] Figure 1 A schematic diagram of the structure of a symbolic music generation method based on random forest provided in Example 1 of the present invention.
[0053] Figure 2 A flowchart of a method for generating symbolic music based on random forests is provided in Example 1 of the present invention.
[0054] Figure 3 A flowchart of the random forest model training of musical notes provided in Example 1 of the present invention.
[0055] Figure 4 This is a flowchart of style consistency model training provided in Example 1 of the present invention.
[0056] Figure 5 Another flow chart of the random forest-based symbolic music generation method provided in Example 1 of the present invention.
[0057] Figure 6 A schematic diagram of a symbolic music generation device based on random forest provided in Embodiment 2 of the present invention.
[0058] The present invention is further described in detail below in conjunction with the accompanying drawings and specific embodiments. DETAILED DESCRIPTION
[0059] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention. Therefore, the following detailed description of the embodiments of the present invention provided in the drawings is not intended to limit the scope of the invention claimed for protection, but merely represents the selected embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.
[0060] Embodiment 1
[0061] Embodiment 1 of the present invention provides a symbolic music generation method based on random forest, which can be implemented by a symbolic music generation device based on random forest (hereinafter referred to as music generation device), and in particular, executed by one or more processors in the music generation device.
[0062] In this embodiment, the music generating device may be an electronic device equipped with a processor, the processor having a computer program of the random forest-based symbolic music generation method and the computer program can be executed, such as a computer, a smart phone, a smart tablet, etc.
[0063] With the help of deep learning technology, the generation of symbolic music has made significant progress. However, due to the high complexity and abstractness of music, it is difficult to have an accurate and easy-to-use method to automatically generate a continuous and beautiful audio signal. The present invention converts audio files into music symbols, and on this basis, learns the feature values, short-term style and long-term style consistency of the notes using a random forest algorithm, generates a fusion model, and finally uses the model to generate symbolic music. The symbolic music generated by the present invention has strong expressiveness and accuracy in terms of note rules and music style consistency.
[0064] like Figure 1 and Figure 2 As shown, a symbolic music generation method based on random forests captures the style characteristics of a large number of existing music works by learning them, and generates new symbolic music works based on them, which includes steps S1 to S5.
[0065] S1, obtaining a sample data set, wherein the sample data set includes pure music files of various styles, and the format of the pure music files includes MP3 format.
[0066] In this embodiment, pure music MP3 files of various styles including classical, pop, rock, and electronic music (music files of other formats may also be used, which is not limited here) are constructed into a complete music sample data set, with no less than 1,000 samples of each style, and each music sample is no less than 1 minute in length and has a complete music beginning and ending, with a total of 4,000 sample data.
[0067] S2, processing the pure music file to obtain a time domain signal, and using FFT to convert the time domain signal into a frequency domain signal to extract an audio waveform.
[0068] In this embodiment, FFT, that is, fast Fourier transform method, is used to process each MP3 file data in the sample data set, convert the time domain signal into a frequency domain signal, and extract the audio waveform information therein.
[0069] S3, processing and analyzing the audio waveform, identifying the notes, and obtaining a music symbol file, wherein the notes include pitch, duration and loudness;
[0070] In this embodiment, there are 4000 music symbol files in total, which are stored in the format of MIDI files.
[0071] S4, inputting the music symbol file of the sample data set into the symbolic music model for training, and obtaining a trained symbolic music model; wherein, the symbolic music model includes a note random forest model for generating notes and a style consistency model for judging the music style; the note random forest model and the style consistency model respectively generate decision trees through the random forest algorithm, and use the autocorrelation function and Gini impurity to extract features and classify the music symbol file.
[0072] In this embodiment, the random forest algorithm is a supervised learning method that uses multiple decision trees to label known samples and predict unknown samples. The random forest is created by training many decision trees on different subsets of the training data and then averaging the predictions of each tree. The bootstrap sampling process used in the present invention introduces randomness into the tree training process, which helps to reduce overfitting of the model.
[0073] Preferably, if Figure 3 As shown, the note random forest model is created by RandomForestClassifier, and its training steps are as follows:
[0074] A1, read 4000 MIDI notation music files, store the data in DataFrame, pre-process the input music notation files to distinguish pitch, duration and loudness data, and annotate each music notation file with a style label to obtain the pre-processed music notation files, where the style labels include classical, pop, rock and electronic;
[0075] A2, the preprocessed music notation file is divided into a training set and a test set, wherein the number of style labels in the training set and the test set is evenly distributed, and is evenly distributed according to classical, pop, rock, and electronic styles. 3600 copies are taken as the training set and 400 copies are taken as the test set, so as to evaluate the performance of the model after training the model.
[0076] A3, using a training set consisting of 3600 samples, inputting the training set into the note random forest model for training, the number of trees in the model can be set to 128, and the maximum depth of the tree is 2-256 (usually 128, the same as the number of pitches in the MIDI file);
[0077] A31, using boostrap sampling method, generates a large number of sample sets from the original data set by repeated random sampling with replacement, sampling every 50ms of music length for each sample in the training set, and using autocorrelation function to calculate the audio features of a single audio data block. The calculation formula of the autocorrelation function is:
[0078] ;
[0079] Among them, R(i) represents the similarity, is the value of the tth data in the audio data block, It is the mean of the audio data block, i represents the number of steps of audio data block delay, i=0-K, K is the order of the model, which is used to weigh the feature extraction effect and the amount of calculation, usually K=16, the larger the K value, the more accurate the feature parameters.
[0080] The autocorrelation coefficient reflects the frequency characteristics of audio. Frequency characteristics are the basic characteristics of audio. Through it, the timbre and intensity of different sounds can be represented, and the sounds produced by different people, different musical instruments, and different objects can be roughly distinguished.
[0081] A32, based on the decision tree of random forest, the audio features are classified by Gini impurity into left and right subtrees until the Gini impurity is less than a threshold (in this embodiment, the threshold is 0.05) or the iteration reaches the maximum tree depth, and a leaf node is generated. The leaf node stores the current audio feature value and the corresponding pitch, tone length and loudness data. The formula of the Gini impurity is:
[0082] ;
[0083] in, It represents Gini impurity, P(D) represents the probability of a random sample corresponding to a category, and D is the category number.
[0084] The key to decision trees is how to select partitioning attributes to classify data. We hope that as the tree is partitioned, the samples contained in the nodes of the decision tree belong to the same category as much as possible, that is, the "purity" of the nodes is getting higher and higher. The Gini impurity formula is used to quantify the impurity of the sample set, that is, to reflect the distribution of each category in the sample set.
[0085] A33, determine whether the number of current decision trees has reached the threshold. If so, complete the training of the note random forest model, otherwise return to step A31.
[0086] In this embodiment, A32 is repeated until the Gini impurity is less than 0.05 or the maximum tree depth (2-256, usually 128) is reached, and a leaf node is generated to store the current audio feature value and the corresponding original data's pitch, duration, and loudness.
[0087] A4, input the test set into the note random forest model for evaluation, and when the evaluation score is greater than the set threshold, a trained note random forest model is obtained.
[0088] Preferably, the calculation formula of the evaluation score is:
[0089] ;
[0090] Among them, the evaluation score F1 is the harmonic mean of precision and recall, the maximum value is 1, and the minimum value is 0. The larger the F1 value, the better the model performance.
[0091] , represents the precision rate, x represents the current model number, n represents the number of individuals that are truly positive and predicted to be positive, and N represents the number of individuals predicted to be positive by the model;
[0092] C , represents the recall rate, and M represents the number of truly positive individuals.
[0093] When the model F1 score is greater than 0.7, the model is judged to be stable and the trained note random forest model is obtained, otherwise the note random forest model is retrained.
[0094] Then, the trained note random forest model is saved to a file so that it can be loaded when generating music. At the same time, the audio feature values of each node of the decision tree and the corresponding pitch, duration and loudness of the original data are saved.
[0095] Next, we introduce short-term style decision trees and long-term style decision trees to generate a style consistency model and complete the music style judgment of a complete piece of music.
[0096] Preferably, style consistency refers to the mean square error of rhythm and pitch, and the smaller the score, the higher the quality of the music.
[0097] According to the sample sampling requirements, the style consistency model is divided into a short-term style decision tree and a long-term style decision tree to calculate the mean square error of the music rhythm and tone and judge the quality of the music.
[0098] Short-term style refers to the rhythm and tone differences before and after the current segment (100ms-500ms);
[0099] Long-term style refers to the mean square error of the differences in style between musical sections (prelude, verse, chorus).
[0100] Therefore, the sample sampling requirement of the short-term style decision tree is to take the original sample data every [50ms, 200ms] sampling;
[0101] The sample sampling requirement of the long-term style decision tree is to take the original sample data every [500ms, 1000ms] sampling, and the sampled data are the starting 5-10 seconds, middle 5-10 seconds and ending 5-10 seconds of the original sample data;
[0102] Then, the style consistency model is trained, and the training steps are as follows:
[0103] B1, sample each sample in the input training set according to the set sample sampling requirements;
[0104] B2, according to each sample, the audio feature of each sample is calculated using the autocorrelation function, and the audio feature is divided into left and right subtrees using Gini impurity, until the Gini impurity is less than a threshold or the iteration reaches the maximum tree depth, and a style leaf node is generated, and the style leaf node stores the audio feature value of the current sample and the corresponding style data;
[0105] B3, determine whether the number of current decision trees reaches the set threshold. If it has reached it, add up the results of all decision trees. If the number of labels in the summed result that are consistent with the original data exceeds half, the style classification is considered correct and the training of the style consistency model is completed. Otherwise, return to step B1.
[0106] In this embodiment, the number of trees in the style consistency model is set to 128, and the maximum depth of the tree can be set to 2-64. In this embodiment, the maximum depth of the tree is set to 4. The data is a set of 3600 samples, and the styles are classified into 4 styles: classical, pop, rock, and electronic.
[0107] like Figure 4 As shown, the detailed training process of the short-term style and the long-term style includes steps one to three.
[0108] Step 1: Train your short-term style
[0109] Step 1: Sample the original data for 100ms to obtain the sampled data;
[0110] Step 2: According to the sampled data, use Gini impurity to select the optimal classification and divide the data into left and right subtrees;
[0111] Step 3: Repeat step 2 until the style attribute of the leaf node;
[0112] step4: Repeat step1-step3 until 128 trees are generated;
[0113] Step 5: Add up the results of the 128 trees. If more than half of them are consistent with the labels of the original data, the short-term style classification is considered correct.
[0114] Step 2: Train your long-term style
[0115] Step 1: Increase the sampling interval to 500ms, and only sample the first 5-10 seconds, the middle 5-10 seconds, and the last 5-10 seconds of the song;
[0116] Step 2: Use Gini impurity to select the optimal classification and divide the data into left and right subtrees;
[0117] Step 3: Repeat step 2 until the style attribute of the leaf node;
[0118] step4: Repeat step1-step3 until 128 trees are generated;
[0119] Step 5: Add up the results of the 128 trees. If more than half of them are consistent with the labels of the original data, the long-term style classification is considered correct.
[0120] Step 3:
[0121] Save Model: Save the trained style consistency model to a file so that you can load the model when generating music.
[0122] The trained and evaluated note random forest model and style consistency model are fused to obtain a symbolic music model, and the fused model and feature value library are saved to generate new symbolic music works.
[0123] S5, obtaining music description data, inputting the music description data into a trained symbolic music model, and generating a new symbolic music work, wherein the music description data includes a music clip and a text description.
[0124] Specifically, Figure 5 The process of symbolic music generation shown is as follows:
[0125] Input example music and text descriptions into the trained symbolic music model;
[0126] The audio feature value is extracted by the note random forest model in the symbolic music model;
[0127] The obtained audio feature values are matched with the feature value library to generate new symbolic music notes, which include pitch, duration and loudness;
[0128] The generated notes are input into the style consistency model for short-term and long-term style judgment. If the style is consistent, a new piece of music is output, otherwise it is re-input into the note random forest model.
[0129] In another specific embodiment, the music mainstream generation method and the method of the present invention are evaluated and compared by the following evaluation method, as shown in Table 1, and the automatically generated music is evaluated by the music completion and style consistency, as follows:
[0130] (1) Musical completion: Musical completion is a subjective quality assessment, which is divided into a professional group and a large sample group. The higher the score, the better the music quality.
[0131] Professional group: select 5 or more music professionals to score the grammatical rules and music norms of more than 20 pieces of music generated by the algorithm of the present invention (score 1-10 points) and then take the average value;
[0132] Large sample group: more than 100 random listeners (ages include the elderly, middle-aged, and young, and occupations and educational backgrounds are randomly selected) are selected to rate the comfortability and conformity to mainstream effects of more than 20 pieces of music generated by the algorithm of the present invention (scores range from 1 to 10), and then the average value is taken.
[0133] (2) Style consistency: Style consistency refers to the mean square deviation of rhythm and pitch. The smaller the value, the better the music quality.
[0134] The short-term style feature mean square error refers to the mean square error of the rhythm and pitch differences every 500ms within the music segment (usually an automatically generated piece of music is divided into three segments);
[0135] The mean square error of long-term style features refers to the mean square error of the differences in music styles between music segments.
[0136] Table 1: Algorithm effect comparison table
[0137]
[0138] It can be seen from Table 1 that the music automatically generated by the present invention has obvious optimization in various parameters such as subjective evaluation of music professional group, subjective evaluation of large sample, mean square deviation of short-time style characteristics and mean square deviation of long-time style characteristics, especially in subjective evaluation of large sample and mean square deviation of long-time style characteristics. This method can generate symbolic music with good consistency of note rules and music style, and is an effective method for generating symbolic music.
[0139] In summary, compared with the prior art, the present invention has the following beneficial effects:
[0140] The method proposed in the present invention introduces a random forest algorithm and a style consistency parameter, trains multiple decision trees on different subsets of training data to process pitch, duration, loudness and style consistency features, and finally forms a symbolic music model, which can more accurately capture the detailed features of music in different areas;
[0141] In terms of the style consistency dimension, the present invention subdivides and designs short-term style consistency models and long-term style consistency models to optimize the generation of character music works with better overall style.
[0142] Embodiment 2
[0143] like Figure 6As shown, the second embodiment of the present invention further provides a symbolic music generation device based on random forest, comprising:
[0144] A sample data set construction unit, used to obtain a sample data set, wherein the sample data set includes pure music files of various styles, and the format of the pure music files includes MP3 format;
[0145] An audio waveform analysis unit, used to process the pure music file to obtain a time domain signal, and convert the time domain signal into a frequency domain signal using FFT to extract the audio waveform;
[0146] A note recognition unit, used to process and analyze the audio waveform, recognize notes, and obtain a music notation file, wherein the notes include pitch, duration, and loudness;
[0147] A model training unit is used to obtain a trained symbolic music model, input the music symbol file of the sample data set into the symbolic music model for training, and obtain the trained symbolic music model; wherein the symbolic music model includes a note random forest model for generating notes and a style consistency model for judging the music style; the note random forest model and the style consistency model respectively generate decision trees through the random forest algorithm, and use the autocorrelation function and Gini impurity to extract features and classify the music symbol file;
[0148] The music generation unit is used to obtain a new symbolic music work, acquire music description data, input the music description data into a trained symbolic music model, and generate a new symbolic music work, wherein the music description data includes a music clip and a text description.
[0149] Embodiment 3
[0150] The third embodiment of the present invention also provides a symbolic music generation device based on random forest, which includes a memory and a processor, wherein the memory stores a computer program, and the computer program can be executed by the processor to implement the symbolic music generation method based on random forest as described above.
[0151] Embodiment 4
[0152] The fourth embodiment of the present invention also provides a computer-readable storage medium, on which computer-readable instructions are stored. When the computer-readable instructions are executed by a processor of a device where the computer-readable storage medium is located, the random forest-based symbolic music generation method as described above is implemented.
[0153] In several embodiments provided in the embodiments of the present invention, it should be understood that the disclosed apparatus and method can also be implemented in other ways. The apparatus and method embodiments described above are merely schematic. For example, the flowcharts in the accompanying drawings show the possible architecture, functions and operations of the apparatus, method and computer program product according to multiple embodiments of the present invention. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of a code, and the module, program segment or a part of the code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flow chart, and the combination of boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or action, or can be implemented with a combination of dedicated hardware and computer instructions.
[0154] In addition, the functional modules in the various embodiments of the present invention may be integrated together to form an independent part, or each module may exist independently, or two or more modules may be integrated to form an independent part.
[0155] If the function is implemented in the form of a software function module and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art or the part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions to enable a computer device (which can be a personal computer, an electronic device, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program code. It should be noted that in this article, the term "include", "include" or any other variant thereof is intended to cover non-exclusive inclusion, so that the process, method, article or device including a series of elements includes not only those elements, but also includes other elements that are not explicitly listed, or also includes elements inherent to such process, method, article or device. Without more constraints, an element defined by the phrase "comprising a..." does not exclude the existence of other identical elements in the process, method, article or apparatus comprising the element.
[0156] The terms used in the embodiments of the present invention are only for the purpose of describing specific embodiments, and are not intended to limit the present invention. The singular forms "a", "said" and "the" used in the embodiments of the present invention and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings.
[0157] It should be understood that the term "and / or" used in this article is only a description of the association relationship of associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article generally indicates that the associated objects before and after are in an "or" relationship.
[0158] The word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining" or "in response to detecting", depending on the context. Similarly, the phrases "if it is determined" or "if (stated condition or event) is detected" may be interpreted as "when it is determined" or "in response to determining" or "when detecting (stated condition or event)" or "in response to detecting (stated condition or event)", depending on the context.
[0159] The "first\second" mentioned in the embodiments is only to distinguish similar objects, and does not represent a specific order for the objects. It is understandable that the "first\second" can be interchanged with the specific order or sequence where permitted. It should be understood that the objects distinguished by "first\second" can be interchanged where appropriate, so that the embodiments described herein can be implemented in an order other than those illustrated or described herein.
[0160] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A symbolic music generation method based on random forest, characterized in that: include: S1, obtaining a sample data set, wherein the sample data set includes pure music files of various styles, and the format of the pure music files includes MP3 format; S2, processing the pure music file to obtain a time domain signal, and using FFT to convert the time domain signal into a frequency domain signal, and extracting an audio waveform; S3, processing and analyzing the audio waveform, identifying the notes, and obtaining a music symbol file, wherein the notes include pitch, duration and loudness; S4, inputting the music symbol file of the sample data set into the symbolic music model for training, and obtaining a trained symbolic music model; wherein the symbolic music model includes a note random forest model for generating notes and a style consistency model for judging the music style; the note random forest model and the style consistency model respectively generate decision trees through the random forest algorithm, and use the autocorrelation function and Gini impurity to extract features and classify the music symbol file; S5, inputting the music description data into the trained symbolic music model to generate a new symbolic music work, wherein the music description data includes a music clip and a text description; the specific generation steps are as follows: inputting the music description data into a trained symbolic music model; The audio feature value is extracted by the note random forest model in the symbolic music model; Match the obtained audio feature values with the feature value library to generate new notes of symbolic music; The generated notes are input into the style consistency model for short-term and long-term style judgment. If the style is consistent, a new piece of music is output. Otherwise, it is re-input into the note random forest model. The training steps of the style consistency model include: B1, sample each sample in the input training set according to the set sample sampling requirements; B2, according to each sample, the audio feature of each sample is calculated using the autocorrelation function, and the audio feature is divided into left and right subtrees using Gini impurity, until the Gini impurity is less than a threshold or the iteration reaches the maximum tree depth, and a style leaf node is generated, and the style leaf node stores the audio feature value of the current sample and the corresponding style data; B3, determine whether the number of current decision trees reaches the set threshold. If it has reached the threshold, add up the results of all decision trees. If more than half of the summed results are consistent with the labels of the original data, the style classification is considered correct and the training of the style consistency model is completed. Otherwise, return to step B1; The sample sampling requirements include short-term style sample sampling requirements and long-term style sample sampling requirements, so as to calculate the mean square error of music rhythm and pitch and judge the quality of music; wherein, The short-time style sample sampling requirement is to take the original sample data every Sampling, where [50ms,200ms]; The long-term style sample sampling requirement is to take the original sample data every Sampling, and the sampled data is the starting 5-10 seconds, the middle 5-10 seconds and the ending 5-10 seconds of the original sample data, where [500ms,1000ms].
2. A method for generating symbolic music based on random forest according to claim 1, characterized in that ,The note random forest model is created by RandomForestClassifier, and its training steps are as follows: A1, preprocessing the input music notation file to distinguish the pitch, tone length and loudness data, and marking each music notation file with a style tag to obtain a preprocessed music notation file, wherein the style tags include classical, pop, rock and electronic; A2, dividing the preprocessed music notation file into a training set and a test set, wherein the number of style labels in the training set and the test set are evenly distributed; A3, inputting the training set into the note random forest model for training; A4, input the test set into the random forest model for evaluation, and when the evaluation score is greater than the set threshold, a trained note random forest model is obtained.
3. A method for generating symbolic music based on random forest according to claim 2, characterized in that , the A3 specifically includes the following steps: A31, using the boostrap sampling method, sampling each sample in the training set every 50ms of music length, and using the autocorrelation function to calculate the audio features of a single audio data block. The calculation formula of the autocorrelation function is: ; Among them, R(i) represents the similarity, is the value of the tth data in the audio data block, is the mean value of the audio data block, i represents the number of steps of audio data block delay, i=0-K, K is the order of the model, the larger the value of K, the more accurate the feature parameters; A32, based on the decision tree of random forest, the audio features are classified by Gini impurity into left and right subtrees until the Gini impurity is less than the threshold or the iteration reaches the maximum tree depth, and a leaf node is generated. The leaf node stores the current audio feature value and the corresponding pitch, tone length and loudness data. The formula of the Gini impurity is: ; in, represents Gini impurity, P(D) represents the probability of a random sample corresponding to a category, and D is the category number; A33, determine whether the number of current decision trees has reached the threshold. If so, complete the training of the note random forest model, otherwise return to step A31.
4. The method for generating symbolic music based on random forest according to claim 3, characterized in that ,The calculation formula of the evaluation score in step A4 is: ; The evaluation score F1 represents the harmonic mean of precision and recall, with a maximum value of 1 and a minimum value of 0. The larger the F1 value, the better the model performance. , represents the precision rate, x represents the current model number, n represents the number of individuals that are truly positive and predicted to be positive, and N represents the number of individuals predicted to be positive by the model; C , represents the recall rate, and M represents the number of truly positive individuals.
5. A symbolic music generation device based on random forest, characterized in that: include: A sample data set construction unit, used to obtain a sample data set, wherein the sample data set includes pure music files of various styles, and the format of the pure music files includes MP3 format; An audio waveform analysis unit, used to process the pure music file to obtain a time domain signal, and convert the time domain signal into a frequency domain signal using FFT to extract the audio waveform; A note recognition unit, used to process and analyze the audio waveform, recognize notes, and obtain a music notation file, wherein the notes include pitch, duration, and loudness; The model training unit is used to obtain a trained symbolic music model, input the music symbol file of the sample data set into the symbolic music model for training, and obtain the trained symbolic music model; wherein the symbolic music model includes a note random forest model for generating notes and a style consistency model for judging the music style; the note random forest model and the style consistency model respectively generate decision trees through the random forest algorithm, and use the autocorrelation function and Gini impurity to extract features and classify the music symbol file; wherein the training steps of the style consistency model include: B1, sample each sample in the input training set according to the set sample sampling requirements; B2, according to each sample, the audio feature of each sample is calculated using the autocorrelation function, and the audio feature is divided into left and right subtrees using Gini impurity, until the Gini impurity is less than a threshold or the iteration reaches the maximum tree depth, and a style leaf node is generated, and the style leaf node stores the audio feature value of the current sample and the corresponding style data; B3, determine whether the number of current decision trees reaches the set threshold. If it has reached the threshold, add up the results of all decision trees. If more than half of the summed results are consistent with the labels of the original data, the style classification is considered correct and the training of the style consistency model is completed. Otherwise, return to step B1; The sample sampling requirements include short-term style sample sampling requirements and long-term style sample sampling requirements, so as to calculate the mean square error of music rhythm and pitch and judge the quality of music; wherein, The short-time style sample sampling requirement is to take the original sample data every Sampling, where [50ms,200ms]; The long-term style sample sampling requirement is to take the original sample data every Sampling, and the sampled data is the starting 5-10 seconds, the middle 5-10 seconds and the ending 5-10 seconds of the original sample data, where [500ms,1000ms]; The music generation unit is used to obtain a new symbolic music work, acquire music description data, input the music description data into a trained symbolic music model, and generate a new symbolic music work, wherein the music description data includes a music clip and a text description; the specific generation steps are as follows: inputting the music description data into a trained symbolic music model; The audio feature value is extracted by the note random forest model in the symbolic music model; Match the obtained audio feature values with the feature value library to generate new notes of symbolic music; The generated notes are input into the style consistency model for short-term and long-term style judgment. If the style is consistent, a new piece of music is output, otherwise it is re-input into the note random forest model.
6. A symbolic music generation device based on random forest, characterized in that: It includes a processor and a memory, wherein the memory stores a computer program, and the computer program can be executed by the processor to implement a symbolic music generation method based on random forest as described in any one of claims 1-4.
7. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-readable instructions, and when the computer-readable instructions are executed by a processor of a device where the computer-readable storage medium is located, a symbolic music generation method based on random forest is implemented as described in any one of claims 1 to 4.
Citation Information
Patent Citations
Method for generating music for lyrics text, apparatus thereof and computer-readable storage medium
CN109166564A
Music generation method and device based on cyclic neural network
CN109727590A
Video style migration method based on time domain consistency constraint
CN110175951A
Song rhythm generation method and device based on classifier, storage medium and device
CN110516103A
Game music style classification method and device, readable medium and electronic equipment
CN113813609A
Cited By
Music generation method based on ViT-LSTM model
CN119943009A
