Method and system for multi-turn dialogue generation based on conditional diffusion model

By employing a multi-turn dialogue generation method based on a conditional diffusion model, the generated responses are more relevant and diverse by utilizing the latent background information of the training data, thus solving the problem of insufficient relevance and diversity in existing technologies.

CN117556009BActive Publication Date: 2026-07-31HEFEI UNIV OF TECH
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
HEFEI UNIV OF TECH
Filing Date
2023-11-13
Publication Date
2026-07-31

AI Technical Summary

Technical Problem

Existing dialogue generation models fail to fully utilize the potential contextual information in the dialogue training dataset, resulting in generated responses that are not highly relevant to the context and lack diversity.

Method used

A multi-turn dialogue generation method based on the conditional diffusion model is adopted. The context representation of the multi-turn dialogue context is obtained through a pre-trained conditional diffusion model, and Gaussian noise is randomly sampled from the standard Gaussian distribution. Under the guidance of the context representation, the noise is gradually restored to the latent variables, and finally the response is generated.

Benefits of technology

The generated responses are more relevant and diverse, making better use of the rich potential information in the training data, resulting in more reasonable and natural responses.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117556009B_ABST
    Figure CN117556009B_ABST
Patent Text Reader

Abstract

This invention provides a method, system, storage medium, and electronic device for generating multi-turn dialogues based on a conditional diffusion model, relating to the field of natural language processing technology. Based on a pre-trained conditional diffusion model, the invention first obtains the multi-turn dialogue context; secondly, it obtains the context representation of the multi-turn dialogue context and randomly samples Gaussian noise from a standard Gaussian distribution; thirdly, based on the conditional diffusion model, it progressively denoises the Gaussian noise under the guidance of the context representation, restoring it to latent variables consistent with the multi-turn dialogue context; finally, it generates the final response based on the context representation and latent variables. Introducing a conditional diffusion model to fit the distribution of latent variables fully utilizes the rich latent information in the training data, resulting in more relevant and diverse generated responses.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of natural language processing technology, and specifically to a method, system, storage medium, and electronic device for generating multi-turn dialogues based on a conditional diffusion model. Background Technology

[0002] The main challenge in open-domain dialogue response generation is producing relevant and diverse responses. The training data used to train dialogue models contains a large amount of unknown background information, making the dialogue a one-to-many problem, where different people can offer different but reasonable answers to the same question.

[0003] Existing models ignore the high-level semantic information between the context and the target response in the dialogue training dataset during the training phase, which makes insufficient use of the potential background information in the dialogue training dataset. This results in the responses generated in the application phase not being highly relevant to the context and having poor diversity. Summary of the Invention

[0004] (a) Technical problems to be solved

[0005] To address the shortcomings of existing technologies, this invention provides a multi-turn dialogue generation method, system, storage medium, and electronic device based on a conditional diffusion model, which solves the problem of not fully utilizing the potential background information in the dialogue training dataset.

[0006] (II) Technical Solution

[0007] To achieve the above objectives, the present invention provides the following technical solution:

[0008] A multi-turn dialogue generation method based on a conditional diffusion model, comprising:

[0009] Obtain the context of a multi-turn dialogue;

[0010] Obtain the context representation of the multi-turn dialogue context;

[0011] Randomly sample a Gaussian noise from a standard Gaussian distribution;

[0012] Based on the conditional diffusion model, noise is gradually denoised under the guidance of the context representation, and the Gaussian noise is restored to a latent variable that conforms to the context of the multi-turn dialogue.

[0013] Based on the contextual representation and latent variables, the final response is generated.

[0014] Preferably, the conditional diffusion model is a UNet model; its training process includes:

[0015] S10. Based on the pre-trained recognition network, obtain the first latent variables of several multi-turn dialogue context samples;

[0016] S20. During the forward diffusion process, for the first latent variable of any multi-turn dialogue context sample, Gaussian noise is added sequentially over T time steps to gradually transform the first latent variable into a standard Gaussian distribution to obtain the final Gaussian noise z. T ;

