Software vulnerability assessment method based on continuous learning

By adopting a continuous learning method in software vulnerability assessment, combining source code and vulnerability description, using pre-trained models for prompt fine-tuning, and preventing forgetting through early stop strategy and EWC loss function, the vulnerabilities in the existing technology are solved. The prediction of inaccurate and forgetfulness achieves more accurate and stable prediction of vulnerability severity.

CN119026138AActive Publication Date: 2024-11-26NANTONG UNIV

Patent Information

Application Number
CN202411106268.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-13
Publication Date
2024-11-26
Estimated Expiration
2044-08-13

AI Technical Summary

Technical Problem

Existing software vulnerability assessment methods are difficult to effectively integrate source code and vulnerability description, resulting in inaccurate prediction of vulnerability severity, and traditional models are prone to catastrophic forgetting when facing new tasks.

Method used

Using a continuous learning-based approach, the source code and vulnerability description are input into the pre-trained model CodeT5 by designing a mixed prompt template for training, the natural language output is mapped to specific categories using mapping methods, and early stop strategy and EWC loss function are used to prevent it. Disaster forgetting, building the optimal software vulnerability severity prediction model.

Benefits of technology

More accurate and efficient software vulnerability severity prediction is achieved, reducing the model's forgetting of old task data and improving stability and reliability under real projects.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119026138A_ABST
    Figure CN119026138A_ABST
Patent Text Reader

Abstract

The invention provides a software vulnerability assessment method based on continuous learning, and belongs to the technical field of software engineering. The technical problem that the evaluation precision is reduced due to catastrophic forgetting when the dynamic data flow is dealt with is solved. According to the technical scheme, the method comprises the following steps: (1) collecting and processing a data set related to vulnerability severity prediction, and dividing the data set into several tasks; (2) replaying the number of old tasks by using the model confidence; (3) fusing source codes and vulnerability descriptions, and inputting the fused source codes and vulnerability descriptions into CodeT5 for model and prompt template training; (4) introducing an EWC regularization item, and ensuring that parameters do not have large deviation when a new task is trained; and (5) fusing the source code and the vulnerability description by means of a mixed prompt template, inputting the model and completing the prediction of the severity. The method has the advantages that by means of prompt fine adjustment and fusion of source codes and vulnerability description, vulnerability assessment is conducted according to dynamic data of real projects, and the problem of disastrous forgetting is relieved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of software engineering, and in particular to a software vulnerability assessment method based on continuous learning. Background Art

[0002] Software vulnerabilities can pose a serious threat to the security and reliability of computer systems and may cause significant economic losses. In particular, with the emergence of new technologies, the complexity of the Internet has increased, resulting in an increase in the frequency of vulnerabilities. However, due to the complexity of the software and limited repair resources, it is impossible to complete the repair of vulnerabilities in a short period of time. Therefore, it is necessary to identify high-risk vulnerabilities and fix them first.

[0003] The Common Vulnerability Scoring System is a general vulnerability assessment framework that considers all aspects of a vulnerability and generates a vulnerability severity score based on expert knowledge. Therefore, there is an urgent need for automated assessment tools or models to help software workers screen out which vulnerabilities need to be addressed.

[0004] To solve this problem, researchers use the information obtained to build a vulnerability assessment model to predict the severity of the vulnerability. Compared with the fine-tuning method based on pre-trained language models, traditional models are already behind. However, there are two problems if the pre-trained language model is used directly to carry out downstream tasks. On the one hand, it is challenging for pre-trained language models to learn sample-specific knowledge, and on the other hand, fine-tuning requires a large amount of data to perform well. Later, the emergence of prompt learning alleviated the above problems. In addition, existing research basically only predicts one type of information (source code or vulnerability description), and cannot fully mine vulnerability information. Therefore, it is necessary to study a more advanced software vulnerability severity prediction method that integrates source code and vulnerability description to better solve the problem of software vulnerability assessment.

[0005] How to solve the above technical problems becomes the subject faced by the present invention. Summary of the invention

[0006] The purpose of the present invention is to provide a software vulnerability assessment method based on continuous learning, which can predict the severity of software vulnerabilities.

