Feature extraction model training method and device, storage medium and electronic equipment

By training the script language model using a phased learning strategy and weight pruning, the problem of the model's difficulty in extracting semantic features was solved, thereby improving the vulnerability identification effect and training efficiency.

CN119513607BActive Publication Date: 2025-12-12GUANGZHOU ZHONO ELECTRONICS TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411650546.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-11-18
Publication Date
2025-12-12
Estimated Expiration
2044-11-18

AI Technical Summary

Technical Problem

Existing scripting language models struggle to effectively extract semantic features in vulnerability detection, resulting in poor vulnerability identification performance.

Method used

A phased learning strategy is adopted to train the model, including the growth phase, synthesis phase, evaluation phase, pre-split phase, split phase, and dormancy phase. The model training process is optimized by combining weight pruning and improved generative adversarial network methods.

Benefits of technology

This improved the model's ability to identify scripting language vulnerabilities, reduced the risk of overfitting, and enhanced training efficiency and accuracy.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119513607B_ABST
    Figure CN119513607B_ABST
Patent Text Reader

Abstract

The application provides a feature extraction model training method and device, a storage medium and an electronic device. In the method, the electronic device obtains a sample script set; a current to-be-trained model is trained by a first learning strategy to extract features from the sample script set until the current to-be-trained model reaches a preset performance; the current to-be-trained model is trained by a second learning strategy to extract features from the sample script set; and the above steps are iterated until the current to-be-trained model meets an iteration stop condition as a feature extraction model. In this way, the training process of the model is divided into different stages, and different optimization strategies are adopted in each training stage, so that the model can more flexibly adapt to changes in training data to reduce the risk of overfitting, thereby effectively jumping out of a local optimal solution, and the trained feature extraction model can extract effective semantic features from scripts.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the field of neural networks, in particular to a feature extraction model training method and device, a storage medium and an electronic device. BACKGROUND

[0002] Script languages are widely welcomed for their convenient and efficient characteristics. They greatly simplify the programming process, enabling developers to quickly implement various functions with less code. At the same time, script languages usually have excellent automation and text processing capabilities. However, current script languages still have deficiencies in vulnerability detection, mainly manifested in limited detection coverage and low efficiency.

[0003] Taking TCL (Tool Command Language) scripts as an example. The scripts are widely used in digital back-end processing, such as layout, routing, timing analysis, etc., and their security and correctness directly affect the quality and reliability of the entire chip design. With the increasing complexity of integrated circuit design and the shortening of design cycle, traditional manual inspection methods cannot meet the rapid development needs. Therefore, a script vulnerability prediction method based on a neural network model is proposed in the related art.

[0004] However, it is found in practice that, as a weakly typed computer language, script languages, although providing certain grammatical constraints, have higher degrees of freedom compared to strongly typed computer languages. Therefore, the dynamic changes and complexity of scripts make it difficult to extract effective semantic features during model training, thereby affecting the recognition effect of the trained model on vulnerabilities in scripts. Therefore, there is an urgent need to provide a model training method for script languages to enable the model to learn effective semantic features from script languages. SUMMARY

[0005] To overcome at least one deficiency in the prior art, the present application provides a feature extraction model training method, device, storage medium and electronic device, specifically including:

[0006] In a first aspect, the present application provides a feature extraction model training method, the method comprising:

[0007] obtaining a sample script set;

[0008] training the current to-be-trained model to extract features from the sample script set by a first learning strategy until the current to-be-trained model reaches a preset performance;

[0009] training the current to-be-trained model to extract features from the sample script set by a second learning strategy;

[0010] iterating the above steps until the current to-be-trained model meets an iteration stop condition as the feature extraction model.

[0011] With reference to the optional implementation manner of the first aspect, the training of the current to-be-trained model from the sample script set by the first learning strategy until the current to-be-trained model reaches the preset performance comprises:

[0012] updating the current to-be-trained model at a first learning rate according to a first feature extraction loss obtained by processing the sample script set by the current to-be-trained model;

[0013] generating new weights for the current to-be-trained model according to existing weights of the current to-be-trained model;

[0014] iterating the above steps until the current to-be-trained model reaches the preset performance.

[0015] With reference to the optional implementation manner of the first aspect, the first learning rate comprises a preset base learning rate and a target acceleration coefficient, and the updating of the current to-be-trained model at the first learning rate according to the first feature extraction loss obtained by processing the sample script set by the current to-be-trained model comprises:

[0016] obtaining a descending speed and a curvature of a corresponding loss function according to the first feature extraction loss obtained by processing the sample script set by the current to-be-trained model;

[0017] obtaining the target acceleration coefficient according to the descending speed and the curvature;

[0018] updating the current to-be-trained model according to the base learning rate and the target acceleration coefficient.

[0019] With reference to the optional implementation manner of the first aspect, the training of the current to-be-trained model from the sample script set by the second learning strategy comprises:

[0020] obtaining a gradient of a corresponding loss function according to a second feature extraction loss obtained by processing the sample script set by the current to-be-trained model;

[0021] generating a fine-tuning parameter of the current to-be-trained model according to the gradient, and updating the current to-be-trained model by using the fine-tuning parameter;

[0022] performing weight pruning on the current to-be-trained model;

[0023] updating the current to-be-trained model at a second learning rate according to a third feature extraction loss obtained by processing the sample script set by the current to-be-trained model.