[0017] S30. During the reverse diffusion process, at each reverse time step t, the context representation of any multi-turn dialogue context sample is passed through a linear layer. Mapped to It is then mapped to an intermediate layer of the model via a cross-attention layer to reduce the final Gaussian noise z. T Reduced to the second latent variable;

[0018] In the cross-attention layer, the latent variable z corresponding to the reverse time step t is used. t As a query Using context intermediate representation As keys and values;

[0019] S40. Construct the loss function L DM And train the UNet model until it converges;

[0020]

[0021] Where DM represents the diffusion model; z0 represents the first latent variable; The noise ∈ indicates that it follows a standard Gaussian distribution; θ represents the parameter, ∈ θ Represents the UNet model; t is a time step randomly sampled from 1 to T; α t =1-β t and β t The weights are taken from the linear scheduling table {β1,…,β}. T}

[0022] Preferably, the training process of the recognition network is as follows:

[0023] S100. Pre-acquire multi-turn dialogue context samples c = {u1, u2, ... u} containing n sentences. n}, and the corresponding target response r = {r1, r2, ... r} k}; where the i-th sentence is defined as u i ={w i,1 ,w i,2 ,…w i,m}, w i,mr represents the m-th word in the i-th sentence. k This represents the k-th word in the generated response;

[0024] S200: Based on a hierarchical encoder, obtain the context representation of each multi-turn dialogue context sample. And based on a word-level encoder, obtain the sentence vector h of the corresponding target response. r ;

[0025] S300, Transfer sentence vector h r The last element in the context representation that represents contextual information Perform splicing to obtain the features h of the latent space. z ;

[0026]

[0027] Wherein, ConCat represents the splicing operation;

[0028] S400, Based on the characteristics of the potential space h z The third latent vector z is obtained based on the recognition network to be trained;

[0029]

[0030] u=MLP φ (h z )

[0031] log(σ 2 ) = MLP φ (h z )

[0032] Where, q φ (z|c,r) represents the recognition network; φ represents the network parameters; u is the mean vector of a Gaussian distribution; σ 2 I is the covariance matrix, where σ 2 I is the variance, and I is the identity matrix; MLP stands for Multilayer Perceptron.

[0033] S500. The distribution e(r) of the third latent variable z and the response r is used as the input of the response decoder, and its output is fed into the feedforward layer and the softmax layer in sequence. The greedy decoding method is used to select the word with the highest probability of generation at each time step as the output, and finally the complete response sequence is obtained.

[0034] S600, Construct the loss function L NLL And train the recognition network until it converges;

[0035]

[0036] Among them, NLL represents negative log-likelihood; |r| < t represents the partially generated response, and p(r t |c, z, r < t) represents the probability of generating the response r at the next time step t t .

[0037] Preferably, the hierarchical encoder in S200 sequentially includes a word-level encoder and a sentence-level encoder. The word-level encoder includes a first Transformer encoder and a gated recurrent unit, and the sentence-level encoder is a second Transformer encoder;

[0038] The process of obtaining the context representation includes:

[0039] Obtain the sentence embedding of the i-th sentence u i ={w i,1 , w i,2 , … w i,m};

[0040] At the word-level encoder, use the sentence embedding as the input of the first Transformer encoder;

[0041] {x′ i,1 , x′ i,2 , …, x′ i,m}=TransformerEncoder{x i,1 , x i,2 , …, x i,m}

[0042] where x i,m is the word embedding of the word w i,m ; x′ i,m is the re-representation of x i,m ;

[0043] And use {x′ i,1 [[ID=�7]], x′ i,2 , …, x′ i,m} as the input of the gated recurrent unit to obtain a sentence vector of a fixed dimension;

[0044] h i =GRU(x′ i,1 , x′ i,2 , …, x′ i,m )

[0045] where GRU represents the gated recurrent unit;<00002�4>

[0046] At the sentence-level encoder, use each sentence vector as the input of the second Transformer encoder to obtain the context representation;

[0047]