[0007] The idea of ​​the present invention is: a software vulnerability assessment method based on continuous learning proposed in the present invention constructs a bimodal input of source code and vulnerability description through a designed hybrid prompt template, designs a mapping method, adds mapping words corresponding to categories, inputs the bimodal information into a pre-trained model CodeT5 for training, maps the natural language output of the model to specific categories through the constructed mapping method, constructs an optimal software vulnerability severity prediction model by comparing performance changes and using an early stopping strategy, thereby performing software vulnerability assessment more accurately and efficiently.

[0008] The present invention is implemented by the following measures: a software vulnerability assessment method based on continuous learning, which includes the following steps:

[0009] (1) By mining the CVE vulnerability database and actual software development projects based on the Git platform, we collect vulnerability-related data, including CVE ID, vulnerability code, vulnerability severity, vulnerability description, etc., and preprocess these data to construct a dataset D. The vulnerability severity includes types: LOW, MEDIUM, HIGH, and CRITICAL. The specific steps are as follows:

[0010] (1-1) By obtaining the CVE ID, vulnerability severity, and vulnerability description of the vulnerability in CVE, extract all code changes related to the vulnerability from the open source project based on the Git website, and extract the source code before modification;

[0011] (1-2) Preprocess the source code, including removing comments, blank lines, and pre-line comments, and finally form the vulnerability dataset D.

[0012] (2) Divide the data set. First, simulate dynamic learning in a continuous learning scenario to divide the data set tasks. Then, divide the data set of each task into training set, validation set, and test set in a ratio of 8:1:1. The division process uses a stratified sampling method to ensure that the distribution of vulnerability severity in the two sets is consistent.

[0013] (3) We use the model confidence-based replay method to replay the old task data set. Before each model training, we select the data from the old task for replay based on the model confidence and merge the replayed data with the current task data set to divide it into training set, validation set, and test set in a ratio of 8:1:1. The division process uses the stratified sampling method to ensure that the distribution of vulnerability severity in the two sets is consistent.

[0014] (3-1) We consider all datasets of each task before the current task and combine them into D train And train the model f.

[0015] (3-2) We calculate the training set D train For each sample x i Confidence level. i The confidence comes from the predicted probability of the model, and the maximum probability is taken as the confidence. The confidence formula is designed as follows:

[0016]

[0017] Where K is the number of categories, is the logit of class j, is xi logit of the predicted class, is the exponential sum of all categorical logits, used for normalization.

[0018] (3-3) We sort D according to the confidence score train Sort the samples in ascending order and get sorted samples Then, we select the N samples with the lowest confidence from the training set for replay, denoted as D replay Finally, we will train the current task Combined with selected low confidence samples, as follows:

[0019]

[0020] (4) For the data set processed in step (3), extract the source code and vulnerability description, combine them with the hybrid prompt template we constructed to form a new input, input it into the pre-trained model CodeT5, and use the prompt fine-tuning to train the software vulnerability severity prediction model and the hybrid prompt template. The specific steps include the following:

[0021] (4-1) Construct a prompt template: Use hard prompts to distinguish source code and vulnerability descriptions, adding "The codesnippet:" and "The vulnerability description:" respectively. For severity classification, use the [SOFT] tag to create soft prompts, initialize it to "Classify the severity:" during training, and use the [MASK] tag to predict or fill in missing information;

[0022] (4-2) Construct a mapping method: Map the natural language output of the model to specific categories. If the output is "low" or "slight", it is mapped to LOW; if it is "medium" or "moderate", it is mapped to MEDIUM; if it is "high" or "severe", it is mapped to HIGH; if it is "critical" or "significant", it is mapped to CRITICAL;

[0023] (4-3) Input the bimodal information into the pre-trained model CodeT5 for prompt fine-tuning and mixed prompt template training.

[0024] (5) The EWC loss function is used in model training. When training a new task, the model parameters (weights) are restricted to a position close to the optimal parameters of the previous task, ensuring that the learning process of the new task does not significantly change the parameters that are critical to the old task, thereby alleviating catastrophic forgetting.

[0025] (5-1) We use the traditional stochastic gradient descent (SGD) method to train the neural network model and the initial task model. During the training process, the data will be randomly shuffled and processed in small batches. After completing the training of the initial task, we save the trained model parameters.