[0024] With reference to the optional implementation of the first aspect, the gradient comprises a weight gradient and a bias gradient, the fine-tuning parameter comprises a weight fine-tuning parameter and a bias fine-tuning parameter, and the generating the fine-tuning parameter of the current to-be-trained model according to the gradient comprises:

[0025] obtaining a first cosine value of a product between the weight gradient and a preset amplitude parameter;

[0026] determining a product between the first cosine value and a preset frequency parameter as the weight fine-tuning parameter;

[0027] obtaining a second cosine value of a product between the bias gradient and a preset amplitude parameter;

[0028] determining a product between the second cosine value and a preset frequency parameter as the bias fine-tuning parameter.

[0029] With reference to the optional implementation of the first aspect, the learning rate of the first learning strategy is greater than the learning rate of the second learning strategy.

[0030] With reference to the optional implementation of the first aspect, the sample script set comprises an extended sample generated by a sample expansion model, and the method further comprises:

[0031] obtaining an original script set;

[0032] obtaining a current gradient of a corresponding loss function according to a model loss obtained by processing the original script set in a current generative adversarial network;

[0033] updating the current generative adversarial network by a quasi-Newton method according to the current gradient and a historical gradient during a previous iteration;

[0034] iterating the above steps until the current generative adversarial network meets an iteration stop condition as a sample expansion model.

[0035] With reference to the optional implementation of the first aspect, the updating the current generative adversarial network by the quasi-Newton method according to the current gradient and the historical gradient during the previous iteration comprises:

[0036] calculating an approximate Hessian matrix of the quasi-Newton method according to the historical gradient;

[0037] adjusting the current gradient by the approximate Hessian matrix, and updating the current generative adversarial network according to the adjusted current gradient.

[0038] In a second aspect, the present application further provides a feature extraction model training device, the device comprising:

[0039] a sample obtaining module, configured to obtain a sample script set;

[0040] a model training module configured to train a current to-be-trained model to extract features from the sample script set by a first learning strategy until the current to-be-trained model reaches a preset performance;

[0041] train the current to-be-trained model to extract features from the sample script set by a second learning strategy;

[0042] iterate the above steps until the current to-be-trained model meets an iteration stop condition as the feature extraction model.

[0043] With reference to the optional implementation of the second aspect, the model training module is further configured to:

[0044] update the current to-be-trained model at a first learning rate according to a first feature extraction loss obtained by processing the sample script set by the current to-be-trained model;

[0045] generate new weights for the current to-be-trained model according to existing weights of the current to-be-trained model;

[0046] iterate the above steps until the current to-be-trained model reaches the preset performance.

[0047] With reference to the optional implementation of the second aspect, the first learning rate includes a preset base learning rate and a target acceleration coefficient, and the model training module is further configured to:

[0048] obtain a descending speed and a curvature of a corresponding loss function according to a first feature extraction loss obtained by processing the sample script set by the current to-be-trained model;

[0049] obtain the target acceleration coefficient according to the descending speed and the curvature;

[0050] update the current to-be-trained model according to the base learning rate and the target acceleration coefficient.

[0051] With reference to the optional implementation of the second aspect, the model training module is further configured to:

[0052] obtain a gradient of a corresponding loss function according to a second feature extraction loss obtained by processing the sample script set by the current to-be-trained model;

[0053] generate a fine-tuning parameter of the current to-be-trained model according to the gradient, and update the current to-be-trained model by using the fine-tuning parameter;

[0054] perform weight pruning on the current to-be-trained model;

[0055] update the current to-be-trained model at a second learning rate according to a third feature extraction loss obtained by processing the sample script set by the current to-be-trained model.

[0056] In combination with the optional implementation of the second aspect, the gradient comprises a weight gradient and a bias gradient, the fine-tuning parameter comprises a weight fine-tuning parameter and a bias fine-tuning parameter, and the model training module is further specifically configured to:

[0057] obtain a first cosine value of a product between the weight gradient and a preset amplitude parameter;

[0058] determine a product between the first cosine value and a preset frequency parameter as the weight fine-tuning parameter;

[0059] obtain a second cosine value of a product between the bias gradient and a preset amplitude parameter;

[0060] determine a product between the second cosine value and a preset frequency parameter as the bias fine-tuning parameter.

[0061] In combination with the optional implementation of the second aspect, the learning rate of the first learning strategy is greater than the learning rate of the second learning strategy.

[0062] In combination with the optional implementation of the second aspect, the sample script set comprises an extended sample generated by a sample augmentation model, and the method sample obtaining module is further configured to:

[0063] obtain an original script set;

[0064] The model training module is further configured to obtain a current gradient of a corresponding loss function according to a model loss obtained by processing the original script set in the current generative adversarial network;

[0065] update the current generative adversarial network by a quasi-Newton method according to the current gradient and a historical gradient during a previous iteration;

[0066] iterate the above steps until the current generative adversarial network meets an iteration stop condition as a sample augmentation model.

[0067] In combination with the optional implementation of the second aspect, the model training module is further specifically configured to:

[0068] calculate an approximate Hessian matrix of the quasi-Newton method according to the historical gradient;

[0069] adjust the current gradient by the approximate Hessian matrix, and update the current generative adversarial network according to the adjusted current gradient.

[0070] In a third aspect, the present application further provides a storage medium storing a computer program, which, when executed by a processor, implements the feature extraction model training method.

[0071] In a fourth aspect, the present application also provides an electronic device, which comprises a processor and a memory, and the memory stores a computer program, and the computer program, when executed by the processor, implements the feature extraction model training method.

[0072] Compared with the prior art, the present application has the following beneficial effects:

[0073] The present application provides a feature extraction model training method, device, storage medium and electronic device. In the method, an electronic device obtains a sample script set; a current to-be-trained model is trained by a first learning strategy to extract features from the sample script set until the current to-be-trained model reaches a preset performance; the current to-be-trained model is trained by a second learning strategy to extract features from the sample script set; and the above steps are iterated until the current to-be-trained model meets an iteration stop condition as a feature extraction model. In this way, the training process of the model is divided into different stages, and different optimization strategies are adopted in each training stage, so that the model can more flexibly adapt to changes in training data to reduce the risk of overfitting, thereby effectively jumping out of a local optimal solution, and the trained feature extraction model can extract effective semantic features from scripts. BRIEF DESCRIPTION OF DRAWINGS

[0074] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the following will briefly introduce the drawings needed to be used in the embodiments. It should be understood that the following drawings only show some embodiments of the present application, and therefore should not be regarded as a limitation on the scope, and for those skilled in the art, other related drawings can also be obtained without creative labor.

[0075] Figure 1 One of the flowcharts of the feature extraction model training method provided by the embodiments of the present application;

[0076] Figure 2 The second flowchart of the feature extraction model training method provided by the embodiments of the present application;

[0077] Figure 3 The training flowchart of the sample expansion model provided by the embodiments of the present application;

[0078] Figure 4 The structure diagram of the generative adversarial network provided by the embodiments of the present application;

[0079] Figure 5 The structure diagram of the feature extraction model training device provided by the embodiments of the present application;

[0080] Figure 6 The structure diagram of the electronic device provided by the embodiments of the present application. DETAILED DESCRIPTION

[0081] So that the objectives, technical solutions, and advantages of the embodiments of the present application are more apparent, the technical solutions in the embodiments of the present application will be described clearly and completely below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only some of the embodiments of the present application, rather than all the embodiments. The components of the embodiments of the present application described and shown in the drawings can be arranged and designed in various different configurations.

[0082] Therefore, the following detailed description of the embodiments of the present application provided in the drawings is not intended to limit the scope of the claimed present application, but only represents selected embodiments of the present application. All other embodiments obtained by those of ordinary skill in the art based on the embodiments in the present application without creative labor are within the scope of protection of the present application.

[0083] It should be noted that similar reference numerals and letters in the following drawings represent similar items, and therefore, once an item is defined in one drawing, it need not be further defined and explained in subsequent drawings.

[0084] In the description of the present application, it should be noted that the terms “first”, “second”, “third”, and the like are only used to distinguish descriptions, and cannot be understood as indicating or implying relative importance. In addition, the terms “include”, “contain” or any other variants thereof are intended to cover non-exclusive inclusion, so that the process, method, article or device including a series of elements not only includes those elements, but also includes other elements not explicitly listed or inherent to such process, method, article or device. Without more limitations, the element defined by the statement “including a…” does not exclude the presence of another identical element in the process, method, article or device including the element.

[0085] Based on the above statement, as introduced in the background, the dynamic change and complexity of the script make it difficult to extract effective semantic features in the model training process, thereby affecting the recognition effect of the trained model on the vulnerabilities in the script. Therefore, there is an urgent need to provide a model training method for script language so that the model can learn effective semantic features from the script language.

[0086] Based on the discovery of the above technical problems, the inventors have proposed the following technical solutions after creative labor to solve or improve the above problems. It should be noted that the defects in the above prior art solutions are the result of the inventors' careful research after practice, and therefore, the discovery process of the above problems and the solutions proposed by the embodiments of the present application to solve the above problems should be the contribution of the inventors to the present application in the process of invention and creation, and should not be understood as technical content known to those skilled in the art.

[0087] In view of this, the embodiment provides a feature extraction model training method. In the method, an electronic device acquires a sample script set; a current to-be-trained model is trained by a first learning strategy to extract features from the sample script set until the current to-be-trained model reaches a preset performance; the current to-be-trained model is trained by a second learning strategy to extract features from the sample script set, where a learning rate of the first learning strategy is greater than a learning rate of the second learning strategy; and the above steps are iterated until the current to-be-trained model meets an iteration stop condition as a feature extraction model. In this way, the training process of the model is divided into different stages, and different optimization strategies are adopted in each training stage, so that the model can more flexibly adapt to changes in training data to reduce the risk of overfitting, thereby effectively jumping out of a local optimal solution, and the trained feature extraction model can extract effective semantic features from scripts.

[0088] It should be noted that the electronic device implementing the above feature extraction model training method can be, but is not limited to, a mobile terminal, a tablet computer, a laptop computer, a desktop computer, a server, and the like. The server can be a single server or a server group. The server group can be centralized or distributed (for example, the server can be a distributed system). In some embodiments, the server can be local or remote relative to the user terminal. In some embodiments, the server can be implemented on a cloud platform; for example only, the cloud platform can include a private cloud, a public cloud, a hybrid cloud, a community cloud, a distributed cloud, an inter-cloud, a multi-cloud, and the like, or any combination thereof. In some embodiments, the server can be implemented on an electronic device having one or more components.

[0089] To make the scheme provided by the embodiment more clear, the following takes a server as the electronic device implementing the feature extraction model training method, and combines the above description of the feature extraction model training method to describe the implementation of the feature extraction model training method. Figure 1 The steps of the method are described in detail. However, it should be understood that the operations of the flowchart can not be implemented in sequence, and the steps without logical context relationship can be reversed in sequence or implemented simultaneously. In addition, one or more other operations can be added to the flowchart or one or more operations can be removed from the flowchart under the guidance of the content of the present application. For example, as shown in the flowchart, the method includes: Figure 1

