A co-emotion dialogue generation method fusing knowledge and emotional reason context graphs
By constructing a directed acyclic graph dialogue context graph and a knowledge augmentation network, combined with an external knowledge base and an emotion classifier, the problems of insufficient information processing in multi-turn dialogues and inaccurate identification of emotion causes are solved, thereby achieving a deeper understanding of user emotions and improved empathetic response in the dialogue system.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-16
- Publication Date
- 2026-04-07
AI Technical Summary
Existing methods for generating empathic dialogues are insufficient in processing information during multi-turn dialogues, making it difficult to identify the content implied by the speaker. Furthermore, the identification of emotional causes is not accurate enough, resulting in a lack of coherence and content relevance in the generated responses.
This paper adopts an empathic dialogue generation method that integrates knowledge and emotional causal context graphs. By constructing a directed acyclic graph dialogue context graph (DCG) and a knowledge-enhanced KDCG network, combined with an external knowledge base and an emotion classifier, it identifies user emotions and their causes, and generates more targeted and humanized responses.
By effectively integrating contextual information from multiple rounds of dialogue, the system enhances its understanding of user emotions and the coherence of responses, accurately identifies implicit emotions and intentions, and generates more targeted and empathetic dialogue content.
Smart Images

Figure CN119903157B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of information processing technology, and in particular to a method for generating empathic dialogues that integrates knowledge and emotional cause context graphs. Background Technology
[0002] In human-computer interaction, the understanding and expression of emotions are crucial. Empathic dialogue systems, as an important research direction in open-domain dialogue generation, generate responses with appropriate content and emotion by understanding the user's speaking context and emotions, thereby resonating with the user's emotions and enhancing the naturalness and interactivity of human-computer dialogue. Empathic dialogue generation technology has not only promoted the development of other generative fields in NLP in academia, but has also demonstrated unique application value in practical applications, especially in education and healthcare.
[0003] Existing methods mostly improve empathic response generation from two directions: emotion understanding and response strategy optimization. Regarding emotion understanding, researchers have proposed different approaches to accurately predict the speaker's emotional state and generate appropriate responses accordingly. Li et al. proposed a multi-resolution interactive empathic dialogue generation model, EmpDG, which creates coarse-grained and fine-grained emotion representations for the input sequence using an external emotion dictionary and emotion classifier, and enhances the capture of contextual information and diverse emotions through hierarchical modeling. Majumder et al. employed an emotion simulation mechanism in their MIME model, improving empathic expression in generated responses by mimicking the speaker's emotions, while dynamically adjusting the intensity of generated dialogue emotion expression using emotion weights. Regarding response strategies, Shin et al. proposed a "prospective emotion prediction" mechanism, predicting the user's possible subsequent emotional states to model empathic responses, emphasizing that during dialogue, it is necessary not only to focus on current emotions but also to anticipate potential emotional changes. They optimized the empathic response model through multi-task learning and reinforcement learning methods. This model simulates user experience responses 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 a Transformer model for emotion recognition. By introducing external knowledge, they improved the ability to understand complex emotional expressions, demonstrating the important role of knowledge in emotion understanding.
[0004] Existing methods for generating empathic dialogues mainly suffer from the following three shortcomings:
[0005] First, there is insufficient information processing in multi-turn dialogues. Traditional methods simply connect each utterance with a fixed number of neighboring utterances to construct a graph, such as EmpDG, which relies on piecing together dialogue history. This approach has limitations in integrating contextual information from multi-turn dialogues, failing to effectively capture remote contextual information, resulting in generated responses that lack coherence and depth.
[0006] Secondly, it is difficult to effectively identify the content expressed by the speaker. Current methods lack a deep understanding of the context and social knowledge of the dialogue. For example, the MIME model only focuses on mimicking user emotions and cannot accurately identify the content expressed by users through metaphors, hints, etc., especially when it involves implicit emotions or complex intentions, its performance is poor.
[0007] Finally, the identification of emotional causes is not precise enough. Existing research often focuses on using surface-level information about emotions. For example, the "prospective sentiment prediction" mechanism relies too much on emotion labels and ignores the specific reasons for the emotion, resulting in insufficient content relevance in the generated responses. Summary of the Invention
[0008] The technical problem this invention aims to solve is to address the shortcomings of existing technologies by providing an empathic dialogue generation method that integrates knowledge and emotional cause context graphs. This method effectively solves the problem of integrating contextual information in multi-turn dialogues by introducing emotional cause context graphs. Furthermore, by incorporating background knowledge from a knowledge base into the emotional cause context graphs, it enhances the system's ability to understand implicit emotions and intentions, ultimately comprehensively improving the dialogue system's depth of 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 humanized empathic responses.
[0009] To solve the above-mentioned technical problems, the technical solution adopted by the present invention is as follows:
[0010] An empathic dialogue generation method integrating knowledge and emotional cause context graphs is proposed. The model comprises six modules: discourse encoding, knowledge-integrated dialogue context graphs, knowledge-enhanced KDCG network, emotion classification, emotion cause identification, and response generation. The specific method is as follows:
[0011] Step 1: Preprocess the dataset, including data cleaning and filtering, text preprocessing, sentiment category encoding, and introduction of control tags;
[0012] Step 2: Speech Encoding; Two embedding methods are used to embed words into the sentences in the dataset. The first method uses pre-trained GloVe word vectors to generate text embeddings. text The first method captures the semantic information of the discourse; the second method uses positional embedding. pos The two embeddings are used to identify the position of the utterance in the dialogue and provide positional information of the dialogue structure. The two embeddings are added together to form a comprehensive utterance embedding representation, which is then input into the Transformer encoder to generate a higher-level utterance encoding representation.
[0013] Step 3: Knowledge Acquisition and Encoding; Acquire knowledge related to the dialogue content from an external knowledge base and encode it so that it can be organically combined with the dialogue context later;
[0014] Step 4: Dialogue Context Graph Construction; Construct a 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 utterance node only receives information from a specific previous utterance, thereby preventing information from being transmitted back to itself or its predecessor node through any path;
[0015] Step 5: Construct a Knowledge-integrated Dialogue Context Graph (KDCG) to integrate the knowledge extracted from the discourse into the dialogue context graph; the KDCG consists of three parts: the set of discourse nodes V, the adjacency matrix of discourse interactions A, and so on. c Adjacency matrix A for 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 an emotion classifier to accurately capture and respond to the user's emotional state, based on the contextual representation of the last sentence in the dialogue. last The system generates an emotion category distribution and uses the argmax function to select the emotion category with the highest probability as the final predicted emotion category. During training, the predicted emotion category distribution P is minimized. emo The cross-entropy loss between the actual emotion label e* and the actual emotion label is used to optimize the emotion classification accuracy. The calculation process is shown in Equations (17) to (19).
[0018] P emo =softmax(W e h last +b e (17)
[0019]
[0020] L emo =-log(P emo (e * (19)
[0021] Where softmax(·) is the normalization function, W e and b e L represents the weight parameter matrix and the bias vector, respectively. emo The loss function for the emotion classification task;
[0022] Step 8: Emotion Cause Identification; The emotion cause identification problem is treated 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, i.e., to label each word with a {0,1} binary tag; A semi-supervised method is used, combining a small-scale labeled data and a large-scale unlabeled data for training;
[0023] Step 9: Response Generation; To utilize dialogue history, knowledge selection, and speaker emotional reasoning information, a GPT-2 model is used to generate a target response Y = [y1, y2, ... y] of length M. M The calculation process is shown in formula (28);
[0024]
[0025] Among them, E 0:t-1 H represents the embedding representation of the generated word sequence, where H is the knowledge-enhanced contextual information representation. For the predicted sentiment category, Predict the probability distribution of the sentiment causes for the entire input sequence, where y0:t-1 is the generated word sequence, P(y t |y 0:t-1 ) indicates that y has already been generated 0:t-1 The t-th word y is generated under the condition of t The conditional probability distribution.
[0026] Furthermore, the preprocessing in step 1 is as follows:
[0027] Data cleaning and filtering: Thoroughly clean the dataset, remove incomplete or malformed 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 text format and standardize input data;
[0029] Emotion category encoding: Numerical encoding of emotion categories, mapping them to corresponding numerical representations for model learning and prediction;
[0030] Control tags are introduced: control tags [UNK], [PAD], [SOS], [EOS], [USR], [SYS], and [CLS] are introduced and assigned unique index values; among them, [UNK] represents unknown words, [PAD] is used to fill the sequence length, [SOS] and [EOS] mark the start and end of the dialogue respectively, [USR] and [SYS] distinguish between user and system speech, and [CLS] represents the comprehensive semantic representation of the entire dialogue.
[0031] Furthermore, in step 2, the calculation formulas for 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 Let E represent the m-th word in the dialogue, T be the total number of words in the dialogue, and E be the m-th word. GloVe (w m ) indicates using GloVe word vectors on w m Perform word embedding, e text (w m ) is w m Embedded text representation; p represents the position of the utterance in the dialogue, pos embed (p) indicates positional embedding of p, e pos (p) is the position representation of p after embedding;
[0035] The generation of higher-level discourse encoding representation H 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] Where E is the sum of the two embedding representations, and TRS Enc (·) indicates that the Transformer encoder is used for encoding operations.
[0039] Furthermore, in step 3, the specific method for obtaining knowledge related to the dialogue content from an external knowledge base is as follows:
[0040] The large-scale commonsense knowledge base ATOMIC-2020 was selected as the external knowledge source. The BART version of the pre-trained commonsense reasoning model COMET was used to reason about commonsense knowledge based on five key commonsense relationships: xIntent, xEffect, xReact, oEffect, and oReact, thereby obtaining commonsense feature sequences. Each represents the i-th utterance u in the dialogue.i Common sense knowledge features are obtained by reasoning based on specific common sense relationships, where i = 1, 2, ..., N; N is the number of utterances in the entire dialogue; among the 5 key common sense relationships, xIntent represents the speaker's intention, xEffect and oEffect represent the effects 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 for knowledge encoding is as follows:
[0042] The COMET model is used to perform commonsense reasoning on each sentence in the input sequence; for each relation r∈{xIntent,xEffect,oEffect,xReact,oReact}, 5 commonsense inferences are generated. and And connect them to obtain a common sense sequence. Based on relation type, this knowledge is divided into cognitive state knowledge and emotional state knowledge. Cognitive state knowledge refers to the impact of the speaker's and others' intentions and behaviors, using relation type r1∈{xIntent, xEffect, oEffect}. Emotional state knowledge refers to the speaker's and others' emotional reactions, using relation type r2∈{xReact, oReact}. Two encoders are designed: a cognitive encoder Enc Cog and the emotion encoder Enc Aff It 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 commonsense sequence, and uses the final hidden state of [CLS] to represent the semantic information of the entire sequence. The emotion encoder processes knowledge of emotional states, using the average of the lexical hidden states to obtain a representation of the emotional sequence. The specific calculation process is shown in formulas (5) to (8);
[0043]
[0044] Among them, H c and H e These are the encoded representations of the knowledge sequence of cognitive state and the knowledge sequence of emotional state, respectively.
[0045] Furthermore, the specific method of step 4 is as follows:
[0046] Input the set of all speech nodes V = {v1, v2, ..., v...} N} and speaker identity index function P(·), v i It is the i-th statement u iThe corresponding graph nodes, i = 2, 3, ..., N; initialize the edge set. The set of relation types R = {0, 1}, where l indicates that the connected nodes belong to the same speaker, and 0 indicates that they are 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 decrease the value of τ until τ = 0; if v i and v τ The speakers are the same, i.e., P(v) τ )=P(v i If v ), 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 have been traversed.
[0050] Finally, output the complete structure of the dialogue context graph DCG: G = (V, ε, R).
[0051] Furthermore, in step 5, each node v in the discourse node set V i Includes an attribute e, used to store the utterance representation;
[0052] Adjacency matrix A for 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 If there is an edge between them, then A c [i, j].flag = 1, otherwise A c [i, j].flag = 0; type stores the relation type of the edge, if node v i and v j The speaker's identity p i and p j If they are the same, then A c [i, j].type = SSI, otherwise A c [i, j].type = DSI; where SSI represents information transmission from the same speaker, and DSI represents information transmission from different speakers;
[0053] Adjacency matrix A for 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 the `kno` attribute, used to identify the presence or absence of an edge; `kno` is used to store specific knowledge information associated with the edge, i.e.
[0054] A knowledge selection strategy is formulated based on the speaker's identity to maintain consistency between knowledge transfer and speaker interaction in the dialogue: if the speaker's identity p of the current utterance is consistent with that of the previous utterance... i With p j If they are the same, then select the knowledge of the speaker's intention, effect, and reaction, namely xIntent, xEffect, and xReact; otherwise, select the knowledge of the other speaker's effect and reaction, namely oEffect and oReact.
[0055] Furthermore, the specific method for step 6 is as follows:
[0056] For the target discourse node v i Calculate its relationship with adjacent nodes v in the same layer. j Edge weight α i,j The calculation process is shown in formula (9);
[0057]
[0058] in, It is the discourse node v i In the node representation of layer l-1 of KDCG It is the discourse node v j In the node representation of the l-th layer of KDCG and N is a learnable parameter matrix. i Represents the discourse node v i The set of adjacent nodes, It is the discourse node v i The corresponding common sense knowledge encoding representation, Based on knowledge selection strategy It is a cognitive sequence encoding representation Or cognitive sequence encoding representation
[0059] Based on the calculated edge weights, context information and knowledge information are aggregated from adjacent nodes. The calculation process is shown in formulas (10) and (11).
[0060]
[0061] in, For a learnable parameter matrix, con i and klg i These are the aggregation results of the node's context information and the aggregation results of its knowledge information, 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 formulas (12) and (13);
[0063]
[0064] Among them, nod i and ctx i The updated node v i The current state and context state;
[0065] Then, the contextual knowledge unit GRU is used. k and self-circulating knowledge unit GRU s To obtain rich information related to knowledge, the calculation process is shown in formulas (14) and (15);
[0066]
[0067] Among them, ckg i and skg i The updated node v i The contextual knowledge state and the self-circulating knowledge state, k i,i For node v i Knowledge and information relevant to oneself;
[0068] Finally, the four types of information are summed to update v in each layer. i The word node representation 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 a Transformer encoder, and the probability distribution of the predicted emotion causes of the entire input sequence is obtained through a feedforward neural network. The calculation process is shown in formulas (20) to (22);
[0071] H = Enc(X) (20)
[0072]
[0073] Where Enc(·) indicates that the encoding operation is performed using the Transformer encoder, W c and b c For learnable parameters, c represents the predicted probability that each word is a cause of emotion. l Let L1 represent the true probability that each word is a cause of emotion, and L1 be the loss function for the emotion cause recognition task.
[0074] For unlabeled data, based on the given input sequence X = (x1, x2, ..., x... T In the emotion classification task, the attention weight distribution is used to select the top k words with the highest weights as the emotion reasons of the input sequence, and then the emotion reason labels are automatically constructed 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] Where score(·) represents the contribution score of each word to the sentiment classification, Att cause This represents the distribution of attention weights of the input sequence in the emotion classification task, Top k (·) indicates selecting the k words with the highest weight. cause The set is the top k words with the highest weights, and label(·) represents the emotional reason label for each word; the subsequent calculation process is the same as in (20) to formula (21);
[0079] Furthermore, to better optimize the identification of emotion causes, an auxiliary loss function L2 is introduced, which is calculated by Att. cause and The inner product is used for regularization constraints, 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, Let λ1, λ2, and λ3 represent the probability distribution of each word in the sequence as an emotional cause, and let λ1, λ2, and λ3 represent the weight parameters of each loss term.
[0083] Furthermore, in step 9, in order to improve the GPT-2 model's attention to emotional factors when generating responses, a biased self-attention mechanism based on emotional factors is introduced in the fine-tuning stage. That is, a multiplicative signal based on emotional factors is introduced into 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 responses. 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 the query vector, key vector, and value vector obtained by different linear transformations of the text encoding representation H, respectively. k W represents the vector dimension. q W k and W v M is the transformation matrix. e Let λ be the bias matrix for emotional causes, λ be a hyperparameter, I be the identity matrix, and z be the bias matrix for emotional causes. i ∈{1,2,...,Z} represents the index of the self-attention layer, MaskedWeight(·) represents the attention weight distribution after masking, BiasedWeight(·) represents the self-attention weight after adjustment for emotional bias, Normalize(·) represents the row-normalization function, and BaisedAttention(·) represents the final attention calculation result after introducing emotional bias.
[0087] The beneficial effects of adopting the above technical solution are as follows: The empathic dialogue generation method that integrates knowledge and emotional context graphs provided by this invention proposes a dialogue context modeling method based on directed acyclic graphs to solve the problem of inappropriate processing and integration of multi-turn dialogue context information: First, according to the speaker's identity and positional relationship, each utterance in the dialogue is dynamically connected with the preceding utterance, and a dialogue context graph (DCG) is flexibly constructed according to the actual context of the dialogue; then, a graph neural network is used to model the DCG, and utterance 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 transmission between the remote dialogue background and the surrounding environment.
[0088] This invention proposes a Knowledge into Dialogue Context Graph (KDCG) to address the difficulty in identifying implicit emotional information and needs in dialogues. First, by distinguishing common-sense knowledge between the speaker and listener, key information such as the user's true reactions and intentions is obtained. Then, social common-sense knowledge from ATOMIC-2020 is introduced, and the COMET model is trained to infer textual information beyond the scope of the common-sense knowledge graph. Finally, knowledge of five key relation types—xIntent, xEffect, xReact, oEffect, and oReact—is selected to enrich the representation of the discourse, enabling the system to better understand the emotions and needs implied in the user's discourse.
[0089] This invention proposes a semi-supervised emotion cause identification method based on sequence labeling to address the problems of neglected and difficult identification of emotion causes. First, emotion cause detection is treated as a sequence labeling problem. Then, a small-scale labeled data and a large-scale unlabeled data are combined to jointly model the dependency relationship between emotion and cause and construct a semi-supervised training model. Finally, the trained model is used to predict the speaker's emotion and its word-level emotion cause, improving the ability to identify emotion causes and making the generated dialogue content more targeted and empathetic. Attached Figure Description
[0090] Figure 1 The architecture diagram of the Knowledge into Emotional Causal Graph (KECG) model provided in the embodiments of the present invention;
[0091] Figure 2 A simplified diagram of the KECG model architecture provided in this embodiment of the invention;
[0092] Figure 3The flowchart illustrates the process of the empathic dialogue generation method that integrates knowledge and emotional context graphs, as provided in this embodiment of the invention. Detailed Implementation
[0093] The specific embodiments of the present invention will be described in further detail below with reference to the accompanying drawings and examples. The following examples are for illustrative purposes only and are not intended to limit the scope of the invention.
[0094] This embodiment provides a method for generating empathic dialogues that integrates knowledge and emotional causal context graphs, and proposes an empathic dialogue generation model that integrates knowledge and emotional causal context graphs. Figure 1 This is a model architecture diagram of KECG in this embodiment. Figure 2 To simplify the diagram, the proposed empathic dialogue generation model, which integrates knowledge and emotional cause context graphs, mainly comprises six modules: discourse encoding, knowledge-integrated dialogue context graph, knowledge-enhanced KDCG network, emotion classification, emotion cause identification, and response generation. The functions of each module are as follows:
[0095] Speech encoding: The input speech sequence is embedded using pre-trained GloVe word vectors and position embeddings, and then fed into the Transformer encoder to generate a context-encoded representation of the speech.
[0096] Knowledge-integrated dialogue context graph: External common sense knowledge is obtained using the ATOMIC-2020 common sense knowledge base and COMET model. Each dialogue is treated as a directed acyclic graph and modeled as a dialogue context graph DCG according to the constraints between utterances.
[0097] Knowledge-enhanced KDCG network: It collects dialogue information by utilizing knowledge-aware features based on speaker identity and contextual information units through a knowledge adjacency matrix and a series of GRU units;
[0098] Emotion Classification: Train an emotion classifier that classifies emotions based on the contextual representation of the last sentence of the conversation;
[0099] Emotional Cause Identification: By combining small-scale labeled data and large-scale unlabeled data, the speaker's emotional causes can be identified through semi-supervised training.
[0100] Response generation: Based on the obtained feature information, a biased attention mechanism based on emotional reasons is introduced to generate empathetic responses with appropriate content.
[0101] Figure 3 The flowchart of the specific processing steps for generating empathic dialogues by integrating knowledge and emotional context maps is as follows.
[0102] Step 1: Preprocess the dataset, including data cleaning and filtering, text preprocessing, sentiment category encoding, and introduction of control tags. Details are as follows:
[0103] Data cleaning and filtering: Thoroughly clean the dataset, remove incomplete or malformed 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 text format and standardize input data;
[0105] Emotion category encoding: Numerical encoding of emotion categories, mapping them to corresponding numerical representations for model learning and prediction;
[0106] Control tags are introduced: control tags [UNK], [PAD], [SOS], [EOS], [USR], [SYS], and [CLS] are introduced and assigned unique index values; among them, [UNK] represents unknown words, [PAD] is used to fill the sequence length, [SOS] and [EOS] mark the start and end of the dialogue respectively, [USR] and [SYS] distinguish between user and system speech, and [CLS] represents the comprehensive semantic representation of the entire dialogue.
[0107] Step 2: Speech Encoding. Two embedding methods are used to embed words into the sentences in the dataset to enhance the model's semantic understanding of the speech. The first method uses pre-trained GloVe word vectors to generate text embeddings. text The first method captures the semantic information of the discourse; the second method uses positional embedding. pos It identifies the position of utterances in the dialogue, providing positional information about the dialogue structure. The calculation processes for the two methods are 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 Let E represent the m-th word in the dialogue, T be the total number of words in the dialogue, and E be the m-th word. GloVe (w m ) indicates using GloVe word vectors on w m Perform word embedding, e text (w m ) is W mEmbedded text representation; p represents the position of the utterance in the dialogue, pos embed (p) indicates positional embedding of p, e pos (p) is the position representation of p after embedding.
[0111] The two embeddings are added together to form a comprehensive discourse embedding representation, which is then fed into the Transformer encoder to generate a higher-level discourse coding representation H. 0 The calculation process is shown in formulas (3) and (4).
[0112] E = e text (w m )+e pos (p) (3)
[0113] H 0 =TRS Enc (E) (4)
[0114] Where E is the sum of the two embedding representations, and TRS Enc (·) indicates that the Transformer encoder is used for encoding operations.
[0115] Step 3: Knowledge Acquisition and Encoding. To enhance the richness of semantic information, knowledge related to the dialogue content is acquired from external knowledge bases and encoded for subsequent integration with the dialogue context.
[0116] External commonsense knowledge acquisition. The ATOMIC-2020 large-scale commonsense knowledge base, containing over 300,000 events and 870,000 reasoning relationships, was selected as the external knowledge source. Using the BART version of the pre-trained commonsense reasoning model COMET, commonsense knowledge was reasoned based on five key commonsense relationships: xIntent, xEffect, xReact, oEffect, and oReact, to obtain commonsense feature sequences.
[0117]
[0118] Each represents the i-th utterance u in the dialogue. i Common sense knowledge features are derived from reasoning based on specific common sense relationships, where i = 1, 2, ..., N; N is the number of utterances in the entire dialogue. Among the five key common sense relationships, 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. Common sense reasoning is performed on each sentence in the input sequence using the COMET model. For each relation r∈{xIntent,xEffect,oEffect,xReact,oReact}, five common sense inferences are generated. and And connect them to obtain a common sense sequence. Based on relation type, this knowledge is divided into cognitive state knowledge and emotional state knowledge. Cognitive state knowledge refers to the impact of the speaker's and others' intentions and behaviors, using relation type r1∈{xIntent, xEffect, oEffect}. Emotional state knowledge refers to the speaker's and others' emotional reactions, using relation type r2∈{xReact, oReact}. Two encoders are designed: a cognitive encoder Enc Cog and the emotion encoder Enc Aff This 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 commonsense sequence, and uses the final hidden state of [CLS] to represent the semantic information of the entire sequence. The emotion encoder processes knowledge of emotional states, using the average of the lexical hidden states to obtain a representation of the emotional sequence. The specific calculation process is shown in formulas (5) to (8);
[0120]
[0121] Among them, H c and H e These are the encoded representations of the knowledge sequence of cognitive state and the knowledge sequence of emotional state, respectively.
[0122] Step 4: Dialogue Context Graph Construction. Construct a dialogue context graph (DCG) based on the dialogue and the corresponding speaker identity information. Represent the dialogue as a directed acyclic graph (DAG), ensuring that each utterance node only receives information from a specific previous utterance, thereby preventing information from being back propagated to itself or its predecessor node through any path.
[0123] First, input the set of all speech nodes V = {v1, v2, ..., v...} N} and speaker identity index function P(·), v i It is the i-th statement u i The corresponding graph nodes, i = 2, 3, ..., N; initialize the edge set. The set of relation types R = {0, 1}, where 1 indicates that the connected nodes belong to the same speaker, and 0 indicates that they are different speakers. Starting from the second utterance node v2, each node v is traversed sequentially. i For the current node v i Check all its predecessor nodes vτ That is, starting from τ = i-1, gradually decrease the value of τ until τ = 0; if v i and v τ The speakers are the same, i.e., P(v) τ )=P(v i If v ), 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 utterance nodes have been traversed. Finally, output the complete structure G = (V, ε, R) of the dialogue context graph DCG.
[0124] Step 5: Constructing a Knowledge-Integrated Dialogue Context Graph. To enhance the model's comprehension capabilities, a Knowledge-Integrated Dialogue Context Graph (KDCG) is constructed to integrate the knowledge extracted from the utterances into the dialogue context graph. The KDCG consists of three parts: the set of utterance nodes V, the adjacency matrix A of utterance interactions, and... c Adjacency matrix A for knowledge transfer between discourses k That is, G = (V, A) c A k ).
[0125] Each node v in the set of discourse nodes V i It includes an attribute e, which is used to store the utterance representation.
[0126] Adjacency matrix A for discourse interaction c It includes two attributes: flag and type. flag stores either 0 or 1, used to indicate whether an edge exists. For node v... i and v j If v i to v j If there is an edge between them, then A c [i, j].flag = 1, otherwise A c [i, j].flag = 0. `type` stores the relation type of the edge; if node v... i and v j The speaker's identity p i and p j If they are the same, then A c [i, j].type = SSI, otherwise A c [i, j].type = DSI. Where SSI represents information transmission from the same speaker, and DSI represents information transmission from different speakers.
[0127] Adjacency matrix A for knowledge transfer between discourses k It includes two attributes: flag and kno. Matrix A k The flag attribute and matrix Ac The `flag` attribute is the same as the `kno` attribute, used to identify the presence or absence of an edge. `kno` is used to store specific knowledge information associated with the edge, i.e.
[0128] Knowledge selection strategies. To maintain consistency between knowledge transfer and speaker interaction in a dialogue, knowledge selection strategies are formulated based on the speaker's identity. If the speaker's identity p of the current utterance is consistent with that of the previous utterance... i With p j If they are the same, then select the knowledge of the speaker's intention, effect, and reaction, namely xIntent, xEffect, and xReact; otherwise, select the knowledge of the other speaker's effect and reaction, namely oEffect and oReact.
[0129] Step 6: Perform knowledge fusion based on the constructed dialogue context graph KDCG.
[0130] For the target discourse node v i Calculate its relationship with adjacent nodes v in the same layer. j Edge weight α i,j The calculation process is shown in formula (9).
[0131]
[0132] in, It is the discourse node v i In the node representation of layer l-1 of KDCG It is the discourse node v j In the node representation of the l-th layer of KDCG and N is a learnable parameter matrix. i Represents the discourse node v i The set of adjacent nodes, It is the discourse node v i The corresponding common sense knowledge encoding representation, Based on knowledge selection strategy It is a cognitive sequence encoding representation Or cognitive sequence encoding representation
[0133] Based on the calculated edge weights, contextual information and knowledge information are aggregated from adjacent nodes. The calculation process is shown in formulas (10) and (11).
[0134]
[0135] in, For a learnable parameter matrix, con i and klg iThese are the aggregation results of the node's context information and knowledge information, respectively.
[0136] In addition, the node unit GRU is used. n and context unit GRU c To capture the current state and context information of the node, the calculation process is shown in formulas (12) and (13).
[0137]
[0138] Among them, nod i and ctx i The updated node v i The current state and context state.
[0139] Then, the contextual knowledge unit GRU is used. k and self-circulating knowledge unit GRU s To obtain rich information related to knowledge, the calculation process is shown in formulas (14) and (15).
[0140]
[0141] Among them, ckg i and skg i The updated node v i The contextual knowledge state and the self-circulating knowledge state, k i,i For node v i Knowledge and information relevant to oneself.
[0142] Finally, the four types of information are summed to update v in each layer. i The word node representation is shown in formula (16).
[0143]
[0144] Step 7: Emotion Classification. Train an emotion classifier to accurately capture and respond to the user's emotional state, based on the contextual representation h of the last sentence in the dialogue. last The system generates an emotion category distribution and uses the argmax function to select the emotion category with the highest probability as the final predicted emotion category. During training, the predicted emotion category distribution P is minimized. emo And actual emotion label e * The cross-entropy loss between the two is used to optimize the accuracy of emotion classification. The calculation process is shown in formulas (17) to (19).
[0145] P emo =softmax(W e hlast +b e (17)
[0146]
[0147] L emo =-log(P emo (e * (19)
[0148] Where softmax(·) is the normalization function, W e and b e L represents the weight parameter matrix and the bias vector, respectively. emo The loss function is used for the emotion classification task.
[0149] Step 8: Emotion Cause Identification. The emotion cause identification problem is treated as a sequence labeling task. The goal is to predict whether each word in the input dialogue sequence is a cause of the speaker's emotion, i.e., to assign a {0, 1} binary label to each word. To address the problem of data scarcity, a semi-supervised method is adopted, combining a small amount of labeled data with a large amount of unlabeled data for training.
[0150] For labeled data, the context encoding representation H of the input sequence X is obtained through a Transformer encoder, and the probability distribution of the predicted sentiment causes for the entire input sequence is obtained through a feedforward neural network. The calculation process is shown in formulas (20) to (22);
[0151] H = Enc(X) (20)
[0152]
[0153] Where Enc(·) indicates that the encoding operation is performed using the Transformer encoder, W c and b c For learnable parameters, c represents the predicted probability that each word is a cause of emotion. l Let L1 represent the true probability that each word is a cause of emotion, and L1 be the loss function for the emotion cause recognition task.
[0154] For unlabeled data, based on the given input sequence X = (x1, x2, ..., x... T In the emotion classification task, the attention weight distribution is used to select the top k words with the highest weights as the emotion reasons of the input sequence, and then the emotion reason labels are automatically constructed 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] Where score(·) represents the contribution score of each word to the sentiment classification, Att cause This represents the distribution of attention weights of the input sequence in the emotion classification task, Top k (·) indicates selecting the k words with the highest weight. cause Let be the set of the top k words with the highest weights, and label(·) represent the emotional reason label for each word. In this way, emotional reason labels are automatically constructed for unlabeled data, and the subsequent calculation process is the same as in formulas (20) to (21).
[0159] Furthermore, to better optimize the identification of emotion causes, an auxiliary loss function L2 is introduced, which is calculated by Att. cause and The inner product is used for regularization constraints, 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, Let λ1, λ2, and λ3 represent the probability distribution of each word in the sequence as an emotional cause, and let λ1, λ2, and λ3 represent the weight parameters of each loss term.
[0163] Step 9: Response Generation; To utilize dialogue history, knowledge selection, and speaker emotional reasoning information, a GPT-2 model is used to generate a target response Y = [y1, y2, ... y] of length M. M The calculation process is shown in formula (28);
[0164]
[0165] Among them, E 0:t-1 H represents the embedding representation of the generated word sequence, where H is the knowledge-enhanced contextual information representation. For the predicted sentiment category, Predict the probability distribution of the emotional causes for the entire input sequence, y0:t-1 Given the generated word sequence, P(y) t |y 0:t-1 ) indicates that y has already been generated 0:t-1 The t-th word y is generated under the condition of t The conditional probability distribution.
[0166] To enhance the GPT-2 model's attention to emotional factors during response generation, an emotion-based biased self-attention mechanism is introduced during the fine-tuning stage. This involves adding an emotion-based multiplicative signal to the existing GPT-2 architecture without adding any additional parameters. Based on the hierarchical nature of deep neural network learning, a dynamic weight adjustment strategy is designed: in the early 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 comprehensively considers emotional factors when generating responses. The calculation process is shown in equations (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 the query vector, key vector, and value vector obtained by different linear transformations of the text encoding representation H, respectively. k W represents the vector dimension. q W k and W v M is the transformation matrix. e Let λ be the bias matrix for emotional causes, λ be a hyperparameter, I be the identity matrix, and z be the bias matrix for emotional causes. i ∈{1,2,...,Z} represents the index of the self-attention layer, MaskedWeight(·) represents the attention weight distribution after masking, BiasedWeight(·) represents the self-attention weight after adjustment for emotion-cause bias, Normalize(·) represents the row-normalization function, and BaisedAttention(·) represents the final attention calculation result after introducing emotion-cause bias.
[0170] This embodiment conducts experiments using data from the empathic dialogue generation benchmark dataset ED and the word-level emotion cause annotation dataset EmoCause. The ED dataset contains 32 specific emotions and empathic dialogue data within those emotional scenarios. The EmoCause dataset is constructed based on the validation and test sets of the ED dataset and includes word-level emotion cause annotations. Comparative experiments on emotion cause identification and empathic response generation tasks are performed on both the EmoCause and ED datasets with representative models. The experimental results of the comparative models are then compared with the KECG model proposed in this invention.
[0171] In the emotion cause identification task, to maintain consistency with the evaluation metrics of the comparison models, the experimental evaluation metrics were uniformly adopted as Acc, Top-1 Recall, Top-3 Recall, and Top-5 Recall. The comparative experimental results of emotion cause identification are shown in Table 1.
[0172] Table 1. Results of the comparative experiment on identifying the causes of emotions.
[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] Experimental results show that the KECG model in this embodiment performs excellently on all evaluation metrics, especially in Top-nRecall (n=1,3,5), where it shows a significant improvement compared to other methods. Compared to Roberta Att, although it is slightly inferior in accuracy, it shows a significant improvement in recall. These results demonstrate that the semi-supervised training method used in this embodiment of the KECG model can effectively narrow the gap between emotion recognition and emotion cause recognition, enhancing the model's ability to recognize emotion causes.
[0175] In the empathy response generation task, to maintain consistency with the evaluation metrics of the comparison model, the automatic evaluation metrics used in the experiment were uniformly PPL, Dist-1, Dist-2, and Acc, while the manual evaluation metrics were uniformly Fluency, Relevance, and Relevance. A / B testing was also conducted. The results of the automatic evaluation, manual evaluation, and A / B testing of the empathy response generation are shown in Tables 2, 3, and 4, respectively.
[0176] Table 2. Automatic evaluation results of empathy response generation
[0177]
[0178]
[0179] Table 3. Results of Artificial 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. A / B Test Results for Empathy Response 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, experimental results show that the KECG model in this embodiment outperforms other models on the PPL metric. This improvement is attributed to the model's integration of emotional causes, which enhances the understanding of the speaker's content and improves the overall quality of the generated responses. Regarding diversity, the KECG model in this embodiment shows a slight decrease in the Dist-1 metric compared to other models. This may be because the introduction of emotional causes makes the responses more focused on emotional factors, thus reducing the originality of the dialogue to some extent. Nevertheless, the KECG model in this embodiment outperforms other models on the Dist-2 metric, indicating that the model can maintain linguistic diversity while preserving emotional coherence. This may be because the model can still select words from the dialogue history and retrieved knowledge entities. In terms of accuracy, the KECG model in this embodiment also demonstrates excellent performance. By introducing emotional cause words, the model can more accurately capture the nuances of emotional states and dialogue, thus more precisely reflecting the speaker's emotions and intentions when generating responses. This sensitivity to emotional causes significantly improves the model's accuracy in understanding and generating empathetic responses, effectively enhancing the overall performance of the model.
[0184] In human evaluation, experimental results show that the KECG model in this embodiment achieved high scores across all three dimensions: fluency, relevance, and empathy. Particularly in empathy, its score was significantly higher than other models. This result indicates that introducing an emotion-based biased self-attention mechanism is key to improving performance. This mechanism allows the model to focus more on emotion-related words when generating responses, thus producing more emotionally consistent dialogue. Furthermore, the high score consistency coefficient also indicates a high degree of consistency in the positive evaluations of the KECG model in this embodiment by the evaluators.
[0185] In A / B testing, experimental results showed that the KECG model in this embodiment achieved a high win rate compared to other models. Specifically, in comparisons with the MoEL, MIME, and EmpDG models, the KECG model in this embodiment achieved a win rate exceeding 40%, and reached a high win rate of 43.9% compared to the MoEL model. This result further demonstrates the advantages of the KECG model in generating empathetic responses, particularly in meeting user expectations and evoking resonance.
[0186] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features therein; and these modifications or substitutions 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 empathic dialogues that integrates knowledge and emotional context graphs, characterized in that: A model for generating empathic dialogue that integrates knowledge and emotional cause context maps is proposed. This model comprises six modules: discourse encoding, knowledge-integrated dialogue context maps, a 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, sentiment category encoding, and introduction of control tags; Step 2: Speech encoding; Two embedding methods are used to embed words into sentences in the dataset. The first method uses pre-trained GloVe word vectors to generate text embeddings. text The first method captures the semantic information of the discourse; the second method uses positional embedding. pos The two embeddings are used to identify the position of the utterance in the dialogue and provide positional information of the dialogue structure. The two embeddings are added together to form a comprehensive utterance embedding representation, which is then input into the Transformer encoder to generate a higher-level utterance encoding representation. Step 3: Knowledge Acquisition and Encoding; Acquire knowledge related to the dialogue content from an external knowledge base and encode it so that it can be organically combined with the dialogue context later; Step 4: Dialogue Context Graph Construction; Construct a 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 utterance node only receives information from a specific previous utterance, thereby preventing information from being transmitted back to itself or its predecessor node through any path; Step 5: Construct a Knowledge-integrated Dialogue Context Graph (KDCG) to integrate the knowledge extracted from the discourse into the dialogue context graph; the KDCG consists of three parts: the set of discourse nodes V, the adjacency matrix of discourse interactions A, and so on. c Adjacency matrix A for 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 an emotion classifier to accurately capture and respond to the user's emotional state based on the contextual representation h of the last sentence in the dialogue. last The system generates an emotion category distribution and uses the argmax function to select the emotion category with the highest probability as the final predicted emotion category. During training, the predicted emotion category distribution P is minimized. emo The cross-entropy loss between the actual emotion label e* and the actual emotion label is used to optimize the emotion classification accuracy. The calculation process is shown in Equations (17) to (19). P emo =softmax(W e h last +b e ) (17) L emo =-log(P emo (and * )) (19) Where softmax(·) is the normalization function, W e and b e L represents the weight parameter matrix and the bias vector, respectively. emo The loss function for the emotion classification task; Step 8: Emotion Cause Identification; The emotion cause identification problem is treated 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, i.e., to label each word with a {0,1} binary tag; A semi-supervised method is used, combining a small-scale labeled data and a large-scale unlabeled data for training; Step 9: Response Generation; To utilize dialogue history, knowledge selection, and speaker emotional reasoning information, a GPT-2 model is used to generate a target response Y = [y1, y2, ... y] of length M. M The calculation process is shown in formula (28); Among them, E 0:t-1 H represents the embedding representation of the generated word sequence, where H is the knowledge-enhanced contextual information representation. For the predicted sentiment category, Predict the probability distribution of the emotional causes for the entire input sequence, y 0:t-1 Given the generated word sequence, P(y) t |y 0:t-1 ) indicates that y has already been generated 0:t-1 The t-th word y is generated under the condition of t The conditional probability distribution.
2. The empathic dialogue generation method based on knowledge and emotional cause context graphs as described in claim 1, characterized in that: The preprocessing in step 1 is as follows: Data cleaning and filtering: Thoroughly clean the dataset, remove incomplete or malformed 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 text format and standardize input data; Emotion category encoding: Numerical encoding of emotion categories, mapping them to corresponding numerical representations for model learning and prediction; Control tags are introduced: control tags [UNK], [PAD], [SOS], [EOS], [USR], [SYS], and [CLS] are introduced and assigned unique index values; among them, [UNK] represents unknown words, [PAD] is used to fill the sequence length, [SOS] and [EOS] mark the start and end of the dialogue respectively, [USR] and [SYS] distinguish between user and system speech, and [CLS] represents the comprehensive semantic representation of the entire dialogue.
3. The method for generating empathic dialogue by integrating knowledge and emotional cause context graphs according to claim 1, characterized in that: In step 2, the calculation formulas for 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 Let E represent the m-th word in the dialogue, T be the total number of words in the dialogue, and E be the m-th word. GloVe (w m ) indicates using GloVe word vectors on w m Perform word embedding, e text (w m ) is w m Embedded text representation; p represents the position of the utterance in the dialogue, pos embed (p) indicates positional embedding of p, e pos (p) is the position representation of p after embedding; The generation of higher-level discourse encoding representation H 0 The calculation process is as follows: E=e text (w m )+e pos (p) (3) H 0 =TRS Enc (E) (4) Where E is the sum of the two embedding representations, and TRS Enc (·) indicates that the Transformer encoder is used for encoding operations.
4. The method for generating empathic dialogue by integrating knowledge and emotional cause context graphs according to claim 1, characterized in that: In step 3, the specific method for obtaining knowledge related to the dialogue content from an external knowledge base is as follows: The large-scale commonsense knowledge base ATOMIC-2020 was selected as the external knowledge source. The BART version of the pre-trained commonsense reasoning model COMET was used to reason about commonsense knowledge based on five key commonsense relationships: xIntent, xEffect, xReact, oEffect, and oReact, thereby obtaining commonsense feature sequences. Let u represent the i-th utterance in the dialogue. i Common sense knowledge features are obtained by reasoning based on specific common sense relationships, where i = 1, 2, ..., N; N is the number of utterances in the entire dialogue; among the 5 key common sense relationships, xIntent represents the speaker's intention, xEffect and oEffect represent the effects 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 for knowledge encoding is as follows: The COMET model is used to perform commonsense reasoning on each sentence in the input sequence; for each relation r∈{xIntent,xEffect,oEffect,xReact,oReact}, 5 commonsense inferences are generated. and And connect them to obtain a common sense sequence. Based on relation type, this knowledge is divided into cognitive state knowledge and emotional state knowledge. Cognitive state knowledge refers to the impact of the speaker's and others' intentions and behaviors, using relation type r1∈{xIntent, xEffect, oEffect}. Emotional state knowledge refers to the speaker's and others' emotional reactions, using relation type r2∈{xReact, oReact}. Two encoders are designed: a cognitive encoder Enc Cog and the emotion encoder Enc Aff It 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 commonsense sequence, and uses the final hidden state of [CLS] to represent the semantic information of the entire sequence. The emotion encoder processes knowledge of emotional states, using the average of the lexical hidden states to obtain a representation of the emotional sequence. The specific calculation process is shown in formulas (5) to (8); Among them, H c and H e These are the encoded representations of the knowledge sequence of cognitive state and the knowledge sequence of emotional state, respectively.
5. The method for generating empathic dialogue by integrating knowledge and emotional cause context graphs according to claim 4, characterized in that: The specific method for step 4 is as follows: Input the set of all speech nodes V = {v1, v2, ..., v...} N } and speaker identity index function P(·), v i It is the i-th statement u i The corresponding graph nodes, i = 2, 3, ..., N; initialize the edge set. The set of relation types R = {0, 1}, where 1 indicates that the connected nodes belong to the same speaker, and 0 indicates that they are 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 decrease the value of τ until τ = 0; if v i and v τ The speakers are the same, i.e., P(v) τ )=P(v i If v ), 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 have been traversed. Finally, output the complete structure of the dialogue context graph DCG: G = (V, ε, R).
6. The method for generating empathic dialogue by integrating knowledge and emotional cause context graphs according to claim 5, characterized in that: In step 5, each node v in the speech node set V i Includes an attribute e, used to store the utterance representation; Adjacency matrix A for 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 If there is an edge between them, then A c [i, j].flag = 1, otherwise A c [i, j].flag = 0; type stores the relation type of the edge, if node v i and v j The speaker's identity p i and p j If they are the same, then A c [i, j].type = SSI, otherwise A c [i, j].type = DSI; where SSI represents information transmission from the same speaker, and DSI represents information transmission from different speakers; Adjacency matrix A for knowledge transfer between discourses k Includes two attributes: flag and kno; matrix A k The flag attribute and matrix A c The `flag` attribute is the same as the `kno` attribute, used to identify the presence or absence of an edge; `kno` is used to store specific knowledge information associated with the edge, i.e. A knowledge selection strategy is formulated based on the speaker's identity to maintain consistency between knowledge transfer and speaker interaction in the dialogue: if the speaker's identity p of the current utterance is consistent with that of the previous utterance... i With p j If they are the same, then select the knowledge of the speaker's intention, effect, and reaction, namely xIntent, xEffect, and xReact; otherwise, select the knowledge of the other speaker's effect and reaction, namely oEffect and oReact.
7. The method for generating empathic dialogue by integrating knowledge and emotional cause context graphs according to claim 6, characterized in that: The specific method for step 6 is as follows: For the target discourse node v i Calculate its relationship with adjacent nodes v in the same layer. j Edge weight α i,j The calculation process is shown in formula (9); in, It is the discourse node v i In the node representation of layer l-1 of KDCG It is the discourse node v j In the node representation of the l-th layer of KDCG and N is a learnable parameter matrix. i Represents the discourse node v i The set of adjacent nodes, It is the discourse node v i The corresponding common sense knowledge encoding representation, Based on knowledge selection strategy It is a cognitive sequence encoding representation Or cognitive sequence encoding representation Based on the calculated edge weights, context information and knowledge information are aggregated from adjacent nodes. The calculation process is shown in formulas (10) and (11). in, For a learnable parameter matrix, con i and klg i These are the aggregation results of the node's context information and the aggregation results of its knowledge information, 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 formulas (12) and (13); Among them, nod i and ctx i The updated node v i The current state and context state; Then, the contextual knowledge unit GRU is used. k and self-circulating knowledge unit GRU s To obtain rich information related to knowledge, the calculation process is shown in formulas (14) and (15); Among them, ckg i and skg i The updated node v i The contextual knowledge state and the self-circulating knowledge state, k i,i For node v i Knowledge and information relevant to oneself; Finally, the four types of information are summed to update v in each layer. i The word node representation is shown in formula (16).
8. The method for generating empathic dialogue by integrating knowledge and emotional cause context graphs 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 a Transformer encoder, and the probability distribution of the predicted emotion causes of the entire input sequence is obtained through a feedforward neural network. The calculation process is shown in formulas (20) to (22); H = Enc(X) (20) Where Enc(·) indicates that the encoding operation is performed using the Transformer encoder, W c and b c For learnable parameters, c represents the predicted probability that each word is a cause of emotion. l Let L1 represent the true probability that each word is a cause of emotion, and L1 be the loss function for the emotion cause recognition task. For unlabeled data, based on the given input sequence x = (x1, x2, ..., x... T In the emotion classification task, the attention weight distribution is used to select the top k words with the highest weights as the emotion reasons of the input sequence, and then the emotion reason labels are automatically constructed for the unlabeled data. The calculation process is as follows: To cause =softmax(score(X)) (23) IN cause =Top k (X, That cause ) (24) Where score(·) represents the contribution score of each word to the sentiment classification, Att cause This represents the distribution of attention weights of the input sequence in the emotion classification task, Top k (·) indicates selecting the k words with the highest weight. cause The set of the top k words with the highest weights, label(·) represents the emotional reason label of each word; the subsequent calculation process is the same as (20) to formula (21); Furthermore, to better optimize the identification of emotion causes, an auxiliary loss function L2 is introduced, which is calculated by Att. cause and The inner product is used for regularization constraints, 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, Let λ1, λ2, and λ3 represent the probability distribution of each word in the sequence as an emotional cause, and let λ1, λ2, and λ3 represent the weight parameters of each loss term.
9. The method for generating empathic dialogue by integrating knowledge and emotional cause context graphs according to claim 8, characterized in that: In step 9, in order to improve the GPT-2 model's attention to emotional factors when generating responses, an emotional-based biased self-attention mechanism is introduced in the fine-tuning stage. That is, an emotional-based multiplicative signal is introduced into the existing GPT-2 architecture without adding any additional parameters. Based on 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 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 the query vector, key vector, and value vector obtained by different linear transformations of the text-encoded representation H, respectively, and d k W represents the vector dimension. q W k and W v M is the transformation matrix. e Let λ be the bias matrix for emotional causes, λ be a hyperparameter, I be the identity matrix, and z be the bias matrix for emotional causes. i ∈{1,2,...,Z} represents the index of the self-attention layer, MaskedWeight(·) represents the attention weight distribution after masking, BiasedWeight(·) represents the self-attention weight after adjustment for emotional bias, Normalize(·) represents the row-normalization function, and BaisedAttention(·) represents the final attention calculation result after introducing emotional bias.
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