System log detection model robust adversarial training method based on mode unit extraction

By combining shapelet-based pattern unit extraction and LSTM dynamic time-step masking mechanism with knowledge distillation for hard sample learning, the problem of insufficient robustness of malware detection models in adversarial sample environments is solved, achieving efficient anomaly detection and generalization capabilities.

CN121935703APending Publication Date: 2026-04-28JIANGSU UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-01-20
Publication Date
2026-04-28

AI Technical Summary

Technical Problem

Existing malware detection models lack robustness in adversarial example environments, struggle to cope with large-scale disturbances, and have limited generalization capabilities, leading to decreased detection accuracy.

Method used

We employ a Shapelet-based pattern unit extraction, a dynamic time-step weighting mechanism using a Long Short-Term Memory (LSTM) network, and a knowledge distillation strategy that combines learning from difficult samples. By using a custom distance metric to extract semantically relevant feature pattern units and dynamically adjusting feature weights, we enhance the model's attention to anomalous features and improve robustness through a teacher-student model framework.

Benefits of technology

It effectively eliminates adversarial perturbations, improves feature purity and model discrimination ability, and enhances detection accuracy and generalization ability in complex adversarial environments.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121935703A_ABST
    Figure CN121935703A_ABST
Patent Text Reader

Abstract

The invention provides a system log detection model anti-robust training method based on mode unit extraction, and belongs to the technical field of intelligent system security and log anomaly detection. The method comprises the following steps: step 1, performing Shaplet mode unit extraction on an original log sequence, and enhancing a Shaplet algorithm through custom distance measurement so as to extract a feature mode unit with semantic significance, so that effective reconstruction of the log sequence is realized, and countermeasure noise is suppressed; step 2, inputting the reconstructed sequence into a model based on a long short-term memory (LSTM) network, weighting according to the probability that each time step belongs to a normal system behavior through a time step masking mechanism guided by confidence, and highlighting potential anomaly; and step 3, adopting a teacher-student learning normal form, and utilizing misclassification samples of the teacher model to carry out difficult sample guide training on the student model so as to improve the robustness of the model under various adversarial attacks.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to intelligent system security and log anomaly detection technology, specifically to an adversarial robust training method for a system log detection model based on pattern unit extraction. Background Technology

[0002] Malware is one of the major threats to computer system security today, seriously jeopardizing data integrity, system availability, and user privacy. With the increasing complexity and quantity of malware, malicious code detection technology has become a crucial line of defense for network and information security. Traditional signature-based detection methods rely on manually extracted static features, which are insufficient to respond promptly to the rapid mutation and diversification of malware. More intelligent and robust detection methods are urgently needed. Dynamic analysis provides an effective approach to malware detection. This method generates system logs by monitoring the system call behavior of running programs, capturing dynamic feature information reflecting the semantics of program execution. Combining dynamic analysis with deep learning technology can effectively improve detection performance and generalization ability, enabling the identification and classification of unknown malware samples. Compared with traditional methods such as static analysis, detection methods based on dynamic behavior have stronger adaptability and the ability to detect novel malicious samples.

[0003] However, with the widespread application of deep learning in malware detection, the robustness of these models has become increasingly apparent. Attackers can exploit adversarial examples to introduce carefully designed perturbations into the input data, causing the model to produce incorrect classifications while maintaining the malicious functionality, thus bypassing the detection system. Such attacks reveal the inherent weakness of deep learning models—their over-reliance on surface features—significantly undermining the reliability and security of log analysis-based detection systems.

