Model training method and device
By using a dual-tower correlation model, combined with unsupervised pre-training and manual annotation, the problem of insufficient training samples was solved, and more accurate correlation identification was achieved.
Patent Information
- Application Number
- CN202210448257.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-04-26
- Publication Date
- 2025-10-28
- Estimated Expiration
- 2042-04-26
AI Technical Summary
In existing technologies, due to the high cost of manual annotation, there are few training samples for relevance model training, resulting in inaccurate identification of relevance by the model. Furthermore, sample annotation based on user click behavior is prone to misleading the model, leading to significant noise.
A correlation model with a dual-tower structure is adopted. Feature distances are determined in the pre-training stage through unsupervised contrastive learning, and manual annotation is combined for training in the subsequent stage to adjust model parameters, reduce noise interference, and improve model performance.
By combining pre-training with a dual-tower structure with subsequent manual annotation, the features of query text and search results can be more accurately represented, improving the recognition accuracy and performance of the relevance model.
Smart Images

Figure CN114860876B_ABST
Abstract
Description
Technical Field
[0001] This specification relates to the field of search technology, and in particular to a model training method and apparatus. Background Technology
[0002] In search scenarios, search results are typically ranked based on their relevance to the query text entered by the user, as shown by the relevance model output.
[0003] Due to the high cost of manual annotation and the limited number of manually annotated training samples available for training relevance models, current methods primarily generate labels for training samples based on historical search logs. Typically, search results clicked by the user and recorded in the historical search logs are used as positive samples, labeled as related to their corresponding query text. Negative samples are determined through random sampling, and their labels are "irrelevant."
[0004] However, users consider many factors when clicking on search results, and the relevance between the query text and the search result is only one of them. If positive and negative samples are distinguished solely based on whether a user clicks on a search result, the relevance model may be misled into believing that search results clicked by users based on factors other than relevance are highly relevant to the query text, leading to inaccurate relevance identification by the model. Summary of the Invention
[0005] This specification provides a model training method and apparatus to partially solve the aforementioned problems existing in the prior art.
[0006] The following technical solution is adopted in this specification:
[0007] This specification provides a model training method. The relevance model with a dual-tower structure includes a query tower and a result tower, wherein the query tower and the result tower share parameters. The method includes:
[0008] Based on the search results set of each query text, each first sample is determined, which consists of the query text and its corresponding pair of search results;
[0009] For each first sample, each search result in the first sample is input into the result tower to obtain the first feature corresponding to each search result;
[0010] Input the query text from the first sample into the query tower to determine the two second features corresponding to the query text;
[0011] The contrast loss is determined based on the feature distance between the first features and the feature distance between the second features in each first sample, and the correlation model is pre-trained based on the contrast loss.
[0012] After pre-training is completed, the relevance model is trained again based on each second sample obtained by combining each query text with each search result, and the annotation of each second sample determined by the relevance between the query text and the search results in each second sample. The relevance model is used to determine the ranking of search results corresponding to the query text input by the user.
[0013] Optionally, the query text from the first sample is input into the query tower to determine two second features corresponding to the query text, specifically including:
[0014] Using the query tower, two similar texts of the query text are determined based on the query text in the first sample;
[0015] The features corresponding to the two similar texts are determined as the second features.
[0016] Optionally, the contrast loss is determined based on the feature distance between the first features and the feature distance between the second features in each first sample, specifically including:
[0017] For each first sample, the feature distance between each first feature within the first sample is determined as the first distance, and the feature distance between each first feature of the first sample and each pairwise first feature of other first samples is determined as the second distance.
[0018] Based on the first distance and each of the second distances, the result loss corresponding to the first sample is determined, wherein the first distance is positively correlated with the result loss, and the second distance is negatively correlated with the result loss;
[0019] The feature distance between each second feature within the first sample is determined as the third distance, and the feature distance between each second feature of the first sample and each pairwise second feature of the other first sample is determined as the fourth distance.
[0020] Based on the third distance and each of the fourth distances, the query loss corresponding to the first sample is determined, wherein the third distance is positively correlated with the query loss, and the fourth distance is negatively correlated with the query loss;
[0021] The comparison loss is determined based on the result loss and the query loss corresponding to each first sample.
[0022] Optionally, the result loss corresponding to the first sample is determined based on the first distance and each of the second distances, specifically including:
[0023] For each search result in the first sample, determine the corresponding result text, and generate each difficult sample corresponding to the search result based on the result text;
[0024] Each difficult sample is input into the result tower to determine the third feature corresponding to each difficult sample;
[0025] For each first feature of the first sample, the feature distance between the first feature and each third feature of the first sample is determined as each fifth distance;
[0026] Based on the first distance, each second distance, and each fifth distance corresponding to the first sample, determine the result loss corresponding to the first sample;
[0027] The fifth distance is negatively correlated with the resulting loss.
[0028] Optionally, for each search result in the first sample, the corresponding result text is determined, and based on the result text, each difficult sample corresponding to the search result is generated, specifically including:
[0029] Determine the type of the subject in the query text of the first sample, and use that as the type of the query text;
[0030] For each search result in the first sample, determine the result text of the search result, and determine the related text of the query text in the first sample contained in the result text;
[0031] Identify other query texts that belong to the same type as the query text in the first sample;
[0032] For each other query text, replace the relevant text with that other query text to obtain the replacement text;
[0033] Each replacement text is used as a hard sample corresponding to the search result.
[0034] Optionally, for each search result in the first sample, the corresponding result text is determined, and based on the result text, each difficult sample corresponding to the search result is generated, specifically including:
[0035] Determine the type of the subject in the query text of the first sample as the type of the query text, and determine other query texts that belong to the same type as the query text in the first sample;
[0036] For each search result in the first sample, determine the result text of the search result, and replace the result text with each of the other query texts to obtain the replacement text;
[0037] Each alternative text is used as a hard sample corresponding to the search result.
[0038] Optionally, the relevance model is further trained based on each second sample obtained by combining each query text with each search result, and the annotation of each second sample determined based on the relevance between the query text and the search results in each second sample. Specifically, this includes:
[0039] For each query text, the query text is combined with the result text of each search result corresponding to the query text to obtain each second sample corresponding to the query text;
[0040] For each second sample, the relevance between the query text and the result text of the search results in that second sample, which is determined manually, is used as the label for that second sample;
[0041] The second sample is input into the pre-trained relevance model to obtain the features corresponding to the query text and the result text in the second sample, as well as the relevance between the query text and the result text in the second sample.
[0042] Based on the difference between the relevance of each second sample and its corresponding label output by the pre-trained relevance model, and the features corresponding to each second sample, the mixed loss is determined, and the relevance model is trained again with the goal of minimizing the mixed loss.
[0043] Optionally, based on the difference between the relevance of each second sample output by the pre-trained relevance model and the corresponding label, and the features corresponding to each second sample, a mixture loss is determined, specifically including:
[0044] For each second sample, determine the difference between the relevance of the second sample output by the pre-trained relevance model and the label of the second sample;
[0045] The third loss is determined based on the differences between each second sample;
[0046] Based on the features corresponding to each second sample, the feature distance between the query text and the result text within each second sample and the feature distance between the query text and the result text between each second sample are determined, so as to determine the fourth loss based on the determined feature distances;
[0047] The mixed loss is determined based on the third loss and the fourth loss.
[0048] This specification provides a model training device. The relevance model with a dual-tower structure includes a query tower and a result tower, wherein the query tower and the result tower share parameters. The device includes:
[0049] The first sample determination module is used to determine each first sample based on the search results set of each query text. The first sample consists of the query text and its corresponding pair of search results.
[0050] The first feature determination module is used to input each search result in the first sample into the result tower for each first sample to obtain the first feature corresponding to each search result.
[0051] The second feature determination module is used to input the query text in the first sample into the query tower and determine the two second features corresponding to the query text respectively.
[0052] The first training module is used to determine the contrast loss based on the feature distance between the first features and the feature distance between the second features in each first sample, and to pre-train the correlation model based on the contrast loss.
[0053] The second training module is used to continue training the relevance model after pre-training is completed, based on each second sample obtained by combining each query text with each search result, and the annotation of each second sample determined by the relevance between the query text and the search results in each second sample. The relevance model is used to determine the ranking of search results corresponding to the query text input by the user.
[0054] This specification provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the above-described model training method.
[0055] This specification provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the model training method described above.
[0056] The above-mentioned technical solutions adopted in this specification can achieve the following beneficial effects:
[0057] In the model training method provided in this specification, during the pre-training phase, a first training sample is determined for a search result and its corresponding pair of search results. A dual-tower relevance model is used to determine the first feature of each search result in the first sample and the two second features corresponding to the query text. Based on the feature distances between the first features and the feature distances between the second features of each first sample, a contrastive loss is determined to pre-train the relevance model. Then, the query text and its corresponding search results are combined to obtain second samples. The relevance between the query text and the search results in the second samples is used as a label to continue training the relevance model.
[0058] As can be seen from the above method, this method can enable the relevance model to accurately represent the features of the query text and the result text of the search results through contrastive learning in the pre-training stage, and then further train the relevance model based on the labeled relevance, so that the relevance model can accurately output the relevance. Attached Figure Description
[0059] The accompanying drawings, which are included to provide a further understanding of this specification and form part of this specification, illustrate exemplary embodiments and are used to explain this specification, but do not constitute an undue limitation thereof. In the drawings:
[0060] Figure 1 This is a flowchart illustrating one model training method described in this specification.
[0061] Figure 2 This is a schematic diagram of a stage training provided in this manual;
[0062] Figure 3 This is a schematic diagram of a stage training provided in this manual;
[0063] Figure 4 This is a schematic diagram of a model training device provided in this specification;
[0064] Figure 5 This is a schematic diagram of the structure of an electronic device provided in this specification. Detailed Implementation
[0065] Relevance models are typically trained using supervised training methods. To improve the performance of the trained relevance model, a large number of manually labeled training samples are needed. However, manual labeling is costly, and the number of labeled training samples for relevance is usually limited.
[0066] Currently, automatic annotation methods can, to some extent, address the problem of insufficient training samples in manual annotation. Typically, search results clicked historically by the user are used as positive samples, and the correlation between the search result and its corresponding query text is used as the label. Negative samples are determined through random sampling, and their label is "unrelated."
[0067] However, users consider many factors when clicking on search results. The relevance between the user's query text and the search result is only one factor in determining whether a user clicks on a search result. Users may also consider other factors such as the category, price, and ranking of the search result. If positive and negative samples are distinguished solely based on whether a user clicks on a search result, it can easily mislead the relevance model into believing that search results clicked by users based on factors other than relevance are highly relevant to the query text, leading to inaccurate relevance identification by the relevance model. In other words, the training of the model contains significant noise, resulting in an inaccurate relevance identification by the trained relevance model.
[0068] To at least partially address the aforementioned issues, the relevance model is trained in two stages based on the model training method provided in this specification. After training the relevance model through unsupervised learning in the first stage, the model can be further trained in the second stage using manually labeled training samples, building upon the parameters obtained in the first stage. This allows for fine-tuning of the parameters, resulting in a more accurate and performant relevance model output.
[0069] In this specification, in the first stage, the relevance model is pre-trained using a contrastive learning method. Based on contrastive learning, the relevance model can be trained using training samples without requiring annotation. Furthermore, in the first stage, this specification adjusts the parameters of the relevance model based on contrastive loss. The construction of the contrastive loss does not depend on the similarity between the query text and the corresponding result text of the search results. Instead, for each query text, two similar texts are identified, and the contrastive loss is determined based on the similarity of features between similar texts output by the relevance model (i.e., the feature distance in this specification), and the similarity of features between the result texts of the two search results clicked by the user corresponding to the query text. In other words, there is no interaction between the features of the query text and the search results.
[0070] In this specification, since there is no interaction between the query text and the result text, and the aim is to narrow the distance in the feature space between the features of two similar texts of a query text, and the distance in the feature space between the result texts of two search results of a query text. Instead of binding the query text and result text together, or comparing the query text with the result text of a search result clicked by the user, we compare the features of two search results clicked by the user, and the features of two similar texts of a user's query text. Therefore, the model can learn how to more accurately represent each text during the learning process, and can reduce the interference of other factors on the determination of relevance, thus reducing training noise.
[0071] In the second stage, since the ultimate goal of the model is still to output the relevance between the query text and the search results, the training samples are determined by the query text and the search results clicked by the user. Furthermore, the labels (relevance) of the training samples are determined manually. Also in the second stage, based on the labels of the training samples, a contrastive loss is used to determine the loss for the second stage, compensating for the insufficient number of manually labeled training samples and further ensuring the accuracy of the trained relevance model.
[0072] In this way, the relevance model can learn to better represent the features of different texts in the first stage, so that after the second stage of training, the relevance model can more accurately determine the relevance between the query text and the search results based on the features of different texts, and the trained relevance model can have better performance.
[0073] To make the objectives, technical solutions, and advantages of this specification clearer, the technical solutions of this specification will be clearly and completely described below in conjunction with specific embodiments and corresponding drawings. Obviously, the described embodiments are only a part of the embodiments of this specification, and not all of them. Based on the embodiments in this specification, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this specification.
[0074] The technical solutions provided by the embodiments of this specification are described in detail below with reference to the accompanying drawings.
[0075] Figure 1 This is a flowchart illustrating one model training method described in this specification, which specifically includes the following steps:
[0076] S100: Based on the search results set of each query text, determine each first sample, which consists of the query text and its corresponding pair of search results.
[0077] In this specification, the model training method can be applied to search scenarios. This model training method can be executed by the server of a business platform providing search services. Based on this method, a relevance model used to output the relevance between search results and query text can be trained. In one or more embodiments of this specification, the relevance model is a dual-tower structure, including a query tower and a result tower. The query tower corresponds to the query text and is used to determine its corresponding features based on the input query text. The result tower corresponds to the search results and is used to determine its corresponding features based on the input search result text.
[0078] In one or more embodiments of this specification, firstly, during the training of the relevance model in the first stage, the server can determine each query text and its corresponding search results based on the historical search logs of the business platform. Specifically, for each query text, the search results are the search results clicked by the user, and these search results constitute a search result set corresponding to that query text. The query text is the text entered by the user during the search, corresponding to the concept of a query in the field of natural language processing, while the text of the search results corresponds to the concept of a document (doc).
[0079] It should be noted that the meaning of the "click" operation is not limited. For example, a click can refer to a user clicking on a search result to get details, or it can refer to clicking to place an order, clicking to add to favorites, etc. This instruction manual does not impose any restrictions here.
[0080] In one or more embodiments of this specification, after determining each query text and its corresponding search result set, the server can determine each first sample based on the search result set of each query text. For each first sample, the first sample consists of a query text and its corresponding pair of search results. Specifically, for each query text, the server can combine each search result in pairs within the search result set of that query text to obtain result groups, and for each result group, the result group and the query text are used as a training sample, i.e., a first sample.
[0081] S102: For each first sample, input each search result in the first sample into the result tower to obtain the first feature corresponding to each search result.
[0082] In one or more embodiments of this specification, after determining the first sample, the server can input each search result in the first sample into the result stack of the relevance model to obtain the first feature corresponding to each search result.
[0083] Since all the search results in this first sample are clicked by users after entering the same query text, there are similarities among the search results in this first sample that prompted users to click. Based on the first features of this first sample, the relevance model can learn how to accurately represent the result text of similar search results.
[0084] S104: Input the query text from the first sample into the query tower to determine the two second features corresponding to the query text.
[0085] In one or more embodiments of this specification, the server can input the query text in the first sample into the query tower of the relevance model to determine the two second features corresponding to the query text.
[0086] Specifically, the server can use the query tower to determine two similar texts of the query text in the first sample. Then, it determines the features corresponding to the two similar texts as their respective second features.
[0087] The query tower incorporates a dropout mechanism. Based on this dropout mechanism, when the query text is input into the query tower, some neurons within the tower are randomly frozen. This allows for the masking of certain characters in the query text, resulting in a similar text. Inputting the query text into the dropout module twice yields two similar texts.
[0088] In one or more embodiments of this specification, the query tower and result tower of the relevance model can each correspond to a Bidirectional Encoder Representation from Transformers (BERT) model. That is, one BERT model corresponds to the query tower of the relevance model, and one BERT model corresponds to the result tower of the relevance model.
[0089] S106: Determine the contrast loss based on the feature distance between the first features and the feature distance between the second features in each first sample, and pre-train the correlation model based on the contrast loss.
[0090] In one or more embodiments of this specification, after obtaining the first feature and the second feature corresponding to each first sample, the server can determine the contrast loss based on the feature distance between the first features and the feature distance between the second features in each first sample, and pre-train the correlation model based on the determined contrast loss with the goal of minimizing the contrast loss.
[0091] In one or more embodiments of this specification, when determining the contrast loss, specifically, the server may, for each first sample, determine the feature distance between each first feature within the first sample as a first distance, and determine the feature distance between each first feature of the first sample and each pairwise first feature of other first samples as second distances. Based on the first distance and the second distances corresponding to the first sample, the result loss corresponding to the first sample is determined.
[0092] The first distance is positively correlated with the resulting loss, and the second distance is negatively correlated with the resulting loss.
[0093] Furthermore, the server can determine the feature distance between each second feature within the first sample, as a third distance, and determine the feature distance between each second feature of the first sample and each pairwise second feature of other first samples, as fourth distances. Based on the third distance and the fourth distances, the query loss corresponding to the first sample is determined.
[0094] The third distance is positively correlated with the query loss, while the fourth distance is negatively correlated with the query loss.
[0095] After determining the query loss and result loss for each first sample, the server can determine the comparison loss based on the result loss and query loss for each first sample.
[0096] In one or more embodiments of this specification, the relevance model may further include an output layer for determining feature distances based on the features output by the query tower and the result tower.
[0097] The output layer may include an activation layer and a regression layer. When determining the feature distance, taking the first distance as an example, each first feature is input into the activation layer of the output layer, and the activation feature corresponding to each first feature is determined. Based on each activation feature, the inner product of each activation feature can be determined through the regression layer, which is used as the first distance.
[0098] The activation layer can be a sigmoid activation function layer, and the regression layer is an inner product layer.
[0099] In one or more embodiments of this specification, the server may determine a first loss based on the result loss corresponding to each first sample, and determine a second loss based on the query loss corresponding to each first sample. Then, a comparison loss is determined based on the first loss and the second loss.
[0100] In one or more embodiments of this specification, the formula for determining the first loss may be as follows:
[0101] L d =-(L1+L2)
[0102]
[0103]
[0104] Among them, L dThe first loss is A = exp(δ(f(D1), f(D2)) / T), where A is the exponential feature distance obtained by using the first distance corresponding to the first sample as input to the exp function, and T is a preset temperature coefficient. f(D1) represents the activation feature corresponding to the first feature of the first result text in the first sample, and f(D2) represents the activation feature corresponding to the first feature of the second result text in the first sample. δ(f(D1), f(D2)) represents the feature distance obtained after inputting f(D1) and f(D2) into the regression layer. D1 represents the result text of the first search result in the first sample, and D2 represents the result text of the second search result in the first sample. That is, the loss corresponding to one of the result texts in the first sample. That is, the loss corresponding to the other result text in the first sample. and The sum is the result loss corresponding to the first sample.
[0105] B = ∑ j∈D exp(δ(f(D1),f(D j B represents the sum of the exponential feature distances between each of the first features corresponding to the first sample and the first features of other first samples. D represents the set of result texts corresponding to other first samples.
[0106] exp(δ(f(D1),f(D j f(D) / T) is the exponential feature distance corresponding to a second distance. j This refers to the first feature of the j-th first sample among other first samples. Here, B is negatively correlated with L1.
[0107] C=exp(δ(f(D2),f(D1)) / T) and C=A. F=∑ j∈D exp(δ(f(D2),f(D j )) / T). δ(f(D2),f(D j )) represents the combination of f(D2) and f(D j The feature distance obtained after inputting into the regression layer.
[0108] In one or more embodiments of this specification, the formula for determining the second loss may be as follows:
[0109] L q =-(L3+L4)
[0110]
[0111]
[0112] Among them, Lq This refers to the second loss. G = exp(δ(f(Q1),f(Q2)) / T), where T is still the temperature coefficient. G is the exponential feature distance corresponding to the feature distance between two second features of the query text in a first sample. H = ∑ i∈E exp(δ(f(Q1),f(Q i E represents the set of similar texts corresponding to the query texts of other first samples. δ(f(Q1),f(Q)) i )) / T, which is the feature distance between the second feature of the first similar text in the first sample and the i-th similar text in set E, i.e., the fourth distance. H is the sum of all the fourth distances corresponding to the first similar text in the first sample. Q1 represents the first similar text corresponding to the first sample, and Q2 represents the second similar text corresponding to the first sample. That is, the loss corresponding to one of the similar texts in the first sample. That is, the loss corresponding to another similar text in the first sample. and The sum is the query loss corresponding to the first sample.
[0113] I=exp(δ(f(Q2),f(Q1)) / T), and I=G. J=∑ i∈E exp(δ(f(Q2),f(Q i )) / T).
[0114] In one or more embodiments of this specification, the comparison loss can be obtained by directly summing the first loss and the second loss. Alternatively, the comparison loss can be determined by weighted summing of the first loss and the second loss.
[0115] Therefore, the formula for determining the contrast loss can be as follows:
[0116] L=α*L q +L d
[0117] Where α is a preset weight, which can be set as needed.
[0118] S108: After pre-training is completed, the relevance model is trained again based on each second sample obtained by combining each query text with each search result, and the annotation of each second sample determined by the relevance between the query text and the search results in each second sample. The relevance model is used to determine the ranking of the search results corresponding to the query text input by the user.
[0119] In one or more embodiments of this specification, after the relevance model is pre-trained in the first stage, the server can continue to train the relevance model in the second stage based on each second sample obtained by combining each query text with each search result, and the annotation of each second sample determined by the relevance between the query text and the search results in each second sample.
[0120] This relevance model can be used to determine the ranking of search results corresponding to the query text entered by the user.
[0121] In the second stage, when further training the relevance model, specifically, the server can combine each query text with the result text of each corresponding search result to obtain each second sample corresponding to the query text. Then, for each second sample, the manually determined relevance between the query text and the result text of the search result is used as the label for that second sample. This second sample is then input into the pre-trained relevance model to obtain the features corresponding to the query text and result text in that second sample, as well as the relevance between them. Then, based on the difference between the relevance of each second sample output by the pre-trained relevance model and its corresponding label, and the features corresponding to each second sample, the server can determine the mixed loss and continue training the relevance model with the goal of minimizing this mixed loss.
[0122] It should be noted that in the first stage of training, the freeze ratio of the result tower is 0, and in the second stage, the freeze ratios of both the result tower and the query tower are 0, meaning that no dropout processing is performed on the input.
[0123] based on Figure 1 The model training method shown involves determining a first training sample in the pre-training phase for a search result and its corresponding pair of search results. A dual-tower relevance model is used to determine the first feature of each search result in this first sample and the two second features corresponding to the query text. Based on the feature distances between the first and second features of each first sample, a contrastive loss is determined to pre-train the relevance model. Then, the query text and its corresponding search results are combined to obtain second samples. The relevance between the query text and the search results in the second samples is used as a label to continue training the relevance model.
[0124] As can be seen from the above method, in the pre-training stage, based on the first sample, the relevance model can accurately represent the features of the query text and the result text of the search results through contrastive learning, and accurately represent different query texts and different result texts of search results. Then, based on the second sample and manually labeled relevance, the relevance model is further trained, enabling it to accurately output the relevance between the query text and the search results based on accurate features. Furthermore, when further training the relevance model after pre-training, in addition to determining the loss based on the difference between the labeled training samples and the relevance output by the relevance model, a hybrid loss is obtained by combining contrastive loss. This compensates for the limited number of manually labeled training samples, ensuring the performance of the relevance model and making the relevance output by the model more accurate.
[0125] Furthermore, in search scenarios, multiple search results can typically be determined based on a user's query text, and the corresponding result texts are usually semantically similar. Therefore, in order for the model to better distinguish different result texts and identify their semantics, and to better represent the characteristics of different result texts, in one or more embodiments provided in this specification, for each first sample, based on each search result of the first sample, a difficult example, i.e., a hard sample, can be determined for each search result.
[0126] Then, when determining the result loss in step S106, the server can also determine the result text corresponding to each search result in the first sample, and generate each difficult sample corresponding to the search result based on the result text. Each difficult sample is then input into the result pyramid of the relevance model to determine the features corresponding to each difficult sample, which are used as third features.
[0127] Next, for each first feature of the first sample, the feature distance between the first feature and each third feature of the first sample is determined as each fifth distance. Based on the first distance, each second distance, and each fifth distance corresponding to the first sample, the resulting loss for the first sample is determined. The fifth distance is negatively correlated with the resulting loss.
[0128] Specifically, when identifying difficult samples, the server can determine the subject of the query text for the first sample and the type of the subject in the query text, which is then used as the type of the query text. The subject of the query text is the object described in the query text. For example, when the query text is "cola", cola is the subject; when the query text is "fried chicken wings", chicken wings are the subject.
[0129] Next, for each search result in the first sample, the server determines the result text of that search result and identifies the related text of the query text in the first sample contained within that result text. Then, it identifies other query texts of the same type as the query text in the first sample, and for each other query text, replaces the related text with that other query text to obtain replacement text. Finally, each replacement text is used as a hard sample corresponding to that search result.
[0130] In this context, related text refers to text that is semantically identical or similar to the query text. Related text can be the same word as the query text, or it can be a synonym or near-synonym for the query text. For example, if the query text is "hot pot," then if the result text contains the character "hot pot," that character is considered related text. Similarly, if the result text contains characters such as "copper pot" or "shabu-shabu," it can also be considered related text. Since the query text may not only contain nouns, related text can also be determined based on the main body of the query text. Of course, the above are just examples and do not limit the specific application scenarios of the search. For example, search results can be products, merchants, etc.
[0131] In one or more embodiments of this specification, when identifying difficult samples, the server may further determine the type of the main body in the query text of the first sample as the type of the query text, and identify other query texts belonging to the same type as the query text in the first sample. Then, for each search result in the first sample, the result text of the search result is determined, and the result text is replaced with each of the other query texts to obtain a substitute text. Finally, each substitute text is taken as the difficult sample corresponding to the search result.
[0132] In one or more embodiments of this specification, when determining other query texts of the same type as the query text of the first sample, the number of difficult samples can be determined based on a preset number.
[0133] Of course, when identifying difficult samples, both relevant text and alternative text can be identified, and each difficult sample can be identified based on the relevant text and alternative text.
[0134] The number of suffering samples can be set as needed, for example, it can be 10 or other values, which are not limited in this specification.
[0135] In one or more embodiments of this specification, the formula for determining the first loss may also be as follows:
[0136] L d =-(L5+L6)
[0137]
[0138]
[0139] Among them, L d That is, the first loss, and
[0140]
[0141]
[0142] Where P is the set of difficult samples corresponding to the first result text D1 in the first sample. h That is, the h-th difficult sample in set P. T is the set of difficult samples corresponding to the second result text D2 in the first sample. v That is, the vth difficult sample in the set D. and The sum is the result loss corresponding to the first sample.
[0143] A = exp(δ(f(D1), f(D2)) / T)
[0144]
[0145] C = exp(δ(f(D2), f(D1)) / T)
[0146]
[0147] That is, A, B, C, and F are the same as A, B, C, and F in the above embodiment where the first loss is not determined based on difficult samples. The meaning of the corresponding characters in the formula can be referred to the above explanation of the formula, and will not be repeated here.
[0148] In this specification, the relevance model is trained based on difficult samples, which enables the model to more accurately represent similar but different texts, thus making the determination of relevance more accurate.
[0149] In one or more embodiments of this specification, when determining the hybrid loss in step S108, the server may, for each second sample, determine the difference between the relevance corresponding to the second sample output by the pre-trained relevance model and the annotation of the second sample. Then, based on the differences corresponding to each second sample, a third loss is determined. Furthermore, based on the features corresponding to each second sample, the feature distance between the query text and the result text within each second sample and the feature distance between the query text and the result text between each second sample are determined, so as to determine a fourth loss based on the determined feature distances. Finally, based on the third loss and the fourth loss, the hybrid loss is determined.
[0150] The relevance of the annotation can be categorized as: relevant, moderately relevant, and irrelevant, represented by 0, 1, and 2 respectively. The feature distance between the query text and the result text within the second sample is the relevance of that second sample.
[0151] Therefore, during the second stage of training the relevance model, the loss function can include two types: a third loss based on the difference between the relevance between the annotations and the model output, and a fourth loss based on contrastive learning. This allows the relevance model to be trained using manually determined annotations with less noise, further improving its accuracy. Furthermore, combining the fourth loss with the third loss ensures effective model training even with a limited number of manually annotated training samples.
[0152] It should be noted that during the training phases in both the first and second stages, the server can determine a mixed loss using a sample set (corresponding to the batch concept in machine learning). Furthermore, in the second stage, the relevance model outputs a score, based on which the relevance between the query text and the search results can be determined as relevant, moderately relevant, or irrelevant.
[0153] In the second stage, the feature distance between the query text and the result text output by the regression layer in the output layer of the relevant model is used to determine their relevance.
[0154] Furthermore, since the quality of training samples affects the training effect of the model, and the presence of some high-frequency query texts in the training samples can interfere with the training of the relevance model, to ensure that the query texts in the first sample are as diverse and proportionally balanced as possible, when determining each query text in steps S100 and / or S108, the frequency of occurrence of each query text can be determined based on historical search logs, and each query text can be uniformly sampled according to its frequency of occurrence. Then, based on the sampled query texts, the first and / or second samples as training samples are determined. It should be noted that during sampling, the number of each query text sampled does not necessarily need to be the same; the difference in the number of different query texts should be controlled within a preset range. For example, there may be ten query texts 1, five query texts 2, and 40 query texts 3 in the query texts, with a ratio of 2:1:8. During sampling, to reduce the interference of high-frequency query texts (i.e., reduce the number of query texts 3), sampling may not follow this ratio, nor necessarily a 1:1:1 ratio. Sampling can be aimed at reducing the difference among the three, for example, sampling can be done in a 2:1:4 ratio.
[0155] In one or more embodiments of this specification, when determining the third loss, specifically, the server can, for each second sample, determine the labeled feature value corresponding to the second sample based on the label of the second sample, and then determine the absolute value of the difference between the relevance of the second sample output by the relevance model and the labeled feature value of the second sample. Based on the difference between this absolute value and a preset margin, an output feature value is determined. Then, the server can determine the loss corresponding to the second sample based on the maximum value between the output feature value and the preset margin feature value. Summing the losses corresponding to each second sample determines the third loss.
[0156] In one or more embodiments of this specification, the third loss and the fourth loss can be summed to obtain the mixed loss. Alternatively, a weighted summation method can be used to determine the mixed loss.
[0157] In one or more embodiments of this specification, the formula for determining the mixing loss may be as follows:
[0158] L mix =L mar +β*L C
[0159] Among them, L mix That is, mixed loss, L mar That is, the third loss, L C This is the fourth loss. β is the preset weight.
[0160] and,
[0161] L mar =∑max(0,(|y pred -y|-margin))
[0162] L C =-L s1 -L s2
[0163] Here, 0 represents the boundary feature value, and margin represents the edge value, used to create gaps between the output relevance of training samples with different relevance levels, making them easier to distinguish. pred That is, the relevance score output by the relevance model and y pred =δ(f(Q), f(D)). f(Q) is the activation feature corresponding to the query text in the second sample, f(D) is the activation feature corresponding to the result text in the second sample, and y pred We obtain it by taking the inner product of the two. y represents the labeled feature value, and... y label That is, labeling.
[0164]
[0165]
[0166] Q represents the query text in a second sample, and D represents the result text of the search results in that second sample. D′ represents the set of result texts from other second samples. E′ represents the set of query texts from other second samples.
[0167] δ(f(Q),f(D)) / T represents the feature distance corresponding to a second sample.
[0168] δ(f(Q),f(D j )) / T represents the feature distance between the query text in the second sample and the j-th query text in set D′. δ(f(D),f(Q) i )) / T represents the feature distance between the result text in the second sample and the i-th query text in set E′. Let L represent the loss corresponding to the query text in a second sample. s1 This represents the sum of the losses corresponding to the query text in each of the second samples. L represents the loss corresponding to the result text in the second sample. s2 This represents the sum of the losses corresponding to the result text in each of the second samples.
[0169] It should be noted that, in determining L C In the formula, the meaning of each character, such as T, exp(δ(f(D), f(Q)), is explained. i The explanation of the formula for the contrast loss in the first stage can be referred to above, and will not be repeated here.
[0170] To facilitate understanding, this manual also provides a diagram illustrating the stages of training. For example... Figure 2 , 3 As shown.
[0171] Figure 2 and Figure 3 This is a schematic diagram of a stage training provided in this manual. Figure 2 This is the first phase. Figure 3 This is the second stage. For example... Figure 2 In the first stage, inputting the query text of the first sample into the query tower of the relevance model yields the second features of that query text. Inputting each pair of result texts from the first sample into the result tower yields the first features corresponding to each result text. Inputting the first and second features of the first sample into the output layer determines the feature distances corresponding to each first sample. Based on the feature distances corresponding to each first sample, the first and second losses are determined to determine the contrast loss. It should be noted that each result text in a first sample is input into the result tower separately. Figure 2 To better illustrate the difference between the content of the input relevance model corresponding to a first sample and the content of the input relevance model for a second sample in the second stage, the input process of a pair of result texts is shown simultaneously.
[0172] Figure 3 As can be seen, inputting the query text from the second sample into the query tower yields the features corresponding to the query text. Inputting the result text from the search results in the second sample into the result tower yields the features corresponding to the result text. Inputting each feature of the second sample into the output layer yields the activation features and relevance of the second sample. Inputting each second sample into the relevance model yields the activation features and relevance of each second sample. Based on the difference between the relevance of each second sample and its corresponding label, a third loss can be determined. Based on the activation features of each second sample, the feature distance between the query text and result text of different second samples can be determined. Based on the feature distances, a fourth loss can be determined. Based on the third and fourth losses, a mixed loss can be determined.
[0173] In this specification, the first and second losses constituting the first stage are both different contrastive losses. The third loss is a type of margin loss. The fourth loss is also a type of contrastive loss.
[0174] The above describes one or more embodiments of the model training method provided in this specification. Based on the same idea, this specification also provides corresponding model training devices, such as... Figure 4 As shown.
[0175] Figure 4 This is a schematic diagram of a model training device provided in this specification. The relevance model with a dual-tower structure includes a query tower and a result tower, wherein the query tower and the result tower share parameters. The device includes:
[0176] The first sample determination module 200 is used to determine each first sample based on the search result set of each query text. The first sample consists of the query text and its corresponding pair of search results.
[0177] The first feature determination module 201 is used to input each search result in the first sample into the result tower for each first sample to obtain the first feature corresponding to each search result.
[0178] The second feature determination module 202 is used to input the query text in the first sample into the query tower and determine the two second features corresponding to the query text respectively.
[0179] The first training module 203 is used to determine the contrast loss based on the feature distance between the first features and the feature distance between the second features in each first sample, and to pre-train the correlation model based on the contrast loss.
[0180] The second training module 204 is used to continue training the relevance model after pre-training is completed, based on each second sample obtained by combining each query text with each search result, and the annotation of each second sample determined by the relevance between the query text and the search results in each second sample. The relevance model is used to determine the ranking of search results corresponding to the query text input by the user.
[0181] Optionally, the second feature determination module 202 is further configured to determine two similar texts of the query text based on the query text in the first sample through the query tower, and determine the features corresponding to the two similar texts respectively as each second feature.
[0182] Optionally, the first training module 203 is further configured to, for each first sample, determine the feature distance between each first feature within the first sample as a first distance, and determine the feature distance between each first feature of the first sample and each pairwise first feature of other first samples as second distances; determine the result loss corresponding to the first sample based on the first distance and each second distance, wherein the first distance is positively correlated with the result loss and the second distance is negatively correlated with the result loss; determine the feature distance between each second feature within the first sample as a third distance, and determine the feature distance between each second feature of the first sample and each pairwise second feature of other first samples as fourth distances; determine the query loss corresponding to the first sample based on the third distance and each fourth distance, wherein the third distance is positively correlated with the query loss and the fourth distance is negatively correlated with the query loss; and determine the contrast loss based on the result loss and the query loss corresponding to each first sample.
[0183] Optionally, the first training module 203 is further configured to: determine the result text corresponding to each search result in the first sample; generate each difficult sample corresponding to the search result based on the result text; input each difficult sample into the result tower; determine the third feature corresponding to each difficult sample; determine the feature distance between each first feature and each third feature of the first sample as each fifth distance for each first feature of the first sample; and determine the result loss corresponding to the first sample based on the first distance, each second distance, and each fifth distance, wherein the fifth distance is negatively correlated with the result loss.
[0184] Optionally, the first training module 203 is further configured to determine the type of the subject in the query text of the first sample, and for each search result in the first sample, determine the result text of the search result, and determine the related text of the query text in the first sample contained in the result text, determine other query texts that belong to the same type as the query text of the first sample, and for each other query text, replace the related text with the other query text to obtain a replacement text, and use each replacement text as a hard sample corresponding to the search result.
[0185] Optionally, the first training module 203 is further configured to determine the type of the subject in the query text of the first sample as the type of the query text, and determine other query texts that belong to the same type as the query text in the first sample. For each search result in the first sample, the result text of the search result is determined, and the result text is replaced with each other query text to obtain each substitute text. Each substitute text is used as each hard sample corresponding to the search result.
[0186] Optionally, the second training module 204 is further configured to, for each query text, combine the query text with the result text of each search result corresponding to the query text to obtain each second sample corresponding to the query text; for each second sample, use the manually determined relevance between the query text and the result text of the search result in the second sample as the label of the second sample; input the second sample into the pre-trained relevance model to obtain the features corresponding to the query text and the result text in the second sample, as well as the relevance between the query text and the result text in the second sample; determine the mixed loss based on the difference between the relevance of each second sample output by the pre-trained relevance model and the corresponding label, as well as the features corresponding to each second sample; and continue training the relevance model with the goal of minimizing the mixed loss.
[0187] Optionally, the second training module 204 is further configured to, for each second sample, determine the difference between the relevance of the second sample output by the pre-trained relevance model and the label of the second sample, determine a third loss based on the difference of each second sample, determine the feature distance between the query text and the result text within each second sample and the feature distance between the query text and the result text between each second sample based on the features of each second sample, determine a fourth loss based on the determined feature distances, and determine a hybrid loss based on the third loss and the fourth loss.
[0188] This specification also provides a computer-readable storage medium storing a computer program that can be used to execute the above-described... Figure 1 The provided model training method.
[0189] This instruction manual also provides Figure 5 The diagram shows the structure of the electronic device. Figure 5 As shown, at the hardware level, this electronic device includes a processor, internal bus, memory, and non-volatile memory, and may also include other hardware required for business operations. The processor reads the corresponding computer program from the non-volatile memory into memory and then runs it to achieve the above. Figure 1 The provided model training method.
[0190] It should be noted that all actions involving the acquisition of signals, information, or data in this manual are performed in accordance with the relevant data protection laws and regulations of the country where the device is located, and with the authorization of the owner of the relevant device.
[0191] Of course, in addition to software implementation, this specification does not exclude other implementation methods, such as logic devices or a combination of hardware and software. In other words, the execution subject of the following processing flow is not limited to each logic unit, but can also be hardware or logic devices.
[0192] In the 1990s, improvements to a technology could be clearly distinguished as either hardware improvements (e.g., improvements to the circuit structure of diodes, transistors, switches, etc.) or software improvements (improvements to the methodology). However, with technological advancements, many methodological improvements today can be considered direct improvements to the hardware circuit structure. Designers almost always obtain the corresponding hardware circuit structure by programming the improved methodology into the hardware circuit. Therefore, it cannot be said that a methodological improvement cannot be implemented using hardware physical modules. For example, a Programmable Logic Device (PLD) (such as a Field Programmable Gate Array (FPGA)) is such an integrated circuit whose logic function is determined by the user programming the device. Designers can program and "integrate" a digital system onto a PLD themselves, without needing chip manufacturers to design and manufacture dedicated integrated circuit chips. Furthermore, nowadays, instead of manually manufacturing integrated circuit chips, this programming is mostly implemented using "logic compiler" software. Similar to the software compiler used in program development, the original code before compilation must be written in a specific programming language, called a Hardware Description Language (HDL). There are many HDLs, such as ABEL (Advanced Boolean Expression Language), AHDL (Altera Hardware Description Language), Confluence, CUPL (Cornell University Programming Language), HDCal, JHDL (Java Hardware Description Language), Lava, Lola, MyHDL, PALASM, and RHDL (Ruby Hardware Description Language). Currently, the most commonly used are VHDL (Very-High-Speed Integrated Circuit Hardware Description Language) and Verilog. Those skilled in the art should understand that by simply performing some logic programming on the method flow using one of these hardware description languages and programming it into an integrated circuit, the hardware circuit implementing the logical method flow can be easily obtained.
[0193] The controller can be implemented in any suitable manner. For example, it can take the form of a microprocessor or processor and a computer-readable medium storing computer-readable program code (e.g., software or firmware) executable by the (micro)processor, logic gates, switches, application-specific integrated circuits (ASICs), programmable logic controllers, and embedded microcontrollers. Examples of controllers include, but are not limited to, the following microcontrollers: ARC 625D, Atmel AT91SAM, Microchip PIC18F26K20, and Silicon Labs C8051F320. A memory controller can also be implemented as part of the control logic of the memory. Those skilled in the art will also recognize that, in addition to implementing the controller in purely computer-readable program code form, the same functionality can be achieved by logically programming the method steps to make the controller take the form of logic gates, switches, application-specific integrated circuits, programmable logic controllers, and embedded microcontrollers. Therefore, such a controller can be considered a hardware component, and the means included therein for implementing various functions can also be considered as structures within the hardware component. Alternatively, the means for implementing various functions can be considered as both software modules implementing the method and structures within the hardware component.
[0194] The systems, devices, modules, or units described in the above embodiments can be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer. Specifically, a computer can be, for example, a personal computer, laptop computer, cellular phone, camera phone, smartphone, personal digital assistant, media player, navigation device, email device, game console, tablet computer, wearable device, or any combination of these devices.
[0195] For ease of description, the above devices are described in terms of function, divided into various units. Of course, in implementing this specification, the functions of each unit can be implemented in one or more software and / or hardware components.
[0196] It will be understood by those skilled in the art that embodiments of the present invention may be provided as methods, systems, or computer program products. Thus, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware. Furthermore, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0197] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 a process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0198] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 a process or multiple processes and / or boxes Figure 1 The function specified in one or more boxes.
[0199] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 a process or multiple processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0200] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0201] Memory may include non-persistent storage in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.
[0202] Computer-readable media includes both permanent and non-permanent, removable and non-removable media that can store information using any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic magnetic disk storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.
[0203] It should also be noted that the terms "comprises," "includes," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a process, method, commodity, or apparatus that includes a series of elements includes not only those elements but also other elements not explicitly listed, or includes elements inherent to such process, method, commodity, or apparatus. In the absence of further limitations, an element defined by the phrase "comprises a ..." does not exclude the presence of other identical elements in the process, method, commodity, or apparatus that includes the element.
[0204] Those skilled in the art will understand that the embodiments of this specification can be provided as methods, systems, or computer program products. Therefore, this specification may take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this specification may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0205] This specification can be described in the general context of computer-executable instructions that are executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc., that perform a specific task or implement a specific abstract data type. This specification can also be practiced in distributed computing environments, where tasks are performed by remote processing devices connected via a communication network. In distributed computing environments, program modules can reside in local and remote computer storage media, including storage devices.
[0206] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to interchangeably. Each embodiment focuses on describing the differences from other embodiments. In particular, the system embodiments are basically similar to the method embodiments, so the description is relatively simple; relevant parts can be referred to the descriptions in the method embodiments.
[0207] The above description is merely an embodiment of this specification and is not intended to limit this specification. Various modifications and variations can be made to this specification by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this specification should be included within the scope of the claims of this specification.
Claims
1. A model training method, characterized in that, The relevance model of the dual-tower structure includes a query tower and a result tower, wherein the query tower and the result tower share parameters, and the method includes: Based on the search results set of each query text, each first sample is determined, which consists of the query text and its corresponding pair of search results; For each first sample, each search result in the first sample is input into the result tower to obtain the first feature corresponding to each search result; Input the query text from the first sample into the query tower to determine the two second features corresponding to the query text; The contrast loss is determined based on the feature distance between the first features and the feature distance between the second features in each first sample, and the correlation model is pre-trained based on the contrast loss. After pre-training is completed, the relevance model is further trained based on the second samples obtained by combining each query text with each search result, and the annotations of each second sample determined by the relevance between the query text and the search results in each second sample. The relevance model is used to determine the ranking of search results corresponding to the user-input query text. The query text in the first sample is input into the query tower to determine the two second features corresponding to the query text, specifically including: Using the query tower, two similar texts of the query text are determined based on the query text in the first sample; The features corresponding to the two similar texts are determined as each second feature; the contrast loss is determined based on the feature distance between the first features and the feature distance between the second features in each first sample, specifically including: For each first sample, the feature distance between each first feature within the first sample is determined as the first distance, and the feature distance between each first feature of the first sample and each pairwise first feature of other first samples is determined as the second distance. Based on the first distance and each of the second distances, the result loss corresponding to the first sample is determined, wherein the first distance is positively correlated with the result loss and the second distance is negatively correlated with the result loss; the feature distance between each of the second features in the first sample is determined as the third distance, and the feature distance between each of the second features of the first sample and each of the second features of other first samples is determined as the fourth distance; Based on the third distance and each of the fourth distances, the query loss corresponding to the first sample is determined, wherein the third distance is positively correlated with the query loss and the fourth distance is negatively correlated with the query loss; based on the result loss corresponding to each first sample and the query loss corresponding to each first sample, the comparison loss is determined; based on the first distance and each of the second distances, the result loss corresponding to the first sample is determined, specifically including: For each search result in the first sample, determine the corresponding result text, and generate each difficult sample corresponding to the search result based on the result text; Each difficult sample is input into the result tower to determine the third feature corresponding to each difficult sample; For each first feature of the first sample, the feature distance between the first feature and each third feature of the first sample is determined as each fifth distance; Based on the first distance, each second distance, and each fifth distance corresponding to the first sample, determine the result loss corresponding to the first sample; The fifth distance is negatively correlated with the resulting loss.
2. The method as described in claim 1, characterized in that, For each search result in the first sample, determine the corresponding result text, and generate each difficult sample corresponding to that search result based on the result text, specifically including: Determine the type of the subject in the query text of the first sample, and use that as the type of the query text; For each search result in the first sample, determine the result text of the search result, and determine the related text of the query text in the first sample contained in the result text; Identify other query texts that belong to the same type as the query text in the first sample; For each other query text, replace the relevant text with that other query text to obtain the replacement text; Each replacement text is used as a hard sample corresponding to the search result.
3. The method as described in claim 1, characterized in that, For each search result in the first sample, determine the corresponding result text, and generate each difficult sample corresponding to that search result based on the result text, specifically including: Determine the type of the subject in the query text of the first sample as the type of the query text, and determine other query texts that belong to the same type as the query text in the first sample; For each search result in the first sample, determine the result text of the search result, and replace the result text with each of the other query texts to obtain the replacement text; Each alternative text is used as a hard sample corresponding to the search result.
4. The method as described in claim 1, characterized in that, Based on each second sample obtained by combining each query text with each search result, and the annotation of each second sample determined by the relevance between the query text and the search results in each second sample, the relevance model is further trained, specifically including: For each query text, the query text is combined with the result text of each search result corresponding to the query text to obtain each second sample corresponding to the query text; For each second sample, the relevance between the query text and the result text of the search results in that second sample, which is determined manually, is used as the label for that second sample; The second sample is input into the pre-trained relevance model to obtain the features corresponding to the query text and the result text in the second sample, as well as the relevance between the query text and the result text in the second sample. Based on the difference between the relevance of each second sample and the corresponding label output by the pre-trained relevance model, and the features corresponding to each second sample, the mixed loss is determined, and the relevance model is continued to be trained with the goal of minimizing the mixed loss.
5. The method as described in claim 4, characterized in that, Based on the difference between the relevance of each second sample output by the pre-trained relevance model and its corresponding label, and the features corresponding to each second sample, the mixture loss is determined, specifically including: For each second sample, determine the difference between the relevance of the second sample output by the pre-trained relevance model and the label of the second sample; The third loss is determined based on the differences between each second sample; Based on the features corresponding to each second sample, the feature distance between the query text and the result text within each second sample and the feature distance between the query text and the result text between each second sample are determined, so as to determine the fourth loss based on the determined feature distances; The mixed loss is determined based on the third loss and the fourth loss.
6. A model training device, characterized in that, The relevance model of the dual-tower structure includes a query tower and a result tower, wherein the query tower and the result tower share parameters, and the device includes: The first sample determination module is used to determine each first sample based on the search results set of each query text. The first sample consists of the query text and its corresponding pair of search results. The first feature determination module is used to input each search result in the first sample into the result tower for each first sample to obtain the first feature corresponding to each search result. The second feature determination module is used to input the query text in the first sample into the query tower and determine the two second features corresponding to the query text respectively. The first training module is used to determine the contrast loss based on the feature distance between the first features and the feature distance between the second features in each first sample, and to pre-train the correlation model based on the contrast loss. The second training module is used to continue training the relevance model after pre-training is completed, based on each second sample obtained by combining each query text with each search result, and the annotation of each second sample determined by the relevance between the query text and the search results in each second sample. The relevance model is used to determine the ranking of search results corresponding to the query text input by the user. Input the query text from the first sample into the query tower to determine the two second features corresponding to the query text, specifically including: Using the query tower, two similar texts of the query text are determined based on the query text in the first sample; The features corresponding to the two similar texts are determined as each second feature; the contrast loss is determined based on the feature distance between the first features and the feature distance between the second features in each first sample, specifically including: For each first sample, the feature distance between each first feature within the first sample is determined as the first distance, and the feature distance between each first feature of the first sample and each pairwise first feature of other first samples is determined as the second distance. Based on the first distance and each of the second distances, the result loss corresponding to the first sample is determined, wherein the first distance is positively correlated with the result loss and the second distance is negatively correlated with the result loss; the feature distance between each of the second features in the first sample is determined as the third distance, and the feature distance between each of the second features of the first sample and each of the second features of other first samples is determined as the fourth distance; Based on the third distance and each of the fourth distances, the query loss corresponding to the first sample is determined, wherein the third distance is positively correlated with the query loss and the fourth distance is negatively correlated with the query loss; based on the result loss corresponding to each first sample and the query loss corresponding to each first sample, the comparison loss is determined; based on the first distance and each of the second distances, the result loss corresponding to the first sample is determined, specifically including: For each search result in the first sample, determine the corresponding result text, and generate each difficult sample corresponding to the search result based on the result text; Each difficult sample is input into the result tower to determine the third feature corresponding to each difficult sample; For each first feature of the first sample, the feature distance between the first feature and each third feature of the first sample is determined as each fifth distance; Based on the first distance, each second distance, and each fifth distance corresponding to the first sample, determine the result loss corresponding to the first sample; The fifth distance is negatively correlated with the resulting loss.
7. A computer-readable storage medium, characterized in that, The storage medium stores a computer program, which, when executed by a processor, implements the method described in any one of claims 1 to 5.
8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the method described in any one of claims 1 to 5.
Citation Information
Patent Citations
Method and device for determining search results, apparatus, and computer storage medium
CN109033140A
Model training method and device
CN113344078A
Recommendation method and system based on graph contrast learning and social network enhancement
CN114036406A