Training method of safety detection model, safety detection method, device and equipment

By pruning and sample set training on large language models, teacher models and student models suitable for network security detection are generated, which solves the speed and accuracy of large-scale language models in network traffic detection, and achieves fast and accurate security detection.

CN120498709AActive Publication Date: 2025-08-15SANGFOR TECH INC
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510374626.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-03-27
Publication Date
2025-08-15
Estimated Expiration
2045-03-27

AI Technical Summary

Technical Problem

Large-scale language models have low inference speed in network traffic security detection, resulting in the inability to quickly intercept abnormal traffic, causing losses to users.

Method used

By acquiring the teacher model and the student model, the first sample set is used to train the student model, and then the second sample set is used to train. The second sample set contains specified sample safety data to ensure that the sample label is inconsistent with the prediction detection results, and realize the model's attention to difficult-to-identify samples and reduce prediction errors.

Benefits of technology

Improve the accuracy and reliability of the security detection model, ensuring that abnormal traffic can be quickly and accurately identified in network traffic detection.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120498709A_ABST
    Figure CN120498709A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a safety detection model training method, a safety detection method, a safety detection device and equipment. The method comprises the steps that a teacher model and a student model are obtained, the teacher model is obtained by conducting fine tuning training on a large language model through sample safety data in a first sample set, and the student model is obtained by conducting pruning processing on the teacher model or the large language model; training the student model by using the teacher model and the first sample set to obtain an initial safety detection model; training the initial security detection model by using a second sample set to obtain a target security detection model, the second sample set comprising specified sample security data, and the specified sample security data being selected from the first sample set, the sample label corresponding to the specified sample security data is inconsistent with the prediction detection result in the fine tuning training process or the student model training process. Through adoption of the target security detection model, rapid and accurate detection of the network traffic can be realized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and more specifically, to a training method for a security detection model, a security detection method, a device, and equipment. Background Art

[0002] In related technologies, the Large Language Model (LLM) is a natural language processing model based on the transformer attention network unit. It has multiple layers, each of which mainly includes an attention network unit (attention) and a fully connected layer (MLP). Large language models can achieve good results in many tasks, but due to their large size, they have a low inference speed. For example, in traffic security detection scenarios, if the detection speed is too slow, abnormal traffic may not be intercepted, which will cause significant losses to users.

[0003] Based on this, obtaining a security detection model with a simple model structure so as to quickly and accurately detect network traffic security is an urgent problem to be solved. Summary of the Invention

[0004] In view of this, the embodiments of the present application propose a security detection model training method, security detection method, device and equipment, which can realize fast and accurate security detection of network traffic.

[0005] In a first aspect, an embodiment of the present application provides a method for training a security detection model, the method comprising: obtaining a teacher model and a student model, the teacher model being obtained by fine-tuning a large language model using sample safety data in a first sample set, and the student model being obtained by pruning the teacher model or the large language model; training the student model using the teacher model and the first sample set to obtain an initial security detection model; training the initial security detection model using a second sample set to obtain a target security detection model, the second sample set including specified sample safety data, the specified sample safety data being selected from the first sample set, and the sample label corresponding to the specified sample safety data being inconsistent with its predicted detection result during the fine-tuning training process or the student model training process.

[0006] In a second aspect, an embodiment of the present application provides a security detection method, which includes: obtaining data to be detected; performing security detection on the data to be detected using a target security detection model to obtain a detection result, and the target security detection model is obtained using a security detection model training method.

[0007] In a third aspect, an embodiment of the present application provides a training device for a security detection model, the device comprising: a model acquisition module, a first training module and a second training module; the model acquisition module is used to acquire a teacher model and a student model, the teacher model is obtained by fine-tuning a large language model using sample security data in a first sample set, and the student model is obtained by pruning the teacher model or the large language model; the first training module is used to train the student model using the teacher model and the first sample set to obtain an initial security detection model; the second training module is used to train the initial security detection model using a second sample set to obtain a target security detection model, the second sample set includes specified sample safety data, the specified sample safety data is selected from the first sample set, and the sample label corresponding to the specified sample safety data is inconsistent with its predicted detection result during the fine-tuning training process or the student model training process.

[0008] In one possible implementation, the training device of the security detection model also includes a first selection module, a second selection module and a sample set construction module; the first selection module is used to obtain specified sample security data from the first sample set based on the predicted detection results of each network sample traffic data in the first sample set during the fine-tuning training process or the student model training process; the second selection module is used to select target sample security data from the first sample set whose similarity with the specified sample security data is greater than a preset similarity threshold; the sample set construction module is used to construct a second sample set including the specified sample security data and the target sample security data.

[0009] In one embodiment, the model acquisition module is further configured to perform multiple random pruning operations on the teacher model or the large language model to obtain multiple student models; the first training module includes a training submodule and a model selection submodule. The training submodule is configured to train the multiple student models using the teacher model and the first sample set to obtain multiple trained student models and training snapshots of each trained student model; and the model selection submodule is configured to select an initial security detection model from the multiple trained student models based on the performance indicators included in the training snapshots of each trained student model.

[0010] In one embodiment, the large language model includes multiple attention heads, and the model acquisition module is also used to perform multiple random pruning processes on the attention heads of the teacher model or the large language model to obtain multiple student models, wherein each time the random pruning process is performed, at least one attention head of the teacher model or the large language model is pruned to obtain a student model.

[0011] In one possible implementation, the model selection submodule is also used to obtain the model structure complexity of the trained student model based on the model structure of the trained student model; obtain the score of each trained student model based on the performance indicators and model structure complexity of each trained student model; and select the trained student model with the highest score from multiple trained student models as the initial security detection model.