[0004] In recent years, research on adversarial perturbations in system log anomaly detection has gradually increased, mainly focusing on improving the robustness of models against adversarial attacks. Existing studies have explored methods such as semantic feature analysis, multi-factor feature fusion, and pattern anomaly detection to enhance the model's ability to identify abnormal behavior. Adversarial training and adversarial detection methods have improved the model's defense performance to some extent. However, due to the high-dimensional feature space and long-term sequence characteristics of system log data, anomalous logs and normal logs have high structural similarity, leading to blurred model decision boundaries and decreased training effectiveness. Furthermore, unlike subtle perturbations in the image domain, adversarial examples in malware detection often achieve this by inserting a large number of meaningless or normal operations. These large-scale perturbations significantly disrupt the log sequence structure, making existing detection methods difficult to cope with complex adversarial attacks. Although adversarial training can improve the robustness of models in specific attack scenarios, it often comes at the cost of sacrificing the detection accuracy of normal samples and is difficult to generalize across different types of adversarial strategies. Summary of the Invention

[0005] To address the shortcomings of existing malware anomaly detection methods, such as insufficient robustness in adversarial example environments, sensitivity to large-scale perturbations, and limited model generalization ability, this invention proposes an adversarially robust training method for system log detection models based on pattern unit extraction. This method integrates shapelet-based pattern unit extraction, a dynamic time-step weighting mechanism using Long Short-Term Memory (LSTM) networks, and a knowledge distillation strategy incorporating hard sample learning, achieving highly robust anomaly detection in complex adversarial environments. By extracting semantically relevant feature pattern units through a custom distance metric, adversarial perturbations are effectively eliminated; a dynamic time-step masking mechanism enhances the model's focus on anomalous features; and knowledge distillation training using a teacher-student model on hard samples improves the model's resistance to various types of adversarial examples.

[0006] The technical solution of this invention is: a method for adversarial robust training of a system log detection model based on pattern unit extraction, comprising:

[0007] Step 1: Extract Shapelet pattern units from the original log sequence. Enhance the Shapelet algorithm with a custom distance metric to extract semantically meaningful feature pattern units, thereby achieving effective reconstruction of the log sequence and suppressing adversarial noise.

[0008] Step 2: Input the reconstructed sequence into a model based on a Long Short-Term Memory (LSTM) network. Through a confidence-guided time-step masking mechanism, the sequence is weighted according to the probability that each time step belongs to normal system behavior, thus highlighting potential anomalies.

[0009] Step 3: Adopt the teacher-student learning paradigm and use the misclassified samples of the teacher model to guide the training of the student model with difficult samples, thereby improving the robustness of the model under various adversarial attacks.

[0010] Firstly, the specific steps of step 1 above are as follows:

[0011] Step 1-1: Log Sequence Input and Subsequence Generation. This invention first obtains a dataset of system log event sequences with category labels. For each log sequence, all possible subsequences are systematically generated within a preset length range as candidate pattern units.

[0012] Steps 1-2: Custom Distance Metric Calculation and Discriminative Evaluation. For each candidate subsequence, a matching-based custom distance metric is proposed to process label-encoded class sequences. The minimum distance between the subsequence and all log sequences in the dataset is calculated to measure the semantic similarity between the subsequence and samples from different classes. Tolerance for structural shifts is achieved by searching for events with the same label and minimizing positional differences.

[0013] Steps 1-3: High-discriminative pattern unit screening. Based on the calculated distance results, all candidate subsequences are evaluated for discriminative power. If a subsequence exhibits small distances among samples of the same class and large distances among samples of different classes, it is considered to have high discriminative power. These high-discriminative subsequences are identified as pattern units to reflect key behavioral characteristics in the log sequences.

[0014] Steps 1-4: Sample Reconstruction Based on Longest Common Subsequence. To further eliminate adversarial perturbations, this invention utilizes the Longest Common Subsequence (LCS) matching algorithm to reconstruct the original log sequence, retaining only the sequence fragments that overlap with the extracted pattern units. This process effectively removes meaningless noise events or injected interference operations, thereby preserving the core behavioral structure of the log.

[0015] Steps 1-5: Perturbation Removal and Robustness Enhancement. After the above steps, the generated reconstructed sequence can more accurately reflect the true behavioral characteristics of the system. This step effectively removes structural perturbations in adversarial examples while maintaining semantic integrity, enabling the subsequent anomaly detection model to maintain high detection accuracy and robustness even in adversarial attack environments.

