Transform-based memory auto-encoder anomaly detection method

By introducing the Transformer architecture and conditional memory module into the memory autoencoder, the problem of insufficient detection ability and excessive generalization ability of close to normal anomalies in the existing technology is solved, and the accurate capture and anomaly identification of complex data patterns are achieved. Significantly improved anomaly detection performance.

CN118779805APending Publication Date: 2024-10-15CHONGQING TECH & BUSINESS UNIV +2
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202410966126.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-18
Publication Date
2024-10-15

AI Technical Summary

Technical Problem

The anomaly detection method based on memory autoencoders has limited recognition ability when dealing with abnormal data that is close to normal, has too strong generalization ability and relies on pre-trained models, resulting in limited performance in the absence of a large amount of pre-training data.

Method used

Using a Transformer-based memory autoencoder, combined with the Transformer encoder, decoder and conditional memory module, through block embedding and block merging operations, the Transformer's self-attention mechanism is used to capture complex patterns, and the conditional memory module is updated in real time to normal mode to improve the accuracy of anomaly detection.

Benefits of technology

It significantly improves the performance of anomaly detection, can more accurately capture complex data patterns, improves the ability to identify anomalies, simplifies the detection process and improves the adaptability and flexibility of the model.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118779805A_ABST
    Figure CN118779805A_ABST
Patent Text Reader

Abstract

The invention belongs to the technical field of anomaly detection, and particularly discloses a transform-based memory auto-encoder anomaly detection method, which comprises the following steps of: 1, constructing a neural network model by using the following strategies: in the model, combining a transform encoder, a transform decoder and a condition memory module into a transform memory auto-encoder; finally, recovering the feature x4 into a reconstructed sample # imgabs0 # through a block merging layer; 2, training the neural network model by using a normal sample; and step 3, inputting a detection sample into the trained model, calculating the difference between the original sample x and the reconstructed sample x5, if the difference is greater than a threshold value, determining that the sample is an abnormal sample, otherwise, determining that the sample is a normal sample. According to the method, more accurate capture and anomaly recognition of a complex data mode are realized, and the anomaly detection performance of the model during data processing is remarkably improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of anomaly detection, and specifically discloses an anomaly detection method of a transformer-based memory autoencoder. Background Art

[0002] Existing anomaly detection methods based on memory autoencoders combine the advantages of autoencoders in deep learning with additional memory modules, specifically targeting the problem of abnormal data identification in unsupervised or semi-supervised environments. The autoencoder part encodes the input data into a low-dimensional representation through training and then decodes and reconstructs it to learn the distribution and potential structure of the input data. The memory module is designed to preserve the key features of normal data observed during training. It can be a fixed or variable length data structure that accumulates and stores the representation of normal data. During training, the model accepts a large number of normal samples as input, and the autoencoder learns how to accurately reconstruct these normal samples, while the memory module records the features extracted during the learning process. This allows the model to build a tight model of normality, so that it can more sensitively capture abnormal data that does not match the pattern in memory in the subsequent detection stage. When new data flows in, the autoencoder attempts to reconstruct it and calculates the reconstruction error. If this error exceeds a predetermined threshold, or the new data is significantly different from the normal pattern in the memory module, the data is marked as abnormal. This strategy takes advantage of the memory module's ability to store historical normality, improves the accuracy of anomaly recognition, and reduces false positives due to reliance on short-term input changes. In addition, the flexibility of this method lies in the ability to adjust the size and form of the memory module, as well as how to use the stored memory to evaluate new inputs, so as to adapt to different types and complexities of data sets. In general, the memory autoencoder provides an effective anomaly detection framework, which is particularly suitable for real-world application scenarios where normal data far outnumbers abnormal data.

[0003] However, the anomaly detection method based on memory autoencoder encounters the following problems when processing certain types of data:

[0004] The ability to detect anomalies that are close to normal is limited. For anomalies that are not much different from normal data, the memory autoencoder may have difficulty identifying them. This is because if the abnormal data is similar to the normal data, the reconstruction error may not increase significantly, resulting in the anomaly not being effectively detected.

[0005] Traditional autoencoders may ignore some minor abnormal patterns due to their strong generalization ability. Although the memory enhancement module solves this problem to a certain extent, it is still a challenge to balance the generalization ability of the model and its sensitivity to abnormalities.

[0006] Reliance on pre-trained models,Memory autoencoders may rely on pre-trained models when performing anomaly detection,,which limits their performance without a large amount of pre-training data.

[0007] In summary, although memory autoencoders have shown potential in anomaly detection, these challenges still need to be overcome in practical applications to ensure their effectiveness and reliability. Summary of the invention