[0012] In one embodiment, the first training module also includes a first detection submodule, a second detection submodule, a prediction loss acquisition submodule, a distillation loss acquisition submodule, a model loss acquisition submodule and a parameter adjustment submodule; the first detection submodule is used to use the teacher model to perform security detection on the sample safety data in the first sample set to obtain a first security detection result; the second detection submodule is used to use the student model to perform security detection on the sample safety data in the first sample set to obtain a second security detection result; the prediction loss acquisition submodule is used to obtain the prediction loss based on the second security detection result and the sample label of the sample safety data; the distillation loss acquisition submodule is used to obtain the distillation loss based on the first security detection result and the second security detection result of the sample safety data; the model loss acquisition submodule is used to perform a weighted sum of the prediction loss and the distillation loss to obtain the model loss of the student model; the parameter adjustment submodule is used to adjust the student model based on the model loss of the student model to obtain an initial security detection model.

[0013] In a fourth aspect, an embodiment of the present application provides a security detection device, which includes: a detection data acquisition module for acquiring data to be detected; a detection result acquisition module for performing security detection on the data to be detected using a target security detection model to obtain a detection result; the target security detection model is obtained using a security detection model training device.

[0014] In one possible implementation, the security detection model is deployed on a grayscale release platform, and the detection data acquisition module is further used to obtain the data to be detected allocated by the grayscale release platform to the target security detection model.

[0015] In a fifth aspect, an embodiment of the present application provides an electronic device comprising a processor and a memory; one or more programs are stored in the memory and configured to be executed by the processor to implement the above method.

[0016] In a sixth aspect, an embodiment of the present application provides a computer-readable storage medium, in which program code is stored, wherein the above method is executed when the program code is executed by a processor.

[0017] In a seventh aspect, embodiments of the present application provide a computer program product or computer program, which includes computer instructions stored in a computer-readable storage medium. A processor of a computer device retrieves the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the above-described method.

[0018] The embodiments of the present application provide a training method, a security detection method, an apparatus and a device for a security detection model. The method comprises: using the teacher model and the first sample set to train the student model to obtain an initial security detection model; using the second sample set to train the initial security detection model to obtain a target security detection model, the second sample set includes specified sample security data, the specified sample security data is selected from the first sample set, and the sample label corresponding to the specified sample security data is inconsistent with its predicted detection result during the fine-tuning training process or the student model training process. In the above method, since the teacher model is obtained by training a large language model using the first sample set, the teacher model is an expert model that is more suitable for network security tasks, and it has good performance in network security detection tasks. Subsequently, a student model is obtained by pruning the large language model or the teacher model, and a second sample set including specified sample safety data is obtained from the first sample set. Since the sample label of the specified sample safety data is inconsistent with its predicted detection result during the training or fine-tuning training of the student model, that is, the specified sample safety data is the correctly classified sample data, when the second sample set is used to train the initial safety detection model, the model can pay more attention to samples that are difficult to identify, reduce the model's prediction errors on such samples, and thus make the final target safety detection model more accurate and reliable. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present application. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.

[0020] Figure 1 A schematic diagram of a process for training a security detection model provided in an embodiment of the present application is shown;

[0021] Figure 2 A flowchart of a method for training a security detection model provided in an embodiment of the present application is shown;

[0022] Figure 3Another flowchart of a method for training a security detection model provided by an embodiment of the present application is shown;

[0023] Figure 4 Shown Figure 1 Flow chart of step S140;

[0024] Figure 5 A flowchart of the student model training phase in a security detection model training method provided in an embodiment of the present application is shown;

[0025] Figure 6 Another flow chart of a method for training a security detection model provided in an embodiment of the present application is shown;

[0026] Figure 7 Another flowchart of a method for training a security detection model provided in an embodiment of the present application is shown;

[0027] Figure 8 Shown Figure 1 Flow chart of step S150;

[0028] Figure 9 A schematic diagram of a safety inspection method according to an embodiment of the present invention is shown;

[0029] Figure 10 A connection block diagram of a training device for a safety detection model proposed in an embodiment of the present application is shown;

[0030] Figure 11 A connection block diagram of a safety detection device proposed in an embodiment of the present application is shown;

[0031] Figure 12 A structural block diagram of an electronic device for executing the method according to an embodiment of the present application is shown. DETAILED DESCRIPTION

[0032] Example embodiments will now be described more fully with reference to the accompanying drawings. However, example embodiments can be implemented in many forms and should not be construed as limited to the examples set forth herein; rather, these embodiments are provided so that this application will be thorough and complete and will fully convey the concepts of the example embodiments to those skilled in the art.

[0033] In addition, described feature, structure or characteristic can be combined in one or more embodiments in any suitable manner.In the following description, many specific details are provided so as to provide a full understanding of the embodiments of the present application. However, it will be appreciated by those skilled in the art that the technical scheme of the present application can be put into practice without one or more of the specific details, or other methods, components, devices, steps etc. can be adopted. In other cases, known methods, devices, implementations or operations are not shown or described in detail to avoid blurring the various aspects of the application.

[0034] The block diagrams shown in the accompanying drawings are merely functional entities and do not necessarily correspond to physically separate entities. That is, these functional entities may be implemented in software, in one or more hardware modules or integrated circuits, or in different networks and / or processor devices and / or microcontroller devices.

[0035] The flowcharts shown in the accompanying drawings are for illustrative purposes only and do not necessarily include all contents and operations / steps, nor must they be executed in the order described. For example, some operations / steps may be decomposed, while others may be combined or partially combined. Therefore, the actual execution order may vary depending on the actual situation.

