Search method, electronic device and storage medium based on neural network model
A search method based on a neural network model is provided. The neural network model includes a semantic representation model, a recall model, and a ranking model. The present disclosure relates to the field of artificial intelligence, and in particular to the technical field of search. An implementation of the method comprises: inputting a target search and a plurality of objects to be matched to the semantic representation model to obtain a first output of the semantic representation model; inputting the first output of the semantic representation model to the recall model, and obtaining at least one recall object matching the target search from the plurality of objects to be matched by using the recall model; and inputting a second output of the semantic representation model to the ranking model, and obtaining a matching value of each of the at least one recall object by using the ranking model.
1 . A search method based on a neural network model, the neural network model comprising a semantic representation model, a recall model, and a ranking model, and the method being performed by an electronic device and comprising:
inputting, to the semantic representation model shared by both the recall model and the ranking model, a target search and a plurality of objects to be matched to obtain a first output of the semantic representation model, wherein the first output has a semantic understanding representation of recall and ranking;
inputting the first output of the semantic representation model to the recall model, and obtaining at least one recall object matching the target search from the plurality of objects to be matched by using the recall model, wherein the recall model makes a binary classification prediction on the plurality of objects to be matched to determine whether the plurality of objects to be matched match the target search;
inputting, to the semantic representation model shared by both the recall model and the ranking model, the target search and the at least one recall object matching the target search to obtain a second output of the semantic representation model, wherein the second output comprises a semantic understanding representation of recall and ranking; and
inputting the second output of the semantic representation model to the ranking model, and obtaining a matching value of each of the at least one recall object by using the ranking model.
2 . The method according to claim 1 , wherein the neural network model further comprises a feature extraction model, and the feature extraction model is configured to:
obtain, based on the first output of the semantic representation model, one or more recall objects and a matching value of each of the one or more recall objects.
3 . The method according to claim 2 , wherein operations for training the neural network model comprise operations for training the semantic representation model and the feature extraction model, operations for training the recall model, and operations for training the ranking model,
wherein the operations for training the semantic representation model and the feature extraction model comprises:
obtaining a first sample search and a first sample object, and marking a first real classification label and a first real matching value of the first sample object, wherein the first real classification label represents whether the first sample object matches the first sample search, and the first real matching value represents a degree of matching between the first sample object and the first sample search;
inputting the first sample search and the first sample object to the semantic representation model to obtain a third output of the semantic representation model;
inputting the third output of the semantic representation model to the feature extraction model to obtain a first predicted classification label and a first predicted matching value of the first sample object;
calculating a first loss value based on the first real classification label and the first real matching value of the first sample object and the first predicted classification label and the first predicted matching value of the first sample object; and
adjusting a parameter of the semantic representation model and a parameter of the feature extraction model based on the first loss value,
wherein the operations for training the recall model and the operations for training for the ranking model are performed in response to completion of training for the semantic representation model and the feature extraction model, and an input to the recall model and an input to the ranking model each comprises an output of the semantic representation model.
4 . The method according to claim 3 , wherein when performing at least one of the operations for training the recall model and the operations for training the ranking model, the parameter of the semantic representation model is fixed.
5 . The method according to claim 4 , wherein the operations for training the recall model comprises:
obtaining a second sample search and a second sample object, and marking a second real classification label of the second sample object, wherein the second real classification label represents whether the second sample object matches the second sample search;
inputting the second sample search and the second sample object to the semantic representation model to obtain a fourth output of the semantic representation model;
inputting the fourth output of the semantic representation model to the recall model to obtain a second predicted classification label of the second sample object;
calculating a second loss value based on the second real classification label of the second sample object and the second predicted classification label of the second sample object; and
adjusting a parameter of the recall model based on the second loss value.
6 . The method according to claim 5 , wherein the second sample object comprises a positive sample object that matches the second sample search and a negative sample object that does not match the second sample search.
7 . The method according to claim 4 , wherein the operations for training the ranking model comprises:
obtaining a third sample search and a third sample object matching the third sample search, and marking a second real matching value of the third sample object, wherein the second real matching value represents a degree of matching between the third sample object and the third sample search;
inputting the third sample search and the third sample object to the semantic representation model to obtain a fifth output of the semantic representation model;
inputting the fifth output of the semantic representation model to the ranking model to obtain a second predicted matching value of the third sample object;
calculating a third loss value based on the second real matching value of the third sample object and the second predicted matching value of the third sample object; and
adjusting a parameter of the ranking model based on the third loss value.
8 . The method according to claim 7 , wherein the second real matching value lies in an interval [0,1].
9 . The method according to claim 3 , wherein at least one of the recall model and the ranking model is a pre-trained model.
10 . The method according to claim 3 , wherein the first loss value comprises a first sub-loss value and a second sub-loss value, and the calculating the first loss value comprises:
calculating the first sub-loss value based on the first real classification label of the first sample object and the first predicted classification label of the first sample object;
calculating the second sub-loss value based on the first real matching value of the first sample object and the first predicted matching value of the first sample object; and
calculating the first loss value based on the first sub-loss value and a first weight thereof and the second sub-loss value and a second weight thereof,
wherein the operations for training the semantic representation model and the feature extraction model further comprises:
adjusting the first weight and the second weight based on the first loss value.
11 . The method according to claim 10 , wherein the first sample object comprises a positive example object that matches the first sample search and a negative example object that does not match the first sample search.
12 . An electronic device, comprising:
at least one processor; and
a memory communicatively connected to the at least one processor, wherein
the memory stores instructions executable by the at least one processor, and when executed by the at least one processor, the instructions cause the at least one processor to perform a method based on a neural network model including a semantic representation model, a recall model, and a ranking model, the method comprising:
inputting, to the semantic representation model shared by both the recall model and the ranking model, a target search and a plurality of objects to be matched to obtain a first output of the semantic representation model, wherein the first output has a semantic understanding representation of recall and ranking;
inputting the first output of the semantic representation model to the recall model, and obtaining at least one recall object matching the target search from the plurality of objects to be matched by using the recall model, wherein the recall model makes a binary classification prediction on the plurality of objects to be matched to determine whether the plurality of objects to be matched match the target search;
inputting, to the semantic representation model shared by both the recall model and the ranking model, the target search and the at least one recall object matching the target search to obtain a second output of the semantic representation model, wherein the second output comprises a semantic understanding representation of recall and ranking; and
inputting the second output of the semantic representation model to the ranking model, and obtaining a matching value of each of the at least one recall object by using the ranking model.
13 . The electronic device according to claim 12 , wherein the neural network model further comprises a feature extraction model, and the feature extraction model is configured to:
obtain, based on the first output of the semantic representation model, one or more recall objects and a matching value of each of the one or more recall objects.
14 . An electronic device, comprising:
at least one processor; and
a memory communicatively connected to the at least one processor, wherein
the memory stores instructions executable by the at least one processor, and when executed by the at least one processor, the instructions cause the at least one processor to perform the method according to claim 3 .
15 . The electronic device according to claim 14 , wherein when performing at least one of the operations for training the recall model and the operations for training the ranking model, the parameter of the semantic representation model is fixed.
16 . The electronic device according to claim 15 , wherein the operations for training the recall model comprises:
obtaining a second sample search and a second sample object, and marking a second real classification label of the second sample object, wherein the second real classification label represents whether the second sample object matches the second sample search;
inputting the second sample search and the second sample object to the semantic representation model to obtain a fourth output of the semantic representation model;
inputting the fourth output of the semantic representation model to the recall model to obtain a second predicted classification label of the second sample object;
calculating a second loss value based on the second real classification label of the second sample object and the second predicted classification label of the second sample object; and
adjusting a parameter of the recall model based on the second loss value.
17 . The electronic device according to claim 16 , wherein the second sample object comprises a positive sample object that matches the second sample search and a negative sample object that does not match the second sample search.
18 . The electronic device according to claim 15 , wherein the operations for training the ranking model comprises:
obtaining a third sample search and a third sample object matching the third sample search, and marking a second real matching value of the third sample object, wherein the second real matching value represents a degree of matching between the third sample object and the third sample search;
inputting the third sample search and the third sample object to the semantic representation model to obtain a fifth output of the semantic representation model;
inputting the fifth output of the semantic representation model to the ranking model to obtain a second predicted matching value of the third sample object;
calculating a third loss value based on the second real matching value of the third sample object and the second predicted matching value of the third sample object; and
adjusting a parameter of the ranking model based on the third loss value.
19 . A non-transitory computer-readable storage medium storing computer instructions, wherein the computer instructions, when executed by one or more processors, are used to cause the computer to perform the method according to claim 1 .
20 . A non-transitory computer-readable storage medium storing computer instructions, wherein the computer instructions, when executed by one or more processors, are used to cause the computer to perform the method according to claim 3 .