[0048] Preferably, in step S200, the same word-level encoder is used to obtain the sentence vector h corresponding to the target response. r .

[0049] Preferably, the response decoder in S500 includes a masked multi-head attention layer, an encoder-decoder attention layer, and a latent decoder attention layer in sequence, and the process of obtaining its output includes:

[0050] Get the target reply for each word r i The distribution e(r) i );

[0051] e(r i ) = embed(r i )+PE(r i )

[0052] Where embed(·) represents the word embedding function, and PE represents the position embedding function;

[0053] Merge each word r i The distribution e(r) i Obtain the distribution e(r) of the response r and use it as input to the masked multi-head attention layer to update the response representation:

[0054] H dec =MultiHead(e(r),e(r),e(r))

[0055] MultiHead represents the multi-head attention mechanism;

[0056] The response will be represented as H. dec As a query, the dialogue context H con Using keys and values ​​as input to the encoder-decoder attention layer, a cross-attention mechanism is employed to fuse response and dialogue context information:

[0057] Y = MultiHead(H dec H con H con )

[0058] Using the third latent variable z and Y as input to the latent-decoding attention layer, the final output is obtained:

[0059] Y′=MultiHead(Y,z,z).

[0060] A multi-turn dialogue generation system based on a conditional diffusion model, comprising:

[0061] The acquisition module is used to acquire the context of multi-turn dialogues;

[0062] An encoding module is used to obtain a contextual representation of the multi-turn dialogue context;

[0063] The sampling module is used to randomly sample a Gaussian noise from a standard Gaussian distribution;

[0064] The restoration module is used to gradually denoise the Gaussian noise based on the conditional diffusion model and guided by the context representation, restoring the Gaussian noise to latent variables that conform to the multi-turn dialogue context.

[0065] A generation module is used to generate a final response based on the context representation and potential variables.

[0066] A storage medium storing a computer program for generating multi-turn dialogues based on a conditional diffusion model, wherein the computer program causes a computer to execute the multi-turn dialogue generation method as described above.

[0067] An electronic device, comprising:

[0068] One or more processors; a memory; and one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the one or more processors, the programs including methods for performing the multi-turn dialogue generation method as described above.

[0069] (III) Beneficial Effects

[0070] This invention provides a method, system, storage medium, and electronic device for generating multi-turn dialogues based on a conditional diffusion model. Compared with existing technologies, it has the following advantages:

[0071] This invention, based on a pre-trained conditional diffusion model, first obtains a multi-turn dialogue context; second, it obtains a context representation of the multi-turn dialogue context and randomly samples Gaussian noise from a standard Gaussian distribution; third, based on the conditional diffusion model, it progressively denoises the Gaussian noise under the guidance of the context representation, restoring it to latent variables consistent with the multi-turn dialogue context; finally, it generates the final response based on the context representation and latent variables. Introducing a conditional diffusion model to fit the distribution of latent variables fully utilizes the rich latent information in the training data, resulting in more relevant and diverse generated responses. Attached Figure Description

[0072] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0073] Figure 1 A technical framework diagram of a multi-turn dialogue generation method based on a conditional diffusion model provided in an embodiment of the present invention;

[0074] Figure 2 A block diagram of a multi-turn dialogue generation method based on a conditional diffusion model provided in an embodiment of the present invention;

[0075] Figure 3 This is a schematic diagram of a training process based on a conditional diffusion model, provided as an embodiment of the present invention. Detailed Implementation

[0076] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention are described clearly and completely. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0077] This application provides a method, system, storage medium, and electronic device for generating multi-turn dialogues based on a conditional diffusion model, which addresses the problem of underutilizing potential background information in dialogue training datasets.

[0078] The technical solution in this application is to solve the above-mentioned technical problems, and the general idea is as follows:

[0079] This invention recognizes that modeling these latent contextual semantics from dialogues can improve the consistency and diversity between dialogue context and responses. However, it is currently difficult to know how much latent information is hidden in the dialogue context, and labeling the contextual information of dialogue datasets is a complex task that requires the involvement of domain experts and a significant amount of human effort. How to effectively and automatically learn the latent contextual information of dialogues without manual annotation remains a challenging problem.