[0016] Secondly, the specific steps of step 2 above are as follows:

[0017] Step 2-1, Normal Pattern Reference Model Training. First, a normal pattern reference model is trained on normal log data to learn the typical behavioral patterns of the system under normal conditions. During training, this reference model predicts the features of the next event or time step based on the event sequence of a normal sequence, thus forming an approximation of the normal behavior distribution. By minimizing the prediction error (training loss), the model gradually grasps the characteristic patterns of normal log sequences, providing a benchmark for subsequent anomaly feature identification.

[0018] Step 2-2: Calculating the confidence score for the anomalous sequence. The trained normal pattern reference model is used to predict the behavioral pattern at each time step in the anomalous log sequence, obtaining the "normal confidence score" for each time step.

[0019] Steps 2-3: Masking Factor Construction and Feature Weighting. After obtaining the normal confidence level for each time step, a time step masking factor is constructed to dynamically adjust the weight of each time step feature during model training. This allows time steps that are highly similar to normal behavior to receive a smaller masking value, thereby reducing their impact during training; while time steps that deviate from the normal pattern correspond to a larger masking value, to enhance the model's attention to potential anomalous features.

[0020] Steps 2-4: Input Layer Masking and LSTM Training. The masking factor is applied to the input layer of the Long Short-Term Memory (LSTM) network. The adjusted input is obtained by performing element-wise multiplication of the masking factor with each time step. This processing is completed before the features enter the LSTM unit, effectively reducing the propagation influence of normal components and preventing them from interfering with the model's internal state updates.

[0021] Steps 2-5, Dynamic Training and Gradient Update: Under the masking operation, the LSTM model is trained using the standard sequence-to-sequence learning approach. Since the input features are dynamically adjusted, the model focuses on anomalous features during forward propagation, and gradient calculations are updated based on the masked input during backpropagation. Through this mechanism, the model parameters are guided during training to enhance the ability to identify anomalous components and suppress interference from normal components, thereby achieving higher detection accuracy and adversarial robustness.

[0022] Thirdly, the specific steps of step 3 above are as follows:

[0023] Step 3-1, Teacher Model Training and Difficult Sample Identification. This invention employs a teacher-student framework to improve the model's robustness in adversarial example environments. First, a Long Short-Term Memory (LSTM) teacher model is trained using the original training dataset, enabling it to complete sample classification tasks under normal conditions. After the teacher model is trained, samples that are still misclassified in the training set are identified and defined as "difficult samples." These samples are typically near the decision boundary and represent key situations where the model struggles to distinguish them accurately. For each sample, its difficulty score is defined as: .in, Indicates the teacher model on the sample Predict its true label The probability of a sample being classified. A higher difficulty score indicates that the sample is closer to the classification boundary and more susceptible to adversarial perturbations.

[0024] Step 3-2: Difficult Sample Weighting and Weight Calculation. After identifying difficult samples, this invention assigns weights to each sample based on its difficulty score to reflect its classification difficulty. Samples with lower prediction confidence in the teacher model will receive higher weights, thus having a stronger impact on the gradient updates of the student model during subsequent training, guiding the student model to pay more attention to these key samples.

[0025] Step 3-3, Distillation Training and Weighted Loss Construction of the Student Model. The training of the student model is based on a weighted loss function consisting of three parts: (1) Hard Label Loss. The true labels of the samples are used. Calculate the standard classification loss to ensure the model's basic ability to recognize known categories. (2) Soft label loss. By minimizing the Kullback-Leibler divergence between the output probability distributions of the student model and the teacher model, the student model is encouraged to imitate the probability distribution characteristics of the teacher model. (3) Hard sample loss. For the hard samples identified above, the loss term is multiplied by the sample weight to increase the model's learning strength for hard samples, thereby strengthening the model's discriminative ability in the decision boundary region. The final loss function of the student model is defined as:

[0026] .

[0027] Among them, L hard L soft and L difficult α, β, and γ represent the hard label loss, soft label loss, and hard sample loss, respectively; α, β, and γ represent the weight coefficients of the three types of loss, respectively.

