Method for generating model using training data, and electronic device
A method for generating a model includes: obtaining training data for training a target model, in which the training data includes labeled data and unlabeled data; obtaining a first output result by the target model based on the labeled data; obtaining a second output result by the target model based on the unlabeled data; and obtaining an optimized target model by optimizing the target model based on the first output result and the second output result.
1 . A method for generating a model, comprising:
obtaining training data for training a target model, wherein the training data comprises labeled data and unlabeled data;
obtaining a first output result by the target model based on the labeled data;
obtaining a second output result by the target model based on the unlabeled data; and
obtaining an optimized target model by optimizing the target model based on the first output result and the second output result;
wherein obtaining the optimized target model by optimizing the target model based on the first output result and the second output result, comprises: calculating a first loss value based on the first output result; calculating a second loss value based on the second output result; and obtaining the optimized target model by optimizing the target model based on the first loss value and the second loss value, wherein calculating the first loss value based on the first output result, comprises: calculating the first loss value based on a valid number of the labeled data, the first output result and labels for the labeled data, wherein the valid number of the labeled data is calculated based on part of the labeled data satisfying a preset condition, wherein the valid number (the number of representative samples) of the labeled data is
e
c
l
=
(
1
-
β
N
c
s
,
l
)
/
(
1
-
β
)
,
wherein β=(N s,l −l)/N s,l , wherein the first loss value is
CE
softmax
(
z
s
,
l
,
y
s
,
l
)
=
-
1
-
β
1
-
β
N
c
s
,
l
log
(
exp
(
z
y
s
,
l
)
∑
i
=
0
C
exp
(
z
i
s
,
l
)
)
,
N
c
s
,
l
is a number of labeled data for each category, N s,l is a total number of the labeled data, C is a number of categories, θ is variable parameter of the target model,
x
i
l
is sample of labeled data,
wherein the target model is configured to identify a target object, and the labeled data in the training data are images containing the target object, the label represents that the target object is present in a target object area of the image of the labeled data, the unlabeled data in the training data is an image containing the target object, and there is no label representing the target object in a target object area of the image of the unlabeled data, or
the target model is configured to identify image categories and to identify image contents, the contents comprise: people, animals, plants, buildings and natural scenes, the labeled data in the training data are images that are labeled with category information, the unlabeled data in the training data are images that are not labeled with category information, or
the target model is configured to process textual information, where the labeled data in the training dataset comprises text and corresponding labels, the unlabeled data comprises not labeled text.
2 . The method of claim 1 , wherein calculating the second loss value based on the second output result, comprises:
calculating the second loss value based on a valid number of the unlabeled data, the second output result and a weight factor for the unlabeled data, wherein the valid number of the unlabeled data is calculated based on part of the unlabeled data satisfying a preset condition.
3 . The method of claim 1 , wherein obtaining the optimized target model by optimizing the target model based on the first loss value and the second loss value, comprises:
obtaining a total loss value based on the first loss value and the second loss value; and
obtaining the optimized target model by optimizing the target model based on the total loss value.
4 . The method of claim 1 , wherein obtaining the training data for training the target model, comprises:
obtaining labeled raw data and unlabeled raw data;
obtaining the labeled data by adding first noise information to the labeled raw data; and
obtaining the unlabeled data by adding second noise information to the unlabeled raw data.
5 . The method of claim 4 , wherein the second noise information comprises the first noise information and third noise information, and an interference intensity of the third noise information is greater than an interference intensity of the first noise information.
6 . An electronic device, comprising:
at least one processor; and
a memory communicatively coupled to the at least one processor; wherein,
the memory stores instructions executable by the at least one processor, and when the instructions are executed by the at least one processor, the at least one processor is configured to:
obtain training data for training a target model, wherein the training data comprises labeled data and unlabeled data;
obtain a first output result by the target model based on the labeled data;
obtain a second output result by the target model based on the unlabeled data; and
obtain an optimized target model by optimizing the target model based on the first output result and the second output result;
wherein obtaining the optimized target model by optimizing the target model based on the first output result and the second output result, comprises: calculating a first loss value based on the first output result; calculating a second loss value based on the second output result; and obtaining the optimized target model by optimizing the target model based on the first loss value and the second loss value, wherein calculating the first loss value based on the first output result, comprises: calculating the first loss value based on a valid number of the labeled data, the first output result and labels for the labeled data, wherein the valid number of the labeled data is calculated based on part of the labeled data satisfying a preset condition, wherein the valid number (the number of representative samples) of the labeled data is
e
c
l
=
(
1
-
β
N
c
s
,
l
)
/
(
1
-
β
)
,
wherein β=(N s,l −l)/N s,l , wherein the first loss value is
CE
softmax
(
z
s
,
l
,
y
s
,
l
)
=
-
1
-
β
1
-
β
N
c
s
,
l
log
(
exp
(
z
y
s
,
l
)
∑
i
=
0
C
exp
(
z
i
s
,
l
)
)
,
N
c
s
,
l
is a number of labeled data for each category, N s,l is a total number of the labeled data, C is a number of categories, θ is variable parameter of the target model,
x
i
l
is sample of labeled data,
wherein the target model is configured to identify a target object, and the labeled data in the training data are images containing the target object, the label represents that the target object is present in a target object area of the image of the labeled data, the unlabeled data in the training data is an image containing the target object, and there is no label representing the target object in a target object area of the image of the unlabeled data, or
the target model is configured to identify image categories and to identify image contents, the contents comprise: people, animals, plants, buildings and natural scenes, the labeled data in the training data are images that are labeled with category information, the unlabeled data in the training data are images that are not labeled with category information, or
the target model is configured to process textual information, where the labeled data in the training dataset comprises text and corresponding labels, the unlabeled data comprises not labeled text.
7 . The electronic device of claim 6 , wherein the processor is configured to:
calculate the second loss value based on a valid number of the unlabeled data, the second output result and a weight factor for the unlabeled data, wherein the valid number of the unlabeled data is calculated based on part of the unlabeled data satisfying a preset condition.
8 . The electronic device of claim 6 , wherein the processor is configured to:
obtain a total loss value based on the first loss value and the second loss value; and
obtain the optimized target model by optimizing the target model based on the total loss value.
9 . The electronic device of claim 6 , wherein the processor is configured to:
obtain labeled raw data and unlabeled raw data;
obtain the labeled data by adding first noise information to the labeled raw data; and
obtain the unlabeled data by adding second noise information to the unlabeled raw data.
10 . The electronic device of claim 9 , wherein the second noise information comprises the first noise information and third noise information, and an interference intensity of the third noise information is greater than an interference intensity of the first noise information.
11 . A non-transitory computer-readable storage medium storing computer instructions, wherein the computer instructions are configured to cause a computer to implement a method for generating a model, the method comprising:
obtaining training data for training a target model, wherein the training data comprises labeled data and unlabeled data;
obtaining a first output result by the target model based on the labeled data;
obtaining a second output result by the target model based on the unlabeled data; and
obtaining an optimized target model by optimizing the target model based on the first output result and the second output result;
wherein obtaining the optimized target model by optimizing the target model based on the first output result and the second output result, comprises: calculating a first loss value based on the first output result; calculating a second loss value based on the second output result; and obtaining the optimized target model by optimizing the target model based on the first loss value and the second loss value, wherein calculating the first loss value based on the first output result, comprises: calculating the first loss value based on a valid number of the labeled data, the first output result and labels for the labeled data, wherein the valid number of the labeled data is calculated based on part of the labeled data satisfying a preset condition, wherein the valid number (the number of representative samples) of the labeled data is
e
c
l
=
(
1
-
β
N
c
s
,
l
)
/
(
1
-
β
)
,
wherein β=(N s,l −l)/N s,l , wherein the first loss value is
CE
softmax
(
z
s
,
l
,
y
s
,
l
)
=
-
1
-
β
1
-
β
N
c
s
,
l
log
(
exp
(
z
y
s
,
l
)
∑
i
=
0
C
exp
(
z
i
s
,
l
)
)
,
N
c
s
,
l
is a number of labeled data for each category, N s,l is
a total number of the labeled data, C is a number of categories, θ is variable parameter of the target model,
x
i
l
is sample of labeled data,
wherein the target model is configured to identify a target object, and the labeled data in the training data are images containing the target object, the label represents that the target object is present in a target object area of the image of the labeled data, the unlabeled data in the training data is an image containing the target object, and there is no label representing the target object in a target object area of the image of the unlabeled data, or
the target model is configured to identify image categories and to identify image contents, the contents comprise: people, animals, plants, buildings and natural scenes the labeled data in the training data are images that are labeled with category information, the unlabeled data in the training data are images that are not labeled with category information, or
the target model is configured to process textual information, where the labeled data in the training dataset comprises text and corresponding labels, the unlabeled data comprises not labeled text.
12 . The storage medium of claim 11 , wherein calculating the second loss value based on the second output result, comprises:
calculating the second loss value based on a valid number of the unlabeled data, the second output result and a weight factor for the unlabeled data, wherein the valid number of the unlabeled data is calculated based on part of the unlabeled data satisfying a preset condition.
13 . The storage medium of claim 11 , wherein obtaining the optimized target model by optimizing the target model based on the first loss value and the second loss value, comprises:
obtaining a total loss value based on the first loss value and the second loss value; and
obtaining the optimized target model by optimizing the target model based on the total loss value.
14 . The storage medium of claim 11 , wherein obtaining the training data for training the target model, comprises:
obtaining labeled raw data and unlabeled raw data;
obtaining the labeled data by adding first noise information to the labeled raw data; and
obtaining the unlabeled data by adding second noise information to the unlabeled raw data.