A model training method and device
By combining anti-perturbation and attenuation factors, the problem of low training accuracy of neural networks under finite samples is solved, the generalization ability and accuracy of the model is improved, overfitting is reduced, and more efficient model training is achieved.
Patent Information
- Application Number
- CN202110125583.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-01-29
- Publication Date
- 2024-11-26
- Estimated Expiration
- 2041-01-29
AI Technical Summary
Neural networks have low training accuracy under limited training samples, making it difficult to effectively improve the generalization ability of the model and avoid overfitting.
By combining anti-perturbation and attenuation factors, the impact of anti-perturbation on gradients is determined, and its impact on model updates is reduced, thereby improving the generalization ability of the model and avoiding overfitting. Specific steps include determining the anti-perturbation based on the original sample and model, adjusting the gradient through the attenuation factor, performing model updates, and gradually approximating the target model through backpropagation training and loss function optimization.
The accuracy and generalization ability of the model are improved, the overfitting problem is reduced, and the target model is gradually approached by combining anti-perturbation and attenuation factors, which improves the training effect under finite samples.
Smart Images

Figure CN112784984B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of neural network learning technology, and in particular to a model training method and device. Background Art
[0002] Neural network is a complex network system formed by a large number of simple processing units widely connected to each other. It reflects many basic characteristics of human brain function and is a highly complex nonlinear dynamic learning system. By utilizing the learning ability of neural network, it can automatically learn the characteristics of the system in the process of controlling the uncertain system, so as to automatically adapt to the variation of the characteristics of the system over time, in order to achieve the optimal control of the system. In the automatic process, neural network needs to provide a large number of training samples for training, but because the number of training samples is limited, the accuracy of neural network training is low under limited training samples.
[0003] Application Contents
[0004] The embodiments of the present application provide a model training method and device, which have the effect of improving the accuracy of the model.
[0005] A first aspect of an embodiment of the present application provides a model training method, the method comprising: determining an adversarial perturbation based on a first model and an original sample; determining a first gradient based on the original sample, the adversarial perturbation and an attenuation factor; wherein the attenuation factor is used to reduce the impact of the adversarial perturbation on the first gradient; and updating the first model according to the first gradient to obtain a second model.
[0006] According to another embodiment of the present application, determining the adversarial perturbation based on the first model and the original sample includes: determining a first loss function based on the first model and the original sample; back-propagation training the first model based on the first loss function and the original sample to obtain a third model and a second gradient; determining the adversarial perturbation based on the first loss function and the second gradient.
[0007] According to another embodiment of the present application, a first gradient is determined according to the original sample, the adversarial perturbation and the attenuation factor, including: determining a virtual sample according to the adversarial perturbation and the original sample; determining a second loss function according to the third model and the virtual sample; performing back-propagation training on the third model according to the second loss function and the virtual sample to obtain a fourth model and a third gradient; and determining a first gradient according to the attenuation factor and the third gradient.
[0008] According to another embodiment of the present application, the first model is updated according to the first gradient to obtain the second model, including: restoring the target parameters of the fourth model according to the third model to obtain the fifth model; and updating the fifth model according to the first gradient to obtain the second model.
[0009] According to another embodiment of the present application, the method further includes: determining an attenuation function, and determining an attenuation factor based on the attenuation function.
[0010] According to another embodiment of the present application, the method further includes: determining an attenuation function according to a model training parameter corresponding to the first model, and determining an attenuation factor based on the attenuation function; wherein the model training parameter is at least one of a model training time and a number of model training times.
[0011] According to another embodiment of the present application, the attenuation function includes a first attenuation function and a second attenuation function; accordingly, determining the attenuation factor based on the attenuation function includes: when the model training parameters meet a preset parameter threshold, determining the attenuation factor according to the first attenuation function; when the model training parameters do not meet the preset parameter threshold, determining the attenuation factor according to the second attenuation function; wherein there is a difference between the first attenuation function and the second attenuation function.
[0012] According to another embodiment of the present application, the method further includes: determining the second model as the first model; returning to execute determining the adversarial disturbance based on the first model and the original sample.
[0013] According to another embodiment of the present application, after obtaining the second model, the method further includes: determining a loss value based on the second model; when the loss value satisfies the loss threshold, determining the second model as the target model; wherein the loss threshold is determined based on the model training parameters.
[0014] According to a second aspect of an embodiment of the present application, a model training device is provided, the device comprising: a determination module, used to determine an adversarial perturbation based on a first model and an original sample; the determination module is also used to determine a first gradient based on the original sample, the adversarial perturbation and an attenuation factor; wherein the attenuation factor is used to reduce the impact of the adversarial perturbation on the first gradient; and an update module, used to update the first model according to the first gradient to obtain a second model.
[0015] According to another embodiment of the present application, the determination module includes: a determination submodule, used to determine a first loss function based on the first model and the original sample; a training submodule, used to back-propagate training the first model based on the first loss function and the original sample to obtain a third model and a second gradient; the determination submodule is also used to determine the adversarial perturbation based on the first loss function and the second gradient.
[0016] According to another embodiment of the present application, the determination submodule is further used to determine a virtual sample according to the adversarial disturbance and the original sample;
[0017] The determination submodule is further used to determine a second loss function according to the third model and the virtual sample;
[0018] The training submodule is further used to perform back propagation training on the third model according to the second loss function and the virtual sample to obtain a fourth model and a third gradient;
[0019] The determination submodule is further configured to determine a first gradient according to the attenuation factor and the third gradient.
[0020] According to another embodiment of the present application, the updating module includes: a restoration submodule, used to restore the target parameters of the fourth model according to the third model to obtain the fifth model; and an updating submodule, used to update the fifth model according to the first gradient to obtain the second model.
[0021] According to another embodiment of the present application, the determination module is further used to determine an attenuation function, and determine the attenuation factor based on the attenuation function.
[0022] According to another embodiment of the present application, the determination module is also used to determine the attenuation function according to the model training parameters corresponding to the first model, and determine the attenuation factor based on the attenuation function; wherein the model training parameters are at least one of the model training time and the number of model training times.
[0023] According to another embodiment of the present application, the attenuation function includes a first attenuation function and a second attenuation function; accordingly, the determination submodule is also used to determine the attenuation factor according to the first attenuation function when the model training parameters meet the preset parameter threshold; the determination submodule is also used to determine the attenuation factor according to the second attenuation function when the model training parameters do not meet the preset parameter threshold; wherein there is a difference between the first attenuation function and the second attenuation function.
[0024] According to another embodiment of the present application, the determination module is further used to determine the second model as the first model; the device also includes: a return module, used to return to execute the determination of the adversarial disturbance based on the first model and the original sample.
[0025] According to another embodiment of the present application, the determination module is also used to determine the loss value based on the second model; the determination module is also used to determine the second model as the target model when the loss value meets the loss threshold; wherein the loss threshold is determined based on the model training parameters.
[0026] The model training method and device provided in the embodiment of the present application perturb the first gradient through adversarial disturbance to improve the generalization ability of the second model, and reduce the impact of the adversarial disturbance on the first gradient through an attenuation factor to avoid overfitting problems in the second model, so that the second model has better accuracy.
[0027] It should be understood that the teachings of the present application are not required to achieve all of the beneficial effects described above, but specific technical solutions can achieve specific technical effects, and other embodiments of the present application can also achieve beneficial effects not mentioned above. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] By reading the detailed description below with reference to the accompanying drawings, the above and other purposes, features and advantages of the exemplary embodiments of the present application will become easily understood. In the accompanying drawings, several embodiments of the present application are shown in an exemplary and non-limiting manner, wherein:
[0029] Figure 1 A schematic diagram of the implementation process of a training method for a model in an embodiment of the present application is shown;
[0030] Figure 2 A schematic diagram of the implementation flow of a training method for a model in another embodiment of the present application to determine an anti-disturbance is shown;
[0031] Figure 3 A schematic diagram of the implementation flow of determining the first gradient by a training method of a model in another embodiment of the present application is shown;
[0032] Figure 4 A schematic diagram of the implementation process of determining a target model by a training method of a model in another embodiment of the present application is shown;
[0033] Figure 5 A schematic diagram of the implementation flow of a training device of another embodiment model of the present application.
[0034] In the drawings, the same or corresponding reference numerals represent the same or corresponding parts. DETAILED DESCRIPTION
[0035] The principles and spirit of the present application will be described below with reference to several exemplary embodiments. It should be understood that these embodiments are provided only to enable those skilled in the art to better understand and implement the present application, and are not intended to limit the scope of the present application in any way. On the contrary, these embodiments are provided to make the present application more thorough and complete, and to fully convey the scope of the present application to those skilled in the art.
[0036] The technical solution of the present application is further described in detail below with reference to the accompanying drawings and specific embodiments.
[0037] Figure 1 A schematic diagram of the implementation flow of a training method for a model of an embodiment of the present application is shown.
[0038] See also Figure 1 In a first aspect, an embodiment of the present application provides a model training method, the method comprising: operation 101, determining an adversarial disturbance based on a first model and an original sample; operation 102, determining a first gradient based on the original sample, the adversarial disturbance and an attenuation factor; wherein the attenuation factor is used to reduce the influence of the adversarial disturbance on the first gradient; operation 103, updating the first model according to the first gradient to obtain a second model.
[0039] The model training method provided in the embodiment of the present application perturbs the first gradient through adversarial perturbation to improve the generalization ability of the second model, and reduces the impact of the adversarial perturbation on the first gradient through an attenuation factor to avoid the overfitting problem of the second model, and updates the first model through the first gradient so that the second model has better accuracy.
[0040] In operation 101 of the present method, the first model may be any one or more of an untrained original model, a general pre-trained model, or a model that has undergone multiple rounds of training; the model type may be an image model and a text model; the model may also be a single model or a combined model. The original sample refers to a sample that has not been processed by operation 102. The original sample may be a sample obtained by collection, or a sample obtained by data preprocessing, wherein the sample content of the original sample is determined according to the type of the first model and the information content that needs to be classified using the second model, and the original sample may be a discrete sample or a continuous sample. For example, when the second model is applied to the field of intelligent customer service, the original sample may be a conversation sample corresponding to intelligent customer service. When the original sample is a conversation sample, the original sample is perturbed by adversarial perturbation to make the original sample more interpretable. The present method determines the adversarial perturbation according to the content of the original sample and the parameters corresponding to the first model, so that the adversarial perturbation of the original sample is more targeted and has a better effect.
[0041] In operation 102 of the present method, the attenuation factor is used to reduce the effect of the adversarial disturbance on the first gradient. The first gradient can be used to describe the accuracy gap between the first model and the target model, and can provide the optimal adjustment direction for the first model parameter adjustment. Specifically, the first gradient can be represented by a vector, and the gap and adjustment direction are determined by the value and direction of the vector. The first gradient is determined based on the original sample, the adversarial disturbance and the attenuation factor. The attenuation factor can reduce the effect of the adversarial disturbance on the original sample to achieve the purpose of reducing the effect of the adversarial disturbance on the first gradient. The attenuation factor can also reduce the effect of the adversarial disturbance on the first gradient by reducing the first gradient. Determining the first gradient by adversarial disturbance and attenuation factor can make the second model obtained by updating the first model according to the first gradient more accurate.
[0042] In operation 103 of the present method, the first model is updated according to the first gradient to obtain the second model. When the first model is updated according to the first gradient, the accuracy of the updated model can meet or approach the target model. That is, the second model can be the target model, or it can be a model that is closer to the target model than the first model. It should be supplemented that by returning the second model as the first model to perform the above operation multiple times, the second model obtained in each round is re-executed as the first model of the next round. Since the adversarial disturbance is determined according to the first model and the original sample, the adversarial disturbance determined according to the first model and the original sample in each round will be different, and then different first gradients can be determined by different adversarial disturbances and attenuation factors in the case of limited original samples, and the first model is updated round by round by the first gradient, so that the second model can gradually approach until it meets the requirements of the target model. Through the above method, a target model with higher accuracy can be obtained.
[0043] Figure 2 A schematic diagram of the implementation flow of a training method for a model of another embodiment of the present application to determine countermeasure disturbances is shown.
[0044] See also Figure 2 According to another embodiment of the present application, operation 101, determining the adversarial perturbation according to the first model and the original sample, includes: operation 1011, determining the first loss function according to the first model and the original sample; operation 1012, back-propagation training the first model according to the first loss function and the original sample to obtain a third model and a second gradient; operation 1013, determining the adversarial perturbation according to the first loss function and the second gradient.
[0045] This method can directly determine the adversarial perturbation based on the original sample and the first model; it can also predict the adversarial perturbation based on the original sample and the first model by constructing a model; it can also determine the adversarial perturbation by performing data processing based on the original sample and the first model.
[0046] In one implementation scenario, first, according to the first model and the original sample, the forward loss function corresponding to the first model and the original sample, that is, the first loss function, is determined by calculation, wherein, according to the task type, the first loss function can be selected as one of the classification loss function or the regression loss function, when the task type is classification, the first loss function can be selected as the multi-classification cross entropy loss function, and when the task type is regression, the first loss function can be selected as the mean square error loss function. It should be added that the determination of the following other loss functions or loss values can be determined by these two or other loss functions. And the first model is back-propagated and trained according to the first loss function and the original sample to obtain the third model and the second gradient. Among them, in the back-propagation training, the first model is parameter updated for the first time by the first loss function and the original sample to obtain the third model, and the second gradient corresponding to the third model is obtained. The second gradient is used to describe the accuracy deviation between the third model and the target model, and can provide the optimal adjustment direction for the third model parameter adjustment. Afterwards, the adversarial perturbation is determined according to the first loss function and the second gradient. The adversarial disturbance is not unconstrained, and the norm of the adversarial disturbance can be made smaller than a preset constant, which can be determined based on the attenuation factor. Specifically, it can be expressed by the formula:
[0047] ||Δx||≤∈(x)
[0048] Among them, Δx is the adversarial disturbance and ∈(x) is a preset constant.
[0049] An adversarial perturbation function can be constructed based on the first loss function and the second gradient as parameters. Specifically, the adversarial perturbation function can be determined based on the concept of gradient ascent to achieve the purpose of perturbing the first gradient. The adversarial perturbation can perturb the original sample so that the loss of the loss function of the corresponding perturbed sample increases, thereby achieving the purpose of perturbation.
[0050] In a specific scenario, the adversarial perturbation function can be determined as:
[0051]
[0052] Among them, Δx is the adversarial disturbance, ∈(x) is a constant, is the second gradient, L(x, y; θ) is the first loss function, where x is the input information of the original sample corresponding to the first loss function, y is the label information corresponding to the original sample, and θ is the model parameter corresponding to the first model.
[0053] In order to prevent the adversarial perturbation from being too large, other adversarial perturbation functions can be constructed to normalize the adversarial perturbation.
[0054] In another specific scenario, the adversarial perturbation function can be determined as:
[0055]
[0056] Among them, Δx is the adversarial disturbance, ∈(x) is a constant, is the second gradient, L(x, y; θ) is the first loss function, where x is the input information of the original sample corresponding to the first loss function, y is the label information corresponding to the original sample, and θ is the model parameter corresponding to the first model.
[0057] In another specific implementation scenario, the anti-disturbance function can also be determined as:
[0058]
[0059] Among them, Δx is the adversarial disturbance, ∈(x) is a constant, is the second gradient, L(x, y; θ) is the first loss function, where x is the original sample corresponding to the first loss function, y is the sample label corresponding to the original sample, and θ is the model parameter corresponding to the first model.
[0060] It can be understood that this method is inspired by the above-mentioned adversarial disturbance function, and other adversarial disturbance functions can also be constructed.
[0061] Figure 3 A schematic diagram of the implementation flow of determining the first gradient by a training method of a model in another embodiment of the present application is shown.
[0062] See also Figure 3 According to another embodiment of the present application, operation 102, determining a first gradient according to the original sample, the adversarial perturbation and the attenuation factor, includes: operation 1021, determining a virtual sample according to the adversarial perturbation and the original sample; operation 1022, determining a second loss function according to the third model and the virtual sample; operation 1023, performing back propagation training on the third model according to the second loss function and the virtual sample to obtain a fourth model and a third gradient; operation 1024, determining a first gradient according to the attenuation factor and the third gradient.
[0063] This method can determine the first gradient by integrating the original sample, adversarial perturbation and attenuation factor. The specific integration method can be one or more of multiplication, addition or other calculation methods. In one implementation, the adversarial perturbation can be first added and integrated with the original sample to obtain a virtual sample, and then forward propagation is performed based on the virtual sample and the third model to obtain the corresponding forward loss function, that is, the second loss function, and the third model is back-propagated and trained based on the second loss function and the virtual sample to obtain the fourth model and the third gradient. Among them, the second loss function can be one of the classification loss function and the regression loss function. As above, in the back-propagation training, the third model is parameter updated for the second time through the second loss function and the virtual sample to obtain the fourth model, and the third gradient corresponding to the fourth model is obtained. In one embodiment, the function of the back-propagation training can be:
[0064]
[0065] Wherein, D represents a virtual sample, x+Δx represents the input information corresponding to the virtual sample, y represents the label information corresponding to the virtual sample, θ' is the model parameter corresponding to the third model, L(x+Δx,y; θ') is the second loss function corresponding to a single virtual sample, Δx is the adversarial perturbation, Ω is the perturbation space corresponding to the adversarial perturbation; θ" is the model parameter corresponding to the fourth model.
[0066] The third gradient is used to describe the accuracy gap between the fourth model and the target model, and can provide the optimal adjustment direction for the subsequent parameter adjustment of the fourth model. The first gradient is determined by multiplying and integrating the attenuation factor and the third gradient, so that the attenuation factor weakens the third gradient, thereby obtaining the first gradient.
[0067] In another embodiment, after obtaining the adversarial disturbance, it can be directly integrated with the adversarial disturbance through an attenuation factor. The integration can be multiplication, subtraction, averaging, etc. to reduce the disturbance amount of the adversarial disturbance. The adversarial disturbance with the integrated attenuation factor is added and integrated with the original sample to obtain another virtual sample. Back propagation training is performed through the other virtual sample to obtain a fourth model and a third gradient. In this embodiment, the third gradient is the first gradient, and the attenuation factor can also play a role in reducing the impact of the adversarial disturbance on the first gradient.
[0068] According to another embodiment of the present application, operation 103, updating the first model according to the first gradient to obtain the second model, includes: first, restoring the target parameters of the fourth model according to the third model to obtain the fifth model; then, updating the fifth model according to the first gradient to obtain the second model.
[0069] It can be understood that when the original sample is a discrete sample, such as text data, after the third model is back-propagated and trained with virtual samples obtained by integrating the original sample and the adversarial perturbation, the target parameters of the fourth model obtained cannot correspond to the original sample. Based on this, this method restores the parameters (word_embedding) corresponding to the word vector in the embedding (Input Embedding) layer in the fourth model, and restores it to the parameters corresponding to the word vector in the embedding layer in the third model, that is, the target parameters are the parameters corresponding to the word vector, so as to obtain the fifth model, so that the target parameters of the fifth model can correspond to the original sample, and then the parameters of the fifth model are updated according to the first gradient to obtain the second model.
[0070] It should be added that, in another embodiment, after obtaining the first gradient, the first model or the third model can be directly updated by the first gradient to obtain another second model. The second model obtained by the two methods can improve the prediction accuracy compared with the first model.
[0071] According to another embodiment of the present application, the method further includes: first, determining the second model as the first model; and then returning to determine the adversarial disturbance based on the first model and the original sample.
[0072] During the model training process, by determining the second model as the first model, operations 101 to 103 can be returned to be executed. The steps of operations 101 to 103 can be repeated multiple times, so that the second model obtained in each round of training can gradually approach the target model, and the second model obtained in each round can be improved in accuracy compared with the second model in the previous round.
[0073] Figure 4 A schematic diagram of the implementation flow of determining a target model by a model training method according to another embodiment of the present application is shown.
[0074] See also Figure 4According to another embodiment of the present application, after obtaining the second model in operation 103, the method further includes: operation 401, determining the loss value according to the second model; operation 402, determining the second model as the target model when the loss value meets the loss threshold; wherein the loss threshold is determined according to the model training parameters. In order to obtain the target model, the method can set a preset condition, and when the second model meets the preset condition, the second model that meets the preset condition is determined as the target model. It should be supplemented that when the second model does not meet the preset condition, the second model that does not meet the preset condition is determined as the first model, and then the method returns to perform the determination of the adversarial disturbance according to the first model and the original sample. Among them, the preset condition can be a threshold value corresponding to a certain type of parameter in the second model. If the parameter of this type in the second model decreases with the improvement of the model accuracy, when the parameter in the second model is lower than and equal to the threshold, the second model can be considered to meet the preset condition. Similarly, if the parameter of this type in the second model increases with the improvement of the model accuracy, when the parameter in the second model is lower than and equal to the threshold, the second model can be considered to meet the preset condition.
[0075] In one implementation scenario of the present method, the preset condition may be a loss threshold corresponding to the loss value, and the loss threshold may be a preset constant or a threshold that changes dynamically according to a preset rule. In one specific implementation scenario, the loss threshold may be determined based on a model training parameter. It is understood that the model training parameter is at least one of a model training time and a number of model training times. In a specific implementation scenario, the corresponding minimum model training time step is set according to the model accuracy requirement, and the corresponding loss threshold is determined based on the minimum model training time step of the model. It is understood that the fewer the minimum model training time steps, the smaller the accuracy of the corresponding loss threshold. The loss threshold may also include a loss difference threshold and a model training time step. In a specific implementation scenario, after the model training time step reaches the minimum model training time step, if the loss value of the model changes less than the loss difference threshold within a preset number of training time steps, the second model corresponding to the last round of model training is determined as the target model.
[0076] According to another embodiment of the present application, the method further includes: determining an attenuation function, and determining an attenuation factor based on the attenuation function.
[0077] In this method, the attenuation factor can be a constant or a dynamically changing value. When the attenuation factor is a dynamically changing value, the attenuation factor can be dynamically adjusted so that the attenuation factor can adapt to the corresponding counter-perturbation, thereby avoiding excessive counter-perturbation and thus reducing the impact of the counter-perturbation on the first gradient. This method does not limit the function type of the attenuation function, which can be various types of attenuation functions such as cosine annealing attenuation function, exponential attenuation function, linear attenuation function, etc. When constructing the attenuation function, this method can use any one or more parameters related to model training, such as model training parameters, counter-perturbation, first gradient, etc., as parameters of the attenuation function. For example, with counter-perturbation as the parameter of the attenuation function, as the counter-perturbation increases, the value of the attenuation factor is reduced to weaken the counter-perturbation.
[0078] According to another embodiment of the present application, the method further includes: determining an attenuation function according to a model training parameter corresponding to the first model, and determining an attenuation factor based on the attenuation function; wherein the model training parameter is at least one of a model training time and a number of model training times.
[0079] The method can determine the attenuation function through the model training parameters corresponding to the first model. For example, according to the attenuation function related to the model training time step, in one implementation, the more training time steps, the smaller the attenuation factor corresponding to the attenuation function, and the better the attenuation effect on the adversarial disturbance. For example, the attenuation function can be: ∈(ts)=ts / gts+(1-α). Wherein, ∈(ts) is the attenuation factor, ∈(ts) is 0≤α≤1; ts represents the current time step of model training; gts represents the total time step of preset model training; a is a constant, and a takes a value of 0≤α≤1.
[0080] According to another embodiment of the present application, the attenuation function includes a first attenuation function and a second attenuation function; accordingly, determining the attenuation factor based on the attenuation function includes: when the model training parameters meet the preset parameter threshold, determining the attenuation factor according to the first attenuation function; when the model training parameters do not meet the preset parameter threshold, determining the attenuation factor according to the second attenuation function; wherein there is a difference between the first attenuation function and the second attenuation function.
[0081] The attenuation function can also be a combination function composed of multiple attenuation functions with differences, that is, the attenuation function includes at least a first attenuation function and a second attenuation function. The difference between the first attenuation function and the second attenuation function includes, but is not limited to, one or more of the constants in the function, the types of functions, and the like. The first attenuation function and the second attenuation function can be at least one of a variety of functions such as a constant, an exponential function, a linear function, and a cosine annealing function. As needed, the attenuation function of the present method can also include a third attenuation function and a fourth attenuation function, which will not be described in detail below. It should be supplemented that the combined attenuation function formed by the multiple attenuation functions of the present method is a continuous function.
[0082] When constructing the attenuation function, the method can reduce the value of the attenuation factor obtained by the attenuation function as the model training parameters increase, or increase the value of the attenuation factor obtained by the attenuation function as the model training parameters increase. The method processes the model training parameters in segments, and the model training parameters of different segments correspond to different attenuation factors. In a specific implementation, two attenuation functions can be constructed according to the model training time step. When the value of the model training time step is low, a constant with a value close to or equal to 1 is used as the attenuation factor, so that the approximate range of the model parameters can be quickly determined based on the adversarial disturbance. As the value of the model training time step increases, a smaller value is used as the attenuation factor to improve the accuracy of the model parameters.
[0083] In a specific implementation, the attenuation function may be:
[0084]
[0085] Wherein, ∈(ts) is the attenuation factor, ∈(ts) is 0≤α≤1, ts represents the model training time step; wts represents the model training segmented time step; wherein the model training segmented time step is less than the preset model training total time step, a is a constant, and a takes a value of 0≤α≤1. In a specific implementation, α can often take a value of 0.8, and wts takes a value of the preset model training total time step * 0.8. In another implementation scenario, the attenuation factor can also be determined based on the value of the third gradient, that is, the model training time step in the above scenario is replaced by a variable corresponding to the third gradient.
[0086] Figure 5 A schematic diagram of the implementation flow of a training device of another embodiment model of the present application.
[0087] A second aspect of an embodiment of the present application provides a model training device, the device comprising: a determination module 501, used to determine an adversarial disturbance based on a first model and an original sample; the determination module 501 is also used to determine a first gradient based on the original sample, the adversarial disturbance and an attenuation factor; wherein the attenuation factor is used to reduce the impact of the adversarial disturbance on the first gradient; an update module 502, used to update the first model according to the first gradient to obtain a second model.
[0088] According to another embodiment of the present application, the determination module 501 includes: a determination submodule 5011, used to determine a first loss function based on the first model and the original sample; a training submodule 5012, used to back-propagate training the first model based on the first loss function and the original sample to obtain a third model and a second gradient; the determination submodule 5011 is also used to determine adversarial perturbations based on the first loss function and the second gradient.
[0089] According to another embodiment of the present application, the determination submodule 5011 is further configured to determine a virtual sample according to the adversarial disturbance and the original sample;
[0090] The determination submodule 5011 is further used to determine a second loss function according to the third model and the virtual sample;
[0091] The training submodule 5012 is further used to perform back propagation training on the third model according to the second loss function and the virtual sample to obtain a fourth model and a third gradient;
[0092] The determination submodule 5011 is further configured to determine the first gradient according to the attenuation factor and the third gradient.
[0093] According to another embodiment of the present application, the updating module 502 includes: a restoring submodule 5021, used to restore the target parameters of the fourth model according to the third model to obtain the fifth model; and an updating submodule 5022, used to update the fifth model according to the first gradient to obtain the second model.
[0094] According to another embodiment of the present application, the determination module 501 is further configured to determine an attenuation function, and determine an attenuation factor based on the attenuation function.
[0095] According to another embodiment of the present application, the determination module 501 is further used to determine the attenuation function according to the model training parameters corresponding to the first model, and determine the attenuation factor based on the attenuation function; wherein the model training parameters are at least one of the model training time and the number of model training times.
[0096] According to another embodiment of the present application, the attenuation function includes a first attenuation function and a second attenuation function; accordingly, the determination submodule 5011 is also used to determine the attenuation factor according to the first attenuation function when the model training parameters meet the preset parameter threshold; the determination submodule 5011 is also used to determine the attenuation factor according to the second attenuation function when the model training parameters do not meet the preset parameter threshold; wherein there is a difference between the first attenuation function and the second attenuation function.
[0097] According to another embodiment of the present application, the determination module 501 is further used to determine the second model as the first model; the device also includes: a return module 503, which is used to return to execute the determination of the adversarial disturbance based on the first model and the original sample.
[0098] According to another embodiment of the present application, the determination module 501 is also used to determine the loss value based on the second model; the determination module 501 is also used to determine the second model as the target model when the loss value meets the loss threshold; wherein the loss threshold is determined based on the model training parameters.
[0099] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or device including the element.
[0100] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as: multiple units or components can be combined, or can be integrated into another system, or some features can be ignored or not executed. In addition, the coupling, direct coupling, or communication connection between the components shown or discussed can be through some interfaces, and the indirect coupling or communication connection of the devices or units can be electrical, mechanical or other forms.
[0101] The units described above as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units; they may be located in one place or distributed on multiple network units; some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.
[0102] In addition, all functional units in the embodiments of the present application may be integrated into one processing unit, or each unit may be a separate unit, or two or more units may be integrated into one unit; the above-mentioned integrated units may be implemented in the form of hardware or in the form of hardware plus software functional units.
[0103] A person skilled in the art can understand that all or part of the steps of implementing the above method embodiment can be completed by hardware related to program instructions, and the aforementioned program can be stored in a computer-readable storage medium. When the program is executed, it executes the steps of the above method embodiment; and the aforementioned storage medium includes: mobile storage devices, read-only memories (ROM), magnetic disks or optical disks, etc., various media that can store program codes.
[0104] Alternatively, if the above-mentioned integrated unit of the present application is implemented in the form of a software function module and sold or used as an independent product, it can also be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the embodiment of the present application can be essentially or partly embodied in the form of a software product that contributes to the prior art. The computer software product is stored in a storage medium, including several instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the methods described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as mobile storage devices, ROMs, magnetic disks, or optical disks.
[0105] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
Claims
1. A model training method, the method comprising: Determine an adversarial perturbation according to the first model and the original sample; Determine a first gradient according to the original sample, the adversarial disturbance and the attenuation factor; wherein the attenuation factor is used to reduce the influence of the adversarial disturbance on the first gradient; Update the first model according to the first gradient to obtain a second model; The method of determining the adversarial perturbation according to the first model and the original sample includes: determining a first loss function according to the first model and the original sample; back-propagation training the first model according to the first loss function and the original sample to obtain a third model and a second gradient; and determining the adversarial perturbation according to the first loss function and the second gradient.
2. The method according to claim 1, determining the first gradient according to the original sample, the adversarial disturbance and the attenuation factor, comprising: Determine a virtual sample according to the adversarial perturbation and the original sample; Determine a second loss function according to the third model and the virtual sample; Perform back propagation training on the third model according to the second loss function and the virtual sample to obtain a fourth model and a third gradient; A first gradient is determined according to the attenuation factor and the third gradient.
3. The method according to claim 2, updating the first model according to the first gradient to obtain a second model, comprising: Reducing the target parameters of the fourth model according to the third model to obtain a fifth model; The fifth model is updated according to the first gradient to obtain a second model.
4. The method according to claim 1, further comprising: A decay function is constructed, and a decay factor is determined based on the decay function.
5. The method according to claim 1, further comprising: constructing an attenuation function according to the model training parameters corresponding to the first model, and determining an attenuation factor based on the attenuation function; The model training parameter is at least one of the model training time and the number of model training times.
6. The method according to claim 5, wherein the attenuation function comprises a first attenuation function and a second attenuation function; Accordingly, determining the attenuation factor based on the attenuation function includes: When the model training parameter meets the preset parameter threshold, constructing the attenuation factor according to the first attenuation function; When the model training parameter does not meet the preset parameter threshold, constructing an attenuation factor according to the second attenuation function; There is a difference between the first attenuation function and the second attenuation function.
7. The method according to claim 1, further comprising: determining the second model as the first model; Return to determine the adversarial perturbation according to the first model and the original sample.
8. The method according to claim 1, after obtaining the second model, further comprising: determining a loss value according to the second model; When the loss value satisfies a loss threshold, determining the second model as a target model; Wherein, the loss threshold is determined according to the model training parameters.
9. A model training device, comprising: A determination module, used to determine the adversarial disturbance according to the first model and the original sample; The determination module is further used to determine the first gradient according to the original sample, the adversarial disturbance and the attenuation factor; wherein the attenuation factor is used to reduce the influence of the adversarial disturbance on the first gradient; An updating module, configured to update the first model according to the first gradient to obtain a second model; The determination module includes: a determination submodule, used to determine a first loss function based on the first model and the original sample; a training submodule, used to back-propagate training the first model based on the first loss function and the original sample to obtain a third model and a second gradient; a determination submodule, also used to determine the adversarial perturbation based on the first loss function and the second gradient.