[0028] Compared with the prior art, the beneficial effects of the present invention are as follows:

[0029] 1. The proposed invention can effectively remove adversarial perturbations and improve feature purity. By using shapelet-based pattern unit extraction and a custom matching distance metric, this invention can identify and reconstruct key behavioral patterns in log sequences, filtering out meaningless or maliciously inserted noise events, thereby ensuring the semantic consistency and data quality of input features and providing reliable input for subsequent anomaly detection.

[0030] 2. The proposed invention can adaptively focus on abnormal features, enhancing the model's discriminative ability. By employing a dynamic time-step masking mechanism based on normal confidence, the model can dynamically adjust the importance of features at each time step during training, reducing the interference of normal behavior segments on the learning process, and focusing on learning the differential features of abnormal behaviors, thereby improving the model's detection accuracy and robustness.

[0031] 3. Combining knowledge distillation and hard sample learning enhances robustness and generalization. Through a teacher-student model framework, the student model learns the knowledge distribution of the teacher model while focusing on strengthening its learning of difficult classification samples, improving the model's stability in the decision boundary region. This mechanism effectively addresses various types of adversarial attacks, enhancing the detection system's generalization ability and robustness in complex environments. Attached Figure Description

[0032] Fig. 1 This is a flowchart of an adversarial robustness training method for a system log detection model based on pattern unit extraction.

[0033] Fig. 2 This is the overall flowchart of the adversarial robust training method for system log detection models based on pattern unit extraction. Detailed Implementation

[0034] The technical solution of the present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments. It should be understood that the following embodiments are only used to illustrate the present invention and are not intended to limit the scope of protection of the present invention.

[0035] This invention provides an adversarial robust anomaly detection method based on the concept of directional fuzz testing. The method mainly includes: a pattern unit extraction and perturbation removal step, an LSTM-based dynamic time-step masking step, and a hard sample learning step based on knowledge distillation. Through the synergistic design of these steps, this invention can effectively improve the robustness and adversarial sample resistance of the model in anomaly detection tasks.

[0036] like Figs. 1-2 As shown, the present invention provides a method for training a system log detection model with adversarial robustness based on pattern unit extraction, comprising:

[0037] Step 201, Pattern Unit Extraction and Perturbation Removal. This step aims to extract discriminative behavioral pattern units from the original log sequence and generate more representative and robust input data by removing meaningless perturbation operations, providing high-quality feature input for subsequent anomaly detection.

[0038] Step 2011: Log Sequence Input and Subsequence Generation. This embodiment first obtains a system log event sequence dataset with category labels. Each log sequence consists of multiple event identifiers, each corresponding to an operation or state in the system. Each log sequence is labeled as either normal or abnormal. Within a preset subsequence length range, the system automatically traverses each log sequence, generating all possible consecutive subsequences as candidate pattern units. This process comprehensively covers potential behavioral fragments in the logs, providing a candidate set for subsequent pattern recognition.

[0039] Step 2012: Custom Distance Metric Calculation and Discriminative Evaluation. For each candidate subsequence, this embodiment designs a custom distance metric method based on event matching to evaluate the similarity between different sequences, defined as follows:

[0040] ;

[0041] Among them, W S W represents the source sequence to be evaluated. R This represents the reference sequence used for comparison. i Let r represent the value of the element at position i in sequence Ws. j Represents sequence W RThe element value at position j is considered. Traditional Euclidean distance is typically used for comparing numerical data, but in log data, event types are encoded as discrete labels, and numerical values ​​do not reflect semantic differences. Therefore, the method of this invention finds events with the same label during comparison by matching event identifiers one by one in subsequences and calculates their positional differences within the sequence. The system selects the event with the closest position among all possible matching positions as the matching result, and uses the average offset of all matches to reflect the degree of difference between the two sequences. This matching method can effectively identify log events that are semantically similar but have slightly different sequences, thereby improving tolerance to structural deformations and disturbances.

