Emotional dialogue generation method fusing knowledge and emotion reason context graph
By constructing a dialogue context map and a dialogue context map that integrates knowledge, combining emotion classification and emotional cause recognition, the shortcomings of the existing empathy dialogue generation methods in multiple rounds of dialogue information processing, speaker expression content recognition and emotional cause recognition are solved, and a more targeted and humanized empathy response generation is achieved.
Patent Information
- Application Number
- CN202510070177.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-16
- Publication Date
- 2025-04-29
- Estimated Expiration
- 2045-01-16
AI Technical Summary
The existing empathy dialogue generation methods have shortcomings in multiple rounds of dialogue information processing, speaker expression content recognition, and emotional reasons recognition, resulting in lack of coherence in the generated responses, difficulty in accurately identifying implicit emotions and intentions, and emotional reasons recognition is not accurate enough.
A method of empathy dialogue generation that integrates knowledge and emotional cause context map is proposed. By constructing a dialogue context map and a dialogue context map that integrates knowledge, combining emotion classification and emotional cause identification, a more targeted and humanized empathy response is generated.
It effectively solved the problem of contextual information integration in multiple rounds of dialogue, improved the system's ability to understand implicit expression of emotions and intentions, and the generated responses are more coherent and profound, and the ability to identify emotional causes is significantly improved.
Smart Images

