A Raman spectroscopy classification method based on self-attention mechanism

By introducing a self-attention mechanism into the Raman spectral classification model and extracting multi-scale features in convolutional operations, the problem of insufficient accuracy in the processing of low signal-to-noise Raman spectral data is solved, and high-precision spectral classification and simplified processing flow are achieved.

CN115130566BActive Publication Date: 2025-04-11ZHEJIANG UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202210696961.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-06-20
Publication Date
2025-04-11
Estimated Expiration
2042-06-20

AI Technical Summary

Technical Problem

The existing Raman spectral classification model is difficult to achieve higher accuracy when processing conventional Raman spectral data with relatively low signal-to-noise.

Method used

The Raman spectral classification method based on the self-attention mechanism is adopted, and the multi-scale global features and hierarchical features of the Raman spectroscopy are extracted through the fusion of convolutional operations and the self-attention mechanism, thereby improving the modeling ability and classification accuracy of the model.

Benefits of technology

High-precision classification of conventional Raman spectra is realized, data processing steps are simplified, and has good scalability, and is suitable for analysis of other forms of spectral spectra.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115130566B_ABST
    Figure CN115130566B_ABST
Patent Text Reader

Abstract

The present invention discloses a Raman spectrum classification method based on a self-attention mechanism. The method comprises the following steps: preprocessing data according to spectral quality; inputting spectral data into several components based on a self-attention mechanism to extract features; inputting the extracted features into a fully connected layer to obtain the output of category probability; adjusting model parameters continuously through an Adam optimization algorithm according to a loss function to obtain the global optimal solution parameters of the fit; inputting test set data into the trained model to output the classification results. Compared with the prior art, the method enhances the modeling capability of global features, and can extract hierarchical features of multi-scale spectra of Raman spectra, thereby achieving a higher classification accuracy, and effectively promoting the promotion of applications such as early cancer diagnosis and bacterial classification based on Raman spectroscopy.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to a spectrum classification method, and in particular to a Raman spectrum classification method based on a self-attention mechanism. Background Art

[0002] Raman spectroscopy is a spectral technology developed based on the principle of Raman scattering. It can detect the structure and composition of proteins, lipids, DNA and other biomacromolecules in biological samples, and provide rich molecular level information. Raman spectroscopy is often called "molecular fingerprint". It has the advantages of being simple, fast, real-time and non-invasive, highly sensitive and low-cost. With the development of Raman spectroscopy technology, from the study of tissue specimens to the detection of single cells, from cancer tissue detection to the identification of body fluid specimens, Raman spectroscopy technology has been widely used in the field of medical research and has great application potential. The rise and rapid development of interdisciplinary subjects has rapidly promoted the research and application of Raman spectroscopy.

[0003] However, the existing Raman spectroscopy classification models based on traditional machine learning methods, CNN network structures, etc., which are widely used, can effectively distinguish data based on surface-enhanced Raman spectroscopy, but they still cannot achieve high accuracy for spectral data with low signal-to-noise ratio, such as conventional Raman spectroscopy data containing high noise.

[0004] With the continuous advancement of science and technology, the practice and promotion of applications have higher and higher requirements for the accuracy of Raman spectroscopy. In addition to the improvement of Raman spectroscopy technology, on the other hand, the analysis technology for Raman spectroscopy is also developing. The present invention provides a Raman spectroscopy classification method based on a self-attention mechanism. By integrating the convolution operation with the self-attention mechanism, the model's modeling ability for the global features of the Raman spectrum is enhanced, and the hierarchical features of the multi-scale spectrum can be extracted at the same time, thereby achieving a higher classification accuracy. The method can simply and quickly classify conventional Raman spectra without the need for complex steps such as complex nano-substrate preparation and material quality control. In addition, the method can also be easily extended to the analysis of other forms of spectra, which can effectively promote the implementation of applications such as early cancer diagnosis and bacterial classification based on spectral data. Summary of the invention

[0005] The purpose of the present invention is to provide a Raman spectrum classification method based on the self-attention mechanism. Compared with the existing methods, the present method can provide better feature extraction capability and obtain higher-precision classification results. At the same time, the method has high scalability and high practical value.