[0042] Step 2013: High-discriminatory pattern unit screening. After calculating the similarity of all candidate subsequences, the system performs discriminative analysis on each subsequence using the Shaplet algorithm, defined as follows:

[0043] ;

[0044] Where T represents the sequence sample, S represents the candidate subsequence, and D is the minimum custom distance between consecutive subsequences. This represents the expected value. If a subsequence exhibits high similarity among samples of the same class but significant differences among samples of different classes, it is considered to have high discriminative power. The system selects the most representative pattern units based on the discriminative score and uses them as the core features for subsequent data reconstruction and anomaly detection. In this way, key structures reflecting the system's behavioral patterns can be extracted from a large amount of log data.

[0045] Step 2014: Sample Reconstruction Based on the Longest Common Subsequence. After obtaining the set of pattern units, this embodiment uses the longest common subsequence matching algorithm to reconstruct the original log sequence. Specifically, each original log is compared with a pattern unit, retaining only event fragments that partially overlap with the pattern unit, and deleting irrelevant or redundant log events. This process is equivalent to filtering out noise that is not beneficial to model training or invalid operations injected by adversarial examples from the original data, ensuring that the reconstructed sequence contains only event information closely related to the actual behavior of the system.

[0046] Step 2015: Perturbation Removal and Robustness Enhancement. After the above steps, the generated reconstructed log sequence can more accurately reflect the core behavioral characteristics of the system. While preserving the semantic integrity of the logs, this embodiment effectively eliminates structural perturbations and redundant operations introduced by adversarial attacks. This result not only improves the quality of the input data but also significantly enhances the robustness and stability of the subsequent anomaly detection model when facing adversarial examples and complex system behaviors.

[0047] Step 202, Dynamic Temporal Step Masking Mechanism Based on LSTM. This embodiment provides a dynamic temporal step masking mechanism based on Long Short-Term Memory (LSTM) networks to automatically adjust the weights of input features during model training, thereby enhancing the model's robustness and detection accuracy when facing anomalous sequences or adversarial examples. This mechanism introduces the concepts of "normal confidence" and "temporal step masking factor," enabling the model to adaptively reduce the influence of normal behavioral features and highlight the contribution of anomalous features.

[0048] Step 2021: Normal Pattern Reference Model Training. First, a normal pattern reference model is trained on a sample set containing only normal log data. The goal of this model is to learn the typical behavioral patterns of the system under normal conditions. During training, the reference model learns the temporal order of normal log events based on a Long Short-Term Memory (LSTM) network, predicts subsequent events in the sequence, and continuously optimizes the model parameters based on the prediction error. ;

[0049] Among them, c t This represents the state of the memory unit. t For the output of the forget gate, i t For input gate output, These serve as candidate memories. Through continuous training, the model gradually learns the behavioral patterns and event distribution of the system during normal operation, providing a benchmark for subsequent anomaly detection.

[0050] Step 2022: Calculating the Confidence of Anomaly Sequences. After the normal pattern reference model is trained, it is applied to log sequences containing anomaly samples. The model predicts each time step in the anomaly sequence based on previously learned normal behavior patterns. Based on this, a "normal confidence score" is calculated for each time step, representing the degree of similarity between that time step and normal behavior. If the confidence score for a time step is high, it indicates that the behavior is consistent with the normal pattern; if the confidence score is low, it suggests that the time step may contain anomalous features or potential attack behavior. In this way, the system can perform refined behavioral evaluation of each time step in the entire anomaly sequence, identifying the most anomalous parts.

[0051] Step 2023: Construction of Masking Factors and Feature Weighting. After obtaining the normal confidence levels for all time steps, the system generates a corresponding masking factor for each time step based on the confidence results. This masking factor is used to dynamically adjust the importance of the features at that time step in model training. Time steps with higher confidence levels are considered closer to normal behavior, and their masking factor values ​​are relatively smaller, thus weakening their impact on model training. Time steps with lower confidence levels correspond to larger masking factor values, and the model will pay more attention to these abnormal features during training. This dynamic weighting mechanism allows the model to automatically focus on time segments with abnormal features during the learning process, thereby improving detection sensitivity and robustness.

