A music chord recognition method based on LightGBM algorithm
Chord recognition is performed using the LightGBM algorithm, which solves the problems of low chord recognition accuracy and high computing resource consumption in the existing technology, and achieves fast and accurate chord recognition, which is suitable for music teaching assistance.
Patent Information
- Application Number
- CN202211246585.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-10-12
- Publication Date
- 2025-09-30
- Estimated Expiration
- 2042-10-12
AI Technical Summary
In the existing technology, the accuracy of non-deep learning chord recognition methods is not high enough, while the deep learning-based methods require large-scale training samples and consume a lot of computing resources, resulting in long prediction time and affecting prediction accuracy.
The LightGBM algorithm is used for chord recognition. Through CENS chromaticity feature extraction and model training, combined with Optuna hyperparameter tuning, the model parameters are optimized to achieve fast chord recognition.
High-accuracy chord recognition is achieved under limited computing resources, with good robustness and timeliness, making it suitable for music teaching assistance.
Smart Images

Figure CN115631739B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of intelligent musical instruments, and in particular to a music chord recognition method based on the LightGBM algorithm. Background Art
[0002] With the advancement of science and technology and people's pursuit of artistic life, various technologies to assist in learning to play musical instruments have emerged.
[0003] In the learning of musical instruments, chord practice is both the focus and the difficulty, so the technology of recognizing chords has emerged in the field of smart musical instruments.
[0004] Chord recognition refers to the process of identifying chords in music through algorithms, determining the chord type, and marking the chord's starting and ending points. Chord recognition algorithms generally include feature extraction and chord estimation, and the algorithm types can be divided into non-deep learning methods and deep learning methods. Feature extraction refers to extracting audio features from music that are beneficial for chord detection. Commonly used chord features include Pitch Class Profile (PCP), Chroma Log Pitch (CLP), Chroma Energy Normalized Statistics (CENS), etc. Chord estimation methods include template matching, Hidden Markov Model (HMM), Dynamic Bayesian Network (DBN), Deep Learning (DP), etc. Chord recognition can be completed by performing chord estimation based on the extracted audio features.
[0005] However, the accuracy of non-deep learning chord recognition methods is not high enough. Although deep learning-based chord recognition methods can achieve higher accuracy, they require large-scale training samples to obtain relevant model parameters. At the same time, the model also has a certain degree of overfitting and weak robustness. Under limited computing resources, the more these model parameters are, the longer the model prediction time is, which has a certain impact on the prediction accuracy. Summary of the Invention
[0006] Based on this, it is necessary to propose a music chord recognition method based on the LightGBM algorithm to solve the problems of chord estimation confusion caused by the low recognition of chord features and the low recognition accuracy of the probability model in the chord recognition task, so as to establish a machine learning model that can quickly predict the chord information in songs of the same type of music style, while achieving a high recognition accuracy and ensuring a certain model robustness.
[0007] The present invention provides a music chord recognition method based on the LightGBM algorithm, comprising the following steps:
[0008] Step S1, collecting song data and label data corresponding to multiple songs, performing CENS chromaticity feature extraction on the song data to obtain feature data, simplifying the label data and converting it into chord labels corresponding to the feature data, combining the feature data and chord labels into a dataset D, and dividing the dataset D into a training set S and a test set T;
[0009] Step S2, perform LightGBM model training on the training set S to obtain model parameters;
[0010] Step S3: inputting model parameters and test set T into the LightGBM model to perform chord recognition and obtain chord recognition data;
[0011] Step S4: perform error evaluation on the chord recognition data to obtain a prediction result.
[0012] Preferably, step S1 includes the following steps:
[0013] Step S12, calculate the chromaticity vector of the song using constant Q transformation:
[0014] Step S13, performing L1 normalization on the chromaticity vector;
[0015] Step S14, performing threshold quantization on the normalized chromaticity vector to obtain chromaticity features;
[0016] Step S15, performing temporal smoothing on the chromaticity features;
[0017] Step S16, performing L2 normalization on the temporally smoothed chromaticity features to obtain the CENS features of the song;
[0018] Step S17: Simplify and convert the label data corresponding to each song into one of the three chord labels: major triad, minor triad, and unknown chord.
[0019] Preferably, the step of downsampling the song data is further included before step S12.
[0020] Preferably, step S12 calculates the chromaticity vector of the song according to the following formula:
[0021]
[0022] where w k (n) is the window length N k Hanning window, N k According to the scale center frequency f k change:
[0023]
[0024] The symbol [x] represents the smallest integer greater than or equal to x, f s is the sampling frequency, Q=1 / (2 1 / B -1),
[0025] Preferably, in step S17, the major triad includes 12 chord types, namely, C chord, C# chord, D chord, D# chord, E chord, F chord, F# chord, G chord, G# chord, A chord, A# chord, and B chord; and the minor triad includes 12 chord types, namely, C:min chord, C#:min chord, D:min chord, D#:min chord, E:min chord, F:min chord, F#:min chord, G:min chord, G#:min chord, A:min chord, A#:min chord, and B:min chord.
[0026] Preferably, step S2 includes the following steps:
[0027] Step S21, performing model training on the training data based on the LightGBM algorithm to determine model parameters;
[0028] Step S22: Obtain a set of optimal parameters based on Optuna hyperparameter automatic tuning.
[0029] Preferably, step S22 includes the following steps:
[0030] Step S221, setting a parameter grid to determine a parameter search range;
[0031] Step S222, trying a set of hyperparameter combinations through kFold cross validation;
[0032] Step S223, calling the LightGBM classification function to train the model;
[0033] Step S224, predicting the test set T using the trained model;
[0034] Step S225: Return the average score based on the custom evaluation index;
[0035] Step S226: Select the best parameter combination and output it.
[0036] The present invention provides a method for music chord recognition based on the LightGBM algorithm, comprising the following steps: Step S1, collecting song data and label data corresponding to multiple songs, performing CENS chromatic feature extraction on the song data to obtain feature data, simplifying the label data into chord labels corresponding to the feature data, combining the feature data and chord labels into a dataset D, and dividing the dataset D into a training set S and a test set T; Step S2, training the training set S with a LightGBM model to obtain model parameters; Step S3, inputting the model parameters and the test set T into the LightGBM model to perform chord recognition and obtain chord recognition data; Step S4, performing error evaluation on the chord recognition data to obtain prediction results. The method for music chord recognition based on the LightGBM algorithm provided by the present invention can accurately identify chord labels and their corresponding moments in target style songs, helping music enthusiasts to learn chord knowledge by themselves with related instruments. The method also has good accuracy and timeliness, and the prediction results can provide auxiliary teaching support for music while meeting accuracy requirements. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] In order to more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the specific embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0038] Figure 1 The flowchart of a music chord recognition method based on the LightGBM algorithm is provided in one embodiment. DETAILED DESCRIPTION
[0039] The technical solution of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the embodiments described are only some embodiments of the present invention, not all embodiments. All other embodiments obtained by ordinary technicians in this field based on the embodiments of the present invention without making any creative efforts shall fall within the scope of protection of the present invention.
[0040] As used in this application, the terms "component," "module," and "system" are intended to refer to a computer-related entity, which can be hardware, a combination of hardware and software, software, or software in execution. For example, a component can be, but is not limited to, a process running on a processor, a processor, an object, an executable code, a thread of execution, a program, and / or a computer. As an illustration, both an application running on a server and a server can be a component. One or more components can reside in a process and / or a thread of execution, and a component can be located within a computer and / or distributed between two or more computers.
[0041] As used herein, the terms "inference" or "inference" generally refer to the process of inferring or reasoning about the state of a system, environment, and / or user from a set of observations captured via events and / or data. For example, inference can be used to identify a specific context or action, or can generate a probability distribution over states. Inference can be probabilistic, that is, a probability distribution over states of interest is computed based on a consideration of data and events. Inference can also refer to techniques for synthesizing higher-level events from a set of events and / or data. Such inference results in the construction of new events or actions from a set of observed events and / or stored event data, regardless of whether the events are related in adjacent time and regardless of whether the events and data come from one or several event and data sources.
[0042] The LightGBM algorithm (Light Gradient Boosting Machine) is a distributed gradient boosting (GBDT) framework based on the decision tree algorithm, open sourced by the Distributed Machine Learning Toolkit (DMTK) team at Microsoft Research Asia. GBDT is a very popular and effective algorithm model in machine learning. The main idea of GBDT is to iteratively train weak classifiers (decision trees) to obtain the optimal model. In each iteration, the negative gradient of the current model on all samples is first calculated. Then, a new weak classifier is trained based on this value and its weight is calculated, ultimately updating the model. However, in data environments with large training samples and high-dimensional features, the performance and accuracy of the GBDT algorithm face significant challenges. The LightGBM algorithm improves training speed without sacrificing accuracy by optimizing the sampling of sample points during model training and the feature dimension when selecting split points.
[0043] like Figure 1 As shown, the present invention provides a music chord recognition method based on the LightGBM algorithm, which includes the following steps:
[0044] Step S1, collecting song data and label data corresponding to multiple songs, performing CENS chromaticity feature extraction on the song data to obtain feature data, simplifying the label data and converting it into chord labels corresponding to the feature data, combining the feature data and chord labels into a dataset D, and dividing the dataset D into a training set S and a test set T;
[0045] Step S2, perform LightGBM model training on the training set S to obtain model parameters;
[0046] Step S3: input model parameters and test set T into the LightGBM model to perform chord recognition and obtain chord recognition data;
[0047] Step S4: perform error evaluation on the chord recognition data to obtain a prediction result.
[0048] In this embodiment, the processor used is Intel i7-10700, its memory is 16GB, the system used is Windows 10 (64-bit), the programming language version is Python 3.8, and the integrated development environment is Pycharm.
[0049] In step S1, the song and label dataset consists of songs by The Beatles (180 songs) and Jay Chou (29 songs). The label data is obtained by manual annotation. The Beatles' album is a commonly used test dataset in many chord recognition tasks. In addition, the present invention also adds Jay Chou's songs to improve the diversity of the dataset and the robustness of the system.
[0050] Preferably, step S1 includes the following steps:
[0051] Step S11, downsample the song to 11025 Hz to reduce the amount of calculation.
[0052] Step S12, using constant Q transform to calculate the chromaticity vector of the song audio file. Specifically, the chromaticity vector of the song is calculated according to the following formula:
[0053]
[0054] where w k (n) is the window length N k Since the Q factor of each frequency band of CQT is constant, the length of the analysis window N k According to the scale center frequency f k change:
[0055]
[0056] The symbol [x] represents the smallest integer greater than or equal to x, f sis the sampling frequency, Q=1 / (2 1 / B -1), In this embodiment, min =32.703 Hz is the minimum frequency for signal analysis, B is the number of frequency bands in each octave, in this embodiment, B=36, and the frame shift hop_length is 1024.
[0057] Step S13: perform L1 normalization on the chromaticity vector according to the following formula:
[0058]
[0059] In step S14, the chroma vector normalized in step S13 is threshold-quantized. The quantization thresholds are [0.05, 0.1, 0.2, 0.4], and the corresponding quantization weights are [0.25, 0.25, 0.25, 0.25]. Each time the element value crosses (is greater than) a threshold from small to large, 0.25 is added to obtain the final chroma quantization value.
[0060] Step S15: Temporally smooth the chromaticity features obtained in step S14. A Hanning window is used as a smoothing window and convolved with the chromaticity quantization value to obtain the temporally smoothed chromaticity features. In this embodiment, the smoothing window length is 41 points.
[0061] Step S16, perform L2 normalization on the feature vector processed in step S15 to obtain the CENS feature of the song. The L2 normalization formula is:
[0062]
[0063] Step S17: Simplify and convert the corresponding chord labels of each song. According to music theory knowledge, all chord types are converted into major triads (C, C#, D, D#, E, F, F#, G, G#, A, A#, B), minor triads (C:min, C#:min, D:min, D#:min, E:min, F:min, F#:min, G:min, G#:min, A:min, A#:min, B:min) and unknown types (N), a total of 25 types, and are represented by numbers 0 to 24.
[0064] Preferably, step S2 includes:
[0065] Step S21: Perform model training on the training data based on the LightGBM algorithm to determine the model parameters.
[0066] The LightGBM algorithm is an efficient implementation framework of the Gradient Boosting Decision Tree (GBDT) algorithm. It optimizes the processing of large data volumes and high-dimensional features through gradient-based one-side sampling (GOSS) and exclusive feature bundling (EFB) technology, supports efficient parallel training, and has the advantages of faster training speed, lower memory consumption, and better accuracy.
[0067] Step S22: Obtain a set of optimal LightGBM model parameters based on Optuna hyperparameter automatic tuning.
[0068] Specifically, step S22 includes the following steps:
[0069] Step S221: Set the parameter grid and set the parameter search range. The specific parameters and parameter settings are as follows:
[0070] ①n_estimators: the number of decision trees, specifically set to 10000;
[0071] ②learning_rate: learning rate, the specific range is set between 0.001 and 0.3;
[0072] ③num_leaves: the number of leaf nodes, the specific range is set between 20 and 3000, with a step size of 10;
[0073] ④max_depth: maximum tree depth, the specific range is set between 3 and 12, with a step size of 1;
[0074] ⑤min_data_in_leaf: The minimum number of samples for a leaf node to be split downwards. The specific range is set to 200 to 10,000, with a step size of 100;
[0075] ⑥max_bin: The number of bins, the specific range is set to 200 to 500;
[0076] ⑦lambda_l 1: L1 regularization parameter, the specific range is set to 0 to 50;
[0077] ⑧lambda_l 2: L2 regularization parameter, the specific range is set to 0 to 50;
[0078] ⑨min_gain_to_split: minimum gain for splitting, the specific range is set to 0 to 15;
[0079] ⑩bagging_fraction: specifies the percentage of training samples used to train each tree, the specific range is set to 0.2 to 0.9, with a step size of 0.1;
[0080] bagging_freq: bagging frequency, the specific range is set to 0 to 20;
[0081] feature_fraction: Specifies the percentage of features to be sampled when training each tree. The specific range is set to 0.2 to 0.9 with a step size of 0.1.
[0082] In step S222, kFold cross validation is performed to try out a set of hyperparameter combinations to ensure model stability, where k is 5.
[0083] Step S223, calling the LightGBM classification function to train the model.
[0084] Step S224: predict the test set using the trained model.
[0085] Step S225: Return the average score based on the custom evaluation index, where the goal is to minimize the log_loss index.
[0086] Step S226: Select the best parameter combination according to the target and output it.
[0087] A set of optimal parameter combinations in this embodiment is as follows:
[0088] n_estimators: 10000;
[0089] learning_rate = 0.20308;
[0090] num_leaves=2940;
[0091] max_depth=3;
[0092] min_data_in_leaf=200;
[0093] max_bin=200;
[0094] lambda_l 1=0.09067;
[0095] lambda_l 2=13.30040;
[0096] min_gain_to_split=0.11886;
[0097] bagging_fraction=0.5;
[0098] bagging_freq=20;
[0099] feature_fraction=0.7.
[0100] Set the objective function, set the appropriate range of each LightGBM model parameter, select the optimal number of training times based on the model running time, and automatically search for the best parameter combination based on the target value.
[0101] Step S3 specifically involves processing the test song in step S1 to obtain its CENS features, which are then substituted into the optimal LightGBM model trained in step S2 for chord recognition.
[0102] In this embodiment, a set of better model parameters trained in step S2 is used to obtain the LightGBM chord recognition model, which is used to identify the test data. It should be noted that the CENS features extracted from the test song need to maintain the consistency of the feature processing parameters used in the training song.
[0103] Step S4 specifically compares the chord labels identified in step S3 with the correct chord labels, calculates the overall recognition accuracy, and outputs the prediction results. The above model achieved an 88% recognition accuracy on the test data, and the average time (feature extraction + chord prediction) for a song (average duration of 176.3 seconds) was 16.9 seconds.
[0104] The music chord recognition method based on the LightGBM algorithm provided by the present invention comprises the following steps: Step S1, collecting song data of multiple songs and label data corresponding to the songs, performing CENS chromaticity feature extraction on the song data to obtain feature data, and converting the label data into
[0105] Simplify the conversion into chord labels corresponding to the feature data, collect the feature data and chord labels into a data set D, and divide the data set D into a training set S and a test set T; step S2, train the training set S with a LightGBM model to obtain model parameters; step S3, input the model parameters and the test set T into the LightGBM model, perform chord recognition, and obtain chord recognition data; step S4, perform error evaluation on the chord recognition data to obtain a prediction result. The music chord recognition method based on the LightGBM algorithm provided by the present invention can accurately identify the chord labels and the time in the target style song, which helps music lovers to learn chord knowledge by themselves with related instruments, and the method has good accuracy and timeliness. The prediction results can provide auxiliary teaching support for music under the premise of meeting the accuracy requirements. Because the LightGBM model of the present invention occupies low memory, supports parallel processing, and can process large-scale data.
[0106] The above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the above embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the above embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.
Claims
1. A music chord recognition method based on LightGBM algorithm, characterized in that: The following steps are involved: Step S1, collecting song data of multiple songs and label data corresponding to the songs, performing CENS chromaticity feature extraction on the song data to obtain feature data, simplifying the label data and converting it into chord labels corresponding to the feature data, combining the feature data and the chord labels into a dataset D, and dividing the dataset D into a training set S and a test set T; Step S2, performing LightGBM model training on the training set S to obtain model parameters; Step S3, inputting the model parameters and the test set T into the LightGBM model, performing chord recognition, and obtaining chord recognition data; Step S4, performing error evaluation on the chord recognition data to obtain a prediction result; The step S1 further comprises the following steps: Step S12, calculating the chroma vector of the song using a constant Q transform; Step S13, performing L1 normalization on the chromaticity vector; Step S14, performing threshold quantization on the normalized chromaticity vector to obtain chromaticity features; Step S15, performing temporal smoothing on the chromaticity feature; Step S16, performing L2 normalization on the temporally smoothed chromaticity feature to obtain the CENS feature of the song; Step S17: simplify and convert the label data corresponding to each song into one of the three chord labels: major triad, minor triad, and unknown chord.
2. The music chord recognition method based on the LightGBM algorithm according to claim 1, characterized in that: Before step S12, the method further includes the step of downsampling the song data.
3. The music chord recognition method based on the LightGBM algorithm according to claim 1, characterized in that: The step S12 calculates the chromaticity vector of the song according to the following formula: where w k (n) is the window length N k Hanning window, N k According to the scale center frequency f k change: The symbol [x] represents the smallest integer greater than or equal to x, f s is the sampling frequency, Q=1 / (2 1 / B -1), where f min is the minimum frequency for signal analysis, and B is the number of frequency bands per octave.
4. The music chord recognition method based on the LightGBM algorithm according to claim 1, characterized in that: In step S17, the major triad includes 12 chord types, namely, C chord, C# chord, D chord, D# chord, E chord, F chord, F# chord, G chord, G# chord, A chord, A# chord, and B chord; and the minor triad includes 12 chord types, namely, C:min chord, C#:min chord, D:min chord, D#:min chord, E:min chord, F:min chord, F#:min chord, G:min chord, G#:min chord, A:min chord, A#:min chord, and B:min chord.
5. The music chord recognition method based on the LightGBM algorithm according to claim 1, characterized in that: The step S2 comprises the following steps: Step S21, performing model training on the training data based on the LightGBM algorithm to determine the model parameters; Step S22: Obtain a set of optimal parameters based on Optuna hyperparameter automatic tuning.
6. The music chord recognition method based on the LightGBM algorithm according to claim 5, characterized in that: The step S22 includes the following steps: Step S221, setting a parameter grid to determine a parameter search range; Step S222, trying a set of hyperparameter combinations through kFold cross validation; Step S223, calling the LightGBM classification function to train the model; Step S224, predicting the test set T using the trained model; Step S225: Return the average score based on the custom evaluation index; Step S226: Select the best parameter combination and output it.
Citation Information
Patent Citations
Method for automatically compiling accompaniment chords
CN111739491A
Broadband radar target HRRP identification method based on hybrid model fusion
CN114154534A