A method and device for generating an optimization model
By organizing and splicing the data of user questions and knowledge base questions in the retrieval question answering system, and using the BERT model for encoding and training, the problem of the text matching model not utilizing intent information is solved, and the accuracy and performance of text matching are improved.
Patent Information
- Application Number
- CN202110289744.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-03-16
- Publication Date
- 2024-10-15
- Estimated Expiration
- 2041-03-16
AI Technical Summary
The text matching model in existing retrieval question answering systems fails to fully utilize the intent information of user questions, resulting in insufficient accuracy.
By obtaining training data and organizing it into user questions, knowledge base questions, intent category labels and similarity category labels, the user question types and knowledge base question types are spliced into a whole, adding specific characters as input, using the BERT model for encoding, and selecting features The vector performs text similarity and intent classification calculations and trains the model based on the joint loss function to select the model with the highest F1 value.
It enhances the model's understanding of user input questions, improves the performance of text matching tasks, assists text matching through intent classification, and improves the accuracy of the model.
Smart Images

Figure CN112905750B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of model training, and in particular to a method and device for generating an optimization model. Background Art
[0002] The text matching task is the core task in the search-based question answering system. By calculating the matching degree between the user question and the question in the knowledge base, the best answer corresponding to the user question is returned. Among them, the BERT (a language model) model is a bidirectional language model pre-trained based on large-scale corpus, which can be transferred to the text matching task through fine-tuning. Currently, fine-tuning based on the BERT model is the mainstream method for text matching tasks.
[0003] However, the text matching model in the current retrieval-based question-answering system directly takes user questions as input and does not fully utilize the implicit intent information in user questions, which results in insufficient accuracy.
[0004] Therefore, a better method is needed to solve the problems in the prior art. Summary of the invention
[0005] The present invention provides a method and device for generating an optimization model, which can solve the technical problem of accuracy in the prior art.
[0006] The technical solution of the present invention to solve the above technical problems is as follows:
[0007] The embodiment of the present invention provides a method for generating an optimization model, comprising:
[0008] Get training data;
[0009] Organizing the training data into user questions, questions in a knowledge base, intent category labels of user questions, and similarity category labels;
[0010] The user question type and the question type in the knowledge base are concatenated into a whole through the first character, and the second character and the first character are added to the beginning and the end of the whole respectively as input;
[0011] Based on the input, BERT is used to perform modeling to obtain an encoded vector;
[0012] Select the vector corresponding to the second character as a feature vector;
[0013] Inputting the feature vectors into a first fully connected layer for text similarity calculation and a second fully connected layer for intent classification, respectively, to obtain a text similarity score and an intent classification score;
[0014] Training the model based on the text similarity score and the intent classification score and a loss function of a model combining the first fully connected layer and the second fully connected layer;
[0015] The model with the highest F1 value is selected as the best model from the trained models.
[0016] In a specific embodiment, the text similarity score is determined by the following formula:
[0017] y similarity =Softmax(F similarity (h i ));
[0018] Among them, y similarity is the text similarity score; h i is the eigenvector; F similarity It is the first fully connected layer used for text similarity calculation.
[0019] In a specific embodiment, the intent classification score is determined by the following formula:
[0020] y intent =Softmax(F intent (h i ));
[0021] Among them, y intent Score the intent classification; h i is the eigenvector; F intent is the second fully connected layer for intent classification.
[0022] In a specific embodiment, the loss function is:
[0023] L=αL similarity +(1-α)L intent ;
[0024] Where L is the loss of the model combining the first fully connected layer and the second fully connected layer; L similarity is the loss of the text matching task; L intent is the loss of the intent classification task, α (0≤α≤1) is the coefficient parameter used to control L similarity With L intent The ratio of the two losses.
[0025] In a specific embodiment, the loss of the text matching task is:
[0026]
[0027] Where N is the number of samples, i is the i-th (1≤i≤N) sample in the training data, and yi is the sample similarity category label, y′ i The probability of predicting positive samples for the model.
[0028] In a specific embodiment, the loss of the intent classification task is:
[0029]
[0030] Where K is the total number of sample intent categories, j is the jth (1≤j≤K) category in the intent category, and l j is the sample intent category label, p j The probability that the intent class is j calculated for the model.
[0031] In a specific embodiment, the network parameters of the model are updated by a back-propagation algorithm.
[0032] The embodiment of the present invention further provides a device for generating an optimization model, including:
[0033] An acquisition module is used to acquire training data;
[0034] An organization module, used for organizing the training data into user questions, questions in a knowledge base, intent category labels of user questions, and similarity category labels;
[0035] A concatenation module, used for concatenating the user question type and the question type in the knowledge base into a whole through the first character, and adding the second character and the first character at the beginning and the end of the whole respectively as input;
[0036] A vector module, used for modeling based on the input using BERT to obtain an encoded vector;
[0037] A selection module, used for selecting the vector corresponding to the second character as a feature vector;
[0038] An input module, used to input the feature vector into a first fully connected layer for text similarity calculation and a second fully connected layer for intent classification, respectively, to obtain a text similarity score and an intent classification score;
[0039] A training module, configured to train the model based on the text similarity score and the intent classification score and a loss function of the model combining the first fully connected layer and the second fully connected layer;
[0040] The processing module is used to select the model with the highest F1 value from the trained models as the best model.
[0041] In a specific embodiment, the text similarity score is determined by the following formula:
[0042] y similarity =Softmax(F similarity (h i ));
[0043] Among them, y similarity is the text similarity score; h i is the eigenvector; F similarity It is the first fully connected layer used for text similarity calculation.
[0044] In a specific embodiment, the intent classification score is determined by the following formula:
[0045] y intent =Softmax(F intent (h i ));
[0046] Among them, y intent Score the intent classification; h i is the eigenvector; F intent is the second fully connected layer for intent classification.
[0047] The beneficial effects of the present invention are:
[0048] The embodiment of the present invention proposes a method and device for generating an optimization model, the method comprising: obtaining training data; organizing the training data into user questions, questions in a knowledge base, and intent category labels and similarity category labels of user questions; splicing the user question type and the question type in the knowledge base into a whole through the first character, and adding the second character and the first character at the beginning and end of the whole as input; modeling based on the input using BERT to obtain an encoded vector; selecting the vector corresponding to the second character as a feature vector; inputting the feature vector into the first fully connected layer for text similarity calculation and the second fully connected layer for intent classification, respectively, to obtain a text similarity score and an intent classification score; training the model based on the text similarity score and the intent classification score and the loss function of the model combining the first fully connected layer and the second fully connected layer; selecting the model with the highest F1 value from the trained models as the best model. In this solution, intent classification is combined with text matching tasks, so that the model learns the features of different intents, which can enhance the model's understanding of user input questions, play an auxiliary role in text matching tasks, and improve the performance of model text matching. BRIEF DESCRIPTION OF THE DRAWINGS
[0049] Figure 1 A schematic diagram of a flow chart of a method for generating an optimization model provided by an embodiment of the present invention;
[0050] Figure 2A schematic diagram of a framework of a model in a method for generating an optimization model provided in an embodiment of the present invention;
[0051] Figure 3 A schematic diagram of the structure of a device for generating an optimization model provided by an embodiment of the present invention;
[0052] Figure 4 A schematic diagram of a terminal provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0053] The principles and features of the present invention are described below in conjunction with the accompanying drawings. The examples given are only used to explain the present invention and are not used to limit the scope of the present invention.
[0054] Example 1
[0055] Embodiment 1 of the present invention discloses a method for generating an optimization model, such as Figure 1 As shown, the following steps are included:
[0056] Step 101: Obtain training data;
[0057] Step 102: Organize the training data into user questions, questions in the knowledge base, intent category labels of user questions, and similarity category labels;
[0058] Specifically, organize the training data into Sentence1 i ,Sentence2 i ,l i ,y i form, where Sentence1 i Indicates user questions, Sentence2 i represents the questions in the knowledge base, l i Indicates the intent category label of the user’s question, y i Represents similarity category labels.
[0059] Step 103: concatenate the user question type and the question type in the knowledge base into a whole through the first character, and add the second character and the first character to the beginning and the end of the whole respectively as input;
[0060] Specifically, Sentence1 i ,Sentence2 i Concatenate through [SEP] characters and add [CLS] and [SEP] characters at the beginning and end as input.
[0061] Step 104: Use BERT to perform modeling based on the input to obtain an encoded vector;
[0062] Specifically, the input is modeled using BERT to obtain the encoded vector.
[0063] Step 105: Select the vector corresponding to the second character as a feature vector;
[0064] Specifically, the vector corresponding to the [CLS] character is selected as the feature vector h i . Input them into two fully connected layers with different parameters, where the fully connected layer F_similarity is used to calculate text similarity
[0065] Step 106: input the feature vector into a first fully connected layer for text similarity calculation and a second fully connected layer for intent classification, respectively, to obtain a text similarity score and an intent classification score;
[0066] In a specific embodiment, the text similarity score is determined by the following formula:
[0067] y similarity =Softmax(F similarity (h i ));
[0068] Among them, y similarity is the text similarity score; h i is the eigenvector; F similarity It is the first fully connected layer used for text similarity calculation.
[0069] Furthermore, the intent classification score is determined by the following formula:
[0070] y intent =Softmax(F intent (h i ));
[0071] Among them, y intent Score the intent classification; h i is the eigenvector; F intent is the second fully connected layer for intent classification.
[0072] In addition, the loss function is:
[0073] L=αL similarity +(1-α)L intent ;
[0074] Where L is the loss of the model combining the first fully connected layer and the second fully connected layer; L similarity is the loss of the text matching task; L intent is the loss of the intent classification task, α (0≤α≤1) is the coefficient parameter used to control L similarity With Lintent The ratio of the two losses.
[0075] In a specific embodiment, the loss of the text matching task is:
[0076]
[0077] Where N is the number of samples, i is the i-th (1≤i≤N) sample in the training data, and y i is the sample similarity category label, and y′i is the probability of the model predicting a positive sample.
[0078] In a specific embodiment, the loss of the intent classification task is:
[0079]
[0080] Where K is the total number of sample intent categories, j is the jth (1≤j≤K) category in the intent category, and l j is the sample intent category label, p j The probability that the intent class is j calculated for the model.
[0081] Step 107: training the model based on the text similarity score and the intent classification score and a loss function combining the first fully connected layer and the second fully connected layer model;
[0082] Specifically, the model is Figure 2 As shown in the figure, a BERT joint learning model for intent classification and text matching is constructed with the help of the intent category labels of user questions.
[0083] Specifically, the network parameters of the model are updated by a back propagation algorithm. After each update, a trained model is obtained and step 108 is executed.
[0084] Step 108: Select the model with the highest F1 value from the trained models as the best model.
[0085] Specifically, F1 is also called F value, F-measure, or other variants).
[0086] The F1 value is defined on a per-category basis and includes two major concepts: precision and recall. Precision refers to the proportion of individuals predicted to belong to a certain category that actually belong to that category. Recall refers to the ratio of the number of individuals correctly predicted to belong to a certain category to the total number of individuals of that category in the data set.
[0087] In this solution, intent classification is combined with text matching tasks so that the model can learn the characteristics of different intents. This can enhance the model's understanding of user input questions, assist the text matching task, and improve the model's text matching performance.
[0088] Example 2
[0089] Embodiment 2 of the present invention also discloses a device for generating an optimization model, such as Figure 3 As shown, including:
[0090] An acquisition module 201 is used to acquire training data;
[0091] An organization module 202, used to organize the training data into user questions, questions in the knowledge base, intent category labels of user questions, and similarity category labels;
[0092] A concatenation module 203 is used to concatenate the user question type and the question type in the knowledge base into a whole through the first character, and add the second character and the first character at the beginning and end of the whole respectively as input;
[0093] A vector module 204, configured to perform modeling using BERT based on the input to obtain an encoded vector;
[0094] A selection module 205, configured to select the vector corresponding to the second character as a feature vector;
[0095] An input module 206, used to input the feature vector into a first fully connected layer for text similarity calculation and a second fully connected layer for intent classification, respectively, to obtain a text similarity score and an intent classification score;
[0096] A training module 207, configured to train the model based on the text similarity score and the intent classification score and a loss function of the model combining the first fully connected layer and the second fully connected layer;
[0097] The processing module 208 is used to select the model with the highest F1 value from the trained models as the best model.
[0098] In a specific embodiment, the text similarity score is determined by the following formula:
[0099] y similarity =Softmax(F similarity (h i ));
[0100] Among them, y similarity is the text similarity score; h i is the eigenvector; F similarityIt is the first fully connected layer used for text similarity calculation.
[0101] In a specific embodiment, the intent classification score is determined by the following formula:
[0102] y intent =Softmax(F intent (h i ));
[0103] Among them, y intent Score the intent classification; h i is the eigenvector; F intent is the second fully connected layer for intent classification.
[0104] In a specific embodiment, the loss function is:
[0105] L=αL similarity +(1-α)L intent ;
[0106] Where L is the loss of the model combining the first fully connected layer and the second fully connected layer; L similarity is the loss of the text matching task; L intent is the loss of the intent classification task, α (0≤α≤1) is the coefficient parameter used to control L similarity With L intent The ratio of the two losses.
[0107] In a specific embodiment, the loss of the text matching task is:
[0108]
[0109] Where N is the number of samples, i is the i-th (1≤i≤N) sample in the training data, and y i is the sample similarity category label, y′ i The probability of predicting positive samples for the model.
[0110] In a specific embodiment, the loss of the intent classification task is:
[0111]
[0112] Where K is the total number of sample intent categories, j is the jth (1≤j≤K) category in the intent category, and l j is the sample intent category label, p j The probability that the intent class is j calculated for the model.
[0113] In a specific embodiment, the network parameters of the model are updated by a back-propagation algorithm.
[0114] Example 3
[0115] Embodiment 3 of the present invention further discloses a terminal, such as Figure 4 As shown, it includes: a memory and a processor, and the processor executes the method in Example 1 when running the application in the memory.
[0116] The embodiment of the present invention proposes a method and device for generating an optimization model, the method comprising: obtaining training data; organizing the training data into user questions, questions in a knowledge base, and intent category labels and similarity category labels of user questions; splicing the user question type and the question type in the knowledge base into a whole through the first character, and adding the second character and the first character at the beginning and end of the whole as input; modeling based on the input using BERT to obtain an encoded vector; selecting the vector corresponding to the second character as a feature vector; inputting the feature vector into the first fully connected layer for text similarity calculation and the second fully connected layer for intent classification, respectively, to obtain a text similarity score and an intent classification score; training the model based on the text similarity score and the intent classification score and the loss function of the model combining the first fully connected layer and the second fully connected layer; selecting the model with the highest F1 value from the trained models as the best model. In this solution, intent classification is combined with text matching tasks, so that the model learns the features of different intents, which can enhance the model's understanding of user input questions, play an auxiliary role in text matching tasks, and improve the performance of model text matching.
[0117] The above are only specific embodiments of the present invention, but the protection scope of the present invention is not limited thereto. Any technician familiar with the technical field can easily think of various equivalent modifications or replacements within the technical scope disclosed by the present invention, and these modifications or replacements should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention shall be based on the protection scope of the claims.
Claims
1. A method for generating an optimization model, It is characterized in that include: Get training data; Organizing the training data into user questions, questions in a knowledge base, intent category labels of user questions, and similarity category labels; The type of the user's question and the type of the question in the knowledge base are concatenated into a whole through the first character, and the second character and the first character are added to the beginning and the end of the whole respectively as input; Based on the input, BERT is used to perform modeling to obtain an encoded vector; Select the vector corresponding to the second character as a feature vector; Inputting the feature vectors into a first fully connected layer for text similarity calculation and a second fully connected layer for intent classification, respectively, to obtain a text similarity score and an intent classification score; Training the model based on the text similarity score and the intent classification score and a loss function of a model combining the first fully connected layer and the second fully connected layer; Select the model with the highest F1 value from the trained models as the best model; Wherein, the loss function is: L=αL similarity +(1-α)L intent ; Where L is the loss of the model combining the first fully connected layer and the second fully connected layer; L similarity is the loss of the text matching task; L intent is the loss of the intent classification task, and α is the coefficient parameter used to control L similarity With L intent The ratio of the two losses, where 0≤α≤1.
2. The method according to claim 1, It is characterized in that The text similarity score is determined by the following formula: y similarity =Softmax(F similarity (h i )); Among them, y similarity is the text similarity score; h i is the eigenvector; F similarity It is the first fully connected layer used for text similarity calculation.
3. The method according to claim 1, It is characterized in that The intent classification score is determined by the following formula: y intent =Softmax(F intent (h i )); Among them, y intent Score the intent classification; h i is the eigenvector; F intent is the second fully connected layer for intent classification.
4. The method according to claim 1, Features , the loss of the text matching task is: Where N is the number of samples, i is the i-th sample in the training data, and y i is the sample similarity category label, y′ i is the probability of the model predicting a positive sample, where 1≤i≤N.
5. The method according to claim 1, Features ,The loss of the intent classification task is: Where N is the number of samples, i is the i-th sample in the training data, 1≤i≤N, K is the total number of sample intent categories, j is the j-th category in the intent category, 1≤j≤K, l j is the sample intent category label, p j The probability that the intent class is j calculated for the model.
6. The method according to claim 1, It is characterized in that The network parameters of the model are updated via a back-propagation algorithm.
7. A device for generating an optimization model, It is characterized in that include: An acquisition module is used to acquire training data; An organization module, used for organizing the training data into user questions, questions in a knowledge base, intent category labels of user questions, and similarity category labels; A concatenation module, used for concatenating the type of the user's question and the type of the question in the knowledge base into a whole through the first character, and adding the second character and the first character at the beginning and end of the whole respectively as input; A vector module, used for modeling based on the input using BERT to obtain an encoded vector; A selection module, used for selecting the vector corresponding to the second character as a feature vector; An input module, used to input the feature vector into a first fully connected layer for text similarity calculation and a second fully connected layer for intent classification, respectively, to obtain a text similarity score and an intent classification score; A training module, configured to train the model based on the text similarity score and the intent classification score and a loss function of the model combining the first fully connected layer and the second fully connected layer; A processing module, used for selecting a model with the highest F1 value from the trained models as the best model; Wherein, the loss function is: L=αL similarity +(1-α)L intent ; Where L is the loss of the model combining the first fully connected layer and the second fully connected layer; L similarity is the loss of the text matching task; L intent is the loss of the intent classification task, and α is the coefficient parameter used to control L similarity With L intent The ratio of the two losses, where 0≤α≤1.
8. The device as claimed in claim 7, It is characterized in that The text similarity score is determined by the following formula: y similarity =Softmax(F similarity (h i )); Among them, y similarity is the text similarity score; h i is the eigenvector; F similarity It is the first fully connected layer used for text similarity calculation.
9. The device as claimed in claim 7, It is characterized in that The intent classification score is determined by the following formula: y intent =Softmax(F intent (h i )); Among them, y intent Score the intent classification; h i is the eigenvector; F intent is the second fully connected layer for intent classification.