[0006] The purpose of the present invention is achieved through the following technical solutions:

[0007] A Raman spectrum classification method based on a self-attention mechanism comprises the following steps:

[0008] Step S1, preprocessing the data according to the spectral quality;

[0009] Step S2, inputting the spectral data into several components based on the self-attention mechanism to extract features;

[0010] Step S3, input the extracted features into the fully connected layer to obtain the output of the category probability;

[0011] Step S4, adjusting the model parameters by using the Adam optimization algorithm according to the loss function to obtain the global optimal solution parameters of the fit;

[0012] Step S5: input the test set data into the trained model and output the classification result.

[0013] Furthermore, the step S1 comprises:

[0014] Step S11, discarding the Raman spectra with a spectral intensity of 0;

[0015] Step S12, judging whether to perform baseline correction on the Raman spectrum according to the quality of the Raman spectrum data;

[0016] Step S13, normalizing the Raman spectrum.

[0017] Furthermore, the step S2 comprises:

[0018] Step S21: input the preprocessed spectral data X into the multi-scale encoding submodule of the component, apply k one-dimensional convolution kernels with different sizes, step sizes and dimensions to the Raman spectral data X, and concatenate the results of the k convolution operations to obtain Raman data X containing multiple scale information. E ;

[0019] Step S22: The encoded spectrum data X E The input component consists of a Transformer submodule consisting of m feature extractors in series, and obtains X T ;

[0020] Step S23, using the output of the previous component as the input of the next component, repeating N times, and obtaining the output of the Nth component as the feature Z extracted from the Raman spectrum.

[0021] Furthermore, the step S22 includes:

[0022] Step S221: The encoded spectrum data X E Input the Multi-HeadAttention sublayer with residual connection in the feature extractor and get the output X Attention ;

[0023] XAtorntion =LayerNorm(X E +f(X E ))

[0024] f(·)=MultiHead(Q, K, V)=Concat(head1, head2,..., head h )W O

[0025]

[0026]

[0027] in, Q, K, V = X E , d represents the dimension after the convolution operation, c represents the number of k scale convolution kernels, and h represents the number of multi-head attention mechanisms. is the training parameter;

[0028] Step S222: X Attention Input the Feed Forward sublayer with residual connection in the feature extractor to get the output X Forward :

[0029] g(x)=max(0,xW1+b1)W2+b2

[0030] X Forward =LayerNorm(X Attention +g(X Attention ))

[0031] in, is the training parameter;

[0032] Step S223: Use the output of the previous feature extractor as the input of the next feature extractor, repeat m times, and obtain the output X of the Transformer module. T .

[0033] Furthermore, the step S3 comprises:

[0034] Step S31, extracting the Raman spectrum feature X T Perform layer standardization;

[0035] Step S32, input the normalized data into the fully connected layer to obtain the output of category probability.

[0036] Furthermore, the step S4 comprises:

[0037] Step S41, calculating the gap between the model prediction result and the actual result according to the cross entropy loss function;

[0038] Step S42, according to the derivative of the loss function, use the Adam optimization algorithm to continuously iterate and update the parameters to obtain the global optimal parameters of the fit.

[0039] The beneficial effects of the present invention are as follows: the present invention, through the complementarity of convolution operation and self-attention mechanism, takes into account both local and global features more than the existing methods, can mine the multi-scale information of Raman spectra, enhance the modeling ability of the model, extract hierarchical feature representation, effectively improve the classification accuracy of Raman spectra, and provide support for applications based on Raman spectroscopy in fields such as physical materials and biomedicine. BRIEF DESCRIPTION OF THE DRAWINGS

[0040] Figure 1 It is a flow chart of the Raman spectrum classification method based on the self-attention mechanism of the present invention;

[0041] Figure 2 It is the calculation flow chart of the Transformer submodule in the present invention;

[0042] Figure 3 is a schematic diagram of spectrum data of the present invention applied to an embodiment;

[0043] Figure 4 is a training loss curve diagram of the present invention applied to an embodiment;

[0044] Figure 5 4 is a diagram of classification results of the present invention applied to an embodiment. DETAILED DESCRIPTION

