An empathetic reply generation method based on dynamic interaction of utterance-level features

By using a dynamic interaction-based empathic response generation method based on discourse-level features, and leveraging a Transformer encoder and a multi-layer heterogeneous graph attention network, this method addresses the problems of coarse-grained modeling and context-detached reasoning in existing technologies. This enables computer systems to better understand human emotions and generate natural, context-appropriate responses.

CN117808103BActive Publication Date: 2026-06-02NORTHEASTERN UNIV CHINA

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
NORTHEASTERN UNIV CHINA
Filing Date
2024-01-04
Publication Date
2026-06-02

AI Technical Summary

Technical Problem

Existing methods for generating empathic responses suffer from coarse-grained dialogue history modeling and context-detached common-sense reasoning, resulting in responses that are not fluent, have low consistency, and lack empathy.

Method used

We employ a dynamic interaction method based on discourse-level features. By combining a Transformer encoder and a multi-layer heterogeneous graph attention network with a DIALeCT contextualized common sense inferencer, we construct a two-stage heterogeneous graph attention network to capture the interaction of emotional and intentional features in the context in a fine-grained manner. This allows us to train the model to generate more natural and human-like responses.

Benefits of technology

This enables computer systems to better understand human emotions, generate more context-appropriate response texts that resonate with users' emotions, adapt to different fields and cultural backgrounds, and improve the naturalness and readability of responses.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117808103B_ABST
    Figure CN117808103B_ABST
Patent Text Reader

Abstract

The application provides a kind of empathetic reply generation method based on speech level feature dynamic interaction, it is related to artificial intelligence technical field.The method of artificial intelligence and natural language processing enables computer system to understand, identify and simulate human emotion, and replies in the way of emotional, considerate and understanding.By the method of the application, computer system can better understand human emotion, and communicate and interact with people in a more natural and more humanized way, which overcomes the problems of incoherent reply content, low consistency and poor empathy caused by coarse-grained dialogue history modeling and context-independent common sense reasoning in the prior art.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of artificial intelligence technology, and in particular to a method for generating empathic responses based on dynamic interaction with discourse-level features. Background Technology

[0002] With the research and development of artificial intelligence technology, chatbots have achieved leaps and bounds in various aspects of technology. Chatbots of various forms, offering new and effective communication methods, are widely used in many industries, providing users with entirely new ways to communicate. However, under current technology, building a truly human-like open-domain dialogue system still faces enormous challenges. This requires not only that chatbots understand and express human language, but also that they possess personality and emotions like humans. Empathy, a fundamental human characteristic, describes the ability to understand the emotions and situations of others and requires achieving emotional and cognitive resonance with others. Furthermore, empathy is considered one of the most valuable emotional phenomena for improving human-computer interaction. Empathic response generation technology uses dialogue history information as input and, through mathematical models and calculations, enables the computer to output an appropriate response, giving the computer the ability to resonate emotionally with the user.

[0003] Current empathic response generation methods are all based on deep learning algorithms. They mainly utilize an end-to-end sequence generation Seq2Seq model, which consists of an encoder and a decoder with an attention mechanism. When decoding each word, the attention mechanism dynamically calculates the weight of each input hidden state and obtains the current attention vector through a weighted linear combination. Different models can be flexibly used as encoders and decoders, such as the currently widely used Bi-LSTM and Transformer models.

[0004] Existing methods for generating empathic responses have the following two main drawbacks.

[0005] First, the feature information extracted by existing research methods is dialogue-level and coarse-grained. Most of these models map the entire dialogue history into a representation vector, ignoring the special structure of the dialogue. Empathic dialogue is a multi-turn dialogue between two people, so there is a clear temporal relationship and hierarchical structure between the utterances. Ignoring the special structure of the dialogue may lead to the loss of a lot of important information.

[0006] Furthermore, event-based common-sense knowledge is difficult to align with the context of a dialogue. For referencing external knowledge, most existing methods use ConceptNet or Comet for common-sense reasoning. However, the reasoning process of these two methods is context-independent because they only focus on the target utterance being reasoned about. Dialogue, however, is a coherent, multi-turn structure. Much of the information needed to understand the target utterance is likely scattered throughout the dialogue, not necessarily confined to a given utterance. Therefore, using these two methods for reasoning only yields localized common-sense reasoning, leading to inconsistencies or contradictions between the generated content and the dialogue history. Summary of the Invention

[0007] The technical problem this invention aims to solve is to address the shortcomings of existing technologies by providing a method for generating empathetic responses based on dynamic interaction with discourse-level features. This method enables computer systems to better understand human emotions and communicate and interact with people in a more natural and human way. It overcomes the problems of non-fluent responses, low consistency, and poor empathy caused by coarse-grained dialogue history modeling and context-detached common-sense reasoning in existing technologies.

[0008] To solve the above-mentioned technical problems, the technical solution adopted by the present invention is as follows:

[0009] A method for generating empathic responses based on dynamic interaction with discourse-level features includes the following steps:

[0010] Step 1: Dataset Acquisition and Preprocessing;

[0011] Obtain an open-source dataset for the empathic response generation task, and split the dataset into training, validation, and test sets. Each sample data includes a dialogue history D and a target response text Y = u. res Automatically label emotions and intentions for all samples in the training, validation, and test sets; for each utterance u in the dialogue history D i The DIALeCT contextualized common sense reasoning engine is used to perform common sense reasoning and obtain contextualized common sense knowledge.

[0012] Step 2: Encoding discourse and common sense knowledge;

[0013] Dialogue u based on Transformer encoder i And the acquired contextualized common sense knowledge Encode and map to a vector;

[0014] Step 3: Construct a two-stage heterogeneous graph attention network, including a cognitive enhancement graph and a dynamic interaction graph;

[0015] Step 3.1: Cognitive Enhancement Map;

[0016] A multi-layer heterogeneous graph attention network is adopted, and common sense knowledge and utterances in dialogue history related to cognition are selected as nodes. Various types of edges are designed according to the correlation between different nodes. The feature information between different nodes is aggregated through graph attention mechanism to obtain cognitively enhanced utterance encoding.

[0017] Step 3.2: Dynamic Interactive Graph;

[0018] A multi-layer heterogeneous graph attention network and an improved graph attention mechanism are used to simulate the dynamic interaction between different discourses and features.

[0019] Step 4: Model training process, including sentiment and intent prediction based on cross-entropy loss function and empathic text generation based on negative log-likelihood function, and weighted summation of the two training processes; after training, save the optimal model, and test it on the optimal model using data from the test set.

[0020] Further, step 1 includes the following steps:

[0021] Step 1.1: Dataset Acquisition;

