Method for training neural network and related device
Abstract
This disclosure discloses a method for training a neural network and a related device. The method includes: inputting a first sample subset into a first neural network, to generate first feature information and a first prediction result of a first query sample; generating a second prediction result of the first query sample based on second feature information corresponding to M groups of support samples included in a sample set, first labeling results corresponding to the M groups of support samples, and the first feature information, and training the first neural network. A first loss function indicates a similarity between the first prediction result and a second labeling result, and a second loss function indicates a similarity between the first prediction result and the second prediction result, or indicates a similarity between the second prediction result and the second labeling result.
Claims
exact text as granted — not AI-modified1 . A method for training a neural network, wherein the method comprises:
obtaining a first sample subset from a sample set, wherein the sample set comprises M groups of support samples, and the first sample subset comprises a first support sample and a first query sample; inputting the first sample subset into a first neural network, wherein the first neural network generates first feature information of the first query sample, and obtaining a first prediction result that corresponds to the first query sample and that is output by the first neural network, wherein the first prediction result is generated based on a similarity between feature information of the first support sample and the first feature information; generating a second prediction result corresponding to the first query sample based on second feature information corresponding to the M groups of support samples, first labeling results corresponding to the M groups of support samples, and the first feature information of the first query sample, wherein each of the first labeling results indicates a correct result corresponding to one of the M groups of support samples; and training the first neural network based on a first loss function and a second loss function, until a preset condition is met; wherein the first loss function indicates a similarity between the first prediction result and a second labeling result, and the second loss function indicates a similarity between the first prediction result and the second prediction result, or a similarity between the second prediction result and the second labeling result; and wherein the second labeling result is a correct result of the first query sample.
2 . The method according to claim 1 , wherein after the inputting the first sample subset into the first neural network, the method further comprises:
generating the feature information of the first support sample by using the first neural network, wherein the first support sample is selected from a first group, and the first group is one of the M groups; adding the feature information of the first support sample to a first queue of a feature information base, wherein the feature information base comprises M queues in one-to-one correspondence with the M groups of support samples, the first queue is a queue corresponding to the first group in the M queues, and is configured to store feature information corresponding to the first group of support samples; and before the generating a second prediction result corresponding to the first query sample based on second feature information corresponding to the M groups of support samples, first labeling results corresponding to the M groups of support samples, and the first feature information, the method further comprises: obtaining the second feature information corresponding to the M groups of support samples based on the feature information base.
3 . The method according to claim 2 , wherein a second queue is any queue in the M queues, the second queue comprises feature information of at least one support sample, and the obtaining the second feature information corresponding to the M groups of support samples based on the feature information base comprises:
averaging the feature information of all the support samples comprised in the second queue, to obtain one piece of second feature information corresponding to the second queue.
4 . The method according to claim 1 , wherein the generating the second prediction result corresponding to the first query sample based on second feature information corresponding to the M groups of support samples, first labeling results corresponding to the M groups of support samples, and the first feature information comprises:
performing a similarity calculation operation based on the second feature information and the first feature information, to obtain first similarity information, wherein the first similarity information indicates a similarity between the first query sample and each of the M groups of support samples; and generating the second prediction result based on the first similarity information and the first labeling results.
5 . The method according to claim 1 , wherein the first neural network is a neural network that classifies samples, the first sample subset comprises N categories of first support samples, and the first prediction result indicates a predicted category of the first query sample in the N categories; and
the generating a second prediction result corresponding to the first query sample based on second feature information corresponding to the M groups of support samples, first labeling results corresponding to the M groups of support samples, and the first feature information of the first query sample comprises: generating a first classification category based on the second feature information corresponding to the M groups of support samples, the first labeling results corresponding to the M groups of support samples, and the first feature information of the first query sample, wherein the first classification category indicates a predicted category of the first query sample in M categories; and obtaining the second prediction result from the first classification category, wherein the second prediction result indicates the predicted category of the first query sample in the N categories.
6 . The method according to claim 1 , wherein the first neural network is a neural network that performs regression on samples.
7 . The method according to claim 6 , wherein a grouping basis of the M groups is one or more of the following: users, locations, or time corresponding to the support samples.
8 . The method according to claim 6 , wherein at least one first support sample comprised in the first sample subset comes from a same group of the M groups, and at least one first query sample comprised in the first sample subset comes from a same group of the M groups.
9 . The method according to claim 1 , wherein the first neural network is any one of the following neural networks: a fully-connected neural network, a convolutional neural network, or a residual neural network.
10 . A sample processing method, wherein the method comprises:
obtaining a third support sample and a third query sample; and inputting the third support sample and the third query sample into a first neural network, to obtain a third prediction result that corresponds to the third query sample and that is output by the first neural network, wherein the third prediction result is generated based on a similarity between feature information of the third support sample and feature information of the third query sample, wherein the first neural network is obtained through training based on a first loss function and a second loss function, wherein the first loss function indicates a similarity between the prediction result output by the first neural network and a correct result, wherein the second loss function indicates a similarity between the prediction result output by the first neural network and a second prediction result corresponding to the third query sample, or, a similarity between the second prediction result and the correct result, wherein the second prediction result is obtained based on second feature information corresponding to M groups of support samples, correct results corresponding to the M groups of support samples, and the feature information of the third query sample, wherein the third support sample belongs to a third group of support samples, wherein the third query sample belongs to a third group of query samples, and wherein the third group is one of the M groups.
11 . A training device, comprising:
a processor; and a memory that stores program instructions, which, when executed by the processor, cause the training device to perform operations comprising: obtaining a first sample subset from a sample set, wherein the sample set comprises M groups of support samples, and the first sample subset comprises a first support sample and a first query sample; inputting the first sample subset into a first neural network, wherein the first neural network generates first feature information of the first query sample, and obtaining a first prediction result that corresponds to the first query sample and that is output by the first neural network, wherein the first prediction result is generated based on a similarity between feature information of the first support sample and the first feature information; generating a second prediction result corresponding to the first query sample based on second feature information corresponding to the M groups of support samples, first labeling results corresponding to the M groups of support samples, and the first feature information of the first query sample, wherein each of the first labeling results indicates a correct result corresponding to one of the M groups of support samples; and training the first neural network based on a first loss function and a second loss function, until a preset condition is met; wherein the first loss function indicates a similarity between the first prediction result and a second labeling result, and the second loss function indicates a similarity between the first prediction result and the second prediction result, or a similarity between the second prediction result and the second labeling result; and wherein the second labeling result is a correct result of the first query sample.
12 . The training device according to claim 11 , wherein after the inputting the first sample subset into the first neural network, the operations further comprises:
generating the feature information of the first support sample by using the first neural network, wherein the first support sample is selected from a first group, and the first group is one of the M groups; adding the feature information of the first support sample to a first queue of a feature information base, wherein the feature information base comprises M queues in one-to-one correspondence with the M groups of support samples, the first queue is a queue corresponding to the first group in the M queues, and is configured to store feature information corresponding to the first group of support samples; and before the generating a second prediction result corresponding to the first query sample based on second feature information corresponding to the M groups of support samples, first labeling results corresponding to the M groups of support samples, and the first feature information, the training device further comprises: obtaining the second feature information corresponding to the M groups of support samples based on the feature information base.
13 . The training device according to claim 12 , wherein a second queue is any queue in the M queues, the second queue comprises feature information of at least one support sample, and the obtaining the second feature information corresponding to the M groups of support samples based on the feature information base comprises:
averaging the feature information of all the support samples comprised in the second queue, to obtain one piece of second feature information corresponding to the second queue.
14 . The training device according to claim 11 , wherein the generating the second prediction result corresponding to the first query sample based on second feature information corresponding to the M groups of support samples, first labeling results corresponding to the M groups of support samples, and the first feature information comprises:
performing a similarity calculation operation based on the second feature information and the first feature information, to obtain first similarity information, wherein the first similarity information indicates a similarity between the first query sample and each of the M groups of support samples; and generating the second prediction result based on the first similarity information and the first labeling results.
15 . The training device according to claim 11 , wherein the first neural network is a neural network that classifies samples, the first sample subset comprises N categories of first support samples, and the first prediction result indicates a predicted category of the first query sample in the N categories; and
the generating a second prediction result corresponding to the first query sample based on second feature information corresponding to the M groups of support samples, first labeling results corresponding to the M groups of support samples, and the first feature information of the first query sample comprises: generating a first classification category based on the second feature information corresponding to the M groups of support samples, the first labeling results corresponding to the M groups of support samples, and the first feature information of the first query sample, wherein the first classification category indicates a predicted category of the first query sample in M categories; and obtaining the second prediction result from the first classification category, wherein the second prediction result indicates the predicted category of the first query sample in the N categories.
16 . The training device according to claim 11 , wherein the first neural network is a neural network that performs regression on samples.
17 . The training device according to claim 16 , wherein a grouping basis of the M groups is one or more of the following: users, locations, or time corresponding to the support samples.
18 . The training device according to claim 16 , wherein at least one first support sample comprised in the first sample subset comes from a same group of the M groups, and at least one first query sample comprised in the first sample subset comes from a same group of the M groups.
19 . The training device according to claim 11 , wherein the first neural network is any one of the following neural networks: a fully-connected neural network, a convolutional neural network, or a residual neural network.
20 . The training device according to claim 19 , wherein the first neural network is trained to execute a few-shot task.Join the waitlist — get patent alerts
Track US2023153619A1 — get alerts on status changes and closely related new filings.
We store only your email — no account needed. See our privacy policy.