[0090] S1A, acquiring a sample script set.

[0091] ​The sample script set includes a plurality of script codes in text form. The script codes can be any of TCL, Python, JavaScript, PHP, and the like. It can be understood that the method provided in the embodiment is applicable to a plurality of script languages, and is not limited to TCL scripts.

[0092] In addition, it should be noted that the to-be-trained model is a neural network. For example, the neural network can have a structure of two hidden layers, the first hidden layer includes 100 neurons, the second hidden layer includes 50 neurons, and the activation function is a ReL_RU activation function. Like a conventional neural network, before being trained by the sample script set, the to-be-trained model needs to undergo a series of initialization operations. That is, the server needs to initialize the weights w r and the bias b r of the to-be-trained model, and set an initial learning rate In an optional implementation, the setting method of the initial weights and bias can be represented as:

[0093]

[0094] In the formula, ~ represents being subject to a specific distribution, that is, the mean value of is 0, and the variance is a normal distribution. is the variance of the initial distribution, and in the embodiment, the value of is 0.01.

[0095] Continuing to refer to Figure 1 The feature extraction model training method further includes:

[0096] S2A, training the current to-be-trained model to extract features from the sample script set by using a first learning strategy until the current to-be-trained model reaches a preset performance.

[0097] It should be noted that, considering the dynamic changes and complexity of scripts, it is difficult to extract effective semantic features in the model training process. Inspired by the periodic metabolic process of biological cells, that is, different mechanisms are used to optimize the response and adaptability of organisms at different stages. Therefore, by simulating each stage in the cell cycle, the embodiment proposes a ring-shaped dynamic model training method for optimizing the parameters of the to-be-trained model. It can be understood that the embodiment divides the training process of the to-be-trained model into a plurality of stages, and each stage uses a different strategy to adjust the weights and bias of the neural network, so that the to-be-trained model can more flexibly adapt to changes in the training data.

[0098] As with the periodic metabolic processes of biological cells, the training process of the to-be-trained model is divided into "growth period, synthesis period, evaluation period, pre-splitting period, splitting period, and dormancy period" in this embodiment. The first learning strategy corresponds to the "growth period, synthesis period, and evaluation period" three stages, which are described in detail as follows, i.e., as shown in Figure 2 Figure 1 Step S2A specifically includes:

[0099] S2A-1, updating the current to-be-trained model according to the first feature extraction loss obtained by processing the sample script set by the current to-be-trained model at a first learning rate.

[0100] In this embodiment, the first learning rate corresponds to the "growth period", which requires increasing the weight adjustment amount to quickly adapt to the characteristics of the training data. Therefore, in addition to including a preset basic learning rate, the first learning rate also includes a target acceleration coefficient. Based on the basic learning rate and the target acceleration coefficient, the server can obtain the descent speed and curvature of the corresponding loss function according to the first feature extraction loss obtained by processing the sample script set by the current to-be-trained model; obtain the target acceleration coefficient according to the descent speed and curvature; and update the current to-be-trained model according to the basic learning rate and the target acceleration coefficient.

[0101] For example, the update mode of the first learning rate can be represented as:

[0102]

[0103] In the formula, η r represents the basic learning rate, γ r represents the target acceleration coefficient, L R represents the loss function of the to-be-trained model, for example, a cross-entropy loss; represents the gradient of the loss function with respect to the weight parameter, represents the gradient of the loss function with respect to the bias parameter, represents the weight parameter after the tth iteration, represents the weight parameter after the (t+1)th iteration, represents the bias parameter after the tth iteration, represents the bias parameter after the (t+1)th iteration, represents the mathematical symbol of the partial derivative operation.

[0104] For the target acceleration coefficient γ r ​The embodiment sets the descending speed and curvature of the loss function to avoid over-adjustment. In addition, a preset maximum acceleration coefficient is provided to limit the maximum value of the acceleration coefficient. Therefore, the server obtains a candidate acceleration coefficient of the base learning rate according to the descending speed and curvature; and then selects the minimum value of the candidate acceleration coefficient and the preset maximum acceleration coefficient as the target acceleration coefficient of the base learning rate.

[0105] To this end, the calculation expression of the target acceleration coefficient is as follows:

[0106]

[0107] In the formula, The preset maximum acceleration coefficient is denoted by max(), and the minimum value function is denoted by min().

[0108] In this way, during the growth period of the to-be-trained model, the target acceleration coefficient is introduced on the basis of the base learning rate, thereby improving the convergence rate of the model.

[0109] S2A-2, according to the existing weight of the current to-be-trained model, generates a new weight for the current to-be-trained model.

[0110] In the embodiment, generating a new weight for the current to-be-trained model corresponds to the "synthesis period", that is, synthesizing multiple weight parameters into a new parameter through a specific operation, thereby improving the generalization ability of the network. The function used by the embodiment to synthesize multiple weight parameters into a new parameter is called a synthesis function S(w r ), and the expression is as follows:

[0111]

[0112] In the formula, denotes the i-th weight parameter, denotes the importance coefficient of the i-th weight parameter, and nr denotes the number of weight parameters. The importance coefficient of the i-th weight parameter is related to the gradient size of the weight parameter in the "growth period". The expression of the importance coefficient of the i-th weight parameter is as follows:

[0113]

[0114] In the formula, σ wr denotes the decay speed parameter, and the calculation expression is as follows:

[0115]