[0026] (5-2) Calculate the Fisher information matrix to quantify the importance of each parameter to the initial task. We use the training data A to calculate the Fisher information matrix item of each parameter. Specifically, the Fisher information matrix item I(θ) is calculated by calculating the loss function of each parameter θ The gradient of , and taking the squared expected value of these gradients, the formula is:

[0027]

[0028] In practice, this is often approximated by computing the average of the squared gradients over the training data:

[0029]

[0030] in is the log-likelihood loss function.

[0031] (5-3) After calculating the Fisher information matrix and the importance weights of each parameter, these will be saved for use in subsequent tasks. When training a new task, we use a loss function with a regularization term to ensure that the model parameters do not deviate too much from the parameters of the initial task. EWC prevents catastrophic forgetting by adding a penalty term to the loss function. This regularization term is weighted according to the Fisher information matrix. The formula of the loss function is defined as follows:

[0032]

[0033] Where L B (θ) is the loss function of the current task, λ is a hyperparameter used to balance the importance of new tasks and old tasks, and F i is the Fisher information matrix of the i-th parameter, θ i is the i-th parameter of the current task, is the i-th parameter trained in the initial task. This formula adds a penalty term during the training of the new task to prevent the model parameters from deviating from the optimal parameters learned in the previous task.

[0034] (6) During the model training process, the early stopping strategy is used. If the index of the validation set drops for 10 consecutive times, the training is stopped to prevent overfitting problems. The constructed optimal software vulnerability severity prediction model and the corresponding prompt template are returned. The specific steps include the following:

[0035] (6-1) Calculate the change in the F1 indicator value of the model on the validation set.

[0036] (6-2) When the F1 value does not exceed the current best performance for 10 consecutive rounds, the training is stopped and the best vulnerability severity prediction model and hybrid prompt template are returned.

[0037] (7) For the software vulnerability that needs to be evaluated, the source code and description of the vulnerability can be extracted, fused with the trained mixed prompt template P, and finally input into the software vulnerability severity prediction model M constructed above to complete the severity prediction of the target software vulnerability.

[0038] (7-1) Extract the source code and vulnerability description of the vulnerability to be evaluated, and fuse them with the trained hybrid prompt template P;

[0039] (7-2) Input the fused data into the trained prediction model M to generate output in natural language form;

[0040] (7-3) Map the natural language results output by the model into specific severity levels and return the final prediction results.

[0041] Compared with the prior art, the beneficial effects of the present invention are as follows: a software vulnerability assessment method based on continuous learning proposed in the present invention takes the bimodal information fusion of vulnerability source code and vulnerability description as input, uses an advanced pre-trained language model and performs prompt fine-tuning, and considers the usage scenarios of continuous learning, so as to better mine vulnerability information and classify the severity of vulnerabilities more accurately and reliably, while at the same time alleviating to a certain extent the catastrophic forgetting problem of the model caused by the increase of data changing over time in real projects. BRIEF DESCRIPTION OF THE DRAWINGS

[0042] The accompanying drawings are used to provide further understanding of the present invention and constitute a part of the specification. They are used to explain the present invention together with the embodiments of the present invention and do not constitute a limitation of the present invention.

[0043] Figure 1 A system framework diagram of a software vulnerability assessment method based on continuous learning provided by the present invention. DETAILED DESCRIPTION

[0044] In order to make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. Of course, the specific embodiments described here are only used to explain the present invention and are not used to limit the present invention.

[0045] Example 1

[0046] This embodiment provides a technical solution, a software vulnerability assessment method based on continuous learning, see Figure 1 As shown, the present invention provides a software vulnerability assessment method based on continuous learning, which specifically includes the following contents:

[0047] (1) By mining the CVE vulnerability database and actual software development projects based on the Git platform, we collect vulnerability-related data, including CVE ID, vulnerability code, vulnerability severity, vulnerability description, etc., and preprocess these data to construct a dataset D. The vulnerability severity includes types: LOW, MEDIUM, HIGH, and CRITICAL. The specific steps are as follows:

[0048] (1-1) By obtaining the CVE ID, vulnerability severity, and vulnerability description of the vulnerability in CVE, extract all code changes related to the vulnerability from the open source project based on the Git website, and extract the source code before modification;