[0052] Step 2024: Input Layer Masking and LSTM Model Training. During model training, a masking factor is applied to the input layer of the LSTM network. Specifically, at each time step, the system adjusts the weights of the input features based on the value of the masking factor, reducing the weights of parts of the input that resemble normal behavior and increasing the weights of parts that deviate from the normal pattern. This operation is completed before the features enter the LSTM unit, effectively preventing the over-propagation of normal components and avoiding their interference with internal state updates. Compared to traditional methods that weight the features at the output layer, this approach can more directly affect the model's feature learning process, allowing the model to focus on anomalous information in the early stages.

[0053] Step 2025: Dynamic Training and Gradient Optimization. After input layer masking, the LSTM model is trained using conventional sequence learning. During forward propagation, the model automatically highlights the contribution of anomalous features based on the masked input; during backpropagation, the system calculates gradients based on the masked features, thereby enhancing anomaly detection capabilities and suppressing the influence of normal features during parameter updates. This training strategy enables the model to maintain stable performance in adversarial examples and complex anomaly scenarios, effectively improving detection accuracy and overall robustness.

[0054] Step 203: Robust training mechanism based on knowledge distillation and hard sample learning. This embodiment provides a robust training mechanism based on knowledge distillation and hard sample learning. By introducing a teacher-student model framework, the student model can retain the knowledge of the teacher model while paying more attention to classifying difficult samples and easily perturbed boundary samples, thereby significantly improving the system's robustness and detection accuracy in adversarial attack environments.

[0055] Step 2031: Teacher Model Training and Hard Sample Identification. First, a Long Short-Term Memory (LSTM) teacher model is built and trained on the complete training dataset. The goal of the teacher model is to learn the system's discrimination patterns under normal and abnormal conditions, providing guidance for the student model. After training, the system analyzes the teacher model's classification results for each sample in the training set to identify samples that are still misclassified or have low prediction confidence. These samples are located near the model's decision boundary, possessing high uncertainty and representativeness, and are defined as "hard samples." Hard samples typically appear as marginal samples with small feature differences but different classification labels, revealing weak areas of the model in complex scenarios. Therefore, identifying these samples is a crucial step in achieving targeted reinforcement training.

[0056] Step 2032: Difficult Sample Weighting and Weight Allocation. After identifying difficult samples, this invention assigns corresponding weights to each sample to reflect its importance in the training process. Specifically, the lower the prediction confidence of the teacher model for a sample, the higher the weight assigned to that sample in the student model's training. This means that the model will pay more attention to these types of samples when updating parameters, enabling it to learn more robust discrimination boundaries. This confidence-based dynamic weighting method allows the training process to adaptively adjust the sample contribution, thereby maximizing the model's learning efficiency for key samples with limited training resources.

[0057] Step 2033: Distillation Training and Multiple Loss Optimization of the Student Model. After determining the teacher model and sample weights, distillation training of the student model begins. The student model inherits and extends knowledge of complex patterns by mimicking the output distribution of the teacher model and combining it with actual label information. During training, the optimization objective of the student model consists of three types of losses: the first is hard label loss, used to constrain the model's classification accuracy on real labels, ensuring the model has basic classification ability; the second is soft label loss, used to minimize the difference in output probability distribution between the student model and the teacher model, enabling the student model to learn the implicit feature structure and inter-class relationships of the teacher model; the third is hard sample loss, which is multiplied by the weight value of hard samples during calculation, thereby increasing the model's learning intensity for these key samples. Through the joint optimization of the above multiple losses, the student model can strengthen its ability to identify hard samples and potential adversarial samples while inheriting the knowledge of the teacher model.