[0116] In this way, the above embodiment generates a new weight for the current to-be-trained model. After the above growth period and synthesis period, the "evaluation period" of the to-be-trained model is entered, and therefore, step S2A further includes:

[0117] S2A-3, determining whether the current to-be-trained model reaches the preset performance, if yes, continuing to execute step S3A, otherwise, returning to execute step S2A-1 to continue to perform the fast adjustment of the parameters of the to-be-trained model.

[0118] It can be understood that after entering the evaluation period of the to-be-trained model, it is necessary to evaluate whether the performance of the current to-be-trained model after fast convergence reaches the preset performance, and whether to enter the next “pre-split period” is determined according to the evaluation result. For this purpose, the embodiment provides a performance evaluation function P(w r ,b r ) for determining whether to enter the next cycle. The performance evaluation function P(w r ,b r ) is represented as:

[0119]

[0120] In the formula, θ r represents a performance threshold, and the value is 0.5, that is, the recognition accuracy of the current to-be-trained model after the feature extracted by the to-be-trained model is input into the vulnerability recognition model is lower than 0.5, and the result of L(w r ,b r ) is 1, then the to-be-trained model enters the growth period again, otherwise, the to-be-trained model enters the next pre-split period. Therefore, continuing to refer to Figure 1 , after step S2, the method further includes:

[0121] S3A, training the current to-be-trained model to extract features from the sample script set by the second learning strategy.

[0122] In the embodiment, it is necessary to enable the to-be-trained model to quickly adapt to the training data in the first stage, and to finely adjust the parameters of the model in the second stage. Therefore, as an optional implementation manner, the learning rate of the first learning strategy can be greater than the learning rate of the second learning strategy. In this way, the to-be-trained model quickly adapts to the training data to improve the training efficiency.

[0123] As described in the above embodiment of the periodic metabolic process of biological cells, the second learning strategy of the embodiment corresponds to the above-mentioned “pre-split period, split period, and dormancy period”. The three stages will be described in detail as follows, that is, as shown in Figure 2 , step S3A in Figure 1 specifically includes:

[0124] S3A-1, obtaining the gradient of the corresponding loss function according to the second feature extraction loss obtained by processing the sample script set by the current to-be-trained model.

[0125] S3A-2, generating a fine-tuning parameter of the current to-be-trained model according to the gradient; and updating the current to-be-trained model by using the fine-tuning parameter.

[0126] In this embodiment, updating the current to-be-trained model by using the fine-tuning parameter corresponds to simulating the preparation division stage of the cell in the pre-mitotic stage, so only a slight adjustment is needed for the current to-be-trained model. Therefore, as an optional implementation of S3A-2, the server can obtain a first cosine value of a product of the weight gradient and a preset amplitude parameter; determine a product between the first cosine value and a preset frequency parameter as the weight fine-tuning parameter; obtain a second cosine value of a product of the bias gradient and the preset amplitude parameter; and determine a product between the second cosine value and the preset frequency parameter as the bias fine-tuning parameter.

[0127] For example, the calculation expression of the weight fine-tuning parameter and the bias fine-tuning parameter can be represented as:

[0128]

[0129] wherein, Δw r represents the weight fine-tuning parameter, Δb r represents the bias fine-tuning parameter, represents the weight gradient, represents the bias gradient, β r represents the preset amplitude parameter, ξ r represents the preset frequency parameter. As an optional implementation, ξ r may be 5, β r may be 3.14.

[0130] For the above ξ r and β r , they can also be calculated in the following way:

[0131]

[0132] wherein, ρ r represents a scaling factor of the perturbation amplitude, which can be 0.95.

[0133] After the above pre-mitotic stage, the to-be-trained model enters the mitotic stage, so step S3A further includes:

[0134] S3A-3, performing weight pruning on the current to-be-trained model.

[0135] In this stage, the structure of the to-be-trained model needs to be greatly adjusted, therefore, the weight pruning method is adopted to optimize the to-be-trained model. It should be noted that in the training process of the neural network model, weight pruning is a common optimization method, that is, by removing unimportant weights in the network, the complexity of the model is reduced, thereby reducing the calculation cost and storage requirement. In this embodiment, the weight parameters with a gradient greater than a preset gradient threshold value are retained, therefore, the expression of the weight pruning function R(w r ) is as follows:

[0136]

[0137] In the formula, λ r represents the gradient threshold value. In this embodiment, the gradient threshold value can be set to 0.01, that is, the weights with a gradient greater than 0.01 are retained.

[0138] After the above-mentioned “splitting period”, the to-be-trained model enters the “hibernation period”, therefore, step S3A further includes:

[0139] S3A-4, updating the current to-be-trained model according to the third feature extraction loss obtained by processing the sample script set by the current to-be-trained model at a second learning rate.

[0140] In this embodiment, the hibernation period means that the weights of the to-be-trained model gradually tend to be stable, which means that the learning rate of the model needs to be reduced, therefore, the second learning rate in the hibernation period is much smaller than the first learning rate in the growth period. In order to determine a relatively appropriate learning rate, the server can determine the second learning rate according to the current iteration number, wherein the second learning rate is inversely related to the current iteration number. The corresponding expression is as follows:

[0141]

[0142] In the formula, η r represents the second learning rate, δ r represents the attenuation coefficient, which can be set to 0.95, and k r represents the current iteration number.

[0143] Therefore, after the to-be-trained model is trained fast and then slowly by the above-mentioned first learning strategy and second learning strategy, it is further necessary to determine whether it can be used as a feature extraction model, therefore, as shown in step S3, the feature extraction model training method further includes: Figure 1