[0036] It should be noted that the term "plurality" used in this document refers to two or more. "And / or" describes a relationship between associated objects, indicating that three possible relationships exist. For example, "A and / or B" can represent: A alone, A and B together, or B alone. The character " / " generally indicates an "or" relationship between the associated objects.

[0037] It should also be noted that in the embodiments of the present application, the collection, use, processing and storage of application information are all subject to the user's permission and must comply with the regulations of the region.

[0038] Figure 1 The present application specifically illustrates a training method for a security detection model. The method can be applied to an electronic device, which can be a terminal device or a server. The method includes:

[0039] Step S110: Obtain a teacher model and a student model, wherein the teacher model is a model obtained by fine-tuning the large language model using the sample safety data in the first sample set, and the student model is a model obtained by pruning the teacher model or the large language model.

[0040] The teacher model and the student model can be obtained by obtaining the teacher model and the student model from a database; or by obtaining the teacher model from a database and pruning the teacher model to obtain the student model; or by obtaining a large language model and a first sample set, fine-tuning the first large prediction model using the first sample set to obtain the teacher model, and then pruning the teacher model and / or the teacher model to obtain the student model. The above methods for obtaining the teacher model and the student model are merely illustrative and are not specifically limited in this embodiment.

[0041] Please refer to Figure 2 and Figure 3 ,in, Figure 2 The flowchart of pruning the teacher model to obtain the student model is shown. Figure 3 A flowchart of pruning a large language model to obtain a student model is shown.

[0042] Step S120: using the teacher model and the first sample set to train the student model to obtain an initial security detection model.

[0043] The purpose of training the student model is to transfer the knowledge of a large and complex model (the teacher model) to a small and simplified model (the student model). This allows the student model to learn the output distribution of the teacher model, thereby reducing the complexity of the model while maintaining or approaching the performance of the teacher model as much as possible.

[0044] Step S130: Use the second sample set to train the initial security detection model to obtain a target security detection model, where the second sample set includes specified sample safety data, which is selected from the first sample set, and the sample label corresponding to the specified sample safety data is inconsistent with its predicted detection result during the fine-tuning training process or the student model training process.

[0045] Among them, when the initial security detection model is trained using the second sample set, the initial security detection model is used to perform security detection on the sample safety data in the second sample set to obtain a third security detection result, and a loss is calculated based on the third security detection result and the sample label of the sample safety data to obtain a second loss. The model parameters of the initial security detection model are adjusted using the second loss to minimize the second loss, and it is determined whether the second loss is less than a threshold and whether the number of iterations reaches a preset number of iterations.

[0046] If the second loss is not less than the preset loss threshold and the number of iterations has not reached the second number of iterations, return to the step of performing security detection on the sample safety data in the second sample set using the initial security detection model until the loss value of the second loss is less than the second preset loss threshold or the number of iterations reaches the second preset number of iterations, and the target security detection model is obtained.

[0047] Using the above-described security detection model training method, a large language model is first trained using a first sample set to obtain a teacher model. This teacher model becomes an expert model more suitable for network security tasks and exhibits good performance on network security detection tasks. Subsequently, a student model is obtained by pruning the large language model or teacher model. This student model is then trained using the teacher model and the first sample set. This allows the student model to learn the teacher model's "soft" knowledge (e.g., probability distribution), improving both its performance and its robustness. Finally, a second sample set comprising designated sample security data is obtained from the first sample set. Because the sample labels of the designated sample security data are inconsistent with the predicted detection results obtained during the student model training or fine-tuning process, i.e., the designated sample security data are correctly classified sample data, when the initial security detection model is trained using the second sample set, the model can focus more on difficult-to-identify samples, reducing the model's prediction errors on such samples, thereby increasing the accuracy and reliability of the resulting target security detection model.

[0048] In one embodiment, the above step S110 may specifically include steps S110a to S110c.

[0049] Step S110a: Acquire a first sample set, where the first sample set includes a plurality of sample safety data and a sample label corresponding to each sample safety data.

[0050] Among them, sample security data can be network traffic and / or email data, etc.; it can also be data in the terminal (such as processes, threads, files and / or registries, etc.) and / or cloud data (such as log data (security audit logs and / or server logs, etc.), UEBA data (user behavior data, etc.), API data and / or container data, etc.) and other security-related data.

[0051] The sample label is the result of determining whether the sample security data belongs to a certain type, such as whether it is malware communication, whether there is an attack behavior, whether it is spam, etc. It should be understood that the sample label is the result of manual annotation or predetermined by other means, which is used to guide the machine learning model to perform supervised learning and help the model learn to distinguish different types of traffic. In one embodiment of the present application, the sample label includes classification categories such as black, white, and gray. Exemplarily, the sample security data can be network traffic data obtained in other security scenarios such as phishing security detection and terminal security detection. The sample security data of the phishing security detection scenario can also include a complete phishing email message. In the terminal security detection scenario, the sample security data also includes complete terminal process chain information.

[0052] In one embodiment, the first sample data may be obtained by obtaining a plurality of sample traffic data from a public security-related dataset, thereby constructing the first sample set. The security-related dataset typically includes processed network traffic records and their corresponding security tags (sample tags).

[0053] In another embodiment, a pre-deployed network monitoring tool (such as Wireshark, Zeek) can be used to capture network traffic in an actual environment as sample network traffic, and sample labels can be configured for the sample network traffic through manual labeling or an automatic analysis system to obtain a first sample set.

[0054] Step S110b: fine-tune the large language model using the first sample set to obtain a teacher model.