[0058] Step 2034: Dynamically Weighted Training and Robustness Enhancement. At each stage of training, the parameter updates of the student model are dynamically driven by a weighted loss function. Since difficult samples are given higher weights in the loss calculation, the model's training naturally focuses on those samples that are most easily perturbed or pose the greatest discrimination challenge. This dynamically weighted training strategy not only improves the model's discrimination accuracy on boundary samples but also enables the model to maintain stable output when facing adversarial perturbations.

[0059] The specific embodiments of the present invention have been described in detail above. To verify the effectiveness and feasibility of the method proposed in this invention, experiments are conducted below using specific datasets. The experimental results and related comparative data demonstrate that the final generated student model significantly outperforms traditional models in terms of detection accuracy, generalization performance, and resistance to adversarial attacks. It can be widely applied in fields such as log anomaly detection, system intrusion identification, and intelligent security auditing.

[0060] Table 1 shows the dataset selected for the experimental testing phase of this invention:

[0061] ;

[0062] Table 2 shows the experimental results of the effectiveness of this method for log defect detection:

[0063] ;

[0064] Table 3 shows the experimental results of the anti-adversarial attack performance of this method against different adversarial attacks:

[0065] ;

[0066] Table 4 presents the ablation experiment results showing the effectiveness of the knowledge distillation combined with the difficult sample learning method:

[0067] ;

[0068] Table 5 presents the ablation experiment results showing the effectiveness of the knowledge distillation combined with the difficult sample learning method:

[0069] ;

[0070] Table 6 presents the ablation experiment results showing the effectiveness of the knowledge distillation combined with the difficult sample learning method:

[0071] .

[0072] In the description of this specification, the references to terms such as "one embodiment," "some embodiments," "illustrative embodiment," "example," "specific example," or "some examples," etc., indicate that a specific feature, structure, material, or characteristic described in connection with that embodiment or example is included in at least one embodiment or example of the invention. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples.

[0073] Although embodiments of the invention have been shown and described, those skilled in the art will understand that various changes, modifications, substitutions and alterations can be made to these embodiments without departing from the principles and spirit of the invention, the scope of which is defined by the claims and their equivalents.

Claims

1. A method for adversarial robust training of a system log detection model based on pattern unit extraction, characterized in that, Includes the following steps: Step 1: Extract Shapelet pattern units from the original log sequence. Enhance the Shapelet algorithm with a custom distance metric to extract semantically meaningful feature pattern units, thereby achieving effective reconstruction of the log sequence and suppressing adversarial noise. Step 2: Input the reconstructed sequence into the model based on the Long Short-Term Memory (LSTM) network. Through the confidence-guided time step masking mechanism, the sequence is weighted according to the probability that each time step belongs to the normal system behavior, thus highlighting potential anomalies. Step 3: Adopt the teacher-student learning paradigm and use the misclassified samples of the teacher model to guide the training of the student model with difficult samples, thereby improving the robustness of the model under various adversarial attacks.

2. The method according to claim 1, characterized in that, The specific implementation of step 1 includes the following steps: Step 1-1, Log sequence input and subsequence generation: First, obtain the system log event sequence dataset with category labels. For each log sequence, systematically generate all possible subsequences as candidate pattern units within a preset length range. Steps 1-2: Custom distance metric calculation and discriminative evaluation. For each candidate subsequence, a custom distance metric based on matching is proposed to process the label-encoded category sequence. The minimum distance between the subsequence and all log sequences in the dataset is calculated to measure the semantic similarity between the subsequence and samples of different categories. By searching for events with the same label and minimizing positional differences, tolerance for structural shifts is achieved. Steps 1-3: High discriminative pattern unit screening. Based on the calculated distance results, all candidate subsequences are evaluated for discriminativeness. If a subsequence meets the preset first threshold condition in distance between samples of the same type and meets the preset second threshold condition in distance between samples of different types, it is considered to have high discriminative power. These high discriminative subsequences are identified as pattern units to reflect the key behavioral features in the log sequence. Steps 1-4: Sample reconstruction based on the longest common subsequence. To further eliminate adversarial perturbations, the original log sequence is reconstructed using the longest common subsequence (LCS) matching algorithm. Only the sequence segments that overlap with the extracted pattern units are retained. This process can effectively remove meaningless noise events or injected interference operations, thereby preserving the core behavioral structure of the log. Steps 1-5: Perturbation Removal and Robustness Enhancement. After the above steps, the generated reconstructed sequence can more accurately reflect the true behavioral characteristics of the system. This step effectively removes structural perturbations in adversarial examples while maintaining semantic integrity, so that the subsequent anomaly detection model still has high detection accuracy and robustness in adversarial attack environments.

