A multi-turn dialogue method for fixed knowledge domain retrieval model
Through the combination of tf-idf features and BERT model, combined with the KdConv data set and knowledge graph, the problem of multiple rounds of dialogue and insufficient answer coverage in the retrieval dialogue system is solved, and high-quality dialogue replies and diversity improvement are achieved.
Patent Information
- Application Number
- CN202111442653.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-30
- Publication Date
- 2024-08-27
- Estimated Expiration
- 2041-11-30
AI Technical Summary
Existing retrieval dialogue systems are difficult to conduct multiple rounds of dialogue and cannot provide reasonable answers outside of specific question and answer pairs. Database expansion consumes a lot of manpower and material resources and is difficult to cover all questions.
By obtaining the tf-idf features of the input question for rough sorting, combined with the pre-trained BERT model for precise sorting, and using the KdConv format data set and knowledge graph for data enhancement, an attention loss function is added to improve the model reply effect.
It achieves high-quality multi-round conversations in fixed knowledge fields, improves the model's response accuracy and diversity, and solves the problems of contextual association and data set unified rules.
Smart Images

Figure CN114138959B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of robot natural language processing, and in particular to a multi-round dialogue method for a fixed knowledge domain retrieval model. Background Art
[0002] At present, most dialogue systems are retrieval-based. Because retrieval-based models are based on large-scale question-answer databases, the responses are relatively stable and can avoid grammatical errors and will not generate offensive language. They are often used in the service industry and are widely used in engineering. However, existing retrieval models also have some shortcomings:
[0003] (1) Most retrieval models retrieve data from the database in a question-and-answer format, which makes it difficult to conduct multiple rounds of dialogue with context;
[0004] (2) The limitation of the retrieval model is that it can only answer questions in specific question-answer pairs. Once text outside the database is entered, no reasonable answer can be obtained.
[0005] In order to answer all questions as much as possible, it is necessary to continuously expand the capacity of the database. The construction of the database is mainly done manually, which consumes manpower and material resources, and it is difficult to cover all questions. Summary of the invention
[0006] The purpose of the present invention is to overcome the defects of the above-mentioned prior art and provide a multi-round dialogue method for a fixed knowledge domain retrieval model.
[0007] The purpose of the present invention can be achieved by the following technical solutions:
[0008] A multi-round dialogue method for a fixed knowledge domain retrieval model comprises the following steps:
[0009] 1) Obtain the tf-idf features of the input question text and perform rough sorting to obtain multiple best matching candidate responses;
[0010] 2) The question text and candidate responses are combined into sentence pairs, and the pre-trained BERT model is used to accurately sort them, and the response with the highest score is predicted as the expected response.
[0011] The step 1) is specifically as follows:
[0012] After the input question text is converted into TF-IDF features, two rounds of BM25 retrieval are used to perform rough sorting based on the relevance between the input question text and the text in the corpus, and the question that best matches the input text is selected.
[0013] In the first round of BM25 retrieval, the query text and all the question texts in the corpus are searched through QQ matching to screen out the top ten most matching questions. Each question corresponds to multiple rounds of dialogues, which are used as candidate replies for the second round of BM25 retrieval. For the highest-scoring reply after the first round of BM25 retrieval, the input question text and the reply are concatenated and used again as a candidate reply for the second round of BM25 retrieval, and finally the 10 best-matching candidate replies are retrieved.
[0014] In the step 2), data enhancement based on the knowledge graph is performed on the sentence pairs consisting of the question text and the candidate responses based on the KdConv format dataset.
[0015] In the pre-training stage of the BERT model, the triple data in the KdConv format dataset is merged with the output of the BERT structure to improve the model's response effect.
[0016] For the i-th group of triples in the KdConv format dataset, define k i The word vectors representing the head entity and relation are defined as v i The word vector representing the tail entity, the query vector q and the word vector k output by the BERT encoder containing the semantic information of the input question text i Calculate the weight α i =softmax i (q T k i ), the weight α i And the word vector v of the corresponding tail entity i Multiply them together to get the weighted sum vector representing the triple to predict the probability scores of candidate responses.
[0017] After adding the corresponding weighted sum vector v containing triple information to the BERT model training process, the new loss function is specifically the original cross entropy loss function L 0 Based on this, we add the attention loss function L att .
[0018] The expression of the new loss function L is:
[0019] L=L 0 +βL att
[0020] Among them, β is the attention loss coefficient.
[0021] The BERT model is evaluated by text diversity and text accuracy. The accuracy of the BERT model is evaluated using the Hits indicator and the BLEU indicator, and the text diversity is evaluated using the Distinct indicator. The changes in accuracy with the attention loss coefficient β are obtained respectively, and the optimal value is confirmed based on this.
[0022] The optimal value of the attention loss coefficient β is 0.105.
[0023] Compared with the prior art, the present invention has the following advantages:
[0024] 1. The present invention utilizes the format of the KdConv dataset to address the problems of the lack of context association in the existing Chinese search-based dialogue model and the lack of unified rules in the dataset, obtains a high-quality dataset containing triple information, and merges the triple data with the query vector output by the BERT structure containing the semantic information of the input question text to obtain a new feature, namely the weighted sum vector, which is trained with a new loss function to improve the response effect of the model.
[0025] 2. The present invention evaluates the improved retrieval model that incorporates knowledge graph information in terms of text accuracy evaluation indicators BLUE@n, Hit@n and text diversity evaluation indicator Distinct@n, selects the optimal attention loss coefficient of 0.105, and determines the objective function of the final retrieval model. Compared with the model without adding knowledge graph information, the retrieval model effectively improves both the accuracy score and the diversity score. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] Figure 1 A framework for a retrieval-based dialogue system.
[0027] Figure 2 This is the specific process of the retrieval model ranking algorithm.
[0028] Figure 3 The database ER diagram of the data set collection platform is used.
[0029] Figure 4 It is the front-end interface of the dataset collection platform.
[0030] Figure 5 This is the encoding process of the BERT model for the input.
[0031] Figure 6 The BERT sorting process with knowledge graph information added.
[0032] Figure 7 The accuracy of the model is evaluated by the Hits indicator and the BLEU indicator.
[0033] Figure 8 Evaluate the diversity of the model for the Distinct metric.
[0034] Fig. 9 To demonstrate the dialogue effect of the optimal model using the music field as an example.
[0035] Fig.10 It is a flowchart of the overall method of the present invention. DETAILED DESCRIPTION
[0036] The present invention is described in detail below in conjunction with the accompanying drawings and specific embodiments. This embodiment is implemented based on the technical solution of the present invention, and provides a detailed implementation method and specific operation process, but the protection scope of the present invention is not limited to the following embodiments.
[0037] like Fig.10 As shown, in view of the shortcomings of the current retrieval dialogue model, the present invention proposes a multi-round dialogue method for a fixed knowledge domain retrieval model, comprising the following steps:
[0038] S1. Build a corpus in a unified format and develop a corpus collection platform using database and web technologies;
[0039] S2, extract the TF-IDF features of the text, perform BM25 search, and provide candidate responses for the input text;
[0040] S3. Use the BERT model to predict the characteristics of the following text, input the input text and the candidate response into sentence pairs and input them into the BERT model, and predict the response with the highest score, which is the expected response;
[0041] S4, using KdConv knowledge graph for data enhancement, adding triple data information for training on the basis of BERT model;
[0042] S5. Optimize the original objective function and determine the attention loss coefficient, and select the optimal attention loss coefficient.
[0043] In step S1, a standardized data set collection platform is implemented using Mysql database + Springboot backend architecture + react frontend framework;
[0044] Example
[0045] This embodiment provides a music field search model dialogue method, the framework diagram of the method is as follows: Figure 2 As shown, the specific steps include:
[0046] S1. Collection of KdConv format datasets to obtain high-quality triple information containing knowledge graphs;
[0047] S2, BM25 rough sorting process, two rounds of BM25 retrieval are performed based on the tf-idf features of the text, and finally the 10 best matching candidate replies are retrieved;
[0048] S3. Through the precise sorting of the BERT pre-trained model, the question and the candidate responses obtained in step S2 are combined into sentence pairs and input into the BERT model. The response with the highest score is predicted as the expected response.
[0049] S4, based on the data enhancement of KdConv knowledge graph, the corresponding vector containing triple information is added to the vector output by BERT encoder;
[0050] S5. Optimization of the objective function. According to the added triple information, the objective function increases the attention loss coefficient accordingly to improve the model accuracy and diversity.
[0051] During the implementation of step S1, the instance database platform is built using Mysql database + Springboot backend architecture + react frontend framework.
[0052] In the implementation process of step S2, after the input text is converted into TF-IDF features, it is sorted according to the relevance between the input text and the text in the corpus and the questions matching the input text are selected. This sorting method uses the BM25 retrieval algorithm to search the query text with all the question texts in the corpus through QQ matching, and selects the top ten most matching questions {Q 1 ,...,Q 10}, each question in the dataset corresponds to multiple rounds of dialogue, all of which are used as candidate replies in the second round of BM25 retrieval algorithm. After the first round of BM25 retrieval, the highest-scoring reply is obtained, and the input text is concatenated with the reply and then searched again in the candidate replies, and finally the 10 best matching candidate replies are retrieved.
[0053] In the implementation of step S3, BERT is selected as the model for accurate sorting. BERT performs well for tasks where the language itself contains the answer. In retrieval-based NLP tasks, it does not need to rely on other features outside the text. Therefore, BERT is selected to accurately sort the candidate texts. In the pre-training stage, BERT adds Next Sentence Prediction, and the self-attention mechanism comes with the attention of words in sentence A and any words in sentence B. This fine-grained matching improves the matching accuracy. Step S2 retrieves 10 candidate answers through two rounds of BM25 algorithm, and the question and the candidate answers are respectively composed of sentence pairs and input into the BERT model. The response with the highest score is predicted as the expected response.
[0054] During the implementation of step S4, BERT performs well for tasks where the answer is contained in the language itself, but the text often contains some other features, which can be represented in the form of knowledge graph triples for more feature processing. The KdConv format dataset provides a corpus that simulates a continuous conversation between two people for the multi-round retrieval dialogue model, so that the model can fit the context while ensuring the semantic and grammatical correctness of the reply text. First, the first main question is used as the beginning of a conversation, and then the conversation content is extended according to the main question. The conversation content is completely obtained based on the triple information and does not contain additional information. The KdConv format dataset facilitates the addition of knowledge graph triple knowledge to the model to improve the model's response effect. For the i-th group of triples in the dataset, define k i The word vectors representing the head entity and relation are defined as v i The query vectors q and k that contain the semantic information of the input text are output by the BERT structure. i Calculate a series of weights: α i =softmax i (q T k i ), multiplying the weight by the corresponding tail entity word vector, we can get the weighted sum vector representing the triple:
[0055] In the implementation process of step S5, the corresponding vector v containing triple information is added to the BERT model training process, and the loss function is in the cross entropy loss function L 0 Based on this, attention loss L is added att :
[0056] L=L 0 +βL att
[0057] The confirmation of the attention loss coefficient β was obtained through comparative experiments. The evaluation indicators of the model were evaluated from two perspectives: text diversity and text accuracy. The accuracy of the model was evaluated using the Hits and BLEU indicators. The accuracy changes with the attention loss coefficient β as shown in the figure below: Figure 7 The text diversity of the model is evaluated using the Distinct indicator, and the diversity score changes with the attention loss coefficient β as shown in Figure 8 , combining these two indicators, taking the attention loss coefficient β as 0.105, the final objective function is written as:
[0058] L=L 0 +0.105L att
[0059] The preferred specific embodiments of the present invention are described in detail above. It should be understood that a person skilled in the art can make many modifications and changes based on the concept of the present invention without creative work. Therefore, any technical solution that can be obtained by a person skilled in the art through logical analysis, reasoning or limited experiments based on the concept of the present invention on the basis of the prior art should be within the scope of protection determined by the claims.
Claims
1. A multi-round dialogue method for a fixed knowledge domain retrieval model, characterized in that: The following steps are involved: 1) Obtain the tf-idf features of the input question text and perform rough sorting to obtain multiple best matching candidate responses; 2) The question text and candidate responses are combined into sentence pairs, and the pre-trained BERT model is used to accurately sort them. The response with the highest score is predicted as the expected response; The step 1) is specifically as follows: After the input question text is converted into TF-IDF features, two rounds of BM25 retrieval are used to perform rough sorting based on the relevance between the input question text and the text in the corpus, and the question that best matches the input text is selected; In the first round of BM25 search, the query text and all the question texts in the corpus are searched through QQ matching and the top ten most matching questions are selected. Each question corresponds to multiple rounds of dialogue, which are used as candidate replies for the second round of BM25 search. For the highest-scoring reply obtained after the first round of BM25 search, the input question text and the reply are concatenated and used as the candidate reply for the second round of BM25 search. Finally, the 10 best-matching candidate replies are retrieved. In the step 2), data enhancement based on the knowledge graph is performed on the sentence pairs consisting of the question text and the candidate responses based on the KdConv format dataset; In the pre-training phase of the BERT model, the triple data in the KdConv format dataset is merged with the output of the BERT structure to improve the model's response effect; For the i-th group of triples in the KdConv format dataset, define k i The word vectors representing the head entity and relation are defined as v i The word vector representing the tail entity, the query vector q and the word vector k output by the BERT encoder containing the semantic information of the input question text i Calculate the weight α i =softmax i (q T k i ), the weight α i And the word vector v of the corresponding tail entity i Multiply them together to get the weighted sum vector representing the triple to predict the probability scores of candidate responses.
2. A multi-round dialogue method for a fixed knowledge domain retrieval model according to claim 1, characterized in that: After adding the corresponding weighted sum vector v containing triple information to the BERT model training process, the new loss function is specifically to add the attention loss function L0 to the original cross entropy loss function att .
3. A multi-round dialogue method for a fixed knowledge domain retrieval model according to claim 2, characterized in that: The expression of the new loss function L is: L=L0+βL att Among them, β is the attention loss coefficient.
4. A multi-round dialogue method for a fixed knowledge domain retrieval model according to claim 3, characterized in that: The BERT model is evaluated by text diversity and text accuracy. The accuracy of the BERT model is evaluated using the Hits indicator and the BLEU indicator, and the text diversity is evaluated using the Distinct indicator. The changes in accuracy with the attention loss coefficient β are obtained respectively, and the optimal value is confirmed based on this.
5. A multi-round dialogue method for a fixed knowledge domain retrieval model according to claim 4, characterized in that: The optimal value of the attention loss coefficient β is 0.105.
