A method for generating diversity responses by introducing continuous latent variables
By introducing continuous latent variables, dialogue behavior is modeled into a continuous latent variable space. BERT and transformer models are used to generate dialogue responses, which solves the problem of insufficient response diversity in existing technologies and improves the generation effect of the dialogue system.
Patent Information
- Application Number
- CN202311305321.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-10-10
- Publication Date
- 2025-10-28
- Estimated Expiration
- 2043-10-10
AI Technical Summary
Existing dialogue systems suffer from blank and generic responses when generating replies, resulting in a poor user experience. Existing technologies have limitations in improving response diversity, especially in real-world scenarios where dialogue behaviors are diverse and boundaries are blurred.
A diverse response generation method based on continuous latent variables is introduced. By adding an additional neural network to the discrete latent variable method, the dialogue behavior is modeled into a continuous latent variable space. The BERT language model and the transformer model are used to identify the dialogue behavior, and candidate responses are generated through Gaussian distribution. Finally, the optimal response is selected.
It improves the diversity and quality of dialogue responses, meets the needs of diverse and ambiguous dialogue behaviors in real-world scenarios, and enhances the generation effect of the dialogue system.
Smart Images

Figure CN117370515B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of dialogue systems in natural language processing, and specifically relates to a method for generating diverse responses by introducing continuous latent variables. Background Technology
[0002] Dialogue systems are systems capable of communicating with humans through language, representing a significant area of research in the field of artificial intelligence and natural language processing. Today, dialogue systems have become integrated into people's lives, handling tasks such as hotel bookings, personal assistants, website customer service, car navigation, educational support, and casual conversation. Advances in dialogue systems are attributed to the development of deep learning technology. How to enable dialogue systems to generate higher-quality responses and better serve humanity is a pressing application challenge that needs to be addressed. Currently, deep learning-based dialogue systems generally suffer from the following drawbacks in training and inference: blank responses and generic responses are long-standing problems in generative dialogue. Because response generation is based on probability calculations, generic responses like "I don't know" have a high probability, and the model may classify meaningful responses as noise and ignore them. This leads to a poor user experience in real-world conversations. Solving this challenge can make the dialogues generated by the system more diverse, readable, and engaging.
[0003] To address the issue of improving response diversity, existing technologies all suffer from discrepancies with real-world application scenarios. Vijayakumar et al. [Vijayakumar A K. Diverse beam search: Decoding diverse solutions from neural sequence models: 1610.02424, 2016] proposed Diverse Beam Search (DBS) by incorporating a word different from the currently available word into the beam search target, which can improve diversity. Shao et al. [Shao L. Generating long and diverse responses with neural conversation models: 2017] proposed a random beam search algorithm that randomly samples when selecting top-B responses, a method that integrates search and sampling algorithms. Both of these approaches improve dialogue response diversity by refining the beam search algorithm, but require experimental determination of appropriate hyperparameters for different scenarios to ensure the effectiveness of the method, resulting in additional overhead. Qiu et al. [Qiu L. Are training samples correlated?] [Learning to generated dialogue responses with multiple references: 2019: 3826-3835] considers the one-to-many mapping problem in open dialogue systems and proposes a two-stage generation model to increase response diversity. The first stage extracts multiple common features based on real responses, and the second stage extracts the most unique one. Ko et al. [Ko W J. Generating dialogue responses from asemantic latent space: 2010.01658, 2020] solve the one-to-many mapping problem by designing a classification task, and also overcomes the deficiency of cross-entropy loss-based methods in integrating semantic information, learning latent semantic representations. Given a sample response, different responses can be generated by exploring semantic approximation vectors in the latent space. Bao et al. [Bao S. PLATO: Pre-trained dialogue generation model with discrete latent variable: 1910.07931, 2019] propose a pre-trained dialogue generation model based on latent variables, using BERT model parameters for fine-tuning to complete dialogue generation, and improving response diversity by using latent variables and response selection.These works have achieved great success, but real-world dialogue behavior is far more diverse and has blurred boundaries, and modeling dialogue behavior using discrete latent variables still has limitations. Introducing external knowledge can also enhance the diversity of responses. Wu et al. [Wu S. Diverse and informative dialogue generation with context-specific commonsense knowledge awareness: 2020: 5811-5820] established a commonsense dialogue generation model, seeking highly relevant knowledge facts based on dialogue history and introducing them into the dialogue to improve response diversity. Su et al. [Su H. Diversifying dialogue generation with non-conversational text: 2005.04346, 2020] incorporated external knowledge sources to diversify the generated responses, but unlike others, they used non-conversational text such as news articles as relevant knowledge facts. This type of knowledge is obviously easier to obtain, breaking the traditional view that dialogue systems can only be trained on dialogue datasets. While these methods are effective, they are prone to generating false information, and the accuracy of knowledge usage needs improvement.
[0004] Variational methods are a way to model data features as distributions. By using variational methods, dialogue behavior can be modeled in a continuous latent variable space, which is more in line with real-world scenarios than methods that introduce discrete latent variables, and can improve the diversity of dialogue responses. Summary of the Invention
[0005] The technical problem solved by this invention is to overcome the shortcomings of existing technologies and address the issue of more diverse dialogue behaviors and blurred boundaries in real-world scenarios by providing a method for generating diverse responses that introduces continuous latent variables. By adding an additional neural network to the method that introduces discrete latent variables, dialogue behaviors are modeled into a continuous latent variable space, thereby improving the diversity of dialogue responses.
[0006] The technical solution of this invention: a method for generating diversity responses by introducing continuous latent variables, such as... Figure 1 As shown, the training steps are as follows:
[0007] Step S1: Dialogue Data Processing. Dialogues are typically two-person conversations, presented alternately in the order of the dialogue. During use, all dialogues are treated as continuous text, with each speaker switch serving as a segment to construct the input data. Specifically, a 12-turn dialogue is divided into 11 data samples; the first sample uses the second sentence as the label and the preceding dialogue as input; the second sample uses the third sentence as the label and the preceding dialogue as input, and so on. In addition, two special characters, [speaker-o] and [speaker-s], are used to mark the words of different speakers, respectively, hoping that the model can learn the differences in speaker identities and generate responses from the perspectives of different speakers. This invention also supports dialogues containing knowledge, directly concatenating relevant knowledge with the dialogue.
[0008] Step S2: Dialogue Action Recognition. Input the dialogue into the selected BERT language model. Calculate the current dialogue action using the output of the BERT language model. Connect four fully connected neural networks to represent the dialogue action to construct a transformer model. Use this model to recognize the current dialogue action. Dialogue action refers to the operations and actions performed during a dialogue. BERT is a pre-trained model proposed by Google AI Research in October 2018. BERT stands for Bidirectional Encoder Representation from Transformers. The design goals of each neural network are as follows:
[0009] (1) The first fully connected layer: is used to output K means, which serve as the mean of the behavior distribution and provide options for distribution selection.
[0010] (2) The second fully connected layer is used to output K variances, which serve as the variances of the behavior distribution and provide optional conditions for distribution selection.
[0011] (3) The third fully connected layer: as a classification layer, the number of categories is K. It selects from the Gaussian distribution, which is also the selection of behavioral samples sampled from the Gaussian distribution.
[0012] (4) The fourth fully connected layer: Following the design of the discrete latent variable method, the response selection loss is calculated and used to optimize the model and the final response selection.
[0013] Step S3: Output Response Generation. Using the dialogue behavior recognition part of the transformer model calculated in Step S2, candidate responses are generated, and then the correct probability of the candidate responses is verified to select the final response result.
[0014] The output response inference process is as follows:
[0015] S301 generates candidate responses: A random sample is sampled from a standard Gaussian distribution. Using the mean and variance matrices of the dialogue behaviors determined during training, a behavior vector of length K is generated through a reparameterization method, representing K candidate behaviors. These K candidate behaviors are then used to generate K candidate responses.
[0016] S302 Output Response Generation: Input the dialogue and candidate responses into the model simultaneously, calculate the response, and select the candidate response with the minimum loss as the final response.
[0017] The advantages of the present invention compared with the prior art are:
[0018] To address the limitations of existing technologies that use discrete latent variables to model dialogue behavior, which are disconnected from reality, this invention fully considers the diversity of dialogue behavior and the ambiguity of dialogue behavior boundaries in real-world scenarios. By using variational methods, dialogue behavior is modeled into a continuous latent variable space, ensuring that the modeling of dialogue behavior satisfies real-world scenarios. This enhances the diversity of dialogue responses and, consequently, improves the quality of dialogue responses. Attached Figure Description
[0019] Figure 1 This is a flowchart of a diversity response generation method that introduces continuous latent variables in an embodiment of the present invention;
[0020] Figure 2 This is a schematic diagram of the overall model framework of the present invention;
[0021] Figure 3 This is a schematic diagram of the method for introducing continuous latent variables according to the present invention. Detailed Implementation
[0022] To make the objectives, advantages, and technical solutions of this invention clearer, the following specific measures are provided, in conjunction with the appendix. Figure 2-3 The present invention will be further described in detail below.
[0023] This invention mainly includes the following specific contents, such as Figure 1 As shown.
[0024] Step S1: Dialogue data processing. Since this has been described in detail above, it will not be repeated here. The following mainly describes steps S2 and S3.
[0025] In steps S2 and S3, the transformer model is used. The input of the transformer model is x = {x1, x2, ..., x...} n}, where x iEach component consists of a dialogue action z, a dialogue context c, and a dialogue response r. After passing through the input embedding layer, x is input into the backbone model, which is composed of 12 stacked transformer blocks. The output is h = {h1, h2, ..., h...} n} represents the hidden layer representation for each input x, where n is the sentence length.
[0026] The transformer model framework comprises two phases: training and inference, both employing self-attention masks, but with slight differences. In the training phase, the self-attention mask matrix is an all-one matrix, meaning each word calculates its attention score with all other words, and each word is visible to all other words. In the inference phase, the self-attention mask matrix remains all-one for the dialogue action z and dialogue context c, but becomes a step matrix for the dialogue response r. This means that each word in the dialogue response r only calculates its attention score with the words preceding it, and each word can only see the words before it. It's worth noting that the two phases of this framework share parameters.
[0027] Step S2: Dialogue Action Recognition. Input the dialogue into the selected BERT language model, calculate the current dialogue action using the BERT language model's output, and then connect four fully connected neural networks to represent the dialogue action to construct the transformer model. The design goals of each neural network are as follows:
[0028] (1) The first fully connected layer: is used to output K means, which serve as the mean of the behavior distribution and provide options for distribution selection.
[0029] (2) The second fully connected layer is used to output K variances, which serve as the variances of the behavior distribution and provide optional conditions for distribution selection.
[0030] (3) The third fully connected layer: as a classification layer, the number of categories is K. It selects from the Gaussian distribution, which is also the selection of behavioral samples sampled from the Gaussian distribution.
[0031] (4) The fourth fully connected layer: Following the design of the discrete latent variable method, the response selection loss is calculated and used to optimize the model and the final response selection.
[0032] The training process of the transformer model is described in detail below:
[0033] The training process is divided into two phases: the potential behavior recognition sub-phase and the training response generation sub-phase.
[0034] 1) Sub-stage 1: Potential behavior identification
[0035] The attention mask for the latent behavior recognition sub-stage is performed using a matrix of all 1s. All input words will have their relevance scores to other words calculated in the transformer block, and all words are visible to other words.
[0036] In the latent behavior recognition sub-stage, a total number of behaviors K is first defined, representing a maximum of K possible dialogue behaviors. The model receives complete input, including the dialogue behavior, dialogue context, and dialogue response. The goal is to identify latent behaviors, which means estimating the posterior distribution p(z|c, r). Specifically, a simple fully connected neural network is connected to the output of z, and the probability of each behavior is calculated using the softmax function. The behavior with the highest probability is selected. The formula for calculating the z value is as follows:
[0037] p(z|c, r) = softmax(W1h1 + b1)
[0038] Where W1 represents the parameters of the first fully connected neural network, and b1 represents the neural network bias value.
[0039] The potential behavior identification sub-stage also requires calculating the response selection loss L. RS The response selection loss assesses the degree of matching between the dialogue context c and the dialogue response r, and uses cross-entropy to calculate the loss. The calculation formula is as follows:
[0040]
[0041] Among them, l r The output value for positive samples. For the output value of the negative sample, r - For negative samples of dialogue responses, p(l) r The calculation method for =1|c,r) is as follows:
[0042] p(l r =1|c,r)=sigmoid(W2h1+b2)
[0043] Where W2 is the parameter of the second fully connected neural network, and b2 is the neural network bias value.
[0044] The positive sample here is the input obtained by directly concatenating the correct dialogue response with the dialogue context, while the negative sample is obtained by randomly selecting a sentence and concatenating it with the dialogue context.
[0045] Introduce continuous latent variables (for training), with the hidden representation h1 as the input. The specific steps are as follows:
[0046] ① First, sample a sample ε ~ N(0, 1) from the standard Gaussian distribution.
[0047] ② The mean μ of the sample ε is calculated by the neural network: μ = W4h1 + b4, where W4 is the parameter of the fully connected neural network and b4 is the bias value of the fully connected neural network.
[0048] ③ The variance σ of sample ε 2 σ is calculated by a neural network 2 =W5h1+b5, where W5 is the parameter of the fully connected neural network and b5 is the bias value of the fully connected neural network.
[0049] ④ This step uses the reparameter method, which yields a sample from a given Gaussian distribution. Given the mean μ, standard deviation σ, and sample value ε, the calculation formula is as follows:
[0050] z=μ+σ*ε
[0051] ⑤ Here, the distribution selection method is calculated. The selection vector p is calculated by the neural network as p = softmax(W1h1 + b1), where W1 is the parameter of the fully connected neural network and b1 is the bias value of the fully connected neural network.
[0052] ⑥ Here, the distribution is selected by performing a dot product operation z = z⊙p on the sampled behavior vector z and the selection vector p to select the final dialogue behavior.
[0053] 2) Sub-phase 2: Training response generation
[0054] The attention mask for the training response generation sub-stage is all 1s in the dialogue context part and a lower-order ladder matrix of 1s in the response part. When generating the next word, it can only see the dialogue context content and the already generated part of the sentence.
[0055] The z-value calculated in the latent behavior recognition sub-stage is input into the model along with the dialogue context c and the dialogue response r, and two loss functions, negative log-likelihood loss L, are calculated. NLL Bag-of-words loss L BOW L NLL The calculation is derived from the hidden layer output corresponding to the dialogue response r, and the calculation formula is as follows:
[0056]
[0057] Where t is the number of steps generated, T is the total number of steps generated, and r <t It is the response generated in the previous t generation steps, r t It is the word to be generated in the t-th generation step.
[0058] And L BOW The value is calculated from the hidden layer output corresponding to the dialogue action z, and the calculation formula is as follows:
[0059]
[0060] Where V represents the dictionary, v represents the words in the vocabulary, and f predicts the next word using a fully connected neural network in a non-autoregressive manner. The calculation formula is as follows:
[0061] f = softmax(W3h1 + b3)
[0062] Where W3 is the parameter of the third neural network, and b3 is the bias value of the third neural network.
[0063] Model parameter optimization: Summing all loss functions yields the final loss L. ALL Use backpropagation to update parameters, L ALL The calculation formula is as follows:
[0064] L ALL =L NLL +L BOW +L Rs
[0065] Step S3: Output Response Generation Stage. Using the dialogue behavior recognition part of the transformer model from Step S2, candidate responses are generated. Then, the correct probability of the candidate responses is verified to select the final response result. The specific steps are as follows:
[0066] The output response generation stage is divided into a candidate output response generation sub-stage (step S301) and an output response selection sub-stage (step S302).
[0067] The output response inference process is as follows:
[0068] Step S301: Candidate output response generation:
[0069] Introducing continuous latent variables (inference): Given the mean matrix μ and variance matrix σ 2 A random sample ε ~ N(0, 1) can be directly sampled from the standard Gaussian distribution. Through the reparameter method, a behavior vector z = μ + σ·ε of length K is generated, representing K candidate dialogue behaviors, and further K candidate responses are generated.
[0070] Step S302: Output response selection:
[0071] The generated response and dialogue context are simultaneously input into the model. Using the masking method from the dialogue behavior recognition stage during training, the probability p(l) of each candidate output response being correct is calculated. r =1|c,r), select the highest one as the final output response.
[0072] Those skilled in the art will readily understand that the above description is merely a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.
Claims
1. A method for generating diversity responses by introducing continuous latent variables, characterized in that, Includes the following steps: Step S1: Process dialogue data and construct input dialogue data: Treat all dialogues as continuous text, use each speaker switch as a segment, and alternately provide dialogue data according to the order of the dialogue to construct the input dialogue data. Step S2: Dialogue behavior recognition; Input the dialogue into the selected BERT language model, use the output of the BERT language model to calculate the current dialogue behavior, connect the current dialogue behavior to four fully connected neural networks to build a transformer model, and use the model to recognize the current dialogue behavior; Step S3: Output response generation; Using the dialogue behavior recognition part of the transformer model in step S2 to calculate the dialogue behavior value, generate candidate responses, and then verify the correct probability of the candidate responses to select the final response result; The specific implementation of step S1 is as follows: a set of n rounds of dialogue is split into n-1 data samples; the first sample uses the second sentence as the label and the previous dialogue as the input; the second sample uses the third sentence as the label and the previous dialogue as the input, and so on; and two special characters [speaker-o] and [speaker-s] are used to mark the words of different speakers respectively. In step S2, the transformer model is used, and the input of the transformer model is... ,in, Each is composed of dialogue behavior Dialogue context and dialogue replies composition; After passing through the embedding layer of the input model, it is fed into the backbone model, which consists of 12 stacked transformer blocks. The output is... , is corresponding to each input The hidden layer representation, where Sentence length; The training process of the transformer model is as follows: The training process is divided into a latent behavior recognition sub-stage and a training response generation sub-stage; Sub-stage 1) Potential behavior identification: The attention mask for the latent behavior recognition sub-stage is performed using a matrix of all 1s. All input words will have their relevance scores to other words calculated in the transformer block, and all words are visible to other words. In the latent behavior recognition sub-stage, a total number of behaviors K is first set, representing that there are at most K types of dialogue behaviors. The model receives complete input, including the dialogue behaviors. Dialogue context and dialogue replies The goal is to identify potential behaviors, which means estimating the posterior distribution. The specific implementation method is as follows: In The output of the function is fed into a simple fully connected neural network, and then... Calculate the probability of each action and select the action with the highest probability. The formula for calculating the value is as follows: in, For the parameters of the first fully connected neural network, These are the bias values for the neural network. The potential behavior identification sub-stage also requires calculating the response selection loss. The response selection loss is determined by the dialogue context. and dialogue replies The degree of matching is used to calculate the loss using cross-entropy, and the calculation formula is as follows: in, The output value for positive samples. The output value for the negative sample. For negative samples of dialogue responses, The calculation formula is as follows: in, For the parameters of the second fully connected neural network, These are the bias values for the neural network. The positive sample here is the input obtained by directly concatenating the correct dialogue response with the dialogue context, while the negative sample is obtained by randomly selecting a sentence and concatenating it with the dialogue context. Introducing continuous latent variables, with the input being the hidden representation. The specific steps are as follows: ① First, a sample is taken from the standard Gaussian distribution. ; ② Sample The mean Calculated by neural network ,in These are the parameters of a fully connected neural network. It is the bias value of a fully connected neural network; ③ Sample variance Calculated by neural network ,in These are the parameters of a fully connected neural network. It is the bias value of a fully connected neural network; ④ This step uses the reparameter method, which allows us to obtain a sample from a given Gaussian distribution with a given mean. Standard deviation and sample values The calculation formula is as follows: ⑤ The distribution selection method here is to choose a vector. Calculated by neural network ,in These are the parameters of a fully connected neural network. It is the bias value of a fully connected neural network; ⑥ Here, the distribution is selected using sampled dialogue behaviors. With selection vector Perform dot product operation. p, select the final dialogue action; Sub-phase 2) Training response generation: The attention mask for the response generation sub-stage is all 1s in the dialogue context part and a lower step matrix of 1s in the response part. When generating the next word, only the dialogue context content and the already generated part of the sentence can be seen. The potential behavior identification sub-stage calculated Values and Dialogue Context and dialogue replies Input both data into the model and calculate the negative log-likelihood loss of the two loss functions. Bag-of-words loss , The calculation is derived from the dialogue response. The corresponding hidden layer output is calculated using the following formula: in, It is the number of steps generated. To generate the total number of steps, It was before The responses generated in the previous generation step It is The words to be generated in each generation step; and The calculation is derived from dialogue behavior. The corresponding hidden layer output is calculated using the following formula: in, It means dictionary, and This refers to words in the vocabulary list; It predicts the next word using a fully connected neural network in a non-autoregressive manner, and its calculation formula is as follows: in, It is the third neural network parameter. It is the bias value of the third neural network; Optimize the model parameters: sum all loss functions to obtain the final loss. Update parameters using backpropagation. The calculation formula is as follows:
2. The method according to claim 1, characterized in that, In step S3, the dialogue behavior value calculated by the dialogue behavior recognition part of the transformer model in step S2 is used to generate candidate responses, and then the correct probability of the candidate responses is verified to select the final response result. The output response inference process is as follows: Generate candidate responses: Introduce a continuous latent variable to sample a random sample from a standard Gaussian distribution. Directly use the mean and variance matrices of the dialogue behavior determined during training. Through the reparameter method, generate a behavior vector of length K to represent K candidate behaviors. Use these K candidate behaviors to generate K candidate responses. Output response generation: Input the dialogue and candidate responses into the model simultaneously, calculate the response, and select the candidate response with the minimum loss as the final response.