[0022] We obtained an open-source dataset for the empathic response generation task and split it into training, validation, and test sets. Each sample data includes a dialogue history D and a target response text Y = u. res The dialogue history D includes multiple utterances, D = [u1, u2, ..., u...]. N-1 ], every word i Including multiple words, represented as u i =[w1,w2,…,w m ];

[0023] Step 1.2: Fine-grained automatic annotation of emotions and intentions;

[0024] Automatically label all samples in the training, validation, and test sets from step 1.1 with sentiment and intent. These fine-grained sentiment or intent labels will be used in subsequent multi-task learning. The specific method is as follows:

[0025] Step 1.2.1: Construct a 32-class emotion classifier and an 8-class intention classifier based on the RoBERTa model;

[0026] Step 1.2.2: Use an emotion classifier and an intention classifier to classify the emotion and intention of each utterance. For each dialogue, obtain the emotion label E = [r1, e2, ..., e...]. N-1 ,e res ] and intent label A = [a1, a2, ..., a N-1 ,ares ];

[0027] Step 1.3: Contextualized common-sense reasoning;

[0028] For each utterance in the dialogue history D i The DIALeCT contextualized common sense reasoning engine is used to perform common sense reasoning and obtain contextualized common sense knowledge. This involves four types of common-sense knowledge: antecedent, subsequent events, emotional reaction, and intentional response; the specific method is as follows:

[0029] Step 1.3.1: For each utterance u i Design fill template Among them, question r This represents one of the four types of common sense knowledge. <sep>Indicates a separator;

[0030] Step 1.3.2: Preprocess the dataset by converting it into a format that the DIALeCT model can input according to the filling template;

[0031] Step 1.3.3: Input the processed data into the DIALeCT model to obtain contextualized common sense knowledge.

[0032] Furthermore, step 2 includes the following steps:

[0033] Step 2.1: Insert a special identifier [CLS] at the beginning of each input sequence to capture utterance-level feature representations;

[0034] Step 2.2: Perform word embedding processing on the dialogue text obtained in Step 2.1, and introduce position embedding and speaker embedding to obtain a preliminary representation vector of the discourse, capturing contextual information and the identity of the speakers;

[0035] Step 2.3: Speech Encoder;

[0036] Based on the Transformer encoder, as shown in Equations (2) and (3), the representation vector obtained in step 2.2 is input into the encoder for encoding, and the encoded [CLS] identifier is used as the representation of the entire utterance;

[0037]

[0038]

[0039] in, The vector represents the initial representation of the utterance; the encoder represents the encoder. Let represent the representation vector of all words in the i-th utterance. The representation vector representing the position of the [CLS] identifier in the i-th utterance is used to represent the representation vector of the entire utterance.

[0040] Step 2.4: Encoding common sense knowledge;

[0041] Similar to the speech encoder, as shown in Equations (4) and (5), based on the Transformer encoder, the representation vector obtained in step 2.2 is input into the encoder, and finally the encoded vector is input into the average hidden layer to obtain the knowledge representation vector.

[0042]

[0043]

[0044] in, The vector representing the common sense knowledge of the r-th type of common sense in the i-th statement; denoted as the common sense knowledge representation vector after dimensionality reduction by the average hidden layer, and MEAN represents the average hidden layer.

[0045] Furthermore, the specific method of step 2.2 is as follows:

[0046] Step 2.2.1: Word embedding;

[0047] Word embedding is performed based on GloVE, a pre-trained word vector of 300 dimensions, mapping each word to a vector in a high-dimensional space, represented as follows:

[0048] Step 2.2.2: Location embedding;

[0049] The combination of sine and cosine functions is used to generate position embeddings, enabling the model to understand the position of words in the sequence;

[0050] Step 2.2.3: Speaker embedding;

[0051] Each speaker is mapped to an embedding vector, which is then combined with word embeddings and positional embeddings;

[0052] Step 2.2.4: Integrate embedded information;

[0053] By combining word embedding, positional embedding, and speaker embedding, and adding the vectors obtained from steps 2.2.1, 2.2.2, and 2.2.3, a preliminary representation vector of the discourse is obtained. The formula is shown in equation (1);

[0054]

[0055] Among them, emb CLS The embedding vector representing the [CLS] identifier; Represents word embedding vectors; This represents the obtained position embedding vector; This represents the speaker embedding vector.

[0056] Furthermore, the specific steps of step 3.1 are as follows:

[0057] Step 3.1.1: Constructing a cognitive enhancement map

[0058] Constructing the adjacency matrix of heterogeneous graphs Indicates the relationship between different nodes;

[0059] Step 3.1.1.1: Construct heterogeneous graph nodes;

[0060] The discourse codes and knowledge codes obtained in steps 2.3 and 2.4 are selected as nodes of the heterogeneous graph, including discourse nodes, antecedent nodes, and subsequent event nodes; a [CLS] identifier is used as the target discourse node for initialization.

[0061] Step 3.1.1.2: Construct heterogeneous graph edges;

[0062] Edges of a heterogeneous graph are constructed based on the relationships between nodes, including the following three types:

[0063] An edge is constructed between any two discourse nodes to represent the fusion of discourse context; a self-loop is constructed between each node and itself; an event chain is constructed based on the common knowledge of the relationship between the cause and the subsequent events and the discourse, so that the cause-discourse-subsequent events constitute an event chain.

[0064] Step 3.1.2: Cognitive Enhancement Graph Coding;

[0065] The cognitive enhancement graph is constructed using step 3.1.1, and graph encoding is performed using a multi-layer graph attention network. The specific steps are as follows:

[0066] Step 3.1.2.1: Node Embedding Layer;

[0067] The discourse codes, antecedent common sense codes, and subsequent event common sense codes obtained in steps 2.3 and 2.4 are input into the heterogeneous graph attention network;

[0068] Step 3.1.2.2: Graph attention mechanism;

[0069] Graph attention mechanism is used to compute the value of a given node o. i The weights between the given node and its neighboring nodes are calculated using the formulas shown in equations (6) and (7); then, the given node o is updated by aggregating the feature information of its neighboring nodes. i The calculation formula is shown in equation (8);

[0070]

[0071]

[0072]

[0073] in, Indicates a given node o i Its neighboring node o j The weights between them; Represents node o i With node o j Attention scores between; Represents the i-th node; l represents the l-th layer in the multi-layer graph attention network; Represents all neighboring nodes of the i-th node; LeakyReLU represents the activation function; a, W k The weights of the linear layer are represented by K; the number of heads in the multi-head attention mechanism is represented by σ; and the non-linear activation function is represented by σ.

[0074] Step 3.1.2.3: Cognitive Enhancement of Discourse Representation;

[0075] Through the multi-layer graph attention network in step 3.1.2.2, all nodes are updated multiple times, incorporating the feature information of their neighboring nodes. Finally, the updated utterance representation V′ is generated. u Discourse representation as cognitive enhancement V cog As shown in formula (9);

