A sleep staging method based on sparse attention mechanism

By combining multi-segment sequence input and sparse attention mechanism with Transformer encoding layer, the problem of high computational complexity and large storage consumption in sleep staging of deep learning methods is solved. By reducing the computational complexity and storage consumption in sleep staging, the accuracy and efficiency of sleep staging are significantly improved, making up for the shortcomings of traditional methods in long time series analysis, and significantly improving the accuracy and efficiency of sleep staging.

CN120093214BActive Publication Date: 2025-12-05SOUTH CHINA UNIV OF TECH
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510108123.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-01-23
Publication Date
2025-12-05
Estimated Expiration
2045-01-23

AI Technical Summary

Technical Problem

Existing deep learning methods have high computational complexity and large storage consumption in sleep staging, making it difficult to effectively capture long-term related sleep features. Furthermore, traditional methods are inefficient in long-term analysis and cannot effectively utilize the spatiotemporal features of sleep signals, resulting in low efficiency and insufficient accuracy in long-term signal processing.

Method used

By employing multiple segment sequence inputs, combining a sparse attention mechanism and a Transformer encoding layer, features are extracted through a convolutional sliding window. The sparse attention mechanism is used to select key feature connections, reducing computational complexity and capturing long-term temporal information. Window feature extraction and Transformer integration of segment sequence features improve staging accuracy.

Benefits of technology

It significantly improves the accuracy and efficiency of sleep staging, reduces computational complexity while maintaining high accuracy, is highly adaptable, can be extended to the analysis of various physiological signals, and has strong transferability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120093214B_ABST
    Figure CN120093214B_ABST
Patent Text Reader

Abstract

The application discloses a sleep staging method based on a sparse attention mechanism, comprising the following steps: obtaining and preprocessing sleep signals to obtain a plurality of segment sequences; taking a target segment sequence and a plurality of segment sequences before and after the target segment sequence as input units; extracting time domain features of each segment sequence input by using a sliding window; inputting the time domain features of each segment sequence into a Transformer encoding layer adopting a sparse attention mechanism to perform feature enhancement; integrating the enhanced features of each segment sequence to obtain comprehensive feature representations of the input units and inputting the feature representations into the Transformer encoding layer to perform feature enhancement; and inputting the enhanced features of the input units into a pooling layer and a full connection layer to perform sleep stage classification and output. The application can reduce the calculation burden, retain key features of the sleep signals, and improve the accuracy and efficiency of sleep staging.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of biomedical signal processing, and particularly refers to a sleep staging method based on a sparse attention mechanism. BACKGROUND

[0002] Sleep staging is an important means commonly used in scientific research to measure the sleep quality and structure of individuals. At present, the traditional sleep staging method mainly relies on manual annotation, which is time-consuming and easily affected by the subjective experience of the annotator. The rise of automatic sleep staging technology makes it possible to automatically complete sleep staging by using multi-channel signals such as EEG (electroencephalogram), EOG (electrooculogram) and EMG (electromyogram) in combination with machine learning or deep learning models.

[0003] Existing deep learning methods are mostly based on CNN, RNN or standard Transformer models. CNN can extract local features, but has certain limitations in modeling long-time sequence correlation. RNN and LSTM can capture long-range dependencies, but are slow in processing long sequences and are prone to gradient vanishing or explosion problems. Standard Transformer has extremely high computational complexity and huge memory consumption for long sequence data due to the use of full-attention calculation. Sleep staging involves long-time sequence, and usually needs to capture the gradual transformation features of sleep stages in a larger time range (several minutes to tens of minutes). At the same time, sleep signals have complex time sequence dependencies and fine-grained feature differences, and efficient feature extraction and encoding methods are needed to capture macro time information and micro window features.

[0004] Therefore, there is a need for a deep learning method that can reduce attention calculation complexity and utilize longer time sequence context information to better adapt to actual sleep staging tasks. The present application proposes a new method to address the above problems, which fully utilizes sleep signal context information through multiple segment sequence input, effectively reduces computational complexity through sparse attention mechanism, significantly improves staging accuracy through window feature extraction and Transformer feature extraction of segment sequences, and feature extraction of integrated features of each segment sequence by Transformer. SUMMARY

