Model training method and apparatus
By combining knowledge distillation algorithms and generative adversarial networks, and using teacher models to assist in training student models, the problem of balancing privacy protection and prediction accuracy in machine learning models is solved, achieving both privacy protection of training data and improvement of model prediction accuracy.
Patent Information
- Application Number
- CN202311124793.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-08-31
- Publication Date
- 2026-11-24
- Estimated Expiration
- 2043-08-31
AI Technical Summary
Existing technologies fall short in balancing privacy protection and prediction accuracy in machine learning models. Member inference attacks may lead to the leakage of training data, and conventional defense methods can compromise the model's prediction accuracy.
This paper employs a combination of knowledge distillation algorithm and generative adversarial network. The teacher model is trained by constructing multiple sample subsets, and the student model is trained by using the teacher model. The class labels are labeled using a dataset with the same distribution. The student model is trained by combining knowledge distillation algorithm to improve prediction accuracy, while hiding the training data.
While ensuring the accuracy of model predictions, the risk of training data leakage is reduced, the classification ability of student models is improved, and a balance between privacy protection and prediction accuracy is achieved.
Smart Images

Figure CN117150299B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of machine learning technology, and in particular to a model training method and apparatus. Background Technology
[0002] With the continuous development of machine learning technology, a lot of private data may be used in the training of machine learning models. Attacks targeting machine learning models may lead to the leakage of some private data used for model training.
[0003] Membership-based attacks are a common attack method targeting machine learning models. They infer whether a single data point or set of data participated in the model's training by querying the model's predictions, thus deducing relationships between the data. To mitigate the risk of training data leakage due to membership-based attacks, several privacy-preserving training methods have been proposed. However, many of these methods sacrifice predictive accuracy. For example, regularization methods, which add noise using differential privacy, may achieve privacy protection but struggle to guarantee prediction accuracy. Therefore, balancing the privacy of training data with the predictive accuracy of machine learning models is a crucial technical challenge that needs to be addressed by those skilled in the art. Summary of the Invention
[0004] In view of this, this application provides a model training method and apparatus to improve the privacy protection of the model's training data while ensuring the model's prediction accuracy.
[0005] To achieve the above objectives, this application provides a model training method, comprising:
[0006] Obtain a training sample set, which includes multiple first samples labeled with category labels;
[0007] Determine multiple sample subsets of the training sample set, wherein the sample subsets are part of the training sample set, and the multiple first samples in different sample subsets are not completely identical;
[0008] For each sample subset, a teacher model is trained using the first sample in the sample subset, resulting in multiple teacher models trained from the multiple sample subsets;
[0009] Obtain a dataset comprising multiple unlabeled second samples, and the dataset having the same data distribution as the training sample set;
[0010] For each second sample, the category features of the second sample are determined using each teacher model. Based on the category features of the second sample determined by each teacher model, the category label of the second sample is determined. The category features of the second sample are used to characterize the category to which the second sample belongs.
[0011] Based on each second sample in the dataset and its category label, a student model is trained using a knowledge distillation algorithm, and the trained student model is determined as a classification model for object classification.
[0012] In one possible implementation, obtaining the dataset includes:
[0013] A generative adversarial network is trained based on each first sample in the training sample set to obtain the trained generative adversarial network.
[0014] Multiple second samples are generated using the generator in the trained generative adversarial network, resulting in a dataset containing multiple second samples.
[0015] In another possible implementation, the step of training the student model using a knowledge distillation algorithm based on each second sample in the dataset and the category label of each second sample includes:
[0016] Based on the category represented by the category label of each second sample in the dataset, multiple second samples corresponding to different categories are selected from the dataset to obtain a data subset consisting of multiple selected second samples. The number of second samples corresponding to each category in the data subset is the same.
[0017] Based on each second sample and its category label in the aforementioned data subset, a student model is trained using a knowledge distillation algorithm.
[0018] In another possible implementation, the step of determining the category features of the second sample using each teacher model, and determining the category label of the second sample based on the category features determined by each teacher model, includes:
[0019] The category distribution vector of the second sample is determined using each teacher model;
[0020] The average value of the category distribution vectors of the second sample determined by each teacher model is used as the category label of the second sample.
[0021] In yet another possible implementation, determining multiple subsets of the training sample set includes:
[0022] The training sample set is divided into multiple initial subsets, and the first samples included in different initial subsets are different, and the difference in the number of first samples in different initial subsets is less than a set threshold.
[0023] For each initial subset, each first sample in the training sample set that does not belong to the initial subset is assigned to a sample subset, resulting in multiple sample subsets corresponding to multiple initial subsets.
[0024] In another possible implementation, the step of training the student model using a knowledge distillation algorithm based on each second sample in the dataset and the category label of each second sample includes:
[0025] For each second sample in the dataset, the second sample is input into the student model that needs to be trained to obtain the predicted category features of the second sample as predicted by the student model;
[0026] Based on the category labels and predicted category features of each second sample, the first loss function value of the student model is determined using the cross-entropy loss function;
[0027] Based on the category labels and predicted category features of each second sample, the value of the second loss function of the student model is determined using the distillation loss function;
[0028] Based on the first loss function value and the second loss function value, the comprehensive loss function value of the student model is determined;
[0029] Return to the operation of inputting the second sample into the student model to be trained, until the comprehensive loss function value of the student model converges or the number of training iterations reaches the set number, and the trained student model is obtained.
[0030] In another possible implementation, the student model has the same model structure as the teacher model.
[0031] In another aspect, this application also provides a model training apparatus, comprising:
[0032] A sample set acquisition unit is used to acquire a training sample set, wherein the training sample set includes multiple first samples labeled with category labels;
[0033] A subset determination unit is used to determine multiple sample subsets of the training sample set, wherein the sample subsets belong to a part of the training sample set, and the multiple first samples in different sample subsets are not completely identical;
[0034] The teacher model training unit is used to train a teacher model using the first sample in each sample subset, thereby obtaining multiple teacher models trained from the multiple sample subsets.
[0035] A dataset acquisition unit is used to acquire a dataset, which includes multiple second samples without category labels, and the dataset has the same data distribution as the training sample set;
[0036] The label determination unit is used to determine the category features of each second sample using each teacher model, and to determine the category label of the second sample based on the category features of the second sample determined by each teacher model. The category features of the second sample are used to characterize the category to which the second sample belongs.
[0037] The student model training unit is used to train a student model using a knowledge distillation algorithm based on each second sample and its category label in the dataset, and to determine the trained student model as a classification model for object classification.
[0038] In yet another possible implementation, the dataset acquisition unit includes:
[0039] An adversarial network training unit is used to train a generative adversarial network based on each first sample in the training sample set, thereby obtaining the trained generative adversarial network.
[0040] The dataset generation unit is used to generate multiple second samples using the generator in the trained generative adversarial network, resulting in a dataset containing multiple second samples.
[0041] In yet another possible implementation, the student model training unit includes:
[0042] The data filtering subunit is used to select multiple second samples corresponding to different categories from the dataset based on the category labels of each second sample in the dataset, and obtain a data subset consisting of multiple selected second samples, wherein the number of second samples corresponding to each category in the data subset is the same;
[0043] The student model training subunit is used to train the student model using a knowledge distillation algorithm based on each second sample and its category label in the data subset.
[0044] As can be seen from the above, in this embodiment, based on the knowledge distillation method, the trained teacher model is used to assist in training the student model, thereby improving the prediction accuracy of the trained student model and ensuring that the student model, as a classification model, has high prediction accuracy. In the process of using the teacher model to assist in training the student model in conjunction with the knowledge distillation algorithm, the student model is not directly trained using the training sample set used to train the teacher model. Instead, a dataset with the same distribution as the training sample set is used, and the student model is trained using the category features determined by each teacher model for each second sample in the dataset. Based on this, the trained student model is used as a classification model, thereby hiding the training sample set and the vulnerable teacher model, reducing the risk of training sample leakage.
[0045] Furthermore, this application combines the knowledge distillation algorithm with the idea of ensemble models. Based on the training sample set, multiple sample subsets are constructed, and teacher models are trained using these multiple sample subsets to obtain multiple trained teacher models. This weakens the information carried by a single teacher model. On this basis, the category features of the second sample in the dataset predicted by multiple teacher models are combined to label the second sample used to train the student model. This can further hide the information carried by each teacher model and reduce the risk of training data leakage. Attached Figure Description
[0046] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only embodiments of this application. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.
[0047] Figure 1 This paper illustrates a flowchart of a model training method provided in an embodiment of this application.
[0048] Figure 2 This illustration shows a schematic diagram of the principle of training a teacher model in an embodiment of this application;
[0049] Figure 3 This paper illustrates a schematic diagram of the implementation principle framework of the model training method in an embodiment of this application.
[0050] Figure 4 This illustration shows another flowchart of the model training method provided in an embodiment of this application;
[0051] Figure 5 This invention illustrates a flowchart of a student model training method provided in an embodiment of this application.
[0052] Figure 6A schematic diagram of the composition structure of a model training device provided in an embodiment of this application is shown. Detailed Implementation
[0053] The solution in this application embodiment can be applied to machine learning-based classification model training scenarios to reduce the risk of training data used to train classification models being leaked due to member inference attacks.
[0054] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of this application.
[0055] like Figure 1 The illustration shows a flowchart of a model training method provided in an embodiment of this application. The method of this embodiment can be applied to computer devices, which can be personal computers, independent servers, or node devices in systems such as cloud platforms, without limitation.
[0056] The method in this embodiment may include:
[0057] S101, obtain the training sample set.
[0058] The training sample set includes multiple first samples labeled with category labels.
[0059] The training sample set is private data used for model training, and therefore naturally belongs to data that needs to be protected from leakage.
[0060] For ease of distinction, this application refers to the samples in the training sample set as the first sample.
[0061] Understandably, the training sample set and the category labels of the samples in the training sample set will differ in different classification scenarios, and can be set according to actual needs. For ease of understanding, an example is provided:
[0062] Taking the training of an animal classification model as an example, the training sample set can be animal images of different animals, and the category label of the animal image can be the category of the animal in the image.
[0063] S102, determine multiple subsets of the training sample set.
[0064] Among them, the sample subsets are part of the training sample set, and the first samples in different sample subsets are not completely the same.
[0065] In this application, there are various ways to determine multiple sample subsets from the training sample set, and this application does not impose any restrictions on this.
[0066] For example, the training sample set can be divided equally to obtain multiple sample subsets.
[0067] Understandably, to ensure the prediction accuracy of subsequent teacher models, it is necessary to make the sample subsets as balanced in number as possible. While ensuring differences between different sample subsets, it is also necessary to ensure that the number of first samples in each sample subset is as large as possible. Based on this, in another possible implementation, this application can divide the training sample set into multiple initial subsets, with different first samples included in different initial subsets, and the difference in the number of first samples in different initial subsets is less than a set threshold. For example, multiple first samples in the training sample set can be evenly distributed into different initial subsets, with the number of first samples in different initial subsets being the same or differing by at most one. Furthermore, for each initial subset, each first sample in the training sample set that does not belong to that initial subset can be assigned to a sample subset, resulting in multiple sample subsets corresponding to multiple initial subsets.
[0068] In this context, each first sample in the training sample set that does not belong to the initial subset actually constitutes the complement of the initial subset. Therefore, the sample subset corresponding to the initial subset is also the complement of the initial subset.
[0069] S103, For each sample subset, the teacher model is trained using the first sample in the sample subset, resulting in multiple teacher models trained from multiple sample subsets.
[0070] For each sample subset, since each first sample in the subset is labeled with a category label, the teacher model can be trained in a supervised manner using each first sample in the subset to obtain the trained teacher model.
[0071] Understandably, the teacher model to be trained can be the same for each sample subset. However, due to the differences between different sample subsets, the internal parameters of the classroom model trained using different sample subsets will also differ.
[0072] For example, consider dividing the training sample set into multiple initial subsets, and then using the complement of each initial subset as the final sample subset. Figure 2 The example diagram shown illustrates the training of multiple teacher models.
[0073] exist Figure 2 In this context, the private training data serves as the training sample set. The private training data is then divided into multiple initial subsets, resulting in the following: Figure 2Multiple initial subsets, namely initial subsets D1, D2, ..., D... k , where k is the total number of initial subsets. Based on this, by determining the complement of each initial subset in the private training dataset, multiple sample subsets can be obtained. For example... Figure 2 As shown, the sample subset corresponding to the initial subset D1 is C. u D1, the sample subset corresponding to the initial subset D2 is C. u D2, and so on, initial subset D k The corresponding sample subset is C u D k .
[0074] exist Figure 2 Based on this, a separate classroom model is trained for each subset of samples, such as... Figure 2 The network model structure within each small box of the classroom model represents a classroom model. Correspondingly, by training teacher models with k initial subsets, k trained teacher models can be obtained.
[0075] In this application, there are no restrictions on the specific implementation of the training teacher model.
[0076] For example:
[0077] For each subset of samples, the first sample in each subset is sequentially input into the teacher model to be trained, and the predicted class result of the first sample is obtained by the teacher model. For example, the predicted class result can be the predicted class probability distribution, which includes the predicted probability that the first sample belongs to each class.
[0078] Accordingly, combining the category labels of each first sample and the predicted category, the loss function value L of the teacher model can be calculated using the cross-entropy loss function shown in Formula 1. CE :
[0079]
[0080] Where n is a natural number from 1 to N, N is the total number of the first samples in the sample subset, c is a natural number from 1 to C, C is the total number of classifiable categories, and p nc y represents the predicted probability that the nth sample in the sample subset belongs to the cth class; nc Let y be the probability that the nth sample belongs to the cth class, where if the nth sample is labeled as belonging to the cth class, then y nc The value is 1; otherwise, y nc The value of is 0.
[0081] Based on the above, the operation of inputting each first sample in the sample subset into the teacher model to be trained is repeated continuously until the loss function value of the teacher model converges or the number of training iterations reaches the set number.
[0082] Of course, the above is just one example. This embodiment also applies to other methods of training teacher models, and there are no limitations on them.
[0083] S104, Obtain the dataset.
[0084] The dataset includes multiple second samples without category labels, and it has the same data distribution as the training sample set.
[0085] In this application, to protect the privacy of the training sample set, the training sample set is not directly used to train subsequent student models, in order to reduce the student models' reliance on the training dataset. Instead, to train a student model with the same functionality as the teacher model, a dataset with the same distribution as the training sample set is required.
[0086] This dataset contains multiple data sets. For ease of distinction, the data in this dataset is referred to as the second sample. Since the dataset itself is not directly usable for training, the second samples in the dataset are not labeled. The classroom model is needed to help determine the category of each second sample in order to achieve category labeling of the second samples.
[0087] It is understood that this application may not impose any restrictions on the specific implementation of how the dataset is obtained.
[0088] In one possible implementation, considering that in real-world scenarios, collecting or obtaining a dataset with the same distribution as the training sample set is inconvenient or relatively complex, this application can also use a generator to generate the dataset in order to reduce the complexity of obtaining the dataset.
[0089] Specifically, a Generative Adversarial Network (GAN) can be trained based on the first samples in the training sample set to obtain the trained GAN.
[0090] Generative Adversarial Networks (GANs) consist of a generator G and a discriminator D (also known as a distinguisher). During the training of a GAN, the generator and the discriminator are trained alternately until a generator capable of generating a dataset similar to the training sample set is obtained.
[0091] For example, during the training of a generative adversarial network, a reference dataset of a set length and conforming to a specific distribution (such as the Zhengtai distribution) can be input into the generative adversarial network. The generator will output a generated dataset based on the reference dataset. This generated dataset will be input into the discriminator along with the real training sample set. The discriminator will then judge the authenticity of the generated dataset and each data in the training sample set. This process is repeated until the discriminator can no longer distinguish between the real and fake data in the generated dataset output by the generator and the data in the training sample set.
[0092] When training a generative adversarial network (GAN), the loss function min can be calculated using the following formula (Formula 2). G max D V(D,G):
[0093]
[0094] Where x represents any first sample in the training sample set, or represents the first sample x, p x (x) represents the data distribution of the training sample set. This indicates that the first sample in the training sample set conforms to the distribution p. x (x). D(x) represents the discriminant's judgment result for the first sample x. For example, if the judgment result is true, D(x) is 1, otherwise D(x) is 0.
[0095] Where z represents any data z in the reference dataset input to the generator, p z (z) represents the data distribution of the generated reference dataset, such as a normal distribution, etc. This indicates that the reference dataset conforms to the distribution p. z G(z) represents the generated data generated by the generator based on the data z in the reference dataset, and D(G(z)) represents the discriminant's judgment result on the generated data G(z) generated by the generator.
[0096] Of course, this is just a brief introduction to training generative adversarial networks, and this application does not impose any restrictions on the specific training process.
[0097] Accordingly, after training the generative adversarial network, this application can use the generator in the trained generative adversarial network to generate multiple second samples, thereby obtaining a dataset that includes multiple second samples.
[0098] For example, you can input the reference dataset used when training the generative adversarial network, or input other datasets or data vectors with the same length and distribution as the reference dataset, to obtain the dataset composed of various data output by the generator.
[0099] S105, For each second sample, the category features of the second sample are determined using each teacher model, and the category label of the second sample is determined based on the category features of the second sample determined by each teacher model.
[0100] The category feature of the second sample is used to characterize the category to which the second sample belongs.
[0101] In one possible implementation, the category feature can be the category to which the second sample belongs, determined by the teacher model. Correspondingly, the category label of the second sample can be the category that appears most frequently among the categories predicted by each teacher model.
[0102] For example, after inputting the second sample into the teacher model, a category probability distribution is obtained. This category probability distribution includes the probabilities that the second sample belongs to multiple different categories. Essentially, this category probability distribution is also a vector, which this application refers to as the category distribution vector. For instance, if the predicted probabilities of the second sample belonging to cat, dog, and deer are 0.7, 0.2, and 0.1 respectively, then the category probability distribution is represented as (0.7, 0.2, 0.1). Based on this, the category to which the second sample belongs can be determined based on the category probability distribution. For example, the category corresponding to the highest probability value in the category probability distribution can be determined as the category to which the second sample belongs.
[0103] In another possible implementation, considering that the category probability distribution contains more information and can more accurately reflect whether the second sample belongs to different categories, in order to improve the accuracy of the subsequently trained student model, this application uses the category feature as the category distribution vector of the second sample. Based on this, this application uses the average of the category distribution vectors of the second sample determined by each teacher model as the category label of the second sample. In this case, the category label of the second sample is also a vector, also known as a soft label.
[0104] Of course, there are other ways to determine the category label of the second sample using the teacher models, and there are no restrictions on this.
[0105] S106. Based on each second sample in the dataset and its category label, a student model is trained using a knowledge distillation algorithm, and the trained student model is determined as the classification model for object classification.
[0106] In training a student model using the knowledge distillation algorithm, it is necessary to consider not only the cross-entropy loss between the predicted class features of the second sample and the class label of the second sample, but also the distillation loss between the predicted class features of the second sample and the class label of the second sample.
[0107] In this application, the trained student model is used as the classification model for classification, thereby hiding the training sample data used to train the classroom model and the teacher model.
[0108] It is understood that, in this application, the student model's structure can be simpler than the teacher model's structure. In one alternative implementation, to further ensure the accuracy of the student model's classification, the student model has the same structure as the teacher model in this application. For example, both the teacher and student models can be convolutional neural networks or other network models with the same structure, without restriction.
[0109] As can be seen from the above, in this embodiment, based on the knowledge distillation method, the trained teacher model is used to assist in training the student model, thereby improving the prediction accuracy of the trained student model and ensuring that the student model, as a classification model, has high prediction accuracy. In the process of using the teacher model to assist in training the student model in conjunction with the knowledge distillation algorithm, the student model is not directly trained using the training sample set used to train the teacher model. Instead, a dataset with the same distribution as the training sample set is used, and the student model is trained using the category features determined by each teacher model for each second sample in the dataset. Based on this, the trained student model is used as a classification model, thereby hiding the training sample set and the vulnerable teacher model, reducing the risk of training sample leakage.
[0110] Furthermore, this application combines the knowledge distillation algorithm with the idea of ensemble models. Based on the training sample set, multiple sample subsets are constructed, and teacher models are trained using these multiple sample subsets to obtain multiple trained teacher models. This weakens the information carried by a single teacher model. On this basis, the category features of the second sample in the dataset predicted by multiple teacher models are combined to label the second sample used to train the student model. This can further hide the information carried by each teacher model and reduce the risk of training data leakage.
[0111] It is understood that, in the embodiments of this application, after obtaining the dataset, in order to reduce the impact of class imbalance on the accuracy of the student model, this application may also select multiple second samples corresponding to different categories from the dataset based on the category labels of each second sample in the dataset, and obtain a data subset consisting of multiple selected second samples, wherein the number of second samples corresponding to each category in the data subset is the same.
[0112] For example, the category labels of each second sample in the dataset represent different categories. For each category involved in the second samples of the dataset, a target number of second samples can be assigned to that category. This ensures that the number of second samples corresponding to each category in the final data subset is the same and meets the target number. This target number can be set as needed, such as 200.
[0113] Correspondingly, a student model can be trained using a knowledge distillation algorithm based on each second sample in the data subset and the category label of each second sample.
[0114] The following is based on Figure 3 The diagram shown illustrates one implementation principle of training a student model, and explains the process of the model training method of this application.
[0115] like Figure 4 As shown, it illustrates another flowchart of the model training method provided in this application embodiment. The method of this embodiment may include:
[0116] S401, obtain the training sample set.
[0117] The training sample set includes multiple first samples labeled with category tags;
[0118] S402 divides the training sample set into multiple initial subsets on an average basis.
[0119] The first samples included in different initial subsets are different, and the difference in the number of first samples in different initial subsets is less than a set threshold. The threshold can be set to 1, or other values as needed.
[0120] S403, for each initial subset, each first sample in the training sample set that does not belong to the initial subset is assigned to a sample subset, resulting in multiple sample subsets corresponding to multiple initial subsets.
[0121] S404, train a teacher model using the first sample in each sample subset, and obtain multiple teacher models trained from multiple sample subsets.
[0122] like Figure 3 As shown, the private training data (i.e., the training sample set) is first divided into multiple initial subsets, such as D1, D2, ... D... k Then, the complement of each initial subset is determined, resulting in k sample subsets for each initial subset. A classroom model is then trained using the first sample from each initial subset, resulting in k classroom models. This part is related to the previous steps. Figure 2 Similarly, please refer to the previous related introductions for details.
[0123] The above steps can be found in the relevant descriptions of the previous embodiments, and will not be repeated here.
[0124] It is understood that the above steps S402 to S404 are an example of one implementation method for training multiple teacher models. The other implementation methods mentioned above are also applicable to this embodiment.
[0125] S405, train the generative adversarial network based on each first sample in the training sample set to obtain the trained generative adversarial network.
[0126] S406 uses the generator in the trained generative adversarial network to generate multiple second samples, resulting in a dataset containing multiple second samples.
[0127] like Figure 3 As shown, this application trains both the teacher model and the generative adversarial network (GAN) using private training data (training sample set), thereby obtaining the generator in the trained GAN. Based on this, this application can use the generator to generate datasets (such as...). Figure 3 (X).
[0128] It should be noted that the above steps S405 and S406 can be executed synchronously with the preceding steps S402 to S404, or steps S402 to S404 can be executed first and then steps S405 and S406 can be executed, or steps S405 and S406 can be executed first and then steps S302 to S304 can be executed. There are no restrictions on this.
[0129] Steps S405 and S406 above are examples of one way to obtain a dataset. The other implementation methods mentioned above are also applicable to this embodiment.
[0130] S407, for each second sample in the dataset, use each teacher model to determine the category distribution vector of that second sample.
[0131] S408, for each second sample, the average value of the category distribution vectors of the second sample determined by each teacher model is used as the category label of the second sample.
[0132] Combination Figure 3 Explanation, in Figure 3 After the generator produces dataset X, each second sample in dataset X is still input into each teacher model to obtain the class distribution vector of the second sample determined by each teacher model. Based on this, for each second sample, an average vector is obtained by averaging the second class distribution vectors determined by each teacher model. This average vector is then used as the class label of the second sample, i.e., the soft label Y.
[0133] S409, Based on the category represented by the category label of each second sample in the dataset, select multiple second samples corresponding to different categories from the dataset to obtain a data subset composed of the selected multiple second samples.
[0134] In this subset of data, the number of second samples corresponding to each category is the same.
[0135] like Figure 3 As shown, after obtaining the dataset and determining the category labels of each second sample in the dataset, this application does not directly use each second sample and its category labels in the dataset to train the student model. Instead, it needs to determine and reconstruct a subset of data in which the data of the second samples corresponding to different categories are basically the same. Therefore, training the student model with each second sample in this subset of data can be more conducive to improving the accuracy of the student model's classification prediction.
[0136] S410, Based on each second sample and its category label in this data subset, train the student model using the knowledge distillation algorithm.
[0137] In the above embodiments of this application, there are various possibilities for the specific implementation of the student model using the knowledge distillation algorithm, and no limitation is imposed. For ease of understanding, the following explanation uses one implementation of training the student model as an example. Figure 5 The diagram illustrates a flowchart of training a student model using a knowledge distillation algorithm based on a dataset, as shown in this embodiment of the application. The method in this embodiment may include:
[0138] S501, for each second sample in the dataset, input the second sample into the student model that needs to be trained, and obtain the predicted category features of the second sample predicted by the student model.
[0139] For ease of distinction, the category features of the second sample predicted by the student model are referred to as the predicted category features.
[0140] Similar to the category features of the second sample determined by the teacher model above, the predicted category feature can be the predicted category probability distribution, or it can be the category to which the second sample belongs, determined based on the predicted category probability distribution. There are no restrictions on this.
[0141] It is understood that this embodiment uses training a student model based on a dataset as an example. In practical applications, if a subset of data is constructed based on the dataset, then... Figure 5 The datasets in each process can be replaced with subsets of data; this will not be elaborated further.
[0142] S502, based on the class labels and predicted class features of each second sample, uses the cross-entropy loss function to determine the first loss function value of the student model.
[0143] For ease of distinction, the loss function value of the student model determined using the cross-entropy loss function is referred to as the first loss function value.
[0144] The cross-generation loss function can be found in Formula 1 above, and will not be repeated here.
[0145] S503, based on the class labels and predicted class features of each second sample, the second loss function value of the student model is determined using the distillation loss function.
[0146] The distillation loss function for knowledge distillation can be expressed as follows: Formula 3:
[0147]
[0148] Among them, L KD (p(u,T),p(z,T)) represents the second loss function value of the student model.
[0149] Where i represents the i-th category, i is a natural number from 1 to M, and M is the total number of different categories corresponding to each second sample in the dataset, which is the total number of categories that the student model can classify.
[0150] Where T is a softening parameter in the knowledge distillation process.
[0151] Among them, u i p(u) represents the probability value of each second sample in the dataset labeled in the i-th category. i ,T) is the softening parameter T determined by combining knowledge distillation. i The normalized value.
[0152] Among them, z i p(z) represents the predicted probability value of each second sample in the dataset for the i-th class, as predicted by the student model. i (T) is the softening parameter T determined by combining knowledge distillation. i The normalized value.
[0153] For example, under normal circumstances, i.e., when knowledge distillation is not required, z i normalized value p(z) i This can be expressed as Formula Four:
[0154]
[0155] Where j is a natural number from 1 to M, z jThe predicted probability value of each second sample in the dataset for the i-th category, as predicted by the student model.
[0156] In knowledge distillation, considering T, then z i normalized value p(z) i (T) can be expressed as the following formula five:
[0157]
[0158] It is understandable that for p(u) i The process of finding T is similar and will not be repeated here.
[0159] S504. Based on the first loss function value and the second loss function value, determine the comprehensive loss function value of the student model.
[0160] In one possible implementation, a first weight corresponding to the first loss function value and a second weight corresponding to the second loss function value can be determined first. The first and second weights can be set according to actual needs. Considering that knowledge distillation loss contains more information, the second weight can be set relatively larger.
[0161] Accordingly, the weighted sum of the first loss function value and the second loss function value can be calculated by combining the first weight determined by the first loss function value and the second weight corresponding to the second loss function value to obtain the comprehensive loss function value.
[0162] For example, the comprehensive loss function value L of the student model stu This can be expressed as Formula Six below:
[0163] L stu =λL KD (p(u,T),p(z,T))+(1-λ)L s (y,p(z,1)) (Formula 6);
[0164] Where λ is the second loss function value L of the student model. KD The weights of (p(u,T),p(z,T)), L s (y,p(z,1)) represents the first loss function value of the student model.
[0165] S505, check if the comprehensive loss function value of the student model has converged or if the number of training iterations has reached the set number. If yes, training ends and the trained student model is determined as the classification model for classification. If no, return to step S501 until the comprehensive loss function value of the student model converges or the number of training iterations has reached the set number, and the trained student model is obtained.
[0166] For example, after each execution of step S504, the value of the comprehensive loss function determined in this round is stored, the number of training iterations is incremented by one, and then step S505 is executed until the value of the comprehensive loss function converges or the number of training iterations reaches the set number.
[0167] Corresponding to the model training method provided in the embodiments of this application, this embodiment also provides a model training device.
[0168] like Figure 6 The diagram illustrates a structural composition of a model training apparatus provided in an embodiment of this application. The apparatus in this embodiment may include:
[0169] The sample set acquisition unit 601 is used to acquire a training sample set, which includes a plurality of first samples labeled with category labels.
[0170] Subset determination unit 602 is used to determine multiple sample subsets of the training sample set, wherein the sample subsets belong to a part of the training sample set, and the multiple first samples in different sample subsets are not completely the same.
[0171] The teacher model training unit 603 is used to train a teacher model using the first sample in each sample subset, thereby obtaining multiple teacher models trained from the multiple sample subsets.
[0172] Dataset acquisition unit 604 is used to acquire a dataset, which includes multiple second samples without category labels, and the dataset has the same data distribution as the training sample set;
[0173] The label determination unit 605 is used to determine the category features of each second sample using each teacher model, and to determine the category label of the second sample based on the category features of the second sample determined by each teacher model. The category features of the second sample are used to characterize the category to which the second sample belongs.
[0174] The student model training unit 606 is used to train a student model using a knowledge distillation algorithm based on each second sample and its category label in the dataset, and to determine the trained student model as a classification model for object classification.
[0175] In one possible implementation, the dataset acquisition unit includes:
[0176] An adversarial network training unit is used to train a generative adversarial network based on each first sample in the training sample set, thereby obtaining the trained generative adversarial network.
[0177] The dataset generation unit is used to generate multiple second samples using the generator in the trained generative adversarial network, resulting in a dataset containing multiple second samples.
[0178] In yet another possible implementation, the student model training unit includes:
[0179] The data filtering subunit is used to select multiple second samples corresponding to different categories from the dataset based on the category labels of each second sample in the dataset, and obtain a data subset consisting of multiple selected second samples, wherein the number of second samples corresponding to each category in the data subset is the same;
[0180] The student model training subunit is used to train the student model using a knowledge distillation algorithm based on each second sample and its category label in the data subset.
[0181] In yet another possible implementation, the label-determining unit includes:
[0182] The vector determination subunit is used to determine the category distribution vector of each second sample using each teacher model;
[0183] The label determination subunit is used to determine the average value of the category distribution vectors of the second sample determined by each teacher model as the category label of the second sample.
[0184] In yet another possible implementation, the subset determination unit includes:
[0185] The sample set partitioning subunit is used to divide the training sample set into multiple initial subsets, wherein the first samples included in different initial subsets are different, and the difference in the number of first samples in different initial subsets is less than a set threshold.
[0186] The subset determination subunit is used to assign each first sample in the training sample set that does not belong to the initial subset to a sample subset for each initial subset, thereby obtaining multiple sample subsets corresponding to multiple initial subsets.
[0187] In another possible implementation, the student model training unit includes:
[0188] The feature sub-determination unit is used to input the second sample into the student model to be trained for each second sample in the dataset, and obtain the predicted category features of the second sample predicted by the student model.
[0189] The first loss determination unit is used to determine the first loss function value of the student model based on the category label and predicted category features of each second sample using the cross-entropy loss function.
[0190] The second loss determination unit is used to determine the second loss function value of the student model based on the category label and predicted category features of each second sample using the distillation loss function;
[0191] The comprehensive loss determination unit is used to determine the comprehensive loss function value of the student model based on the first loss function value and the second loss function value;
[0192] The loop control unit is used to return to the operation of inputting the second sample into the student model to be trained until the comprehensive loss function value of the student model converges or the number of training iterations reaches a set number, so as to obtain the trained student model.
[0193] It should be noted that the various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. Furthermore, the features described in the various embodiments of this specification can be substituted or combined with each other, enabling those skilled in the art to implement or use this application. For apparatus embodiments, since they are basically similar to method embodiments, the description is relatively simple; relevant parts can be referred to the descriptions of the method embodiments.
[0194] Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover 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 limitations, 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 the element.
[0195] The above description of the disclosed embodiments enables those skilled in the art to make or use this application. 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 this application. Therefore, this application 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.
[0196] The above are merely preferred embodiments of this application. It should be noted that those skilled in the art can make various improvements and modifications without departing from the principles of this application, and these improvements and modifications should also be considered within the scope of protection of this application.
Claims
1. A model training method, characterized in that, include: Obtain a training sample set, which includes multiple first samples labeled with category labels, wherein the samples are images; The training sample set is divided into multiple initial subsets, each initial subset containing a different first sample, and the difference in the number of first samples in different initial subsets is less than a set threshold. For each initial subset, each first sample in the training sample set that does not belong to the initial subset is assigned to a sample subset, resulting in multiple sample subsets corresponding to the multiple initial subsets. The sample subsets corresponding to the initial subsets are the complements of the initial subsets. The sample subsets are part of the training sample set, and the multiple first samples in different sample subsets are not completely identical. For each sample subset, a teacher model is trained using the first sample in the sample subset, resulting in multiple teacher models trained from the multiple sample subsets; A generative adversarial network is trained based on each first sample in the training sample set to obtain a trained generative adversarial network; multiple second samples are generated using the generator in the trained generative adversarial network to obtain a dataset including multiple second samples, wherein the dataset includes multiple second samples without category labels, and the dataset has the same data distribution as the training sample set. For each second sample, the category features of the second sample are determined using each teacher model, and the category features of the second sample are used to characterize the category to which the second sample belongs; the category distribution vector of the second sample is determined using each teacher model based on the category features of the second sample, and the category distribution vector characterizes the probability that the second sample belongs to each category; the average value of the category distribution vectors of the second sample determined by each teacher model is determined as the category label of the second sample. Based on each second sample and its category label in the dataset, a student model is trained using a knowledge distillation algorithm. This ensures that the training sample set is not directly used during the training process, and the trained student model is determined as a classification model for image classification, thereby improving the prediction accuracy of the student model.
2. The method according to claim 1, characterized in that, The step of training a student model using a knowledge distillation algorithm based on each second sample and its category label in the dataset includes: Based on the category represented by the category label of each second sample in the dataset, multiple second samples corresponding to different categories are selected from the dataset to obtain a data subset consisting of multiple selected second samples. The number of second samples corresponding to each category in the data subset is the same. Based on each second sample and its category label in the aforementioned data subset, a student model is trained using a knowledge distillation algorithm.
3. The method according to claim 1, characterized in that, The step of training a student model using a knowledge distillation algorithm based on each second sample and its category label in the dataset includes: For each second sample in the dataset, the second sample is input into the student model that needs to be trained to obtain the predicted category features of the second sample as predicted by the student model; Based on the category labels and predicted category features of each second sample, the first loss function value of the student model is determined using the cross-entropy loss function; Based on the category labels and predicted category features of each second sample, the value of the second loss function of the student model is determined using the distillation loss function; Based on the first loss function value and the second loss function value, the comprehensive loss function value of the student model is determined; Return to the operation of inputting the second sample into the student model to be trained, until the comprehensive loss function value of the student model converges or the number of training iterations reaches the set number, and the trained student model is obtained.
4. The method according to claim 1, characterized in that, The student model and the teacher model have the same model structure.
5. A model training device, characterized in that, include: A sample set acquisition unit is used to acquire a training sample set, which includes multiple first samples labeled with category labels, wherein the samples are images; A subset determination unit is used to determine multiple sample subsets of the training sample set, wherein the sample subsets belong to a part of the training sample set, and the multiple first samples in different sample subsets are not completely identical; The teacher model training unit is used to train a teacher model using the first sample in each sample subset, thereby obtaining multiple teacher models trained from the multiple sample subsets. The dataset acquisition unit is used to train a generative adversarial network based on each first sample in the training sample set to obtain a trained generative adversarial network; and to generate multiple second samples using the generator in the trained generative adversarial network to obtain a dataset including multiple second samples, wherein the dataset includes multiple second samples without category labels, and the dataset has the same data distribution as the training sample set. The label determination unit is used to determine the category features of each second sample using each teacher model, and to determine the category label of the second sample based on the category features of the second sample determined by each teacher model. The category features of the second sample are used to characterize the category to which the second sample belongs. The student model training unit is used to train a student model using a knowledge distillation algorithm based on each second sample and its category label in the dataset. This ensures that the training sample set is not directly used during the training of the student model, and the trained student model is determined as a classification model for image classification, thereby improving the prediction accuracy of the student model. The subset determination unit includes: The sample set partitioning subunit is used to divide the training sample set into multiple initial subsets, wherein the first samples included in different initial subsets are different, and the difference in the number of first samples in different initial subsets is less than a set threshold. The subset determination subunit is used to assign each first sample in the training sample set that does not belong to the initial subset to a sample subset for each initial subset, thereby obtaining multiple sample subsets corresponding to multiple initial subsets, wherein the sample subsets corresponding to the initial subsets are the complements of the initial subsets; The dataset acquisition unit includes: An adversarial network training unit is used to train a generative adversarial network based on each first sample in the training sample set, thereby obtaining the trained generative adversarial network. The dataset generation unit is used to generate multiple second samples using the generator in the trained generative adversarial network, resulting in a dataset containing multiple second samples. The label determination unit includes: The vector determination subunit is used to determine the category distribution vector of the second sample based on the category features of the second sample using each teacher model. The category distribution vector represents the probability that the second sample belongs to each category. The label determination subunit is used to determine the average value of the category distribution vectors of the second sample determined by each teacher model as the category label of the second sample.
6. The apparatus according to claim 5, characterized in that, The student model training unit includes: The data filtering subunit is used to select multiple second samples corresponding to different categories from the dataset based on the category labels of each second sample in the dataset, and obtain a data subset consisting of multiple selected second samples, wherein the number of second samples corresponding to each category in the data subset is the same; The student model training subunit is used to train the student model using a knowledge distillation algorithm based on each second sample and its category label in the data subset.
Citation Information
Patent Citations
CoVID-19 chest X-ray image classification learning-oriented training data privacy protection method
CN115482435A