[0076] V cog =V′ u (9).

[0077] Furthermore, the specific steps of step 3.2 are as follows:

[0078] Step 3.2.1: Construct a dynamic interaction graph

[0079] Constructing the adjacency matrix of heterogeneous graphs This represents the relationships between different nodes, where different values ​​in the adjacency matrix represent different types of edges; the specific construction steps are as follows:

[0080] Step 3.2.1.1: Construct heterogeneous graph nodes;

[0081] Select the cognitively enhanced discourse code V obtained in step 3.1.2.3. cog The common sense knowledge encoding obtained in step 2.4 is used as a node in the heterogeneous graph;

[0082] Step 3.2.1.2: Construct heterogeneous graph edges;

[0083] Design various types of edges based on the relationships between different nodes, including:

[0084] Propagation edge: for node v i and its subsequent node v j Construct a directed edge between v and v, where v i With v j Nodes belonging to the same type, and i≤j, are included in the graph adjacency matrix.

[0085] Transformation edges: Directed edges are constructed between different feature nodes of adjacent utterances to represent the dynamic interaction between different features, and the adjacency matrix is ​​transformed.

[0086] Alignment edges: Construct undirected edges between different features of the same utterance to fully integrate different features, ensuring consistency between features, and aligning the graph adjacency matrix.

[0087] Step 3.2.2: Dynamic Interaction Graph Encoding;

[0088] The cognitive enhancement graph is constructed using step 3.2.1, and graph encoding is performed using a multi-layer graph attention network. The specific steps are as follows:

[0089] Step 3.2.2.1: Node Embedding Layer;

[0090] The cognitively enhanced discourse code V obtained in step 3.1.2.3 cog The emotion common sense code and intention common sense code obtained in step 2.4 are input into the heterogeneous graph attention network;

[0091] Step 3.2.2.2: Graph attention mechanism;

[0092] The graph attention mechanism is improved to make it more suitable for dynamic interactions between different features. The specific steps are as follows:

[0093] Step 3.2.2.2.1: Vector comparison function;

[0094] Vector comparison functions are used to extract the differences between different vectors. The calculation formulas are shown in equations (10) and (11) respectively. The calculation formula is shown in equation (12);

[0095]

[0096] t ij =v i -v j (11)

[0097] f c (v i ,v j ) = v i ⊙v j (12)

[0098] Among them, f c (v i ,v j ) represents the comparison function; ReLU represents the ReLU activation function; W c These are the weight parameters of the linear layer; t ij Represents node v i With node v j The vector difference; ⊙ represents the Hadamard product;

[0099] Step 3.2.2.2.2: Weight calculation;

[0100] First, for each node’s neighboring nodes, the attention weights between them are calculated, as shown in Equations (13) and (14). This is achieved by performing a linear transformation on the node features and applying an attention mechanism. This process allows the model to assign different attention weights to each node’s neighbors to distinguish the importance between different nodes. Furthermore, the output of the vector comparison function in step 3.2.2.2.1 is used to enhance the feature representation of the nodes by the differences and correlations between adjacent nodes.

[0101]

[0102]

[0103] in, Indicates a given node v i Its neighboring node v j The weights between them; Indicates a given node v i Its neighboring node v j The weights between the comparison functions;

[0104] Step 3.2.2.2.3: Weighted aggregation;

[0105] As shown in formula (15), the calculated attention weights are used to perform a weighted average or weighted summation on the neighbor features of the node, thereby aggregating the information of the neighbor nodes.

[0106]

[0107] Finally, the updated emotion common sense node vector and intention common sense encoding node vector are represented as follows: and

[0108] Furthermore, the specific steps of step 4 are as follows:

[0109] Step 4.1: Training process based on cross-entropy loss function;

[0110] To more accurately understand the emotions and intentions of both parties in a conversation, a multi-task learning approach is adopted. An auxiliary task for classifying emotions and intentions is designed, and the loss value is calculated based on the cross-entropy loss function to train the model.

[0111] Step 4.1.1: Predicting Emotion and Intention Labels;

[0112] Using the emotion node vector output in step 3.2.2.2.3 With the intent node vector First, the vector is passed through a linear layer to reduce its dimensionality, mapping it to a 32-dimensional vector and an 8-dimensional vector, corresponding to 32 categories of emotion and 8 categories of intention. Then, the resulting vector is input into the Softmax layer to convert it into a probability distribution, and the calculation formulas are shown in Equations (16) and (17).

[0113]

[0114]