[0008] In response to the above problems, the present invention proposes a transformer-based memory autoencoder anomaly detection method. By introducing the Transformer architecture to optimize the anomaly detection model of the memory autoencoder, more accurate capture and anomaly identification of complex data patterns can be achieved, significantly improving the anomaly detection performance of the model when processing data.

[0009] The transformer-based memory autoencoder anomaly detection method includes:

[0010] Step 1: Build a neural network model using the following strategy:

[0011] In the model, the Transformer encoder, Transformer decoder and a conditional memory module are combined into a Transformer memory autoencoder;

[0012] In this autoencoder, given an input sample First, we perform a block embedding operation on it, split the sample image into multiple small blocks through a convolutional layer and flatten each small block into a vector to obtain the input of the Transformer encoder. Where L is the number of blocks and D is the size of the embedding dimension;

[0013] The Transformer encoder encodes the input x1 into the feature representation

[0014] Input x2 into the conditional memory module, and take the L dimensions in x2 as the feature vector f of D i The index is used as a condition to find the corresponding memory pattern M in the memory module. i , and use these patterns to map the input to obtain a new feature vector

[0015] The feature vector x3 is reconstructed into the original feature space after passing through the Transformer encoder, and the reconstructed feature is output.

[0016] Finally, after a block merging layer, feature x4 is restored to the reconstructed sample

[0017] Step 2: training the neural network model using normal samples;

[0018] Step 3: Input the test sample into the trained model and calculate the difference between the original sample x and the reconstructed sample x5. If the difference is greater than the threshold, the sample is considered an abnormal sample, otherwise it is a normal sample.

[0019] Furthermore, the Transformer encoder is composed of N cascaded Encoder modules stacked together, each of which consists of two sub-layer connection structures. The first sub-layer connection structure includes a multi-head self-attention sub-layer, a normalization layer, and a residual connection. The second sub-layer connection structure includes a feed-forward fully connected sub-layer, a normalization layer, and a residual connection. The encoding process is shown in the following formula:

[0020]

[0021]

[0022] Among them, LayerNorm represents normalized calculation, Attention represents self-attention calculation, MultiHead represents multi-head operation, and W O is the coefficient matrix in the multi-head operation, Concat represents the concatenation operation, Q, K, and V represent the query, key, and value matrices respectively, and is the corresponding coefficient matrix in the i-th attention layer, and MLP represents the feed-forward fully connected sub-layer calculation.

[0023] Furthermore, the mapping process in the conditional memory module is shown in the following formula:

[0024] x2=[f1,f2,…,f L ],

[0025] Memory=[M1,M2,…,M L ],

[0026] M i =[m1,m2,…,m k ],

[0027]

[0028] Where CS represents the cosine similarity calculation, Memory represents the memory pattern module, and k is the number of memory items corresponding to each feature vector.

[0029] Furthermore, the structure of the Transformer decoder is similar to that of the Transformer encoder, which is composed of N cascaded Decoder modules stacked together. The difference is that the Decoder module contains two Multi-Head Attentions. The first Multi-Head Attention uses the Masked operation. The K, V matrix of the second Multi-Head Attention is calculated using the feature vector x3, and Q is calculated using the output of the previous Decoder module. The process is shown in the following formula:

[0030] x4=TransformerDecoder(x3),.

[0031] Furthermore, in step 3, the mean square error is used to calculate the difference between the original sample x and the reconstructed sample.

[0032] The principles and beneficial effects of the present invention are:

[0033] This paper proposes a new model, namely a transformer-based memory autoencoder. By introducing the Transformer architecture to optimize the anomaly detection model of the memory autoencoder, it can achieve more accurate capture and anomaly identification of complex data patterns, and significantly improve the anomaly detection performance of the model when processing data.

[0034] The present invention combines the powerful feature extraction capability of Transformer. The self-attention mechanism of Transformer can effectively capture long-distance dependencies and complex patterns in images, which helps to better understand and represent changes in normal data. Dynamic learning is achieved using a conditional memory mechanism. By introducing a conditional memory module, the model can update and store the normal patterns observed so far in real time, thereby adapting to the evolution of normal data and improving the accuracy of anomaly detection. End-to-end anomaly detection process: From image input to feature extraction to anomaly determination, the entire process constitutes an end-to-end anomaly detection system, which simplifies the process and improves efficiency. Scalability and flexibility: The architecture allows new modules to be flexibly inserted or existing modules to be adjusted in different components (such as memory modules and autoencoders) to facilitate optimization according to specific task requirements.

[0035] In summary, the present invention combines Transformer and memory autoencoder together to provide a novel and effective framework for building an efficient, accurate and adaptable anomaly detection system, which significantly improves the anomaly detection performance of the model when processing data. BRIEF DESCRIPTION OF THE DRAWINGS