[0080] Accordingly, this invention introduces the conditional diffusion model into a multi-turn dialogue generation model based on the Transformer structure, proposing a conditional diffusion enhanced dialogue model to explicitly model the latent background information in the dialogue dataset. It should be noted that this invention assumes that the latent variables follow a decomposed Gaussian distribution and uses it to model the latent background information in the dialogue. This assumption is prior art; for details, please refer to the reference: Zhao T, Zhao R, Eskenazi M. Learning Discourse-level Diversity for Neural Dialog Models using Conditional Variational Autoencoders[C] / / Proceedings of the 55th Annual Meeting of the Association for Computational Linguistics(Volume 1:LongPapers).2017:654-664.

[0081] Specifically, such as Figure 1 As shown: During the training phase, a recognition network is used to model the distribution of latent variables between the dialogue context and the target response. Subsequently, a dialogue context-guided conditional diffusion model is used to model a prior distribution to fit the latent variable distribution obtained from the recognition network. During the inference phase, since the target response is unknown, the context-guided conditional diffusion model progressively denoises a noise sampled randomly from a Gaussian distribution to generate latent variables, which are then combined with the context representation to finally generate the response. Specifically, in both phases, the latent variables are fed into the decoder for fusion to help generate a plausible response.

[0082] In summary, the multi-turn dialogue generation model trained on the same dialogue training dataset in this embodiment of the invention generates more reasonable and natural responses compared to other dialogue generation models.

[0083] To better understand the above technical solutions, the following will provide a detailed explanation of the technical solutions in conjunction with the accompanying drawings and specific implementation methods.

[0084] Example:

[0085] like Figure 2 As shown, this embodiment of the invention provides a multi-turn dialogue generation method based on a conditional diffusion model, which, based on a pre-trained conditional diffusion model, includes:

[0086] Obtain the context of a multi-turn dialogue;

[0087] Obtain the context representation of the multi-turn dialogue context;

[0088] Randomly sample a Gaussian noise from a standard Gaussian distribution;

[0089] Based on the conditional diffusion model, noise is gradually denoised under the guidance of the context representation, and the Gaussian noise is restored to a latent variable that conforms to the context of the multi-turn dialogue.

[0090] Based on the contextual representation and latent variables, the final response is generated.

[0091] This invention introduces a conditional diffusion model to fit the distribution of latent variables, making full use of the rich latent information in the training data, resulting in stronger relevance and diversity of the generated responses.

[0092] It should be emphasized that, since the prediction application (inference stage) of the multi-turn dialogue generation method provided in this embodiment of the invention relies on a pre-trained conditional diffusion model, and the training process of the conditional diffusion model relies on a pre-trained recognition network (training stage), the specific content of the scheme will be introduced in the following sections according to the training stage and the inference stage:

[0093] Training phase:

[0094] First, let's introduce the training process of the recognition network:

[0095] S100. Pre-acquire multi-turn dialogue context samples c = {u1, u2, ... u} containing n sentences. n}, and the corresponding target response r = {r1, r2, ... r} k}; where the i-th sentence is defined as u i ={w i,1 ,w i,2 ,…w i,m}, w i,m r represents the m-th word in the i-th sentence. k This represents the k-th word in the generated response.

[0096] S200: Based on a hierarchical encoder, obtain the context representation of each multi-turn dialogue context sample. And based on a word-level encoder, obtain the sentence vector h of the corresponding target response. r .

[0097] Among them, such as Figure 1 As shown, the hierarchical encoder sequentially includes a word-level encoder and a sentence-level encoder, wherein the word-level encoder includes a first transformer encoder and a gated recursive unit, and the sentence-level encoder is a second transformer encoder;

[0098] Accordingly, the context representation The acquisition process includes:

[0099] First, obtain the i-th sentence u. i ={w i,1 ,w i,2 ,…w i,m Sentence embedding;

[0100] Then, at the word-level encoder, the sentence embedding is used as the input of the first transformer encoder to re-represent the words in the sentence and capture the long-range dependencies in the sequence;

[0101] {x′ i,1 ,x′ i,2 ,…,x′ i,m} = TransformerEncoder{x i,1 ,x i,2 ,…,x i,m}

[0102] Where, x i,m It is the word w i,m Word embedding; x′ i,m For x i,m The restatement;

[0103] and {x′ i,1 ,x′ i,2 ,…,x′ i,m The fixed-dimensional sentence vector is obtained by using the input of the gated recursive unit.

[0104] h i =GRU(x′) i,1 ,x′ i,2 ,…,x′ i,m )

[0105] Wherein, GRU represents a gated recursive unit;

[0106] Finally, at the sentence-level encoder, each sentence vector is used as the input to the second transformer encoder to obtain the context representation;

[0107]

[0108] Specifically, the same word-level encoder is used to obtain the sentence vector h corresponding to the target response. r .

[0109] h r =WrodLevelEncoder(r1,r2,…,r k )

[0110] Or it can be expressed as:

[0111] h r =GRU(x′) i,1 ,x′ i,2 ,…,x′ i,k )

[0112] {x′ i,1 ,x′ i,2 ,…,x′ i,k} = TransformerEncoder{x i,1 ,x i,2 ,…,x i,k}

[0113] S300, Transfer sentence vector h r The last element in the context representation that represents contextual information Perform splicing to obtain the features h of the latent space. z ;

[0114]

[0115] ConCat represents the splicing operation.

[0116] S400, Based on the characteristics of the potential space h z The third latent vector z is obtained based on the recognition network to be trained;

[0117]

[0118] u=MLP φ (h z )

[0119] log(σ 2 ) = MLP φ (h z )

[0120] Where, q φ (z|c,r) represents the recognition network; φ represents the network parameters; u is the mean vector of a Gaussian distribution; σ 2 I is the covariance matrix, where σ 2 I is the variance, and I is the identity matrix; MLP stands for Multilayer Perceptron.

[0121] S500. The distribution e(r) of the third latent variable z and the response r is used as the input of the response decoder, and its output is sequentially fed into the feedforward layer and the softmax layer. The greedy decoding method is used to select the word with the highest probability of generation at each time step as the output, and finally the complete response sequence is obtained.

[0122] Among them, such as Figure 1As shown, the response decoder includes a masked multi-head attention layer, an encoder-decoder attention layer, and a latent decoder attention layer in sequence. The process of obtaining its output includes:

[0123] First, obtain the target reply for each word r. i The distribution e(r) i );

[0124] e(r i ) = embed(r i )+PE(r i )

[0125] Where embed(·) represents the word embedding function, and PE represents the position embedding function;

[0126] Then merge each word r i The distribution e(r) i Obtain the distribution e(r) of the response r and use it as input to the masked multi-head attention layer to update the response representation:

[0127] H dec =MultiHead(e(r),e(r),e(r))

[0128] MultiHead represents the multi-head attention mechanism;

[0129] Furthermore, the reply will indicate H dec As a query, the dialogue context H con Using keys and values ​​as input to the encoder-decoder attention layer, a cross-attention mechanism is employed to fuse response and dialogue context information:

[0130] Y = MultiHead(H dec H con H con )

[0131] Finally, to incorporate the latent variables into the decoder, a latent-decoder attention layer is introduced to perform cross-attention operations on the latent variables. Specifically, the third latent variable z and Y are used as inputs to this latent-decoder attention layer to obtain the final output.

[0132] Y′=MultiHead(Y,z,z).

[0133] After outputting Y′, it is successively sent to the forward feedback layer and the softmax layer to obtain the probability of the word during the generation process. Next, the greedy decoding method is used to select the word with the highest generation probability at each time step as the output. This means selecting the word with the highest probability at each time step, then adding it to the generated response sequence, and then proceeding to the next time step, repeating this process until a terminator is generated or the maximum generation length is reached.

[0134] S600. Construct the loss function L NLL , and train the recognition network until convergence;