[0115] Among them, P emotion (e i P represents the probability distribution of emotion categories; intent (a i ) represents the probability distribution of the intention classification; e i This represents the sentiment label of the i-th statement; a i The intent label represents the i-th statement; softmax represents the softmax activation function; W e W a This represents the weight parameters of the linear layer;

[0116] Step 4.1.2: Cross-entropy loss;

[0117] The difference between the predicted probability distribution and the true probability distribution is calculated using the cross-entropy loss function. The loss function calculation method is shown in Equations (18), (19) and (20).

[0118]

[0119]

[0120]

[0121] in, The loss function represents the emotion classification task; The loss function representing the intent classification task; The loss function representing the overall loss of the classification task;

[0122] During the training process using cross-entropy loss, a self-decay strategy is adopted for the learning rate. The initial value of the warm-up learning rate is set to 10000, and the parameters are optimized using the Adam optimizer. After each epoch of training, the current model's fit is validated on the validation set. During the validation process, the model does not perform reverse iteration updates and the optimal model is saved. Finally, the accuracy of emotion classification and intent classification are used as evaluation metrics on the validation set to visualize the model's performance.

[0123] Step 4.2: Training process based on negative log-likelihood function;

[0124] To better measure the difference between the probability distribution generated by the model and the distribution of the actual target text, and to continuously optimize the model using this difference, a negative log-likelihood function is used to calculate the loss value in the text generation stage, and cognitive enhancement graphs are utilized. The output vector and dynamic interaction graph The vector output from the middle, and the first m words generated, are used to predict the probability distribution of the next word. The calculation formula is shown in Equation (21).

[0125]

[0126] in, The loss function representing the generation task; y m This represents the m-th word to be generated; M represents the number of words to be generated; y represents the generated response text; y <m This represents the first m words that have been generated;

[0127] Step 4.3: The training process for multi-task learning;

[0128] To achieve a balance among multiple tasks, the loss values ​​obtained in steps 4.1 and 4.2 are weighted and summed to obtain the final loss function.

[0129]

[0130] Where λ1 and λ2 represent two loss values, respectively. The corresponding weights;

[0131] Step 4.4: During the training process, the model is first trained using the training set data. After each training epoch, the current model's fit is verified on the validation set. The model does not perform reverse iteration updates during the validation process. PPL, Dist-1, Dist-2, Emotion-Acc, and Intent-Acc are used as evaluation metrics on the validation set to visualize the model's performance and save the optimal model. PPL is used to measure the fluency of the generated text, Dist-1 and Dist-2 are used to measure the diversity and richness of the generated text, Emotion-Acc is used to measure the accuracy of emotion classification, and Intent-Acc is used to measure the accuracy of intent classification.

[0132] Step 4.5: Finally, use the data in the test set to test the optimal model and obtain the test results of the test set on the evaluation metrics of PPL, Dist-1, Dist-2, Emotion-Acc, and Intent-Acc.

[0133] The beneficial effects of adopting the above technical solution are as follows: The empathic response generation method based on dynamic interaction of discourse-level features provided by this invention enables computer systems to understand, recognize, and simulate human emotions through artificial intelligence and natural language processing methods, and to respond in an emotional, considerate, and understanding manner. This invention models the dynamic interaction of discourse-level features in empathic dialogues, enhances the cognitive and emotional understanding of the discourse context through a contextualized common-sense inference engine, and captures the interaction of emotional and intentional features in the context with fine granularity by constructing a two-stage heterogeneous graph attention network, thereby obtaining more detailed and comprehensive semantic features. During the model training phase, multiple auxiliary tasks are designed to enhance the in-depth understanding of the discourse context, more accurately identify the emotional flow in the discourse, and thus achieve generated response texts that are more context-appropriate, better understand the user's situation and emotions, and can achieve emotional resonance with the user. The method of this invention can accurately identify and understand the emotions and feelings input by users, including joy, sadness, anger, etc., thereby better responding to users' emotional needs; the responses generated by this invention should be grammatically and logically context-appropriate, natural and fluent, making the responses more readable and understandable; the responses of this invention need to match the emotions input by users and respond with corresponding emotions and tones, thereby conveying empathy and understanding; this invention can adapt to different fields, contexts and cultural backgrounds in order to more comprehensively understand and respond to users' emotional needs. Attached Figure Description

[0134] Figure 1 This is a schematic diagram of the empathic dialogue model structure provided in an embodiment of the present invention. Detailed Implementation

[0135] 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.

[0136] This embodiment constructs a two-stage heterogeneous graph attention network, which enhances the understanding of cognition within the discourse context by fusing event chains and realizes dynamic interaction of discourse-level features. It effectively integrates multiple feature information and enhances the understanding of user emotions through auxiliary tasks such as sentiment classification and intent classification, making the generated response text more empathetic. Figure 1 The diagram shown is a model diagram of the method in this embodiment. The specific method of this embodiment is described below.

[0137] Step 1: Dataset Acquisition and Preprocessing; Specific steps are as follows:

[0138] Step 1.1: Dataset Acquisition;

[0139] We obtained an open-source dataset for the empathic response generation task and split it into training, validation, and test sets. Each sample data includes a dialogue history D and a target response text Y = u. res The dialogue history D includes N-1 utterances, where D = [u1, u2, ..., u...]. N-1 ], every word i Including m words, represented as u i =[w1,w2,…,w m ];

[0140] Step 1.2: Fine-grained automatic annotation of emotions and intentions;

[0141] Automatic emotion and intent labels are applied to all samples in the training set, validation set, and test set in step 1.1. Fine-grained emotion or intent labels will be used in subsequent multi-task learning.

[0142] Step 1.2.1: Construct a 32-class emotion classifier and an 8-class intention classifier based on the RoBERTa model;

[0143] Step 1.2.2: Use an emotion classifier and an intention classifier to classify the emotion and intention of each utterance. For each dialogue, obtain the emotion label E = [e1, e2, ..., e...]. N-1 ,e res ] and intent label A = [a1, a2, ..., a N-1 ,a res ].

[0144] Step 1.3: Contextualized common-sense reasoning;

[0145] For each utterance in the dialogue history D i The DIALeCT contextualized common sense reasoning engine is used to perform common sense reasoning and obtain contextualized common sense knowledge. It involves four types of common sense knowledge: antecedent, subsequent events, emotional reaction, and intention to respond.

[0146] Step 1.3.1: For each utterance u i Design fill template Among them, question r This represents one of the four types of common sense knowledge. <sep>Indicates a separator;

[0147] Step 1.3.2: Preprocess the dataset by converting it into a format that the DIALeCT model can input according to the filling template;

[0148] Step 1.3.3: Input the processed data into the DIALeCT model to obtain contextualized common sense knowledge.

[0149] Step 2: Encoding discourse and common sense knowledge;

[0150] Dialogue u based on Transformer encoder i And the acquired contextualized common sense knowledge Encode and map to a vector;

[0151] Step 2.1: Insert a special identifier [CLS] at the beginning of each input sequence to capture utterance-level feature representations;

[0152] Step 2.2: Perform word embedding on the dialogue text obtained in Step 2.1, and introduce position embedding and speaker embedding to obtain a preliminary representation vector of the discourse, capturing contextual information and the identity of the speakers;

[0153] Step 2.2.1: Word embedding;

[0154] Word embedding is performed based on GloVE, a pre-trained word vector of 300 dimensions, mapping each word to a vector in a high-dimensional space, represented as follows:

[0155] Step 2.2.2: Location embedding;

[0156] Since the Transformer model does not consider word order, it needs positional embeddings to provide information about the position of words in the sequence. Positional embeddings are generated using a combination of sine and cosine functions, enabling the model to understand the position of words in the sequence.

[0157] Step 2.2.3: Speaker embedding;

[0158] In multi-turn dialogues, the contexts of different speakers may differ, so introducing speaker embeddings helps the model distinguish between different speakers. Each speaker is mapped to an embedding vector, which is then combined with word embeddings and position embeddings; this helps the model better understand the context and speaker variations in the dialogue.

[0159] Step 2.2.4: Integrate embedded information;

[0160] Combining word embeddings, positional embeddings, and speaker embeddings can be achieved through simple addition or concatenation. This fusion allows the model to consider word semantics, position, and speaker information when processing dialogue. In this embodiment, the vectors obtained from steps 2.2.1, 2.2.2, and 2.2.3 are added together to obtain the preliminary representation vector of the utterance. The formula is shown in equation (1);

[0161]

[0162] Among them, emb CLS The embedding vector representing the [CLS] identifier; Represents word embedding vectors; This represents the obtained position embedding vector; This represents the speaker embedding vector.

[0163] Step 2.3: Speech Encoder;

[0164] Based on the Transformer encoder, as shown in Equations (2) and (3), the representation vector obtained in step 2.2 is input into the encoder for encoding, and the encoded [CLS] identifier is used as the representation of the entire utterance;

[0165]

[0166]

