A dialogue response generation method and a dialogue response generation method model
Through the dynamic knowledge selection mechanism, the Transformer block is used to capture the dynamic information of knowledge flow, which solves the problem of insufficient utilization of historical selection knowledge in existing models and improves the accuracy of knowledge selection and the quality of dialogue responses.
Patent Information
- Application Number
- CN202210975994.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-15
- Publication Date
- 2025-09-30
- Estimated Expiration
- 2042-08-15
AI Technical Summary
Existing sequential knowledge selection models have shortcomings in utilizing history to select knowledge statements and fail to fully utilize dynamic information, resulting in the dialogue system generating inappropriate responses.
A dynamic knowledge selection mechanism is introduced to explicitly model the dynamic information in historical selected knowledge sentences by calculating the selection perception vector and the knowledge flow trend vector. The Transformer block is used to capture the dynamic information in the knowledge flow, and knowledge selection is performed through comparison function and attention mechanism.
It significantly improves the accuracy of knowledge selection and the quality of dialogue responses, generating more reasonable response statements.
Smart Images

Figure CN115357698B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of dialogue systems, and in particular to a dialogue response generation method and a dialogue response generation method model. Background Art
[0002] In recent years, the rise of new-generation artificial intelligence technologies, represented by deep learning, has driven the rapid development of natural language processing (NLP). Dialogue systems, a key research topic in empowering machines with natural language processing capabilities, have attracted considerable attention from both academia and industry. Traditional end-to-end generative dialogue systems based on a sequence-to-sequence (Seq2Seq) framework can generate a sequence of responses to an input dialogue sequence after training. However, these systems tend to generate generic, repetitive responses that are rigid, meaningless, and inappropriate, such as "OK," "Yes," and "I don't know," and lack the ability to expand the conversational context. Recent research has shown promising results in increasing the information content of responses. Knowledge-grounded conversations (KGC) introduce additional knowledge into the response generation process, making the generated responses more informative. However, a key challenge lies in knowledge selection (KS): how to select appropriate knowledge statements from a given set of knowledge statements to incorporate into the response generation process.
[0003] Existing knowledge selection models can generally be divided into two categories: non-sequential selection and sequential selection. Figure 1 and Figure 2 ,in, Figure 1 Module diagram of the non-sequential knowledge selection model. Figure 2 This is a block diagram of the sequential knowledge selection model. In non-sequential knowledge selection models, knowledge selection in each round of dialogue is independent, relying solely on the dialogue context and a given set of candidate knowledge statements. Knowledge selection primarily considers the relationship between the current dialogue context and external knowledge. Sequential knowledge selection models, on the other hand, not only consider the current dialogue context and a given set of candidate knowledge statements, but also consider historical knowledge selection from previous rounds of dialogue and adjust the current knowledge selection strategy based on the knowledge selection patterns in previous rounds. This sequential selection approach can better simulate multi-round dialogues and promote accurate knowledge selection in subsequent rounds.
[0004] In multi-round conversations, the topic of the conversation is often related to the knowledge introduced. Changes in the topic also lead to changes in the knowledge we should select. We describe this knowledge change as a dynamic knowledge flow. While knowledge flow undoubtedly plays an important role in promoting knowledge selection, it has not been fully utilized in previous research. For example, Kim et al. (Kim B, Ahn J, Kim G (2020) Sequential latent knowledge selection for knowledge-grounded dialogue. In: 8th International Conference on Learning Representations, ICLR 2020, Addis Ababa, Ethiopia, April 26-30, 2020. OpenReview.net, URL https: / / openreview.net / forum?id=Hke0K1HKwr) proposed a Sequential Knowledge Transformer (SKT) model to track the prior and posterior distributions of knowledge selection. This model can not only reduce the ambiguity caused by the diversity of dialogue knowledge selection, but also better utilize the response information to make the correct selection of knowledge; however, the SKT model only uses historically selected knowledge sentences as one of the inputs for its latent variable calculation, which is an indirect utilization. This method does not directly and fully utilize the historically selected knowledge sentences and cannot reasonably utilize dynamic knowledge flow information.Zheng et al. (Zheng C, Cao Y, Jiang D, et al (2020) Difference-aware knowledge selection for knowledge-grounded conversation generation. In: Cohn T, He Y, Liu Y (eds) Findings of the Association for Computational Linguistics: EMNLP2020, Online Event, 16-20 November 2020, vol EMNLP2020. Association for Computational Linguistics, pp 115–125) proposed a difference-aware knowledge selection (DiffKS) model, which calculates the difference between the selected knowledge sentence and the current candidate sentence, and uses a deep learning network to learn the correct difference, thereby promoting the model to select appropriate knowledge; however, the DiffKS model only calculates the difference between the selected knowledge sentence and the current candidate sentence, and utilizes the historical selected knowledge sentences from the perspective of difference, which is also one-sided and insufficient. Meng et al. (Initiative-Aware Self-Supervised Learning for Knowledge-Grounded Conversations[C] / / Proceedings of the 44th International ACM SIGIR Conferenceon Research and Development in Information Retrieval.2021:522-532.) proposed a hybrid active knowledge selection method (MIKe), designed a novel active discriminator to distinguish the active type of knowledge selection in each conversation round, and made judgments based on the situation, promoting the model to select more appropriate knowledge and generate more informative and engaging responses. However, it is more inclined to how to train the active discriminator, and does not pay attention to the utilization of the dynamic knowledge flow information contained in the historically selected knowledge sentences.
[0005] In summary, existing sequential knowledge selection models are insufficient in utilizing the knowledge selected in previous rounds of dialogue. Merely implicit utilization or differential comparison cannot fully utilize the dynamic information implicit in historically selected knowledge statements, making it impossible to make correct knowledge selections, which leads to the dialogue system generating inappropriate responses. Summary of the Invention
[0006] Based on this, the purpose of the present invention is to provide a method for generating dialogue responses that improves the accuracy of knowledge selection.
[0007] The present invention is achieved through the following technical solutions:
[0008] A method for generating a dialogue response, comprising the steps of:
[0009] S12: Calculate and select a perception vector based on the historical selection knowledge vector, and then execute steps S13 and S14 respectively;
[0010] S13: Calculating a knowledge flow trend vector based on the selection perception vector and the historical selection knowledge vector;
[0011] S14: Compare the selected perception vector and the candidate knowledge vector to obtain comparison information;
[0012] S15: Encode the context sentence to obtain a context vector; wherein step S15 is performed at any stage before step S20;
[0013] S20: Calculate knowledge selection distribution by using the context vector and the knowledge flow trend vector as queries, and the candidate knowledge vector and the comparison information as keys;
[0014] S30: Calculating the attention score of each candidate knowledge vector according to the knowledge selection distribution, and taking the candidate knowledge vector with the highest attention score as the currently selected knowledge vector;
[0015] S40: Calculating a historical decoding state vector based on the context vector and the currently selected knowledge vector, and calculating a current moment's decoding state vector based on the historical decoding state vector and historical generated words;
[0016] S50: Calculate the vocabulary generation probability at the current moment and the knowledge replication probability at the current moment based on the decoding state vector at the current moment, the historical generated words, the context vector, and the currently selected knowledge vector, and calculate the target generation probability at the current moment based on the vocabulary generation probability at the current moment and the knowledge replication probability at the current moment.
[0017] The dialogue response generation method described in the present invention introduces a dynamic knowledge selection mechanism, which explicitly and directly models historical selected knowledge statements to obtain a selection perception vector containing dynamic information of the knowledge flow; then, by interactively calculating the selection perception vector, a knowledge flow trend vector is obtained to predict the knowledge flow trend in the knowledge selection process, which is conducive to improving the accuracy of the knowledge selection process and prompting the dialogue system to generate more reasonable response statements.
[0018] Furthermore, step S12 is specifically as follows:
[0019] A self-attention mechanism of a layer of Transformer blocks is used to model the historical selection knowledge vector, capture the dynamic information in the knowledge flow, and obtain the selection perception vector, which is calculated as follows:
[0020] F τ =Transformer[TE(r τ-N,s , r τ-N+1,s ,...,r τ-1,s )] (4)
[0021] F τ ={f τ-N , f τ-N+1 ,...,f τ-1} (5)
[0022] Where, F τ is the selected perception vector of the τth round of dialogue; f τ-N , f τ-N+1 ,...,f τ-1 are the mutual perception vectors from the (τ-N)th round to the (τ-1)th round of dialogue; TE() represents the operation of adding the information embedding of the corresponding round to each of the historical selection knowledge vectors; r τ-N,s , r τ-N+1,s ,...,r τ-1,s are the historical selection knowledge vectors for the (τ-N)th to (τ-1)th rounds of dialogue respectively; N is the knowledge selection parameter.
[0023] Furthermore, the calculation formula of the knowledge flow trend vector is:
[0024]
[0025]
[0026] Where, T τ is the knowledge flow trend vector of the τth round of dialogue; f τ-n is the mutual perception vector of the (τ-n)th round of dialogue, r τ-n,s Select a knowledge vector for the history of the (τ-n)th round of dialogue; n Choose the weight for the knowledge of the (τ-n)th round of dialogue; where n∈[1, N], and
[0027] Furthermore, step S14 is specifically as follows:
[0028] Each candidate knowledge vector is compared with the selected perception vector of the current round by a comparison function to obtain the comparison information, which is calculated as follows:
[0029]
[0030]
[0031] Among them, f n is the mutual perception vector of the (τ-n)th round of dialogue, r l is the lth candidate knowledge vector, o τ,l is the comparison information between the lth candidate knowledge vector and the selected knowledge vector in the τth round of dialogue; Compare(,) represents the comparison function, F() represents the tanh activation function, and ⊙ represents the Hamada product.
[0032] Furthermore, step S20 is specifically as follows:
[0033] The context vector and the knowledge flow trend vector are used as queries, and the candidate knowledge vector and the comparison information are used as keys to calculate the knowledge selection distribution. The calculation formula is:
[0034]
[0035] Where, is the context vector; β τ,l is the knowledge selection distribution calculated with the lth candidate knowledge vector and its corresponding comparison information as the key; v is the matrix transformation parameter, represents the transpose of the matrix, W query is the query matrix, W key is the key matrix; tanh() represents the tanh activation function.
[0036] Furthermore, before step S12, the following steps are also included:
[0037] S11: Encode all candidate knowledge statements in the candidate knowledge statement set to obtain the candidate knowledge vector; wherein, the candidate knowledge statement set includes historically selected knowledge statements, and the candidate knowledge vector includes the corresponding historically selected knowledge vector.
[0038] Furthermore, step S11 is specifically as follows:
[0039] A bidirectional gated recurrent unit is used to encode all candidate knowledge sentences in the candidate knowledge sentence set for the first time to obtain a candidate knowledge intermediate vector; a bidirectional gated recurrent unit is used to encode the candidate knowledge intermediate vector for the second time to obtain a candidate knowledge vector.
[0040] Furthermore, the parameter optimization step is also included:
[0041] S91: Initialize the network parameters of steps S11 to S80, randomly divide the conversation samples in the training set into multiple batches, execute steps S11 to S80 on the conversation samples in the training set batch by batch to optimize the network parameters, and calculate the loss using a total loss function; wherein the total loss function includes a knowledge flow supervision loss function, a knowledge selection loss function, and a response generation loss function;
[0042] S92. After each iteration, perform steps S11 to S80 on the conversation samples in the validation set to perform validation, and record the validation results and corresponding network parameters of each iteration;
[0043] S93: After multiple iterations, the network parameters corresponding to the optimal verification result in step S92 are selected to update the network parameters of steps S11 to S80, and then steps S11 to S80 are executed on the dialogue samples of the test set to perform performance testing.
[0044] The present invention also provides a dialogue response generation model, comprising:
[0045] A selection perception vector calculation module is used to calculate the selection perception vector based on the historical selection knowledge vector;
[0046] a knowledge flow trend vector calculation module, configured to calculate a knowledge flow trend vector based on the selection perception vector and the historical selection knowledge vector;
[0047] a comparison information calculation module, configured to compare the selected perception vector with the candidate knowledge vector to obtain comparison information;
[0048] A context encoding module is used to encode the context sentence and obtain a context vector;
[0049] a knowledge selection distribution calculation module, configured to calculate the knowledge selection distribution according to the candidate knowledge vector, the knowledge flow trend vector, the comparison information and the context vector;
[0050] a currently selected knowledge vector calculation module, configured to calculate an attention score for each candidate knowledge vector according to the knowledge selection distribution, and select the candidate knowledge vector with the highest attention score as the currently selected knowledge vector;
[0051] a current decoding state vector calculation module, configured to calculate a historical decoding state vector based on the context vector and the currently selected knowledge vector, and to calculate a current moment's decoding state vector based on the historical decoding state vector and historical generated words;
[0052] The target generation probability calculation module is used to calculate the vocabulary generation probability at the current moment and the knowledge replication probability at the current moment based on the decoding state vector, the historical generated words, the context vector, and the currently selected knowledge vector at the current moment, and calculate the target generation probability at the current moment based on the vocabulary generation probability at the current moment and the knowledge replication probability at the current moment.
[0053] Furthermore, it also includes:
[0054] The candidate knowledge encoding module is used to encode all candidate knowledge statements in the candidate knowledge statement set to obtain the candidate knowledge vector; wherein, the candidate knowledge statement set includes historically selected knowledge statements, and the candidate knowledge vector includes the corresponding historically selected knowledge vector.
[0055] Compared with the prior art, the present invention provides a dialogue response generation method and a dialogue response generation method model, and designs a dynamic knowledge selection mechanism. It not only reasonably models the historically selected knowledge sentences and extracts the dynamic information implicit in the knowledge selection process, thereby fully utilizing the historically selected knowledge sentences, but also calculates the knowledge flow trend vector based on the extracted dynamic information, thereby guiding the dialogue system to select more appropriate knowledge sentences in the current round, significantly improving the knowledge selection accuracy of the dialogue system and the quality of dialogue responses; in addition, the present invention also involves a KFS loss function, which supervises the model's learning of the real selection perception vector, improves the modeling ability of the knowledge selection process, and further promotes correct knowledge selection.
[0056] For better understanding and implementation, the present invention is described in detail below with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0057] Figure 1 A schematic diagram of a module for a non-sequential knowledge selection model in background technology;
[0058] Figure 2 A schematic diagram of a module for a sequential knowledge selection model in background technology;
[0059] Figure 3 A flowchart of the steps of a method for generating a dialogue reply provided by the present invention;
[0060] Figure 4 A network architecture diagram of a conversation response generation model provided by the present invention;
[0061] Figure 5 A schematic diagram of a module of a dialogue response generation model provided by the present invention. DETAILED DESCRIPTION
[0062] In the prior art, sequential knowledge selection models have problems such as insufficient accuracy in knowledge selection and inappropriate response sentences generated. The reason is that these models do not fully utilize historically selected knowledge sentences, do not take into account the dynamic information implicit in historically selected knowledge sentences, and cannot predict the knowledge flow trend in the knowledge selection process. Based on this, the present invention proposes a dynamic knowledge selection mechanism (DKSM) mechanism, which explicitly and directly models historically selected knowledge sentences to obtain a selection perception vector containing dynamic information; further, by interactively calculating the selection perception vector, a knowledge flow trend vector is obtained to predict the knowledge flow trend in the knowledge selection process, which is beneficial to improving the accuracy of knowledge selection and prompting the dialogue system to generate more reasonable response sentences.
[0063] In order to make the purpose, technical solutions and advantages of the present invention more clear, specific embodiments are given below for illustration.
[0064] See also Figure 3 , which is a flowchart of a method for generating a conversation reply provided by the present invention, the method comprising the steps of:
[0065] S11: Encode all candidate knowledge sentences in the candidate knowledge sentence set to obtain candidate knowledge vectors; wherein the candidate knowledge sentence set includes historically selected knowledge sentences, and the candidate knowledge vectors include corresponding historically selected knowledge vectors;
[0066] S12: Calculate and select a perception vector based on the historical selection knowledge vector, and then execute steps S13 and S14 respectively;
[0067] S13: Calculate the knowledge flow trend vector based on the selection perception vector and the historical selection knowledge vector;
[0068] S14: comparing the selected perception vector and the candidate knowledge vector to obtain comparison information;
[0069] S15: Encode the context sentence to obtain a context vector; wherein step S15 is performed at any stage before step S20;
[0070] S20: Calculate knowledge selection distribution based on candidate knowledge vectors, knowledge flow trend vectors, comparison information, and context vectors;
[0071] S30: Calculate the attention score of each candidate knowledge vector according to the knowledge selection distribution, and use the candidate knowledge vector with the highest attention score as the current selected knowledge vector;
[0072] S40: Calculate the historical decoding state vector based on the context vector and the currently selected knowledge vector, and calculate the current moment's decoding state vector based on the historical decoding state vector and the historical generated words;
[0073] S50: Calculate the vocabulary generation probability and the knowledge replication probability at the current moment according to the current decoding state vector, historical generated words, context vector, and current selected knowledge vector, and calculate the target generation probability at the current moment according to the vocabulary generation probability and the knowledge replication probability;
[0074] S60: Using the word with the highest probability value among the target generation probabilities at the current moment as the generated word at the current moment;
[0075] S70: Determine whether the generated word at the current moment is an end symbol; if so, execute step S80; if not, treat the generated word at the current moment as a historical generated word and return to step S40;
[0076] S80: The generated words at all moments are combined into a reply sentence and output.
[0077] For a dialogue of Ω rounds, in each round of dialogue, given a context sentence and a set of candidate knowledge sentences, the task of KGC is to select a candidate knowledge sentence from the candidate knowledge sentence set as the current selected knowledge sentence, and generate an appropriate reply sentence by combining the current selected knowledge sentence with the context sentence.
[0078] For the τth round of dialogue, the user’s input statement is represented as X τ =(x τ,1 , x τ,2 ,...,x τ,M ), where M is the sequence length of the input sentence, x τ,m ∈X τ is the mth word in the input sentence, and m∈[1,M],τ∈[1,Ω]. The candidate knowledge sentence set is represented as K=(K1,K2,...,K L ), where L is the total number of candidate knowledge sentences, K l ∈K is the lth candidate knowledge statement in the candidate knowledge statement set, and l∈[1, L]. A candidate knowledge statement is selected from the candidate knowledge statement set as the current selected knowledge statement for the τth round of dialogue, which is denoted by K τ,s ={k τ,1 , k τ,2 ,...,k τ,J}, where J is the sequence length of the currently selected knowledge statement, k τ,j ∈K τ,sis the jth word in the input sentence, and j∈[1, J]. The candidate knowledge sentence set also includes a historical selection knowledge sentence set, which consists of candidate knowledge sentences selected before the τth round of dialogue, where the historical selection knowledge sentences from the (τ-N)th round to the (τ-1)th round of dialogue are represented as N is a trainable knowledge selection parameter, and its value range is N∈[0,τ-1]. When τ=1, N=0, and no knowledge statement is selected at this time, so the historical selected knowledge statement is set to a blank knowledge statement K0. In particular, we add this blank knowledge statement to the candidate knowledge statement set, and the candidate knowledge statement set should eventually be expressed as K=(K0, K1, K2, ..., K L ). The target generated reply sentence is represented as Y τ =(y τ,1 ,y τ,2 ,...,y τ,T ), where T is the length of the reply sequence, y τ,t ∈Y τ is the tth word in the reply sentence, and t∈[1,T].
[0079] In step S11, a bidirectional gated recurrent unit (Bi-GRU) is used to encode all candidate knowledge sentences in the candidate knowledge sentence set for the first time to obtain a candidate knowledge intermediate vector; and a Bi-GRU is used to encode the candidate knowledge intermediate vector for the second time to obtain a candidate knowledge vector; wherein, the first encoding can extract the text information in the candidate knowledge sentence, and the second encoding can mine the mutual connection between the candidate knowledge sentences.
[0080] Specifically, for the lth candidate knowledge sentence, the first encoding process is:
[0081]
[0082]
[0083] Where, e() represents word embedding using Global Vectors for Word Representation (GloVe); BiGRU k [] indicates the first encoding of the candidate knowledge sentence after word embedding using Bi-GRU; |l| is the sequence length of the lth candidate knowledge sentence, that is, the number of words in the sentence; are the word vectors after encoding the lth candidate knowledge sentence; The backward word vector obtained by encoding the first word of the l-th candidate knowledge sentence, The forward word vector obtained by encoding the last word of the lth candidate knowledge sentence; Indicates the concatenation operation of two vectors; is the candidate knowledge intermediate vector of the lth candidate knowledge sentence. According to formulas (1) to (2), all candidate knowledge sentences in the candidate knowledge sentence set are encoded for the first time to obtain the candidate knowledge intermediate vector: in,
[0084] In addition, considering that candidate knowledge sentences are usually segmented from continuous text, we use Bi-GRU to perform a second encoding on the candidate knowledge intermediate vectors to further explore the contextual dependencies and correlations between candidate knowledge sentences. The second encoding process is as follows:
[0085]
[0086] Where r l is the candidate knowledge vector of the lth candidate knowledge sentence, and l∈[1,L], r l ∈H K ′;BiGRU r () indicates that Bi-GRU is used to encode the candidate knowledge intermediate vector for the second time.
[0087] For the τth round of dialogue, the historical selected knowledge statements from the (τ-N)th round to the (τ-1)th round of dialogue are expressed as After encoding through formulas (1) to (3), the corresponding historical selection knowledge vector can be obtained That is, the historical selection knowledge vectors from the (τ-N)th round to the (τ-1)th round of dialogue are: r τ-N,s , r τ-N+1,s ,...,r τ-1,s , where the historical selection knowledge vector of the first round of dialogue is set to the zero vector.
[0088] In step S12, a self-attention mechanism of a transformer layer is used to model the historical selection knowledge vectors in multiple rounds of dialogue, capture the dynamic information in the knowledge flow, and obtain the selection perception vector. For the τth round of dialogue, the calculation formula of the selection perception vector is:
[0089] F τ =Transformer[TE(r τ-N,s , r τ-N+1,s ,...,r τ-1,s )] (4)
[0090] F τ ={f τ-N , f τ-N+1 ,...,fτ-1} (5)
[0091] Where, F τ is the selected perception vector for the τth round of dialogue; f τ-N , f τ-N+1 ,...,f τ-1 are the mutual perception vectors from the (τ-N)th round to the (τ-1)th round of dialogue respectively; TE() represents the TurnEmbedding operation, which is the operation of adding the information embedding of the corresponding round to each historical selection knowledge vector to help identify the sequential relationship of the historical selection knowledge vectors; among them, the selection perception vector of the first round of dialogue is also set to the zero vector.
[0092] In step S13, the knowledge flow trend vector is further calculated based on the selection perception vector to predict the knowledge selection trend of the current round. The calculation formula is:
[0093]
[0094]
[0095] Where, T τ is the knowledge flow trend vector of the τth round of dialogue; f τ-n is the mutual perception vector of the (τ-n)th round of dialogue, r τ-n,s Select the knowledge vector for the (τ-n)th round of dialogue history; λ n Select the weight for the knowledge in the (τ-n)th round of dialogue, and When τ=1, since the historical selection knowledge vector and the selection perception vector are both zero vectors, the calculated knowledge flow trend vector is also a zero vector.
[0096] In step S14, in order to extract more features about the knowledge selection trend from the historical selected knowledge statements, each candidate knowledge vector is compared with the selection perception vector of the current round through a comparison function to obtain comparison information; specifically, for the lth candidate knowledge vector, the calculation formula for its comparison information is:
[0097]
[0098]
[0099] Among them, τ,l is the comparison information between the lth candidate knowledge vector and the selected knowledge vector in the τth round of dialogue; Compare(,) represents the comparison function, F() represents the tanh activation function, and ⊙ represents the Hamada product.
[0100] In step S15, the context sentence includes the input sentence of the current round, and the input sentence and reply sentence of the previous round, which is expressed as: Among them, C τ is the context statement, X τ-1 and Y τ-1 are the input sentence and reply sentence of the (τ-1)th round respectively, X τ is the input sentence of the τth round; I is the sequence length of the context sentence, c τ,i ∈C τ is the i-th word in the context sentence, and i∈[1,I].
[0101] Similarly, Bi-GRU is used to encode the context sentence to obtain the context vector. The encoding process is:
[0102]
[0103]
[0104] Where, e() represents word embedding of context sentence using GloVe; BiGRU c [] indicates that Bi-GRU is used to encode the context sentence after word embedding; are word vectors encoded after the context sentences are encoded; The backward word vector obtained by encoding the first word of the context sentence, The forward word vector obtained by encoding the last word of the context sentence; Indicates the concatenation operation of two vectors; is the context vector.
[0105] Most existing knowledge selection models only consider context vectors when selecting knowledge, causing the model to blindly select candidate knowledge statements that are highly relevant to the context sentence, but this is usually not the correct knowledge we want. While the introduction of historical knowledge selection vectors helps promote the selection of correct knowledge, their accuracy in knowledge selection is still relatively low, and the generated response sentences are not appropriate. To improve the accuracy of knowledge selection, after steps S11 to S15, the present invention also comprehensively considers various aspects of information, such as candidate knowledge vectors, knowledge flow trend vectors, comparison information, and context vectors, to perform knowledge selection.
[0106] In step S20, the context vector and the knowledge flow trend vector are used as queries, and the candidate knowledge vector and the comparison information are used as keys to calculate the knowledge selection distribution. The calculation formula is:
[0107]
[0108] Where, βτ,l is the knowledge selection distribution calculated with the lth candidate knowledge vector and its corresponding comparison information as the key; v is the trainable matrix transformation parameter, represents the transpose of the matrix, W query is the trainable query matrix, W key is a trainable key matrix; tanh() represents the tanh activation function.
[0109] In step S30, the attention score of each candidate knowledge vector is calculated according to the knowledge selection distribution, and the candidate knowledge vector with the highest attention score is used as the current selected knowledge vector. The calculation process is as follows:
[0110] α τ,l =softmax(β τ,l ) (13)
[0111]
[0112] Where, α τ,l is the attention score of the lth candidate knowledge vector, and softmax() indicates that the softmax function is used to normalize the knowledge selection distribution; is a value of the independent variable l, and Indicates the search for α τ,l The value of l when the maximum value is obtained; Indicates when When α τ,l Get the maximum value; Indicates selection candidate knowledge vectors is the current selected knowledge vector r in the τth round of dialogue τ,s .
[0113] In step S40, a gated recurrent unit (GRU) is used to calculate the historical decoding state vector based on the context vector and the currently selected knowledge vector, and the current decoding state vector is calculated based on the historical decoding state vector, the historical generated words, and the currently selected knowledge vector. The calculation process is as follows:
[0114]
[0115]
[0116] Where W D is the trainable decoding matrix, b D is a trainable decoding parameter; GRU D() indicates that GRU is used for decoding; t is the current moment in the decoding process, corresponding to each word in the reply sentence, and t∈[1, T]; H τ,0 is the initial decoding state vector of the τth round of dialogue, H τ,t is the current decoding state vector of the τth round of dialogue, H τ,t-1 is the historical decoding state vector of the τth round of dialogue, is the historical generated word for the τth round of dialogue. Among them, when t=1, Initialized to 0, and the initial decoding state vector is used as the historical decoding state vector, that is, H τ,t-1 =H τ,0 ; When t>1, the generated word at the previous moment is used as the historical generated word, and the current decoding state vector at the previous moment is used as the historical decoding state vector at the current moment.
[0117] In step S50, the copy mechanism is adopted to calculate the vocabulary generation probability at the current moment and the knowledge copy probability at the current moment according to the decoding state vector, historical generated words, context vector, and current selected knowledge vector at the current moment, and calculate the target generation probability at the current moment according to the vocabulary generation probability at the current moment and the knowledge copy probability at the current moment.
[0118] The calculation method of the vocabulary generation probability at the current moment is:
[0119]
[0120]
[0121] Where, is the generated word selected from the vocabulary at the current moment; the vocabulary is obtained by counting the frequency of each word in the conversation history and candidate knowledge sentences, and then sorting them from highest to lowest; w is the one-hot vector of a word w in the vocabulary; Indicates that word w is used as a generated word The word probability vector of ; e is a natural constant; Represents the decoding state vector H at the given current moment τ,t 、Historical Generated Words Context vector and the current selected knowledge vector The probability of generating the vocabulary at the current moment is expressed as The probability distribution of W G Generate a matrix for the learnable vocabulary, b G Generate parameters for a learnable vocabulary.
[0122] The calculation method of the knowledge replication probability at the current moment is:
[0123]
[0124]
[0125] Where, is the generated word copied from the currently selected knowledge sentence at the current moment of the τth round of dialogue; Indicates that word w is used as a generated word word probability vector of ; is the probability of knowledge selection at the current moment, which means copying from the current selected knowledge statement given Ψ The probability distribution of is the current selected knowledge statement in the τth round of dialogue (expressed as ), for The word vector obtained by two Bi-GRU encodings; Indicates that word w is a word in the currently selected knowledge sentence G() represents the tanh activation function.
[0126] The calculation formula for the target generation probability at the current moment is:
[0127]
[0128] Where, is the generated word at the current moment of the τth round of dialogue; is the target generation probability at the current moment, indicating the final generation given Ψ The probability distribution of ; Z is the normalization term.
[0129] The target generation probability at the current moment is a probability distribution, in which each probability value corresponds to a word. To generate a complete text sequence as a reply statement, steps S60 to S80 need to be performed:
[0130] The word with the highest probability value among the target generation probabilities at the current moment is used as the generated word at the current moment. The calculation formula is:
[0131]
[0132] Where, Express request The value of w when the maximum value is obtained, and when hour, Get the maximum value.
[0133] After obtaining the generated word at the current moment, determine whether the generated word is an end symbol. If so, compose the generated words of all moments into a reply sentence and output it. If not, return to step S40 to continue decoding to obtain the generated word at the next moment, and repeat this cycle until the generated word is an end symbol.
[0134] Based on steps S11 to S80, an initial dialogue response generation model can be formed. In order to maximize the target generation probability at the current moment and generate a response sentence that matches the context sentence and the candidate knowledge sentence set, the initial dialogue response generation model needs to be trained to optimize the model's network parameters. Therefore, the dialogue response generation method also includes a parameter optimization step:
[0135] S91: Initialize the network parameters of steps S11 to S80, randomly divide the conversation samples in the training set into multiple batches, execute steps S11 to S80 on the samples in the training set batch by batch to optimize the network parameters, and calculate the loss using the total loss function;
[0136] Specifically, the network parameters include the knowledge selection parameter N, the matrix conversion parameter v, the knowledge selection weight λ n , query matrix W query , bond matrix W key , decoding matrix W D , decoding parameter b D , vocabulary generation matrix W G , vocabulary generation parameter b G The total loss function includes the knowledge flow supervision (KFS) loss function, the knowledge selection (KS) loss function and the response generation (RG) loss function, and its calculation formula is:
[0137]
[0138] Where, is the total loss function, is the KFS loss function, is the KS loss function, is the RG loss function; θ represents the above network parameters; γ is a hyperparameter with a value of [0, 1], which is used to balance the objectives of learning the basic tasks (KS loss function and RG loss function) and the KFS loss function.
[0139] Among them, the KFS loss function supervises the learning of the modeling of the knowledge selection process in multi-round dialogues, which is calculated using the mean square error (MSE):
[0140]
[0141]
[0142] Where, is the actual selected perception vector for the τth round of dialogue; are the true mutual perception vectors from the (τ-N+1)th round to the τth round of dialogue; is the current selected knowledge vector for the τth round of dialogue; s * is the index of the real currently selected knowledge statement, i.e. the sth one in the candidate knowledge statement set * candidate knowledge sentences.
[0143] The goal of the KS loss function is to supervise the learning of knowledge selection by minimizing the loss that defines the knowledge selection process:
[0144]
[0145] Where, is the attention score of the true current selected knowledge vector in the τth round of dialogue.
[0146] The RG loss function quantifies the difference between the true response sentence and the generated response sentence, which is calculated using the negative log likelihood (NLL) loss function:
[0147]
[0148] Where, is the tth word of the real response sentence in the τth round of dialogue.
[0149] S92. After each epoch, perform steps S11 to S80 on the conversation samples in the validation set to perform verification, and record the verification results and corresponding network parameters of each iteration. Each complete traversal of all conversation samples in the training set is called an iteration.
[0150] S93: After multiple iterations, the network parameters corresponding to the optimal verification result in step S92 are selected to update the network parameters of steps S11 to S80, and steps S11 to S80 are executed on the dialogue samples in the test set to perform performance testing. The performance test uses common indicators of dialogue response generation systems: ACC, BLEU-2, BLEU-4, and ROUGE-2. ACC is used to evaluate the accuracy of knowledge selection, while BLEU-2, BLEU-4, and ROUGE-2 evaluate the quality of response generation.
[0151] The present invention also provides a dialogue response generation model constructed according to steps S11 to S93.
[0152] Please also see Figure 4 and Figure 5 ,in, Figure 4 This is a network architecture diagram of a dialogue response generation model provided by the present invention. Figure 5 This is a module diagram of a conversation response generation model provided by the present invention. The conversation response generation model includes:
[0153] A candidate knowledge encoding module is used to encode all candidate knowledge sentences in the candidate knowledge sentence set to obtain candidate knowledge vectors; wherein the candidate knowledge sentence set includes historically selected knowledge sentences, and the candidate knowledge vectors include corresponding historically selected knowledge vectors;
[0154] A selection perception vector calculation module is used to calculate the selection perception vector based on the historical selection knowledge vector;
[0155] A knowledge flow trend vector calculation module is used to calculate the knowledge flow trend vector according to the selection perception vector and the historical selection knowledge vector;
[0156] A comparison information calculation module is used to compare the selected perception vector with the candidate knowledge vector to obtain comparison information;
[0157] A context encoding module is used to encode the context sentence and obtain a context vector;
[0158] A knowledge selection distribution calculation module is used to calculate the knowledge selection distribution by taking the context vector and the knowledge flow trend vector as queries and the candidate knowledge vector and the comparison information as keys;
[0159] The currently selected knowledge vector calculation module is used to calculate the attention score of each candidate knowledge vector according to the knowledge selection distribution, and take the candidate knowledge vector with the highest attention score as the currently selected knowledge vector;
[0160] The current decoding state vector calculation module is used to calculate the historical decoding state vector based on the context vector and the current selected knowledge vector, and calculate the current moment's decoding state vector based on the historical decoding state vector and the historical generated words;
[0161] The target generation probability calculation module is used to calculate the current word list generation probability and the current knowledge replication probability based on the current decoding state vector, historical generated words, context vector, and current selected knowledge vector, and calculate the current target generation probability based on the current word list generation probability and the current knowledge replication probability;
[0162] The reply sentence generation module is used to take the word with the largest probability value in the target generation probability at the current moment as the generated word at the current moment, and judge whether the generated word is an end symbol; if so, the generated words of all moments are combined into a reply sentence and output; if not, the generated word at the current moment is taken as a historical generated word and transmitted to the current decoding state vector calculation module for continued decoding to predict the generated word at the next moment until the generated word at the current moment is an end symbol.
[0163] The present invention also provides a conversation response generation system, comprising a memory, a processor, and a computer program stored in the memory and running on the processor, wherein the processor implements the steps of the above-mentioned conversation response generation method when executing the computer program.
[0164] The present invention also provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a computer, the steps of the above-mentioned dialogue response generation method are implemented.
[0165] In a specific embodiment, the above-mentioned dialogue response generation model is implemented in the PyTorch framework through steps S11 to S93. The datasets used are the Holl-E dataset and the Wizard-of-Wikipedia (WoW) dataset. The dialogue samples in both datasets are labeled with the knowledge selection statements in each dialogue round to evaluate the performance of the dialogue response generation model.
[0166] The Holl-E dataset collects background knowledge in the film field. The response sentences in each dialogue sample are directly copied or rewritten from the relevant sentences in the background knowledge. The dialogue samples in the Holl-E dataset are divided into training, validation, and test sets. The training set includes 7211 dialogue samples, the validation set includes 930 dialogue samples, and the test set includes 913 dialogue samples. Each dialogue sample consists of five rounds (i.e., Ω = 5), with an average of 60 knowledge sentences per round.
[0167] The WoW dataset consists of multi-turn conversations based on Wikipedia conducted in a wizard-apprentice model, where the wizard responds to selected knowledge statements. The conversation samples in the WoW dataset are divided into training, validation, and test sets. The training set includes 18,430 conversation samples, the validation set includes 1,948 conversation samples, and the test set includes 1,933 conversation samples. The test set is further divided into a seen test set (965 conversation samples) and an unseen test set (968 conversation samples). Each conversation sample consists of four turns (i.e., Ω = 4), with an average of 61 knowledge statements provided per turn.
[0168] We use the Natural Language Toolkit (NLTK) to tokenize sentences in the database, limiting the vocabulary size of the Holl-E dataset to 16KB and the WoW dataset to 20KB. In steps S11 and S15, the word embedding dimension is set to 300, and the dropout rate is set to 0.5. In steps S11-S15, the unidirectional hidden dimension of the encoding is set to 200, and the total hidden dimension of both directions is 400. In step S40, the hidden dimension of the decoding is set to 400. The samples in the training set are randomly divided into multiple batches, with a batch size of 8 and a number of iterations of 20.
[0169] After initializing the network parameters of the conversational response generation model, conversational samples from the training set were fed into the model in batches for training. The Adam algorithm was used to optimize the model's network parameters, with an initial learning rate of 0.0005. After each iteration, conversational samples from the validation set were fed into the model for validation. The validation performance and network parameters for each iteration were recorded. After 20 iterations, the model with the best validation result was selected as the optimal conversational response generation model. Conversational samples from the test set were fed into the optimal conversational response generation model for performance testing. The test results are shown in Table 1. Compared with seven existing models in the art, namely the sequence to sequence (Seq2Seq) model, the hierarchical recurrent encoder-decoder (HRED) model, the memory network (MemNet) model, the posterior knowledge selection (PostKS) model, the sequential latent knowledge selection (SLKS) model, the difference-aware knowledge selection-disentangled (DiffKS-dis) model using separate computing, and the difference-aware knowledge selection-fused (DiffKS-fus) model using fusion computing, the dialogue response generation model proposed in this paper achieves the best results in the four indicators of ACC, BLEU-2, BLEU-4 and ROUGE-2, which fully proves that the introduction of the dynamic knowledge selection mechanism is conducive to improving the accuracy of knowledge selection and the quality of dialogue responses.
[0170] Compared with the prior art, the present invention provides a dialogue response generation method and a dialogue response generation method model, and designs a dynamic knowledge selection mechanism. It not only reasonably models the historically selected knowledge sentences and extracts the dynamic information implicit in the knowledge selection process, thereby fully utilizing the historically selected knowledge sentences, but also calculates the knowledge flow trend vector based on the extracted dynamic information, thereby guiding the dialogue system to select more appropriate knowledge sentences in the current round, significantly improving the knowledge selection accuracy of the dialogue system and the quality of dialogue responses; in addition, the present invention also involves a KFS loss function, which supervises the model's learning of the real selection perception vector, improves the modeling ability of the knowledge selection process, and further promotes correct knowledge selection.
[0171] Table 1. Comparison of the effects of the dialogue response generation model of the present invention and seven dialogue response generation models in the prior art
[0172]
[0173] The above-described embodiments merely illustrate several implementations of the present invention. While the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the present invention. It should be noted that a person skilled in the art would be able to make numerous variations and improvements without departing from the spirit of the present invention, and all such variations and improvements fall within the scope of protection of the present invention.
Claims
1. A method for generating a dialogue response, characterized in that: Including steps: S12: Calculate and select a perception vector based on the historical selection knowledge vector, and then execute steps S13 and S14 respectively; S13: Calculating a knowledge flow trend vector based on the selection perception vector and the historical selection knowledge vector; S14: Compare the selected perception vector and the candidate knowledge vector to obtain comparison information; S15: Encode the context sentence to obtain a context vector; wherein step S15 is performed at any stage before step S20; S20: Calculating knowledge selection distribution according to the candidate knowledge vector, the knowledge flow trend vector, the comparison information and the context vector; S30: Calculating the attention score of each candidate knowledge vector according to the knowledge selection distribution, and taking the candidate knowledge vector with the highest attention score as the currently selected knowledge vector; S40: Calculating a historical decoding state vector based on the context vector and the currently selected knowledge vector, and calculating a current moment's decoding state vector based on the historical decoding state vector and historical generated words; S50: Calculating the vocabulary generation probability and the knowledge replication probability at the current moment according to the decoding state vector, the historical generated words, the context vector, and the currently selected knowledge vector at the current moment, and calculating the target generation probability at the current moment according to the vocabulary generation probability and the knowledge replication probability at the current moment; S60: Using the word with the highest probability value among the target generation probabilities at the current moment as the generated word at the current moment; S70: Determine whether the generated word at the current moment is an end symbol; if so, execute step S80; if not, treat the generated word at the current moment as a historical generated word and return to step S40; S80: The generated words at all moments are combined into a reply sentence and output.
2. The method for generating a dialogue response according to claim 1, wherein: Step S12 is specifically as follows: A self-attention mechanism of a layer of Transformer blocks is used to model the historical selection knowledge vector, capture the dynamic information in the knowledge flow, and obtain the selection perception vector, which is calculated as follows: F τ =Transformer[TE(r τ-N,s ,r τ-N+1,s ,...,r τ-1,s )] (4) F τ ={f τ-N ,f τ-N+1 ,...,f τ-1 } (5) Where, F τ is the selected perception vector of the τth round of dialogue; f τ-N ,f τ-N+1 ,...,f τ-1 are the mutual perception vectors from the (τ-N)th round to the (τ-1)th round of dialogue; TE() represents the operation of adding the information embedding of the corresponding round to each of the historical selection knowledge vectors; r τ-N,s ,r τ-N+1,s ,...,r τ-1,s are the historical selection knowledge vectors for the (τ-N)th to (τ-1)th rounds of dialogue respectively; N is the knowledge selection parameter.
3. The method for generating a dialogue response according to claim 2, wherein: The calculation formula of the knowledge flow trend vector is: Where, T τ is the knowledge flow trend vector of the τth round of dialogue; f τ-n is the mutual perception vector of the (τ-n)th round of dialogue, r τ-n,s Select a knowledge vector for the history of the (τ-n)th round of dialogue; n Choose the weight for the knowledge of the (τ-n)th round of dialogue; where n∈[1,N], and 4. The method for generating a dialogue response according to claim 3, wherein: Step S14 is specifically as follows: Each candidate knowledge vector is compared with the selected perception vector of the current round by a comparison function to obtain the comparison information, which is calculated as follows: Among them, f n is the mutual perception vector of the nth round of dialogue, r l is the lth candidate knowledge vector, o τ,l is the comparison information between the lth candidate knowledge vector and the selected knowledge vector in the τth round of dialogue; Compare(,) represents the comparison function, F() represents the tanh activation function, and ⊙ represents the Hamada product.
5. The method for generating a dialogue response according to claim 4, wherein: Step S20 is specifically as follows: The context vector and the knowledge flow trend vector are used as queries, and the candidate knowledge vector and the comparison information are used as keys to calculate the knowledge selection distribution. The calculation formula is: Where, is the context vector; β τ,l is the knowledge selection distribution calculated with the lth candidate knowledge vector and its corresponding comparison information as the key; v is the matrix transformation parameter, represents the transpose of the matrix, W query is the query matrix, W key is the key matrix; tanh() represents the tanh activation function.
6. The method for generating a dialogue response according to any one of claims 1 to 5, wherein: Before step S12, the method further includes the following steps: S11: Encode all candidate knowledge statements in the candidate knowledge statement set to obtain the candidate knowledge vector; wherein, the candidate knowledge statement set includes historically selected knowledge statements, and the candidate knowledge vector includes the corresponding historically selected knowledge vector.
7. The method for generating a dialogue response according to claim 6, wherein: Step S11 is specifically as follows: A bidirectional gated recurrent unit is used to encode all candidate knowledge sentences in the candidate knowledge sentence set for the first time to obtain a candidate knowledge intermediate vector; a bidirectional gated recurrent unit is used to encode the candidate knowledge intermediate vector for the second time to obtain a candidate knowledge vector.
8. The method for generating a dialogue response according to claim 7, wherein: Also includes parameter optimization steps: S91: Initialize the network parameters of steps S11 to S80, randomly divide the conversation samples in the training set into multiple batches, execute steps S11 to S80 on the conversation samples in the training set batch by batch to optimize the network parameters, and calculate the loss using a total loss function; wherein the total loss function includes a knowledge flow supervision loss function, a knowledge selection loss function, and a response generation loss function; S92. After each iteration, perform steps S11 to S80 on the conversation samples in the validation set to perform validation, and record the validation results and corresponding network parameters of each iteration; S93: After multiple iterations, the network parameters corresponding to the optimal verification result in step S92 are selected to update the network parameters of steps S11 to S80, and then steps S11 to S80 are executed on the dialogue samples of the test set to perform performance testing.
9. A dialogue response generation model, characterized in that: include: A selection perception vector calculation module is used to calculate the selection perception vector based on the historical selection knowledge vector; a knowledge flow trend vector calculation module, configured to calculate a knowledge flow trend vector based on the selection perception vector and the historical selection knowledge vector; a comparison information calculation module, configured to compare the selected perception vector with the candidate knowledge vector to obtain comparison information; A context encoding module is used to encode the context sentence and obtain a context vector; a knowledge selection distribution calculation module, configured to calculate the knowledge selection distribution according to the candidate knowledge vector, the knowledge flow trend vector, the comparison information and the context vector; a currently selected knowledge vector calculation module, configured to calculate an attention score for each candidate knowledge vector according to the knowledge selection distribution, and select the candidate knowledge vector with the highest attention score as the currently selected knowledge vector; a current decoding state vector calculation module, configured to calculate a historical decoding state vector based on the context vector and the currently selected knowledge vector, and to calculate a current moment's decoding state vector based on the historical decoding state vector and historical generated words; a target generation probability calculation module, configured to calculate the vocabulary generation probability and the knowledge replication probability at the current moment based on the decoding state vector, the historical generated words, the context vector, and the currently selected knowledge vector at the current moment, and to calculate the target generation probability at the current moment based on the vocabulary generation probability and the knowledge replication probability at the current moment; The reply sentence generation module is used to take the word with the largest probability value in the target generation probability at the current moment as the generated word at the current moment, and determine whether the generated word is an end symbol; if so, the generated words at all moments are combined into a reply sentence and output; if not, the generated word at the current moment is taken as a historical generated word and transmitted to the current decoding state vector calculation module for further decoding.
10. The dialogue response generation model according to claim 9, characterized in that: Also includes: The candidate knowledge encoding module is used to encode all candidate knowledge statements in the candidate knowledge statement set to obtain the candidate knowledge vector; wherein, the candidate knowledge statement set includes historically selected knowledge statements, and the candidate knowledge vector includes the corresponding historically selected knowledge vector.
Citation Information
Patent Citations
Method and device for generating reply statements for multiple rounds of conversations
CN111400481A
Open domain dialogue model and method for enhancing reply personalized expression
CN112100350A