[0135]

[0136] Among them, NLL represents negative log-likelihood, and the negative log-likelihood function is used to measure the error between the response generated by the model and the actual data. Specifically, when training the generation model, the goal can be to minimize the negative log-likelihood loss to improve the ability of the model to generate reasonable responses; |r|<t represents the partially generated response, and p(r t |c,z,r<t) represents the probability of generating the response r at the next time step t t .

[0137] It should be noted that compared with the prior art, the embodiment of the present invention also uses the masked multi-head attention mechanism to mask the future words of the response in the decoder during the training stage of the recognition network, and applies the recurrent function to the response generated in the inference stage.

[0138] After training the recognition network, the training process of the conditional diffusion model is continued accordingly:

[0139] Exemplarily, in the embodiment of the present invention, the conditional diffusion model is set as the UNet model. During its training process, the multi-round dialogue context in the dialogue training dataset is input into the above-mentioned trained recognition network again. Since there are many dialogue records in the dialogue training dataset, the latent variables and context representations generated by the recognition network in the multi-round dialogue generation model in each dialogue record are saved as the dataset for training the conditional diffusion model. The distribution of the latent variables in this dataset is the distribution that the conditional diffusion model is expected to model, and the context representation is used to model the conditional diffusion model.

[0140] Specifically, its training process includes:

[0141] S10. Based on the pre-trained recognition network, obtain the first latent variables of several multi-round dialogue context samples.

[0142] S20. As Figure 3As shown, during the forward diffusion process, for the first latent variable of any multi-turn dialogue context sample, Gaussian noise is added sequentially over T time steps to gradually transform the first latent variable into a standard Gaussian distribution to obtain the final Gaussian noise z. T ;

[0143] The forward diffusion process can be concisely described as follows:

[0144]

[0145] or

[0146]