[0167] in, The vector represents the initial representation of the utterance; the encoder represents the encoder. Let represent the representation vector of all words in the i-th utterance. The representation vector representing the position of the [CLS] identifier in the i-th utterance is used to represent the representation vector of the entire utterance.

[0168] Step 2.4: Encoding common sense knowledge;

[0169] Similar to the speech encoder, as shown in Equations (4) and (5), based on the Transformer encoder, the representation vector obtained in step 2.2 is input into the encoder, and finally the encoded vector is input into the average hidden layer to obtain the knowledge representation vector.

[0170]

[0171]

[0172] Where MEAN represents the average hidden layer; The vector representing the common sense knowledge of the r-th type of common sense in the i-th statement; This represents the common sense knowledge representation vector after dimensionality reduction through the average hidden layer.

[0173] Step 3: Construct a two-stage heterogeneous graph attention network;

[0174] Step 3.1: Cognitive Enhancement Map;

[0175] A multi-layer heterogeneous graph attention network is employed, selecting common-sense knowledge and utterances from dialogue history related to cognition as nodes. Various types of edges are designed based on the relationships between different nodes. The feature information between different nodes is aggregated through a graph attention mechanism to obtain cognitively enhanced utterance encoding. The specific steps for graph encoding using a heterogeneous graph attention network are as follows:

[0176] Step 3.1.1: Constructing a cognitive enhancement map

[0177] Constructing the adjacency matrix of heterogeneous graphs Indicates the relationship between different nodes;

[0178] Step 3.1.1.1: Construct heterogeneous graph nodes;

[0179] The discourse codes and knowledge codes obtained in steps 2.3 and 2.4 are selected as nodes of the heterogeneous graph, including discourse nodes, antecedent nodes, and subsequent event nodes; a [CLS] identifier is used as the target discourse node for initialization.

[0180] Step 3.1.1.2: Construct heterogeneous graph edges;

[0181] Edges of a heterogeneous graph are constructed based on the relationships between nodes, including the following three types:

[0182] An edge is constructed between any two discourse nodes to represent the fusion of discourse context; a self-loop is constructed between each node and itself; an event chain is constructed based on the common knowledge of the relationship between the cause and the subsequent events and the discourse, so that the cause-discourse-subsequent events constitute an event chain.

[0183] Step 3.1.2: Cognitive Enhancement Graph Coding;

[0184] The cognitive enhancement graph is constructed using step 3.1.1, and graph encoding is performed using a multi-layer graph attention network. The specific steps are as follows:

[0185] Step 3.1.2.1: Node Embedding Layer;

[0186] The discourse codes, antecedent common sense codes, and subsequent event common sense codes obtained in steps 2.3 and 2.4 are input into the heterogeneous graph attention network;

[0187] Step 3.1.2.2: Graph attention mechanism;

[0188] Graph attention mechanism is used to compute the value of a given node o. i The weights between the given node and its neighboring nodes are calculated using the formulas shown in equations (6) and (7); then, the given node o is updated by aggregating the feature information of its neighboring nodes. i The calculation formula is shown in equation (8);

[0189]

[0190]

[0191]

[0192] in, Indicates a given node o i Its neighboring node o j The weights between them; Represents node o i With node o j Attention scores between; Represents the i-th node; l represents the l-th layer in the multi-layer graph attention network; Represents all neighboring nodes of the i-th node; LeakyReLU represents the activation function; a, W k σ represents the weight parameters of the linear layer; K represents the number of heads in the multi-head attention mechanism; σ represents the non-linear activation function.

[0193] Step 3.1.2.3: Cognitive Enhancement of Discourse Representation;

[0194] Through the multi-layer graph attention network in step 3.1.2.2, all nodes are updated multiple times, incorporating the feature information of their neighboring nodes. Finally, the updated utterance representation V′ is generated. u Discourse representation as cognitive enhancement V cog As shown in formula (9);

[0195] V cog =V′ u (9)

[0196] Step 3.2: Dynamic Interactive Graph;

[0197] A multi-layer heterogeneous graph attention network and an improved graph attention mechanism are used to simulate the dynamic interaction between different utterances and features:

[0198] Step 3.2.1: Construct a dynamic interaction graph

[0199] Constructing the adjacency matrix of heterogeneous graphs This represents the relationships between different nodes, where different values ​​in the adjacency matrix represent different types of edges; the specific construction steps are as follows:

[0200] Step 3.2.1.1: Construct heterogeneous graph nodes;

[0201] Select the cognitively enhanced discourse code V obtained in step 3.1.2.3. cog The common sense knowledge encoding obtained in step 2.4 is used as a node in the heterogeneous graph;

[0202] Step 3.2.1.2: Construct heterogeneous graph edges;

[0203] Design various types of edges based on the relationships between different nodes, including:

[0204] Propagation Edge: To better simulate the hierarchical structure and sequential nature of dialogue, a propagation edge is constructed between nodes representing the three features of cognition, emotion, and intention. Since dialogue is temporal, subsequent utterances are influenced by previous utterances; therefore, for node v... i and its subsequent node v j Construct a directed edge between v and v, where v i With v j Nodes belonging to the same type, and i≤j, are included in the graph adjacency matrix.

[0205] Transformation edges: Directed edges are constructed between different feature nodes of adjacent utterances to represent the dynamic interaction between different features, and the adjacency matrix is ​​transformed.

[0206] Alignment edges: The same utterance may possess different features, including cognitive, emotional, and intentional characteristics, but the information it conveys remains consistent. Therefore, constructing undirected edges between different features of the same utterance allows for full integration of these features, ensuring consistency. This is achieved by aligning the graph adjacency matrix...

[0207] Step 3.2.2: Dynamic Interaction Graph Encoding;

[0208] The cognitive enhancement graph is constructed using step 3.2.1, and graph encoding is performed using a multi-layer graph attention network. The specific steps are as follows:

[0209] Step 3.2.2.1: Node Embedding Layer;

[0210] The cognitively enhanced discourse code V obtained in step 3.1.2.3 cog The emotion common sense code and intention common sense code obtained in step 2.4 are input into the heterogeneous graph attention network;

[0211] Step 3.2.2.2: Graph attention mechanism;

[0212] Unlike traditional graph attention mechanisms, which have limitations due to the different properties of edges of different types in dynamic interactive graphs, this paper proposes an improved graph attention mechanism to better suit dynamic interactions between different features. The specific steps are as follows:

[0213] Step 3.2.2.2.1: Vector comparison function;

[0214] Vector comparison functions are used to extract the differences between different vectors. The calculation formulas are shown in equations (10) and (11) respectively. The calculation formula is shown in equation (12);

[0215]

[0216] t ij =v i -v j (11)

[0217] f c (v i ,v j ) = v i ⊙v j (12)

[0218] Among them, f c (v i ,v j ) represents the comparison function; ReLU represents the ReLU activation function; W c These are the weight parameters of the linear layer; t ij Represents node v i With node v j The vector difference; ⊙ represents the Hadamard product.

