Raman spectrum classification method based on BiLSTM Multi-Head Attention
By applying the BiLSTM Multi-Head Attention deep learning model in Raman spectral data classification, the problems of low accuracy and insufficient generalization ability of spectral data in the existing technology are solved, and higher classification accuracy and robustness are achieved.
Patent Information
- Application Number
- CN202411592071.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-08
- Publication Date
- 2025-02-18
AI Technical Summary
The prior art has low classification accuracy and insufficient generalization ability when processing complex spectral data.
Using the deep learning classification model based on BiLSTM Multi-Head Attention, the timing characteristics of spectral data are extracted through the bidirectional long and short-term memory network (BiLSTM), and the multi-head self-attention mechanism is used to automatically focus on important feature areas, and the characteristics are optimized in combination with the full connection layer. Nonlinear expression.
It significantly improves the accuracy and robustness of Raman spectral classification, enhances classification performance, and improves the generalization performance of the model through 50% cross-validation.
Smart Images

Figure CN119475133A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to a Raman spectrum classification method based on BiLSTM Multi-Head Attention. Background Art
[0002] Raman spectroscopy is generated by the scattering of light after the molecules of a substance are illuminated by a light source. It is widely used to analyze the structural information of a substance. Depending on the chemical structure and functional groups inside the irradiated substance, the spectral data generated are also different, so it is also called the "chemical fingerprint" of the substance. Raman spectroscopy can not only perform qualitative analysis on substances, but also quantitative analysis on substances. The content of the substance can be determined by the intensity of the spectral peak. Raman spectroscopy has the advantages of high efficiency, high sensitivity, simple sampling without contacting the sample, and can effectively protect test personnel for some infectious samples. It is non-destructive to the sample. Therefore, Raman spectroscopy has now been applied in fields such as food safety, medical testing, materials science, and petrochemical engineering.
[0003] Traditional Raman spectroscopy analysis methods mainly rely on empirical judgment and expert knowledge, usually using a combination of feature extraction and machine learning algorithms. However, as the size of data sets continues to increase, traditional manual feature extraction methods have gradually exposed their limitations and are unable to effectively capture potential information in complex data. In addition, when processing time series data, traditional machine learning algorithms often fail to fully utilize the time series characteristics of data, resulting in insufficient classification performance. Therefore, the existing technology has the problems of low classification accuracy and insufficient generalization ability when processing complex spectral data. Summary of the invention
[0004] The purpose of the present invention is to provide a Raman spectroscopy classification method based on BiLSTM Multi-Head Attention to solve the technical problems of low classification accuracy and insufficient generalization ability in the prior art when processing complex spectral data.
[0005] The technical solution of the present invention is as follows: The Raman spectrum classification method based on BiLSTM Multi-Head Attention includes:
[0006] Firstly, a number of Raman spectrum data are obtained, and a series of preprocessing is performed on the Raman spectrum data to obtain Raman spectrum data with obvious peak information;
[0007] Secondly, build a deep learning classification model based on BiLSTM Multi-Head Attention. The deep learning classification model includes:
[0008] Input layer: used to receive preprocessed Raman spectral data. The input shape of each sample is (batch_size, sequence_length, input_dim);
[0009] BiLSTM layer: The first BiLSTM layer consists of forward and backward LSTMs to extract bidirectional time series features of spectral data; the second BiLSTM layer further extracts deep time series features;
[0010] Attention mechanism layer: weights are assigned to features at different time steps through a multi-head self-attention mechanism to highlight features that are important for the classification task;
[0011] Fully connected layer: used to map the output of the attention mechanism to the feature space required for the classification task;
[0012] Output layer: Use the Softmax activation function to map the output results to classification probabilities;
[0013] Then, the learning classification model was trained through 5-fold cross validation to optimize the model parameters;
[0014] Finally, the learned classification model is evaluated on the test set, the classification accuracy, recall and F1-score indicators are calculated, and the confusion matrix is generated.
[0015] Furthermore, the preprocessing of Raman spectroscopy data includes:
[0016] Baseline correction: Adaptive penalized least squares method is used to correct the baseline drift of Raman spectrum;
[0017] Smoothing: Savitzky-Golay filtering method is used to smooth the Raman spectrum to remove noise;
[0018] Normalization: Use the normalization function to normalize the intensity of the Raman spectrum to the interval [0,1] to improve data consistency.
[0019] Furthermore, the BiLSTM layer contains two hidden layers, each of which consists of 64 hidden units and uses tanh as the activation function.
[0020] Furthermore, the number of heads of the multi-head self-attention mechanism is 8.
[0021] Furthermore, the fully connected layer uses the ReLU activation function and contains 128 neurons.
[0022] Furthermore, the number of neurons in the output layer is equal to the number of classification categories of the Raman spectral data.
[0023] Furthermore, the learning classification model is trained by the Adam optimization algorithm, and the learning rate is set to 0.001.
[0024] Furthermore, 5-fold cross validation is used to reduce the overfitting of the model through different combinations of training sets and validation sets in each fold to improve the generalization performance of the model.
[0025] Beneficial effects of the present invention: When the Raman spectrum classification method based on BiLSTM Multi-Head Attention of the present invention is used, the accuracy and robustness of Raman spectrum classification are significantly improved by introducing a bidirectional long short-term memory network (BiLSTM) and a multi-head self-attention mechanism. The bidirectional LSTM can capture the bidirectional time dependency of Raman spectrum data, and the multi-head self-attention mechanism can automatically focus on important feature areas, thereby enhancing the classification performance. In addition, the fully connected layer used in the model further optimizes the nonlinear expression ability of the features. After 5-fold cross-validation, the model performed well on the test set and can be effectively applied to the classification task of Raman spectrum. It can solve the problems of low classification accuracy and insufficient generalization ability of the prior art when processing complex spectral data. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] Figure 1 It is a flow chart of an embodiment of the Raman spectrum classification method based on BiLSTM Multi-Head Attention of the present invention;
[0027] Figure 2 for Figure 1 Specific flow chart of data preprocessing corresponding to ;
[0028] Figure 3 for Figure 1 Specific flow chart of the corresponding data set division;
[0029] Figure 4 for Figure 1 The specific flow chart of the corresponding model construction;
[0030] Figure 5 for Figure 1 The specific flowchart of model training and optimization corresponding to ;
[0031] Figure 6 for Figure 1 The specific flow chart of the corresponding model evaluation;
[0032] Figure 7 Schematic diagram of the model framework structure after the model is built. DETAILED DESCRIPTION
[0033] In order to make the purpose, technical scheme and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention, that is, the embodiments described are only part of the embodiments of the present invention, rather than all of the embodiments. The components of the embodiments of the present invention described and shown in the drawings herein can be arranged and designed in various different configurations.
[0034] Therefore, the following detailed description of the embodiments of the present invention provided in the accompanying drawings is not intended to limit the scope of the invention claimed for protection, but merely represents selected embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without making creative work are within the scope of protection of the present invention.
[0035] It should be noted that relational terms such as "first" and "second" are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0036] The features and performance of the present invention are further described in detail below in conjunction with the embodiments.
[0037] A specific embodiment of the Raman spectrum classification method based on BiLSTM Multi-Head Attention of the present invention is as follows: Figure 1 As shown in the figure, it mainly includes key steps such as data preprocessing, data set division, model construction, model training and optimization, and model evaluation.
[0038] Among them, the data preprocessing mainly includes: baseline correction, using the adaptive penalty least squares method to correct the baseline drift of the Raman spectrum; smoothing, using the Savitzky-Golay filter method to smooth the Raman spectrum to remove noise; normalization, using the normalization function to normalize the intensity of the Raman spectrum to the interval [0,1] to improve data consistency. Specifically, Figure 2As shown in the figure, first, the Raman spectral data of minerals and the Raman spectral data of cells of patients with type 2 diabetes are collected and made into data sets respectively. Subsequently, the obtained Raman spectral data set is subjected to baseline removal, and the method used is the adaptive penalized least squares method (airPLS). Then, the spectral data after baseline removal is smoothed using the Savitzky-Golay filtering method. Finally, the spectral data after smoothing is mapped to the range of [0,1] using the normalization formula (1); wherein the formula (1) is: x^'=(x-min(x)) / (max(x)-min(x))(1).
[0039] When dividing the data set, Figure 3 As shown in the figure, the dataset is divided into training set and test set in a ratio of 7:3.
[0040] When constructing a data model, that is, when constructing a deep learning classification model based on BiLSTM Multi-Head Attention, the deep learning classification model mainly includes: input layer: used to receive preprocessed Raman spectral data, the input shape of each sample is (batch_size, sequence_length, input_dim); BiLSTM layer: the first layer of BiLSTM consists of forward and reverse LSTM, extracting the bidirectional time series features of the spectral data; the second layer of BiLSTM further extracts deep time series features; attention mechanism layer: weights are assigned to features at different time steps through a multi-head self-attention mechanism to highlight features important to the classification task; fully connected layer: used to map the output of the attention mechanism to the feature space required for the classification task; output layer: the output result is mapped to the classification probability using the Softmax activation function. Add a fully connected layer and an output layer to form a complete BiLSTM Multi-Head Attention model. Construct a BiLSTM network, the first layer of BiLSTM consists of two LSTM layers, forward and reverse, which respectively model the forward and backward dependencies of the time series data. Each LSTM layer contains 64 hidden units, and extracts bidirectional time series features through forward and backward processing. The second layer of BiLSTM further processes the features extracted by the previous layer, which is also composed of 64 hidden units. Through the second layer of BiLSTM, the model can capture more complex and deep time series features. Tanh is used as the activation function in the two layers of BiLSTM.
[0041] Specifically, Figure 4 As shown, the preprocessed data set is used as the input of the model. The input data is a three-dimensional tensor. Where N is the batch size, T is the time step, and D is the input feature dimension. Two BiLSTM layers are added. The BiLSTM layer consists of two LSTM layers, one for processing the forward propagation of the input sequence and the other for processing the backward propagation. The output of the BiLSTM is the concatenation of the two LSTM outputs. Based on formulas (1)-(3), the output value of the BiLSTM is calculated by the forward LSTM and the backward LSTM; where formulas (1)-(3) are:
[0042] Forward LSTM:
[0043] Reverse LSTM:
[0044] BiLSTM output:
[0045] H t It is the hidden state at time step t, which is the concatenation of the forward and backward hidden states, and has a dimension of 2H, where H is the number of hidden units of LSTM.
[0046] A multi-head self-attention mechanism is introduced. The purpose of the multi-head self-attention mechanism is to focus on the weighted combination of different time steps of the BiLSTM output, so as to generate a more representative global feature vector. The multi-head self-attention mechanism works in parallel through multiple attention heads, analyzes the importance information in the time series data from different angles, generates weighted feature representations, and further enhances the classification model's ability to capture time series dependencies and global information; on the feature representation weighted by the attention mechanism, a fully connected layer is introduced to map the high-dimensional feature vector to a lower-dimensional feature space; the model outputs the classification result through a fully connected layer, and the number of neurons in the output layer is equal to the number of categories in the classification task. The Softmax activation function is used to convert the output of the model into a probability distribution of each category, and classification is performed according to the probability.
[0047] First, for the output sequence of BiLSTM H = [H1, H2, ..., H T ], calculate the attention weight a for each time step t ; Next, based on formula (4), for each attention head i, the attention score is calculated; where formula (4) is:
[0048]
[0049] Among them, W i is a learnable weight matrix, V i is a learnable weight vector, b i is the bias vector;
[0050] Then, based on formula (5), the score of each attention head is normalized by the softmax function to calculate the attention weight; where formula (5) is:
[0051]
[0052] Next, the context vector of each attention head is obtained by weighted summing of the BiLSTM outputs using formula (6), where formula (6) is:
[0053]
[0054] Finally, the final context vector is concatenated using formula (7), where formula (7) is:
[0055] c=Concat(c 1 ,c 2 ,…,c h )(7);
[0056] Here, h is the number of attention heads.
[0057] The obtained context vector c is used as the input of the fully connected layer and passes through the fully connected layer and the ReLU activation function based on formula (8); where formula (8) is:
[0058] z1=ReLU(W1c+b1) (8);
[0059] Among them, W1 is the weight matrix of the fully connected layer and b1 is the bias vector.
[0060] Based on formula (9), after a fully connected layer, the classification result is output; where formula (9) is:
[0061]
[0062] Among them, z1 is the output of the previous step, and the output It is a probability distribution, which indicates the probability that a sample belongs to each category.
[0063] When training and optimizing deep learning classification models, such as Figure 5 As shown, first, set the training parameters in the model. The operator can set the experimental parameters suitable for him according to his own data set requirements. Based on formulas (1)-(3), the weighted cross entropy loss function is used to calculate the loss between the predicted value and the true value, and the Adam optimizer is used for gradient descent. The learning rate scheduler (StepLR) is introduced to dynamically adjust the learning rate according to the predetermined strategy during the model training process; where formulas (1)-(3) are:
[0064]
[0065] Among them, w0 is the weight of class 0, w1 is the weight of class 1, and y i is the true label (0 or 1) of the i-th sample, is the predicted probability that the i-th sample corresponds to category 0 and category 1 respectively, θ is the model parameter, η is the learning rate, and η new is the updated learning rate, η initial is the initial learning rate, γ is the learning rate decay factor, which determines the reduction multiple of the learning rate at each decay, epoch is the current number of training rounds, and step_size is the number of epochs at which the learning rate is adjusted. Indicates a floor operation.
[0066] Five-fold cross validation was used to verify the model on the training set, and the parameters of the best fold were taken as the model parameters.
[0067] The method for optimizing model parameters includes: optimizing the model using a weighted cross entropy loss function and adjusting the model parameters using an Adam optimizer; in order to improve the generalization ability of the model, a 5-fold cross validation method is used to verify the training set and select the optimal model parameters.
[0068] When learning a classification model for evaluation, such as Figure 6 As shown in the figure, firstly, the model parameters of the best fold are tested on the test set, and the model is evaluated using indicators such as classification accuracy, recall rate and F1-score, and the classification results of the model are analyzed using the confusion matrix.
[0069] In this embodiment, the BiLSTM layer includes two hidden layers, each of which consists of 64 hidden units and uses tanh as the activation function. The number of heads of the multi-head self-attention mechanism is 8, the fully connected layer uses the ReLU activation function, contains 128 neurons, and the number of neurons in the output layer is equal to the number of classification categories of the Raman spectral data. The learning classification model is trained by the Adam optimization algorithm, and the learning rate is set to 0.001. The 5-fold cross validation is used to reduce the overfitting phenomenon of the model through different training set and validation set combinations in each fold to improve the generalization performance of the model.
[0070] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. The patent protection scope of the present invention shall be based on the claims. All equivalent structural changes made using the contents of the description and drawings of the present invention should also be included in the protection scope of the present invention.
Claims
1. Raman spectrum classification method based on BiLSTM Multi-Head Attention, characterized by: include: Firstly, a number of Raman spectrum data are obtained, and a series of preprocessing is performed on the Raman spectrum data to obtain Raman spectrum data with obvious peak information; Secondly, build a deep learning classification model based on BiLSTM Multi-Head Attention. The deep learning classification model includes: Input layer: used to receive preprocessed Raman spectral data. The input shape of each sample is (batch_size, sequence_length, input_dim); BiLSTM layer: The first BiLSTM layer consists of forward and backward LSTMs to extract bidirectional time series features of spectral data; the second BiLSTM layer further extracts deep time series features; Attention mechanism layer: weights are assigned to features at different time steps through a multi-head self-attention mechanism to highlight features that are important for the classification task; Fully connected layer: used to map the output of the attention mechanism to the feature space required for the classification task; Output layer: Use the Softmax activation function to map the output results to classification probabilities; Then, the learning classification model was trained through 5-fold cross validation to optimize the model parameters; Finally, the learned classification model is evaluated on the test set, the classification accuracy, recall and F1-score indicators are calculated, and the confusion matrix is generated.
2. The Raman spectrum classification method based on BiLSTM Multi-Head Attention according to claim 1, characterized in that: The preprocessing of Raman spectroscopy data includes: Baseline correction: Adaptive penalized least squares method is used to correct the baseline drift of Raman spectrum; Smoothing: Savitzky-Golay filtering method is used to smooth the Raman spectrum to remove noise; Normalization: Use the normalization function to normalize the intensity of the Raman spectrum to the interval [0,1] to improve data consistency.
3. The Raman spectrum classification method based on BiLSTM Multi-Head Attention according to claim 1 or 2, characterized in that: The BiLSTM layer contains two hidden layers, each of which consists of 64 hidden units and uses tanh as the activation function.
4. The Raman spectrum classification method based on BiLSTM Multi-Head Attention according to claim 1 or 2, characterized in that: The number of heads of the multi-head self-attention mechanism is 8.
5. The Raman spectrum classification method based on BiLSTM Multi-Head Attention according to claim 1, characterized in that: The fully connected layer uses the ReLU activation function and contains 128 neurons.
6. The Raman spectrum classification method based on BiLSTM Multi-Head Attention according to claim 1, characterized in that: The number of neurons in the output layer is equal to the number of classification categories of the Raman spectroscopy data.
7. The Raman spectrum classification method based on BiLSTM Multi-Head Attention according to claim 1, characterized in that: The learning classification model is trained using the Adam optimization algorithm, and the learning rate is set to 0.
001.
8. The Raman spectrum classification method based on BiLSTM Multi-Head Attention according to claim 1, characterized in that: The 5-fold cross validation is used to reduce the overfitting of the model through different combinations of training sets and validation sets in each fold to improve the generalization performance of the model.
Citation Information
Cited By
Raman spectrum abnormal data detection method and system based on deep learning
CN119939226A