[0049] (1-2) Preprocess the source code, including removing comments, blank lines, and pre-line comments, and finally form the vulnerability dataset D.

[0050] (2) Divide the data set. First, simulate dynamic learning in a continuous learning scenario to divide the data set tasks. Then, divide the data set of each task into training set, validation set, and test set in a ratio of 8:1:1. The division process uses a stratified sampling method to ensure that the distribution of vulnerability severity in the two sets is consistent.

[0051] (3) We use the model confidence-based replay method to replay the old task data set. Before each model training, we select the data from the old task for replay based on the model confidence and merge the replayed data with the current task data set to divide it into training set, validation set, and test set in a ratio of 8:1:1. The division process uses the stratified sampling method to ensure that the distribution of vulnerability severity in the two sets is consistent.

[0052] (3-1) We consider all datasets of each task before the current task and combine them into D train And train the model f.

[0053] (3-2) We calculate the training set D train For each sample x i Confidence level. i The confidence comes from the predicted probability of the model, and the maximum probability is taken as the confidence. The confidence formula is designed as follows:

[0054]

[0055] Where K is the number of categories, is the logit of class j, is x i logit of the predicted class, is the exponential sum of all categorical logits, used for normalization.

[0056] (3-3) We sort D according to the confidence score train Sort the samples in ascending order and get sorted samples Then, we select the N samples with the lowest confidence from the training set for replay, denoted as D replay Finally, we will train the current task Combined with selected low confidence samples, as follows:

[0057]

[0058] (4) For the data set processed in step (3), extract the source code and vulnerability description, combine them with the hybrid prompt template we constructed to form a new input, input it into the pre-trained model CodeT5, and use the prompt fine-tuning to train the software vulnerability severity prediction model and the hybrid prompt template. The specific steps include the following:

[0059] (4-1) Construct a prompt template: Use hard prompts to distinguish source code and vulnerability descriptions, adding "The codesnippet:" and "The vulnerability description:" respectively. For severity classification, use the [SOFT] tag to create soft prompts, initialize it to "Classify the severity:" during training, and use the [MASK] tag to predict or fill in missing information;

[0060] (4-2) Construct a mapping method: Map the natural language output of the model to specific categories. If the output is "low" or "slight", it is mapped to LOW; if it is "medium" or "moderate", it is mapped to MEDIUM; if it is "high" or "severe", it is mapped to HIGH; if it is "critical" or "significant", it is mapped to CRITICAL;

[0061] (4-3) Input the bimodal information into the pre-trained model CodeT5 for prompt fine-tuning and mixed prompt template training.

[0062] (5) The EWC loss function is used in model training. When training a new task, the model parameters (weights) are restricted to a position close to the optimal parameters of the previous task, ensuring that the learning process of the new task does not significantly change the parameters that are critical to the old task, thereby alleviating catastrophic forgetting.

[0063] (5-1) We use the traditional stochastic gradient descent (SGD) method to train the neural network model and the initial task model. During the training process, the data will be randomly shuffled and processed in small batches. After completing the training of the initial task, we save the trained model parameters.

[0064] (5-2) Calculate the Fisher information matrix to quantify the importance of each parameter to the initial task. We use the training data A to calculate the Fisher information matrix item of each parameter. Specifically, the Fisher information matrix item I(θ) is calculated by calculating the loss function of each parameter θ The gradient of , and taking the squared expected value of these gradients, the formula is:

[0065]

[0066] In practice, this is often approximated by computing the average of the squared gradients over the training data:

[0067]

[0068] in is the log-likelihood loss function.

[0069] (5-3) After calculating the Fisher information matrix and the importance weights of each parameter, these will be saved for use in subsequent tasks. When training a new task, we use a loss function with a regularization term to ensure that the model parameters do not deviate too much from the parameters of the initial task. EWC prevents catastrophic forgetting by adding a penalty term to the loss function. This regularization term is weighted according to the Fisher information matrix. The formula of the loss function is defined as follows:

[0070]

[0071] Where L B (θ) is the loss function of the current task, λ is a hyperparameter used to balance the importance of new tasks and old tasks, and F i is the Fisher information matrix of the i-th parameter, θ i is the i-th parameter of the current task, is the i-th parameter trained in the initial task. This formula adds a penalty term during the training of the new task to prevent the model parameters from deviating from the optimal parameters learned in the previous task.