[0219] Step 3.2.2.2.2: Weight calculation;

[0220] First, for each node’s neighboring nodes, the attention weights between them are calculated, as shown in Equations (13) and (14). This is achieved by performing a linear transformation on the node features and applying an attention mechanism. This process allows the model to assign different attention weights to each node’s neighbors to distinguish the importance between different nodes. Furthermore, the output of the vector comparison function in step 3.2.2.2.1 is used to enhance the feature representation of the nodes by the differences and correlations between adjacent nodes.

[0221]

[0222]

[0223] in, Indicates a given node v i Its neighboring node v j The weights between them; Indicates a given node v i Its neighboring node v j The weights between the comparison functions.

[0224] Step 3.2.2.2.3: Weighted aggregation;

[0225] As shown in formula (15), the calculated attention weights are used to perform a weighted average or weighted summation on the neighbor features of the node, thereby aggregating the information of the neighbor nodes. This step can effectively integrate the information of different nodes and pay more attention to the neighbor nodes with higher weights, while also paying attention to the correlation between adjacent nodes to simulate the interaction of features.

[0226]

[0227] Finally, the updated emotion common sense node vector and intention common sense encoding node vector are represented as follows: and

[0228] Step 4: Model training process, including sentiment and intent prediction based on the cross-entropy loss function, and empathic text generation based on the negative log-likelihood function. The specific steps are as follows:

[0229] Step 4.1: Training process based on cross-entropy loss function;

[0230] To more accurately understand the emotions and intentions of both parties in a conversation, a multi-task learning approach is adopted. An auxiliary task for classifying emotions and intentions is designed, and the loss value is calculated based on the cross-entropy loss function to train the model.

[0231] Step 4.1.1: Predicting Emotion and Intention Labels;

[0232] Using the emotion node vector output in step 3.2.2.2.3 With the intent node vector First, the vector is passed through a linear layer to reduce its dimensionality, mapping it to a 32-dimensional vector and an 8-dimensional vector, corresponding to 32 categories of emotion and 8 categories of intention. Then, the resulting vector is input into the Softmax layer to convert it into a probability distribution, and the calculation formulas are shown in Equations (16) and (17).

[0233]

[0234]