[0005] The present application aims to overcome the deficiencies of the prior art, and provides a sleep staging method based on a sparse attention mechanism, which can realize efficient and accurate automatic sleep stage classification. The technology makes full use of the context information of the sleep signal by using multiple segment sequence inputs, effectively reduces the computational complexity by using a sparse attention mechanism, and enhances the ability to capture key features by using window feature extraction and Transformer to extract features from the segment sequence, and using Transformer to extract features from the integrated features of each segment sequence, thereby improving the accuracy and running efficiency of sleep staging.

[0006] To achieve the above object, the technical scheme provided by the present application is as follows: a sleep staging method based on a sparse attention mechanism, comprising the following steps:

[0007] S1, obtaining a multi-channel sleep signal and preprocessing to obtain a single-channel sleep signal, dividing the single-channel sleep signal into a plurality of continuous segment sequences with a time length of t seconds;

[0008] S2, taking the target segment sequence and its preceding and subsequent n segment sequence data, a total of m segment sequences, as an input unit, wherein m=2n+1, and n is a positive integer;

[0009] S3, performing feature extraction on each segment sequence in the input unit, and using a convolution sliding window to extract the time domain features of the segment sequence;

[0010] S4, for each segment sequence, inputting the extracted time domain features into a Transformer encoding layer using a sparse attention mechanism, selecting key features for connection within the segment through the sparse attention mechanism, and obtaining features enhanced by features;

[0011] S5, integrating the features enhanced by each segment sequence to form a comprehensive feature representation of the input unit, and inputting the feature representation into the Transformer encoding layer to capture the temporal correlation between segments, and obtaining the input unit features enhanced by features;

[0012] S6, inputting the input unit features enhanced by features into a global average pooling layer, and then inputting the pooled features into a multi-layer fully connected layer for sleep stage classification output.

[0013] Further, in step S1, for the obtained multi-channel sleep signal, the preprocessing includes: filtering the multi-channel sleep signal using a band-pass filter to remove noise information; and intercepting the effective interval, retaining only the interval entering sleep, starting from the first non-wake period to record data, and ending at the last non-wake period; selecting one channel from the preprocessed multi-channel sleep signal as a single-channel input.

[0014] Further, in step S3, convolution sliding window feature extraction is used, and the step size is set to half of the window size, ensuring that adjacent windows overlap each other and retain smooth transitions of local time features; the feature tensor obtained after sliding window feature extraction is input into a depth separable convolution layer, and then point convolution is used to linearly combine each channel to obtain the time domain features of the segment sequence.

[0015] Further, in step S4, for each segment sequence, the extracted time domain features are input into a Transformer encoding layer that adopts a sparse attention mechanism, the encoding layer is composed of a Transformer Encoder, and a Top-T sparse attention mechanism is adopted, only the attention weights between each query vector and its most relevant T key vectors are calculated, thereby significantly reducing the amount of full-attention calculation, and the specific steps are as follows:

[0016] S41, feature input and linear transformation: input the time domain features into the Transformer encoding layer, and generate query vectors, key vectors and value vectors through linear transformation:

[0017] Q=XW Q

[0018] K=XW K

[0019] V=XW V

[0020] In the formula, X is the input feature, which is the time domain feature after processing by the depth separable convolution layer, i.e. the window feature matrix; Q is the query vector, which is used for similarity calculation with the key vector to determine the focus of attention distribution; K is the key vector, which is matched with the query vector to determine the attention weight; V is the value vector, which is weighted and summed according to the attention weight to generate the final output feature; W Q , W K , W V is a weight matrix, which is a linear transformation matrix for mapping the input feature to the query vector, the key vector and the value vector;

[0021] S42, similarity calculation: calculate the similarity between the query vector and all key vectors:

[0022]

[0023]