[0072] (6) During the model training process, the early stopping strategy is used. If the index of the validation set drops for 10 consecutive times, the training is stopped to prevent overfitting problems. The constructed optimal software vulnerability severity prediction model and the corresponding prompt template are returned. The specific steps include the following:

[0073] (6-1) Calculate the change in the F1 indicator value of the model on the validation set.

[0074] (6-2) When the F1 value does not exceed the current best performance for 10 consecutive rounds, the training is stopped and the best vulnerability severity prediction model and hybrid prompt template are returned.

[0075] (7) For the software vulnerability that needs to be evaluated, the source code and description of the vulnerability can be extracted, fused with the trained mixed prompt template P, and finally input into the software vulnerability severity prediction model M constructed above to complete the severity prediction of the target software vulnerability.

[0076] (7-1) Extract the source code and vulnerability description of the vulnerability to be evaluated, and fuse them with the trained hybrid prompt template P;

[0077] (7-2) Input the fused data into the trained prediction model M to generate output in natural language form;

[0078] (7-3) Map the natural language results output by the model into specific severity levels and return the final prediction results.

[0079] (8) The proposed method is compared with existing software vulnerability assessment methods on the same data set, and two performance indicators (i.e., F1 source and MCC) from the field of software vulnerability assessment research are used to automatically evaluate the quality of the model:

[0080] Table 1 Comparison of results between the method of the present invention and other methods

[0081]

[0082] Experiments show that the software vulnerability assessment method based on continuous learning proposed in the present invention has higher F1 score and MCC than the baseline method, so it can make more reliable and accurate predictions of the severity of software vulnerabilities. Specifically, the method of the present invention uses a continuous learning method based on model confidence and EWC, which integrates source code and vulnerability descriptions. Compared with the baseline, it can better mine vulnerability information while reducing the forgetting of old task data, which is a more advanced method. Among them, for F1 score, the method of the present invention is higher than the CWM with the highest performance. XGBImproved performance by 8%; for MCC, the method of the present invention is better than Fun LGBM The performance is improved by 12%. These results show the competitiveness of the proposed method.

[0083] Example 2

[0084] On the basis of Example 1, different regularization methods are used to compare the method of the present invention with different regularization methods, and two performance indicators (i.e., F1 source and MCC) from the field of software vulnerability assessment research are used to automatically evaluate the quality of the model:

[0085] Table 2 Comparison of results of the method of the present invention and other methods

[0086]

[0087] Experiments have shown that the software vulnerability assessment method based on continuous learning proposed in the present invention has the highest F1 score and MCC compared to other regularization methods, so it can make more reliable and accurate predictions of the severity of software vulnerabilities. For F1 score, the method of the present invention is 15% and 9% higher than the model using Rwalk and SI as regularization methods, respectively; for MCC, the method of the present invention is 19% and 12% higher than the model using Rwalk and SI as regularization methods, respectively. These results show the competitiveness of the method proposed in the present invention.

[0088] Example 3

[0089] On the basis of Example 1, different playback methods are used to compare the method of the present invention with the method using random playback as playback, and two performance indicators (i.e., F1 source and MCC) from the field of software vulnerability assessment research are used to automatically evaluate the quality of the model:

[0090] Table 3 Comparison of results of the method of the present invention and other methods

[0091]

[0092] Experiments show that the software vulnerability assessment method based on continuous learning proposed by the present invention has the highest F1 score and MCC compared to the method using random playback as playback, so it can make more reliable and accurate predictions of the severity of software vulnerabilities. For F1 score, the method of the present invention is 4% higher than the method using random playback as playback; for MCC, the method of the present invention is 10% higher than the method using random playback as playback. These results show the competitiveness of the method proposed by the present invention.

[0093] Example 4

[0094] On the basis of Example 1, the weight parameter λ of the EWC of the present invention is changed, and the method of the present invention is compared with the method using different λ. Two performance indicators (i.e., F1 source and MCC) from the field of software vulnerability assessment research are used to automatically evaluate the quality of the model:

[0095] Table 4 Comparison of results of the method of the present invention and other methods

