Model training method and apparatus, device, and computer readable medium
By constructing pseudo-samples and removing spurious feature vectors from training samples, and training the initial model with unbiased feature vectors, the shortcut problem caused by data bias is solved, and the prediction accuracy of the model is improved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-06
- Publication Date
- 2026-03-31
AI Technical Summary
Existing intelligent model training methods are prone to shortcut problems due to data bias, resulting in low accuracy in practical applications.
By constructing pseudo-samples from the training samples, removing false features from the target hidden layer feature vectors of the training samples, and training the initial model using unbiased feature vectors until the total loss value meets the convergence condition, the target model is determined.
It improves the prediction accuracy of the model in practical applications, reduces the shortcut problem caused by data bias, and improves the error between the predicted label and the true label.
Smart Images

Figure CN116167459B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of artificial intelligence technology, and in particular to a model training method, apparatus, device, and computer-readable medium. Background Technology
[0002] In the current field of artificial intelligence, the training method for intelligent models is as follows: training samples are input into an initial model, which then obtains and outputs predicted labels corresponding to the training samples. The parameters of the initial model are then adjusted based on the error between the predicted and true labels until the error converges, resulting in an intelligent model that meets the requirements of the current scenario. Here, the predicted label corresponding to the training sample can be understood as the classification result predicted by the model for the training sample. Alternatively, the predicted label can be understood as the actual classification result corresponding to the training sample.
[0003] However, existing training methods for intelligent models are prone to shortcut problems due to data bias. This means that the intelligent model may rely on correlational characteristics that are not part of the deep decision-making logic to cheat and complete the training task. These correlational characteristics refer to the relationship between training samples and actual results. Deep decision-making logic refers to the knowledge points that developers actually want the model to learn. For example, an intelligent model trained in an image question-answering scenario might learn the shape of a banana and forcibly associate all bananas with yellow. However, if a green banana image is input into the intelligent model, it will use this learned shortcut to predict yellow. Therefore, the shortcut problem caused by data bias results in low accuracy and poor performance of intelligent models in practical applications. Summary of the Invention
[0004] In view of this, embodiments of the present invention provide a model training method, apparatus, device, and computer-readable medium to improve the prediction accuracy of the model in practical applications.
[0005] To achieve the above objectives, the embodiments of the present invention provide the following technical solutions:
[0006] Firstly, this application discloses a model training method, including:
[0007] Multiple training samples and corresponding pseudo samples from the training set are input into the initial model. The feature representation model of the initial model obtains and outputs the first hidden layer feature vector of each training sample and the second hidden layer feature vector of each pseudo sample. The pseudo samples corresponding to the training samples are different from some of the data in the training samples.
[0008] For each training sample, the target hidden feature vector of the training sample is removed from the first hidden feature vector of the training sample to obtain the unbiased feature vector of the training sample; wherein, the target hidden feature vector of the training sample is obtained by fusing at least the second hidden feature vector of the target pseudo-sample of the training sample; the target pseudo-sample of the training sample is used to refer to the pseudo-sample whose first predicted label is the same as the true label of the training sample among all pseudo-samples corresponding to the training sample; the first predicted label of the pseudo-sample is obtained by processing the second hidden feature vector of the pseudo-sample through the classifier of the initial model.
[0009] The unbiased feature vector of the training sample is input into the initial model, and the classifier of the initial model obtains and outputs the second predicted label of the training sample.
[0010] The parameters of the initial model are adjusted based on the total loss value of the initial model until the total loss value of the adjusted initial model meets the preset convergence condition. The adjusted initial model is then determined as the target model. The total loss value of the initial model is calculated based at least on the loss value between the second predicted label and the true label of each training sample. The target model is used to process the data to be predicted in a specific application scenario to obtain the target predicted label of the data to be predicted.
[0011] Optionally, in the above model training method, after inputting multiple training samples and pseudo-samples corresponding to each training sample into the initial model, the method further includes: inputting the first hidden layer feature vector of each training sample into the initial model, and obtaining and outputting the third predicted label of each training sample by the classifier of the initial model; and inputting the second hidden layer feature vector of each pseudo-sample into the initial model, and obtaining and outputting the first predicted label of each pseudo-sample by the classifier of the initial model.
[0012] The method for determining the total loss value of the initial model includes:
[0013] The total loss value of the initial model is calculated based on the first loss value, the weight value of the first loss value, the second loss value, the weight value of the second loss value, the third loss value, and the weight value of the third loss value; wherein, the first loss value is the total loss value between the first predicted label of all the pseudo samples corresponding to the training samples and the true label of the training samples; the second loss value is the total loss value between the second predicted label of all the training samples and the true label of the training samples; the third loss value is the total loss value between the third predicted label of all the training samples and the true label of the training samples; the weight values of the second loss value and the third loss value are both greater than the weight of the first loss value.
[0014] Optionally, in the above model training method, after inputting multiple training samples and pseudo-samples corresponding to each training sample into the initial model, the method further includes: inputting the first hidden layer feature vector of each training sample into the initial model, and obtaining and outputting the third predicted label of each training sample by the classifier of the initial model; and inputting the second hidden layer feature vector of each pseudo-sample into the initial model, and obtaining and outputting the first predicted label of each pseudo-sample by the classifier of the initial model.
[0015] The method for determining the total loss value of the initial model includes:
[0016] The first part of the loss value of the initial model is calculated based on the first loss value, the weight value of the first loss value, the second loss value, the weight value of the second loss value, the third loss value, and the weight value of the third loss value; wherein, the first loss value is the total loss value between the first predicted label of all the pseudo samples corresponding to the training samples and the true label of the training samples; the second loss value is the total loss value between the second predicted label of all the training samples and the true label of the training samples; the third loss value is the total loss value between the third predicted label of all the training samples and the true label of the training samples; the weight values of the second loss value and the third loss value are both greater than the weight of the first loss value;
[0017] The second part of the loss value of the initial model is calculated based on the degree of difference between the first hidden layer feature vector and the unbiased feature vector of all the training samples; wherein, the degree of difference between the first hidden layer feature vector and the unbiased feature vector of the training samples is positively correlated with the second part of the loss value.
[0018] The total loss value of the initial model is calculated using the first part of the loss value and the second part of the loss value of the initial model.
[0019] Optionally, in the above model training method, after adjusting the parameters of the initial model according to the total loss value of the initial model until the total loss value of the adjusted initial model meets the preset convergence condition, and then determining the adjusted initial model as the target model, the method further includes:
[0020] Multiple test samples from the test set are input into the target model, and the target model obtains and outputs the fourth predicted label for each test sample.
[0021] The prediction accuracy of the target model is calculated based on the error between the fourth predicted label of multiple test samples and the true label of the test samples; wherein, the prediction accuracy of the target model is used to verify whether the target model meets the usage requirements of the specific application scenario.
[0022] Optionally, in the above model training method, the method for constructing the target hidden layer feature vector of the training samples includes:
[0023] The average value of all target pseudo-samples corresponding to the training sample is calculated to obtain the target hidden layer feature vector of the training sample.
[0024] or,
[0025] The second hidden layer feature vectors of all target pseudo-samples corresponding to the training sample are input into a fully connected layer for fusion to obtain the target hidden layer feature vector of the training sample.
[0026] Optionally, in the above model training method, the method for constructing the target hidden layer feature vector of the training samples includes:
[0027] The target hidden layer feature vector of the training sample is obtained by averaging all pseudo samples corresponding to the training sample.
[0028] or,
[0029] The second hidden layer feature vectors of all pseudo samples corresponding to the training sample are input into a fully connected layer for fusion to obtain the target hidden layer feature vector of the training sample.
[0030] Optionally, in the above model training method, the method for constructing the pseudo-samples corresponding to the training samples includes:
[0031] Masking a portion of the data in the training samples yields pseudo samples corresponding to the training samples.
[0032] or,
[0033] By replacing a portion of the data in the training samples with data that is different from the original data, pseudo samples corresponding to the training samples are obtained.
[0034] Secondly, this application discloses a model training device, comprising:
[0035] The first prediction unit is used to input multiple training samples and pseudo samples corresponding to each training sample into the initial model, and obtain and output the first hidden layer feature vector of each training sample and the second hidden layer feature vector of each pseudo sample by the feature representation model of the initial model; wherein, the pseudo samples corresponding to the training samples are different from some data in the training samples.
[0036] The first processing unit is configured to, for each training sample, remove the target hidden layer feature vector of the training sample from the first hidden layer feature vector of the training sample to obtain the unbiased feature vector of the training sample; wherein, the target hidden layer feature vector of the training sample is obtained by fusing at least the second hidden layer feature vector of the target pseudo-sample of the training sample; the target pseudo-sample of the training sample refers to the pseudo-sample whose first predicted label is the same as the true label of the training sample among all pseudo-samples corresponding to the training sample; the first predicted label of the pseudo-sample is obtained by processing the second hidden layer feature vector of the pseudo-sample through the classifier of the initial model.
[0037] The second prediction unit is used to input the unbiased feature vector of the training sample into the initial model, and the classifier of the initial model obtains and outputs the second predicted label of the training sample.
[0038] An adjustment unit is used to adjust the parameters of the initial model according to the total loss value of the initial model until the total loss value of the adjusted initial model meets a preset convergence condition, and then the adjusted initial model is determined as the target model; wherein, the total loss value of the initial model is calculated at least based on the loss value between the second predicted label of each training sample and the true label of the training sample; the target model is used to process the data to be predicted in a specific application scenario to obtain the target predicted label of the data to be predicted.
[0039] Thirdly, this application discloses a computer-readable medium having a computer program stored thereon, wherein the program, when executed by a processor, implements the method described in any of the first aspects above.
[0040] Fourthly, this application discloses a model training device, comprising:
[0041] One or more processors;
[0042] A storage device on which one or more programs are stored;
[0043] When the one or more programs are executed by the one or more processors, the one or more processors cause the one or more processors to implement the method as described in any of the first aspects above.
[0044] Based on the model training method provided in the above embodiments of the present invention, for each training sample, the target hidden layer feature vector of the training sample is removed from the first hidden layer feature vector of the training sample to obtain the unbiased feature vector of the training sample. Since the target hidden layer feature vector of the training sample is obtained by fusing at least the second hidden layer feature vector of the target pseudo-sample of the training sample, and the target pseudo-sample of the training sample refers to the pseudo-sample whose first predicted label is the same as the true label of the training sample among all pseudo-samples corresponding to the training sample, and the pseudo-samples corresponding to the training sample are different from some data in the training sample, the target hidden layer feature vector of the training sample is a false feature generated by the initial model using the learned judgment shortcut, while the unbiased feature vector of the training sample obtained in this embodiment is equivalent to a vector that can represent the features of the training sample after the false features are eliminated. The target model determined by training the initial model with the unbiased feature vector, compared with the model trained by the existing training method, does not have the shortcut problem caused by data bias, and the error between the predicted target label and the true label is also lower, that is, the accuracy is higher. Attached Figure Description
[0045] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.
[0046] Figure 1 This is a schematic flowchart of a model training method proposed in an embodiment of this application;
[0047] Figure 2 This is a schematic diagram illustrating the construction process of a pseudo-sample according to an embodiment of this application;
[0048] Figure 3 This is a schematic diagram of a training task proposed in an embodiment of this application;
[0049] Figure 4 This is a flowchart illustrating a method for determining the total loss value of an initial model according to an embodiment of this application.
[0050] Figure 5This is a flowchart illustrating a testing method for a target model proposed in an embodiment of this application.
[0051] Figure 6 This is a flowchart illustrating a training method for a correction model proposed in an embodiment of this application.
[0052] Figure 7 This is a schematic diagram of the structure of a model training device proposed in an embodiment of this application. Detailed Implementation
[0053] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0054] In this application, the terms "comprising," "including," or any other variations thereof are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0055] To make the following descriptions of the embodiments clearer, the definitions of several terms involved in the embodiments of this application will be introduced first.
[0056] (1) Initial model, which can be understood as the model that needs to be trained, such as a neural network model or a model in the field of deep learning and machine learning.
[0057] (2) Target model: The model obtained by training the initial model. This target model can be applied to process the data to be predicted in a specific application scenario to obtain the target prediction label of the data to be predicted.
[0058] (3) The target prediction label is the classification result predicted by the target model based on the data to be predicted. For example, if the specific application scenario is automatic homework grading, the target prediction label is the homework score predicted by the target model.
[0059] (4) Training samples are samples used to train the initial model.
[0060] (5) The first hidden layer feature vector of the training sample is a vector used to represent the feature information of the training sample.
[0061] (6) The pseudo-samples corresponding to the training samples are samples that have some data different from and some data the same as the training samples.
[0062] (7) The second hidden layer feature vector of the pseudo sample corresponding to the training sample is a vector used to represent the feature information of the pseudo sample.
[0063] (8) The first predicted label of the pseudo sample, which is used to describe the predicted classification result of the pseudo sample.
[0064] (9) The target pseudo-sample of the training sample is the pseudo-sample whose first predicted label is the same as the real label of the training sample among all the pseudo-samples corresponding to the training sample.
[0065] (10) The target hidden layer feature vector of the training sample is a vector obtained by fusing at least the second hidden layer feature vector of the target pseudo sample of the training sample.
[0066] (11) The unbiased feature vector of the training sample is used to represent the feature information of the training sample. The difference from the feature vector of the first hidden layer is that the unbiased feature vector does not contain false features generated by the initial model using the learned judgment shortcut.
[0067] (12) The second predicted label of the training sample is the classification result of the training sample predicted by the initial model through the unbiased feature vector of the training sample.
[0068] (13) The true label of the training sample is the actual classification result of the training sample.
[0069] (14) The third predicted label of the training sample is the classification result of the training sample predicted by the initial model through the first hidden layer feature vector of the training sample.
[0070] (15) The fourth predicted label of the test sample is the classification result of the test sample predicted by the target model through the first hidden layer feature vector of the test sample. That is, the fourth predicted label of the test sample is used to explain the predicted classification result of the test sample.
[0071] See Figure 1 This application discloses a model training method, which specifically includes the following steps:
[0072] S101. Input multiple training samples and the pseudo samples corresponding to each training sample into the initial model. The feature representation model of the initial model obtains and outputs the first hidden layer feature vector of each training sample and the second hidden layer feature vector of each pseudo sample. The pseudo samples corresponding to the training samples are different from some of the data in the training samples.
[0073] Specifically, for each training sample in the training set, at least one pseudo-sample is constructed in advance. The pseudo-sample corresponding to a training sample differs from some data in the training sample and can be considered an incorrect training sample. If multiple pseudo-samples are constructed, each pseudo-sample can be distinct from the training sample; that is, each pseudo-sample differs from the training sample in different ways.
[0074] The initial model can be an untrained model or a trained model that requires incremental updates. The initial model includes a feature representation model and a classifier. The feature representation model outputs a vector that represents the feature information of the input data (e.g., training samples). The classifier predicts the corresponding classification result based on the vector representing the feature information.
[0075] The training samples in this application embodiment can vary according to different application scenarios. For example, if a user needs to train a grading model for automatic homework grading, the training sample can be text composed of three parts: "question," "standard answer," and "student's answer." Or, if a user needs to train a model with automatic question-and-answer functionality, the training sample can be the question text. The training samples in this application embodiment can be text, images, audio, video, etc., and this application embodiment does not limit the specific type of training samples.
[0076] Specifically, step S101 is executed as follows: Based on multiple training samples in a specific application scenario, at least one pseudo-sample is pre-constructed for each training sample. Then, each training sample in the training set is input into the feature representation model of the initial model to obtain and output the first hidden layer feature vector of the training sample. The pseudo-samples corresponding to each training sample are also input into the feature representation model of the initial model, and the feature representation model obtains and outputs the second hidden layer feature vector of the pseudo-sample corresponding to each training sample.
[0077] The first hidden feature vector of the training sample represents the feature information of the training sample. The second hidden feature vector of the corresponding pseudo-sample represents the feature information of the pseudo-sample. For the same training sample, since some data in the pseudo-sample differs from the training sample, the feature information represented by the second hidden feature vector of the corresponding pseudo-sample should theoretically include some erroneous features.
[0078] If the initial model is a model that requires incremental updates after training, i.e., the current scenario is incremental training, then in a specific embodiment of this application, the training set may include multiple historical training samples and multiple new training samples. Historical training samples refer to training samples used by the initial model during historical training. New training samples are training samples that have not been used to train the initial model. Historical training samples ensure that old knowledge points are not forgotten when training the initial model. In some embodiments, in an incremental training scenario, step S101 can be performed using all new training samples and multiple specific historical training samples. Specific historical training samples can be training samples randomly selected from all historical training samples, or they can be specially selected, representative training samples. This embodiment of the application does not limit the method of selecting training samples from the training set for use in step S101.
[0079] Optionally, in a specific embodiment of this application, the method for constructing pseudo-samples corresponding to training samples includes: masking a portion of the data in the training samples to obtain pseudo-samples corresponding to the training samples; or replacing a portion of the data in the training samples with data that is different from the original data to obtain pseudo-samples corresponding to the training samples.
[0080] Masking can be done by directly deleting part of the data, essentially hollowing out a portion of it. Alternatively, it can involve replacing part of the training sample data with a specific identifier. For example... Figure 2 As shown, Figure 2 The box on the left shows a training sample in an automated grading scenario. This training sample contains questions, standard answers, and student responses. All questions, standard answers, and student responses in this training sample are correct and complete. Based on the training sample shown in the box on the left, a pseudo-sample corresponding to the training sample shown in the box on the right can be constructed.
[0081] For example, see [link / reference] Figure 2 As shown in the right-hand box, compared to the training sample shown in the left-hand box, the text of the student's answer in this pseudo-sample uses an identifier such as "[MASK]" instead.
[0082] There are many ways to replace some data in the training samples with data that is different from the original data. For example, in a question-and-answer scenario, replacing the text of the labeled answer in the training sample with the text of other labeled answers can construct a pseudo-sample corresponding to that training sample. Another example is that during training, when different training tasks are executed, the ID of the training task is input into the initial model. In some embodiments, pseudo-samples can be constructed by modifying the input training task ID. A training task can be understood as the specific predictive ability that the initial model needs to learn. Because in some cases, the task-id itself reveals some special attributes of the task. For example, in a grading model's task scenario, task-0 might only score 0 points, task-10 might only score 10 points, etc., the model should not use the task-id for inference. Even if the first 10 tasks follow a pattern, it cannot be guaranteed that the 11th task will also follow this pattern. An ideal grading model should be general and have semantic judgment capabilities. Therefore, it is necessary to modify the input training task ID to construct pseudo-samples to prevent the model from using the task-id for inference.
[0083] For example Figure 3 As shown, taking an automatic grading scenario as an example, during the initial model training process, Task-0, Task-1, ..., Task-10 were established. The true labels of the training data (also called training samples) used in Task-0 are all 0 points, the true labels of the training data used in Task-1 are all 1 point, the true labels of the training data used in Task-2 are all 2 points, ..., the true labels of the training data used in Task-10 are all 10 points. However, during testing, the test data (i.e., test samples) used are samples from each learned score range. If the model takes a shortcut by using the task ID, the prediction effect of the model will not be very good during the testing phase. Therefore, to prevent the initial model from taking a shortcut by using the task ID to predict the true score of the training data, the task ID can be modified in a certain training task. For example, in Task-1, the task ID of a certain training data can be modified to Task-0, thus completing the construction of pseudo-samples.
[0084] Optionally, in a specific embodiment of this application, after inputting multiple training samples and corresponding pseudo-samples from the training set into the initial model, the method further includes: inputting the first hidden layer feature vector of each training sample into the initial model, and having the classifier of the initial model obtain and output the third predicted label of each training sample; and inputting the second hidden layer feature vector of each pseudo-sample into the initial model, and having the classifier of the initial model obtain and output the first predicted label of each pseudo-sample.
[0085] For each training sample, the first hidden layer feature vector obtained in step S101 is input into the classifier in the initial model. Then, the classifier in the initial model calculates the probability that the training sample belongs to each category based on the first hidden layer feature vector. The category with the highest probability is then determined as the classification result predicted by the initial model for the training sample. Finally, a third predicted label is output to represent the classification result predicted by the initial model for the training sample.
[0086] Similarly, this application also inputs the second hidden layer feature vector of the pseudo-sample corresponding to the training sample obtained in step S101 into the classifier in the initial model. Then, the classifier in the initial model calculates the probability of the pseudo-sample corresponding to the training sample belonging to each category based on the second hidden layer feature vector. Then, the category with the highest probability is determined as the classification result corresponding to the pseudo-sample predicted by the initial model, and finally, the first predicted label is output to represent the classification result corresponding to the pseudo-sample predicted by the initial model.
[0087] For example, such as Figure 2 As shown, the training samples in the left box were ultimately predicted to have a score of 0.5 by the classifier of the initial model (i.e., the third predicted label of the output was 0.5), while the pseudo samples corresponding to the training samples in the right box were ultimately predicted to have a score of 0.5 by the classifier of the initial model (i.e., the first predicted label of the output was 0.5).
[0088] As described above regarding the second hidden layer feature vector, the feature information it describes contains erroneous features, essentially representing an incorrect training sample. If the initial model has learned deep judgment logic, it will not predict the true label of the erroneous training sample. For example, in a question-answering scenario, if the banana in the training sample is changed from yellow to green, and the initial model has learned deep judgment logic, it will not output a yellow result.
[0089] However, if the initial model, using the second hidden layer feature vector, can still predict the same first predicted label as the true label of the training sample, it indicates that the initial model used some decision shortcuts due to data bias during prediction, thus predicting the true label of the training sample. In this case, the features of the second hidden layer feature vector are spurious features represented by these shortcuts. For example, if the banana in the training sample is changed from yellow to green, the initial model, having learned some decision shortcuts from the normal training samples, will assume that bananas are yellow and predict yellow, thus predicting the true label of the originally correct training sample.
[0090] The steps described above can be understood as performing two training phases. One phase is the regular training phase, where training samples are input into the initial model to obtain the first hidden layer feature vector and a third predicted label based on the first hidden layer feature vector. The training samples used in this phase are all correct. The other phase is the attack training phase, where pseudo-samples corresponding to the training samples are input into the initial model to obtain the second hidden layer feature vector and a first predicted label based on the second hidden layer feature vector. The second hidden layer feature vector, represented by the pseudo-samples, attacks the initial model's judgment logic, allowing subsequent steps to eliminate the false features (also known as fake data) generated by the initial model during the attack training phase.
[0091] S102. For each training sample, remove the target hidden feature vector from the first hidden feature vector of the training sample to obtain the unbiased feature vector of the training sample. The target hidden feature vector of the training sample is obtained by fusing it at least with the second hidden feature vector of the target pseudo-sample. The target pseudo-sample refers to the pseudo-sample whose first predicted label is the same as the true label of the training sample among all pseudo-samples corresponding to the training sample. The first predicted label of the pseudo-sample is obtained by processing the second hidden feature vector of the pseudo-sample using the classifier of the initial model.
[0092] Since the target hidden feature vector of the training sample is obtained by fusing at least the second hidden feature vector of the target pseudo-sample of the training sample, and the target pseudo-sample of the training sample is the pseudo-sample whose first predicted label is the same as the real label of the training sample among all the pseudo-samples corresponding to the training sample, the essence of the aforementioned attack training phase is actually to construct pseudo-samples, but let the model predict the real label of the training sample, thereby capturing harmful data attributes.
[0093] As explained by the definition of target pseudo-samples, the second hidden layer feature vector of a target pseudo-sample is essentially some harmful data (or fake data) captured during the attack training phase. At least, the target hidden layer feature vector obtained by fusing the second hidden layer feature vector of the target pseudo-sample contains a fusion of various harmful data.
[0094] In step S102, the target hidden layer feature vector of the training sample is removed from the first hidden layer feature vector of the training sample. This is equivalent to removing the fused harmful data used by the initial model when representing the training sample from the first hidden layer feature vector. The unbiased feature vector of the training sample obtained in this way has already removed harmful data in the feature space. Therefore, the feature information of the training sample does not contain false features represented by the shortcut judgment method. Compared with the original first hidden layer feature vector, the feature representation of the training sample will be more accurate and appropriate. If the unbiased feature vector is used to train the initial model, the initial model can avoid using the shortcut judgment method to predict the result.
[0095] Optionally, one of the removal methods used in step S102 can be to subtract the target hidden layer feature vector of the training sample from the first hidden layer feature vector of the training sample for each training sample, thereby obtaining the unbiased feature vector of the training sample. After the subtraction operation, the unbiased feature vector no longer contains harmful or false feature information, and becomes an ideal and more accurate vector used to represent the features of the training sample.
[0096] Optionally, a weight value can be preset. This weight value is then subtracted from the target hidden layer feature vector to obtain the processed target hidden layer feature vector. Finally, the processed target hidden layer feature vector is subtracted from the first hidden layer feature vector of the training sample to obtain the unbiased feature vector of the training sample. To ensure that the unbiased feature vector more accurately represents the features of the training sample, the target hidden layer feature vector can be adjusted using weight values to prevent the loss of important feature information in the unbiased feature vector obtained after subtraction.
[0097] S103. Input the unbiased feature vector of the training sample into the initial model, and the classifier of the initial model obtains and outputs the second predicted label of the training sample.
[0098] After constructing the unbiased feature vector of the training sample in step S103, the unbiased feature vector of the training sample is input into the classifier of the initial model. The classifier of the initial model obtains and outputs the second predicted label of the training sample. That is, the classifier of the initial model predicts the classification result of the training sample based on the unbiased feature vector of the training sample. For example, the second predicted label is calculated through the classifier function in the initial model: y_i = classifier(H_i). Here, H_i is the unbiased feature vector of the i-th training sample, and y_i is the second predicted label of the i-th training sample. classifier() is the function used by the classifier to calculate the classification result.
[0099] The training process from steps S102 to S103 can be understood as the unbiased training phase. Using the first hidden layer feature vector constructed in the regular training phase and the second hidden layer feature vector constructed in the attack training phase, an unbiased feature vector, freed from harmful information, can be further constructed in the unbiased training phase. Training the initial model with this unbiased feature vector allows the initial model to learn deeper judgment logic, preventing it from using shortcut judgments to predict results due to data bias.
[0100] S104. Adjust the parameters of the initial model based on the total loss value of the initial model until the total loss value of the adjusted initial model meets the preset convergence condition. Then, determine the adjusted initial model as the target model. The total loss value of the initial model is calculated based on the loss value between the second predicted label and the true label of each training sample. The target model is used to process the data to be predicted in a specific application scenario to obtain the target predicted label of the data to be predicted.
[0101] The total loss value of the initial model can be understood as the total error of the initial model. After the processing of steps S101 to S103, the total loss value of the initial model can be determined. Then, the parameters of the initial model are adjusted according to the total loss value. After updating and adjusting the parameters of the initial model, steps S101 to S103 are repeated to recalculate the total loss value of the new initial model until the total loss value of the adjusted initial model meets the preset convergence condition, such as the total loss value being less than the preset value. Then, the adjusted initial model is determined as the target model.
[0102] Optionally, in a specific embodiment of this application, the total loss value of the initial model can be equal to the sum of the loss values between the second predicted labels of all training samples and the true labels of all training samples (i.e., the total loss value between the second predicted labels of all training samples and the true labels of all training samples). This is equivalent to training the model using only the error introduced by the unbiased feature vectors of the training samples in the prediction results.
[0103] For example, the loss value of the unbiased feature vector of a single training sample during training can be calculated using the first formula: loss-i = target-i * log(yi). loss-i is the loss value of the unbiased feature vector of the i-th training sample in the prediction process. target-i is the true label of the i-th training sample, and yi is the second predicted label of the i-th training sample. The total loss value of the unbiased feature vector of a training sample during training can be obtained by summing the loss values of the unbiased feature vectors of all training samples during training.
[0104] Optionally, in another specific embodiment of this application, the method for determining the total loss value of the initial model includes:
[0105] The total loss value of the initial model is calculated based on the first loss value, the weight value of the first loss value, the second loss value, the weight value of the second loss value, the third loss value, and the weight value of the third loss value.
[0106] The first loss value is the total loss between the first predicted label of the pseudo-samples corresponding to all training samples and the true label of the training samples. In other words, the first loss value can be understood as the error between the predicted result of the pseudo-samples corresponding to the training samples and the true result of the training samples.
[0107] The second loss value is the total loss between the second predicted label of all training samples and the true label of the training samples. In other words, the second loss value can be understood as the error between the prediction result obtained from the unbiased feature vector of the training samples and the true result of the training samples.
[0108] The third loss value is the total loss between the third predicted label of all training samples and the true label of the training samples. The weights of the second and third loss values are both greater than the weight of the first loss value. That is, the third loss value can be understood as the error between the prediction result obtained based on the first hidden layer feature vector of the training samples and the true result of the training samples.
[0109] It should be noted that when calculating the total loss value according to the first loss value, the weight value of the first loss value, the second loss value, the weight value of the second loss value, the third loss value, and the third loss value, in the process of constructing the target hidden layer feature vector of the training samples, it is not limited to using the target pseudo-samples corresponding to the training samples to construct the target hidden layer feature vector. Pseudo-samples corresponding to the training samples other than the target pseudo-samples can also be used to construct the target hidden layer feature vector together.
[0110] Specifically, the essence of the unbiased training phase mentioned above is to construct pseudo-samples corresponding to the training samples, but allow the model to predict the true labels of the training samples through the pseudo-samples, thereby capturing false features that are harmful to the initial model. Since the first loss value is used when calculating the total loss value, which is the total loss between the first predicted label of all pseudo-samples corresponding to the training samples and the true label of the training samples, adjusting the parameters of the initial model based on the total loss value will cause the error between the first predicted label of the pseudo-samples corresponding to the training samples and the true label of the training samples to converge. That is, after multiple training sessions, the first predicted label of many pseudo-samples corresponding to the training samples will be equal to the true label of the training samples. Therefore, it is not necessary to deliberately select pseudo-samples (i.e., target pseudo-samples) whose first predicted label is the same as the true label of the training samples to construct the target hidden layer feature vector.
[0111] For example, when the first loss value is used in calculating the total loss value, the method for constructing the target hidden layer feature vector of the training samples can include:
[0112] The target hidden layer feature vector of the training sample is obtained by averaging the values of all pseudo-samples corresponding to the training sample. Alternatively, the second hidden layer feature vectors of all pseudo-samples corresponding to the training sample are input into a fully connected layer for fusion to obtain the target hidden layer feature vector of the training sample.
[0113] The target hidden layer feature vector of the training sample obtained by the above method integrates the feature information of each pseudo sample corresponding to the training sample, which is equivalent to capturing the false features caused by the shortcut problem under various dimensions due to data bias.
[0114] It should be noted that if there is only one pseudo-sample in total, the pseudo-sample corresponding to the training sample is directly used as the target hidden layer feature vector. If there are multiple pseudo-samples corresponding to the training sample, the above method is used for fusion. Among the pseudo-samples corresponding to the training sample, there are target pseudo-samples corresponding to the training sample, and there may also be pseudo-samples that do not belong to the target pseudo-sample. However, after adjusting the parameters of the initial model using the first loss value, most subsequent pseudo-samples will become pseudo-samples that satisfy the definition of the target pseudo-sample.
[0115] For example, when the first loss value is not used in calculating the total loss value, since it is impossible to adjust the model parameters based on the total loss value to achieve convergence of the error between the first predicted label of the pseudo-sample corresponding to the training sample and the true label of the training sample, the method for constructing the target hidden layer feature vector of the training sample can include:
[0116] The target hidden feature vector of the training sample is obtained by averaging the values of all target pseudo-samples corresponding to the training sample. Alternatively, the second hidden feature vectors of all target pseudo-samples corresponding to the training sample are input into a fully connected layer for fusion to obtain the target hidden feature vector of the training sample.
[0117] Since the first loss value is not used when calculating the total loss value, the first predicted label predicted by the second hidden layer feature vector of the target pseudo-sample may not be close to the true label of the training sample. Therefore, when constructing the target hidden layer feature vector, only the target pseudo-sample is selected for fusion. The target hidden layer feature vector of the training sample obtained in the above way fuses the feature information of each target pseudo-sample corresponding to the training sample, which is equivalent to capturing the false features caused by the shortcut problem due to data bias in each dimension.
[0118] It should be noted that if there is only one target pseudo-sample in total, then the target pseudo-sample corresponding to the training sample is directly used as the target hidden layer feature vector. If there are multiple target pseudo-samples corresponding to the training sample, then the above method is used for fusion.
[0119] It should also be noted that the advantage of having a greater weight for both the second and third loss values than the first loss value is as follows: As described above, the second loss value reflects the error between the first predicted label of the pseudo-sample corresponding to the training sample and the true label of the training sample. If the weight of the second loss value is too large, the initial model will focus on training shortcut judgment logic caused by data bias. If its importance is equated with that of the second and third loss values, the initial model may actually use these false attributes for task inference. Therefore, the weights of the second and third loss values need to be greater than the weight of the first loss value. Both the second and third loss values are errors calculated using the feature vectors used to represent the training samples. Therefore, the second and third loss values are more important, especially the third loss value, which represents the prediction error generated by the unbiased feature vector. The unbiased feature vector of the training sample is the most idealized and most accurate vector to describe the training sample constructed in this application. Therefore, the weight of the third loss value can be set to the maximum or the same as the weight of the second loss value.
[0120] Optionally, in a specific embodiment of this application, the first loss value, the weight value of the first loss value, the second loss value, the weight value of the second loss value, the third loss value, and the weight value of the third loss value can be substituted into the second formula to calculate the total loss value of the initial model.
[0121] The second formula is: Loss = A * loss - 1 + B * loss - 2 + C * loss - 3. Where Loss is the total loss of the initial model, A is the weight value of the first loss value, and loss - 1 is the first loss value. B is the weight value of the second loss value, and loss - 2 is the second loss value. C is the weight value of the third loss value, and loss - 3 is the third loss value. For example, A can be 1, and B and C can be 10. The calculation methods for loss - 1, loss - 2, and loss - 3 can all be calculated using the same method as the first formula above, obtaining the loss value of a single training sample and then summing the total loss value of all training samples. This will not be elaborated further here.
[0122] As described above, the first hidden layer feature vector can be obtained during the normal training phase, and the unbiased feature vector can be obtained during the unbiased training phase. However, as can be seen from the process of obtaining the unbiased feature vector described above, this process relies on the intermediate result of the second hidden layer feature vector obtained during the attack training phase. Calculating the second hidden layer feature vector during the actual inference process of the final target model will consume a lot of computational resources and affect the model's inference speed.
[0123] Therefore, refer to Figure 4 In this embodiment of the application, through Figure 4 The method shown for determining the total loss value of the initial model aims to make the first hidden layer feature vector in the regular training phase as close as possible to the unbiased feature vector in the unbiased training phase. This allows for direct referencing of the regular training phase when using the target model, treating the data to be predicted in a specific application scenario as training samples in the regular training phase to obtain the target predicted label for the data to be tested. That is, using... Figure 4 After determining the total loss value as shown, and finally obtaining the target model, the data to be predicted in a specific application scenario can be input into the feature representation model of the target model to obtain and output the first hidden feature vector of the data to be predicted. Then, the first hidden feature vector of the data to be predicted is input into the classifier of the target model to obtain the target predicted label of the data to be predicted. The first hidden feature vector of the data to be predicted is used to describe the feature information of the data to be predicted. The target predicted label of the data to be predicted is used to describe the classification result predicted by the target model for the data to be predicted.
[0124] Specifically, Figure 4 The method for determining the total loss value of the initial model shown includes the following steps:
[0125] S401. Based on the first loss value, the weight value of the first loss value, the second loss value, the weight value of the second loss value, the third loss value, and the weight value of the third loss value, calculate the first part of the loss value of the initial model.
[0126] The first loss value is the total loss between the first predicted label of the pseudo-samples corresponding to all training samples and the real label of the training samples. The second loss value is the total loss between the second predicted label of all training samples and the real label of the training samples. The third loss value is the total loss between the third predicted label of all training samples and the real label of the training samples. The weights of the second and third loss values are both greater than the weight of the first loss value.
[0127] The execution process and principle of step S401 can refer to the aforementioned execution process and principle of "calculating the total loss value of the initial model based on the first loss value, the weight value of the first loss value, the second loss value, the weight value of the second loss value, the third loss value, and the weight value of the third loss value". The difference is that the result obtained by the aforementioned calculation is used as the total loss value of the initial model, while the calculation result obtained in step S401 is only used as a part of the total loss value of the initial model (referred to as the first part of the loss value of the initial model).
[0128] S402. Based on the degree of difference between the first hidden layer feature vector and the unbiased feature vector of all training samples, the second part of the loss value of the initial model is calculated, wherein the degree of difference between the first hidden layer feature vector and the unbiased feature vector of the training samples is positively correlated with the second part of the loss value.
[0129] Specifically, the greater the difference between the first hidden layer feature vector and the unbiased feature vector of the training samples, the larger the second part of the loss value, and consequently the larger the total loss value of the initial model. Conversely, the smaller the difference between the first hidden layer feature vector and the unbiased feature vector of the training samples, the smaller the second part of the loss value, and consequently the smaller the total loss value of the initial model. Since the calculation of the total loss value of the initial model takes into account the difference between the first hidden layer feature vector and the unbiased feature vector of all training samples, adjusting the parameters of the initial model using the total loss value of the initial model can make the difference between the first hidden layer feature vector and the unbiased feature vector smaller and smaller, making the first hidden layer feature vector closer to the ideal unbiased feature vector. Subsequently, in the actual use of the target model, it is no longer necessary to repeatedly infer the unbiased feature vector, saving the computational resources of the target model.
[0130] The calculation order of steps S401 to S402 is not limited in this embodiment.
[0131] An exemplary implementation of calculating the second part of the loss value of the initial model based on the degree of difference between the first hidden layer feature vector and the unbiased feature vector of all training samples includes:
[0132] Substitute the first hidden layer feature vector and unbiased feature vector of all training samples into the third formula to calculate the second part of the loss value of the initial model.
[0133] The third formula is: Wherein, Loss-KL represents the degree of difference between the first hidden feature vector and the unbiased feature vector of all training samples. p(x i q(x) is the first hidden feature vector of the i-th training sample. i) is the unbiased feature vector of the i-th training sample. N is the total number of training samples.
[0134] S403. Calculate the total loss value of the initial model using the first part of the loss value and the second part of the loss value of the initial model.
[0135] The weights of the first and second parts of the initial model's loss value can be set according to actual needs. For example, the weights of the first and second parts of the initial model's loss value can be set to be equal. That is, the total loss value of the initial model is: Loss = Loss - branch + Loss - kl. Here, Loss is the total loss value of the initial model, Loss - branch is the first part of the initial model's loss value, and Loss - kl is the second part of the initial model's loss value.
[0136] Optionally, see Figure 5 In a specific embodiment of this application, if the following is adopted Figure 4 The method shown determines the total loss value of the initial model. After executing step S104, the following steps are also included:
[0137] S501. Input multiple test samples from the test set into the target model, and the target model obtains and outputs the fourth predicted label for each test sample.
[0138] Because the second part of the loss value of the initial model calculated in step S402 mentioned above can make the first hidden layer feature vector close to the unbiased feature vector during the adjustment of the parameters of the initial model, and then in the stage of testing the final target model, it is only necessary to obtain the predicted classification result in the way of the conventional training stage, and the performance of the target model can be evaluated by the predicted classification result, without having to repeat the attack training and unbiased training stages in the testing stage to construct the unbiased feature vector, thus saving the amount of computation in the testing process.
[0139] Specifically, following the standard training process, multiple test samples from the test set are input into the target model. The feature representation model in the target model processes the test samples to obtain the first hidden feature vector. This first hidden feature vector represents the feature information of the test sample. Then, this first hidden feature vector is input into the classifier of the target model, which obtains and outputs the fourth predicted label for the test sample. This fourth predicted label describes the classification result predicted by the target model for the test sample.
[0140] S502. Based on the error between the fourth predicted label of multiple test samples and the true label of the test samples, the prediction accuracy of the target model is calculated, whereby the prediction accuracy of the target model is used to verify whether the target model meets the usage requirements of a specific application scenario.
[0141] The prediction accuracy of the target model can be calculated using the error between the fourth predicted label and the true label of some or all test samples. Specifically, the more test samples whose fourth predicted label matches the true label, the higher the prediction accuracy of the target model. After obtaining the prediction accuracy of the target model, it can be used to evaluate whether the target model meets the requirements of a specific application scenario. Higher prediction accuracy indicates that the target model is more capable of meeting the requirements of the specific application scenario.
[0142] Optionally, in another specific embodiment of this application, if not adopted Figure 4 The method shown determines the total loss value of the initial model. However, if the difference between the first hidden layer feature vector and the unbiased feature vector is not considered when calculating the total loss value, the final target model cannot obtain a first hidden layer feature vector similar to the unbiased feature vector. Therefore, during testing, it is necessary to refer to the training processes of regular training, attack training, and unbiased training. Specifically, after executing step S104, the following steps are also included:
[0143] Multiple test samples from the test set, along with their corresponding pseudo-samples, are input into the target model. The target model's feature representation model obtains and outputs the first hidden feature vector for each test sample and the second hidden feature vector for each corresponding pseudo-sample. For each test sample, the target hidden feature vector is removed from the first hidden feature vector to obtain the unbiased feature vector. This unbiased feature vector is obtained by fusing the second hidden feature vector of the target pseudo-sample. The target pseudo-sample refers to the pseudo-sample whose first predicted label matches the true label of the test sample among all its corresponding pseudo-samples. The first predicted label of the pseudo-sample is obtained by processing the second hidden feature vector of the pseudo-sample using the target model's classifier. The unbiased feature vector of the test sample is then input into the target model, where the classifier obtains and outputs the fourth predicted label. The prediction accuracy of the target model is calculated based on the error between the fourth predicted labels and the true labels of multiple test samples. This prediction accuracy is used to verify whether the target model meets the requirements of a specific application scenario.
[0144] The execution process and principle of obtaining the fourth predicted label of the test sample can be referred to the process and principle of obtaining and outputting the second predicted label of the test sample in steps S101 to S103 above, and will not be repeated here.
[0145] See Figure 6 To make the model training method described in the embodiments of this application clearer, the model training process of the shared grading model is described below, taking the target model as a shared grading model as an example, based on the model training method described in the embodiments of this application:
[0146] See Figure 6 During the regular training phase, training samples in the format of "question + standard answer + student answer" are input into a previously trained shared grading model to obtain the first hidden feature vector H-1 and the third predicted label y-1 of the training samples. During the attack training phase, four different pseudo-samples are created for each training sample. The first type of pseudo-sample masks the student answer in the training sample with "[MASK]", the second type masks the standard answer in the training sample with "[MASK]", the third type masks both the standard answer and the student answer in the training sample with "[MASK]", and the fourth type modifies a specific task ID (Tsk-id) to construct the pseudo-sample. The first, second, third, and fourth pseudo-samples corresponding to the training samples are input into the shared grading model, yielding the second hidden layer feature vectors of the four pseudo-samples H-2, H-3, H-4, and H-5, and the first predicted labels of the four pseudo-samples y-2, y-3, y-4, and y-5, respectively. During the unbiased training phase, H-2, H-3, H-4, and H-5 are fused to obtain the target hidden layer feature vector H{2, 3, 4, 5} for the training samples. Then, for each training sample, the first hidden layer feature vector H-1 is used to subtract the target hidden layer feature vector H{2, 3, 4, 5} to obtain the unbiased feature vector H-6 for that training sample. Finally, the unbiased feature vector H-6 is input into the shared grading model to obtain the second predicted label y-6 for the training sample. For the different predicted labels obtained under the above training conditions, calculate the loss value between each predicted label and its corresponding true label, and obtain loss-1, loss-2, loss-3, loss-4, loss-5 and loss-6. Calculate the total loss value of the shared batching model based on loss-1, loss-2, loss-3, loss-4, loss-5 and loss-6, and then update the parameters of the shared batching model based on the total loss value until the total loss value of the shared batching model converges.
[0147] The specific process and execution principle described above can be found in the previous description of the model training method, and will not be repeated here.
[0148] It should be noted that the embodiments of this application can be applied to train target models for various specific application scenarios. The shared correction model mentioned above is only one of them. Target models such as question-and-answer scenarios can also be trained.
[0149] It should also be noted that, in the embodiments of this application, the parameters of the initial model can be adjusted using the error generated by the initial model in any training stage until the initial model converges, before proceeding to the next training stage. Alternatively, after all training stages, the parameters of the initial model can be adjusted using the total error generated by the initial model across all training stages until the initial model converges. In other words, there are many ways to adjust the parameters of the initial model in the embodiments of this application, and this application does not impose any limitations.
[0150] The model training method provided in this invention removes the target hidden layer feature vector from the first hidden layer feature vector of the training sample for each training sample, obtaining the unbiased feature vector of the training sample. Since the target hidden layer feature vector of the training sample is obtained by fusing at least the second hidden layer feature vector of the target pseudo-sample of the training sample, and the target pseudo-sample refers to the pseudo-sample whose first predicted label is the same as the true label of the training sample among all pseudo-samples corresponding to the training sample, and the pseudo-samples corresponding to the training sample are different from some data in the training sample, the target hidden layer feature vector of the training sample is a false feature generated by the initial model using a learned decision shortcut. The unbiased feature vector of the training sample obtained in this embodiment is equivalent to a vector that can represent the features of the training sample after the false features have been eliminated. The target model determined by training the initial model using the unbiased feature vector, compared to models trained by existing methods, does not have the shortcut problem caused by data bias, and the error between the predicted target label and the true label is also lower, i.e., higher accuracy.
[0151] See Figure 7 Based on the model training method proposed in the above embodiments of this application, this application discloses a model training device, including: a first prediction unit 701, a first processing unit 702, a second prediction unit 703, and an adjustment unit 704.
[0152] The first prediction unit 701 is used to input multiple training samples and the corresponding pseudo-samples from the training set into the initial model, and to obtain and output the first hidden layer feature vector of each training sample and the second hidden layer feature vector of each pseudo-sample from the feature representation model of the initial model. The pseudo-samples corresponding to the training samples differ from some of the data in the training samples.
[0153] The first processing unit 702 is used to remove the target hidden layer feature vector of the training sample from the first hidden layer feature vector of the training sample for each training sample, thereby obtaining the unbiased feature vector of the training sample. The target hidden layer feature vector of the training sample is obtained by fusing it at least with the second hidden layer feature vector of the target pseudo-sample of the training sample. The target pseudo-sample of the training sample refers to the pseudo-sample among all pseudo-samples corresponding to the training sample whose first predicted label is the same as the true label of the training sample. The first predicted label of the pseudo-sample is obtained by processing the second hidden layer feature vector of the pseudo-sample using the classifier of the initial model.
[0154] The second prediction unit 703 is used to input the unbiased feature vector of the training sample into the initial model, and the classifier of the initial model obtains and outputs the second predicted label of the training sample.
[0155] The adjustment unit 704 is used to adjust the parameters of the initial model based on the total loss value of the initial model until the total loss value of the adjusted initial model meets the preset convergence condition, at which point the adjusted initial model is determined as the target model. The total loss value of the initial model is calculated at least based on the loss value between the second predicted label and the true label of each training sample. The target model is used to process the data to be predicted in a specific application scenario to obtain the target predicted label for the data.
[0156] Optionally, in a specific embodiment of this application, it further includes: a third prediction unit and a first calculation unit.
[0157] The third prediction unit is used to input the first hidden layer feature vector of each training sample into the initial model, and the classifier of the initial model obtains and outputs the third predicted label of each training sample. It also inputs the second hidden layer feature vector of each pseudo-sample into the initial model, and the classifier of the initial model obtains and outputs the first predicted label of each pseudo-sample.
[0158] The first calculation unit is used to calculate the total loss value of the initial model based on the first loss value, the weight value of the first loss value, the second loss value, the weight value of the second loss value, the third loss value, and the weight value of the third loss value. The first loss value is the total loss between the first predicted label of all training samples and the true label of all training samples. The second loss value is the total loss between the second predicted label of all training samples and the true label of all training samples. The third loss value is the total loss between the third predicted label of all training samples and the true label of all training samples. The weight values of the second and third loss values are both greater than the weight of the first loss value.
[0159] Optionally, in a specific embodiment of this application, it further includes: a third prediction unit, a second calculation unit, a third calculation unit, and a fourth calculation unit.
[0160] The third prediction unit, after inputting multiple training samples and corresponding pseudo-samples from the training set into the initial model, further includes: inputting the first hidden layer feature vector of each training sample into the initial model, whereby the classifier of the initial model obtains and outputs the third predicted label for each training sample; and inputting the second hidden layer feature vector of each pseudo-sample into the initial model, whereby the classifier of the initial model obtains and outputs the first predicted label for each pseudo-sample.
[0161] The second calculation unit is used to calculate the first part of the loss value of the initial model based on the first loss value, the weight value of the first loss value, the second loss value, the weight value of the second loss value, the third loss value, and the weight value of the third loss value. The first loss value is the total loss between the first predicted label of all training samples and the true label of all training samples. The second loss value is the total loss between the second predicted label of all training samples and the true label of all training samples. The third loss value is the total loss between the third predicted label of all training samples and the true label of all training samples. The weight values of the second and third loss values are both greater than the weight of the first loss value.
[0162] The third computational unit is used to calculate the second part of the loss value of the initial model based on the degree of difference between the first hidden layer feature vector and the unbiased feature vector of all training samples. The degree of difference between the first hidden layer feature vector and the unbiased feature vector of the training samples is positively correlated with the second part of the loss value.
[0163] The fourth calculation unit is used to calculate the total loss value of the initial model using the first part of the loss value and the second part of the loss value of the initial model.
[0164] Optionally, in a specific embodiment of this application, it further includes:
[0165] The test unit is used to input multiple test samples from the test set into the target model, and the target model obtains and outputs the fourth predicted label for each test sample.
[0166] The fifth calculation unit is used to calculate the prediction accuracy of the target model based on the error between the fourth predicted label of multiple test samples and the true label of the test samples. The prediction accuracy of the target model is used to verify whether the target model meets the usage requirements of a specific application scenario.
[0167] Optionally, in a specific embodiment of this application, it further includes:
[0168] The fusion unit is used to calculate the average value of all target pseudo-samples corresponding to the training sample to obtain the target hidden layer feature vector of the training sample. Alternatively, the second hidden layer feature vectors of all target pseudo-samples corresponding to the training sample are input into a fully connected layer for fusion to obtain the target hidden layer feature vector of the training sample.
[0169] Optionally, in a specific embodiment of this application, it further includes:
[0170] The fusion unit is used to calculate the average of all pseudo-samples corresponding to the training sample to obtain the target hidden layer feature vector of the training sample. Alternatively, it inputs the second hidden layer feature vectors of all pseudo-samples corresponding to the training sample into a fully connected layer for fusion to obtain the target hidden layer feature vector of the training sample.
[0171] Optionally, in a specific embodiment of this application, it further includes:
[0172] The building block is used to mask a portion of the data in the training samples to obtain pseudo-samples corresponding to the training samples. Alternatively, it can replace a portion of the data in the training samples with data that is different from the original data to obtain pseudo-samples corresponding to the training samples.
[0173] The operation process of each unit and subunit in the model training device disclosed in this application can be found in the model training method disclosed in the embodiments of this application, and will not be repeated here.
[0174] This application discloses a computer-readable medium having a computer program stored thereon, wherein the program, when executed by a processor, implements any of the model training methods disclosed in the embodiments of this application.
[0175] This application discloses a model training device, comprising: one or more processors; a storage device storing one or more programs thereon; when the one or more programs are executed by the one or more processors, the one or more processors implement any of the model training methods disclosed in the embodiments of this application.
[0176] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, for system or system embodiments, since they are basically similar to method embodiments, the description is relatively simple, and relevant parts can be referred to the descriptions in the method embodiments. The systems and system embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without creative effort.
[0177] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of this invention.
[0178] The above description of the disclosed embodiments enables those skilled in the art to make or use the invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the invention. Therefore, the invention is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A model training method, characterized in that, The method comprises the following steps: inputting a plurality of training samples in a training set and a pseudo sample corresponding to each of the training samples into an initial model respectively, obtaining and outputting, by a feature representation model of the initial model, a first hidden layer feature vector of each of the training samples and a second hidden layer feature vector of each of the pseudo samples; wherein the pseudo sample corresponding to the training sample is different from part of data in the training sample; for each of the training samples, removing a target hidden layer feature vector of the training sample from the first hidden layer feature vector of the training sample to obtain an unbiased feature vector of the training sample; wherein the target hidden layer feature vector of the training sample is fused at least by a second hidden layer feature vector of a target pseudo sample of the training sample; the target pseudo sample of the training sample is used to refer to a pseudo sample in which a first predicted label of the pseudo sample is the same as a true label of the training sample among all the pseudo samples corresponding to the training sample; the first predicted label of the pseudo sample is obtained by processing the second hidden layer feature vector of the pseudo sample by a classifier of the initial model; inputting the unbiased feature vector of the training sample into the initial model, obtaining and outputting, by the classifier of the initial model, a second predicted label of the training sample; adjusting parameters of the initial model according to a total loss value of the initial model until the total loss value of the adjusted initial model meets a preset convergence condition, and determining the adjusted initial model as a target model; wherein the total loss value of the initial model is calculated at least according to a loss value between the second predicted label of each of the training samples and the true label of the training sample; the target model is used to process to-be-predicted data in a specific application scenario to obtain a target predicted label of the to-be-predicted data; wherein the specific application scenario includes an automatic homework grading scenario and a question and answer scenario.
2. The method of claim 1, wherein, After the plurality of training samples in the training set and the pseudo sample corresponding to each of the training samples are input into the initial model, the method further comprises the following steps: inputting the first hidden layer feature vector of each of the training samples into the initial model, obtaining and outputting, by the classifier of the initial model, a third predicted label of each of the training samples; and inputting the second hidden layer feature vector of each of the pseudo samples into the initial model respectively, obtaining and outputting, by the classifier of the initial model, a first predicted label of each of the pseudo samples; The method for determining the total loss value of the initial model comprises: The total loss value of the initial model is calculated according to the first loss value, the weight value of the first loss value, the second loss value, the weight value of the second loss value, the third loss value and the weight value of the third loss value; wherein the first loss value is the total loss value between the first predicted label of the pseudo sample corresponding to each of the training samples and the real label of the training sample; the second loss value is the total loss value between the second predicted label of each of the training samples and the real label of the training sample; the third loss value is the total loss value between the third predicted label of each of the training samples and the real label of the training sample; the weight value of the second loss value and the weight value of the third loss value are both greater than the weight of the first loss value.
3. The method of claim 1, wherein, After the plurality of training samples in the training set and the pseudo sample corresponding to each of the training samples are respectively input into the initial model, the method further comprises: inputting the first hidden layer feature vector of each of the training samples into the initial model, obtaining and outputting the third predicted label of each of the training samples by the classifier of the initial model; and inputting the second hidden layer feature vector of each of the pseudo samples into the initial model respectively, obtaining and outputting the first predicted label of each of the pseudo samples by the classifier of the initial model; The method for determining the total loss value of the initial model comprises: The first part loss value of the initial model is calculated according to the first loss value, the weight value of the first loss value, the second loss value, the weight value of the second loss value, the third loss value and the weight value of the third loss value; wherein the first loss value is the total loss value between the first predicted label of the pseudo sample corresponding to each of the training samples and the real label of the training sample; the second loss value is the total loss value between the second predicted label of each of the training samples and the real label of the training sample; the third loss value is the total loss value between the third predicted label of each of the training samples and the real label of the training sample; the weight value of the second loss value and the weight value of the third loss value are both greater than the weight of the first loss value; The second part loss value of the initial model is calculated according to the difference between the first hidden layer feature vector of each of the training samples and the unbiased feature vector; wherein the difference between the first hidden layer feature vector of the training sample and the unbiased feature vector is positively correlated with the second part loss value; The total loss value of the initial model is calculated by the first part loss value of the initial model and the second part loss value of the initial model.
4. The method of claim 3, wherein, After the parameters of the initial model are adjusted according to the total loss value of the initial model until the total loss value of the adjusted initial model meets the preset convergence condition, the adjusted initial model is determined as the target model, the method further comprises: The plurality of test samples in the test set are input into the target model, and the fourth predicted label of each of the test samples is obtained and output by the target model. The plurality of test samples in the test set are input into the target model, and the fourth predicted label of each of the test samples is obtained and output by the target model. According to errors between fourth prediction labels of the multiple test samples and true labels of the test samples, a prediction accuracy of the target model is calculated; wherein the prediction accuracy of the target model is used to verify whether the target model meets the use requirement of the specific application scenario.
5. The method according to any one of claims 1 to 4, characterized in that, The target hidden layer feature vector of the training sample is constructed in the following manner: averaging all target pseudo samples corresponding to the training sample to obtain the target hidden layer feature vector of the training sample; or, inputting the second hidden layer feature vectors of all target pseudo samples corresponding to the training sample into a full connection layer for fusion to obtain the target hidden layer feature vector of the training sample.
6. The method according to any one of claims 2 to 4, characterized in that, The target hidden layer feature vector of the training sample is constructed in the following manner: averaging all pseudo samples corresponding to the training sample to obtain the target hidden layer feature vector of the training sample; or, inputting the second hidden layer feature vectors of all pseudo samples corresponding to the training sample into a full connection layer for fusion to obtain the target hidden layer feature vector of the training sample.
7. The method of claim 1, wherein, The pseudo sample corresponding to the training sample is constructed in the following manner: masking part of data in the training sample to obtain the pseudo sample corresponding to the training sample; or, replacing part of data in the training sample with data different from the part of data to obtain the pseudo sample corresponding to the training sample.
8. A model training apparatus, comprising: The method comprises: a first prediction unit configured to input multiple training samples in a training set and pseudo samples corresponding to each of the training samples into an initial model, respectively, to obtain and output first hidden layer feature vectors of each of the training samples and second hidden layer feature vectors of each of the pseudo samples by a feature representation model of the initial model; wherein the pseudo samples corresponding to the training samples are different from part of data in the training samples; a first processing unit configured to, for each of the training samples, remove a target hidden layer feature vector of the training sample from the first hidden layer feature vector of the training sample to obtain an unbiased feature vector of the training sample; wherein the target hidden layer feature vector of the training sample is fused at least by second hidden layer feature vectors of target pseudo samples of the training sample; the target pseudo samples of the training sample refer to pseudo samples in which a first prediction label is the same as a true label of the training sample among all pseudo samples corresponding to the training sample; the first prediction label of the pseudo sample is obtained by processing the second hidden layer feature vector of the pseudo sample by a classifier of the initial model; a second prediction unit configured to input the unbiased feature vector of the training sample into the initial model to obtain and output a second prediction label of the training sample by a classifier of the initial model; An adjusting unit is configured to adjust parameters of the initial model according to a total loss value of the initial model until a total loss value of an adjusted initial model meets a preset convergence condition, and determine the adjusted initial model as a target model; wherein the total loss value of the initial model is calculated according to at least a loss value between a second prediction label of each training sample and a real label of the training sample; the target model is configured to process to-be-predicted data in a specific application scenario to obtain a target prediction label of the to-be-predicted data; wherein the specific application scenario includes an automatic homework grading scenario and a question and answer scenario.
9. A computer readable medium characterized by A computer program is stored thereon, wherein the program is executed by a processor to implement the method of any one of claims 1-7.
10. A model training device comprising: Comprising: one or more processors; a memory device having one or more programs stored thereon; when the one or more programs are executed by the one or more processors, the one or more processors implement the method of any one of claims 1-7.
Citation Information
Patent Citations
Cell detection method based on sliding window and depth structure extraction features
CN104346617A
Method and system for extracting ground object spatial spectral features of hyperspectral remote sensing image
CN108764005A