[0045] The specific implementation method and working principle of the present invention are described in detail below in conjunction with the accompanying drawings:

[0046] Example

[0047] The data set used in this example is from the Second Affiliated Hospital of Zhejiang University. Figure 3 As shown in the figure, the data contains 33 healthy people, 30 adenoma patients and 40 cancer patients, and each person contains 900 Raman spectra, of which 20% (20 people) of the data is used as a test set. Figure 1 As shown, the implementation steps of the method are as follows:

[0048] Step S1, preprocessing the data according to the spectral quality, the specific implementation steps are as follows:

[0049] Step S11: discarding the Raman spectra whose spectral intensity contains 0. In this embodiment, the proportion of Raman spectra whose intensity contains 0 is 0.008%, and this part of Raman spectra is discarded;

[0050] Step S12: judging whether to perform baseline correction on the Raman spectrum according to the quality of the Raman spectrum data. In this embodiment, no baseline correction is performed on the Raman spectrum;

[0051] Step S13: Normalize the Raman spectrum. In this embodiment, the intensity of the Raman spectrum is normalized to [0, 1], and the dimension of the Raman spectrum is (1024, 1). Figure 3 shown.

[0052] Step S2: Input the spectral data into several components based on the self-attention mechanism to extract features. The specific implementation steps are as follows:

[0053] Step S21: Input the preprocessed spectral data X into the multi-scale encoding submodule of the component, apply k one-dimensional convolution kernels with different sizes, steps and dimensions to the Raman spectral data X, and concatenate the results of the k convolution operations to obtain Raman data X containing multiple scale information. E In this embodiment, four convolution kernels are selected in turn to act on the preprocessed Raman spectrum X, with sizes of (4, 8, 16, 32), steps of (4, 4, 4, 4), and dimensions of (32, 16, 8, 8). Then, they are concatenated in turn to obtain X with a dimension of (256, 64). E ;

[0054] Step S22: The encoded spectrum data X E The input component consists of a Transformer submodule consisting of m feature extractors in series, and obtains X T In this embodiment, the value of m is 3. The specific steps are as follows:

[0055] Step S221: The encoded spectrum data X E Input the Multi-HeadAttention sublayer with residual connection in the feature extractor and get the output X Attention :

[0056] X Attention =LayerNorm(X E +f(X E ))

[0057] f(·)=MultiHead(Q, K, V)=Concat(head1, head2,..., head h )W O

[0058]

[0059]

[0060] in, Q, K, V = X E , d represents the dimension after the convolution operation, c represents the number of k scale convolution kernels, and h represents the number of multi-head attention mechanisms. is a training parameter. In this embodiment, input X E The dimension is (256, 64), output X Attention The dimension is (256, 64), and the value of h is 8;

[0061] Step S222: X Attention Input the Feed Forward sublayer with residual connection in the feature extractor to get the output X Forward :

[0062] g(x)=max(0,xW1+b1)W2+b2

[0063] X Forward =LayerNorm(X Attention +g(X Attention ))

[0064] in, is a training parameter. In this embodiment,

[0065] Step S223: Use the output of the previous feature extractor as the input of the next feature extractor, repeat m times, and obtain the output X of the Transformer module T In this embodiment, the value of m is 3.

[0066] Step S23: Use the output of the previous component as the input of the next component, repeat N times, and obtain the output of the Nth component as the feature Z extracted from the Raman spectrum. In this embodiment, the value of N is 2.

[0067] Step S3, input the extracted features into the fully connected layer to obtain the output of the category probability. The specific implementation steps are as follows:

[0068] Step S31: extracting the Raman spectrum feature X T Perform LayerNormalization. In this example, after feature extraction, X T The dimension is (32, 256);

[0069] Step S32: Input the normalized data into the fully connected layer to obtain the output of the class probability. In this example, the class output of a Raman spectrum for three classifications is [0.01, 0.82, 0.17].

[0070] Step S4: According to the loss function, the model parameters are continuously adjusted through the Adam optimization algorithm to obtain the global optimal solution parameters of the fitting. The specific implementation steps are as follows:

[0071] Step S41: Calculate the gap between the model prediction result and the actual result according to the cross entropy loss function. In this example, a three-class cross entropy function is used;