[0144] S4A, determining whether the current to-be-trained model meets the iteration stop condition of the feature extraction model, if not, returning to step S2 for execution, otherwise, executing step S5.

[0145] ​S5A, take the current to-be-trained model as a feature extraction model.

[0146] In this way, after at least one round of iteration, the to-be-trained model is trained as a feature extraction model. Since different strategies are used to adjust the weights and biases at each stage, the trained feature extraction model can more flexibly adapt to scripts of various forms.

[0147] In addition, it is found in practice that the collection, labeling and preprocessing of training data are time-consuming and laborious, especially scripts with logical loopholes are difficult to obtain in large quantities. Insufficient training samples can easily lead to poor generalization ability of the model, and at the same time affect the accuracy of the model. Therefore, the sample script set for training the feature extraction model includes extended samples generated by the sample expansion model. Therefore, the embodiment also provides a method for training the sample expansion model. As shown in the following Figure 3 The method comprises the following steps:

[0148] S1B, obtaining an original script set.

[0149] The original script set refers to the collected actual script data set, that is, these script data are usually collected through actual use in real application scenarios or specific tasks, and have authenticity and representativeness, so the original script set is the basis for building high-quality training data. The present embodiment trains the generative adversarial network with these original script sets as samples to obtain a sample expansion model capable of generating high-quality extended samples.

[0150] As shown in the following Figure 4 The generative adversarial network includes two parts: a generator (G) and a discriminator (D). Taking TCL scripts as an example, the working principle is as follows: the generator generates approximate real TCL script code data using input data (for example, random noise), and the discriminator is responsible for distinguishing whether the input data is from the real original script set or the data generated by the generator.

[0151] Based on the above introduction of the original script set and the generative adversarial network, continue to refer to the following Figure 3 The method further comprises the following steps:

[0152] S2B, obtaining the current gradient of the corresponding loss function according to the model loss obtained by processing the original script set in the current generative adversarial network.

[0153] S3B, updating the current generative adversarial network by quasi-Newton method according to the current gradient and the historical gradient during the last iteration.

[0154] It should be noted that in the training process of the generative adversarial network, the model loss is an index for evaluating the performance of the generator (G) and the discriminator (D). Specifically, the model loss reflects the difference between the script data generated by the current generator and the real script data, and the accuracy of the discriminator in distinguishing real data and generated data. By calculating the model loss, the current gradient of the loss function can be obtained, and then the parameters of the generator and the discriminator are adjusted to gradually optimize their performance. However, it is found in practice that the parameter updating method of the traditional generative adversarial network has the problems of poor training stability and slow convergence speed. In this regard, the improved Newton method is used to update the parameters of the generative adversarial network, which can more effectively adjust the network weights, speed up the convergence speed, and improve the quality of the generated data. That is, step S3B includes:

[0155] S3B-1, calculating the approximate Hessian matrix of the Newton method according to the historical gradient.

[0156] S3B-2, adjusting the current gradient through the approximate Hessian matrix, and updating the current generative adversarial network according to the adjusted current gradient.

[0157] S4B, determining whether the current generative adversarial network meets the iteration stop condition as a sample expansion model. If yes, execute S5B, otherwise execute step S2B.

[0158] S5B, taking the current generative adversarial network as a sample expansion model.

[0159] For example, the following takes TCL script as an example to elaborate the training method of the generative adversarial network:

[0160] First, the server initializes the network parameters of the generator and the discriminator. For example, it can be initialized by a small random number, and the random initialization method can be represented as:

[0161] θ g ←rand(-0.1,0.1)

[0162] θ d ←rand(-0.1,0.1)

[0163] In the formula, θ g represents the parameters of the generator, and θ d represents the parameters of the discriminator.

[0164] Then, a batch of data is randomly selected from the existing TCL original script set for the training of the discriminator, and the selected data is represented as:

[0165] D batch ={d1,d2,…,dm}

[0166] The generator receives random noise as input, and generates a batch of TCL fake scripts through forward propagation, denoted as:

[0167] G batch = g(z; θ g )

[0168] In the formula, G batch represents a batch of TCL fake scripts, and z represents the generated random noise.

[0169] Next, the discriminator receives fake data and real data from the generator at the same time, and the training target is to maximize the classification accuracy of the discriminator on real data and generated data, denoted as:

[0170]

[0171]

[0172] In the formula, L d represents the loss function of the discriminator, d(d i ; θ d ) represents the output function of the discriminator, and λ d represents the learning rate, which can be set to 0.01.

[0173] The calculation method of the output function d(x; θ d ) of the discriminator is:

[0174]

[0175] In the formula, f(x; θ d ) represents the original output of the discriminator on the input x, that is, the linear output of the last layer of the discriminator.

[0176] Finally, the generator is trained by improving the ability of the generated data to deceive the discriminator, and the parameter update of the generator depends on the evaluation result of the discriminator on the generated data, and the loss function of the generator training is denoted as:

[0177]

[0178]

[0179] Based on the above introduction of the conventional training method of the generator and the discriminator, the improved Newton method is used to update the weight parameters of the generator and the discriminator. Specifically, in each iteration, the approximate Hessian matrix of the current gradient is calculated using the gradient information of the previous round, so as to adjust the learning rate and the update direction, and the parameter update method is denoted as:

[0180]

[0181]

[0182]

[0183]