[0055] Among them, fine-tuning training refers to the process of further training a model (i.e., a large language model) based on a model that has been pre-trained with a large-scale dataset (i.e., a large language model) using a small-scale dataset for a specific field or task (i.e., the first sample set in the field of traffic security detection), so as to make the trained teacher model better adapt to the specific task or field (security detection) while retaining the general knowledge learned from large-scale data.

[0056] Among them, the fine-tuning training process is as follows: use the large language model to perform security detection on the sample network traffic to obtain the predicted detection result, calculate the loss based on the predicted detection result of the sample network traffic and the sample label to obtain the first loss, adjust the model parameters of the large language model based on the first loss to minimize the first loss, and obtain the teacher model when the number of iterations reaches the first preset number or the first loss value is less than the first preset loss threshold.

[0057] Step S110c: Pruning the teacher model or the large language model to obtain a student model.

[0058] Pruning is an effective method for optimizing deep learning models, reducing model complexity and improving operational efficiency while maintaining performance. Pruning teacher models or large language models involves attention head pruning, neuron pruning, weight pruning, or layer pruning.

[0059] If the teacher model or large language model uses a Transformer architecture, attention head pruning can be performed. Specifically, the multi-head attention mechanism contains multiple attention heads, each responsible for capturing different relationships in the input sequence. Pruning the teacher model or large language model can reduce the model's computational workload by removing some attention heads.

[0060] If the teacher model or the large language model includes a fully connected layer or a feedforward neural network, neuron pruning can be performed; specifically, certain neurons can be removed from the fully connected layer or feedforward neural network of the teacher model or the large language model.

[0061] If you perform weight pruning on the teacher model or the large language model, you can remove weights that are close to zero or unimportant in the weight matrix of the classroom model or the large language model.

[0062] If you perform layer pruning on the teacher model or large language model, you can remove the entire Transformer layer or other types of layers (such as convolutional layers, fully connected layers, residual connection layers, embedding layers, etc.) in the teacher model or large language model.

[0063] In the above step S110c, the teacher model or the large language model may be pruned once or multiple times to obtain one or more student models.

[0064] Among them, after obtaining multiple student models, one of the student models can be selected from the multiple student models for subsequent training.

[0065] It is worth mentioning that the student model obtained after pruning should have lower complexity and higher operating efficiency while maintaining high performance.

[0066] Please refer to 4 and Figure 5 In one embodiment, the above step S120 includes steps S121-S126.

[0067] Step S121: Use the teacher model to perform security detection on the sample security data in the first sample set to obtain a first security detection result.

[0068] Among them, the first security detection result is a soft label (softlabels) generated after processing by the softmax function, which includes the probabilities of multiple classification results. The probability of each classification result is between 0 and 1, and the total is 1, which is used to guide the learning of the student model.

[0069] Step S122: Use the student model to perform security detection on the sample security data in the first sample set to obtain a second security detection result.

[0070] Among them, the second security detection result is also a soft label (softlabels) generated after processing by the softmax function, which includes the probabilities of multiple classification results. The probability of each classification result is between 0 and 1, and the total is 1.

[0071] Step S123: Obtain predicted loss based on the second safety detection result of the sample safety data and the sample label.

[0072] Specifically, a loss function, such as a cross entropy loss function or a Focal loss function, may be used to calculate the loss of the first safety detection result and the sample label to obtain a prediction loss.

[0073] Step S124: Obtaining distillation loss based on the first safety detection result and the second safety detection result of the sample safety data.

[0074] Specifically, the KL divergence loss or the mean square error loss function may be used to perform loss calculation on the first safety detection result and the second safety detection result to obtain the distillation loss.

[0075] Step S125: performing a weighted summation of the prediction loss and the distillation loss to obtain the model loss of the student model.

[0076] Among them, the weights of the prediction loss and the distillation loss can be set according to actual needs. In one embodiment, when the weight of the prediction loss is 1, the weight of the distillation loss can be set to 0.1 (or around 0.1, such as between 0.08-0.12, or between 0.07-0.13, etc.), so as to achieve the optimal training effect in the detection and classification scenario.

[0077] Step S126: adjusting the student model based on the model loss of the student model to obtain an initial safety detection model.

[0078] By using steps S121-S126 above, during the training process, the output distribution of the student model (the second safety detection result, which is a soft label) is simultaneously compared with the true label (the sample label, which is a hard label) and the output distribution of the teacher model (the first safety detection result, which is a soft label) to calculate the loss, resulting in a prediction loss between the second safety detection result and the sample label, and a distillation loss between the first safety detection result and the second safety detection result. The goal of the student model is to minimize the weighted sum of the prediction loss and the distillation loss to obtain an initial safety detection model, so that the initial safety detection model maintains or approaches the performance of the teacher model.

[0079] It is worth mentioning that if there is one student model, the above steps S121-S126 can be performed on the student model to obtain a trained student model, and the trained student model is the initial security detection model; if there are multiple student models, the above steps S121-S126 can be performed on each student model to obtain multiple trained student models, and one of the multiple trained student models can be selected as the initial security detection model.

[0080] Please refer to Figure 6 and Figure 7 In one possible implementation, in the above step S110, in obtaining the teacher model and the student model, when obtaining the student model, the specific acquisition process can be: performing multiple random pruning processes on the teacher model or the large language model to obtain multiple student models.

[0081] Among them, a student model can be obtained by performing a random pruning process on the teacher model or the large language model.

[0082] It is worth mentioning that during a random pruning, one or more of multiple attention heads, multiple layers, and multiple weights can be subtracted at the same time.