[0096]

[0097] Experiments have shown that the software vulnerability assessment method based on continuous learning proposed in the present invention has the highest F1 score and MCC compared to the method using other λ as a parameter, so it can make more reliable and accurate predictions of the severity of software vulnerabilities. For F1 score, the method of the present invention is up to 9% higher than that using other λ as a parameter; for MCC, the method of the present invention is up to 14% higher than that using other λ as a parameter. These results show the competitiveness of the method proposed in the present invention.

[0098] Example 5

[0099] On the basis of Example 1, the amplification size rs based on the model confidence of the present invention is changed, and the method of the present invention is compared with the methods using different rs. Two performance indicators (i.e., F1source and MCC) from the field of software vulnerability assessment research are used to automatically evaluate the quality of the model:

[0100] Table 5 Comparison of results of the method of the present invention and other methods

[0101]

[0102]

[0103] Experiments show that the software vulnerability assessment method based on continuous learning proposed by the present invention has the highest F1 score and MCC compared to the method using other rs as parameters, so it can make more reliable and accurate predictions of the severity of software vulnerabilities. For F1 score, the method of the present invention is up to 3% higher than that using other rs as parameters; for MCC, the method of the present invention is up to 5% higher than that using other rs as parameters. These results show the competitiveness of the method proposed by the present invention.

[0104] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims

1. A software vulnerability assessment method based on continuous learning, characterized in that: The following steps are involved: (1) Through the Git-based software project hosting platform, the CVE vulnerability database and actual software development projects are mined to collect vulnerability-related data, including CVE ID, vulnerability code, vulnerability description, and vulnerability severity. These data are preprocessed to construct a dataset D. First, the CVE ID, vulnerability code, vulnerability severity, and vulnerability description of the vulnerability in CVE are obtained. Then, all code changes related to the vulnerability are extracted from the open source project based on the Git website, and the source code before modification is extracted. The source code is preprocessed, including removing comments, blank lines, and pre-line comments, and finally the vulnerability dataset D is formed. (2) Divide the data set. First, by simulating dynamic learning in a continuous learning scenario, the vulnerability data set D is divided according to tasks. Then, the data set of each task is divided into a training set, a validation set, and a test set in a ratio of 8:1:

1. The division process uses a stratified sampling method to ensure that the distribution of vulnerability severity in different sets is consistent. (3) For the current task, we use the model confidence-based replay method to replay the data set of the old task. Before each model training, we select the data from the old task for replay based on the model confidence and merge the replayed data with the data set of the current task to re-divide them into training set, validation set and test set in a ratio of 8:1:

1. The division process uses the stratified sampling method to ensure that the distribution of vulnerability severity in the two sets is consistent. (4) For the data set processed in step (3), extract the source code and vulnerability description, first build a prompt template, use hard prompts to distinguish the two types of information, source code and vulnerability description, for severity classification, use the [SOFT] tag to create soft prompts, and use the [MASK] tag to predict or fill in missing information, then build a mapping method, through which the natural language output of the model is mapped to a specific category; finally, input the constructed bimodal information into the pre-trained language model CodeT5, and use prompt fine-tuning to perform model training and hybrid prompt template training; (5) When training the model, for a new task, the parameter weights of the model are limited to a position close to the optimal parameters of the previous task, ensuring that the learning process of the new task does not significantly change the parameters that are critical to the old task, thereby alleviating catastrophic forgetting; (6) An early stopping strategy is adopted during model training to calculate the change in the F1 index value of the model on the validation set. If the validation set index decreases for 10 consecutive times, training is stopped to prevent overfitting problems. The optimal software vulnerability severity prediction model M and the corresponding hybrid prompt template P are returned; (7) For the software vulnerabilities that need to be evaluated, the source code and vulnerability description of the vulnerability are extracted, fused with the trained hybrid prompt template P, and finally input into the software vulnerability severity prediction model M constructed above to complete the severity prediction of the target software vulnerability.