[0036] Figure 14 is a framework diagram of a neural network system constructed in an embodiment of the present invention.

[0037] Figure 2 Schematic diagram of the structure of the Transformer encoder (left side) and the Transformer decoder (right side) in an embodiment of the present invention. DETAILED DESCRIPTION

[0038] The transformer-based memory autoencoder anomaly detection method in this example uses Figure 1 The neural network system framework shown in the figure combines the Encoder module and the Decoder module of the Transformer and a conditional memory module (Memory) into a Transformer memory autoencoder, and adds a block embedding layer and a block merging layer at the head and tail of the Transformer, respectively, to divide the image into blocks and merge the blocks into images.

[0039] The neural network system in this example processes data as follows:

[0040] 1. Given a normal input sample First, we perform a block embedding operation on it, split the image into multiple small blocks through a convolutional layer and flatten each small block into a vector to obtain the input of the Transformer encoder. Where L is the number of blocks and D is the size of the embedding dimension, as shown in formula (1):

[0041] x1=Transpose(Flatten(Conv p×p (x))), (1)

[0042] Where p is the size of the convolution kernel, Flatten is the flattening operation, and Transpose represents the transposition operation.

[0043] 2. Transformer encoder encodes the input x1 into feature representation The encoder is composed of N cascaded encoder modules stacked together. Each encoder module consists of two sub-layer connection structures. The first sub-layer connection structure includes a multi-head self-attention sub-layer, a normalization layer, and a residual connection. The second sub-layer connection structure includes a feed-forward fully connected sub-layer, a normalization layer, and a residual connection. The structure of the Transformer encoder is as follows: Figure 2 As shown on the left side of the figure, the process is shown in formulas (2)-(5):

[0044]

[0045] Among them, LayerNorm represents normalized calculation, Attention represents self-attention calculation, MultiHead represents multi-head operation, Concat represents concatenation operation, Q, K, and V represent query, key, and value matrices respectively. and is the corresponding coefficient matrix, and MLP stands for multi-layer perception layer.

[0046] 3. Get After that, we input it into the conditional memory module. Since x2 is composed of L feature vectors with dimension D, i Composition, using the index of each vector as a condition to find the corresponding memory pattern M in the memory module i , use these patterns to map the input and get a new feature vector The process is shown in formulas (6)-(10):

[0047] x2=[f1,f2,…,f L ], (6)

[0048] Memory=[M1,M2,…,M L ], (7)

[0049] M i =[m1,m2,…,mk], (8)

[0050]

[0051] Where CS stands for cosine similarity calculation, k is the number of memory items corresponding to each feature vector, so the size of the memory module is (L×k)×D.

[0052] 4. Get new feature vector After being reconstructed into the original feature space by the Transformer decoder, Figure 2 As shown on the right, the structure of the Transformer decoder is similar to that of the Transformer encoder, and is also obtained by cascading N Decoder modules. The difference is that the Decoder module contains two Multi-Head Attentions. The first Multi-Head Attention uses the Masked operation. The K, V matrix of the second Multi-Head Attention is calculated using the feature vector x3 obtained by the Transformer encoder, while Q is calculated using the output of the previous Decoder module. Finally, a block merging layer is used to restore the features to reconstructed samples with the same form as the original samples. The process is shown in formulas (10) and (11):

[0053] x4=TransformerDecoder(x3), (10)

[0054] x5=ConvTransposep ×p (Reshape(Transpose(x4))), (11)

[0055] Among them, ConvTranspose represents the deconvolution operation, and Reshape represents the reshaping operation.

[0056] The above model is trained with normal image data samples until convergence. Naturally, the update target of the model parameters is to minimize the gap between the input sample and its reconstructed sample. At this time, due to the use of the memory module, the normal mode is stored in the training. If the input sample is a normal sample, the gap between the reconstructed sample and the original sample will be relatively small. Once the input sample is an abnormal sample, the gap between the reconstructed sample and the original sample will inevitably increase significantly. Therefore, in this example, the reconstructed features are used for anomaly detection. Specifically, the difference between the original image and the reconstructed image is calculated, and a loss function such as the mean square error (MSE) is usually used. If the reconstruction error of a sample exceeds the preset threshold, it is marked as abnormal.