[0083] For the process of pruning the teacher model, please refer to the detailed description of the aforementioned step S130.

[0084] In one embodiment, the large language model includes multiple attention heads, and the attention heads of the teacher model or the large language model are randomly pruned multiple times to obtain multiple student models, wherein each time the random pruning process is performed, at least one attention head of the teacher model or the large language model is pruned to obtain a student model.

[0085] In the case that there are multiple student models, the above step S120 may include steps 127-S128.

[0086] Step S127: training a plurality of student models using the teacher model and the first sample set, to obtain a plurality of trained student models and a training snapshot of each trained student model;

[0087] Among them, the process of using the teacher model and the first sample set to train multiple student models can refer to the specific description of steps S121-S126 mentioned above, which will not be repeated here.

[0088] A training snapshot of a trained student model refers to saving the model's parameters and state periodically (e.g., at fixed deployment intervals or intervals of a preset duration) during student model training. These saved files are often called checkpoints. Checkpoint models can be used for model evaluation, resuming training, or further fine-tuning.

[0089] The training snapshot can include performance indicators of the student model, such as precision, recall, F1 score, and ACU value.

[0090] Accuracy is the most direct indicator of a model's prediction accuracy. It is defined as the ratio of correctly predicted samples to the total number of samples. In information retrieval, accuracy is expressed as: Accuracy = Number of correctly retrieved documents / Number of retrieved documents. This metric is suitable for evaluating a model's overall predictive performance, but may be affected when working with imbalanced datasets.

[0091] Recall, also known as recall, is the ratio of the number of relevant documents retrieved to the total number of relevant documents in the document repository. It measures the recall of a retrieval system. In the field of information retrieval, recall reflects the model's ability to identify all actual positive examples. Mathematically, recall can be expressed as: Recall = Number of correctly estimated positive examples by the model / Number of actual positive examples. A higher recall indicates a more comprehensive positive identification by the model, but this may also be accompanied by a higher false positive rate.

[0092] The F1 score is a statistical metric used to measure the accuracy of a binary classification model. It takes into account both the precision and recall of the classification model. The F1 score is the harmonic mean of precision and recall, expressed mathematically as: F1 = 2 × precision × recall / (precision + recall). The F1 score ranges from 0 to 1, with larger values indicating better model performance. This metric is particularly useful in scenarios where both precision and recall are important.

[0093] AUC is the area under the ROC curve and the coordinate axes, and is used to evaluate the performance of a binary classification model. The ROC curve shows the relationship between the true positive rate (TPR) and the false positive rate (FPR) of a model at different thresholds. AUC values range from 0.5 to 1, with larger values indicating better model performance. The advantage of AUC is that it is not affected by the absolute value of the model's prediction score and focuses solely on ranking results, making it particularly suitable for ranking applications. Furthermore, AUC can provide a reasonable evaluation of classifiers even when the sample size is imbalanced.

[0094] Step S128: Selecting an initial security detection model from the multiple trained student models based on the performance indicators included in the training snapshot of each trained student model.

[0095] In one possible implementation, a performance indicator score can be calculated based on at least one performance indicator included in the training snapshot of each trained student model, and the trained student model with the highest performance indicator score is selected as the initial security detection model.

[0096] It is worth mentioning that when calculating the performance index score based on multiple performance indicators, different weight coefficients can be assigned to different myocardial infarction indicators to perform weighted summation of the scores corresponding to the multiple performance indicators to obtain the performance index score.

[0097] Considering that different student models have different model structures and corresponding complexities among multiple student models, the time spent on security testing for each student model is different. In order to ensure that the target security testing model obtained can guarantee the security testing results while effectively reducing the security testing time, in one embodiment, the above step S128 includes:

[0098] Step S128a: Obtain the model structure complexity of the trained student model according to the model structure of the trained student model.

[0099] The model structural complexity reflects the computational cost and resource requirements of the model. The model structural complexity can be expressed by the number of parameters, number of layers, number of neurons per layer, connection method, and operation type. In other words, the model structural complexity can be determined based on one or more of the following: the number of parameters, number of layers, number of neurons per layer, connection method, and operation type of the trained student model.

[0100] In one embodiment, if the pruning method of the present application is to prune the attention heads, the model structure complexity can be determined according to the number of remaining attention heads. The greater the number of remaining attention heads, the higher the corresponding model structure complexity.

[0101] Step S128b: Obtain a score for each trained student model based on the performance indicators and model structure complexity of each trained student model.

[0102] Among them, the performance index is positively correlated with the final score, and the model structure complexity is negatively correlated with the final score.

[0103] Step S128c: Select the trained student model with the highest score from multiple trained student models as the initial security detection model.

[0104] By adopting the above steps S127-S128, the teacher model or large language model is subjected to multiple random pruning processes to generate multiple student models, and these student models are trained using the teacher model and the first sample set, and multiple trained student models can be obtained. This not only increases the diversity of model selection, but also enables the selection of the initial security detection model that best suits the specific task requirements. Furthermore, by adopting the above steps S128a-S128c, the performance indicators and model structure complexity of each trained student model are combined to evaluate and select the student model with the highest score as the initial security detection model. This comprehensive consideration method can balance the performance and resource consumption of the model, ensuring that the selected model is both efficient and reliable in actual deployment.

[0105] In one embodiment, before executing step S130, the method may include selecting a second sample set from the first sample set based on the predicted detection results of each network sample traffic data in the first sample set during the fine-tuning training process or the student model training process, the second sample set including specified sample security data, and the sample label of the specified sample safety data is inconsistent with its predicted detection results during the student model training or fine-tuning training process.