2. A software vulnerability assessment method based on continuous learning according to claim 1, characterized in that: The step (3) specifically includes the following steps: (2-1) Consider all datasets of each task before the current task and combine them into D train And train the model f; (2-2) Calculate the training set D train For each sample x i The confidence level, x i The confidence comes from the predicted probability of the model. The maximum probability is taken as the confidence. The confidence formula is designed as follows: Where K is the number of categories, is the logit of class j, is x i logit of the predicted class, is the exponential sum of all category logits, used for normalization; (2-3) According to the confidence score, D train Sort the samples in ascending order and get sorted samples Then, select the N samples with the lowest confidence from the training set for replay, denoted as D replay Finally, the training set of the current task Combined with selected low confidence samples, as follows:

3. According to a method for software vulnerability assessment based on continuous learning according to claim 1, it is characterized in that: The step (4) specifically includes the following steps: (3-1) Construct a prompt template: Use hard prompts to distinguish source code and vulnerability descriptions, add "The codesnippet:" and "The vulnerability description:" respectively. For severity classification, use the [SOFT] tag to create soft prompts, initialize it to "Classify the severity:" during training, and use the [MASK] tag to predict or fill in missing information; (3-2) Construct a mapping method: Map the natural language output of the model to specific categories. If the output is "low" or "slight", it is mapped to LOW; if it is "medium" or "moderate", it is mapped to MEDIUM; if it is "high" or "severe", it is mapped to HIGH; if it is "critical" or "significant", it is mapped to CRITICAL; (3-3) Input the bimodal information into the pre-trained model CodeT5 for prompt fine-tuning and mixed prompt template training.

4. The software vulnerability assessment method based on continuous learning according to claim 1, characterized in that: The step (5) specifically includes the following steps: (4-1) Use the traditional stochastic gradient descent (SGD) method to train the neural network model and the initial task model. During the training process, the data will be randomly shuffled and processed in small batches. After completing the training of the initial task, the trained model parameters are saved. (4-2) Calculate the Fisher information matrix to quantify the importance of each parameter to the initial task. Use the training data A to calculate the Fisher information matrix item of each parameter. The Fisher information matrix item I(θ) is calculated by calculating the loss function of each parameter θ The gradient of , and taking the squared expected value of these gradients, the formula is: This is approximated by averaging the squared gradients of the training data: in is the log-likelihood loss function; (4-3) After calculating the Fisher information matrix and the importance weight of each parameter, they will be saved. When training a new task, a loss function with a regularization term is used to ensure that the model parameters do not deviate too much from the parameters of the initial task. EWC prevents catastrophic forgetting by adding a penalty term to the loss function. This regularization term is weighted according to the Fisher information matrix. The formula of the loss function is defined as follows: Where L B (θ) is the loss function of the current task, λ is a hyperparameter used to balance the importance of new tasks and old tasks, and F i is the Fisher information matrix of the i-th parameter, θ i is the i-th parameter of the current task, is the i-th parameter trained in the initial task. The formula adds a penalty term during the training of the new task to prevent the model parameters from deviating from the optimal parameters learned in the previous task.

5. The software vulnerability assessment method based on continuous learning according to claim 1, characterized in that: The step (6) specifically includes the following steps: (5-1) Calculate the F1 index change of the model on the validation set; (5-2) When the F1 value does not exceed the current best performance for 10 consecutive rounds, stop training and return the best vulnerability severity prediction model and hybrid prompt template.

6. The software vulnerability assessment method based on continuous learning according to claim 1, characterized in that: The step (7) specifically includes the following steps: (6-1) Extract the source code and vulnerability description of the vulnerability to be evaluated, and fuse them with the trained hybrid prompt template P; (6-2) Input the fused data into the trained prediction model M to generate output in natural language form; (6-3) Map the natural language results output by the model into specific severity levels and return the final prediction results.

Citation Information

Patent Citations

  • Method for determining defects and vulnerabilities in software code

    CN109416719A

  • Semi-supervised vulnerability assessment method based on code lexical and structural information fusion

    CN117556417A

  • Code vulnerability detection method based on code attribute graph learning

    CN118094561A

  • Source code vulnerability detection method and system based on large model

    CN118332557A

  • Source code vulnerability detection and repair through machine learning

    US20240028740A1

Cited By

  • Software vulnerability type identification method based on long-tail incremental learning

    CN119646822A

  • A Software Vulnerability Type Identification Method Based on Long-Tail Incremental Learning

    CN119646822B