[0072] Step S42: Based on the derivative of the loss function, the Adam optimization algorithm is used to iteratively update the parameters to obtain the global optimal parameters of the fit. In this example, after the model converges, the lowest loss value is 0.13. The specific training loss curve is as follows: Figure 4 shown.

[0073] Step S5: Input the test set data into the trained model and output the classification result. In this embodiment, the test set has 32 samples in total. Figure 5 The final classification results are shown.

[0074] Based on Raman spectral data, the present invention completes the classification of Raman spectra through steps such as preprocessing, feature extraction and fully connected layer mapping, providing support for applications based on Raman spectroscopy in the fields of physical materials and biomedicine.

[0075] The above is only a preferred embodiment of the present invention. Although the present invention has been disclosed as a preferred embodiment, it is not intended to limit the present invention. Any technician familiar with the art can make many possible changes and modifications to the technical solution of the present invention by using the above disclosed methods and technical contents without departing from the scope of the technical solution of the present invention, or modify it into an equivalent embodiment of equivalent changes. Therefore, any simple modification, equivalent change and modification made to the above embodiments according to the technical essence of the present invention without departing from the content of the technical solution of the present invention still falls within the scope of protection of the technical solution of the present invention.

Claims

1. A Raman spectrum classification method based on self-attention mechanism, characterized in that: The following steps are involved: Step S1, preprocessing the data according to the spectral quality; Step S2, inputting the spectral data into several components based on the self-attention mechanism to extract features, including: Step S21: input the preprocessed spectral data X into the multi-scale encoding submodule of the component, apply k one-dimensional convolution kernels with different sizes, step sizes and dimensions to the Raman spectral data X, and concatenate the results of the k convolution operations to obtain Raman data X containing multiple scale information. E ; Step S22: the encoded spectrum data X E The input component consists of a Transformer submodule consisting of m feature extractors in series, and obtains X T ,include: Step S221: The encoded spectrum data X E Input the Multi-HeadAttention sublayer with residual connection in the feature extractor and get the output X Attention ; X Attention =LayerNorm(X E +f(X E )) f(·)=multiHead(Q,K,V)=Concat(head1,head2,…,Head h )W O in, Q,K,V=X E , d represents the dimension after the convolution operation, c represents the number of k scale convolution kernels, and h represents the number of multi-head attention mechanisms. is the training parameter; Step S222: X Attention Input the Feed Forward sublayer with residual connection in the feature extractor to get the output X Forward : g(x)=max(0,xW1+b1)W2+b2 X Forward =LayerNorm(X Attention +g(X Attention )) in, is the training parameter; Step S223: Use the output of the previous feature extractor as the input of the next feature extractor, repeat m times, and obtain the output X of the Transformer module. T ; Step S23, using the output of the previous component as the input of the next component, repeating N times, and obtaining the output of the Nth component as the feature Z extracted from the Raman spectrum; Step S3, input the extracted features into the fully connected layer to obtain the output of the category probability; Step S4, adjusting the model parameters by using the Adam optimization algorithm according to the loss function to obtain the global optimal solution parameters of the fit; Step S5: input the test set data into the trained model and output the classification result.

2. The Raman spectrum classification method based on the self-attention mechanism according to claim 1, characterized in that: The step S1 comprises: Step S11, discarding the Raman spectra with a spectral intensity of 0; Step S12, judging whether to perform baseline correction on the Raman spectrum according to the quality of the Raman spectrum data; Step S13, normalizing the Raman spectrum.

3. The Raman spectrum classification method based on the self-attention mechanism according to claim 1, characterized in that: The step S3 comprises: Step S31, extracting the Raman spectrum feature X T Perform layer standardization; Step S32, input the normalized data into the fully connected layer to obtain the output of category probability.

4. The Raman spectrum classification method based on the self-attention mechanism according to claim 1, characterized in that: The step S4 comprises: Step S41, calculating the gap between the model prediction result and the actual result according to the cross entropy loss function; Step S42, according to the derivative of the loss function, use the Adam optimization algorithm to continuously iterate and update the parameters to obtain the global optimal parameters of the fit.