[0184] H g , H d respectively represent the approximate Hessian matrix of the generator and the discriminator parameters, η g , η d respectively represent the respective learning rates. In this embodiment, the Hessian matrix approximation is implemented using the BFGS update rule, and the expression is as follows:

[0185]

[0186]

[0187] In the formula, δ k represents the difference value of parameter update, y k represents the difference value of gradient update.

[0188] The above steps are iterated until a preset stopping iteration condition is met, so that the generator is trained to be a required script generator, and the TCL extension script generated by the script generator can achieve the effect of cheating the discriminator. In this embodiment, the preset stopping iteration condition is to reach a preset maximum number of iterations, and the maximum number of iterations can be set to 1000.

[0189] Based on the same inventive concept as the feature extraction model training method provided in this embodiment, this embodiment also provides a feature extraction model training device. The device includes at least one software functional module stored in the memory in the form of software or solidified in the electronic device. The processor in the electronic device is used to execute the executable modules stored in the memory. For example, the software functional modules and computer programs included in the device. Please refer to Figure 5 From the functional point of view, the device can include:

[0190] The sample acquisition module 11 is used to acquire a sample script set.

[0191] The model training module 12 is used to train the current to-be-trained model to extract features from the sample script set through a first learning strategy until the current to-be-trained model reaches a preset performance; train the current to-be-trained model to extract features from the sample script set through a second learning strategy; and iterate the above steps until the current to-be-trained model meets the iteration stopping condition as a feature extraction model.

[0192] In the embodiment, the sample acquisition module 11 is configured to implement step S1A in Figure 1 , the model training module 12 is configured to implement steps S2A, S3A, S4A, S5A in Figure 1 . Therefore, the detailed description of each module above can refer to the specific embodiments of the corresponding steps. In addition, it should be noted that the feature extraction model training device can also implement other steps or sub-steps of the method through the above modules, as the feature extraction model training method has the same inventive concept, and the embodiment will not be repeated here.

[0193] In addition, each functional module in each embodiment of the present application can be integrated together to form an independent part, or each module can exist independently, or two or more modules can be integrated to form an independent part.

[0194] It should also be understood that the above embodiments, if implemented in the form of software functional modules and sold or used as independent products, can be stored in a computer readable storage medium. Based on this understanding, the technical solutions of the present application essentially or the parts that contribute to the prior art or parts of the technical solutions can be embodied in the form of a software product, which is stored in a storage medium and includes a number of instructions to make a computer device (which can be a personal computer, a server, or a network device, etc.) execute all or part of the steps of the embodiments of the present application.

[0195] Therefore, the present embodiment also provides a storage medium, which is a computer readable storage medium. The storage medium stores a computer program, and the computer program is executed by a processor to implement the feature extraction model training method provided by the present embodiment. The storage medium can be a U disk, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and various media that can store program codes.

[0196] The present embodiment provides an electronic device for implementing the feature extraction model training method. As shown in Figure 6 , the electronic device includes a processor 22 and a memory 21. The memory 21 stores a computer program, and the processor implements the feature extraction model training method provided by the present embodiment by reading and executing the computer program corresponding to the above embodiments in the memory 21.

[0197] Continuing to refer to Figure 6The electronic device further includes a communication unit 23. The memory 21, the processor 22, and the communication unit 23 are electrically connected to each other directly or indirectly through a system bus 24 to enable data transmission or interaction.

[0198] The memory 21 can be an information recording device based on any electronic, magnetic, optical, or other physical principle for recording execution instructions, data, and the like. In some embodiments, the memory 21 can be, but is not limited to, a volatile memory, a non-volatile memory, a storage drive, and the like.

[0199] In some embodiments, the volatile memory can be a random access memory (RAM); in some embodiments, the non-volatile memory can be a read only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), a flash memory, and the like; in some embodiments, the storage drive can be a disk drive, a solid state drive, any type of storage disk (such as an optical disk, a DVD, and the like), or a similar storage medium, or a combination thereof, and the like.

[0200] The communication unit 23 is configured to transmit and receive data via a network. In some embodiments, the network can include a wired network, a wireless network, a fiber optic network, a telecommunications network, an intranet, the Internet, a Local Area Network (LAN), a Wide Area Network (WAN), a Wireless Local Area Network (WLAN), a Metropolitan Area Network (MAN), a Wide Area Network (WAN), a Public Switched Telephone Network (PSTN), a Bluetooth network, a ZigBee network, or a Near Field Communication (NFC) network, etc., or any combination thereof. In some embodiments, the network can include one or more network access points. For example, the network can include wired or wireless network access points, such as base stations and / or network switching nodes, through which one or more components of the service request processing system can connect to the network to exchange data and / or information.

[0201] The processor 22 can be an integrated circuit chip that has the capability of processing signals, and the processor can include one or more processing cores (e.g., a single-core processor or a multi-core processor). By way of example only, the processor can include a Central Processing Unit (CPU), an Application Specific Integrated Circuit (ASIC), an Application Specific Instruction-set Processor (ASIP), a Graphics Processing Unit (GPU), a Physics Processing Unit (PPU), a Digital Signal Processor (DSP), a Field Programmable Gate Array (FPGA), a Programmable Logic Device (PLD), a controller, a microcontroller unit, a Reduced Instruction Set Computing (RISC), or a microprocessor, etc., or any combination thereof.

[0202] It can be understood that Figure 6The structure shown is for illustrative purposes only. Electronic devices may also have more advanced features. Figure 6 Showing more or fewer components, or having with Figure 6 The different configurations shown. Figure 6 The components shown can be implemented using hardware, software, or a combination thereof.