[0057] In the experiment, the network model in this example was used to perform anomaly detection on the classic Parkinson's handwriting medical database (NewHandPD). This database is a public database established by Clayton R's team for researchers around the world to promote research related to Parkinson's disease. The data was collected at the Botucatu School of Medicine, State University of São Paulo, Brazil, and consists of handwriting dynamic signals generated by healthy individuals and Parkinson's patients in writing tests. The database contains data from 35 individuals, including 14 Parkinson's patients (10 men and 4 women) and 21 control (healthy) individuals (11 men and 10 women). Participants were asked to fill in a specific form using a smart pen. The form included performing specific tasks, such as drawing "spiral" and "zigzag" patterns, and performing the so-called diadochokinese test, which involves individuals performing wrist movements with straight arms, without drawing, and only recording the signals generated by the pen. The signals generated by each test are represented as time series, and the differences in signals between healthy individuals and Parkinson's patients when performing the same tasks can be visualized. The final database includes data from three tasks. They are Circle, Mender, and Spiral. Among them, there are 140 normal samples in Mender and 124 normal samples in Spiral. Among Circle samples, there are 35 normal samples and 31 abnormal samples.

[0058] The model in this example has an AUC of 100% when trained on the Spiral and Circle datasets. The model trained on the Mender dataset has an AUC of 99.25%. The experimental results show that the network has achieved the best results in the field of Parkinson's handwriting detection compared with supervised and unsupervised learning methods.

Claims

1. Transformer-based memory autoencoder anomaly detection method, include: Step 1: Build a neural network model using the following strategy: In the model, the Transformer encoder, Transformer decoder and a conditional memory module are combined into a Transformer memory autoencoder; In this autoencoder, given an input sample First, we perform a block embedding operation on it, split the sample image into multiple small blocks through a convolutional layer and flatten each small block into a vector to obtain the input of the Transformer encoder. Where L is the number of blocks and D is the size of the embedding dimension; The Transformer encoder will get the input x 1 Encoding to feature representation x 2 Input to the conditional memory module, with x 2 The L feature vectors f of dimension D in i The index is used as a condition to find the corresponding memory pattern M in the memory module. i , and use these patterns to map the input to obtain a new feature vector Eigenvector x 3 After that, it is reconstructed into the original feature space through the Transformer encoder, and the reconstructed features are output. Finally, a block merging layer is used to merge the feature x 4 Restore to reconstructed sample Step 2: training the neural network model using normal samples; Step 3 Input the detection sample into the trained model and calculate the original sample x and the reconstructed sample x 5 If the difference is greater than the threshold, the sample is considered an abnormal sample, otherwise it is a normal sample.

2. The method according to claim 1, It is characterized in that The Transformer encoder is composed of N cascaded Encoder modules stacked together. Each Encoder module consists of two sub-layer connection structures. The first sub-layer connection structure includes a multi-head self-attention sub-layer, a normalization layer, and a residual connection. The second sub-layer connection structure includes a feed-forward fully connected sub-layer, a normalization layer, and a residual connection. The encoding process is shown in the following formula: Among them, LayerNorm represents normalized calculation, Attention represents self-attention calculation, MultiHead represents multi-head operation, and W O is the coefficient matrix in the multi-head operation, Concat represents the concatenation operation, Q, K, V represent the query, key and value matrices respectively, and W i Q , W i K and W i V is the corresponding coefficient matrix in the i-th attention layer, and MLP represents the feed-forward fully connected sub-layer calculation.

3. The method according to claim 2, It is characterized in that The mapping process in the conditional memory module is shown in the following formula: x 2 =[f 1 ,f 2 ,...,f L ], Memory=[M 1 ,M 2 ,...,M L ], M i =[m 1 ,m 2 ,...,m k ], Where CS represents the cosine similarity calculation, Memory represents the memory pattern module, and k is the number of memory items corresponding to each feature vector.

4. The method according to claim 3, It is characterized in that The structure of the Transformer decoder is similar to that of the Transformer encoder, which is composed of N cascaded Decoder modules stacked together. The difference is that the Decoder module contains two Multi-Head Attention modules. The first Multi-Head Attention uses the Masked operation, and the K, V matrix of the second Multi-Head Attention uses the feature vector x 3 Calculate, and Q is calculated using the output of the previous Decoder module. The process is shown in the following formula: x 4 =TransformerDecoder(x 3 ),。 5. The method according to claim 4, It is characterized in that In step 3, the mean square error is used to calculate the difference between the original sample x and the reconstructed sample.

6. A neural network model as described in any one of claims 1-5.

Citation Information

Patent Citations

  • Training method and device for anomaly detection model based on differential privacy

    CN111539769A

  • Aircraft brake system anomaly detection method based on generative adversarial network and auto-encoder

    CN116910673A

  • Encrypted traffic anomaly detection method and device based on deep learning

    CN116933195A

  • TransformerLSTM-based ship anomaly detection method

    CN116955945A

  • Autoregression Image Abnormity Detection Method of Enhancing Latent Space Based on Memory

    US20230154177A1