[0106] In one possible implementation, if the second sample set only includes specified sample security data, the above steps can specifically be: based on the predicted detection results of each network sample traffic data in the first sample set during the fine-tuning training process or the student model training process, obtain the specified sample security data from the first sample set, and construct a second sample set including the specified sample security data.

[0107] It is worth mentioning that since the predicted detection result is a soft label generated after processing by the softmax function, if the category with the largest probability value in the soft label of the sample safety data is inconsistent with the sample label of the sample safety data, it indicates that the sample label of the sample safety data is inconsistent with its predicted detection result during the training or fine-tuning training of the student model.

[0108] If the second sample set also includes other sample safety data in addition to the specified sample safety data, please refer to Figure 8In one embodiment, in another embodiment, before executing step S120, the method further includes:

[0109] Step S150: obtaining designated sample security data from the first sample set according to the prediction detection results of each network sample traffic data in the first sample set during the fine-tuning training process or the student model training process.

[0110] Step S160: Select target sample safety data from the first sample set, the target sample safety data having a similarity with the designated sample safety data greater than a preset similarity threshold.

[0111] Specifically, similarity calculations can be performed on the other sample safety data in the first sample set except the designated sample safety data with each designated sample safety data to obtain the similarity between each designated sample safety data and each other sample safety data, thereby obtaining target sample safety data whose similarity with the designated sample safety data is greater than a preset similarity threshold.

[0112] When similarity calculation is performed, cosine similarity or Euclidean distance may be used to calculate the similarity, etc. The above-mentioned preset similarity threshold may be set according to actual needs and is not specifically limited here.

[0113] Step S170: Constructing a second sample set including the designated sample safety data and the target sample safety data.

[0114] Specifically, the designated sample safety data and the target sample safety data may be added to a set (eg, an empty set, or a set storing sample safety data different from the first sample set) to obtain a second sample set.

[0115] By adopting the above steps S150-S170, it is possible to obtain samples that are predicted incorrectly or difficult to classify during the model iteration process (i.e., specified sample safety data) from the first sample set, and find target sample safety data with similar characteristics to these samples through similarity calculation, thereby expanding the diversity of sample safety data in the second sample set, enabling the target safety detection model to learn a wider range of feature representations, avoiding overfitting while improving the robustness and accuracy of the overall model.

[0116] See also Figure 9 As shown, another embodiment of the present application provides a security detection method, which can be applied to an electronic device, which can be a server, a gateway device, etc. The method includes:

[0117] Step S210: Acquire data to be detected.

[0118] The data to be detected may be any network traffic data that needs to be security-tested.

[0119] Step S220: Perform security detection on the data to be detected using the target security detection model to obtain a detection result.

[0120] The target security detection model is trained using the security detection model training method described in the aforementioned embodiment. For details on the process of obtaining the target security detection model, please refer to the detailed description of steps S110-S170 in the aforementioned embodiment, which will not be repeated here. By adopting the above method, it is possible to quickly and accurately detect the data to be detected.

[0121] To ensure the reliability of the final target security detection model during actual security testing, the aforementioned test data can be network traffic data from a grayscale test set. Grayscale test sets are typically historical traffic data extracted from actual production environments to simulate model performance in real-world scenarios. This historical traffic data may contain various anomalies and edge cases, making it particularly important for evaluating the model's robustness and generalization capabilities.

[0122] Because grayscale test sets are typically large, offline evaluation is necessary. This involves first loading the grayscale test set, then performing predictions on each piece of historical traffic data within each grayscale test set and calculating the corresponding evaluation metrics. The target model's performance on the grayscale test set is then compared with the historical model or baseline model. This further validates the model's improvements and identifies potential issues.

[0123] In one possible implementation, the security detection model is deployed on a grayscale release platform, and the above step S210 may specifically be obtaining the data to be detected allocated by the grayscale release platform to the target security detection model.

[0124] Gray release is a crucial phase before software or models are released online. It allows developers to gradually roll out a new version or model to a small subset of users without impacting the majority of users, allowing them to collect feedback, monitor performance, and assess impact. In the context of machine learning models, this process is particularly important when deploying the best student model to a gray release platform for grayscale testing.

[0125] By deploying the target security detection model to the grayscale release platform, and using the target security detection model and manual comparison through about 3 to 4 days of grayscale data, we can finally draw a conclusion on the effectiveness of the target security detection model.

[0126] The new model undergoes a comprehensive evaluation. This involves considering multiple factors, including model performance, business impact, and user feedback, and weighing the pros and cons to arrive at an evaluation result. Based on the evaluation results, a decision is made as to whether to roll out the new model to all users. If the new model performs poorly, further tuning or a fallback to the old model may be necessary. If the new model performs well, a detailed rollout plan can be developed, and the new model can be gradually rolled out to all users.

[0127] It should be understood that, although the steps in the flowcharts of the above embodiments are shown in sequence as indicated by the arrows, these steps are not necessarily performed in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and these steps can be performed in other orders. Moreover, at least a portion of the steps in the flowcharts of the above embodiments may include multiple steps or multiple stages, and these steps or stages are not necessarily performed at the same time, but can be performed at different times. The execution order of these steps or stages is not necessarily to be performed in sequence, but can be performed in turn or alternately with other steps or at least a portion of steps or stages in other steps.