[0203] It should be understood that the apparatus and methods disclosed in the above embodiments can also be implemented in other ways. The apparatus embodiments described above are merely illustrative. For example, the flowcharts and block diagrams in the accompanying drawings show the architecture, functionality, and operation of possible implementations of apparatus, methods, and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks may occur in a different order than those marked in the drawings. For example, two consecutive blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram and / or flowchart, and combinations of blocks in block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or action, or using a combination of dedicated hardware and computer instructions.

[0204] The above descriptions are merely various embodiments of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.

Claims

1. A feature extraction model training method characterized by, The method comprises: obtaining a sample script set; training a current to-be-trained model from the sample script set by a first learning strategy until the current to-be-trained model reaches a preset performance, comprising: updating the current to-be-trained model at a first learning rate according to a first feature extraction loss obtained by processing the sample script set by the current to-be-trained model; generating new weights for the current to-be-trained model according to existing weights of the current to-be-trained model; iterating the above steps until the current to-be-trained model reaches the preset performance; training the current to-be-trained model from the sample script set by a second learning strategy, comprising: obtaining a gradient of a corresponding loss function according to a second feature extraction loss obtained by processing the sample script set by the current to-be-trained model; generating a fine-tuning parameter of the current to-be-trained model according to the gradient, and updating the current to-be-trained model by using the fine-tuning parameter; performing weight pruning on the current to-be-trained model; updating the current to-be-trained model at a second learning rate according to a third feature extraction loss obtained by processing the sample script set by the current to-be-trained model; wherein the learning rate of the first learning strategy is greater than the learning rate of the second learning strategy; iterating the above steps until the current to-be-trained model meets an iteration stop condition as the feature extraction model.

2. The feature extraction model training method of claim 1, wherein, The first learning rate comprises a preset basic learning rate and a target acceleration coefficient, and updating the current to-be-trained model at the first learning rate according to the first feature extraction loss obtained by processing the sample script set by the current to-be-trained model comprises: obtaining a falling speed and a curvature of a corresponding loss function according to the first feature extraction loss obtained by processing the sample script set by the current to-be-trained model; obtaining the target acceleration coefficient according to the falling speed and the curvature; updating the current to-be-trained model according to the basic learning rate and the target acceleration coefficient. 3.The feature extraction model training method of claim 1, wherein, The gradient comprises a weight gradient and a bias gradient, and the fine-tuning parameter comprises a weight fine-tuning parameter and a bias fine-tuning parameter, and generating the fine-tuning parameter of the current to-be-trained model according to the gradient comprises: obtaining a first cosine value of a product between the weight gradient and a preset amplitude parameter; determining a product between the first cosine value and a preset frequency parameter as the weight fine-tuning parameter; obtaining a second cosine value of a product between the bias gradient and a preset amplitude parameter; determining a product between the second cosine value and a preset frequency parameter as the bias fine-tuning parameter.

4. The feature extraction model training method of claim 1, wherein, The sample script set comprises extended samples generated by a sample augmentation model, and the method further comprises: obtaining an original script set; obtaining a current gradient of a corresponding loss function according to a model loss obtained by processing the original script set by a current generative adversarial network; updating the current generative adversarial network by a quasi-Newton method according to the current gradient and a historical gradient during a previous iteration; iterating the above steps until the current generative adversarial network meets an iteration stop condition as the sample augmentation model.

5. The feature extraction model training method of claim 4, wherein, The updating of the current generative adversarial network by the quasi-Newton method according to the current gradient and the historical gradient during the previous iteration comprises: An approximate Hessian matrix of a quasi-Newton method is calculated according to the historical gradients; The current gradient is adjusted through the approximate Hessian matrix, and the current generative adversarial network is updated according to the adjusted current gradient.

6. A feature extraction model training apparatus characterized by comprising: The device comprises: A sample acquisition module is configured to acquire a sample script set; A model training module is configured to train a current to-be-trained model to extract features from the sample script set through a first learning strategy until the current to-be-trained model reaches a preset performance, including: updating the current to-be-trained model at a first learning rate according to a first feature extraction loss obtained by processing the sample script set by using the current to-be-trained model; generating new weights for the current to-be-trained model according to existing weights of the current to-be-trained model; iterating the above steps until the current to-be-trained model reaches the preset performance; training the current to-be-trained model to extract features from the sample script set through a second learning strategy, wherein the learning rate of the first learning strategy is greater than the learning rate of the second learning strategy, including: obtaining a gradient of a corresponding loss function according to a second feature extraction loss obtained by processing the sample script set by using the current to-be-trained model; generating fine-tuning parameters of the current to-be-trained model according to the gradient, and updating the current to-be-trained model through the fine-tuning parameters; performing weight pruning on the current to-be-trained model; updating the current to-be-trained model at a second learning rate according to a third feature extraction loss obtained by processing the sample script set by using the current to-be-trained model; iterating the above steps until the current to-be-trained model meets an iteration stop condition as the feature extraction model.

7. A storage medium, characterized by The storage medium stores a computer program, and the computer program is executed by the processor to implement the feature extraction model training method in any one of claims 1-5.

8. An electronic device, comprising: The electronic device comprises a processor and a memory, and the memory stores a computer program, and the computer program is executed by the processor to implement the feature extraction model training method in any one of claims 1-5.

Citation Information

Patent Citations

  • Webshell detection method and webshell detection device

    CN112052451A

  • Model training method and device, storage medium and electronic equipment

    CN115618221A