3. The method according to claim 1, characterized in that, The specific implementation of step 2 includes the following steps: Step 2-1, Normal Pattern Reference Model Training: First, a normal pattern reference model is trained on normal log data to learn the typical behavior patterns of the system under normal conditions. During the training process, the reference model predicts the features of the next event or time step based on the event sequence of the normal sequence, thereby forming an approximation of the normal behavior distribution. By minimizing the prediction error (training loss), the model gradually masters the characteristic patterns of the normal log sequence, providing a benchmark for subsequent abnormal feature identification. Step 2-2, Calculate the confidence of the abnormal sequence. Use the trained normal pattern reference model to predict the behavior pattern of each time step in the abnormal log sequence to obtain the "normal confidence" of each time step. Steps 2-3: Masking factor construction and feature weighting. After obtaining the normal confidence level for each time step, a time step masking factor is constructed to dynamically adjust the weight of each time step feature in the model training process. This allows time steps that are highly similar to normal behavior to receive a smaller masking value, thereby reducing their impact during training; while time steps that deviate from the normal pattern correspond to a larger masking value to enhance the model's attention to potential abnormal features. Steps 2-4, Input layer masking and LSTM training: The masking factor is applied to the input layer of the Long Short-Term Memory (LSTM) network. The element-wise product operation between the time step and the masking factor is performed to obtain the adjusted input. This processing method is completed before the features enter the LSTM unit, which can effectively reduce the propagation effect of normal components and avoid them interfering with the internal state update of the model. Steps 2-5: Dynamic Training and Gradient Update. Under the masking operation, the LSTM model is trained in the standard sequence-to-sequence learning manner. Since the input features have been dynamically adjusted, the model can focus on abnormal features during forward propagation. During the backpropagation stage, the gradient calculation is also updated based on the masked input. Through this mechanism, the model parameters are guided to strengthen the ability to identify abnormal components and suppress the interference of normal components during training, thereby achieving higher detection accuracy and adversarial robustness.

4. The method according to claim 1, characterized in that, The specific implementation of step 3 includes the following steps: Step 3-1, Teacher Model Training and Hard Sample Identification: A teacher-student framework is adopted to improve the robustness of the model in adversarial sample environments. First, the Long Short-Term Memory (LSTM) network teacher model is trained using the original training dataset so that it can complete the sample classification task under normal conditions. After the teacher model is trained, samples that are still misclassified in the training set are identified and defined as "hard samples". Step 3-2, Difficult Sample Weighting and Weight Calculation: After identifying difficult samples, weights are assigned to each sample based on its difficulty score to reflect its classification difficulty. For a sample whose prediction confidence is c by the teacher model, the weight assigned to the sample is defined as 1-c, where samples with lower prediction confidence have higher weight values, thus having a stronger impact on the gradient update of the student model in subsequent training and guiding the student model to pay more attention to these key samples. Step 3-3, Distillation training and weighted loss construction of the student model. The training of the student model is based on a weighted loss function consisting of three parts: (1) Hard label loss, which uses the true labels of the samples. (1) Calculate the standard classification loss to ensure the basic recognition ability of the model for known categories; (2) Soft label loss, by minimizing the Kullback-Leibler divergence between the output probability distributions of the student model and the teacher model, encourage the student model to imitate the probability distribution characteristics of the teacher model; (3) Difficult sample loss, for the aforementioned difficult samples, the loss term is multiplied by the sample weight to increase the learning intensity of the model for difficult samples, thereby strengthening the model's discrimination ability in the decision boundary region.