[0128] See also Figure 10 Another embodiment of the present application provides a training device 300 for a security detection model, and the training device 300 for the security detection model includes: a model acquisition module 310, a first training module 320 and a second training module 330; the model acquisition module 310 is used to obtain a teacher model and a student model, the teacher model is obtained by fine-tuning a large language model using sample security data in a first sample set, and the student model is obtained by pruning the teacher model or the large language model; the first training module 320 is used to train the student model using the teacher model and the first sample set to obtain an initial security detection model; the second training module 330 is used to train the initial security detection model using a second sample set to obtain a target security detection model, the second sample set includes specified sample security data, the specified sample security data is selected from the first sample set, and the sample label corresponding to the specified sample security data is inconsistent with its predicted detection result during the fine-tuning training process or the student model training process.

[0129] In one possible implementation, the training device of the security detection model also includes a first selection module, a second selection module and a sample set construction module; the first selection module is used to obtain specified sample security data from the first sample set based on the predicted detection results of each network sample traffic data in the first sample set during the fine-tuning training process or the student model training process; the second selection module is used to select target sample security data from the first sample set whose similarity with the specified sample security data is greater than a preset similarity threshold; the sample set construction module is used to construct a second sample set including the specified sample security data and the target sample security data.

[0130] In one embodiment, the model acquisition module 310 is further configured to perform multiple random pruning operations on the teacher model or the large language model to obtain multiple student models. The first training module 320 includes a training submodule and a model selection submodule. The training submodule is configured to train the multiple student models using the teacher model and the first sample set to obtain multiple trained student models and training snapshots of each trained student model. The model selection submodule is configured to select an initial security detection model from the multiple trained student models based on the performance indicators included in the training snapshots of each trained student model.

[0131] In one embodiment, the large language model includes multiple attention heads, and the model acquisition module 310 is further used to perform multiple random pruning processes on the attention heads of the teacher model or the large language model to obtain multiple student models, wherein each time the random pruning process is performed, at least one attention head of the teacher model or the large language model is pruned to obtain a student model.

[0132] In one possible implementation, the model selection submodule is also used to obtain the model structure complexity of the trained student model based on the model structure of the trained student model; obtain the score of each trained student model based on the performance indicators and model structure complexity of each trained student model; and select the trained student model with the highest score from multiple trained student models as the initial security detection model.

[0133] In one embodiment, the first training module 320 also includes a first detection submodule, a second detection submodule, a prediction loss acquisition submodule, a distillation loss acquisition submodule, a model loss acquisition submodule and a parameter adjustment submodule; the first detection submodule is used to use the teacher model to perform security detection on the sample safety data in the first sample set to obtain a first security detection result; the second detection submodule is used to use the student model to perform security detection on the sample safety data in the first sample set to obtain a second security detection result; the prediction loss acquisition submodule is used to obtain the prediction loss based on the second security detection result and the sample label of the sample safety data; the distillation loss acquisition submodule is used to obtain the distillation loss based on the first security detection result and the second security detection result of the sample safety data; the model loss acquisition submodule is used to perform a weighted sum of the prediction loss and the distillation loss to obtain the model loss of the student model; the parameter adjustment submodule is used to adjust the student model based on the model loss of the student model to obtain an initial security detection model.

[0134] See also Figure 11 As shown, another embodiment of the present application provides a security detection device 400, which includes: a detection data acquisition module 410, used to obtain the data to be detected; a detection result acquisition module 420, used to perform security detection on the data to be detected using a target security detection model obtained by a training device of a security detection model to obtain a detection result.

[0135] In one possible implementation, the security detection model is deployed on a grayscale release platform, and the detection data acquisition module 410 is further configured to acquire the to-be-detected data allocated by the grayscale release platform to the target security detection model.

[0136] Each module in the above-mentioned device can be implemented in whole or in part by software, hardware, or a combination thereof. Each of the above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory in the computer device in the form of software, so that the processor can call and execute the operations corresponding to each of the above modules. It should be noted that the device embodiment in this application corresponds to the aforementioned method embodiment. The specific principles in the device embodiment can be found in the contents of the aforementioned method embodiment, which will not be repeated here.

[0137] The following will be combined Figure 12 An electronic device 100 provided in this application is described.

[0138] See also Figure 12 Based on the method provided in the above embodiment, the embodiment of the present application also provides another electronic device 100 including a processor 102 that can execute the above method. The electronic device 100 can be a server or a terminal device.

[0139] The electronic device 100 further includes a memory 104 . The memory 104 stores a program capable of executing the contents of the aforementioned embodiments, and the processor 102 can execute the program stored in the memory 104 .

[0140] The processor 102 may include one or more cores for processing data and a message matrix unit. The processor 102 utilizes various interfaces and circuits to connect various components within the electronic device 100. It executes instructions, programs, code sets, or instruction sets stored in the memory 104, and accesses data stored in the memory 104 to perform various functions and process data within the electronic device 100. Optionally, the processor 102 may be implemented using at least one of the following hardware forms: a digital signal processing (DSP), a field-programmable gate array (FPGA), or a programmable logic array (PLA). The processor 102 may integrate one or a combination of a central processing unit (CPU), a graphics processing unit (GPU), and a modem. The CPU primarily processes the operating system, user interface, and application programs; the GPU is responsible for rendering and drawing display content; and the modem handles wireless communications. It is understood that the modem may not be integrated into the processor 102 and may be implemented separately via a communication chip.

[0141] The memory 104 may include a random access memory (RAM) or a read-only memory (ROM). The memory 104 may be used to store instructions, programs, codes, code sets, or instruction sets. The memory 104 may include a program storage area and a data storage area, wherein the program storage area may store instructions for implementing an operating system, instructions for implementing at least one function, instructions for implementing the various method embodiments described below, and the like. The data storage area may also store data (e.g., parking location, environmental information, and images) acquired by the electronic device 100 during use.