[0024] In the formula, Q i is the i-th query vector; K j is the j-th key vector; Score(Q i ,K j ) is the similarity between the query vector Q isimilarity score of query vector Q j and key vector K k ; symbol • is the dot product operation in vector, which calculates the similarity of two vectors; d model is the dimension of key vector; d i is the input feature dimension; num_heads is the number of attention heads;

[0025] S43, Top-T selection: for each query vector, select the top T key vectors with the highest similarity, only calculate the attention weight of these key vectors, and form a sparse attention connection:

[0026] Top_T(Q j ) = {j | j ∈ Top_T) Score(Q i , K j )}

[0027] In the formula, Top_T(Q i ) is the index set of the top T key vectors with the highest similarity score with query vector Q i ; Score(Q i , K j ) is the similarity score of query vector Q i and key vector K j ; Top_T(Score(Q i , K j )) is the top T score values in the similarity scores of query vector Q i and all key vectors K j ;

[0028] S44, attention weight calculation and weighted summation: only the selected Top-T key vectors are weighted and summed to generate the output feature:

[0029]

[0030] In the formula, α ij is the normalized attention weight of query vector Q i and key vector K j ; Top_T(Q i ) is the index set of the top T key vectors with the highest similarity score with query vector Q i ; softmax(·) is the softmax function, which converts the input vector into a probability distribution, so that the sum of all output values is 1; V j is the value vector corresponding to key vector K j ; Attention i is the final output feature of query vector Q i .

[0031] Further, in step S5, the features of each segment sequence are integrated after feature enhancement, including splicing the features of multiple segment sequences in the channel dimension, and then passing through a one-dimensional convolution layer to form a comprehensive input unit feature representation; the input unit feature representation is input into a Transformer encoding layer to capture the temporal correlation between segments, and the encoding layer is composed of a Transformer Encoder.

[0032] Further, the specific steps of step S6 are as follows:

[0033] S61, input the input unit feature after feature enhancement into a global average pooling layer to obtain the pooled feature;

[0034] S62, pass the pooled feature through a first fully connected layer, introduce nonlinearity through a ReLU activation function, and apply Dropout regularization to reduce the risk of overfitting;

[0035] S63, after passing through a second fully connected layer, the feature is further mapped to the output space of the sleep stage category, the output is converted into a probability distribution of each category through a Softmax function, and the category with the highest probability is taken as the final prediction result.

[0036] Compared with the prior art, the present application has the following advantages and beneficial effects:

[0037] 1. The present application combines the target segment sequence and its front and rear segment sequence data into a group of inputs to form multiple segment sequence inputs, so that the present application can capture sleep signal change information in a longer time range, and compared with the traditional method of analyzing only the target segment sequence, the multiple segment sequence inputs significantly improve the understanding of the physiological sleep stage transition and continuity, and achieve more accurate and stable staging results;

[0038] 2. The present application adopts a Top-T sparse attention mechanism to calculate only the first T key vectors with the highest similarity. This sparse attention mechanism not only effectively reduces the calculation burden and storage overhead of full-amount attention, but also highlights the most discriminative feature connections in the sleep signal and improves the capture efficiency of key time sequence information, and compared with the traditional global attention model, it greatly reduces the calculation complexity while maintaining high accuracy;

[0039] 3. The use of window feature extraction and Transformer for segment sequence feature extraction, and the use of Transformer for feature extraction of the integrated features of each segment sequence, can capture the potential long-range temporal dependency between different segment sequences, and the structure of extracting features from segment sequences and integrated features of each segment sequence compensates for the defect of the traditional single segment sequence analysis method that lacks continuity.

[0040] 4、The application has strong adaptability and versatility, and can be extended to analysis of multiple physiological signals. Although the application focuses on sleep staging, the multiple segment sequence inputs, feature extraction methods, and sparse attention mechanisms can also be extended to long-term sequence analysis of other physiological signals, and have strong transferability and applicability.

[0041] In summary, the application cooperates with each other in aspects such as multiple segment sequence inputs, sparse attention mechanisms, and feature extraction, not only greatly reduces the computational load, but also significantly improves the accuracy and robustness of sleep staging, makes up for the deficiencies of the prior art in insufficient use of long-term sequence information or high computational cost, and has obvious advantages and beneficial effects. BRIEF DESCRIPTION OF DRAWINGS