[0147] Where t is a time step randomly sampled from 1 to T; z0 represents the first latent variable; This indicates that the noise ∈ follows a standard Gaussian distribution; α t =1-β t and β t The weights are taken from the linear scheduling table {β1,…,β}. T}(In reality, β t It increases as t increases; here, T can be set to 1000, β t Linear interpolation from 0.0001 to 0.02.

[0148] S30, such as Figure 3 As shown, in the reverse time step t during the back-diffusion process, the context representation of any multi-turn dialogue context sample is passed through a linear layer. Mapped to It is then mapped to an intermediate layer of the model via a cross-attention layer to reduce the final Gaussian noise z. T Reduced to the second latent variable

[0149] To guide the back-diffusion process and ensure that the final latent variable z conforms to the context, a cross-attention mechanism is used to enhance the UNet network. For example, Figure 3 As shown, in the cross-attention layer, the latent variable z corresponding to the reverse time step t is used. t As a query Using context intermediate representation As keys and values;

[0150] S40. Construct the loss function L DM And train the UNet model until it converges;

[0151]

[0152] Where DM represents the diffusion model; θ represents the parameters, ∈ θ This represents the UNet model.

[0153] Thus, the training process of the conditional diffusion model in this embodiment of the invention is complete.

[0154] Reasoning stage:

[0155] The inference phase is the prediction and application phase. Therefore, the biggest difference between the inference and training phases is that there is no target response available during the inference phase, making it impossible to obtain the latent variable z through the recognition network. Correspondingly, this embodiment of the invention uses the conditional diffusion model trained above to progressively denoise Gaussian noise randomly sampled from a normal Gaussian distribution to generate latent variables. These latent variables are then fed into the response decoder to guide the generation of multi-turn dialogues.

[0156] Specifically, during the inference phase, a multi-turn dialogue context is obtained. First, the dialogue context is encoded by word-level encoders and sentence-level encoders to obtain a context representation. Then, a Gaussian noise is randomly sampled from a standard Gaussian distribution. Guided by the context representation, the trained conditional diffusion model (denoising neural network UNet) gradually denoises the Gaussian noise to restore it to a latent variable that matches the dialogue context. Finally, the response decoder generates the final response using a greedy decoding method, guided by both the latent variable and the context representation.

[0157] This invention provides a multi-turn dialogue generation system based on a conditional diffusion model, which, based on a pre-trained conditional diffusion model, includes:

[0158] The acquisition module is used to acquire the context of multi-turn dialogues;

[0159] An encoding module is used to obtain a contextual representation of the multi-turn dialogue context;

[0160] The sampling module is used to randomly sample a Gaussian noise from a standard Gaussian distribution;

[0161] The restoration module is used to gradually denoise the Gaussian noise based on the conditional diffusion model and guided by the context representation, restoring the Gaussian noise to latent variables that conform to the multi-turn dialogue context.

[0162] A generation module is used to generate a final response based on the context representation and potential variables.

[0163] This invention provides a storage medium storing a computer program for generating multi-turn dialogues based on a conditional diffusion model, wherein the computer program causes a computer to execute the multi-turn dialogue generation method described above.

[0164] This invention provides an electronic device, comprising:

[0165] One or more processors; a memory; and one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the one or more processors, the programs including methods for performing the multi-turn dialogue generation method as described above.

[0166] It is understood that the multi-turn dialogue generation system, storage medium and electronic device based on the conditional diffusion model provided in the embodiments of the present invention correspond to the multi-turn dialogue generation method based on the conditional diffusion model provided in the embodiments of the present invention. The explanation, examples and beneficial effects of the relevant contents can be referred to the corresponding parts of the multi-turn dialogue generation method, and will not be repeated here.

[0167] In summary, compared with existing technologies, it has the following beneficial effects:

[0168] 1. The multi-turn dialogue generation model trained on the same dialogue training dataset in this embodiment of the invention generates more reasonable and natural responses compared to other dialogue generation models.

[0169] 2. The embodiments of the present invention are based on the design of a hierarchical encoder structure model using Transformer to capture important historical information in the context, and make full use of the context information.

[0170] 3. This embodiment of the invention introduces a conditional diffusion model to fit the distribution of latent variables and guides the decoder to generate responses. This can fully utilize the rich latent information in the training data, resulting in more relevant and diverse generated responses.

[0171] 4. In the inference phase after training, the present invention can generate different responses by sampling the same context using a diffusion model, thus solving the one-to-many problem between context and response in dialogue.

[0172] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

[0173] The above embodiments are only used to illustrate the technical solutions of the present invention, and are not intended to limit it. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A multi-turn dialogue generation method based on a conditional diffusion model, characterized in that, Based on a pre-trained conditional diffusion model, including: Obtain the context of a multi-turn dialogue; Obtain the context representation of the multi-turn dialogue context; Randomly sample a Gaussian noise from a standard Gaussian distribution; Based on the conditional diffusion model, noise is gradually denoised under the guidance of the context representation, and the Gaussian noise is restored to a latent variable that conforms to the context of the multi-turn dialogue. Based on the context representation and latent variables, the final response is generated; The conditional diffusion model is a UNet model; its training process includes: S10. Based on the pre-trained recognition network, obtain the first latent variables of several multi-turn dialogue context samples; S20, in the forward diffusion process, for the first latent variable of any multi-round dialogue context sample, gradually turn the first latent variable to a standard Gaussian distribution by adding Gaussian noise one by one within T time steps to obtain the final Gaussian noise ; S30、At each backward time step t in the backward diffusion process, the context representation of any multi-turn dialogue context sample is mapped through a linear layer to and mapped through a cross-attention layer to an intermediate layer of the model to reduce the final Gaussian noise to the second latent variable; In the cross-attention layer, the latent variable corresponding to the reverse time step t is used. As a query Use context-intermediate representation As keys and values; S40. Constructing the loss function And train the UNet model until it converges; in, Represents a diffusion model; Indicates the first latent variable; Indicates noise It satisfies a standard Gaussian distribution; Indicates parameters, This represents the UNet model; t is a time step randomly sampled from 1 to T; and , The weights are taken from a linear scheduling table. .

2. The multi-turn dialogue generation method as described in claim 1, characterized in that, The training process of the recognition network is as follows: S100, Pre-acquisition includes Multi-turn dialogue context sample of 1 sentence and the corresponding target response Among them, the first The sentence is defined as , Indicates the first The first sentence One word, Indicates the first response generated One word; S200: Based on a hierarchical encoder, obtain the context representation of each multi-turn dialogue context sample. ; and based on a word-level encoder, obtain the sentence vector of the corresponding target response. ; S300, Transform the sentence vector The last element in the context representation that represents contextual information By stitching together the data, we can obtain the features of the latent space. ; in, Indicates a splicing operation; S400, Based on the characteristics of the potential space The third latent vector is obtained based on the recognition network to be trained. ; in, Represents the identification network; Indicates network parameters; It is the mean vector of a Gaussian distribution; It is the covariance matrix, where It is variance. It is an identity matrix; MLP stands for Multilayer Perceptron; S500, the third latent variable and reply Distribution The output of the response decoder is fed into the feedforward layer and the softmax layer in sequence. The greedy decoding method selects the word with the highest probability of generation at each time step as the output, and finally obtains the complete response sequence. S600, Constructing the loss function And train the recognition network until it converges; in, This represents the negative log-likelihood. This indicates the partial response that has already been generated. Indicates the generation of the next time step. Reply The probability of.

3. The multi-turn dialogue generation method as described in claim 2, characterized in that, The hierarchical encoder in S200 includes a word-level encoder and a sentence-level encoder in sequence. The word-level encoder includes a first transformer encoder and a gated recursive unit. The sentence-level encoder is a second transformer encoder. The context representation The acquisition process includes: Get the a sentence Sentence embedding; At the word-level encoder, the sentence embedding is used as input to the first transformer encoder; in, It is a word Word embedding; for The restatement; and will As input to the gated recursive unit, a fixed-dimensional sentence vector is obtained; in, Indicates a gated recursive unit; At the sentence-level encoder, each sentence vector is used as input to the second transformer encoder to obtain the context representation; 。 4. The multi-turn dialogue generation method as described in claim 3, characterized in that, In step S200, the same word-level encoder is used to obtain the sentence vector corresponding to the target response. .

5. The multi-turn dialogue generation method as described in claim 2, characterized in that, The response decoder in S500 includes a masked multi-head attention layer, an encoder-decoder attention layer, and a latent decoder attention layer in sequence. The process of obtaining its output includes: Get the target reply for each word Distribution ; in, Representative word embedding function, Indicates the position embedding function; Merge each word Distribution Get a reply Distribution And as input to the masked multi-head attention layer, update the response representation: in, This represents the multi-head attention mechanism; The reply indicates As a query, the dialogue context Using keys and values ​​as input to the encoder-decoder attention layer, a cross-attention mechanism is employed to fuse response and dialogue context information: The third latent variable and As input to the latent-decoding attention layer, the final output is obtained: 。 6. A multi-turn dialogue generation system based on a conditional diffusion model, characterized in that, Based on a pre-trained conditional diffusion model, a multi-turn dialogue generation method as described in any one of claims 1 to 5 is used to perform the method, including: The acquisition module is used to acquire the context of multi-turn dialogues; An encoding module is used to obtain a contextual representation of the multi-turn dialogue context; The sampling module is used to randomly sample a Gaussian noise from a standard Gaussian distribution; The restoration module is used to gradually denoise the Gaussian noise based on the conditional diffusion model and guided by the context representation, restoring the Gaussian noise to latent variables that conform to the multi-turn dialogue context. A generation module is used to generate a final response based on the context representation and potential variables.

7. A storage medium, characterized in that, It stores a computer program for generating multi-turn dialogues based on a conditional diffusion model, wherein the computer program causes a computer to execute the multi-turn dialogue generation method as described in any one of claims 1 to 5.

8. An electronic device, characterized in that, include: One or more processors; Memory; And one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the one or more processors, the programs including methods for performing the multi-turn dialogue generation method as described in any one of claims 1 to 5.