[0142] The electronic device 100 may also include a network module and a screen. The network module is used to receive and send electromagnetic waves, realize the mutual conversion between electromagnetic waves and electrical signals, and thus communicate with a communication network or other devices, such as communicating with an audio playback device. The network module may include various existing circuit components for performing these functions, such as an antenna, a radio frequency transceiver, a digital signal processor, an encryption / decryption chip, a user identity module (SIM) card, a memory, and the like. The network module can communicate with various networks such as the Internet, an intranet, a wireless network, or communicate with other devices via a wireless network. The above-mentioned wireless network may include a cellular telephone network, a wireless local area network, or a metropolitan area network. The screen can display interface content and perform data interaction, such as displaying the aforementioned interface and triggering operations through the screen.

[0143] The embodiment of the present application also provides a structural block diagram of a computer-readable storage medium. The computer-readable storage medium stores program code, which can be called by a processor to execute the method described in the above method embodiment.

[0144] The computer-readable storage medium may be an electronic memory such as a flash memory, an EEPROM (Electrically Erasable Programmable Read-Only Memory), an EPROM, a hard disk, or a ROM. Alternatively, the computer-readable storage medium includes a non-transitory computer-readable storage medium. The computer-readable storage medium has storage space for program codes for executing any of the method steps described above. These program codes can be read from or written to one or more computer program products. The program codes can be compressed, for example, in an appropriate form.

[0145] The present application also provides a computer program product or computer program, which includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the methods described in the various optional implementations described above.

[0146] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present application.

Claims

1. A training method for a security detection model, characterized in that: The method comprises: Obtaining a teacher model and a student model, wherein the teacher model is obtained by fine-tuning the large language model using the sample safety data in the first sample set, and the student model is obtained by pruning the teacher model or the large language model; Training the student model using the teacher model and the first sample set to obtain an initial security detection model; The initial security detection model is trained using a second sample set to obtain a target security detection model. The second sample set includes specified sample safety data, which is selected from the first sample set, and the sample label corresponding to the specified sample safety data is inconsistent with its predicted detection result during fine-tuning training or student model training.

2. The method according to claim 1, characterized in that Before training the initial security detection model using the second sample set to obtain the target security detection model, the method further includes: Obtaining designated sample safety data from the first sample set according to prediction detection results of each sample safety data in the first sample set during fine-tuning training or during student model training; Selecting target sample safety data from the first sample set, the target sample safety data having a similarity greater than a preset similarity threshold to the designated sample safety data; A second sample set including the designated sample safety data and the target sample safety data is constructed.

3. The method according to claim 1, characterized in that The obtaining of the student model comprises: Performing multiple random pruning processes on the teacher model or the large language model to obtain multiple student models; The method of training the student model using the teacher model and the first sample set to obtain an initial security detection model includes: Training a plurality of student models using the teacher model and the first sample set, obtaining a plurality of trained student models and a training snapshot of each trained student model; An initial security detection model is selected from the plurality of trained student models based on performance metrics included in the training snapshot of each trained student model.

4. The method according to claim 1, wherein The method of training the student model using the teacher model and the first sample set to obtain an initial security detection model includes: Performing a security check on the sample security data in the first sample set using the teacher model to obtain a first security check result; Using the student model to perform security testing on the sample security data in the first sample set, and obtaining a second security testing result; Obtaining a predicted loss based on a second safety detection result of the sample safety data and a sample label; Obtaining a distillation loss based on a first safety test result and a second safety test result of the sample safety data; Performing a weighted summation of the prediction loss and the distillation loss to obtain the model loss of the student model; The student model is adjusted based on the model loss of the student model to obtain an initial security detection model.

5. A safety detection method, characterized in that: The method comprises: Obtain the data to be tested; A target security detection model is used to perform security detection on the data to be detected to obtain a detection result, wherein the target security detection model is obtained by the training method of the security detection model described in any one of claims 1-6.

6. The method according to claim 5, characterized in that The security detection model is deployed on the grayscale release platform, and the acquisition of the data to be detected includes: Obtain the data to be tested that is allocated by the grayscale release platform to the target security detection model.

7. A training device for a safety detection model, characterized in that: The device comprises: A model acquisition module, configured to acquire a teacher model and a student model, wherein the teacher model is obtained by fine-tuning a large language model using sample safety data in the first sample set, and the student model is obtained by pruning the teacher model or the large language model; A first training module is used to train the student model using the teacher model and the first sample set to obtain an initial security detection model; The second training module is used to train the initial security detection model using a second sample set to obtain a target security detection model. The second sample set includes specified sample safety data, which is selected from the first sample set, and the sample label corresponding to the specified sample safety data is inconsistent with its predicted detection result during the fine-tuning training process or the student model training process.

8. An electronic device, characterized in that: include: one or more processors; Memory; One or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the one or more processors, and the one or more programs are configured to perform the method according to any one of claims 1-6 or 7-8.

9. A computer-readable storage medium, characterized in that The computer-readable storage medium stores program code, and the program code can be called by a processor to execute the method according to any one of claims 1 to 4 or 5 to 6.

10. A computer program product comprising a computer program / instructions, characterized in that When the computer program / instructions are executed by a processor, the steps of the method according to any one of claims 1 to 4 or 5 to 6 are implemented.

Citation Information

Patent Citations

  • Security detection method and device, computer equipment and storage medium

    CN119583080A

  • System, Method, and Computer Program Product for Incorporating Knowledge from More Complex Models in Simpler Models

    US20200226476A1