[0042] Figure 1 The figure is a framework diagram of the method of the application.

[0043] Figure 2 The figure is a schematic diagram of the sparse attention mechanism. DETAILED DESCRIPTION

[0044] The application will be described in further detail below in conjunction with the embodiments and the accompanying drawings, but the embodiments of the application are not limited thereto.

[0045] As shown in Figure 1 and Figure 2 , the embodiment discloses a sleep staging method based on a sparse attention mechanism, and the specific circumstances are as follows:

[0046] S1, multiple channel sleep signals are obtained and preprocessed to obtain single channel sleep signals, and the single channel sleep signals are divided into multiple continuous segment sequences with a time length of t seconds;

[0047] For the obtained multiple channel sleep signals, the pre-processing performed includes: filtering the multiple channel sleep signals using a band-pass filter to remove noise information; and intercepting the effective interval to only retain the interval entering sleep, starting from the first non-wake period to record data, and ending at the last non-wake period; selecting one channel from the pre-processed multiple channel sleep signals as a single channel input.

[0048] S2, the target segment sequence and the data of the n segment sequences before and after it, a total of m segment sequences, are collectively used as an input unit, where m = 2n + 1, and n is a positive integer;

[0049] S3, feature extraction is performed on each segment sequence in the input unit, and a convolution sliding window is used to extract the time domain features of the segment sequence, specifically as follows:

[0050] The convolution sliding window feature extraction is used, and the step size is set to half of the window size, so as to ensure that adjacent windows overlap each other and smooth transition of local time features is reserved; the feature tensor obtained through the sliding window feature extraction is input into a depth separable convolution layer, and then point convolution is used to linearly combine each channel, so as to obtain time domain features of the segment sequence.

[0051] S4, for each segment sequence, the extracted time domain features are input into a Transformer encoding layer adopting a sparse attention mechanism, key features are selected and connected within the segment through the sparse attention mechanism, and features enhanced through the features are obtained;

[0052] For each segment sequence, the extracted time domain features are input into a Transformer encoding layer adopting a sparse attention mechanism, the encoding layer is composed of a Transformer Encoder, and a Top-T sparse attention mechanism is adopted, only the attention weights between each query vector and the T most relevant key vectors are calculated, so that the calculation amount of full attention is significantly reduced, and the specific steps are as follows:

[0053] S41, feature input and linear transformation: the time domain features are input into the Transformer encoding layer, and query vectors, key vectors and value vectors are generated through linear transformation:

[0054] Q=XW Q

[0055] K=XW K

[0056] V=XW V

[0057] In the formula, X is the input feature, which is the time domain feature processed through the depth separable convolution layer, that is, the window feature matrix; Q is the query vector, which is used for similarity calculation with the key vector and determines the focus of attention distribution; K is the key vector, which is matched with the query vector and is used to determine the attention weight; V is the value vector, which is weighted and summed according to the attention weight, and generates the final output feature; W Q , W K , W V is a weight matrix, which is a linear transformation matrix for mapping the input feature to the query vector, the key vector and the value vector;

[0058] S42, similarity calculation: the similarity between the query vector and all key vectors is calculated:

[0059]

[0060] In the formula, Q i is the i query vector; K jis the j-th key vector; Score(Q i , K j ) is the similarity score of query vector Q i and key vector K j ; the symbol · is the dot product operation in vectors, which calculates the similarity of two vectors; d k is the dimension of key vectors; d model is the input feature dimension; num_heads is the number of attention heads;

[0061] S43, Top-T selection: for each query vector, select the top T key vectors with the highest similarity, only calculate the attention weights of these key vectors, and form a sparse attention connection:

[0062] Top_T(Q i ) = {K j | j e Top_T(Score(Q i , K j (

[0063] In the formula, Top_T(Q i ) is the index set of the top T key vectors with the highest similarity score with query vector Q i ; Score(Q i , K j ) is the similarity score of query vector Q i and key vector K j ; Top_T(Score(Q i , K j )) is the top T score values in the similarity scores of query vector Q i and all key vectors K j ;

[0064] S44, attention weight calculation and weighted summation: only the selected Top-T key vectors are weighted and summed to generate the output feature:

[0065]

[0066] In the formula, a ij is the normalized attention weight of query vector Q i and key vector K j ; Top_T(Q i ) is the index set of the top T key vectors with the highest similarity score with query vector Q i ; softmax(·) is the softmax function, which converts the input vector into a probability distribution, so that the sum of all output values is 1; V j is the value vector corresponding to key vector K j ; Attentioni is the query vector Q i is the final output feature.

[0067] S5, integrate the feature enhanced features of each segment sequence to form a comprehensive input unit feature representation, and input the feature representation to the Transformer encoding layer to capture the temporal correlation between segments to obtain the input unit feature enhanced by the feature; wherein integrating the feature enhanced features of each segment sequence includes concatenating the features of the plurality of segment sequences in the channel dimension, then passing through a one-dimensional convolution layer to form a comprehensive input unit feature representation; input the input unit feature representation to the Transformer encoding layer to capture the temporal correlation between segments, and the encoding layer is composed of a Transformer Encoder.

[0068] S6: input the input unit feature enhanced by the feature into a global average pooling layer, and then input the pooled feature into a multi-layer fully connected layer to output the sleep stage classification, the specific steps are as follows:

[0069] S61, input the input unit feature enhanced by the feature into a global average pooling layer to obtain the pooled feature;

[0070] S62, pass the pooled feature through the first layer of fully connected layer, introduce nonlinearity through ReLU activation function, and apply Dropout regularization to reduce the risk of overfitting;

[0071] S63, after passing through the second layer of fully connected layer, map the feature to the output space of the sleep stage category, convert the output to the probability distribution of each category through the Softmax function, and take the category with the maximum probability as the final prediction result.

[0072] The above embodiments are the preferred embodiments of the present application, but the embodiments of the present application are not limited by the above embodiments, and any changes, modifications, substitutions, combinations, simplifications made without departing from the spirit and principles of the present application are equivalent replacement methods, and are all included in the protection scope of the present application.

Claims

1. A sleep staging method based on sparse attention mechanism, characterized in that, The method comprises the following steps: S1, obtaining a multi-channel sleep signal and preprocessing to obtain a single-channel sleep signal, and dividing the single-channel sleep signal into a plurality of continuous segment sequences with a time length of t seconds; S2, taking the target segment sequence and the data of the n segment sequences before and after the target segment sequence, i.e., a total of m segment sequences, as an input unit, wherein m=2n+1, and n is a positive integer; S3, performing feature extraction on each segment sequence in the input unit, and extracting time domain features of the segment sequence by using a convolution sliding window; S4, inputting the extracted time domain features into a Transformer encoding layer adopting a sparse attention mechanism, selecting key features for connection within the segment through the sparse attention mechanism, and obtaining features enhanced by the characteristics; S5, integrating the features enhanced by the characteristics of each segment sequence to form a comprehensive feature representation of the input unit, and inputting the feature representation into the Transformer encoding layer to capture the time sequence correlation between the segments, and obtaining the input unit features enhanced by the characteristics; S6, inputting the input unit features enhanced by the characteristics into a global average pooling layer, and then inputting the pooled features into a multi-layer fully connected layer to output the sleep stage classification.

2. The sleep staging method based on sparse attention mechanism according to claim 1, wherein, In step S1, for the obtained multi-channel sleep signal, the preprocessing includes: filtering the multi-channel sleep signal by using a band-pass filter to remove noise information; and intercepting the effective interval to only retain the interval entering sleep, starting from the first non-wake period to record data, and ending at the last non-wake period; and selecting one channel from the preprocessed multi-channel sleep signal as a single-channel input.

3. The sleep staging method based on sparse attention mechanism according to claim 2, wherein, In step S3, the convolution sliding window feature extraction is used, and the step size is set to half of the window size to ensure that adjacent windows overlap each other and retain smooth transitions of local time features; the feature tensor obtained by the sliding window feature extraction is input into a depth separable convolution layer, and then point convolution is used to linearly combine each channel to obtain the time domain features of the segment sequence.

4. The sleep staging method based on sparse attention mechanism according to claim 3, wherein, In step S4, for each segment sequence, the extracted time domain features are input into a Transformer encoding layer adopting a sparse attention mechanism. The encoding layer is composed of a Transformer Encoder, and a Top-T sparse attention mechanism is adopted to only calculate the attention weights between each query vector and the T most relevant key vectors, thereby significantly reducing the amount of full-attention calculation. The specific steps are as follows: S41, feature input and linear transformation: inputting the time domain features into the Transformer encoding layer and generating query vectors, key vectors and value vectors through linear transformation: Q = XW Q K = XW K V = XW V wherein X is the input feature, which is the time domain feature processed by the depth separable convolution layer, i.e., the window feature matrix; Q is the query vector, which is used for similarity calculation with the key vector to determine the focus of attention distribution; K is the key vector, which is matched with the query vector to determine the attention weight; V is the value vector, which is weighted and summed according to the attention weight to generate the final output feature; W Q 、W K 、W V is a weight matrix, which is a linear transformation matrix for mapping the input features to the query vector, the key vector, and the value vector; S42, similarity calculation: calculating the similarity between the query vector and all key vectors: where Q i is an i-th query vector; K j is a j-th key vector; Score(Q i , K j ) is a similarity score of query vector Q i and key vector K j ; the symbol • is a dot product operation in vectors, which calculates the similarity of two vectors; d k is the dimension of key vectors; d model is the input feature dimension; num_heads is the number of attention heads; S43, Top-T selection: for each query vector, select the top T key vectors with the highest similarity, only calculate the attention weights of these key vectors, and form a sparse attention connection: Top_T(Q i ) = {K j | j e Top_T(Score(Q i , K j ))} where Top_T(Q i ) is the index set of the top T key vectors with the highest similarity scores to the query vector Q i ; Score(Q i , K j ) is the similarity score of the query vector Q i and the key vector K j ; Top_T(Score(Q i , K j )) is the top T score values among the similarity scores of the query vector Q i and all key vectors K j . S44, attention weight calculation and weighted summation: only the selected Top-T key vectors are weighted and summed to generate the output feature: In the formula, α ij For query vector Q i With key vector K j Normalized attention weights; Top_T(Q i ) is related to the query vector Q i The set of indices of the top T key vectors with the highest similarity scores; softmax(·) is the softmax function, which transforms the input vector into a probability distribution such that the sum of all output values ​​is 1; V j It is related to the key vector K j The corresponding value vector; Attention i It is the query vector Q i The final output features.

5. The sleep staging method based on sparse attention mechanism according to claim 4, wherein, In step S5, the features of each segment sequence are integrated after feature enhancement, including concatenating the features of multiple segment sequences in the channel dimension, then passing through a one-dimensional convolution layer to form a comprehensive input unit feature representation; the input unit feature representation is input into the Transformer encoding layer to capture the temporal correlation between segments, and the encoding layer is composed of a Transformer Encoder.

6. The sleep staging method based on sparse attention mechanism according to claim 5, wherein, The specific steps of step S6 are as follows: S61, input the input unit feature after feature enhancement into the global average pooling layer to obtain the pooled feature; S62, pass the pooled feature through the first fully connected layer, introduce nonlinearity through the ReLU activation function, and apply Dropout regularization to reduce the risk of overfitting; S63, after passing through the second fully connected layer, the feature is further mapped to the output space of the sleep stage category, the output is converted into a probability distribution of each category through the Softmax function, and the category with the maximum probability is taken as the final prediction result.

Citation Information

Patent Citations

  • Long time series data prediction method based on bidirectional sparse mechanism Transform

    CN116541435A

  • Sparse attention computation model and method, electronic device, and storage medium

    WO2023221940A1