Figure CN119903157A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of information processing technology, and in particular to an empathy dialogue generation method integrating knowledge and emotion cause context graph. Background Art
[0002] In the process of human-computer interaction, the understanding and expression of emotions are particularly important. As an important research direction of open-domain dialogue generation, the empathy dialogue system generates responses with appropriate content and emotions by understanding the user's speaking context and emotions, thereby generating emotional resonance with the user and improving the naturalness and interactivity of human-computer dialogue. Empathy dialogue generation technology has not only promoted the development of other generation fields of NLP in academia, but also demonstrated unique application value in practical applications, especially in education and medical fields.
[0003] Most existing methods improve the generation of empathetic responses from two directions: emotion understanding and response strategy optimization. In terms of emotion understanding, researchers have proposed different methods to accurately predict the speaker's emotional state and generate appropriate responses accordingly. Li et al. proposed a multi-resolution interactive empathetic dialogue generation model EmpDG, which creates coarse-grained and fine-grained emotion representations for input sequences by using external emotion dictionaries and emotion classifiers, and enhances the capture of contextual information and diverse emotions through hierarchical modeling. Majumder et al. adopted an emotion simulation mechanism in the MIME model to improve the empathetic expression in the generated response by imitating the interlocutor's emotions, and dynamically adjusted the intensity of the generated dialogue emotion expression in combination with the emotion weight. In terms of response strategy, Shin et al. proposed a "forward-looking emotion prediction" mechanism to predict the user's possible subsequent emotional state to model empathetic responses, emphasizing that in the process of dialogue, we should not only pay attention to the current emotion, but also look forward to potential emotional changes. The empathetic response model is optimized through multi-task learning, reinforcement learning and other methods. The model simulates the response to the user experience at the emotional level and deeply understands the user's implicit feelings at the cognitive level. Zhong et al. used an external knowledge base and Transformer model for emotion recognition. By introducing external knowledge, they improved the ability to understand complex emotional expressions, showing the important role of knowledge in emotion understanding.
[0004] Existing empathy dialogue generation methods have the following three main defects:
[0005] First, the processing of multi-round dialogue information is insufficient. Traditional methods simply connect each utterance with a fixed number of adjacent utterances to construct a graph. For example, EmpDG relies on the concatenation of dialogue histories, which has limitations in integrating the contextual information of multi-round dialogues and cannot effectively capture remote contextual information, resulting in the lack of coherence and depth in the generated responses.
[0006] Secondly, it is difficult to effectively identify the content expressed by the speaker. Current methods do not have a deep understanding of the context of the conversation, social knowledge and other information. For example, the MIME model only focuses on imitating user emotions and cannot accurately identify the content expressed by users through metaphors, hints, etc., especially when implicit emotions or complex intentions are involved.
[0007] Finally, the identification of emotional causes is not accurate enough. Existing research often focuses on using surface information of emotions. For example, the "forward-looking emotion prediction" mechanism relies too much on emotional labels and ignores the specific reasons for the generation of emotions, making the generated responses insufficient in terms of content relevance. Summary of the invention
[0008] The technical problem to be solved by the present invention is to provide an empathy dialogue generation method that integrates knowledge and emotion cause context graphs in order to address the deficiencies of the above-mentioned prior art. The emotion cause context graph is introduced to effectively solve the problem of context information integration in multiple rounds of dialogues. The background knowledge in the knowledge base is introduced in combination with the emotion cause context graph to improve the system's ability to understand implicitly expressed emotions and intentions, and ultimately comprehensively improve the depth of the dialogue system's understanding of user emotions. Through the joint modeling of emotions and causes, the system can more clearly understand the source of the user's emotions, thereby generating more targeted and humane empathy responses.
[0009] In order to solve the above technical problems, the technical solution adopted by the present invention is:
[0010] A method for generating empathy dialogue by integrating knowledge and emotion cause context graph is proposed. The empathy dialogue generation model integrating knowledge and emotion cause context graph is proposed. The model includes six modules: discourse encoding, dialogue context graph integrating knowledge, knowledge-enhanced KDCG network, emotion classification, emotion cause identification and reply generation. The specific method is as follows:
[0011] Step 1: Preprocess the dataset, including data cleaning and filtering, text preprocessing, emotion category encoding, and control mark introduction;
[0012] Step 2: Discourse encoding: Two embedding methods are used to embed the sentences in the dataset. The first method uses the pre-trained GloVe word vector to generate text embeddings. text , capturing the semantic information of the discourse, and the second way is to embed the position pos Identify the position of the utterance in the conversation and provide the position information of the conversation structure; add the two embeddings to form a comprehensive utterance embedding representation, which is input into the Transformer encoder to generate a higher-level utterance encoding representation;
[0013] Step 3: Knowledge acquisition and knowledge encoding: Acquire knowledge related to the conversation content from the external knowledge base and encode it so that it can be organically combined with the conversation context later;
[0014] Step 4: Constructing the dialogue context graph: Constructing the dialogue context graph DCG based on the dialogue and the corresponding speaker identity information, representing the dialogue as a directed acyclic graph DAG, ensuring that each discourse node only receives information from a specific previous discourse, thereby avoiding information from being transmitted back to itself or its predecessor node through any path;
[0015] Step 5: Construct a dialogue context graph KDCG that integrates knowledge, which is used to integrate the knowledge extracted from the discourse into the dialogue context graph; KDCG consists of three parts, namely, the discourse node set V, the adjacency matrix A of the discourse interaction c and the adjacency matrix A of knowledge transfer between discourses k , that is, G=(V,A c ,A k );
[0016] Step 6: Perform knowledge fusion based on the constructed dialogue context graph KDCG;
[0017] Step 7: Emotion classification: Train the emotion classifier to accurately capture and respond to the user's emotional state, based on the contextual discourse representation h of the last sentence in the conversation. last Generate emotion category distribution and select the emotion category with the maximum probability as the final predicted emotion category through the argmax function During the training process, the predicted emotion category distribution P is minimized. emo The cross entropy loss between the actual emotion label e* is used to optimize the emotion classification accuracy. The calculation process is shown in formulas (17) to (19);
[0018] P emo =softmax(W e h last +b e ) (17)
[0019]
[0020] L emo = -log(P emo (e * )) (19)
[0021] Among them, softmax(·) is the normalization function, W e and b e Represent the weight parameter matrix and bias vector respectively, L emo is the loss function for the emotion classification task;
[0022] Step 8: Emotion cause identification: The emotion cause identification problem is regarded as a sequence labeling task. The goal is to predict whether each word in the input dialogue sequence is the cause of the speaker's emotion, that is, to label each word with {0, 1} binary. A semi-supervised method is used to combine small-scale labeled data and large-scale unlabeled data for training.
[0023] Step 9: Response generation: In order to utilize the dialogue history, knowledge selection, and speaker emotional reason information, the GPT-2 model is used to generate a target response Y = [y1, y2, ...y M ], the calculation process is shown in formula (28);
[0024]
[0025] Among them, E 0:t-1 represents the embedding representation of the generated word sequence, H is the knowledge-enhanced context information representation, is the predicted emotion category, is the predicted probability distribution of the emotional reasons for the entire input sequence, y0:t-1 is the generated word sequence, P(y t |y 0:t-1 ) indicates that after generating y 0:t-1 The tth word y generated under the condition t The conditional probability distribution of .
[0026] Furthermore, the preprocessing in step 1 is specifically as follows:
[0027] Data cleaning and filtering: Comprehensively clean the data set, remove incomplete or incorrectly formatted samples, ensure data quality and consistency, and reduce training noise;
[0028] Text preprocessing: punctuation replacement, case conversion and word segmentation are performed on each set of dialogue texts to optimize the text format and standardize the input data;
[0029] Emotion category encoding: numerically encode emotion categories and map them into corresponding numerical representations for model learning and prediction;
[0030] Introduction of control tags: Control tags [UNK], [PAD], [SOS], [EOS], [USR], [SYS], and [CLS] are introduced and assigned unique index values; among them, [UNK] represents unknown vocabulary, [PAD] is used to fill the sequence length, [SOS] and [EOS] mark the beginning and end of the conversation respectively, [USR] and [SYS] distinguish between user and system speech, and [CLS] represents the comprehensive semantic representation of the entire conversation.
[0031] Furthermore, in step 2, the calculation formulas of the two embedding methods are as follows:
[0032] e text (w m )=E GloVe (w m ), m=1,2,…,T (1)
[0033] e pos (p) = pos embed (p) (2)
[0034] Among them, w m represents the mth word in the conversation, T is the number of words in the entire conversation, and E GloVe (w m ) indicates the use of GloVe word vectors for w m Perform word embedding, e text (w m ) is w m The text representation after embedding; p represents the position of the utterance in the conversation, pos embed (p) means position embedding of p, e pos (p) is the position representation of p after embedding;
[0035] The higher level discourse encoding representation H is generated 0 , the calculation process is as follows:
[0036] E=e text (w m )+e pos (p) (3)
[0037] H 0 =TRS Enc (E) (4)
[0038] Among them, E is the sum of the two embedding representations, TRS Enc (·) indicates that the Transformer encoder is used for encoding.
[0039] Furthermore, in step 3, the specific method of acquiring knowledge related to the conversation content from the external knowledge base is as follows:
[0040] We select the large-scale common sense knowledge base ATOMIC-2020 as the external knowledge source and use the BART version of the pre-trained common sense reasoning model COMET to reason about common sense knowledge based on five key common sense relations xIntent, xEffect, xReact, oEffect, and oReact to obtain common sense feature sequences. Respectively represent the i-th utterance u in the conversationi Common sense knowledge features obtained by reasoning based on specific common sense relations, where i = 1, 2, ..., N; N is the number of utterances in the entire conversation; among the five key common sense relations, xIntent represents the speaker's intention, xEffect and oEffect represent the impact on the speaker and other speakers after a speech, respectively, and xReact and oReact represent the feelings of the speaker and other speakers after the speech, respectively;
[0041] In step 3, the specific method of knowledge encoding is as follows:
[0042] Use the COMET model to perform common sense reasoning on each sentence in the input sequence; for each relationship r∈{xIntent,xEffect,oEffect,xReact,oReact}, generate 5 common sense inferences and And connect them to get the common sense sequence According to the relationship type, this knowledge is divided into cognitive state knowledge and emotional state knowledge; cognitive state knowledge is the influence of the speaker and other people's intentions and behaviors, and the relationship type used is r1∈{xIntent,xEffect,oEffect}; emotional state knowledge is the emotional response of the speaker and other people, and the relationship type used is r2∈{xReact,oReact}; two encoders are designed: cognitive encoder Enc Cog and emotion encoder Enc Aff , which is used to integrate two types of knowledge; the cognitive encoder processes cognitive state knowledge, adds a special token [CLS] at the beginning of the common sense sequence, and uses the final hidden state of [CLS] to represent the semantic information of the entire sequence The emotion encoder processes the knowledge of emotional states and uses the average of the hidden states of the vocabulary to obtain the representation of the emotion sequence. The specific calculation process is shown in formula (5) to formula (8);
[0043]
[0044] Among them, H c and H e They are the encoding representations of cognitive state knowledge sequence and emotional state knowledge sequence respectively.
[0045] Furthermore, the specific method of step 4 is:
[0046] Input the set of all discourse nodes V = {v1, v2, ..., v N} and speaker identity index function P(·), v i is the i-th utterance u iCorresponding graph nodes, i = 2, 3, ..., N; initialize the edge set Relation type set R = {0, 1}, where l indicates that the connected nodes belong to the same speaker, and 0 indicates different speakers;
[0047] Starting from the second discourse node v2, traverse each node v in turn i ;
[0048] For the current node v i , check all its predecessor nodes v τ , that is, starting from τ=i-1, gradually reduce the value of τ until τ=0; if v i and v τ The speaker of P(v τ )=P(v i ), then add an edge (τ, i, 1) to the edge set ε; if v i and v τ If the speakers are different, add an edge (τ, i, 0);
[0049] Repeat the above steps until all discourse nodes are traversed;
[0050] Finally, the complete structure of the dialogue context graph DCG G = (V, ε, R) is output.
[0051] Furthermore, in step 5, each node v in the discourse node set V i Includes an attribute e for storing the utterance representation;
[0052] Adjacency matrix A of discourse interaction c It includes two attributes: flag and type; flag stores 0 or 1 to indicate whether the edge exists; for node v i and v j , if v i to v j There is an edge between them, then A c [i, j].flag=1, otherwise A c [i, j].flag = 0; type stores the relationship type of the edge. If the node v i and v j The speaker identity p i and p j The same, then A c [i, j].type = SSI, otherwise A c [i, j].type = DSI; where SSI indicates information transmission from the same speaker, and DSI indicates information transmission from different speakers;
[0053] Adjacency matrix A of knowledge transfer between discoursesk Includes two attributes: flag and kno; matrix A k The flag attribute and matrix A c The flag attribute is the same as that of , which is used to identify the existence of the edge; kno is used to store the specific knowledge information associated with the edge, that is,
[0054] According to the speaker identity, a knowledge selection strategy is formulated to maintain the consistency of knowledge transfer and speaker interaction in the dialogue: if the speaker identity p of the current utterance is the same as that of the previous utterance i With p j If they are the same, the knowledge of the speaker’s intention, effect, and reaction, namely xIntent, xEffect, and xReact, is selected; otherwise, the knowledge of other people’s effects and reactions, namely oEffect and oReact, is selected.
[0055] Furthermore, the specific method of step 6 is:
[0056] For the target utterance node v i , calculate its relationship with the adjacent node v in the same layer j The edge weight α i,j , the calculation process is shown in formula (9);
[0057]
[0058] in, is the discourse node v i The node representation at the l-1th layer of KDCG is: is the discourse node v j The node representation at the lth layer of KDCG is: and is the learnable parameter matrix, N i Represents the discourse node v i The set of adjacent nodes of is the discourse node v i The corresponding common sense knowledge encoding representation is, Decision making based on knowledge selection strategy It is a cognitive sequence encoding representation Cognitive Sequential Encoding Representation
[0059] According to the calculated edge weight, context information and knowledge information are aggregated from adjacent nodes. The calculation process is shown in formula (10) and formula (11);
[0060]
[0061] in, is the learnable parameter matrix, con i and klg i They are the context information aggregation results and knowledge information aggregation results of the nodes respectively;
[0062] Using Node Unit GRU n and context unit GRU c To capture the current state and context information of the node, the calculation process is shown in formula (12) and formula (13);
[0063]
[0064] Among them, nod i and ctx i are the updated nodes v i The current state and context state of
[0065] Then, use the contextual knowledge unit GRU k and self-circulating knowledge unit GRU s To obtain rich information related to knowledge, the calculation process is shown in formula (14) and formula (15);
[0066]
[0067] Among them, ckg i and skg i are the updated nodes v i The contextual knowledge state and self-circular knowledge state of k i,i For node v i Knowledge and information related to oneself;
[0068] Finally, the four types of information are summed and v in each layer is updated i The discourse node representation of is shown in formula (16);
[0069]
[0070] Furthermore, in step 8, for the labeled data, the context encoding representation H of the input sequence X is obtained through the Transformer encoder, and the predicted probability distribution of the emotion cause of the entire input sequence is obtained through the feedforward neural network. The calculation process is shown in formula (20) to formula (22);
[0071] H=Enc(X) (20)
[0072]
[0073] Among them, Enc(·) represents the encoding operation using the Transformer encoder, W c and b c is a learnable parameter, represents the predicted probability of each word being the reason for the emotion, c l represents the true probability of each word being the cause of emotion, and L1 is the loss function of the emotion cause recognition task;
[0074] For unlabeled data, given an input sequence X = (x1, x2, ..., x T ) The attention weight distribution in the emotion classification task is used to select the top k words with the highest weight as the emotion reasons of the input sequence, and then automatically construct the emotion reason label for the unlabeled data. The calculation process is as follows:
[0075] Att cause =softmax(score(X)) (23)
[0076] I cause =Top k (X,Att cause ) (twenty four)
[0077]
[0078] Among them, score(·) represents the contribution score of each word to the sentiment classification, Att cause Represents the attention weight distribution of the input sequence in the emotion classification task, Top k (·) means selecting the first k words with the highest weight, I cause is the set of the first k words with the highest weight, label(·) represents the emotional reason label of each word; the subsequent calculation process is the same as (20) to formula (21);
[0079] In addition, in order to better optimize the recognition effect of emotion causes, an auxiliary loss function L2 is introduced to calculate Att cause and The inner product of is used for regularization constraint, and multiple loss terms are combined to construct the overall loss function L for the emotion cause classification task. ECE , the calculation process is as follows:
[0080]
[0081] L EcE =λ1L1+λ2L2+λ3L emo (27)
[0082] in, represents the probability distribution of each word in the sequence being the cause of the emotion, and λ1, λ2, and λ3 represent the weight parameters of each loss term.
[0083] Furthermore, in step 9, in order to improve the attention of the GPT-2 model to the emotional cause factors when generating replies, a biased self-attention mechanism based on emotional causes is introduced in the fine-tuning stage, that is, a multiplication signal based on emotional causes is introduced on the existing GPT-2 architecture without adding any additional parameters; according to the hierarchical characteristics of the deep neural network learning process, a dynamic weight adjustment strategy is designed: in the first few layers of the model, the weight of the emotional cause factors is low to ensure the rationality of the sentence structure; as the number of layers increases, the weight of the emotional cause factors gradually increases to ensure that the model can comprehensively consider emotional factors when generating replies; the calculation process is shown in formulas (29) to (31);
[0084]
[0085] BaisedAttention(Q,K,V)=BiasedWeight(Q,K)V(31)
[0086] Where Q = HW q , K = HW k , V = HW v , Q, K and V are respectively the query vector, key vector and value vector obtained by different linear transformations of the text encoding representation H, d k Represents the vector dimension, W q , W k and W v is the transformation matrix, M e is the emotional reason bias matrix, λ is a hyperparameter, I is the identity matrix, z i ∈{1, 2, ..., Z} represents the ordinal number of the self-attention layer, MaskedWeight(·) represents the attention weight distribution after masking, BiasedWeight(·) represents the self-attention weight adjusted by the bias due to emotional reasons, Normalize(·) represents the row-wise normalization function, and BaisedAttention(·) represents the final attention calculation result after the bias due to emotional reasons is introduced.
[0087] The beneficial effects of adopting the above technical solution are: the method for generating empathetic dialogue by integrating knowledge and emotion cause context graph provided by the present invention proposes a dialogue context modeling method based on directed acyclic graph, which is used to solve the problem of inappropriate processing and integration of multi-round dialogue context information: first, according to the identity and position relationship of the speaker, each utterance in the dialogue is dynamically connected with the previous utterance, and a dialogue context graph (DCG) is flexibly constructed according to the actual context of the dialogue; then, the DCG is modeled using a graph neural network, and the discourse information is aggregated multiple times in a single layer to effectively encode the remote context; finally, knowledge perception features based on speaker identity information and context information units that enhance historical context information are introduced to more intuitively simulate the information propagation between the remote dialogue background and the surrounding environment.
[0088] The present invention proposes a knowledge-integrated dialogue context graph (KDCG) to solve the problem that implicit emotional information and needs in dialogues are difficult to identify: first, by distinguishing the common sense knowledge of speakers and listeners, key information such as users' real reactions and intentions is obtained; then, the social common sense knowledge in ATOMIC-2020 is introduced, and text information beyond the scope of the common sense knowledge graph is inferred by training the COMET model; finally, knowledge of five key relationship types, xIntent, xEffect, xReact, oEffect and oReact, is selected to enrich the representation of discourse, so that the system can better understand the emotions and needs implicit in user discourse.
[0089] The present invention proposes a semi-supervised emotion cause recognition method based on sequence labeling to solve the problem that emotion causes are ignored and difficult to identify: first, emotion cause detection is regarded as a sequence labeling problem; then, small-scale labeled data and large-scale unlabeled data are combined to jointly model the dependency relationship between emotions and causes and construct a semi-supervised training model; finally, the trained model is used to predict the speaker's emotions and their word-level emotion causes, thereby improving the ability to recognize emotion causes and making the generated dialogue content more targeted and empathetic. BRIEF DESCRIPTION OF THE DRAWINGS
[0090] Figure 1 A diagram of the architecture of a knowledge-integrated emotional cause graph (KECG) model provided in an embodiment of the present invention;
[0091] Figure 2 A simplified diagram of the KECG model architecture provided by an embodiment of the present invention;
[0092] Figure 3A flowchart of the processing process of the empathy dialogue generation method that integrates knowledge and emotion cause context graph provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0093] The specific implementation of the present invention is further described in detail below in conjunction with the accompanying drawings and examples. The following examples are used to illustrate the present invention, but are not intended to limit the scope of the present invention.
[0094] This embodiment provides a method for generating empathy dialogue by integrating knowledge and emotion cause context diagram, and proposes an empathy dialogue generation model by integrating knowledge and emotion cause context diagram. Figure 1 This is the model architecture diagram of KECG in this embodiment. Figure 2 The proposed empathy dialogue generation model integrating knowledge and emotion cause context graph mainly includes six modules: discourse encoding, dialogue context graph integrating knowledge, knowledge-enhanced KDCG network, emotion classification, emotion cause identification, and reply generation. The functions of each module are as follows:
[0095] Discourse encoding: embed the input discourse sequence through pre-trained GloVe word vectors and position embeddings, and input it into the Transformer encoder to generate the contextual encoding representation of the discourse;
[0096] Knowledge-integrated dialogue context graph: Use the ATOMIC-2020 common sense knowledge base and the COMET model to obtain external common sense knowledge, regard each dialogue as a directed acyclic graph, and model it as a dialogue context graph DCG based on the constraints between discourses;
[0097] Knowledge-enhanced KDCG network: Through the knowledge adjacency matrix and a series of GRU units, it uses knowledge-aware features based on speaker identity and context information units to collect dialogue information;
[0098] Sentiment classification: Train a sentiment classifier based on the contextual representation of the last sentence of the conversation;
[0099] Emotional reason identification: Combining small-scale labeled data and large-scale unlabeled data through semi-supervised training to identify the speaker's emotional reasons;
[0100] Reply generation: Based on the obtained feature information, a biased attention mechanism based on emotion is introduced to generate empathetic replies with appropriate content.
[0101] Figure 3 This is a flowchart of the specific processing process of the empathy dialogue generation method that integrates knowledge and emotion cause context graph. The detailed steps are as follows
[0102] Step 1: Preprocess the dataset, including data cleaning and filtering, text preprocessing, emotion category encoding, and control mark introduction. The details are as follows:
[0103] Data cleaning and filtering: Comprehensively clean the data set, remove incomplete or incorrectly formatted samples, ensure data quality and consistency, and reduce training noise;
[0104] Text preprocessing: punctuation replacement, case conversion and word segmentation are performed on each set of dialogue texts to optimize the text format and standardize the input data;
[0105] Emotion category encoding: numerically encode emotion categories and map them into corresponding numerical representations for model learning and prediction;
[0106] Introduction of control tags: Control tags [UNK], [PAD], [SOS], [EOS], [USR], [SYS], and [CLS] are introduced and assigned unique index values; among them, [UNK] represents unknown vocabulary, [PAD] is used to fill the sequence length, [SOS] and [EOS] mark the beginning and end of the conversation respectively, [USR] and [SYS] distinguish between user and system speech, and [CLS] represents the comprehensive semantic representation of the entire conversation.
[0107] Step 2: Discourse encoding. Two embedding methods are used to embed the sentences in the dataset to enhance the model's ability to understand the semantics of discourse. The first method uses pre-trained GloVe word vectors to generate text embeddings. text , capturing the semantic information of the discourse; the second method embeds the position pos Identify the position of the utterance in the conversation and provide the position information of the conversation structure. The calculation process of the two methods is shown in formula (1) and formula (2) respectively.
[0108] e text (w m )=E GloVe (w m ), m=1,2,…,T (1)
[0109] e pos (p) = pos embed (p) (2)
[0110] Among them, W m represents the mth word in the conversation, T is the number of words in the entire conversation, and E GloVe (w m ) indicates the use of GloVe word vectors for w m Perform word embedding, e text (w m ) is W mThe text representation after embedding; p represents the position of the utterance in the conversation, pos embed (p) means position embedding of p, e pos (p) is the position representation after p is embedded.
[0111] The two embeddings are added together to form a comprehensive discourse embedding representation, which is then input into the Transformer encoder to generate a higher-level discourse encoding representation H 0 , the calculation process is shown in formula (3) and formula (4).
[0112] E=e text (w m )+e pos (p) (3)
[0113] H 0 =TRS Enc (E) (4)
[0114] Among them, E is the sum of the two embedding representations, TRS Enc (·) indicates that the Transformer encoder is used for encoding.
[0115] Step 3: Knowledge acquisition and knowledge encoding: In order to improve the richness of semantic information, knowledge related to the conversation content is acquired from the external knowledge base and encoded so that it can be organically combined with the conversation context later.
[0116] External common sense knowledge acquisition. ATOMIC-2020, a large-scale common sense knowledge base containing more than 300,000 events and 870,000 reasoning relationships, was selected as the external knowledge source. The BART version of the pre-trained common sense reasoning model COMET was used to reason about common sense knowledge based on five key common sense relationships xIntent, xEffect, xReact, oEffect, and oReact to obtain common sense feature sequences:
[0117]
[0118] Respectively represent the i-th utterance u in the conversation i Common sense knowledge features obtained by reasoning based on specific common sense relations, where i = 1, 2, ..., N; N is the number of utterances in the entire conversation. Among the five key common sense relations, xIntent represents the speaker's intention, xEffect and oEffect represent the impact on the speaker and other speakers after a speech, respectively, and xReact and oReact represent the feelings of the speaker and other speakers after the speech, respectively.
[0119] Knowledge encoding. Use the COMET model to perform common sense reasoning on each sentence in the input sequence. For each relationship r∈{xIntent,xEffect,oEffect,xReact,oReact}, generate 5 common sense inferences and And connect them to get the common sense sequence According to the relationship type, this knowledge is divided into cognitive state knowledge and emotional state knowledge. Cognitive state knowledge is the influence of the speaker and other people's intentions and behaviors, and the relationship type used is r1∈{xIntent,xEffect,oEffect}. Emotional state knowledge is the emotional response of the speaker and other people, and the relationship type used is r2∈{xReact,oReact}. Design two encoders: cognitive encoder Enc Cog and emotion encoder Enc Aff , which is used to integrate the two types of knowledge. The cognitive encoder processes cognitive state knowledge, adds a special token [CLS] at the beginning of the common sense sequence, and uses the final hidden state of [CLS] to represent the semantic information of the entire sequence The emotion encoder processes the knowledge of emotional states and uses the average of the hidden states of the vocabulary to obtain the representation of the emotion sequence. The specific calculation process is shown in formula (5) to formula (8);
[0120]
[0121] Among them, H c and H e They are the encoding representations of cognitive state knowledge sequence and emotional state knowledge sequence respectively.
[0122] Step 4: Constructing the dialogue context graph. Construct the dialogue context graph DCG based on the dialogue and the corresponding speaker identity information, and represent the dialogue as a directed acyclic graph DAG, ensuring that each discourse node only receives information from a specific previous discourse, thereby preventing information from being transmitted back to itself or its predecessor node through any path.
[0123] First, input the set of all discourse nodes V = {v1, v2, ..., v N} and speaker identity index function P(·), v i is the i-th utterance u i Corresponding graph nodes, i = 2, 3, ..., N; initialize the edge set The relationship type set R = {0, 1}, where 1 indicates that the connected nodes belong to the same speaker, and 0 indicates different speakers. Starting from the second utterance node v2, traverse each node v in turn. i For the current node v i , check all its predecessor nodes vτ , that is, starting from τ=i-1, gradually reduce the value of τ until τ=0; if v i and v τ The speaker of P(v τ )=P(v i ), then add an edge (τ, i, 1) to the edge set ε; if v i and v τ If the speaker is different, add an edge (τ, i, 0). Repeat the above steps until all speech nodes are traversed. Finally, output the complete structure of the dialogue context graph DCG G = (V, ε, R).
[0124] Step 5: Constructing a dialogue context graph that integrates knowledge. In order to improve the model's understanding ability, a dialogue context graph KDCG that integrates knowledge is constructed to integrate the knowledge extracted from the discourse into the dialogue context graph. KDCG consists of three parts, namely, the discourse node set V, the adjacency matrix A of the discourse interaction, and the c and the adjacency matrix A of knowledge transfer between discourses k , that is, G=(V,A c , A k ).
[0125] Each node v in the discourse node set V i Includes an attribute e for storing the utterance representation.
[0126] Adjacency matrix A of discourse interaction c It includes two attributes: flag and type. Flag stores 0 or 1 to indicate whether the edge exists. i and v j , if v i to v j There is an edge between them, then A c [i, j].flag=1, otherwise A c [i, j].flag = 0. type stores the relationship type of the edge. If the node v i and v j The speaker identity p i and p j The same, then A c [i, j].type = SSI, otherwise A c [i, j].type = DSI. SSI indicates the same speaker information transmission, and DSI indicates the different speakers information transmission.
[0127] Adjacency matrix A of knowledge transfer between discourses k Includes two attributes: flag and kno. Matrix A k The flag attribute and matrix Ac The flag attribute is the same as that of , which is used to identify the existence of the edge. kno is used to store the specific knowledge information associated with the edge, that is,
[0128] Knowledge selection strategy. In order to maintain the consistency of knowledge transfer and speaker interaction in the dialogue, a knowledge selection strategy is formulated according to the speaker identity. If the speaker identity of the current utterance is the same as that of the previous utterance, i With p j If they are the same, the knowledge of the speaker’s intention, effect, and reaction, namely xIntent, xEffect, and xReact, is selected; otherwise, the knowledge of other people’s effects and reactions, namely oEffect and oReact, is selected.
[0129] Step 6: Perform knowledge fusion based on the constructed dialogue context graph KDCG.
[0130] For the target utterance node v i , calculate its relationship with the adjacent node v in the same layer j The edge weight α i,j , the calculation process is shown in formula (9).
[0131]
[0132] in, is the discourse node v i The node representation at the l-1th layer of KDCG is: is the discourse node v j The node representation at the lth layer of KDCG is: and is the learnable parameter matrix, N i Represents the discourse node v i The set of adjacent nodes of is the discourse node v i The corresponding common sense knowledge encoding representation is, Decision making based on knowledge selection strategy It is a cognitive sequence encoding representation Cognitive Sequential Encoding Representation
[0133] According to the calculated edge weights, context information and knowledge information are aggregated from adjacent nodes. The calculation process is shown in formula (10) and formula (11).
[0134]
[0135] in, is the learnable parameter matrix, con i and klg iThey are the context information aggregation results and knowledge information aggregation results of the nodes respectively.
[0136] In addition, using the node unit GRU n and context unit GRU c To capture the current state and context information of the node, the calculation process is shown in formula (12) and formula (13).
[0137]
[0138] Among them, nod i and ctx i are the updated nodes v i The current state and context state of the .
[0139] Then, use the contextual knowledge unit GRU k and self-circulating knowledge unit GRU s To obtain rich information related to knowledge, the calculation process is shown in formula (14) and formula (15).
[0140]
[0141] Among them, ckg i and skg i are the updated nodes v i The contextual knowledge state and self-circular knowledge state of k i,i For node v i Knowledge and information related to oneself.
[0142] Finally, the four types of information are summed and v in each layer is updated i The discourse node representation of is shown in formula (16).
[0143]
[0144] Step 7: Emotion classification. Train the emotion classifier to accurately capture and respond to the user's emotional state, based on the contextual discourse representation h of the last sentence in the conversation. last Generate emotion category distribution and select the emotion category with the maximum probability as the final predicted emotion category through the argmax function During the training process, the predicted emotion category distribution P is minimized. emo and the actual emotion label e * The cross entropy loss between is used to optimize the emotion classification accuracy. The calculation process is shown in formula (17) to formula (19);
[0145] P emo =softmax(W e hlast +b e ) (17)
[0146]
[0147] L emo = -log(P emo (e * )) (19)
[0148] Among them, softmax(·) is the normalization function, W e and b e Represent the weight parameter matrix and bias vector respectively, L emo is the loss function for the emotion classification task.
[0149] Step 8: Emotional cause identification. The emotion cause identification problem is regarded as a sequence labeling task. The goal is to predict whether each word in the input dialogue sequence is the cause of the speaker's emotion, that is, to label each word with {0, 1} binary. In order to cope with the problem of data scarcity, a semi-supervised method is used to combine small-scale labeled data and large-scale unlabeled data for training.
[0150] For labeled data, the context encoding representation H of the input sequence X is obtained through the Transformer encoder, and the predicted probability distribution of the emotion cause of the entire input sequence is obtained through the feedforward neural network. The calculation process is shown in formula (20) to formula (22);
[0151] H=Enc(X) (20)
[0152]
[0153] Among them, Enc(·) represents the encoding operation using the Transformer encoder, W c and b c is a learnable parameter, represents the predicted probability of each word being the reason for the emotion, c l represents the true probability of each word being the cause of emotion, and L1 is the loss function of the emotion cause recognition task;
[0154] For unlabeled data, given an input sequence X = (x1, x2, ..., x T ) The attention weight distribution in the emotion classification task is used to select the top k words with the highest weight as the emotion reasons of the input sequence, and then automatically construct the emotion reason label for the unlabeled data. The calculation process is as follows:
[0155] Att cause=softmax(score(X)) (23)
[0156] I cause =Top k (X,Att cause ) (twenty four)
[0157]
[0158] Among them, score(·) represents the contribution score of each word to the sentiment classification, Att cause Represents the attention weight distribution of the input sequence in the emotion classification task, Top k (·) means selecting the first k words with the highest weight, I cause is the set of the top k words with the highest weight, and label(·) represents the emotion reason label of each word. In this way, the emotion reason label is automatically constructed for the unlabeled data, and the subsequent calculation process is the same as (20) to (21).
[0159] In addition, in order to better optimize the recognition effect of emotion causes, an auxiliary loss function L2 is introduced to calculate Att cause and The inner product of is used for regularization constraint, and multiple loss terms are combined to construct the overall loss function L for the emotion cause classification task. ECE , the calculation process is as follows:
[0160]
[0161] L ECE =λ1L1+λ2L2+λ3L emo (27)
[0162] in, represents the probability distribution of each word in the sequence being the cause of the emotion, and λ1, λ2, and λ3 represent the weight parameters of each loss term.
[0163] Step 9: Response generation: In order to utilize the dialogue history, knowledge selection, and speaker emotional reason information, the GPT-2 model is used to generate a target response Y = [y1, y2, ...y M ], the calculation process is shown in formula (28);
[0164]
[0165] Among them, E 0:t-1 represents the embedding representation of the generated word sequence, H is the knowledge-enhanced context information representation, is the predicted emotion category, Predict the probability distribution of sentiment reasons for the entire input sequence, y0:t-1 is the generated word sequence, P(y t |y 0:t-1 ) indicates that after generating y 0:t-1 The tth word y generated under the condition t The conditional probability distribution of .
[0166] In order to improve the GPT-2 model's attention to emotional factors when generating replies, a biased self-attention mechanism based on emotional factors is introduced in the fine-tuning stage, that is, a multiplication signal based on emotional factors is introduced on the existing GPT-2 architecture without adding any additional parameters. According to the hierarchical characteristics of the deep neural network learning process, a dynamic weight adjustment strategy is designed: in the first few layers of the model, the weight of emotional factors is low to ensure the rationality of the sentence structure; as the number of layers increases, the weight of emotional factors gradually increases to ensure that the model can comprehensively consider emotional factors when generating replies. The calculation process is shown in formulas (29) to (31);
[0167]
[0168] BaisedAttention(Q,K,V)=BiasedWeight(Q,K)V (31)
[0169] Where Q = HW q , K = HW k , V = HW v , Q, K and V are respectively the query vector, key vector and value vector obtained by different linear transformations of the text encoding representation H, d k Represents the vector dimension, W q , W k and W v is the transformation matrix, M e is the emotional reason bias matrix, λ is a hyperparameter, I is the identity matrix, z i ∈{1,2,...,Z} represents the ordinal number of the self-attention layer, MaskedWeight(·) represents the attention weight distribution after masking, BiasedWeight(·) represents the self-attention weight adjusted by the emotion-related bias, Normalize(·) represents the row-wise normalization function, and BaisedAttention(·) represents the final attention calculation result after the emotion-related bias is introduced.
[0170] This embodiment experiments on data from the empathy dialogue generation benchmark dataset ED and the word-level emotion cause annotation dataset EmoCause. The ED dataset contains 32 specific emotions and empathy dialogue data in the emotional scenarios. The EmoCause dataset is constructed based on the validation set and test set of the ED dataset, and contains word-level emotion cause annotations. Comparative experiments on the emotion cause identification task and the empathy response generation task are conducted on the EmoCause and ED datasets with representative models, and the experimental results of the comparative models are compared with the KECG model proposed in the present invention.
[0171] In the emotion cause recognition task, in order to be consistent with the evaluation indicators of the comparison model, the experimental evaluation indicators are uniformly used: Acc, Top-1 Recall, Top-3 Recall and Top-5 Recall. The comparative experimental results of emotion cause recognition are shown in Table 1.
[0172] Table 1 Comparative experimental results of emotion cause recognition
[0173] Models Acc Top-1 Recall Top-3 Recall Top-5 Recall EmpDG 0.31 0.134 0.362 0.493 Roberta_Att 0.58 0.148 0.399 0.596 GEE 0.40 0.173 0.481 0.684 KECG (Ours) 0.53 0.247 0.532 0.735
[0174] The experimental results show that the KECG model of this embodiment performs well in all evaluation indicators, especially in the Top-nRecall (n=1,3,5) indicator, which is significantly improved compared with other methods. Compared with Roberta Att, although it is slightly inferior in accuracy, it has significantly improved in recall. These results show that the semi-supervised training method used by the KECG model of this embodiment can effectively narrow the gap between emotion recognition and emotion cause recognition, and enhance the model's ability to recognize emotion causes.
[0175] In the empathy response generation task, in order to be consistent with the evaluation indicators of the comparison model, the automatic evaluation indicators of the experiment uniformly use PPL, Dist-1, Dist-2 and Acc, and the manual evaluation indicators uniformly use Fluency, Relevance and Relevance, and A / B testing is performed at the same time. The automatic evaluation, manual evaluation and A / B test results of empathy response generation are shown in Table 2, Table 3 and Table 4 respectively.
[0176] Table 2 Automatic evaluation results of empathy response generation
[0177]
[0178]
[0179] Table 3 Results of manual evaluation of empathy response generation
[0180] Models Fluency Relevance Empathy κ MoEL 4.19 2.86 3.22 0.32 MIME 4.30 3.24 3.50 0.28 EmpDG 4.27 3.21 3.42 0.35 KEMP 4.34 3.13 3.31 0.31 CEM 4.44 3.10 3.30 0.32 KCG 4.32 3.30 3.67 0.29 KECG (Ours) 4.57 3.65 3.72 0.43
[0181] Table 4 Results of A / B test on empathy generation
[0182] Models Win Lose Tie κ KECG vs MoEL 43.9% 20.0% 36.1% 0.33 KECG vs MIME 42.2% 25.1% 32.7% 0.37 KECG vs EmpDG 43.0% 32.2% 24.8% 0.35 KECG vs KEMP 39.3% 32.5% 28.2% 0.38 KECG vs CEM 38.5% 28.3% 23.2% 0.44 KECG vs KCG 36.0% 26.3% 38.7% 0.39
[0183] In the automatic evaluation, the experimental results show that the KECG model of this embodiment outperforms other models in the PPL index. This improvement is due to the integration of emotional reasons by the model, which enhances the understanding of the speaker's expression and improves the overall quality of the generated response. In terms of diversity, the KECG model of this embodiment is lower than other models in the Dist-1 index. This may be because the introduction of emotional reasons makes the response more focused on emotional factors, thereby reducing the innovation of the conversation to a certain extent. Despite this, the performance of the KECG of this embodiment on the Dist-2 index is better than that of other models, indicating that the model can maintain language diversity while maintaining emotional coherence. This may be because the model can still select vocabulary from the conversation history and retrieved knowledge entities. In terms of accuracy, the KECG model of this embodiment also shows excellent performance. By introducing emotional reason words, the model can more accurately capture the subtle differences in emotional state and conversation, thereby more accurately reflecting the speaker's emotions and intentions when generating responses. This sensitivity to emotional reasons significantly improves the accuracy of the model in understanding and generating empathetic responses, effectively enhancing the overall performance of the model.
[0184] In the manual evaluation, the experimental results show that the KECG model of this embodiment has obtained high scores in all three dimensions of fluency, relevance and empathy. Especially in empathy, its score is significantly higher than other models. This result shows that the introduction of a biased self-attention mechanism based on emotional reasons is the key to improving performance. This mechanism enables the model to pay more attention to emotion-related words when generating replies, thereby generating more emotionally consistent conversations. In addition, the high score of the score consistency coefficient also shows that the evaluators' positive evaluation of the KECG model of this embodiment is highly consistent.
[0185] In the A / B test, the experimental results show that the KECG model of this embodiment has achieved a higher winning rate in comparison with other models. In particular, in comparison with the MoEL, MIME and EmpDG models, the winning rate of the KECG model of this embodiment exceeded 40%, and reached a high winning rate of 43.9% in comparison with the MoEL model. This result further proves the advantage of the KECG model of this embodiment in generating empathetic replies, especially in meeting user expectations and resonating with them.
[0186] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the above embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the above embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope defined by the claims of the present invention.
Claims
1. A method for generating empathy dialogue by integrating knowledge and emotional cause context graph, characterized by: This paper proposes an empathy dialogue generation model that integrates knowledge and emotion cause context graph. The model includes six modules: discourse encoding, dialogue context graph integrated with knowledge, knowledge-enhanced KDCG network, emotion classification, emotion cause identification, and response generation. The specific method is as follows: Step 1: Preprocess the dataset, including data cleaning and filtering, text preprocessing, emotion category encoding, and control mark introduction; Step 2: Discourse encoding; Two embedding methods are used to embed the sentences in the dataset. The first method uses the pre-trained GloVe word vector to generate text embeddings. text , capturing the semantic information of the discourse, and the second way is to embed the position pos Identify the position of the utterance in the conversation and provide the position information of the conversation structure; add the two embeddings to form a comprehensive utterance embedding representation, which is input into the Transformer encoder to generate a higher-level utterance encoding representation; Step 3: Knowledge acquisition and knowledge encoding: Acquire knowledge related to the conversation content from the external knowledge base and encode it so that it can be organically combined with the conversation context later; Step 4: Constructing the dialogue context graph: Constructing the dialogue context graph DCG based on the dialogue and the corresponding speaker identity information, representing the dialogue as a directed acyclic graph DAG, ensuring that each discourse node only receives information from a specific previous discourse, thereby avoiding information from being transmitted back to itself or its predecessor node through any path; Step 5: Construct a dialogue context graph KDCG that integrates knowledge, which is used to integrate the knowledge extracted from the discourse into the dialogue context graph; KDCG consists of three parts, namely, the discourse node set V, the adjacency matrix A of the discourse interaction c and the adjacency matrix A of knowledge transfer between discourses k , that is, G=(V,A c , A k ); Step 6: Perform knowledge fusion based on the constructed dialogue context graph KDCG; Step 7: Emotion classification; Train the emotion classifier to accurately capture and respond to the user’s emotional state, based on the contextual discourse representation h of the last sentence in the conversation last Generate emotion category distribution and select the emotion category with the maximum probability as the final predicted emotion category through the argmax function During the training process, the predicted emotion category distribution P is minimized. emo The cross entropy loss between the actual emotion label e* is used to optimize the emotion classification accuracy. The calculation process is shown in formulas (17) to (19); P emo =softmax(W e h last +b e ) (17) L emo =-log(P emo (and * )) (19) Among them, softmax(·) is the normalization function, W e and b e Represent the weight parameter matrix and bias vector respectively, L emo is the loss function for the emotion classification task; Step 8: Emotion cause identification: The emotion cause identification problem is regarded as a sequence labeling task. The goal is to predict whether each word in the input dialogue sequence is the cause of the speaker's emotion, that is, to label each word with {0, 1} binary. A semi-supervised method is used to combine small-scale labeled data and large-scale unlabeled data for training. Step 9: Response generation: In order to utilize the dialogue history, knowledge selection, and speaker emotional reason information, the GPT-2 model is used to generate a target response Y = [y1, y2, ...y M ], the calculation process is shown in formula (28); Among them, E 0:t-1 represents the embedding representation of the generated word sequence, H is the knowledge-enhanced context information representation, is the predicted emotion category, Predict the probability distribution of sentiment reasons for the entire input sequence, y 0:t-1 is the generated word sequence, P(y t |y 0:t-1 ) indicates that after generating y 0:t-1 The tth word y generated under the condition t The conditional probability distribution of .
2. The method for generating empathy dialogue by integrating knowledge and emotional cause context graph according to claim 1, characterized in that: The pre-processing in step 1 is as follows: Data cleaning and filtering: Comprehensively clean the data set, remove incomplete or incorrectly formatted samples, ensure data quality and consistency, and reduce training noise; Text preprocessing: punctuation replacement, case conversion and word segmentation are performed on each set of dialogue texts to optimize the text format and standardize the input data; Emotion category encoding: numerically encode emotion categories and map them into corresponding numerical representations for model learning and prediction; Introduction of control tags: Control tags [UNK], [PAD], [SOS], [EOS], [USR], [SYS], and [CLS] are introduced and assigned unique index values; among them, [UNK] represents unknown vocabulary, [PAD] is used to fill the sequence length, [SOS] and [EOS] mark the beginning and end of the conversation respectively, [USR] and [SYS] distinguish between user and system speech, and [CLS] represents the comprehensive semantic representation of the entire conversation.
3. The method for generating empathy dialogue by integrating knowledge and emotional cause context diagram according to claim 1, characterized in that: In step 2, the calculation formulas of the two embedding methods are as follows: have been text (w m )=E GloVe (w m ),m=1,2,…,T (1) and pos (p)=pos embed (p) (2) Among them, w m represents the mth word in the conversation, T is the number of words in the entire conversation, and E GloVe (w m ) indicates the use of GloVe word vectors for w m Perform word embedding, text (w m ) is w m The text representation after embedding; p represents the position of the utterance in the conversation, pos embed (p) means position embedding of p, e pos (p) is the position representation of p after embedding; The higher level discourse encoding representation H is generated 0 , the calculation process is as follows: E=e text (w m )+e pos (p) (3) H 0 =TRS Enc (E) (4) Among them, E is the sum of the two embedding representations, TRS Enc (·) indicates that the Transformer encoder is used for encoding.
4. The method for generating empathy dialogue by integrating knowledge and emotional cause context diagram according to claim 1, characterized in that: In step 3, the specific method of acquiring knowledge related to the conversation content from the external knowledge base is as follows: We select the large-scale common sense knowledge base ATOMIC-2020 as the external knowledge source and use the BART version of the pre-trained common sense reasoning model COMET to reason about common sense knowledge based on five key common sense relations xIntent, xEffect, xReact, oEffect, and oReact to obtain common sense feature sequences. Respectively represent the i-th utterance u in the conversation i Common sense knowledge features obtained by reasoning based on specific common sense relations, where i = 1, 2, ..., N; N is the number of utterances in the entire conversation; among the five key common sense relations, xIntent represents the speaker's intention, xEffect and oEffect represent the impact on the speaker and other speakers after a speech, respectively, and xReact and oReact represent the feelings of the speaker and other speakers after the speech, respectively; In step 3, the specific method of knowledge encoding is as follows: Use the COMET model to perform common sense reasoning on each sentence in the input sequence; for each relationship r∈{xIntent,xEffect,oEffect,xReact,oReact}, generate 5 common sense inferences and And connect them to get the common sense sequence According to the relationship type, this knowledge is divided into cognitive state knowledge and emotional state knowledge; cognitive state knowledge is the influence of the speaker and other people's intentions and behaviors, and the relationship type used is r1∈{xIntent,xEffect,oEffect}; emotional state knowledge is the emotional response of the speaker and other people, and the relationship type used is r2∈{xReact,oReact}; two encoders are designed: cognitive encoder Enc Cog and emotion encoder Enc Aff , which is used to integrate two types of knowledge; the cognitive encoder processes cognitive state knowledge, adds a special token [CLS] at the beginning of the common sense sequence, and uses the final hidden state of [CLS] to represent the semantic information of the entire sequence The emotion encoder processes the knowledge of emotional states and uses the average of the hidden states of the vocabulary to obtain the representation of the emotion sequence. The specific calculation process is shown in formula (5) to formula (8); Among them, H c and H e They are the encoding representations of cognitive state knowledge sequence and emotional state knowledge sequence respectively.
5. The method for generating empathy dialogue by integrating knowledge and emotional cause context diagram according to claim 4, characterized in that: The specific method of step 4 is: Input the set of all discourse nodes V = {v1, v2, ..., v N } and speaker identity index function P(·), v i is the i-th utterance u i Corresponding graph nodes, i = 2, 3, ..., N; initialize the edge set Relation type set R = {0, 1}, where 1 indicates that the connected nodes belong to the same speaker, and 0 indicates different speakers; Starting from the second discourse node v2, traverse each node v in turn i ; For the current node v i , check all its predecessor nodes v τ , that is, starting from τ=i-1, gradually reduce the value of τ until τ=0; if v i and v τ The speaker of P(v τ )=P(v i ), then add an edge (τ, i, 1) to the edge set ε; if v i and v τ If the speakers are different, add an edge (τ, i, 0); Repeat the above steps until all discourse nodes are traversed; Finally, the complete structure of the dialogue context graph DCG G = (V, ε, R) is output.
6. The method for generating empathy dialogue by integrating knowledge and emotional cause context diagram according to claim 5, characterized in that: In step 5, each node v in the discourse node set V i Includes an attribute e for storing the utterance representation; Adjacency matrix A of discourse interaction c It includes two attributes: flag and type; flag stores 0 or 1 to indicate whether the edge exists; for node v i and v j , if v i to v j There is an edge between them, then A c [i, j].flag=1, otherwise A c [i, j].flag = 0; type stores the relationship type of the edge. If the node v i and v j The speaker identity p i and p j The same, then A c [i, j].type = SSI, otherwise A c [i, j].type = DSI; where SSI indicates information transmission from the same speaker, and DSI indicates information transmission from different speakers; Adjacency matrix A of knowledge transfer between discourses k Includes two attributes: flag and kno; matrix A k The flag attribute of the matrix A c The flag attribute is the same as that of , which is used to identify the existence of the edge; kno is used to store the specific knowledge information associated with the edge, that is, According to the speaker identity, a knowledge selection strategy is formulated to maintain the consistency of knowledge transfer and speaker interaction in the dialogue: if the speaker identity p of the current utterance is the same as that of the previous utterance i With p j If they are the same, the knowledge of the speaker’s intention, effect, and reaction, namely xIntent, xEffect, and xReact, is selected; otherwise, the knowledge of other people’s effects and reactions, namely oEffect and oReact, is selected.
7. The method for generating empathy dialogue by integrating knowledge and emotional cause context diagram according to claim 6, characterized in that: The specific method of step 6 is: For the target utterance node v i , calculate its relationship with the adjacent node v in the same layer j The edge weight α i,j , the calculation process is shown in formula (9); in, is the discourse node v i The node representation at the l-1th layer of KDCG is: is the discourse node v j The node representation at the lth layer of KDCG is: and is the learnable parameter matrix, N i Represents the discourse node v i The set of adjacent nodes of is the discourse node v i The corresponding common sense knowledge encoding representation is, Decision making based on knowledge selection strategy It is a cognitive sequence encoding representation Cognitive Sequential Encoding Representation According to the calculated edge weight, context information and knowledge information are aggregated from adjacent nodes. The calculation process is shown in formula (10) and formula (11); in, is the learnable parameter matrix, con i and klg i They are the context information aggregation results and knowledge information aggregation results of the nodes respectively; Using Node Unit GRU n and context unit GRU c To capture the current state and context information of the node, the calculation process is shown in formula (12) and formula (13); Among them, nod i and ctx i are the updated nodes v i The current state and context state of Then, use the contextual knowledge unit GRU k and self-circulating knowledge unit GRU s To obtain rich information related to knowledge, the calculation process is shown in formula (14) and formula (15); Among them, ckg i and skg i are the updated nodes v i The contextual knowledge state and self-circular knowledge state of k i,i For node v i Knowledge and information related to oneself; Finally, the four types of information are summed and v in each layer is updated i The discourse node representation of is shown in formula (16); 8. The method for generating empathy dialogue by integrating knowledge and emotional cause context diagram according to claim 7, characterized in that: In step 8, for the labeled data, the context encoding representation H of the input sequence X is obtained through the Transformer encoder, and the predicted probability distribution of the emotion cause of the entire input sequence is obtained through the feedforward neural network. The calculation process is shown in formula (20) to formula (22); H=Enc(X) (20) Among them, Enc(·) represents the encoding operation using the Transformer encoder, W c and b c is a learnable parameter, represents the predicted probability of each word being the reason for the emotion, c l represents the true probability of each word being the cause of emotion, and L1 is the loss function of the emotion cause recognition task; For unlabeled data, given an input sequence x = (x1, x2, ..., x T ) The attention weight distribution in the emotion classification task is used to select the top k words with the highest weight as the emotion reasons of the input sequence, and then automatically construct the emotion reason labels for the unlabeled data. The calculation process is as follows: To cause =softmax(score(X)) (23) IN cause =Top k (X, That cause ) (24) Among them, score(·) represents the contribution score of each word to the sentiment classification, Att cause Represents the attention weight distribution of the input sequence in the emotion classification task, Top k (·) means selecting the first k words with the highest weight, I cause is the set of the first k words with the highest weight, label(·) represents the emotional reason label of each word; the subsequent calculation process is the same as (20) to formula (21); In addition, in order to better optimize the recognition effect of emotion causes, an auxiliary loss function L2 is introduced to calculate Att cause and The inner product of is used for regularization constraint, and multiple loss terms are combined to construct the overall loss function L for the emotion cause classification task. ECE , the calculation process is as follows: L ECE =λ1L1+λ2L2+λ3L emo (27) in, represents the probability distribution of each word in the sequence being the cause of the emotion, and λ1, λ2, and λ3 represent the weight parameters of each loss term.
9. The method for generating empathy dialogue by integrating knowledge and emotional cause context diagram according to claim 8, characterized in that: In step 9, in order to improve the GPT-2 model's attention to emotional reasons when generating replies, a biased self-attention mechanism based on emotional reasons is introduced in the fine-tuning stage, that is, a multiplication signal based on emotional reasons is introduced on the existing GPT-2 architecture without adding any additional parameters; according to the hierarchical characteristics of the deep neural network learning process, a dynamic weight adjustment strategy is designed: in the first few layers of the model, the weight of the emotional reason factor is low to ensure the rationality of the sentence structure; As the number of layers increases, the weight of the emotional cause factor gradually increases to ensure that the model can comprehensively consider emotional factors when generating responses; the calculation process is shown in formulas (29) to (31); BaisedAttention(Q,K,V)=BiasedWeight(Q,K)V(31) Where Q = HW q , K = HW k , V = HW v , Q, K and y are respectively the query vector, key vector and value vector obtained by different linear transformations of the text encoding representation H, d k Represents the vector dimension, W q , W k and W v is the transformation matrix, M e is the emotional reason bias matrix, λ is a hyperparameter, I is the identity matrix, z i ∈{1, 2, ..., Z} represents the ordinal number of the self-attention layer, MaskedWeight(·) represents the attention weight distribution after masking, BiasedWeight(·) represents the self-attention weight adjusted by the bias due to emotional reasons, Normalize(·) represents the row-wise normalization function, and BaisedAttention(·) represents the final attention calculation result after the bias due to emotional reasons is introduced.
Citation Information
Patent Citations
Power grid customer service co-emotional dialogue reply generation method based on emotion subtle perception
CN117591648A
Emotion-sharing dialogue generation method based on context awareness and emotion reasoning
CN117892736A
Method and system for generating common-situation dialogue with attention mechanism and external knowledge base, and electronic equipment
CN118261249A
BERT-based machine-learning tool for predicting emotional response to text
US20220129621A1
Cited By
Psychotherapy-healing-oriented large model dialogue agent
CN120353899A
Smart home multi-mode dialogue method and device, equipment and medium
CN120822527A
Emotional dialogue generation method and system based on large model
CN120851041A
Emotion support dialogue system based on external knowledge and personalized features
CN121581211A
Emotion recognition method, system and device for mental health of children and storage medium
CN121790020A