Log detection method, device and equipment and computer storage medium
By performing regular expression filtering and semantic enhancement processing on log data, and fusing word vectors and position encoding vectors, the problem in the existing technology that log file parsing cannot reveal semantic relationships is solved, and the accuracy of abnormal log detection is improved.
Patent Information
- Application Number
- CN202410710974.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-03
- Publication Date
- 2024-10-11
AI Technical Summary
In the existing technology, the parsing of log files cannot effectively reveal the semantic relationships of logs, resulting in low accuracy in detecting abnormal logs.
By inputting the log data to be detected into the target model, using regular expression filtering to obtain the log template string data, based on the fusion of words and word vectors, position encoding vectors and attention mask vectors, semantic enhancement is performed and then input into the fully connected layer to obtain the detection results. .
It improves the accuracy of detecting abnormal logs, can better capture the semantic information of logs, and enhances the model's ability to understand logs.
Smart Images

Figure CN118760663A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of information security technology, and in particular to a log detection method, device, equipment, computer storage medium and computer program product. Background Art
[0002] In software systems, log files usually contain a lot of information, which can reflect the system's operating status, errors, and abnormal events, etc. Therefore, log files are often used to troubleshoot software systems.
[0003] In the related art, a recurrent neural network model is usually used to detect abnormal log files to determine the failure of the software system. However, a large number of log files in the related art are parsed into a combination of a log key and a parameter value vector, which cannot effectively reveal the semantic relationship of the logs, resulting in a low accuracy rate in detecting abnormal logs. Summary of the invention
[0004] The embodiments of the present disclosure provide a method, apparatus, device, computer storage medium, and computer program product for log detection, which can improve the accuracy of detecting abnormal logs.
[0005] In a first aspect, an embodiment of the present disclosure provides a log detection method, the method comprising:
[0006] Input the acquired log data to be detected into the target model;
[0007] Use regular expressions to filter the log data to be detected and obtain log template string data including target characters;
[0008] Determine the word vector corresponding to the word in the log template string data based on the correspondence between the word and the word vector in the log template string data; determine the position encoding vector based on the correspondence between the word and the position of the word in the log template string data; determine the attention mask vector based on the number of rows and length of the log template string data;
[0009] The word vector, position encoding vector and attention mask vector are fused to obtain the text feature vector;
[0010] Using the encoder in the target model to semantically enhance the text feature vector, obtaining a semantically enhanced text feature vector;
[0011] The semantically enhanced text feature vector is input into the fully connected layer of the target model to obtain the target detection result.
[0012] In an achievable implementation, the log data to be detected includes target characters, the target characters include constant characters, and the log data to be detected is filtered using a regular expression to obtain log template string data including the target characters, including:
[0013] Use regular expressions to filter out constant characters in the log data to be detected;
[0014] Combine constant characters to get log template string data.
[0015] In an achievable implementation, the target model includes a text embedding layer, the text embedding layer includes a word vector encoding layer, the correspondence between words and word vectors in the log template string data is obtained based on the word segmentation table, and the word vector corresponding to the word of the log template string data is determined based on the correspondence between the words and word vectors in the log template string data, including:
[0016] Divide the log template string data into words to obtain multiple words;
[0017] Based on the word vector encoding layer, multiple word vectors corresponding to multiple words are obtained from the word segmentation table.
[0018] In an achievable implementation, the text embedding layer includes a position encoding layer and an attention mask layer, and the word vector, the position encoding vector and the attention mask vector are fused to obtain a text feature vector, including:
[0019] Based on the position encoding layer, the positions of multiple words in the log template string data are determined to obtain multiple position encoding vectors;
[0020] Based on the attention mask layer, determine the number of rows and length of the log template string data to obtain multiple attention mask vectors;
[0021] Multiple word vectors, multiple position mask vectors, and multiple attention mask vectors are fused and concatenated to obtain a text feature vector.
[0022] In an achievable implementation, the fully connected layer includes a first fully connected layer and a second fully connected layer, and the semantically enhanced text feature vector is input into the fully connected layer of the target model to obtain a target detection result, including:
[0023] Inputting the semantically enhanced text feature vector into the first fully connected layer, and using the first fully connected layer to perform feature extraction on the semantically enhanced text feature vector to obtain first target vector information;
[0024] Inputting the first target vector information into the second fully connected layer, and using the second fully connected layer to reduce the dimension of the first target vector information to obtain the target confidence;
[0025] The target detection result is determined based on the target confidence.
[0026] In an achievable implementation, before inputting the acquired log data to be detected into the target model, the method further includes:
[0027] Initialize the log detection model using preset model parameters;
[0028] Obtain log training data, which includes log data and label data, and the log data corresponds to the label data;
[0029] Filter the log data using regular expressions to obtain training log template string data including target characters;
[0030] Determine the target word vector corresponding to the word in the training log template string data based on the correspondence between the word and the word vector in the training log template string data; determine the target position encoding vector based on the correspondence between the word and the position of the word in the training log template string data; determine the target attention mask vector based on the number of rows and length of the training log template string data;
[0031] The target word vector, target position encoding vector and target attention mask vector are fused to obtain the target text feature vector;
[0032] The encoder in the log detection model is used to linearly combine the target text feature vector to obtain the linearly combined target text feature vector;
[0033] Input the linearly combined target text feature vector into the fully connected layer of the log detection model to obtain the target prediction result;
[0034] Get the binary cross entropy loss information of the target prediction result and the label data;
[0035] When the binary cross entropy loss information is greater than the first threshold, the parameters of the log detection model are adjusted to obtain the target model.
[0036] In an achievable implementation, the encoder in the log detection model includes a first encoder and a second encoder, and when the binary cross entropy loss information is greater than a first threshold, adjusting the parameters of the log detection model to obtain a target model includes:
[0037] When the binary cross entropy loss information is greater than the first threshold, the parameters of the second encoder are adjusted to obtain the target model.
[0038] In an achievable implementation, the encoder in the log detection model includes a first encoder and a second encoder, and when the binary cross entropy loss information is greater than a first threshold, adjusting the parameters of the log detection model to obtain a target model includes:
[0039] When the binary cross entropy loss information is greater than the first threshold, the parameters of the second encoder are adjusted to obtain the target model.
[0040] In one achievable implementation, semantic enhancement is performed on a text feature vector using an encoder in a target model to obtain a semantically enhanced text feature vector, including:
[0041] The encoder in the target model is used to linearly combine the text feature vector to obtain the linearly combined text feature vector.
[0042] In a second aspect, an embodiment of the present disclosure provides a log detection device, the device comprising:
[0043] An input module is used to input the acquired log data to be detected into the target model;
[0044] A filtering module, used to filter the log data to be detected by using regular expressions to obtain log template string data including target characters;
[0045] A determination module is used to determine the word vector corresponding to the word of the log template string data based on the correspondence between the word and the word vector in the log template string data; determine the position encoding vector based on the correspondence between the word and the position of the word in the log template string data; determine the attention mask vector based on the number of rows and length of the log template string data;
[0046] The fusion module is used to fuse the word vector, position encoding vector and attention mask vector to obtain the text feature vector;
[0047] A semantic enhancement module is used to perform semantic enhancement on a text feature vector using an encoder in a target model to obtain a semantically enhanced text feature vector;
[0048] The input module is also used to input the semantically enhanced text feature vector into the fully connected layer of the target model to obtain the target detection result.
[0049] In a third aspect, an embodiment of the present disclosure provides a log detection device, the device comprising a processor and a memory storing computer program instructions; the processor reads and executes the computer program instructions to implement a log detection method as described in any one of the first aspects.
[0050] In a fourth aspect, an embodiment of the present disclosure provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer program instructions, and when the computer program instructions are executed by a processor, the method for log detection as described in any one of the first aspects is implemented.
[0051] In a fifth aspect, an embodiment of the present disclosure provides a computer program product, including a computer program, which implements the log detection method as described in any one of the first aspects when the computer program is executed by a processor.
[0052] The disclosed embodiment provides a method, apparatus, device, computer storage medium and computer program product for log detection, wherein the acquired log data to be detected is input into a target model; the log data to be detected is filtered using a regular expression to obtain log template string data including target characters; the word vector corresponding to the word of the log template string data is determined based on the correspondence between the word and the word vector in the log template string data; the position encoding vector is determined based on the correspondence between the word and the position of the word in the log template string data; the attention mask vector is determined based on the number of rows and length of the log template string data; the word vector, the position encoding vector and the attention mask vector are fused to obtain a text feature vector. By fusion of the word vector, the position encoding vector and the attention mask vector to obtain a text feature vector, accurate semantic information can be obtained. The text feature vector is semantically enhanced using the encoder in the target model to obtain a semantically enhanced text feature vector; the semantic information after linear combination is input into the fully connected layer of the target model to obtain a target detection result. The accuracy of detecting abnormal logs can be improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0053] In order to more clearly illustrate the technical solution of the embodiment of the present invention, the following is a brief introduction to the drawings required for use in the embodiment of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0054] Figure 1 It is a flow chart of a log detection method provided by an embodiment of the present disclosure;
[0055] Figure 2 It is a schematic diagram of a process for obtaining log template string data provided by an embodiment of the present disclosure;
[0056] Figure 3 is a schematic diagram of a process of obtaining a word vector provided by an embodiment of the present disclosure;
[0057] Figure 4 is a schematic diagram of an adjustment log detection model provided by an embodiment of the present disclosure;
[0058] Figure 5 It is a structural schematic diagram of a log detection device provided by an embodiment of the present disclosure;
[0059] Figure 6 It is a structural diagram of a log detection device provided by an embodiment of the present disclosure. DETAILED DESCRIPTION
[0060] The features and exemplary embodiments of various aspects of the present invention will be described in detail below. In order to make the purpose, technical solutions and advantages of the present invention clearer, the present invention will be further described in detail below in conjunction with the accompanying drawings and specific embodiments. It should be understood that the specific embodiments described herein are only intended to explain the present invention, rather than to limit the present invention. For those skilled in the art, the present invention can be implemented without the need for some of these specific details. The following description of the embodiments is only to provide a better understanding of the present invention by illustrating examples of the present invention.
[0061] It should be noted that, in this article, relational terms such as first and second, etc. are only used 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 statement "include..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0062] Before describing the technical solutions provided by the embodiments of the present disclosure, in order to facilitate understanding of the embodiments of the present disclosure, the present disclosure specifically describes the problems existing in the related technologies:
[0063] In software systems, log files usually contain a lot of information, which can reflect the system's operating status, errors, and abnormal events, etc. Therefore, log files are often used to troubleshoot software systems.
[0064] In the related technology, a network model based on Long Short-Term Memory (LSTM) is usually used to predict log files, but it is easily affected by a large number of unlabeled logs. In addition, the scale and parameters of the LSTM method network are small, and the generalization and understanding ability of logs is limited, resulting in low accuracy in detecting abnormal log files.
[0065] In view of the above research findings of the inventors, the embodiments of the present disclosure provide a method, apparatus, device, computer storage medium and computer program product for log detection, which can solve at least one of the above technical problems existing in the related art.
[0066] The disclosed embodiment inputs the acquired log data to be detected into the target model, uses regular expressions to filter the log data to be detected, and obtains log template string data including target characters. Determine the word vector, position encoding vector and attention mask vector according to the attribute information of the log template string data. And fuse the word vector, position encoding vector and attention mask vector to obtain a text feature vector. Use the encoder in the target model to semantically enhance the text feature vector to obtain a semantically enhanced text feature vector. Input the semantically enhanced text feature vector into the fully connected layer of the target model to obtain the target detection result, which can improve the accuracy of detecting abnormal logs.
[0067] In addition, during the model training process, if the prediction results output by the model are significantly different from the labeled data, the parameters of the encoder close to the fully connected layer can be adjusted to obtain a target model whose output prediction results are less different from the labeled data.
[0068] The following first introduces the log detection method provided by the embodiment of the present disclosure.
[0069] Figure 1 FIG. 1 is a flow chart showing a method for log detection provided by an embodiment of the present disclosure. Figure 1 The method may include the following steps S110-S160.
[0070] S110: Input the acquired log data to be detected into the target model.
[0071] After receiving the log data to be detected, the terminal inputs the log data to be detected into the target model.
[0072] S120: Filter the log data to be detected using a regular expression to obtain log template string data including target characters.
[0073] After receiving the log data to be detected, the target model uses a regular expression to match the target character string in the log data to be detected, and combines the target characters that successfully match the regular expression into log template string data. The regular expression represents a character matching rule.
[0074] S130: Determine the word vector corresponding to the word of the log template string data based on the correspondence between the word and the word vector in the log template string data; determine the position encoding vector based on the correspondence between the word and the position of the word in the log template string data; determine the attention mask vector based on the number of rows and length of the log template string data.
[0075] The target model obtains the word vector corresponding to the word in the log template string data according to the correspondence between the word and the word vector in the log template string data. The corresponding position encoding vector is obtained according to the position of each word in the log template string data. The corresponding attention mask vector is obtained according to the number of rows and length of the log template string data.
[0076] S140: Fuse the word vector, position encoding vector and attention mask vector to obtain a text feature vector.
[0077] After obtaining the word vector, position encoding vector and attention mask vector of the words in the log template string data, the target model fuses the word vector, position encoding vector and attention mask vector to obtain the text feature vector.
[0078] S150: Using the encoder in the target model to semantically enhance the text feature vector to obtain a semantically enhanced text feature vector.
[0079] After the target model obtains the text feature vector through fusion, it inputs the text feature vector into the self-attention module obtained by combining multiple Transformer encoders, performs semantic enhancement operation on the text feature vector, and obtains the semantically enhanced text feature vector.
[0080] S160: Input the semantically enhanced text feature vector into the fully connected layer of the target model to obtain the target detection result.
[0081] After obtaining the semantically enhanced text feature vector, the target model inputs the semantically enhanced text feature vector into the fully connected layer of the target model, and outputs the target detection result of the log based on the fully connected layer. Among them, the target detection result represents the anomaly detection result.
[0082] The disclosed embodiment inputs the acquired log data to be detected into the target model; uses regular expressions to filter the log data to be detected to obtain log template string data including target characters; determines the word vector corresponding to the word of the log template string data based on the correspondence between the word and the word vector in the log template string data; determines the position encoding vector based on the correspondence between the word and the position of the word in the log template string data; determines the attention mask vector based on the number of rows and length of the log template string data; and fuses the word vector, the position encoding vector and the attention mask vector to obtain a text feature vector. By fusing the word vector, the position encoding vector and the attention mask vector to obtain a text feature vector, accurate semantic information can be obtained. The encoder in the target model is used to semantically enhance the text feature vector to obtain a semantically enhanced text feature vector; the semantic information after linear combination is input into the fully connected layer of the target model to obtain a target detection result. It can improve the accuracy of detecting abnormal logs.
[0083] In one embodiment, Figure 2 As shown, step S120 uses a regular expression to filter the log data to be detected to obtain log template string data including target characters, which may include steps S121 and S122:
[0084] S121: Filter out constant characters in the log data to be detected using a regular expression.
[0085] The target model performs a matching operation on the characters in the log data to be detected according to the regular expression, and obtains constant characters that successfully match the regular expression.
[0086] Among them, constant characters represent characters that cannot be changed.
[0087] S122: Combine constant characters to obtain log template string data.
[0088] The target model concatenates and combines the matched constant characters in sequence to obtain the log template string data.
[0089] In an example, the log data to be detected is “Jul 26 04:11:23combo:session opened foruser news by uid=0x135445416”, where “Jul 26 04:11:23” and “0x135445416” represent variable characters. The variable characters in the log data to be detected are filtered out by a regular expression, and the log template string data obtained by combining the variable characters is “combo:session opened for user news by uid”.
[0090] In the disclosed embodiment, regular expressions are used to filter out variable characters in the log data to be detected, and the log template string data is obtained by combining them, which can effectively reduce the impact of irrelevant variables on log detection.
[0091] In one embodiment, Figure 3 As shown, step S130 determines the word vector corresponding to the word of the log template string data based on the correspondence between the word and the word vector in the log template string data; determines the position encoding vector based on the correspondence between the word and the position of the word in the log template string data; determines the attention mask vector based on the number of rows and length of the log template string data, which may include steps S131 and S132.
[0092] S131: Divide the log template string data into words to obtain a plurality of words.
[0093] After obtaining the log template string data, the target model divides the log template string data into words to obtain multiple words.
[0094] In an example, the log template string data "combo: session opened for user news byuid" is segmented into words to obtain multiple words "combo", "session", "opened", "for", "user", "news", "by", and "uid".
[0095] S132: Based on the word vector encoding layer, obtain multiple word vectors corresponding to multiple words from the word segmentation table.
[0096] The target model uses the word vector encoding layer in the model to obtain the word vectors corresponding to the words in the log template string data from the word segmentation table. Each word has a unique corresponding word vector.
[0097] In an example, according to the word segmentation table, we can obtain the word vector 2543 corresponding to "combo", the word vector 2379 corresponding to "session", the word vector 2474 corresponding to "opened", the word vector 6902 corresponding to "for", the word vector 3351 corresponding to "user", the word vector 21871 corresponding to "news", the word vector 2243 corresponding to "by", and the word vector 1012 corresponding to "uid".
[0098] The disclosed embodiment can enhance the model's ability to understand words in log detection by obtaining word vectors corresponding to words in the word segmentation table in the log template string data.
[0099] In one embodiment, step S140 fuses the word vector, the position encoding vector and the attention mask vector to obtain a text feature vector, which may include steps S141-S143.
[0100] S141: Based on the position encoding layer, determine the positions of multiple words in the log template string data to obtain multiple position encoding vectors.
[0101] The target model uses the position encoding layer to obtain multiple corresponding position encoding vectors according to the positions of multiple words in the log template string data.
[0102] In an example, "combo" in the log template string data "combo: session opened for user news byuid" is located at the first position in the log template string data, then the position coding vector corresponding to "combo" is 0, and "session" is located at the second position in the log template string data, then the position coding vector corresponding to "session" is 1.
[0103] S142: Based on the attention mask layer, determine the number of rows and length of the log template string data to obtain multiple attention mask vectors.
[0104] The target model uses the attention mask layer to obtain multiple corresponding attention mask vectors according to the number of rows and length of the log in the log template string data.
[0105] S143: Multiple word vectors, multiple position mask vectors and multiple attention mask vectors are merged and concatenated to obtain a text feature vector.
[0106] After obtaining multiple word vectors, multiple position mask vectors, and multiple attention mask vectors, the target model integrates and concatenates the multiple word vectors, multiple position mask vectors, and multiple attention mask vectors to obtain a text feature vector.
[0107] The disclosed embodiment obtains a text feature vector by fusing a word vector, a position encoding vector and an attention mask vector, which can better capture the order and position information between words, thereby obtaining a more accurate text feature vector.
[0108] In one embodiment, step S160 inputs the semantically enhanced text feature vector into the fully connected layer of the target model to obtain the target detection result, which may include steps S161-S163.
[0109] S161: Input the semantically enhanced text feature vector into the first fully connected layer, and use the first fully connected layer to extract features from the semantically enhanced text feature vector to obtain first target vector information.
[0110] After the target model obtains the semantically enhanced text feature vector, the semantically enhanced text feature vector is input into the first fully connected layer in the downstream classification task layer. After the first fully connected layer performs feature extraction on the semantically enhanced text feature vector, the first target vector information is output.
[0111] S162: Input the first target vector information into the second fully connected layer, and use the second fully connected layer to reduce the dimension of the first target vector information to obtain the target confidence.
[0112] After obtaining the first target vector information, the target model performs nonlinear operations through the Rectified Linear Unit (ReLU) activation layer and then inputs it into the Dropout layer, and finally inputs it into the second fully connected layer. After the first target vector information is compressed by dimensionality reduction in the second fully connected layer, the confidence that the log data to be detected belongs to the abnormal type is obtained.
[0113] S163: Determine the target detection result based on the target confidence.
[0114] The target model determines whether the log data to be detected is abnormal based on the obtained confidence level.
[0115] In one example, the size of the first fully connected layer is (1024, 1024), and the first target vector information output by the first fully connected layer is input into the second fully connected layer after nonlinear activation. The size of the second fully connected layer is set to (1024, 2). Finally, the output of the second fully connected layer obtains the abnormal type label.
[0116] In the disclosed embodiment, the semantically enhanced text feature vector is input into the first fully connected layer to obtain the first target vector information, and then the first target vector information is input into the second fully connected layer to obtain the target detection result. By using a series of fully connected layers to extract and combine features, the model can better understand the text feature information and enhance the model's representation ability.
[0117] In one embodiment, before the acquired log data to be detected is input into the target model in step S110, steps S210-S290 are also included.
[0118] S210: Initialize the log detection model using preset model parameters.
[0119] When training the model, select and load the structure and weights of the pre-trained text domain model to initialize the log detection model.
[0120] S220: Obtain log training data.
[0121] A large number of system output log files are read and collected to obtain log training data. The log training data includes log data and label data. The log data corresponds to the label data, and the label data indicates whether the log is an abnormal log.
[0122] S230: Filter the log data using a regular expression to obtain training log template string data including target characters.
[0123] After receiving the log data, the log detection model uses regular expressions to match the target character strings in the log data, and combines the target characters that successfully match the regular expressions into training log template string data.
[0124] S240: Determine the target word vector corresponding to the word in the training log template string data based on the correspondence between the word and the word vector in the training log template string data; determine the target position encoding vector based on the correspondence between the word and the position of the word in the training log template string data; determine the target attention mask vector based on the number of rows and length of the training log template string data.
[0125] The log detection model obtains the target word vector corresponding to the word in the training log template string data according to the correspondence between the word and the word vector in the training log template string data. The corresponding target position encoding vector is obtained according to the position of each word in the training log template string data in the training log template string data. The corresponding target attention mask vector is obtained according to the number of rows and length of the training log template string data.
[0126] S250: Fuse the target word vector, the target position encoding vector and the target attention mask vector to obtain the target text feature vector.
[0127] After obtaining the target word vector, target position encoding vector and target attention mask vector of the words in the training log template string data, the log detection model fuses the target word vector, target position encoding vector and target attention mask vector to obtain the target text feature vector.
[0128] S260: Use the encoder in the log detection model to linearly combine the target text feature vector to obtain the linearly combined target text feature vector.
[0129] After the log detection model obtains the target text feature vector through fusion, it inputs the target text feature vector into the self-attention module obtained by combining multiple Transformer encoders, linearly combines the text feature vectors, and obtains the linearly combined target text feature vector.
[0130] S270: Input the linearly combined target text feature vector into the fully connected layer of the log detection model to obtain a target prediction result.
[0131] After obtaining the linearly combined target text feature vector, the log detection model inputs the linearly combined target text feature vector into the fully connected layer of the log detection model, and outputs the target prediction result of the log based on the fully connected layer.
[0132] S280: Obtain binary cross entropy loss information of target prediction results and label data.
[0133] After receiving the target prediction result, the binary cross entropy loss is used as the loss function to calculate the difference between the target prediction result and the label data.
[0134] In one example, the expression for calculating the binary cross entropy loss is shown in formula (1):
[0135]
[0136] Among them, C is the number of types of sample abnormal labels, p i represents the probability of the i-th anomaly type predicted by the model, y i Represents the one-hot encoding representation of the true label of the sample in the i-th category.
[0137] S290: When the binary cross entropy loss information is greater than the first threshold, adjust the parameters of the log detection model to obtain a target model.
[0138] If the calculated binary cross entropy loss information is greater than the first threshold, indicating that the target prediction result is significantly different from the label data, the parameters of the log detection model are adjusted to obtain the target model. The first threshold represents the binary cross entropy loss threshold.
[0139] The disclosed embodiment uses log training data to train a log detection model and adjusts the parameters of the log detection model according to the difference between the target prediction result and the label data, so that the log detection model has a better understanding of logs of different abnormal types, thereby obtaining a target model.
[0140] In one embodiment, step S290 adjusts the parameters of the log detection model to obtain the target model when the binary cross entropy loss information is greater than the first threshold, and may include step S291.
[0141] S291: When the binary cross entropy loss information is greater than the first threshold, adjust the parameters of the second encoder to obtain the target model.
[0142] If the binary cross entropy loss information is greater than the first threshold, the parameters of the second encoder in all encoders of the target model are adjusted to obtain a target model with adjusted parameters.
[0143] In one embodiment, the parameters of the second encoder close to the fully connected layer in all encoders of the target model may be adjusted to obtain a target model with adjusted parameters.
[0144] In one example, if Figure 4 As shown in the figure, there are 24 layers of encoders in the target model and they are connected in series. Among them, the first 12 layers of encoders are far away from the fully connected layer and are regarded as the first encoder. The last 12 layers of encoders are close to the fully connected layer and are regarded as the second encoder. When adjusting the model parameters, the parameters of the first encoder are frozen and not adjusted. The parameters of the second encoder are adjusted to obtain the target model after parameter adjustment.
[0145] In the embodiment of the present disclosure, when the binary cross entropy loss information is greater than the first threshold, the parameters of the second encoder are adjusted to obtain the target model. Since the encoder close to the fully connected layer is easy to learn the knowledge of log anomaly classification, adjusting the parameters of the second encoder to obtain the target model can achieve a better effect of the target model.
[0146] In one embodiment, step S150 performs semantic enhancement on the text feature vector using the encoder in the target model to obtain the semantically enhanced text feature vector, which may include step S151.
[0147] S151: Use the encoder in the target model to linearly combine the text feature vector to obtain a linearly combined text feature vector.
[0148] After obtaining the text feature vector, the target model uses multiple encoders of the attention module in the target model to linearly combine the semantic vectors of the words obtained under different attention heads to obtain the text feature vector after linear combination.
[0149] The disclosed embodiment utilizes the encoder in the target model to perform linear combination on the text feature vectors, and can perform semantic enhancement processing on the text feature vectors to obtain the text feature vectors after linear combination.
[0150] like Figure 5 As shown, the embodiment of the present disclosure further provides a log detection device 500, and the log detection device 500 includes:
[0151] An input module 501 is used to input the acquired log data to be detected into the target model;
[0152] A filtering module 502 is used to filter the log data to be detected using a regular expression to obtain log template string data including target characters;
[0153] Determination module 503, used to determine the word vector corresponding to the word of the log template string data based on the correspondence between the word and the word vector in the log template string data; determine the position encoding vector based on the correspondence between the word and the position of the word in the log template string data; determine the attention mask vector based on the number of rows and length of the log template string data;
[0154] A fusion module 504 is used to fuse the word vector, the position encoding vector and the attention mask vector to obtain a text feature vector;
[0155] The semantic enhancement module 505 is used to perform semantic enhancement on the text feature vector using the encoder in the target model to obtain the semantically enhanced text feature vector;
[0156] The input module 501 is also used to input the semantically enhanced text feature vector into the fully connected layer of the target model to obtain the target detection result.
[0157] In some embodiments, the log detection apparatus 500 includes an acquisition module, which is used to filter out constant characters in the log data to be detected by using a regular expression; and combine the constant characters to obtain log template string data.
[0158] In some embodiments, the acquisition module is also used to divide the log template string data into units of words to obtain multiple words; based on the word vector encoding layer, multiple word vectors corresponding to the multiple words are obtained from the word segmentation table.
[0159] In some embodiments, the fusion module 504 is specifically configured to:
[0160] Based on the position encoding layer, the positions of multiple words in the log template string data are determined to obtain multiple position encoding vectors;
[0161] Based on the attention mask layer, determine the number of rows and length of the log template string data to obtain multiple attention mask vectors;
[0162] Multiple word vectors, multiple position mask vectors, and multiple attention mask vectors are fused and concatenated to obtain a text feature vector.
[0163] In some embodiments, the determination module 503 is specifically configured to:
[0164] Inputting the semantically enhanced text feature vector into the first fully connected layer, and using the first fully connected layer to perform feature extraction on the semantically enhanced text feature vector to obtain first target vector information;
[0165] Inputting the first target vector information into the second fully connected layer, and using the second fully connected layer to reduce the dimension of the first target vector information to obtain the target confidence;
[0166] The target detection result is determined based on the target confidence.
[0167] In some embodiments, the acquisition module is further used to initialize the log detection model using preset model parameters;
[0168] Obtain log training data, which includes log data and label data, and the log data corresponds to the label data;
[0169] Filter the log data using regular expressions to obtain training log template string data including target characters;
[0170] Determine the target word vector corresponding to the word in the training log template string data based on the correspondence between the word and the word vector in the training log template string data; determine the target position encoding vector based on the correspondence between the word and the position of the word in the training log template string data; determine the target attention mask vector based on the number of rows and length of the training log template string data;
[0171] The target word vector, target position encoding vector and target attention mask vector are fused to obtain the target text feature vector;
[0172] The encoder in the log detection model is used to linearly combine the target text feature vector to obtain the linearly combined target text feature vector;
[0173] Input the linearly combined target text feature vector into the fully connected layer of the log detection model to obtain the target prediction result;
[0174] Get the binary cross entropy loss information of the target prediction result and the label data;
[0175] When the binary cross entropy loss information is greater than the first threshold, the parameters of the log detection model are adjusted to obtain the target model.
[0176] In some embodiments, the log detection apparatus 500 includes an adjustment module, which is used to adjust the parameters of the second encoder to obtain a target model when the binary cross entropy loss information is greater than a first threshold.
[0177] In some embodiments, the log detection apparatus 500 includes a linear combination module, and the linear combination module includes using an encoder in a target model to linearly combine text feature vectors to obtain a linearly combined text feature vector.
[0178] Figure 5 Each module / unit in the device shown has the function of realizing Figure 1 The functions of each step executed by the application system in the present invention can achieve the corresponding technical effects. For the sake of brevity, they will not be repeated here.
[0179] Figure 6 A schematic diagram of the hardware structure of log detection provided by an embodiment of the present disclosure is shown.
[0180] The log detection device may include a processor 601 and a memory 602 storing computer program instructions.
[0181] Specifically, the processor 601 may include a central processing unit (CPU), or an application specific integrated circuit (ASIC), or may be configured to implement one or more integrated circuits of the embodiments of the present application.
[0182] The memory 602 may include a large capacity memory for data or instructions. By way of example and not limitation, the memory 602 may include a hard disk drive (HDD), a floppy disk drive, a flash memory, an optical disk, a magneto-optical disk, a magnetic tape, or a universal serial bus (USB) drive or a combination of two or more of these. In appropriate cases, the memory 602 may include a removable or non-removable (or fixed) medium. In appropriate cases, the memory 602 may be inside or outside the integrated gateway disaster recovery device. In a specific embodiment, the memory 602 is a non-volatile solid-state memory.
[0183] The memory 602 may include a read-only memory (ROM), a random access memory (RAM), a magnetic disk storage medium device, an optical storage medium device, a flash memory device, an electrical, optical or other physical / tangible memory storage device. Therefore, generally, the memory includes one or more tangible (non-transitory) computer-readable storage media (e.g., memory devices) encoded with software including computer-executable instructions, and when the software is executed (e.g., by one or more processors), it is operable to perform the operations described with reference to the method according to one aspect of the present disclosure.
[0184] The processor 601 implements any one of the log detection methods in the above embodiments by reading and executing computer program instructions stored in the memory 602 .
[0185] In one example, the log detection device may further include a communication interface 603 and a bus 604. Figure 6 As shown, the processor 601, the memory 602, and the communication interface 603 are connected via a bus 604 and communicate with each other.
[0186] The communication interface 603 is mainly used to implement communication between various modules, devices, units and / or equipment in the embodiments of the present application.
[0187] Bus 604 includes hardware, software or both, and couples the components of online data traffic billing equipment to each other. For example, but not limitation, the bus may include Accelerated Graphics Port (AGP) or other graphics bus, Enhanced Industry Standard Architecture (EISA) bus, Front Side Bus (FSB), Hyper Transport (HT) interconnection, Industry Standard Architecture (ISA) bus, InfiniBand interconnection, Low Pin Count (LPC) bus, Memory bus, Micro Channel Architecture (MCA) bus, Peripheral Component Interconnect (PCI) bus, PCI-Express (PCI-X) bus, Serial Advanced Technology Attachment (SATA) bus, Video Electronics Standards Association Local (VLB) bus or other suitable bus or two or more of these combinations. In appropriate cases, bus 604 may include one or more buses. Although the embodiment of the present invention describes and illustrates a specific bus, the present invention considers any suitable bus or interconnection. In addition, in conjunction with the method for log detection in the above embodiment, the present application embodiment also provides a computer storage medium to realize. The computer storage medium stores computer program instructions; when the computer program instructions are executed by the processor, any one of the log detection methods in the above embodiments is implemented.
[0188] An embodiment of the present application also provides a computer program product, including a computer program, which implements any one of the log detection methods in the above embodiments when the computer program is executed by a processor.
[0189] It should be clear that the present invention is not limited to the specific configuration and processing described above and shown in the figures. For the sake of simplicity, a detailed description of the known method is omitted here. In the above embodiments, several specific steps are described and shown as examples. However, the method process of the present invention is not limited to the specific steps described and shown, and those skilled in the art can make various changes, modifications and additions, or change the order between the steps after understanding the spirit of the present invention.
[0190] The functional blocks shown in the above structural block diagram can be implemented as hardware, software, firmware or a combination thereof. When implemented in hardware, it can be, for example, an electronic circuit, an application specific integrated circuit (Application Specific Integrated Circuit, ASIC), appropriate firmware, plug-in, function card, etc. When implemented in software, the elements of the present invention are programs or code segments used to perform the required tasks. The program or code segment can be stored in a machine-readable medium, or transmitted on a transmission medium or communication link by a data signal carried in a carrier. "Machine-readable medium" can include any medium capable of storing or transmitting information. Examples of machine-readable media include electronic circuits, semiconductor memory devices, read-only memory (Read-Only Memory, ROM), flash memory, erasable read-only memory (Erasable ReadOnly Memory, EROM), floppy disks, compact disc read-only memory (Compact Disc Read-Only Memory, CD-ROM), optical discs, hard disks, optical fiber media, radio frequency (Radio Frequency, RF) links, etc. The code segment can be downloaded via a computer network such as the Internet, an intranet, etc.
[0191] It should also be noted that the exemplary embodiments mentioned in the present invention describe some methods or systems based on a series of steps or devices. However, the present invention is not limited to the order of the above steps, that is, the steps can be performed in the order mentioned in the embodiments, or in a different order from the embodiments, or several steps can be performed simultaneously.
[0192] Aspects of the present disclosure are described above with reference to the flowchart and / or block diagram of the method, device (system) and computer program product according to the embodiment of the present disclosure. It should be understood that each box in the flowchart and / or block diagram and the combination of each box in the flowchart and / or block diagram can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device to produce a machine so that these instructions executed by the processor of the computer or other programmable data processing device enable the implementation of the function / action specified in one or more boxes of the flowchart and / or block diagram. Such a processor can be, but is not limited to, a general-purpose processor, a special-purpose processor, a special application processor, or a field programmable logic circuit. It can also be understood that each box in the block diagram and / or flowchart and the combination of boxes in the block diagram and / or flowchart can also be implemented by dedicated hardware that performs a specified function or action, or can be implemented by a combination of dedicated hardware and computer instructions.
[0193] The above is only a specific implementation of the present invention. Those skilled in the art can clearly understand that for the convenience and simplicity of description, the specific working process of the system, module and unit described above can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here. It should be understood that the protection scope of the present invention is not limited to this. Any technician familiar with the technical field can easily think of various equivalent modifications or replacements within the technical scope disclosed by the present invention, and these modifications or replacements should be covered within the protection scope of the present invention.
Claims
1. A log detection method, characterized in that: include: Input the acquired log data to be detected into the target model; Filtering the log data to be detected by using a regular expression to obtain log template string data including target characters; Determine the word vector corresponding to the word in the log template string data based on the correspondence between the word and the word vector in the log template string data; Determine a position encoding vector based on the correspondence between words and positions of words in the log template string data; determine an attention mask vector based on the number of rows and length of the log template string data; Fusing the word vector, the position encoding vector and the attention mask vector to obtain a text feature vector; Using the encoder in the target model to semantically enhance the text feature vector to obtain a semantically enhanced text feature vector; The semantically enhanced text feature vector is input into the fully connected layer of the target model to obtain the target detection result.
2. The method according to claim 1, characterized in that The log data to be detected includes the target character, and the target character includes a constant character. The regular expression is used to filter the log data to be detected to obtain log template string data including the target character, including: Using the regular expression to filter out constant characters in the log data to be detected; The constant characters are combined to obtain the log template string data.
3. The method according to claim 1, characterized in that The target model includes a text embedding layer, the text embedding layer includes a word vector encoding layer, the correspondence between words and word vectors in the log template string data is obtained based on a word segmentation table, and the word vector corresponding to the word of the log template string data is determined based on the correspondence between the words and word vectors in the log template string data, including: Dividing the log template string data into words to obtain a plurality of words; Based on the word vector encoding layer, a plurality of word vectors corresponding to the plurality of words are obtained from the word segmentation table.
4. The method according to claim 3, characterized in that The text embedding layer includes a position encoding layer and an attention mask layer, and the word vector, the position encoding vector and the attention mask vector are fused to obtain a text feature vector, including: Based on the position encoding layer, determining the positions of the plurality of words in the log template string data, and obtaining a plurality of the position encoding vectors; Based on the attention mask layer, determining the number of rows and the length of the log template string data, and obtaining a plurality of attention mask vectors; The multiple word vectors, the multiple position mask vectors and the multiple attention mask vectors are fused and spliced to obtain the text feature vector.
5. The method according to claim 1, characterized in that The fully connected layer includes a first fully connected layer and a second fully connected layer, and the semantically enhanced text feature vector is input into the fully connected layer of the target model to obtain a target detection result, including: Inputting the semantically enhanced text feature vector into the first fully connected layer, and using the first fully connected layer to perform feature extraction on the semantically enhanced text feature vector to obtain first target vector information; Inputting the first target vector information into the second fully connected layer, and using the second fully connected layer to reduce the dimension of the first target vector information to obtain target confidence; The target detection result is determined based on the target confidence.
6. The method according to claim 1, characterized in that Before inputting the acquired log data to be detected into the target model, the method further includes: Initialize the log detection model using preset model parameters; Acquire log training data, the log training data including log data and label data, the log data corresponding to the label data; Filtering the log data using a regular expression to obtain training log template string data including target characters; Determine the target word vector corresponding to the word of the training log template string data based on the correspondence between the word and the word vector in the training log template string data; determine the target position encoding vector based on the correspondence between the word and the position of the word in the training log template string data; determine the target attention mask vector based on the number of rows and length of the training log template string data; The target word vector, the target position encoding vector and the target attention mask vector are fused to obtain a target text feature vector; Using the encoder in the log detection model to linearly combine the target text feature vector to obtain a linearly combined target text feature vector; Inputting the linearly combined target text feature vector into the fully connected layer of the log detection model to obtain a target prediction result; Obtaining binary cross entropy loss information of the target prediction result and the label data; When the binary cross entropy loss information is greater than a first threshold, the parameters of the log detection model are adjusted to obtain the target model.
7. The method according to claim 6, characterized in that The encoder in the log detection model includes a first encoder and a second encoder, and when the binary cross entropy loss information is greater than a first threshold, adjusting the parameters of the log detection model to obtain the target model includes: When the binary cross entropy loss information is greater than a first threshold, the parameters of the second encoder are adjusted to obtain the target model.
8. The method according to claim 1, characterized in that The step of using the encoder in the target model to semantically enhance the text feature vector to obtain the semantically enhanced text feature vector includes: The encoder in the target model is used to linearly combine the text feature vectors to obtain a linearly combined text feature vector.
9. A log detection device, characterized in that: The device comprises: An input module, wherein the input module is used to input the acquired log data to be detected into the target model; A filtering module, the filtering module is used to filter the log data to be detected by using a regular expression to obtain log template string data including target characters; A determination module, the determination module is used to determine the word vector corresponding to the word of the log template string data based on the correspondence between the word and the word vector in the log template string data; determine the position encoding vector based on the correspondence between the word and the position of the word in the log template string data; determine the attention mask vector based on the number of rows and length of the log template string data; A fusion module, which is used to fuse the word vector, the position encoding vector and the attention mask vector to obtain a text feature vector; A semantic enhancement module, wherein the semantic enhancement module is used to perform semantic enhancement on the text feature vector using the encoder in the target model to obtain a semantically enhanced text feature vector; The input module is also used to input the semantically enhanced text feature vector into the fully connected layer of the target model to obtain the target detection result.
10. A log detection device, characterized in that: The device comprises: a processor and a memory storing computer program instructions; the processor reads and executes the computer program instructions to implement the log detection method according to any one of claims 1 to 8.
11. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer program instructions, and when the computer program instructions are executed by a processor, the method for log detection according to any one of claims 1 to 8 is implemented.
12. A computer program product, characterized in that The invention comprises a computer program, which implements the log detection method according to any one of claims 1 to 8 when executed by a processor.
Citation Information
Cited By
On-line anomaly detection method and equipment for autonomous controllable power business system, and medium
CN120632722A