[0235] Among them, P emotion (e i P represents the probability distribution of emotion categories; internt (a i ) represents the probability distribution of the intention classification; e i This represents the sentiment label of the i-th statement; a i The intent label represents the i-th statement; softmax represents the softmax activation function; W e W a This represents the weight parameters of the linear layer.

[0236] Step 4.1.2: Cross-entropy loss;

[0237] The difference between the predicted probability distribution and the true probability distribution is calculated using the cross-entropy loss function. The loss function calculation method is shown in Equations (18), (19) and (20).

[0238]

[0239]

[0240]

[0241] in, The loss function represents the emotion classification task; The loss function representing the intent classification task; The loss function represents the overall loss function for the classification task.

[0242] During the training process using cross-entropy loss, a self-decay strategy is adopted for the learning rate. The initial value of the warm-up learning rate is set to 10000, and the parameters are optimized using the Adam optimizer. After each training epoch, the current model's fit is validated on the validation set. During the validation process, the model does not perform reverse iteration updates and the optimal model is saved. Finally, the accuracy of emotion classification and intent classification are used as evaluation metrics on the validation set to visualize the model's performance.

[0243] Step 4.2: Training process based on negative log-likelihood function;

[0244] To better measure the difference between the probability distribution generated by the model and the distribution of the actual target text, and to continuously optimize the model using this difference, a negative log-likelihood function is used to calculate the loss value in the text generation stage, and cognitive enhancement graphs are utilized. The output vector and dynamic interaction graph The vector output from the middle, and the first m words generated, are used to predict the probability distribution of the next word. The calculation formula is shown in Equation (21).

[0245]

[0246] in, The loss function representing the generation task; y m This represents the m-th word to be generated; M represents the number of words to be generated; y represents the generated response text; y <m This represents the first m words that have been generated.

[0247] Step 4.3: The training process for multi-task learning;

[0248] Emotion and intention label prediction is an auxiliary task designed in this invention to make the implied emotions and intentions in utterances more controllable. To achieve a balance among multiple tasks, the loss values ​​obtained in steps 4.1 and 4.2 are weighted and summed to obtain the final loss function.

[0249]

[0250] Where λ1 and λ2 represent two loss values, respectively. The corresponding weights;

[0251] Step 4.4: During the training process, the model is first trained using the training set data. After each training epoch, the current model's fit is verified on the validation set. The model does not perform reverse iteration updates during the validation process. PPL, Dist-1, Dist-2, Emotion-Acc, and Intent-Acc are used as evaluation metrics on the validation set to visualize the model's performance and save the optimal model. PPL (Perplexity) is used to measure the fluency of the generated text, Dist-1 and Dist-2 are used to measure the diversity and richness of the generated text, Emotion-Acc is used to measure the accuracy of emotion classification, and Intent-Acc is used to measure the accuracy of intent classification.

[0252] Step 4.5: Finally, use the data in the test set to test the optimal model and obtain the test results of the test set on the evaluation metrics of PPL, Dist-1, Dist-2, Emotion-Acc, and Intent-Acc.

[0253] This embodiment models the dynamic interaction of discourse-level features in empathic dialogues. It enhances the cognitive and emotional understanding of the discourse context through a contextualized commonsense inferencer, and captures the interaction of emotional and intentional features within the context with fine granularity by constructing a two-stage heterogeneous graph attention network, thus obtaining more detailed and comprehensive semantic features. During the model training phase, multiple auxiliary tasks are designed to enhance the in-depth understanding of the discourse context and more accurately identify the emotional flow within the discourse. This results in generated response texts that are more context-appropriate, better understand the user's situation and emotions, and achieve emotional resonance with the user.

[0254] 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.< / sep> < / sep>

Claims

1. A method for generating empathic responses based on dynamic interaction of discourse-level features, characterized in that: Includes the following steps: Step 1: Dataset Acquisition and Preprocessing; We obtained an open-source dataset for the empathic response generation task, and split the dataset into training, validation, and test sets. Each sample data includes a dialogue history D and a target response text. = Automatically label emotions and intentions for all samples in the training, validation, and test sets; for dialogue history... Every word in The DIALeCT contextualized common sense reasoning engine is used to perform common sense reasoning and obtain contextualized common sense knowledge. ; Step 2: Encoding discourse and common sense knowledge; Dialogue based on Transformer encoder And the acquired contextualized common sense knowledge Encode and map to a vector; Step 3: Construct a two-stage heterogeneous graph attention network, including a cognitive enhancement graph and a dynamic interaction graph; Step 3.1: Cognitive Enhancement Map; A multi-layer heterogeneous graph attention network is adopted, and common sense knowledge and utterances in dialogue history related to cognition are selected as nodes. Various types of edges are designed according to the correlation between different nodes. The feature information between different nodes is aggregated through graph attention mechanism to obtain cognitively enhanced utterance encoding. Step 3.2: Dynamic Interactive Graph; A multi-layer heterogeneous graph attention network and an improved graph attention mechanism are used to simulate the dynamic interaction between different utterances and features; the specific steps are as follows: Step 3.2.1: Construct a dynamic interaction graph ; Constructing the adjacency matrix of heterogeneous graphs The adjacency matrix represents the relationships between different nodes, with different values ​​representing different types of edges. The specific construction steps are as follows: Step 3.2.1.1: Construct heterogeneous graph nodes; Select the cognitively enhanced discourse code obtained in step 3.1.2.

3. The common sense knowledge encoding obtained in step 2.4 is used as a node in the heterogeneous graph; Step 3.2.1.2: Construct heterogeneous graph edges; Design various types of edges based on the relationships between different nodes, including: Propagation edge: for nodes and its subsequent nodes Construct a directed edge between them, where and Nodes belonging to the same type, and and the graph adjacency matrix ; Transformation edges: Directed edges are constructed between different feature nodes of adjacent utterances to represent the dynamic interaction between different features, and the adjacency matrix is ​​transformed. ; Alignment edges: Construct undirected edges between different features of the same utterance to fully integrate different features, ensuring consistency between features, and aligning the graph adjacency matrix. ; Step 3.2.2: Dynamic Interaction Graph Encoding; The cognitive enhancement graph is constructed using step 3.2.1, and graph encoding is performed using a multi-layer graph attention network. The specific steps are as follows: Step 3.2.2.1: Node Embedding Layer; Encode the cognitively enhanced discourse obtained in step 3.1.2.3 The emotion common sense code and intention common sense code obtained in step 2.4 are input into the heterogeneous graph attention network; Step 3.2.2.2: Graph attention mechanism; The graph attention mechanism is improved to make it more suitable for dynamic interactions between different features. The specific steps are as follows: Step 3.2.2.2.1: Vector comparison function; Vector comparison functions are used to extract the differences between different vectors. The calculation formulas are shown in equations (10) and (11) respectively. The calculation formula is shown in equation (12); (10); (11); (12); in, This represents a comparison function; These are the weight parameters of the linear layer; Represents a node The vector difference; It represents the Hadamardi (or Hadama) stack; Step 3.2.2.2.2: Weight calculation; First, for each node’s neighboring nodes, the attention weights between them are calculated, as shown in Equations (13) and (14). This is achieved by performing a linear transformation on the node features and applying an attention mechanism. This process allows the model to assign different attention weights to each node’s neighbors to distinguish the importance between different nodes. Furthermore, the output of the vector comparison function in step 3.2.2.2.1 is used to enhance the feature representation of the nodes by the differences and correlations between adjacent nodes. (13); (14); in, Represents a given node Its neighboring nodes The weights between them; Represents a given node Its neighboring nodes The weights between the comparison functions; Step 3.2.2.2.3: Weighted aggregation; As shown in formula (15), the calculated attention weights are used to perform a weighted average or weighted summation on the neighbor features of the node, thereby aggregating the information of the neighbor nodes; (15); in, This represents the weight parameters of the linear layer; Finally, the updated emotion common sense node vector and intention common sense encoding node vector are represented as follows: and ; Step 4: Model training process, including sentiment and intent prediction based on cross-entropy loss function and empathic text generation based on negative log-likelihood function, and weighted summation of the two training processes; after training, save the optimal model, and test it on the optimal model using data from the test set.

2. The empathic response generation method based on dynamic interaction with discourse-level features according to claim 1, characterized in that: Step 1 includes the following steps: Step 1.1: Dataset Acquisition; We obtained an open-source dataset for the empathic response generation task and split it into training, validation, and test sets; each sample data includes a dialogue history. and a target reply text = Dialogue History Including multiple statements, Every word Including multiple words, represented as ; Step 1.2: Fine-grained automatic annotation of emotions and intentions; Automatically label all samples in the training, validation, and test sets from step 1.1 with sentiment and intent. These fine-grained sentiment or intent labels will be used in subsequent multi-task learning. The specific method is as follows: Step 1.2.1: Construct a 32-class emotion classifier and an 8-class intention classifier based on the RoBERTa model; Step 1.2.2: Use an emotion classifier and an intention classifier to classify the emotion and intention of each utterance, respectively. For each dialogue, obtain the emotion label. and intent label A= ; Step 1.3: Contextualized common-sense reasoning; For the history of dialogue Every word in The DIALeCT contextualized common sense reasoning engine is used to perform common sense reasoning and obtain contextualized common sense knowledge. It involves four types of common sense knowledge: antecedent, subsequent events, emotional reaction, and intention in responding; the specific method is as follows: Step 1.3.1: For each statement Design fill template ,in This represents one of the four types of common sense knowledge. Indicates a separator; Step 1.3.2: Preprocess the dataset by converting it into a format that the DIALeCT model can input according to the filling template; Step 1.3.3: Input the processed data into the DIALeCT model to obtain contextualized common sense knowledge. .

3. The empathic response generation method based on dynamic interaction with discourse-level features according to claim 2, characterized in that: Step 2 includes the following steps: Step 2.1: Insert a special identifier at the beginning of each input sequence. , used to capture discourse-level feature representations; Step 2.2: Perform word embedding processing on the dialogue text obtained in Step 2.1, and introduce position embedding and speaker embedding to obtain a preliminary representation vector of the discourse, capturing contextual information and the identity of the speakers; Step 2.3: Speech Encoder; Based on the Transformer encoder, as shown in equations (2) and (3), the representation vector obtained in step 2.2 is input into the encoder for encoding, and the encoded vector is then... Identifiers serve as representations of the entire utterance; (2); (3); in, The vector represents the initial representation of the utterance; the encoder represents the encoder. Let represent the representation vector of all words in the i-th utterance. The representation vector representing the position of the [CLS] identifier in the i-th utterance, used to represent the representation vector of the entire utterance; Step 2.4: Encoding common sense knowledge; Similar to the speech encoder, as shown in Equations (4) and (5), based on the Transformer encoder, the representation vector obtained in step 2.2 is input into the encoder, and finally the encoded vector is input into the average hidden layer to obtain the knowledge representation vector; (4); (5); in, The vector representing the common sense knowledge of the r-th type of common sense in the i-th statement; denoted as the common sense knowledge representation vector after dimensionality reduction by the average hidden layer, and MEAN represents the average hidden layer.

4. The empathic response generation method based on dynamic interaction with discourse-level features according to claim 3, characterized in that: The specific method for step 2.2 is as follows: Step 2.2.1: Word embedding; Word embedding is performed based on GloVE, a pre-trained word vector of 300 dimensions, mapping each word to a vector in a high-dimensional space, represented as follows: ; Step 2.2.2: Location embedding; The combination of sine and cosine functions is used to generate position embeddings, enabling the model to understand the position of words in the sequence; Step 2.2.3: Speaker embedding; Each speaker is mapped to an embedding vector, which is then combined with word embeddings and positional embeddings; Step 2.2.4: Integrate embedded information; By combining word embedding, positional embedding, and speaker embedding, and adding the vectors obtained from steps 2.2.1, 2.2.2, and 2.2.3, a preliminary representation vector of the discourse is obtained. , which means the formula is shown in equation (1); (1); in, The embedding vector representing the [CLS] identifier; Represents word embedding vectors; This represents the obtained position embedding vector; This represents the speaker embedding vector.

5. The empathic response generation method based on dynamic interaction with discourse-level features according to claim 1, characterized in that: The specific steps of step 3.1 are as follows: Step 3.1.1: Constructing a cognitive enhancement map ; Constructing the adjacency matrix of heterogeneous graphs This represents the relationship between different nodes; Step 3.1.1.1: Construct heterogeneous graph nodes; The discourse codes and knowledge codes obtained in steps 2.3 and 2.4 are selected as nodes of the heterogeneous graph, including discourse nodes, antecedent nodes, and subsequent event nodes; a [CLS] identifier is used as the target discourse node for initialization. Step 3.1.1.2: Construct heterogeneous graph edges; Edges of a heterogeneous graph are constructed based on the relationships between nodes, including the following three types: An edge is constructed between any two discourse nodes to represent the fusion of discourse context; a self-loop is constructed between each node and itself. Event chain: Based on common sense knowledge of the relationship between antecedents and subsequent events and discourses, construct the edges related to the event chain so that antecedent-discourse-subsequent event constitute an event chain. Step 3.1.2: Cognitive Enhancement Graph Coding; The cognitive enhancement graph is constructed using step 3.1.1, and graph encoding is performed using a multi-layer graph attention network. The specific steps are as follows: Step 3.1.2.1: Node Embedding Layer; The discourse codes, antecedent common sense codes, and subsequent event common sense codes obtained in steps 2.3 and 2.4 are input into the heterogeneous graph attention network; Step 3.1.2.2: Graph attention mechanism; Graph attention mechanism is used to compute a given node The weights between the node and its adjacent nodes are calculated using the formulas shown in equations (6) and (7); Then, the given node is updated by aggregating the feature information of neighboring nodes. The calculation formula is shown in equation (8); (6); (7); (8); in, Represents a given node Its neighboring nodes The weights between them; Indicates the first One node; Represents the first in a multi-layer graph attention network layer; Indicates the first All neighboring nodes of a node; Indicates the activation function; This represents the weight parameters of the linear layer; Indicates the number of heads in a multi-head attention mechanism; Represents a non-linear activation function; Step 3.1.2.3: Cognitive Enhancement of Discourse Representation; Through the multi-layer graph attention network in step 3.1.2.2, all nodes are updated multiple times, incorporating the feature information of their neighboring nodes, and finally the updated utterance representation is... Discourse Representation as Cognitive Enhancement ; (9)。 6. The empathic response generation method based on dynamic interaction with discourse-level features according to claim 1, characterized in that: The specific steps of step 4 are as follows: Step 4.1: Training process based on cross-entropy loss function; To more accurately understand the emotions and intentions of both parties in a conversation, a multi-task learning approach is adopted. An auxiliary task for classifying emotions and intentions is designed, and the loss value is calculated based on the cross-entropy loss function to train the model. Step 4.1.1: Predicting Emotion and Intention Labels; Using the emotion node vector output in step 3.2.2.2.3 With the intent node vector First, the vector is passed through a linear layer to reduce its dimensionality, mapping it to 32-dimensional and 8-dimensional vectors respectively, corresponding to 32 categories of emotion and 8 categories of intention; then, the resulting vector is input into... In the layer, it is converted into a probability distribution, and the calculation formula is shown in Equation (16) and Equation (17); (16); (17); in, The probability distribution representing the emotion category; Indicates the first The sentiment tag of each sentence; Indicates the first The intent label of the statement; express Activation function; , This represents the weight parameters of the linear layer; Step 4.1.2: Cross-entropy loss; The difference between the predicted probability distribution and the true probability distribution is calculated using the cross-entropy loss function. The loss function calculation method is shown in Equations (18), (19) and (20). (18); (19); (20); in, The loss function represents the emotion classification task; The loss function representing the intent classification task; The loss function representing the overall loss of the classification task; During the training process using cross-entropy loss, a self-decay strategy is adopted for the learning rate. The initial value of the warm-up learning rate is set to 10000, and the parameters are optimized using the Adam optimizer. After each epoch of training, the current model's fit is validated on the validation set. During the validation process, the model does not perform reverse iteration updates and the optimal model is saved. Finally, the accuracy of emotion classification and intent classification are used as evaluation metrics on the validation set to visualize the model's performance. Step 4.2: Training process based on negative log-likelihood function; To better measure the difference between the probability distribution generated by the model and the distribution of the actual target text, and to continuously optimize the model using this difference, a negative log-likelihood function is used to calculate the loss value in the text generation stage, and cognitive enhancement graphs are utilized. The output vector and dynamic interaction graph The output vector, and the generated first The probability distribution of the next word is predicted using the given words, and the calculation formula is shown in equation (21). (21); in, The loss function representing the generation task; Indicates the number to be generated One word; Indicates the number of words to be generated; The generated response text; Indicates the previous generation One word; Step 4.3: The training process for multi-task learning; To achieve a balance among multiple tasks, the loss values ​​obtained in steps 4.1 and 4.2 are weighted and summed to obtain the final loss function. : (22); in, , These represent two loss values. The corresponding weights; Step 4.4: During the training process, the model is first trained using the training set data. After each training epoch, the current model's fit is verified on the validation set. The model does not perform reverse iteration updates during the validation process. PPL, Dist-1, Dist-2, Emotion-Acc, and Intent-Acc are used as evaluation metrics on the validation set to visualize the model's performance and save the optimal model. PPL is used to measure the fluency of the generated text, Dist-1 and Dist-2 are used to measure the diversity and richness of the generated text, Emotion-Acc is used to measure the accuracy of emotion classification, and Intent-Acc is used to measure the accuracy of intent classification. Step 4.5: Finally, use the data in the test set to test the optimal model and obtain the test results of the test set on the evaluation metrics of PPL, Dist-1, Dist-2, Emotion-Acc, and Intent-Acc.