Training method, device, medium and computer equipment for text vector extraction model
By dynamically adjusting the negative answer text, the rapid convergence problem caused by the difference between the negative sample and the question text in text vector extraction model training is solved, and the model accuracy and search click-through rate are improved.
Patent Information
- Application Number
- CN202210026790.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-01-11
- Publication Date
- 2024-10-29
- Estimated Expiration
- 2042-01-11
AI Technical Summary
During the training process of the existing text vector extraction model, due to the large difference between the randomly selected negative sample text and the question text, the model converges quickly, reducing the training accuracy and the accuracy of the converted text vector, and affecting the user's search click-through rate.
The initial text vector extraction model is obtained by obtaining multiple text training in the sample training set, determining its text feature vector during the iterative training process, and dynamically adjusting the negative answer text according to the similarity to increase the difficulty of model training and avoid rapid convergence.
It improves the training accuracy of the text vector extraction model, ensures the accuracy of text feature vectors, achieves accurate matching between the user's question text and answer text, and improves the search click-through rate.
Smart Images

Figure CN114386505B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of machine learning technology, and in particular to a training method, apparatus, medium, and computer equipment for a text vector extraction model. Background Technology
[0002] In the modern internet age, text retrieval has become an essential tool for search engines. Text retrieval primarily involves matching the user's question text with the corresponding answer text from a text database and providing the answer back to the user. To reduce network latency, it is necessary to use offline models to convert existing question and answer texts into text vectors.
[0003] Currently, during model training, answer text is typically randomly sampled from a text library as negative sample text for the question text. However, this random sampling method results in significantly different negative sample text from the question text, making it easy for the model to distinguish between them. This leads to rapid model convergence, reducing training accuracy and consequently resulting in low accuracy of the converted text vector. Consequently, the converted text vector cannot accurately match the user's question text, impacting the user's search click-through rate. Summary of the Invention
[0004] This invention provides a training method, apparatus, medium, and computer equipment for a text vector extraction model, which mainly improves the training accuracy of the text vector extraction model.
[0005] According to a first aspect of the present invention, a method for training a text vector extraction model is provided, comprising:
[0006] An initial text vector extraction model is obtained by training multiple texts in a sample training set, wherein the multiple texts include multiple question texts and the corresponding positive and negative answer texts for each of the multiple question texts;
[0007] Determine the text feature vectors corresponding to the multiple texts output by the initial text vector extraction model during this round of iterative training;
[0008] Based on the text feature vector, calculate the first similarity between any one question text and the multiple positive answer texts and the multiple negative answer texts, and determine the new negative answer text corresponding to any one question text based on the first similarity.
[0009] Based on the positive answer text and the new negative answer text corresponding to any given question text, the initial text vector extraction model is iteratively trained until the model converges.
[0010] According to a second aspect of the present invention, a training apparatus for a text vector extraction model is provided, comprising:
[0011] The acquisition unit is used to acquire an initial text vector extraction model trained using multiple texts in the sample training set, wherein the multiple texts include multiple question texts and the positive answer texts and negative answer texts corresponding to the multiple question texts respectively;
[0012] The first determining unit is used to determine the text feature vectors corresponding to the multiple texts output by the initial text vector extraction model during this round of iterative training.
[0013] The second determining unit is configured to calculate, based on the text feature vector, a first similarity between any one question text and the multiple positive answer texts and the multiple negative answer texts, and determine the new negative answer text corresponding to any one question text based on the first similarity.
[0014] The training unit is used to iteratively train the initial text vector extraction model based on the positive answer text and the new negative answer text corresponding to any one of the question texts, until the model converges.
[0015] According to a third aspect of the present invention, a computer-readable storage medium is provided having a computer program stored thereon, which, when executed by a processor, performs the following steps:
[0016] An initial text vector extraction model is obtained by training multiple texts in a sample training set, wherein the multiple texts include multiple question texts and the corresponding positive and negative answer texts for each of the multiple question texts;
[0017] Determine the text feature vectors corresponding to the multiple texts output by the initial text vector extraction model during this round of iterative training;
[0018] Based on the text feature vector, calculate the first similarity between any one question text and the multiple positive answer texts and the multiple negative answer texts, and determine the new negative answer text corresponding to any one question text based on the first similarity.
[0019] Based on the positive answer text and the new negative answer text corresponding to any given question text, the initial text vector extraction model is iteratively trained until the model converges.
[0020] According to a fourth aspect of the present invention, a computer device is provided, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to perform the following steps:
[0021] An initial text vector extraction model is obtained by training multiple texts in a sample training set, wherein the multiple texts include multiple question texts and the corresponding positive and negative answer texts for each of the multiple question texts;
[0022] Determine the text feature vectors corresponding to the multiple texts output by the initial text vector extraction model during this round of iterative training;
[0023] Based on the text feature vector, calculate the first similarity between any one question text and the multiple positive answer texts and the multiple negative answer texts, and determine the new negative answer text corresponding to any one question text based on the first similarity.
[0024] Based on the positive answer text and the new negative answer text corresponding to any given question text, the initial text vector extraction model is iteratively trained until the model converges.
[0025] According to the present invention, a training method, apparatus, and computer device for a text vector extraction model are provided. Compared with the current method of randomly sampling negative sample text, the present invention obtains an initial text vector extraction model trained using multiple texts in a sample training set. The multiple texts include multiple question texts and corresponding positive and negative answer texts. The present invention also determines the text feature vectors corresponding to the multiple texts output by the initial text vector extraction model during the current iterative training process. Simultaneously, based on the text feature vectors, a first similarity is calculated between any one question text and the multiple positive and negative answer texts. Based on the first similarity, a new negative answer text corresponding to any one question text is determined. Finally, the initial text vector extraction model is iteratively trained based on the positive and new negative answer texts corresponding to any one question text until the model converges. Therefore, by dynamically changing the negative answer text corresponding to the question text during the training of the text vector extraction model, the training difficulty of the model can be increased, avoiding rapid convergence of the model, thereby improving the training accuracy of the text vector extraction model. This, in turn, ensures the accuracy of the extracted text feature vectors, achieves precise matching between the user's question text and answer text, and improves the user's search click-through rate. Attached Figure Description
[0026] The accompanying drawings, which are included to provide a further understanding of the invention and form part of this application, illustrate exemplary embodiments of the invention and, together with their description, serve to explain the invention and do not constitute an undue limitation thereof. In the drawings:
[0027] Figure 1A flowchart illustrating a training method for a text vector extraction model provided in an embodiment of the present invention is shown.
[0028] Figure 2 A flowchart illustrating the training method of another text vector extraction model provided in an embodiment of the present invention is shown;
[0029] Figure 3 A schematic diagram of a training device structure for a text vector extraction model provided in an embodiment of the present invention is shown.
[0030] Figure 4 A schematic diagram of the training device structure for another text vector extraction model provided in an embodiment of the present invention is shown;
[0031] Figure 5 A schematic diagram of the physical structure of a computer device provided in an embodiment of the present invention is shown. Detailed Implementation
[0032] The present invention will be described in detail below with reference to the accompanying drawings and embodiments. It should be noted that, unless otherwise specified, the embodiments and features described in the present application can be combined with each other.
[0033] Currently, random sampling results in negative sample texts that differ significantly from the question text, making it easy for the model to distinguish between them. This leads to rapid model convergence, reducing training accuracy and consequently resulting in low accuracy of the converted text vectors. Consequently, the converted text vectors cannot accurately match the user's question text, impacting search click-through rates.
[0034] To address the aforementioned problems, embodiments of the present invention provide a training method for a text vector extraction model, such as... Figure 1 As shown, the method includes:
[0035] 101. Obtain an initial text vector extraction model trained using multiple texts in the sample training set, wherein the multiple texts include multiple question texts and the positive answer texts and negative answer texts corresponding to the multiple question texts respectively.
[0036] Specifically, the initial text vector extraction model can be the initial BERT model, where the positive answer text is the positive sample text corresponding to the question text and its corresponding label is 1, and the negative answer text is the negative sample text corresponding to the question text and its corresponding label is 0.
[0037] This invention is primarily applied to scenarios where a text vector extraction model is trained using the positive and negative answer texts corresponding to a question. The executing entity of this invention is a device or equipment capable of training a text vector extraction model, specifically, it can be located on a server side.
[0038] In this embodiment of the invention, to train the initial text vector extraction model, it is necessary to collect multiple question texts from historical users in advance. Simultaneously, based on a preset text library, corresponding positive and negative answer texts are matched for each question text, and each question text and its corresponding positive and negative answer texts are added to a sample training set. The original BERT model is trained using the sample training set. Therefore, step 101 specifically includes: acquiring multiple question texts from historical search users; determining the answer text with the highest click-through rate for each of the multiple question texts from the preset text library, and using the answer text with the highest click-through rate as the corresponding positive answer text for each of the multiple question texts; for any one of the multiple question texts, randomly selecting an answer text from the remaining answer texts in the preset text library as the negative answer text for that question text; using the positive and negative answer texts corresponding to each of the multiple question texts as the sample training set, and training the initial text vector extraction model using the sample training set.
[0039] Specifically, firstly, multiple question texts from historical search users are obtained. For each question text, the answer text with the highest click-through rate is selected from a pre-defined text library and designated as the positive answer text for that question text. The click-through rate of the answer text is equal to the number of times it was clicked by the user divided by the number of times it appeared. Next, for each question text, one answer text other than its corresponding positive answer text is randomly selected from the pre-defined text library and designated as the negative answer text for that question text. Finally, the positive and negative answer texts for each question text are added to the sample training set. For example, the sample training set is G={(q1,p 1+ ,p 1- ),…,(q i ,p i+ ,p i- ),…,(q n ,p n+ ,p n- )}, where, (q i ,p i+ ,p i-Let represent the i-th question text and its corresponding positive answer text (positive sample text) and randomly selected negative answer text (negative sample text) in the sample training set G, respectively. Further, the original BERT model is trained in the first stage using this sample training set to obtain the initial BERT model (initial text vector extraction model). As an optional implementation method, the training process for the initial text vector extraction model includes: determining the initial text feature vectors corresponding to the multiple texts using the original text vector extraction model; and iteratively training the parameters in the original text vector extraction model based on the initial text feature vectors to obtain the initial text vector extraction model. Therefore, after dynamically adjusting the negative answer text corresponding to each question text, the initial BERT model is trained in the second stage, which avoids rapid convergence of the text vector extraction model and improves the training accuracy of the text vector extraction model.
[0040] Further, regarding the specific process of extracting the initial text feature vector, the step of determining the initial text feature vectors corresponding to the multiple texts using the original text vector extraction model includes: performing word segmentation on the target text in the multiple texts to obtain each word corresponding to the target text; inputting the embedding vectors corresponding to each word into the original text vector extraction model for feature extraction to obtain the initial feature vectors corresponding to each word; and concatenating the initial feature vectors corresponding to each word horizontally to obtain the initial text feature vector corresponding to the target text. Further, the step of inputting the embedding vectors corresponding to each word into the original text vector extraction model for feature extraction to obtain the initial feature vectors corresponding to each word includes: performing a linear transformation on the embedding vectors corresponding to each word to obtain the query vector, key vector, and value vector corresponding to each word; multiplying the query vector corresponding to any one of the words by the key vector corresponding to each word to obtain the attention score of each word for any one word; and multiplying and summing the attention scores corresponding to each word and the value vector to obtain the initial feature vector corresponding to any one word. The target text can be any one of multiple texts.
[0041] In this embodiment of the invention, all question texts and their corresponding positive and negative answer texts in the sample training set need to undergo the above-mentioned process of extracting text feature vectors. Moreover, the process of extracting text feature vectors for question texts, positive answer texts, and negative answer texts is the same. Here, we will only take any text (target text) in the sample training set as an example to illustrate the detailed process of extracting text feature vectors. Specifically, the text feature vector is extracted using the attention layer in the original BERT model. First, the target text is segmented into words to obtain the corresponding words. Then, word2vec is used to determine the embedding vectors corresponding to each word. The embedding vectors corresponding to each word are then input into the attention layer of the original BERT model. When extracting text feature vectors, the attention layer first performs different linear transformations on the embedding vectors corresponding to each word to obtain the query vector, key vector, and value vector corresponding to each word. Then, for any word in each segment, the query vector corresponding to that word is multiplied by the key vector corresponding to each word to obtain the attention score of each word for that word. The attention score corresponding to each word is then multiplied by its corresponding value vector and summed to obtain the feature vector corresponding to that word. Thus, the initial feature vectors corresponding to each word of the target text can be obtained in the above way. Finally, the initial feature vectors corresponding to each word are concatenated horizontally to obtain the initial text feature vector corresponding to the target text.
[0042] 102. Determine the text feature vectors corresponding to the multiple texts output by the initial text vector extraction model during this round of iterative training.
[0043] In this embodiment of the invention, in order to continue iterative training of the initial text vector extraction model using the updated negative answer text, it is necessary to determine the text feature vector corresponding to each question text, the text feature vector corresponding to the positive answer text of each question text, and the text feature vector corresponding to the negative answer text of each question text. Specifically, step 102 includes determining the initial text feature vector under the parameters at the end of this round of iterative training as the text feature vector corresponding to each of the multiple texts. Specifically, based on the initial text feature vector output by the original text vector extraction model, a loss function is constructed. The parameters in the original text vector extraction model are iteratively trained based on this loss function. When the loss function is minimized, the initial text feature vector under the target parameters is determined as the text feature vector corresponding to each of the multiple texts.
[0044] 103. Based on the text feature vector, calculate the first similarity between any one question text and the multiple positive answer texts and the multiple negative answer texts, and determine the new negative answer text corresponding to any one question text based on the first similarity.
[0045] Among them, the similarity between any one question text and the new negative answer text is the greatest. In this embodiment of the invention, after determining the text feature vector corresponding to each question text, the text feature vector corresponding to the positive answer text of each question text, and the text feature vector corresponding to the negative answer text of each question text in the sample training set, it is necessary to re-match the negative answer text for each question text based on the text feature vector, that is, to determine the new negative answer text corresponding to each question text. It should be noted that in this embodiment of the invention, the positive answer text corresponding to each question text remains unchanged, and only the negative answer text is changed. In the process of rematching negative answer texts for question texts, for any question text in the sample training set, the similarity between any question text and other positive answer texts and each negative answer text can be calculated based on the text feature vector corresponding to any question text, the text feature vectors of other positive answer texts besides its corresponding positive answer text, and the text feature vectors corresponding to all negative answer texts. Based on this similarity, the text that is most similar to any question text is selected from other positive answer texts and all negative answer texts as the new negative answer text corresponding to any question text. Thus, in the process of training the initial text feature vector extraction model using the new negative answer text, the model can avoid rapid convergence, thereby improving the training accuracy of the model.
[0046] 104. Based on the positive answer text and the new negative answer text corresponding to any one of the question texts, iteratively train the initial text vector extraction model until the model converges.
[0047] In this embodiment of the invention, after determining the new negative answer text corresponding to each question text, a loss function for the initial text vector extraction model is constructed based on the text feature vector corresponding to each question text, the text feature vector corresponding to the positive answer text of each question text, and the text feature vector corresponding to the new negative answer text of each question text. The initial text vector extraction model is then iteratively trained based on this loss function, and the process of updating negative answer samples and training the model is repeated until the model converges.
[0048] According to an embodiment of the present invention, a training method for a text vector extraction model is provided. Compared with the current method of randomly sampling negative sample text, the present invention obtains an initial text vector extraction model trained using multiple texts in a sample training set. These multiple texts include multiple question texts and corresponding positive and negative answer texts. The method determines the text feature vectors corresponding to the multiple texts output by the initial text vector extraction model during the current iterative training process. Simultaneously, based on the text feature vectors, a first similarity is calculated between any one question text and each of the multiple positive and negative answer texts. Based on the first similarity, a new negative answer text corresponding to any one question text is determined. Finally, the initial text vector extraction model is iteratively trained using the positive and new negative answer texts corresponding to any one question text until the model converges. Therefore, by dynamically changing the negative answer texts corresponding to the question texts during the training process, the training difficulty of the model can be increased, preventing rapid convergence and improving the training accuracy of the text vector extraction model. This ensures the accuracy of the extracted text feature vectors, achieving precise matching between the user's question text and answer text, and improving the user's search click-through rate.
[0049] Furthermore, to better illustrate the training process of the above text vector extraction model, as a refinement and extension of the above embodiments, this embodiment of the invention provides another training method for the text vector extraction model, such as... Figure 2 As shown, the method includes:
[0050] 201. Obtain an initial text vector extraction model trained using multiple texts in the sample training set, wherein the multiple texts include multiple question texts and the positive answer texts and negative answer texts corresponding to the multiple question texts respectively.
[0051] In this embodiment of the invention, the positive answer text and negative answer text corresponding to each question text are determined from a preset text library, and the original BERT model is trained based on the positive answer text and negative answer text corresponding to each question text to obtain an initial text vector extraction model.
[0052] 202. Determine the text feature vectors corresponding to the multiple texts output by the initial text vector extraction model during this round of iterative training.
[0053] In this embodiment of the invention, during the process of determining the text feature vector, each question text and its corresponding positive answer text in the sample training set can be grouped into a positive text pair, and each question text and its corresponding negative answer text can be grouped into a negative text pair. When determining the text feature vector, the positive and negative text pairs can be shuffled and then sequentially input into the initial text vector extraction model for feature extraction. This yields the initial text feature vector corresponding to the question text in each positive text pair, as well as the initial text feature vector corresponding to the positive answer text of that question text. At the same time, the initial text feature vector corresponding to the question text in each negative text pair, as well as the initial text feature vector corresponding to the negative answer text of that question text, can also be obtained. Question texts with the same initial text feature vector are considered the same question text. Thus, the initial text feature vectors corresponding to the positive and negative answer texts of the same question text can be obtained respectively. Using these initial text feature vectors, a loss function is constructed, and the original text vector extraction model is trained. When the loss function is minimized, the text feature vectors corresponding to multiple texts are obtained respectively.
[0054] 203. Based on the text feature vector corresponding to any one question text, the text feature vector corresponding to other positive answer texts (excluding the positive answer text of any one question text), and the text feature vector corresponding to the multiple negative answer texts, calculate the first similarity between any one question text and the other positive answer texts and the multiple negative answer texts respectively.
[0055] In this embodiment of the invention, each question text in the sample training set needs to undergo the above-described process of matching a new negative answer text. The specific formula for matching a new negative answer text for each question text is as follows:
[0056]
[0057] Where Eq represents the text feature vector corresponding to each question text, Ep represents the text feature vectors corresponding to other positive answer texts and all negative answer texts, P represents all answer texts (other positive answer texts and all negative answer texts) in the sample training set G excluding the corresponding positive answer text, and p- represents the new negative answer text corresponding to each question text. Based on the above formula, the cosine similarity between any question text and other positive answer texts and all negative answer texts can be calculated, i.e., the first similarity.
[0058] 204. Based on the calculated first similarity, determine the new negative answer text corresponding to any one of the question texts from the other positive answer texts and the plurality of negative answer texts.
[0059] In this embodiment of the invention, the maximum first similarity is selected from the calculated first similarities, and the negative answer text corresponding to the maximum first similarity is used as the new negative answer text corresponding to any question text. This allows for dynamic adjustment of the negative answer text for each question text. By matching the negative answer text with the highest similarity for each question text, the training difficulty of the model can be increased, and the model can be prevented from converging quickly, thereby improving the training accuracy of the model.
[0060] 205. Based on the positive answer text and the new negative answer text corresponding to any one of the question texts, iteratively train the initial text vector extraction model until the model converges.
[0061] In this embodiment of the invention, after determining the new negative answer text corresponding to each question text, the initial text vector extraction model is iteratively trained in the next stage using the original positive answer text and the new negative answer text corresponding to each question text. As an optional implementation, the method includes: calculating a second similarity between the question text and the positive answer text based on the text feature vector corresponding to the question text and the text feature vector corresponding to the positive answer text; constructing a first loss function corresponding to the initial text vector extraction model based on the calculated second similarity; calculating a third similarity between the question text and the new negative answer text based on the text feature vector corresponding to the question text and the text feature vector corresponding to the new negative answer text; constructing a second loss function corresponding to the initial text vector extraction model based on the calculated third similarity; and iteratively training the initial text vector extraction model based on the first loss function and the second loss function until the model converges.
[0062] Specifically, during the training of the initial text vector extraction model, the goal is to make the question text and its corresponding positive answer text increasingly closer together, while simultaneously increasing the gap between the question text and its corresponding new negative answer text. In other words, the goal is to maximize the first loss function while minimizing the second loss function, thereby continuously iterating the initial text vector extraction model until the model converges and the process of matching the question text with the new negative answer text and training the model stops.
[0063] According to an embodiment of the present invention, another training method for a text vector extraction model is provided. Compared with the current method of randomly sampling negative sample text, the present invention obtains an initial text vector extraction model trained using multiple texts in a sample training set. These multiple texts include multiple question texts and corresponding positive and negative answer texts. The method determines the text feature vectors corresponding to the multiple texts output by the initial text vector extraction model during this iterative training process. Simultaneously, based on the text feature vectors, a first similarity is calculated between any one question text and each of the multiple positive and negative answer texts. Based on the first similarity, a new negative answer text corresponding to any one question text is determined. Finally, the initial text vector extraction model is iteratively trained using the corresponding positive and new negative answer texts until the model converges. Therefore, by dynamically changing the negative answer texts corresponding to the question texts during the training process, the training difficulty of the model can be increased, preventing rapid convergence and improving the training accuracy of the text vector extraction model. This ensures the accuracy of the extracted text feature vectors, achieving precise matching between the user's question text and answer text, and improving the user's search click-through rate.
[0064] Furthermore, as Figure 1 In specific implementation, embodiments of the present invention provide a training device for a text vector extraction model, such as... Figure 3 As shown, the device includes: an acquisition unit 31, a first determination unit 32, a second determination unit 33, and a training unit 34.
[0065] The acquisition unit 31 can be used to acquire an initial text vector extraction model trained using multiple texts in a sample training set. The multiple texts include multiple question texts and the positive answer texts and negative answer texts corresponding to the multiple question texts, respectively.
[0066] The first determining unit 32 can be used to determine the text feature vectors corresponding to the multiple texts output by the initial text vector extraction model during this round of iterative training.
[0067] The second determining unit 33 can be used to calculate, based on the text feature vector, a first similarity between any one question text and the multiple positive answer texts and the multiple negative answer texts, and based on the first similarity, determine the new negative answer text corresponding to any one question text.
[0068] The training unit 34 can be used to iteratively train the initial text vector extraction model based on the positive answer text and the new negative answer text corresponding to any question text, until the model converges.
[0069] In specific application scenarios, the acquisition unit 31, such as Figure 4 As shown, it includes: a first determining module 311 and a first training module 312.
[0070] The first determining module 311 can be used to determine the initial text feature vectors corresponding to the multiple texts using the original text vector extraction model.
[0071] The first training module 312 can be used to iteratively train the parameters in the original text vector extraction model based on the initial text feature vector to obtain the initial text vector extraction model.
[0072] The first determining unit 32 can be specifically used to determine the initial text feature vector under the parameters at the end of the current round of iterative training as the text feature vector corresponding to the multiple texts respectively.
[0073] In specific application scenarios, the first determining module 311 includes: a word segmentation submodule, an extraction submodule, and a splicing submodule.
[0074] The word segmentation submodule can be used to segment the target text in the multiple texts to obtain each word corresponding to the target text.
[0075] The extraction submodule can be used to input the embedding vectors corresponding to each word into the original text vector extraction model for feature extraction, so as to obtain the initial feature vectors corresponding to each word.
[0076] The splicing submodule can be used to horizontally splice the initial feature vectors corresponding to each word segment to obtain the initial text feature vector corresponding to the target text.
[0077] Further, the extraction submodule 322 can be specifically used to perform a linear transformation on the embedding vectors corresponding to each word segment to obtain the query vector, key vector, and value vector corresponding to each word segment; multiply the query vector corresponding to any one of the word segments by the key vector corresponding to each word segment to obtain the attention score of each word segment for any one word segment; multiply the attention score corresponding to each word segment and the value vector and sum them to obtain the initial feature vector corresponding to any one word segment.
[0078] Furthermore, the second determining unit 33 includes: a first calculation module 331 and a second determining module 332.
[0079] The first calculation module 331 can be used to calculate the first similarity between any question text and the other positive answer texts and the multiple negative answer texts, respectively, based on the text feature vector corresponding to any question text, the text feature vector corresponding to other positive answer texts besides the positive answer text of any question text, and the text feature vector corresponding to the multiple negative answer texts.
[0080] The second determining module 332 can be used to determine a new negative answer text corresponding to any one question text from the other positive answer texts and the plurality of negative answer texts based on the calculated first similarity.
[0081] In a specific application scenario, the training unit 34 includes: a second calculation module 341, a construction module 342, and a second training module 343.
[0082] The second calculation module 341 can be used to calculate the second similarity between the text of any question and the text of the correct answer based on the text feature vector corresponding to the text of any question and the text feature vector corresponding to the text of the correct answer.
[0083] The construction module 342 can be used to construct a first loss function corresponding to the initial text vector extraction model based on the calculated second similarity.
[0084] The second calculation module 341 can also be used to calculate a third similarity between the arbitrary question text and the new negative answer text based on the text feature vector corresponding to the arbitrary question text and the text feature vector corresponding to the new negative answer text.
[0085] The construction module 342 can also be used to construct a second loss function corresponding to the initial text vector extraction model based on the calculated third similarity.
[0086] The second training module 343 can be used to iteratively train the initial text vector extraction model based on the first loss function and the second loss function until the model converges.
[0087] In a specific application scenario, the acquisition unit 31 can be used to acquire multiple question texts from historical search users; determine the answer text with the highest click rate for each of the multiple question texts from a preset text library, and use the answer text with the highest click rate as the positive answer text corresponding to each of the multiple question texts; for any one of the multiple question texts, randomly select an answer text from the remaining answer texts in the preset text library as the negative answer text for that question text; use the positive answer texts and negative answer texts corresponding to each of the multiple question texts as the sample training set, and use the sample training set to train the initial text vector extraction model.
[0088] It should be noted that other corresponding descriptions of the functional modules involved in the training device for a text vector extraction model provided in this embodiment of the invention can be found in [reference needed]. Figure 1 The corresponding description of the method shown will not be repeated here.
[0089] Based on the above, Figure 1 Accordingly, this embodiment of the invention also provides a computer-readable storage medium storing a computer program that, when executed by a processor, performs the following steps: obtaining an initial text vector extraction model trained using multiple texts in a sample training set, wherein the multiple texts include multiple question texts and corresponding positive and negative answer texts; determining the text feature vectors corresponding to the multiple texts output by the initial text vector extraction model during the current round of iterative training; calculating a first similarity between any one question text and the multiple positive and negative answer texts based on the text feature vectors, and determining a new negative answer text corresponding to any one question text based on the first similarity; and iteratively training the initial text vector extraction model based on the positive and new negative answer texts corresponding to any one question text until the model converges.
[0090] Based on the above, Figure 1 The method shown and as Figure 3 The embodiment of the device shown in the invention also provides a physical structure diagram of a computer device, such as... Figure 5As shown, the computer device includes a processor 51, a memory 52, and a computer program stored in the memory 52 and executable on the processor. Both the memory 52 and the processor 51 are mounted on a bus 53. When the processor 51 executes the program, it performs the following steps: obtaining an initial text vector extraction model trained using multiple texts from a sample training set, wherein the multiple texts include multiple question texts and corresponding positive and negative answer texts; determining the text feature vectors corresponding to the multiple texts output by the initial text vector extraction model during this round of iterative training; calculating a first similarity between any one question text and the multiple positive and negative answer texts based on the text feature vectors, and determining a new negative answer text corresponding to any one question text based on the first similarity; and iteratively training the initial text vector extraction model based on the positive and new negative answer texts corresponding to any one question text until the model converges.
[0091] The technical solution of this invention enables the acquisition of an initial text vector extraction model trained using multiple texts from a sample training set. These multiple texts include multiple question texts and their corresponding positive and negative answer texts. The model then determines the text feature vectors output by the initial text vector extraction model during this iterative training process. Simultaneously, based on these text feature vectors, a first similarity is calculated between any one question text and each of the positive and negative answer texts. Based on this first similarity, a new negative answer text corresponding to any one question text is determined. Finally, the initial text vector extraction model is iteratively trained using the positive and new negative answer texts corresponding to any one question text until the model converges. Therefore, by dynamically changing the negative answer texts corresponding to the question texts during the training process, the training difficulty of the model is increased, preventing rapid convergence and improving the training accuracy. This ensures the accuracy of the extracted text feature vectors, achieving precise matching between the user's question text and answer text, and increasing the user's search click-through rate.
[0092] It is obvious to those skilled in the art that the modules or steps of the present invention described above can be implemented using general-purpose computing devices. They can be centralized on a single computing device or distributed across a network of multiple computing devices. Optionally, they can be implemented using computer-executable program code, thereby storing them in a storage device for execution by a computing device. In some cases, the steps shown or described can be performed in a different order than those presented herein, or they can be fabricated as separate integrated circuit modules, or multiple modules or steps can be fabricated as a single integrated circuit module. Thus, the present invention is not limited to any particular combination of hardware and software.
[0093] The above description is merely a preferred embodiment of the present invention and is not intended to limit the invention. Various modifications and variations can be made to the present invention by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.
Claims
1. A training method for a text vector extraction model, It is characterized in that include: Obtaining an initial text vector extraction model trained using multiple texts in a sample training set, wherein the multiple texts include multiple question texts and positive answer texts and negative answer texts corresponding to the multiple question texts respectively; Determine text feature vectors corresponding to the plurality of texts respectively output by the initial text vector extraction model during this round of iterative training; According to the text feature vector, respectively calculating a first similarity between any one of the multiple question texts and the multiple positive answer texts and the multiple negative answer texts, and determining a new negative answer text corresponding to any one of the question texts based on the first similarity; Iteratively training the initial text vector extraction model according to the positive answer text and the new negative answer text corresponding to any one of the question texts until the model converges; According to the positive answer text and the new negative answer text corresponding to any one of the question texts, the initial text vector extraction model is iteratively trained until the model converges, including: Calculating a second similarity between the any one question text and the correct answer text according to the text feature vector corresponding to the any one question text and the text feature vector corresponding to the correct answer text; Constructing a first loss function corresponding to the initial text vector extraction model according to the calculated second similarity; Calculating a third similarity between the any one question text and the new negative answer text according to the text feature vector corresponding to the any one question text and the text feature vector corresponding to the new negative answer text; Constructing a second loss function corresponding to the initial text vector extraction model according to the calculated third similarity; According to the first loss function and the second loss function, the initial text vector extraction model is iteratively trained, and the process of updating the negative answer text and training the model is repeated until the model converges.
2. The method according to claim 1, It is characterized in that The step of obtaining an initial text vector extraction model obtained by training multiple texts in a sample training set includes: Determine the initial text feature vectors corresponding to the plurality of texts respectively using the original text vector extraction model; Based on the initial text feature vector, iteratively training the parameters in the original text vector extraction model to obtain the initial text vector extraction model; The determining of the text feature vectors respectively corresponding to the plurality of texts output by the initial text vector extraction model during the current round of iterative training includes: The initial text feature vector under the parameters at the end of this round of iterative training is determined as the text feature vectors corresponding to the multiple texts respectively.
3. The method according to claim 1, It is characterized in that The step of using the original text vector extraction model to determine the initial text feature vectors corresponding to the plurality of texts respectively includes: Performing word segmentation processing on a target text among the multiple texts to obtain each word segmentation corresponding to the target text; Inputting the embedding vectors corresponding to the respective word segments into the original text vector extraction model for feature extraction to obtain the initial feature vectors corresponding to the respective word segments; The initial feature vectors corresponding to the various word segments are horizontally spliced to obtain an initial text feature vector corresponding to the target text.
4. The method according to claim 3, It is characterized in that The step of inputting the embedding vectors corresponding to the respective word segments into the original text vector extraction model for feature extraction to obtain the initial feature vectors corresponding to the respective word segments includes: Performing a linear transformation on the embedding vectors corresponding to the respective word segments to obtain the query vectors, key vectors, and value vectors corresponding to the respective word segments; Multiplying the query vector corresponding to any one of the participles by the key vector corresponding to each participle, respectively, to obtain the attention score of each participle for the any one participle; The attention scores corresponding to the respective participles are multiplied by the value vector and the summed up to obtain an initial feature vector corresponding to any participle.
5. The method according to claim 1, It is characterized in that The method of calculating first similarities between any one of the multiple question texts and the multiple positive answer texts and the multiple negative answer texts based on the text feature vector, and determining a new negative answer text corresponding to any one of the question texts based on the first similarities, comprises: Calculate first similarities between the any one question text and the other positive answer texts and the multiple negative answer texts respectively according to the text feature vector corresponding to the any one question text, the text feature vectors corresponding to the other positive answer texts except the positive answer text of the any one question text, and the text feature vectors corresponding to the multiple negative answer texts respectively; According to the calculated first similarity, a new negative answer text corresponding to any one of the question texts is determined from the other positive answer texts and the multiple negative answer texts.
6. The method according to claim 1, It is characterized in that The step of obtaining an initial text vector extraction model obtained by training multiple texts in a sample training set includes: Get multiple question texts of historical search users; Determine the answer texts with the highest click rates for the multiple question texts from the preset text library, and use the answer texts with the highest click rates as the correct answer texts corresponding to the multiple question texts respectively; For any one of the multiple question texts, randomly extract an answer text from the remaining answer texts in the preset text library as a negative answer text for the any one of the question texts; The positive answer texts and negative answer texts respectively corresponding to the multiple question texts are used as the sample training sets, and the sample training sets are used to train the initial text vector extraction model.
7. A training device for a text vector extraction model, It is characterized in that include: An acquisition unit, used to acquire an initial text vector extraction model trained by using multiple texts in a sample training set, wherein the multiple texts include multiple question texts and positive answer texts and negative answer texts respectively corresponding to the multiple question texts; A first determining unit is used to determine text feature vectors corresponding to the multiple texts respectively output by the initial text vector extraction model during this round of iterative training; A second determination unit is used to calculate, according to the text feature vector, a first similarity between any one of the multiple question texts and the multiple positive answer texts and the multiple negative answer texts, and determine a new negative answer text corresponding to any one of the question texts based on the first similarity; A training unit, configured to iteratively train the initial text vector extraction model according to the positive answer text and the new negative answer text corresponding to any one of the question texts until the model converges; The training unit is specifically used to calculate the second similarity between any question text and the positive answer text based on the text feature vector corresponding to any question text and the text feature vector corresponding to the positive answer text; construct a first loss function corresponding to the initial text vector extraction model based on the calculated second similarity; calculate the third similarity between any question text and the new negative answer text based on the text feature vector corresponding to any question text and the text feature vector corresponding to the new negative answer text; construct a second loss function corresponding to the initial text vector extraction model based on the calculated third similarity; iteratively train the initial text vector extraction model based on the first loss function and the second loss function, and repeat the process of updating the negative answer text and the training model until the model converges.
8. A computer-readable storage medium having a computer program stored thereon, It is characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.
9. A computer device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, It is characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.
Citation Information
Patent Citations
Negative sample determination method, related equipment and readable storage medium
CN113849603A
