A method for generating empathetic dialogue by integrating topic prediction and sentiment reasoning
Through the empathetic dialogue generation method that integrates theme prediction and emotional reasoning, the problem of dialogue generation in the existing technology is solved, and the emotional empathy and theme consistency of dialogue generation is improved.
Patent Information
- Application Number
- CN202210019847.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-01-10
- Publication Date
- 2024-12-31
- Estimated Expiration
- 2042-01-10
AI Technical Summary
The existing human-computer dialogue generation system is difficult to continuously generate dialogues with emotional resonance, and early models have inaccuracies in predicting dialogue topics and identifying emotions, ignoring the reasons behind emotions, resulting in incoherent reactions.
A method of empathetic dialogue generation that integrates theme prediction and emotional reasoning is proposed. By constructing a model including theme prediction module, emotion reasoning module and dialogue generation module, hierarchical context encoding, context-related theme representation and context control theme prediction, combined with transformer The model performs emotional cause word recognition, maximizing the conditional probability to generate empathetic responses.
Effectively using context information for topic prediction and emotional recognition, improving the emotional empathy and theme consistency generated by dialogue, and the generated replies can resonate with users more emotionally.
Smart Images

Figure CN114385802B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the fields of natural language processing, deep learning, text sentiment analysis, and dialogue generation, and in particular to an empathy dialogue generation method integrating topic prediction and sentiment reasoning. Background Art
[0002] Scenes of human-computer dialogue are everywhere in people's lives. As a core area in the field of artificial intelligence, human-computer dialogue has always received widespread attention from all walks of life. People have always hoped to create robots that can communicate fluently with people. As early as 1950, Turing clearly proposed the standard for judging whether a robot is intelligent, namely the Turing test. Inspired by the Turing test, human-computer dialogue has attracted the attention of scholars. With the development of deep learning technology, artificial intelligence has ushered in the third wave. The massive dialogue data on the Internet provides data drive and support for human-computer dialogue technology based on deep learning. However, the dialogues generated by early dialogue generation systems do not have any emotions. However, users generally hope that the responses generated by the machine can resonate with themselves emotionally. Without emotional responses, it is easy for users to lose interest in chatting. Therefore, it is necessary to propose an emotional dialogue generation method.
[0003] Most of the early research on emotional dialogue models focused on the generation of single-round dialogues with specified emotions. Such models cannot judge the user's emotions at the moment based on the user's input sentences. Instead, they generate emotional replies by inputting an additional specified emotion into the model encoder or decoder. Each reply is generated in a single round, which means that the model can only have one round of dialogue with the user. However, in real life, people hope that the dialogue with the machine can continue for many rounds, and when generating emotional replies, there is no need to specify emotions. Instead, the user's emotions are analyzed through the user's input and dialogue history information, and the user's desired emotional response is predicted. This way of generating replies is called empathetic dialogue generation.
[0004] Empathic dialogue is derived from the emotional dialogue task. It understands the user's current feelings based on the dialogue history and generates corresponding responses, thereby generating emotional resonance with the user. The main challenges of empathic dialogue generation focus on the prediction of dialogue topics and the recognition of emotions. In terms of dialogue topic prediction, previous studies only predicted dialogue topics based on dialogue history, only considered the individual semantics of each topic, and ignored its specific dialogue context, which may lead to inaccurate topic representation and affect response coherence; in terms of emotion recognition, current methods mainly focus on learning a model to predict emotion labels, but ignore the detection of the reasons behind emotions, which will result in the model only using surface emotional information. Summary of the invention
[0005] In order to solve the above problems in the prior art, the present invention proposes an empathy dialogue generation method integrating topic prediction and emotional reasoning, including constructing an empathy dialogue generation model integrating topic prediction and emotional reasoning, the model including a topic prediction module, an emotional reasoning module and a dialogue generation module, using the topic prediction module to predict the dialogue topic controlled by the context to obtain the predicted topic; using the emotional reasoning module to predict the context emotion tag and identify the emotion cause word to obtain the corresponding emotion information; inputting the obtained topic information and emotion information into the dialogue generation module to obtain an empathy response that resonates with the user's emotion, and the training process of the empathy dialogue generation model integrating topic prediction and emotional reasoning specifically includes the following steps:
[0006] S1: Obtain empathy dialogue data, process the data, and generate training data sets, verification data sets, and test data sets;
[0007] S2: Use word embedding to convert the input sequence in the empathy dialogue dataset into the corresponding word vector representation;
[0008] S3: The vector representation obtained by word embedding is input into the topic prediction and sentiment reasoning modules respectively to perform conversation topic prediction and sentiment reasoning;
[0009] S4: Use trainable emotion embedding as the representation of each context label ε;
[0010] S5: Add the emotion embedding, word embedding and position embedding and input them into the dialogue generation module to obtain the theme words and emotion reason words;
[0011] S6: Maximize the conditional probability p(U m |U <m ) generates a final response, calculates the model’s loss function based on the generated result, inputs the data in the test sample into the model, continuously adjusts the model’s parameters, and completes the model training when the model’s loss function value is less than the set threshold.
[0012] Furthermore, the topic prediction module includes hierarchical context encoding, context-related topic representation and context-controlled topic prediction. Hierarchical context encoding is used to obtain the context representation of the discourse; context-related topic representation is used to obtain the topic representation of the discourse based on the context representation of the discourse; context-controlled topic prediction is used to predict the topic based on the topic representation of the discourse.
[0013] Furthermore, the hierarchical context encoding consists of two layers of BiGRU networks. The first layer of the hierarchical context encoding can Encode to get the utterance level representation It is the discourse i The last hidden layer vector of the utterance-level representation of is expressed as:
[0014]
[0015] The second layer of BiGRU in hierarchical context encoding can be used to encode the utterance-level representation obtained in the first layer. Encoding is performed to obtain context-level representations, including:
[0016]
[0017] Among them, U <m represents the conversation context, N i For discourse U i The number of words, m is the number of utterances in the entire conversation; w n,i Hidden vector, Yes n,i The initial word embedding, w n,i Representation of discourse U i The nth word of ; BiGRU() represents the BiGRU network; It's U i Context-level representation of .
[0018] Furthermore, the context-related topic representation is composed of topic word extraction, intra-topic attention, contextual topic attention, intra-discourse topic representation and inter-discourse topic representation, where:
[0019] When extracting keywords, we use the LDA topic model to extract keywords from the context <m Extract a unique keyword sequence T from s ={t1,…t k}, and from T s For each utterance U i Select keywords Get the context subject as T <m ={T1,…,T m-1};
[0020] The intra-topic attention uses the attention mechanism to calculate the mutual importance weights of different topic words in each discourse, and uses the weights to update the representation of each topic word. The process is expressed as:
[0021]
[0022]
[0023] Contextual topic attention uses the attention mechanism to integrate discourse representation into the topic representation process, which is expressed as:
[0024]
[0025]
[0026] The topic representation within the discourse uses the softmax function to calculate the correlation between the topic word and its related discourse, and obtains a comprehensive topic representation within the discourse, including:
[0027]
[0028]
[0029] Inter-discourse topic representation uses the GRU network to encode the intra-discourse topic representation, capture the relationship between different discourses, and obtain the inter-discourse topic representation, including:
[0030]
[0031] Among them, α j,l represents the mutual importance weight, f() represents the dot product operation, The subject word t j,i ,t l,i The word embedding representation, g relu () is a single-layer fully connected network, ReLU is the activation function, z j,i is the word-level topic representation, glinear is a single-layer linear fully connected network, K i The number of topic words selected for each utterance; β j,n For z j,i and The correlation between For the keyword t j,i The context-dependent topic representation, N i For discourse U i The number of words; j,i Theme j,i with U i The correlation between It is the discourse i comprehensive intra-discourse topic representation; It is the discourse i Integrated discourse-aware topic representation.
[0032] Furthermore, when predicting the context-controlled topic, an H-layer feedforward network is used to predict the transition probability of the conversation topic to the reply, and L topic words with the largest transition probability are selected, including the following process:
[0033]
[0034]
[0035]
[0036]
[0037] Among them, Concat[;] represents the connection operation, W 1 ,…,W H 、b 1 ,…,b H represents the trainable parameters in the model, is the output of the H-layer feedforward network, K represents the number of context-related keywords, represents the transfer weight of the subject word, Indicates the subject word t k Transfer to ReplyU m The probability in , t represents the probability from T s ={t1,…t k}Selected from In the previous L keywords, Top L () indicates selecting the largest L parameters, Indicates the predicted transition topic The word embedding representation, G t is the subject gate sequence, Indicates selection As the probability of predicting the transfer topic.
[0038] Furthermore, the sentiment reasoning module is composed of a transformer model, which predicts the contextual sentiment label ε based on the conversation context, including:
[0039] X={x0,x1,…,x N}
[0040]
[0041]
[0042] Where X is a given conversation context M = {U1,…,U m-1} is the input sequence after being connected, x0 represents the start symbol of the sequence, V is the word representation of X, and W e and b e represents the trainable parameters in the model; p(ε|X) represents the probability of predicting the sentiment label ε based on the conversation context.
[0043] Furthermore, the identification of sentiment-cause words includes:
[0044]
[0045]
[0046]
[0047]
[0048] in, represents the probability that the i-th word is associated with the sentiment reason, c i is the label related to the sentiment reason of the i-th word, W c and b c is a trainable parameter, and C represents the The first k keywords at the time, Indicates the selected The kth topic word at time; is a soft gate with continuous values in [0,1]. Indicates selection in input Probability of being a sentiment-causing word; The vector representation of the first special character [CLS], N i For discourse U i The number of words.
[0049] Furthermore, the dialogue generation module includes an encoder and a decoder, which represents the word vector E w , the emotional label embedding E of the dialogue context ε and the position embedding representation E of the word vector p The added input is fed into the encoder of the dialogue generation module for encoding to obtain contextualized word representations; in the decoder, a cross-attention mechanism is used to pay attention to the contextualized word representations, a topic gate attention and a sentiment-cause word gate attention are added to the cross-attention layer, the topic gate sequence obtained by the topic prediction module is paid attention to, the topic words appearing in the reply in the predicted transfer topic sequence are dynamically selected, the gate sequence obtained by the sentiment reasoning module is paid attention to, and the selection of sentiment-cause related words in the input is dynamically controlled, including:
[0050]
[0051]
[0052] in, The value of indicates the selection of the prediction topic sequence as the probability of a subject word appearing in a response; The value of indicates the selection in the input The probability of being a sentiment-causing word, q lrepresents the query vector, which is the output of the multi-head attention layer; express The embedding representation of express The embedding representation of Indicates selection in input As the probability of sentiment reason words, ⊙ represents the dot product operation, represents the attention weight of the subject gate at the i-th position of the attention layer of the l-th block of the decoder, Represents the attention weight of the sentiment reason word gate at the i-th position of the attention layer of the l-th block of the decoder.
[0053] Furthermore, by maximizing <m Under the condition of m The probability P(U m |U <m ) gets an empathetic response, expressed as:
[0054]
[0055] Among them, p(w n,m |w <n,m ,U <m ,t,C,ε) means that the generated word before time n is w <n,m , the conversation context is U <m , the predicted transfer topic word sequence is t, the emotional reason word sequence is C, and the conversation context emotional label is ε, the word w is generated at time n n,m The probability of n,m Reply U m The word generated at time n, w <n,m Reply U m The generated word before time n, U <m represents the conversation context, t represents the s ={t1,…t k}Selected from In the previous L keywords, represents the transfer weight of the topic word, and C represents the selected ∈ represents the top k topic words at the time of conversation, and ε represents the sentiment label of the conversation context.
[0056] Furthermore, the loss function of the model is the sum of the loss functions of the topic prediction module, the sentiment reasoning module, and the dialogue generation module, where:
[0057] The loss function of the topic prediction module is:
[0058]
[0059]
[0060] The loss function of the sentiment reasoning module is:
[0061]
[0062]
[0063] The loss function of the dialogue generation module is:
[0064]
[0065] Among them, L tran represents the prediction loss of the transfer topic word, K represents the number of context-related topic words; L tran (k) represents the focal loss function, ψ∈[0,1] is a weight control factor, γ≥0 2 is the regulating factor, represents the transfer weight of the subject word; τ k Predicted transfer keywords Whether it appears in the reply, when τ k =1 indicates the predicted transfer keyword Appear in reply U m In the case of τ k =0 indicates the predicted transfer keyword Not appearing in reply U m Medium; L ε represents the contextual sentiment label prediction loss, represents the predicted probability of the contextual sentiment label, represents the probability that the i-th word is associated with the sentiment reason, N i For discourse U i The number of words, L c represents the loss of sentiment reason word detection; L g represents the generation loss of the decoder, N m represents the number of words in the generated response; p(w n,m |w <n,m ,U <m ,t,C,ε) means that the generated word before time n is w <n,m , the conversation context is U <m , the predicted transfer topic word sequence is t, the emotional reason word sequence is C, and the conversation context emotional label is ε, the word w is generated at time n n,m The probability of <m Represents the conversation context, represents the transfer weight of the topic word, and C represents the selected ∈ represents the top k topic words at the time of conversation, and ε represents the sentiment label of the conversation context.
[0066] The present invention well integrates topic information and sentiment information, effectively utilizes context to control topic prediction, accurately predicts context sentiment tags and identifies words related to sentiment reasons, thereby improving the emotional empathy, thematic consistency and content relevance of responses generated by the model. BRIEF DESCRIPTION OF THE DRAWINGS
[0067] Figure 1 This is a schematic diagram of the structure of the empathy dialogue generation model that integrates topic prediction and emotional reasoning of the present invention. DETAILED DESCRIPTION
[0068] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0069] The present invention provides an empathy dialogue generation method based on the fusion of topic prediction and emotional reasoning, and constructs an empathy dialogue generation model that integrates topic prediction and emotional reasoning. The model includes a topic prediction module, an emotional reasoning module and a dialogue generation module. The topic prediction module is used to predict the dialogue topic controlled by the context to obtain the predicted topic; the emotional reasoning module is used to predict the context emotion tag and identify the emotion cause word to obtain the corresponding emotion information; the obtained topic information and emotion information are input into the dialogue generation module to obtain an empathy response that resonates with the user's emotion. The training process of the empathy dialogue generation model that integrates topic prediction and emotional reasoning specifically includes the following steps:
[0070] S1: Obtain empathy dialogue data, process the data, and generate training data sets, verification data sets, and test data sets;
[0071] S2: Use word embedding to convert the input sequence in the empathy dialogue dataset into the corresponding word vector representation;
[0072] S3: The vector representation obtained by word embedding is input into the topic prediction and sentiment reasoning modules respectively to perform conversation topic prediction and sentiment reasoning;
[0073] S4: Use trainable emotion embedding as the representation of each context label ε;
[0074] S5: Add the emotion embedding, word embedding and position embedding and input them into the dialogue generation module to obtain the theme words and emotion reason words;
[0075] S6: Maximize the conditional probability p(U m |U <m ) generates a final response, calculates the model’s loss function based on the generated result, inputs the data in the test sample into the model, continuously adjusts the model’s parameters, and completes the model training when the model’s loss function value is less than the set threshold.
[0076] like Figure 1 In this embodiment, the empathy dialogue generation model integrating topic prediction and sentiment reasoning includes a topic prediction module, a sentiment reasoning module and a dialogue generation module. The user inputs data into the topic prediction module and the sentiment reasoning module respectively. The outputs obtained by the topic reasoning module and the sentiment reasoning module are added and then input into the dialogue generation module to generate a reply as the output of the model. The topic prediction module combines the dialogue context to predict the dialogue topic controlled by the context, and is composed of three parts: hierarchical context encoding, context-related topic representation and context-controlled topic prediction. Figure 1 ,The topic prediction module includes the following operations:
[0077] The first step is to first consider each utterance in the conversation context. After encoding by the first layer of BiGRU, the speech level representation is obtained It's U i The last hidden layer vector of the utterance-level representation is then converted into the utterance-level representation obtained by encoding the first layer. After encoding through the second layer of BiGRU, we finally get the context-level representation, which can be expressed as follows:
[0078]
[0079]
[0080] in, w n,i Hidden vector, Yes n,i The initial word embedding, w n,i Representation of discourse U i The nth word of It's U i Context-level representation of .
[0081] The second step is to use the LDA topic model to extract the content from the context U <m Extract a unique keyword sequence T froms ={t1,…t k}, and from T s For each utterance U i Select keywords Get the context subject as T <m ={T1,…,T m-1}, and then use the intra-topic attention to calculate the mutual importance weights of different topic words in each discourse, and update the representation of each topic word according to the weight. The calculation formula is as follows:
[0082]
[0083]
[0084] in, and For the keyword t j,i With t l,i The word embedding representation, α j,l Mutual importance weight, g relu is a single-layer fully connected network, ReLU is the activation function, z j,i For word-level topic representation, glinear is a single-layer linear fully connected network.
[0085] The third step is to use the following topic attention to calculate z j,i and The correlation between j,n , and according to β j,n Update the topic representation to obtain the context-related topic representation. The calculation formula is as follows:
[0086]
[0087]
[0088] Among them, β j,n Yes j,i and The correlation between Yes j,i Context-dependent topic representation.
[0089] The fourth step is to use the softmax function to calculate the correlation between the topic word and its related discourse ξ j,i , and according to ξ ji To represent the topic within the discourse, the calculation formula is as follows:
[0090]
[0091]
[0092] Among them, ξj,i Theme j,i with U i The correlation between It's U i In-discourse topic representation.
[0093] The fifth step is to use the GRU network to encode the topic representation within the discourse, capture the relationship between different discourses, and obtain the inter-discourse topic representation The calculation formula is as follows:
[0094]
[0095] in, It's U i Integrated discourse-aware topic representation.
[0096] In the sixth step, the topic representation between the discourses obtained in the fifth step and the context-level representation obtained in the first step are used to predict the topic word t through an H-layer feedforward neural network k Transfer to ReplyU m The probability in , get the transfer weight And select the transition probability The topic words in the first L are used as the predicted topic word sequence t. Finally, the topic gate sequence G is obtained from t. t , the calculation formula of the topic prediction process is as follows:
[0097]
[0098]
[0099]
[0100]
[0101] Among them, Concat[;] represents the connection operation, W 1 ,…,W H and b 1 ,…,b H represents the trainable parameters, is the output of the H-layer feedforward network, K represents the number of context-related keywords, represents the transfer weight of the subject word, Indicates the subject word t k Transfer to ReplyU m The probability in , t represents the probability from T s ={t1,…t k}Selected from In the previous L keywords, Indicates the predicted transition topic The word embedding representation, G t is the subject gate sequence, Indicates selection As the probability of predicting the transfer topic.
[0102] The sentiment reasoning module includes sentiment prediction and sentiment cause word recognition, which respectively predict context sentiment labels and recognize words related to sentiment causes, such as Figure 1 As shown, the operations of this module include:
[0103] The conversation context M={U1,…,U m-1} to get the input sequence X = {x0, x1, ..., x N}, and then represent X in words to get A transformer model is used to predict the contextual sentiment label ε, and then the sentiment reason words are identified. The sentiment reason words can provide deeper sentiment information for dialogue generation. If the i-th word is related to the sentiment reason, its sentiment reason label is 1, otherwise it is 0. Given X = {x0, x1, …, x N}, get the probability of each word being associated with the sentiment reason, select from the input The first k topic words at the time are used as the sentiment reason words, and the sentiment reason word gate sequence is obtained according to the sentiment reason label probability. The calculation formula is as follows:
[0104]
[0105]
[0106]
[0107]
[0108] Among them, x0 represents the start symbol of the sequence, V is the word representation of X, and W e and b e represents the trainable parameters, represents the probability that the i-th word is associated with the sentiment reason, c i is the label related to the sentiment reason of the i-th word, W c and b c is a trainable parameter, and C represents the The first k keywords at the time, is a soft gate with continuous values in [0,1]. Indicates selection in input The probability of being a sentiment-causing word.
[0109] The dialogue generation module uses the topic information obtained by the topic prediction module and the emotional information obtained by the emotional reasoning module to generate topic-related and emotionally resonant replies, such as Figure 1 As shown, the module operation includes:
[0110] Embed the word E w , Emotion Embedding ε and position embedding E p The input is added to the encoder and decoder of the dialogue generation module for encoding. The input sequence X = {x0, x1, ..., x N}After being encoded by the encoder, the contextualized word representation is obtained
[0111] In the decoder, a cross attention mechanism is used to pay attention to H, and then a topic gate attention and sentiment reason word gate attention are added to the cross attention layer to obtain the topic gate sequence for the topic prediction module. Pay attention to the topic words that appear in the reply in the predicted transfer topic sequence, and use the gates obtained by the sentiment reasoning module Pay attention to dynamically control the selection of sentiment-related words in the input. The calculation formula is as follows:
[0112]
[0113]
[0114] in, The value of indicates the selection of the prediction topic sequence as the probability of a topic word appearing in a response, The value of indicates the selection in the input The probability of being a sentiment-causing word, q l represents the query vector, which is the output of the multi-head attention layer. express The embedding representation of express The embedding representation of Get an empathetic response.
[0115] The loss function of the model used in the present invention when training the model is the sum of the loss functions of the topic prediction module, the sentiment reasoning module and the dialogue generation module. The loss function of the topic prediction module is:
[0116]
[0117]
[0118] Among them, L tranis the dynamic weighted cross entropy loss, which represents the transfer topic word prediction loss. It can solve the problem of unbalanced training samples. tran (k) represents the focal loss function, ψ∈[0,1] is a weight control factor, γ≥0 2 is the regulating factor.
[0119] The loss function of the sentiment reasoning module is:
[0120]
[0121]
[0122] Among them, L ε represents the contextual sentiment label prediction loss, L c Represents the sentiment reason word detection loss.
[0123] The loss function of the dialogue generation module is:
[0124]
[0125] Among them, L g is a negative log-likelihood loss, representing the generation loss of the decoder, N m Indicates the number of words in the generated response.
[0126] The total loss function of the model is:
[0127] L=L ε +L c +L tran +L g .
[0128] Although embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that various changes, modifications, substitutions and variations may be made to the embodiments without departing from the principles and spirit of the present invention, and that the scope of the present invention is defined by the appended claims and their equivalents.
Claims
1. A method for generating empathetic dialogue by integrating topic prediction and sentiment reasoning, characterized in that: An empathetic dialogue generation model integrating topic prediction and sentiment reasoning is constructed. The model includes a topic prediction module, a sentiment reasoning module and a dialogue generation module. The topic prediction module is used to predict the dialogue topic controlled by the context to obtain the predicted topic. The topic prediction module includes hierarchical context encoding, context-related topic representation and context-controlled topic prediction. Hierarchical context encoding is used to obtain the context representation of the discourse; the context-related topic representation is used to obtain the topic representation of the discourse according to the context representation of the discourse; the context-controlled topic prediction is used to predict the topic according to the topic representation of the discourse. The hierarchical context encoding consists of two layers of BiGRU networks. The first layer of the hierarchical context encoding can encode each utterance in the context. Encode to get the utterance level representation It is the discourse i The last hidden layer vector of the utterance-level representation of is expressed as: The second layer of BiGRU in hierarchical context encoding can be used to encode the utterance-level representation obtained in the first layer. Encoding is performed to obtain context-level representations, including: Among them, U <m represents the conversation context, N i For discourse U i The number of words, m is the number of utterances in the entire conversation; w n,i Hidden vector, Yes n,i The initial word embedding, w n,i Representation of discourse U i The nth word of ; BiGRU() represents the BiGRU network; It's U i Context-level representation of ; The context-sensitive topic representation consists of topic word extraction, intra-topic attention, contextual topic attention, intra-discourse topic representation, and inter-discourse topic representation, where: When extracting keywords, we use the LDA topic model to extract keywords from the context <m Extract a unique keyword sequence T from s ={t1,…t k }, and from T s For each utterance U i Select keywords Get the context subject as T <m ={T1,…,T m-1 }; The intra-topic attention uses the attention mechanism to calculate the mutual importance weights of different topic words in each discourse, and uses the weights to update the representation of each topic word. The process is expressed as: Contextual topic attention uses the attention mechanism to integrate discourse representation into the topic representation process, which is expressed as: The topic representation within the discourse uses the softmax function to calculate the correlation between the topic word and its related discourse, and obtains a comprehensive topic representation within the discourse, including: Inter-discourse topic representation uses the GRU network to encode the intra-discourse topic representation, capture the relationship between different discourses, and obtain the inter-discourse topic representation, including: Among them, α j,l represents the mutual importance weight, f() represents the dot product operation, The subject word t j,i ,t l,i The word embedding representation, g relu () is a single-layer fully connected network, ReLU is the activation function, z j,i is the word-level topic representation, glinear is a single-layer linear fully connected network, K i The number of topic words selected for each utterance; β j,n For z j,i and The correlation between For the keyword t j,i The context-dependent topic representation, N i For discourse U i The number of words; j,i Theme j,i with U i The correlation between It is the discourse i comprehensive intra-discourse topic representation; It is the discourse i The integrated discourse-aware topic representation; When predicting context-controlled topics, an H-layer feedforward network is used to predict the probability of a conversation topic being transferred to a reply, and the L topic words with the largest transfer probability are selected, including the following process: Among them, Concat[;] represents the connection operation, W 1 ,…,W H , b 1 ,…,b H represents the trainable parameters in the model, is the output of the H-layer feedforward network, K represents the number of context-related keywords, represents the transfer weight of the subject word, Indicates the subject word t k Transfer to ReplyU m The probability in , t represents the probability from T s ={t1,…t k }Selected from Top of the L keyword L () indicates selecting the largest L parameters, Indicates the predicted transition topic The word embedding representation, G t is the subject gate sequence, Indicates selection As the probability of predicting the transfer subject words; The sentiment reasoning module is used to predict the contextual sentiment label and identify the sentiment cause words to obtain the corresponding sentiment information. The sentiment reasoning module is composed of a transformer model, which predicts the contextual sentiment label ε based on the dialogue context, including: X={x0,x1,…,x N } Where X is a given conversation context M = {U1,…,U m-1 } is the input sequence after being connected, x0 represents the start symbol of the sequence, V is the word representation of X, and W e and b e represents the trainable parameters in the model; p(ε|X) represents the probability of predicting the sentiment label ε based on the conversation context; Identifying emotional reason words includes: in, represents the probability that the i-th word is associated with the sentiment reason, c i is the label related to the sentiment reason of the i-th word, W c and b c is a trainable parameter, and C represents the The first k keywords at the time, Indicates the selected The kth topic word at time; is a soft gate with continuous values in [0,1]. Indicates selection in input Probability of being a sentiment-causing word; The vector representation of the first special character [CLS]; The obtained topic information and emotional information are input into the dialogue generation module to obtain an empathetic response that resonates with the user's emotions. The dialogue generation module includes an encoder and a decoder. The word vector representation E w , the emotion label embedding E of the dialogue context ε and the position embedding representation E of the word vector p The added input is fed into the encoder of the dialogue generation module for encoding to obtain contextualized word representations; in the decoder, a cross-attention mechanism is used to pay attention to the contextualized word representations, a topic gate attention and a sentiment-cause word gate attention are added to the cross-attention layer, the topic gate sequence obtained by the topic prediction module is paid attention to, the topic words appearing in the reply in the predicted transfer topic sequence are dynamically selected, the gate sequence obtained by the sentiment reasoning module is paid attention to, and the selection of sentiment-cause related words in the input is dynamically controlled, including: in, The value of indicates the selection of the prediction topic sequence as the probability of a subject word appearing in a response; The value of indicates the selection in the input The probability of being a sentiment-causing word, q l represents the query vector, which is the output of the multi-head attention layer; express The embedding representation of express The embedding representation of Indicates selection in input As the probability of sentiment reason words, ⊙ represents the dot product operation, represents the attention weight of the subject gate at the i-th position of the attention layer of the l-th block of the decoder, represents the attention weight of the sentiment reason word gate at the ith position of the attention layer of the lth block of the decoder; By maximizing the <m Under the condition of m The probability P(U m |U <m ) gets an empathetic response, expressed as: Among them, p(w n,m |w <n,m ,U <m ,t,C,ε) means that the generated word before time n is w <n,m , the conversation context is U <m , the predicted transfer topic word sequence is t, the emotional reason word sequence is C, and the conversation context emotional label is ε, the word w is generated at time n n,m The probability of n,m Reply U m The word generated at time n, w <n,m Reply U m The generated word before time n, U <m represents the conversation context, t represents the s ={t1,…t k }Selected from In the previous L keywords, represents the transfer weight of the topic word, and C represents the selected The first k topic words at the time, ε represents the conversation context sentiment label; The training process of the empathetic dialogue generation model that integrates topic prediction and sentiment reasoning specifically includes the following steps: S1: Obtain empathy dialogue data, process the data, and generate training data sets, verification data sets, and test data sets; S2: Use word embedding to convert the input sequence in the empathy dialogue dataset into the corresponding word vector representation; S3: Input the word vector representation into the topic prediction module and the sentiment reasoning module respectively; S4: Use trainable sentiment embedding to obtain the contextual sentiment label of each word vector representation; S5: Add the word vector representation, the sentiment tag of the word vector, and the position vector representation of the word vector and input them into the dialogue generation module to obtain the topic words and sentiment reason words; S6: Calculate the given dialogue context U <m Generate a reply U under the condition m The probability p(U m |U <m ) and take the generated response corresponding to the maximum probability as the final response, calculate the loss function of the model based on the final response, input the data in the test sample into the model, adjust the parameters of the model through directional propagation, and complete the model training when the loss function value of the model is less than the set threshold; The loss function of the model is the sum of the loss functions of the topic prediction module, the sentiment reasoning module, and the dialogue generation module, where: The loss function of the topic prediction module is: The loss function of the sentiment reasoning module is: The loss function of the dialogue generation module is: Among them, L tran represents the prediction loss of the transfer topic word, K represents the number of context-related topic words; L tran (k) represents the focal loss function, ψ∈[0,1] is a weight control factor, γ≥0 2 is the regulating factor, represents the transfer weight of the subject word; τ k Predicted transfer keywords Whether it appears in the reply, when τ k =1 indicates the predicted transfer keyword Appear in reply U m In the case of τ k =0 indicates the predicted transfer keyword Not appearing in reply U m Medium; L ε represents the contextual sentiment label prediction loss, represents the predicted probability of the contextual sentiment label, represents the probability that the i-th word is associated with the sentiment reason, N i For discourse U i The number of words, L c represents the loss of sentiment reason word detection; L g represents the generation loss of the decoder, N m represents the number of words in the generated response; p(w n,m |w <n,m ,U <m ,t,C,ε) means that the generated word before time n is w <n,m , the conversation context is U <m , the predicted transfer topic word sequence is t, the emotional reason word sequence is C, and the conversation context emotional label is ε, the word w is generated at time n n,m The probability of <m Represents the conversation context, represents the transfer weight of the topic word, and C represents the selected ∈ represents the top k topic words at the time of conversation, and ε represents the sentiment label of the conversation context.
Citation Information
Patent Citations
System and method for facilitating affective-state-based artificial intelligence
CA3089830A1
Emotional chat type reply generation method with theme perception
CN111522924A
Method and device for generating emotion-containing intelligent customer service dialogue reply and electronic equipment
CN111522936A
Conversation problem generation method and system considering emotion and theme, and storage medium
CN111949761A
Context-based emotional dialogue method and system and storage medium
CN111949762A