Response generation methods, apparatus, and electronic devices for generating empathic responses.

By constructing the ININ model to simulate the state updates of users and intelligent agents, the problem of inaccurate empathic responses in existing technologies is solved, and more accurate empathic response generation is achieved, thus improving the quality of human-computer interaction.

CN120012786BActive Publication Date: 2025-10-31NAT UNIV OF DEFENSE TECH
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510178096.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-02-18
Publication Date
2025-10-31
Estimated Expiration
2045-02-18

AI Technical Summary

Technical Problem

Existing technologies struggle to generate high-quality empathic responses because they ignore the cross-influence between users and intelligent agents, as well as subtle differences in conversations, leading to inaccurate emotion perception and state recognition.

Method used

By constructing the ININ model, which includes a context encoding module, an in-dialogue state iteration update learning module, and a response generation module, the model simulates the updates of the emotional and cognitive states of users and intelligent agents, captures their mutual influence, and generates more accurate empathetic responses.

Benefits of technology

It achieves more accurate cognitive and emotional state representation, generates empathetic responses, possesses speech-level and dialogue-level understanding capabilities, and improves the quality of human-computer interaction.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120012786B_ABST
    Figure CN120012786B_ABST
Patent Text Reader

Abstract

This invention discloses a response generation method, specifically relating to a response generation method, apparatus, and electronic device for generating empathetic responses. The method includes: inputting the historical dialogue context between a user and an intelligent agent into a context encoding module for encoding processing to obtain a context representation; using an in-dialogue state iterative update learning module to perform in-dialogue state iterative updates on the emotional state and cognitive state corresponding to each sentence in the historical dialogue context to obtain the user's final emotional state and the intelligent agent's final cognitive state; and inputting the context representation, the user's final emotional state, and the intelligent agent's final cognitive state into a response generation module to obtain a target response. This method can generate responses with better empathetic effects.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention pertains to a response generation method, specifically a response generation method, apparatus, and electronic device for generating empathic responses. Background Technology

[0002] Empathic response generation refers to the ability of a dialogue system to identify and interpret a user's cognitive and emotional state, thereby designing responses that address the user's needs and feelings. As a key task in improving dialogue quality, empathic response generation has immeasurable value in open-domain applications, such as psychological counseling and emotional support.

[0003] Most existing methods treat all utterances as a long, continuous sequence, thus inferring user state at the simulation level. These methods ignore the role distinctions between the user and the intelligent agent, as well as the subtle nuances within each utterance, leading to inaccurate emotion perception and state recognition. However, dialogue is a mutually adaptive and collaborative process; both parties influence each other's understanding and response, especially in emotion-supporting dialogues, where significant mutual influence exists in both emotion and cognition. Therefore, simply distinguishing between self and others' consciousness is insufficient; that is, modeling the user's and intelligent agent's states as independent entities without considering their cross-influences makes it difficult to obtain high-quality responses. Furthermore, at the dialogue level, existing methods also ignore the variations between dialogues with the same emotional labels. Consequently, commonly used methods in existing technologies struggle to generate responses with strong empathy. Summary of the Invention

[0004] The technical problem to be solved by the present invention is that the methods commonly used in the prior art are difficult to generate responses with good empathy. In order to solve the above problem, the present invention provides a response generation method, apparatus and electronic device for generating empathic responses.

[0005] The content of this invention includes:

[0006] In a first aspect, embodiments of the present invention provide a response generation method for generating empathic responses, comprising:

[0007] The historical dialogue context between the user and the intelligent agent is input into the context encoding module for encoding processing to obtain a context representation;

[0008] The in-dialogue state iterative update learning module is used to perform in-dialogue state iterative update on the emotional state and cognitive state corresponding to each sentence in the historical dialogue context, so as to obtain the user's final emotional state and the intelligent agent's final cognitive state.

[0009] The context representation, the user's final emotional state, and the intelligent agent's final cognitive state are input into the response generation module to obtain the target response.

[0010] Optionally, before inputting the historical dialogue context between the user and the intelligent agent into the context encoding module for encoding processing to obtain the context representation, the method further includes:

[0011] The ININ model is iteratively trained based on multiple training dialogue contexts to obtain the training response corresponding to the target training dialogue context. The multiple training dialogue contexts include the target training dialogue context. The ININ model includes the context encoding module, the in-dialogue state iterative update learning module, the response generation module, and the inter-dialogue emotion adjacency comparison learning module.

[0012] Based on the multiple training dialogue contexts, the contrast loss in the current iteration training process is determined by the inter-dialogue emotion adjacency contrast learning module, and the emotion prediction loss, generation loss and diversity loss in the current iteration training process are calculated based on the training response.

[0013] The final loss value is determined based on the contrast loss, the sentiment prediction loss, the generation loss, and the diversity loss.

[0014] The parameters of the ININ model are adjusted based on the final loss value. Training ends when the training termination condition is met, and the next iteration of training is performed when the training termination condition is not met.

[0015] Optionally, determining the contrastive loss in the current training iteration based on the multiple training dialogue contexts using the inter-dialogue emotion adjacency contrastive learning module includes:

[0016] The multiple training dialogue contexts are input into K parallel augmentation encoders to obtain K augmentation views, where K is an integer greater than 1;

[0017] Generate the emotion adjacency matrix corresponding to the K augmented views. The emotion adjacency matrix is ​​used to characterize whether the emotion labels of any two training dialogue contexts in the plurality of training dialogue contexts are the same.

[0018] Take any one of the K enhanced views as the target view, and calculate the contrast loss based on the neighbor contrast loss between each other enhanced view and the target view.

[0019] Optionally, the contrast loss is:

[0020]

[0021] in, This is the x-th enhanced view, which is the target view. For the k-th enhanced view, The embedding of the i-th training dialogue context learned for the k-th augmented view. The embedding of the j-th training dialogue context learned for the k-th augmented view. The embedding of the i-th training dialogue context learned for the x-th augmented view. The embedding of the j-th training dialogue context learned for the x-th augmented view, where N is the number of training sample data, θ(·) is the inner product function that measures similarity, and τ is the temperature coefficient. These are positive samples in two enhanced views. Dialogue C in the training batch j A collection of Indicates dialogue C j Dialogue C i They share the same emotional category.

[0022] Optionally, the step of inputting the historical dialogue context between the user and the intelligent agent into the context encoding module for encoding processing to obtain a context representation includes:

[0023] All utterances in the historical dialogue context are concatenated to obtain an input sequence, which includes a special marker to identify the start of the context input in the historical dialogue context.

[0024] The input sequence is processed using a word embedding layer and a position embedding layer to obtain the word embedding and position embedding of the input sequence;

[0025] The final vector representation is generated based on the word embedding, position embedding and role embedding. The role embedding is used to distinguish the dialogue subject in the dialogue context. The dialogue subject is either a user or an intelligent agent.

[0026] The final vector representation is input into the Transformer encoder for processing to obtain the context representation.

[0027] Optionally, the step of using the in-dialogue state iterative update learning module to perform in-dialogue state iterative updates on the emotional state and cognitive state corresponding to each sentence in the historical dialogue context, to obtain the user's final emotional state and the intelligent agent's final cognitive state, includes:

[0028] Common sense knowledge is extracted from each sentence in the historical dialogue context, and the hidden vector of the common sense knowledge is obtained. The common sense knowledge includes emotional state and cognitive state.

[0029] Using the hidden vectors of the aforementioned common-sense knowledge, an initial dialogue graph is generated through an image constructor function;

[0030] The cognitive state and the emotional state are iteratively updated based on the initial dialogue graph to obtain the cognitive state and emotional state corresponding to each utterance;

[0031] Based on the dialogue subjects in the historical dialogue context, the user's final emotional state and the intelligent agent's final cognitive state are determined.

[0032] Optionally, the iterative update of the cognitive state and the emotional state based on the initial dialogue graph to obtain the cognitive state and the emotional state corresponding to each utterance includes:

[0033] Determine the user's initial cognitive state User's initial emotional state The initial cognitive state of intelligent agents and the initial emotional state of the intelligent agent

[0034]

[0035] in, and It is randomly initialized. This indicates the cognitive state of the first sentence in the context of the historical dialogue. Enc represents the emotional state of the first sentence in the historical dialogue context. ini An initial encoder used to represent the user's cognitive and emotional states;

[0036] Based on the user's initial cognitive state The user's initial emotional state The initial cognitive state of the intelligent agent and the initial emotional state of the intelligent agent The process involves iterative updates to obtain the emotional state and cognitive state corresponding to each sentence in the historical dialogue context. The iterative update process for the cognitive state is as follows:

[0037]

[0038] in, For the current discourse U m The cognitive state, m∈(1,M], where M is the number of utterances in the historical dialogue context, ⊙ represents element-wise multiplication, and σ represents the sigmoid activation function. For the trainable weight matrix of the linear layer, This is a trainable bias term;

[0039] The iterative update process of the emotional state is as follows:

[0040]

[0041] in, For the current discourse U m emotional state, b emo W is a trainable bias term. emo This is the trainable weight matrix for the linear layer.

[0042] Secondly, embodiments of the present invention provide a response generation apparatus for generating empathic responses, comprising:

[0043] The context encoding module is used to encode the historical dialogue context between the user and the intelligent agent to obtain a context representation;

[0044] The in-dialogue state iterative update learning module is used to perform in-dialogue state iterative update on the emotional state and cognitive state corresponding to each sentence in the historical dialogue context, so as to obtain the user's final emotional state and the intelligent agent's final cognitive state.

[0045] The response generation module is used to obtain the target response based on the context representation, the user's final emotional state, and the intelligent agent's final cognitive state.

[0046] Thirdly, embodiments of the present invention provide an electronic device, including: a memory, a processor, and a program stored in the memory and executable on the processor; the processor is configured to read the program in the memory to implement the steps in the response generation method for generating empathic responses as described in the first aspect.

[0047] Fourthly, embodiments of the present invention provide a readable storage medium for storing a program, which, when executed by a processor, implements the steps of the response generation method for generating empathic responses as described in the first aspect.

[0048] The beneficial effect of this invention is that, in its embodiments, an in-dialogue state iteration update module is constructed to simulate the emotional and cognitive state updates of the user and the intelligent agent. Each sentence is treated as a continuous time node, and the states of the user and the intelligent agent are updated accordingly to simulate their interaction. By capturing the mutual influence between the user and the intelligent agent in a cross-iteration manner through the in-dialogue state iteration update module, a more accurate representation of cognitive and emotional states is achieved. This modeling of the inherent significant bidirectional influence in human-computer interaction results in a more empathetic and empathetic response. Attached Figure Description

[0049] Appendix Figure 1 A flowchart illustrating a response generation method for generating empathic responses, provided in an embodiment of the present invention;

[0050] Appendix Figure 2a A schematic diagram of the framework of the ININ model provided in an embodiment of the present invention;

[0051] Appendix Figure 2b for Figure 2a A schematic diagram of the context encoding module in the provided ININ model;

[0052] Appendix Figure 2c for Figure 2a A schematic diagram of the in-dialogue state iterative update learning module in the provided ININ model;

[0053] Appendix Figure 2d for Figure 2a A schematic diagram of the response generation module in the provided ININ model;

[0054] Appendix Figure 2e for Figure 2a A schematic diagram of the inter-dialogue emotion adjacency contrast learning module in the provided ININ model;

[0055] Appendix Figure 3 A schematic diagram of a response generation device for generating empathic responses provided in an embodiment of the present invention;

[0056] Appendix Figure 4 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention. Detailed Implementation

[0057] In this application's embodiments, the term "and / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, or B existing alone. The character " / " generally indicates that the preceding and following related objects have an "or" relationship. In this application's embodiments, the term "multiple" refers to two or more, and other quantifiers are similar. The terms "first," "second," etc., in the specification and claims of this application are used to distinguish similar objects and are not used to describe a specific order or sequence. It should be understood that such terms can be interchanged where appropriate so that embodiments of this application can be implemented in orders other than those illustrated or described herein, and the objects distinguished by "first" and "second" are generally of the same class, not limited to the number of objects. For example, the first object can be one or multiple.

[0058] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of the embodiments. Based on the embodiments of this application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of this application.

[0059] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used herein is for the purpose of describing embodiments of this application only and is not intended to limit this application.

[0060] This application provides a response generation method, apparatus, and electronic device for generating empathetic responses, aiming to generate empathetic responses with discourse-level and dialogue-level understanding capabilities.

[0061] Please see Figure 1 , Figure 1 This is a flowchart illustrating a response generation method for generating empathic responses provided in an embodiment of the present invention. The method specifically includes the following steps:

[0062] Step 101: Input the historical dialogue context between the user and the intelligent agent into the context encoding module for encoding processing to obtain the context representation;

[0063] Step 102: Use the in-dialogue state iterative update learning module to perform in-dialogue state iterative update on the emotional state and cognitive state corresponding to each sentence in the historical dialogue context, so as to obtain the user's final emotional state and the intelligent agent's final cognitive state.

[0064] Step 103: Input the context representation, the user's final emotional state, and the intelligent agent's final cognitive state into the response generation module to obtain the target response.

[0065] The response generation method for generating empathic responses provided in this application embodiment can be used to implement the task of generating empathic responses in a multi-turn dialogue system. In this embodiment, the task of generating empathic responses in a multi-turn dialogue system is transformed into a probability calculation task of generating responses based on a given historical dialogue context. Specifically, a given dialogue D can be represented as M+1 utterance sequences D = {U1,…,U...} between two speakers (denoted as user and intelligent agent). M+1 Consider D as two parts (C, Y), where C = {U1, ..., U...}. M} represents the dialogue context, i.e., the historical dialogue context, and Y represents the target response U. M+1 Every utterance in the historical dialogue context U m (m = 1, 2, ..., M) is a subset of arbitrary length N. m The labeled sequence, and the emotion category (also known as the sentiment category) e, are obtained through empathy knowledge learning. Therefore, the task of generating empathic responses can be characterized as calculating the probability P(Y|C,e) of generating a response Y based on a given historical dialogue context C.

[0066] In this embodiment, an in-dialogue state iteration update module is constructed to simulate the emotional state (also known as affective state) and cognitive state updates of the user and the intelligent agent. Each sentence is treated as a continuous time node, and the states of the user and the intelligent agent are updated accordingly to simulate their interaction. By capturing the mutual influence between the user and the intelligent agent in a cross-iteration manner through the in-dialogue state iteration update module, a more accurate representation of cognitive and emotional states is achieved. This modeling of the inherent significant bidirectional influence in human-computer interaction results in a more empathetic and empathetic response.

[0067] In some embodiments, pre-training the context encoding module, the in-dialogue state iterative update learning module, and the response generation module can enable the responses generated by this method to possess utterance-level and dialogue-level understanding capabilities. Optionally, before step 101, the method further includes:

[0068] The ININ model is iteratively trained based on multiple training dialogue contexts to obtain the training response corresponding to the target training dialogue context. The multiple training dialogue contexts include the target training dialogue context. The ININ model includes the context encoding module, the in-dialogue state iterative update learning module, the response generation module, and the inter-dialogue emotion adjacency comparison learning module.

[0069] Based on the multiple training dialogue contexts, the contrast loss in the current iteration training process is determined by the inter-dialogue emotion adjacency contrast learning module, and the emotion prediction loss, generation loss and diversity loss in the current iteration training process are calculated based on the training response.

[0070] The final loss value is determined based on the contrast loss, the sentiment prediction loss, the generation loss, and the diversity loss.

[0071] The parameters of the ININ model are adjusted based on the final loss value. Training ends when the training termination condition is met, and the next iteration of training is performed when the training termination condition is not met.

[0072] Please see Figure 2a , Figure 2a This is a schematic diagram of the ININ model framework. The ININ model consists of four modules: a context encoding module, an in-dialogue state iterative update learning module, a response generation module, and an inter-dialogue emotion adjacency comparison learning module. During training, the target training dialogue context, including its corresponding inference knowledge, is considered internal information, while other training dialogue contexts are considered external information.

[0073] Please see Figure 2b The context encoding module learns context and common-sense knowledge from the dialogue through multiple encoders. For example... Figure 2b As shown in the upper part, optionally, in some embodiments, step 101 specifically includes:

[0074] All utterances in the historical dialogue context are concatenated to obtain an input sequence, which includes a special marker to identify the start of the context input in the historical dialogue context.

[0075] The input sequence is processed using a word embedding layer and a position embedding layer to obtain the word embedding and position embedding of the input sequence;

[0076] The final vector representation is generated based on the word embedding, position embedding and role embedding. The role embedding is used to distinguish the dialogue subject in the dialogue context. The dialogue subject is either a user or an intelligent agent.

[0077] The final vector representation is input into the Transformer encoder for processing to obtain the context representation.

[0078] First, each sentence in the historical dialogue context is concatenated into a long word sequence, resulting in the input sequence C. Then, a preset marker [CLS] is used as the starting marker for the context input, i.e., C = [CLS] ⊕ U1 ⊕ U m ⊕…U M-1 ⊕U M The symbol “⊕” represents a join operation, U m This represents the m-th sentence in the historical dialogue context. Similarly, [CLS] also appears in the final hidden representation of the entire sequence.

[0079] The word embeddings E of the input sequence C are obtained using the word embedding layer and the position embedding layer, respectively. w (C) and location embedding E p (C). Since the in-dialogue state iteration update learning module needs to distinguish between users and intelligent agents, a role embedding E is inserted into the input sequence C. r (C), thus obtaining the final vector representation. The final vector representation E(C) of the historical dialogue context is the sum of the embeddings of the above types:

[0080] E(C)=E w (C)+E p (C)+E r (C);

[0081] in, l≤MN M +1 represents the number of words in the input sequence C, M is the maximum number of words in the sentence, and N... M It is the number of sentences in the dialogue history, d emb It is the embedded dimension.

[0082] By feeding E(C) into the Transformer encoder for processing, a contextual representation can be obtained:

[0083] H ctx =Enc(E(C));

[0084] in, d h It is the size of the encoder's hidden layer.

[0085] Dialogue sequence representations struggle to reflect dialogue turns chronologically. However, the node-line structure of knowledge graphs effectively addresses this issue. To enable the emotional and cognitive states of users and intelligent agents to update and iterate with each dialogue turn, this embodiment constructs a dialogue graph. It treats each dialogue turn as a node, which contains common sense knowledge nodes and emotion nodes for each sentence, cognitive state nodes and emotional state nodes for the user, and cognitive state nodes and emotional state nodes for the agent.

[0086] Optionally, in some embodiments, the step of using the in-dialogue state iteration update learning module to perform in-dialogue state iteration update on the emotional state and cognitive state corresponding to each sentence in the historical dialogue context to obtain the user's final emotional state and the intelligent agent's final cognitive state includes:

[0087] Common sense knowledge is extracted from each sentence in the historical dialogue context, and the hidden vector of the common sense knowledge is obtained. The common sense knowledge includes emotional state and cognitive state.

[0088] Using the hidden vectors of the aforementioned common-sense knowledge, an initial dialogue graph is generated through an image constructor function;

[0089] The cognitive state and the emotional state are iteratively updated based on the initial dialogue graph to obtain the cognitive state and emotional state corresponding to each utterance;

[0090] Based on the dialogue subjects in the historical dialogue context, the user's final emotional state and the intelligent agent's final cognitive state are determined.

[0091] Please see Figure 2c Specifically, the common-sense knowledge of each sentence is first divided into two parts: cognitive state and emotional state, which are then used as a dialogue diagram. The initial state is determined by extracting five common-sense relations ([xReact], [xWant], [xNeed], [xIntent], [xEffect]) from each sentence Um in the dialogue context C. Here, "[xReact]" represents the emotional state, and the other four relations represent cognitive states. The common-sense knowledge is inferred from the dialogue context by the model COMET and the external knowledge base ATOMIC.

[0092] Then, two independent encoders are used to obtain the hidden vectors of common-sense knowledge:

[0093]

[0094] in, It is the cognitive state within the context of historical dialogue. It is the emotional state within the context of historical dialogue, d ck It refers to the number of words in common sense knowledge, C rel It is a representation of the common-sense relational text corresponding to the dialogue, C react It is a representation of the emotional state in the dialogue, Enc rel It is a common sense relation encoder, Enc emo It is an emotional state encoder. This refers to the hidden representation of the predefined tag [CLS], rel∈{xWant,xNeed,xIntent,xEffect}, where ∥ is the join operation, using... The initial dialogue graph can be generated using the graph constructor function.

[0095] In human-computer dialogue, the words spoken by the participants influence each other. This influence can manifest as changes in emotional state or extensions of cognitive state, similar to human dialogue. Both parties continuously enrich their common-sense knowledge, affecting each other's emotions. Therefore, it is necessary to continuously learn the states of both the user and the intelligent agent during the dialogue process.

[0096] First, determine the initial state of the user and the smart agent:

[0097]

[0098] in, and It is randomly initialized. This indicates the cognitive state of the first sentence in the context of the historical dialogue. Enc represents the emotional state of the first sentence in the historical dialogue context. ini It is the initial encoder of the user's cognitive and emotional states.

[0099] The iterative update of cognitive states satisfies:

[0100]

[0101] in, For the current discourse U m The cognitive state, m∈(1,M], where M is the number of utterances in the historical dialogue context, ⊙ represents element-wise multiplication, and σ represents the sigmoid activation function. For the trainable weight matrix of the linear layer, This is a trainable bias term.

[0102] Similarly, the iterative update of emotional states satisfies:

[0103]

[0104] in, For the current discourse U m emotional state, b emo W is a trainable bias term. emo This is the trainable weight matrix for the linear layer.

[0105] Then, based on the role embedding E r (C) can determine whether the iteratively updated state belongs to the user or the intelligent agent, and further classify the updated state to obtain the user's cognitive state, the user's emotional state, the intelligent agent's cognitive state, and the intelligent agent's emotional state as follows:

[0106]

[0107] After iterative updates, the user's final emotional state can be obtained. The final cognitive state of intelligent agents And and Input to the response generation module.

[0108] Optionally, in some embodiments, the step of inputting the context representation, the user's final emotional state, and the intelligent agent's final cognitive state into the response generation module to obtain the target response includes:

[0109] The final emotional state of the user and the final cognitive state of the intelligent agent are fused into the context representation to obtain the final context representation;

[0110] The final context representation is input to the decoder for processing to obtain the target response.

[0111] Please see Figure 2d In the response generation module, the user's final emotional state is first... Fusion into context representation H ctx To obtain an enhanced emotional state context representation

[0112]

[0113] in, To enhance the contextual representation of emotional states, for The feature representation after dimensional transformation, dim = l × d h Enc ctx-emo and Enc ctx-cog These are the emotion enhancement encoder and the cognition enhancement encoder, respectively, and expand(dim) is the dimension transformation function.

[0114] Similarly, the final cognitive state that can be proxies Fusion into context representation H ctx To obtain an enhanced contextual representation of the cognitive state

[0115]

[0116] Finally, based on and Together they are used to generate the final context representation H′ ctx :

[0117]

[0118] in MLP is a multilayer perceptron with ReLU activation, where σ is the sigmoid activation function and ⊙ represents element-wise multiplication.

[0119] The final context representation can be input into the decoder to obtain the target response. Specifically, the target response U M+1 =Y=(y1,…,y T Generated one by one by the decoder based on the tokens:

[0120] P(y t ∣y 1:t-1 ,C)=Dec(Y 1:t-1 ,H′ ctx );

[0121] Among them, Y 1:t-1 This represents the embedding of a token generated before time t, where Dec() is the decoder.

[0122] In this embodiment, the final loss value is determined based on contrast loss, sentiment prediction loss, generation loss, and diversity loss. The calculation methods for each loss are described below.

[0123] Users may have similar emotional needs in different conversational contexts. By learning and comparing the conversational context features of the same emotional category at different scales, the intelligent agent can better adapt to changes in the conversational context. Therefore, an inter-conversational emotion neighbor comparison learning module was set up to extract similar features between conversations of the same emotional category.

[0124] Please see Figure 2b The lower half of the text. Optionally, in some embodiments, determining the contrastive loss in the current training iteration based on the plurality of training dialogue contexts using the inter-dialogue emotion adjacency contrastive learning module includes:

[0125] The multiple training dialogue contexts are input into K parallel augmentation encoders to obtain K augmentation views, where K is an integer greater than 1;

[0126] Generate the emotion adjacency matrix corresponding to the K augmented views. The emotion adjacency matrix is ​​used to characterize whether the emotion labels of any two training dialogue contexts in the plurality of training dialogue contexts are the same.

[0127] Take any one of the K enhanced views as the target view, and calculate the contrast loss based on the neighbor contrast loss between each other enhanced view and the target view.

[0128] To ensure sufficient learning samples, multiple training dialogue contexts are input into K parallel augmentation encoders to obtain different dialogue scenarios, specifically represented as follows:

[0129]

[0130] in, It is the dialogue context representation generated by the k-th enhanced view, k∈[1,K]. Originating from Transformer, the main difference between the two lies in the number of heads in the multi-head attention mechanism. This design aims to obtain dialogue representations in different spatial dimensions, thereby appropriately broadening the context learning space.

[0131] Please see Figure 2e Next, we generate the sentiment adjacency matrices corresponding to the K enhanced views. The specific method for generating the sentiment adjacency matrices is as follows:

[0132] Given batch size B = {C1, C2, ..., C...} N}, t represents the emotion label vector. i Let C represent the i-th training dialogue context. i Tags, Emotion Adjacency Matrix M e The construction formula is as follows:

[0133]

[0134] Among them, M e ∈R N×N , If and only if the emotion labels of dialogues i and j are the same, otherwise

[0135] In the actual implementation, the number K of augmented views is arbitrarily chosen. When K is greater than 2, one of the augmented views is randomly selected. The target view is determined and used as the anchor view, based on each other enhanced view and the target view. The comparison loss is calculated using the neighbor comparison loss between the two neighbors. The details are as follows:

[0136]

[0137] To enhance the view and enhanced view For example, let and They represent enhanced vision. Figure 1 The training dialogue context C learned by augmented view 2 i Embedding, select As the current training dialogue context, positive samples can be divided into three categories:

[0138] (1) The same training dialogue context in different augmented views, i.e.

[0139] (2) Enhance vision Figure 1 Training dialogue contexts with the same emotion label Right now

[0140] (3) Enhance the training dialogue context with the same emotion label in View 2. Right now

[0141] Other training dialogue contexts are negative samples. Therefore, with The number of relevant positive sample pairs should be in It is C j The quantity. With enhanced vision. Figure 1 middle Related enhanced vision Figure 1 The neighbor comparison loss between the augmented view 2 and the enhanced view 2 is calculated using the following formula:

[0142]

[0143] Where θ(·) is the inner product function that measures similarity, and τ is the temperature coefficient. These are positive samples of two enhanced views. Similarly, we can obtain the results in enhanced view 2. Related enhanced vision Figure 1 Neighbor contrast loss between enhanced view 2 and the enhanced view 2

[0144] Will enhance vision Figure 1 The total neighbor contrast loss between view 2 and augmented view 2 is obtained by averaging the values ​​across all training dialogue contexts, and is defined as:

[0145]

[0146] This embodiment also includes emotion prediction loss, generation loss, and diversity loss. Specifically, to predict emotions more accurately, it uses... The [CLS] hidden representation is used for emotion classification, which includes the user's last emotional state in the target training dialogue context:

[0147]

[0148] in,

[0149] Then, the Softmax operation is used to feed e into the linear layer to obtain the sentiment category distribution P. emo :

[0150] P emo =Softmax(W e e)

[0151] Among them, P emo ∈R s , s is the total number of emotion categories available in the dataset, which is calculated during training by determining the emotion category distribution P. emo The sentiment detection loss is obtained by minimizing the cross-entropy loss between the true label e′ and the ground truth label e′.

[0152]

[0153] After obtaining the training response, the negative log-likelihood is used as the generation loss function:

[0154]

[0155] The loss of diversity is as follows:

[0156]

[0157] Where T is the total number of decoding time steps, V is the number of words in the dataset, and a i It is a candidate token for the decoded word, δ t (a i ) is an indicator function.

[0158] The final loss values ​​are as follows:

[0159]

[0160] In this embodiment, an ININ model is proposed for generating empathic responses, possessing both utterance-level and dialogue-level understanding capabilities. Specifically, at the utterance level, an in-dialogue state iteration update strategy is created, treating each utterance as a continuous time node and updating the user and agent states accordingly to simulate their interaction. At the dialogue level, an emotion adjacency matrix is ​​constructed based on emotion tags, and neighbor contrastive learning is applied to capture the overall differences between dialogues within the same emotion category. Furthermore, this embodiment combines representations from both utterance and dialogue levels and integrates them into the empathic response generation process, thereby generating responses with better empathic effects.

[0161] Please see Figure 3 This invention also provides a response generation device 300 for generating empathic responses, comprising:

[0162] The context encoding module 301 is used to encode the historical dialogue context between the user and the intelligent agent to obtain a context representation;

[0163] The in-dialogue state iteration update learning module 302 is used to perform in-dialogue state iteration update on the emotional state and cognitive state corresponding to each sentence in the historical dialogue context, so as to obtain the user's final emotional state and the intelligent agent's final cognitive state.

[0164] The response generation module 303 is used to obtain the target response based on the context representation, the user's final emotional state, and the intelligent agent's final cognitive state.

[0165] Optionally, the response generation device 300 for generating empathic responses further includes:

[0166] The training module is used to iteratively train the ININ model based on multiple training dialogue contexts to obtain the training response corresponding to the target training dialogue context. The multiple training dialogue contexts include the target training dialogue context. The ININ model includes the context encoding module, the in-dialogue state iterative update learning module, the response generation module, and the inter-dialogue emotion adjacency comparison learning module.

[0167] The determination module is used to determine the contrast loss in the current iteration of training based on the multiple training dialogue contexts and the inter-dialogue emotion adjacency contrast learning module, and to calculate the emotion prediction loss, generation loss and diversity loss in the current iteration of training based on the training response.

[0168] The final loss value is determined based on the contrast loss, the sentiment prediction loss, the generation loss, and the diversity loss.

[0169] The parameters of the ININ model are adjusted based on the final loss value. Training ends when the training termination condition is met, and the next iteration of training is performed when the training termination condition is not met.

[0170] Optionally, determining the contrastive loss in the current training iteration based on the multiple training dialogue contexts using the inter-dialogue emotion adjacency contrastive learning module includes:

[0171] The multiple training dialogue contexts are input into K parallel augmentation encoders to obtain K augmentation views, where K is an integer greater than 1;

[0172] Generate the emotion adjacency matrix corresponding to the K augmented views. The emotion adjacency matrix is ​​used to characterize whether the emotion labels of any two training dialogue contexts in the plurality of training dialogue contexts are the same.

[0173] Take any one of the K enhanced views as the target view, and calculate the contrast loss based on the neighbor contrast loss between each other enhanced view and the target view.

[0174] Optionally, the contrast loss is:

[0175]

[0176] in, This is the x-th enhanced view, which is the target view. For the k-th enhanced view, The embedding of the i-th training dialogue context learned for the k-th augmented view. The embedding of the j-th training dialogue context learned for the k-th augmented view. The embedding of the i-th training dialogue context learned for the x-th augmented view. The embedding of the j-th training dialogue context learned for the x-th augmented view, where N is the number of training sample data, θ(·) is the inner product function that measures similarity, and τ is the temperature coefficient. These are positive samples in two enhanced views. Dialogue C in the training batch jA collection of Indicates dialogue C j Dialogue C i They share the same emotional category.

[0177] Optionally, the context encoding module 301 includes:

[0178] A connection unit is used to connect all utterances in the historical dialogue context to obtain an input sequence, the input sequence including a special marker for identifying the start of context input in the historical dialogue context;

[0179] The processing unit is used to process the input sequence using a word embedding layer and a position embedding layer to obtain the word embedding and position embedding of the input sequence;

[0180] A generation unit is used to generate a final vector representation based on the word embedding, position embedding and role embedding, wherein the role embedding is used to distinguish the dialogue subject in the dialogue context, and the dialogue subject is a user or an intelligent agent.

[0181] The encoding unit is used to input the final vector representation into the Transformer encoder for processing to obtain the context representation.

[0182] Optionally, the in-dialogue state iterative update learning module 302 includes:

[0183] The extraction unit is used to extract common sense knowledge from each sentence in the historical dialogue context and obtain the hidden vector of the common sense knowledge, which includes emotional state and cognitive state.

[0184] A construction unit is used to generate an initial dialogue graph by using the hidden vectors of the common sense knowledge through an image constructor.

[0185] The update unit is used to iteratively update the cognitive state and the emotional state based on the initial dialogue graph to obtain the cognitive state and emotional state corresponding to each of the utterances;

[0186] The determining unit is used to determine the user's final emotional state and the intelligent agent's final cognitive state based on the dialogue subjects in the historical dialogue context.

[0187] Optionally, the update unit is specifically used for:

[0188] Determine the user's initial cognitive state User's initial emotional state The initial cognitive state of intelligent agents and the initial emotional state of the intelligent agent

[0189]

[0190] in, and It is randomly initialized. This indicates the cognitive state of the first sentence in the context of the historical dialogue. Enc represents the emotional state of the first sentence in the historical dialogue context. ini An initial encoder used to represent the user's cognitive and emotional states;

[0191] Based on the user's initial cognitive state The user's initial emotional state The initial cognitive state of the intelligent agent and the initial emotional state of the intelligent agent The process involves iterative updates to obtain the emotional state and cognitive state corresponding to each sentence in the historical dialogue context. The iterative update process for the cognitive state is as follows:

[0192]

[0193] in, For the current discourse U m The cognitive state, m∈(1,M], where M is the number of utterances in the historical dialogue context, ⊙ represents element-wise multiplication, and σ represents the sigmoid activation function. For the trainable weight matrix of the linear layer, This is a trainable bias term;

[0194] The iterative update process of the emotional state is as follows:

[0195]

[0196] in, For the current discourse U m emotional state, b emo W is a trainable bias term. emo This is the trainable weight matrix for the linear layer.

[0197] The response generation device 300 for generating empathic responses provided in this application embodiment can execute the above method embodiment, and its implementation principle and technical effect are similar, so it will not be described again here.

[0198] It should be noted that the division of units in the embodiments of this application is illustrative and only represents one logical functional division. In actual implementation, other division methods may be used. Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated units described above can be implemented in hardware or as software functional units.

[0199] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a processor-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) or processor to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0200] like Figure 4 As shown, this application provides an electronic device 400, including: a memory 402, a processor 401, and a program stored in the memory 402 and executable on the processor 401; the processor 401 is used to read the program in the memory 402 to implement the steps in the response generation method for generating empathic responses as described above.

[0201] This application also provides a readable storage medium storing a program that, when executed by a processor, implements the various processes of the above-described response generation method embodiments for generating empathic responses, and achieves the same technical effect. To avoid repetition, it will not be described again here. The readable storage medium can be any available medium or data storage device that the processor can access, including but not limited to magnetic storage (e.g., floppy disks, hard disks, magnetic tapes, magneto-optical disks (MO), etc.), optical storage (e.g., compact disks (CDs), digital video discs (DVDs), Blu-ray discs (BD), high-definition universal discs (HVD), etc.), and semiconductor storage (e.g., read-only memory (ROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), non-volatile memory (NAND FLASH), solid-state disks (SSDs), etc.).

[0202] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.

[0203] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, disk, optical disk) and includes several instructions to cause a terminal (which may be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in the various embodiments of this application.

[0204] The embodiments of this application have been described above with reference to the accompanying drawings. However, this application is not limited to the specific embodiments described above. The specific embodiments described above are merely illustrative and not restrictive. Those skilled in the art can make many other forms under the guidance of this application without departing from the spirit and scope of the claims, and all of these forms are within the protection scope of this application.

Claims

1. A response generation method for generating empathic responses, characterized in that, include: The historical dialogue context between the user and the intelligent agent is input into the context encoding module for encoding processing to obtain a context representation; The in-dialogue state iterative update learning module is used to perform in-dialogue state iterative update on the emotional state and cognitive state corresponding to each sentence in the historical dialogue context, so as to obtain the user's final emotional state and the intelligent agent's final cognitive state. The context representation, the user's final emotional state, and the intelligent agent's final cognitive state are input into the response generation module to obtain the target response; Before the step of inputting the historical dialogue context between the user and the intelligent agent into the context encoding module for encoding processing to obtain the context representation, the method further includes: The ININ model is iteratively trained based on multiple training dialogue contexts to obtain the training response corresponding to the target training dialogue context. The multiple training dialogue contexts include the target training dialogue context. The ININ model includes the context encoding module, the in-dialogue state iterative update learning module, the response generation module, and the inter-dialogue emotion adjacency comparison learning module. Based on the multiple training dialogue contexts, the contrast loss in the current iteration training process is determined by the inter-dialogue emotion adjacency contrast learning module, and the emotion prediction loss, generation loss and diversity loss in the current iteration training process are calculated based on the training response. The final loss value is determined based on the contrast loss, the sentiment prediction loss, the generation loss, and the diversity loss. The parameters of the ININ model are adjusted based on the final loss value. Training ends when the training termination condition is met, and the next iteration of training is performed when the training termination condition is not met. The step of determining the contrastive loss in the current training iteration based on the multiple training dialogue contexts and utilizing the inter-dialogue emotion adjacency contrastive learning module includes: The multiple training dialogue contexts are input into K parallel augmentation encoders to obtain K augmentation views, where K is an integer greater than 1; Generate the emotion adjacency matrix corresponding to the K augmented views. The emotion adjacency matrix is ​​used to characterize whether the emotion labels of any two training dialogue contexts in the plurality of training dialogue contexts are the same. Take any one of the K enhanced views as the target view, and calculate the contrast loss based on the neighbor contrast loss between each other enhanced view and the target view.

2. The method as described in claim 1, characterized in that, The comparison loss is: in, This is the x-th enhanced view, which is the target view. For the k-th enhanced view, The embedding of the i-th training dialogue context learned for the k-th augmented view. The embedding of the j-th training dialogue context learned for the k-th augmented view. The embedding of the i-th training dialogue context learned for the x-th augmented view. Let be the embedding of the j-th training dialogue context learned for the x-th augmented view, N be the number of training sample data, θ(·) be the inner product function that measures similarity, and τ be the temperature coefficient. These are positive samples in two enhanced views. Dialogue C in the training batch j A collection of Indicates dialogue C j Dialogue C i They share the same emotional category.

3. The method as described in claim 1, characterized in that, The step of inputting the historical dialogue context between the user and the intelligent agent into the context encoding module for encoding processing to obtain a context representation includes: All utterances in the historical dialogue context are concatenated to obtain an input sequence, which includes a special marker to identify the start of the context input in the historical dialogue context. The input sequence is processed using a word embedding layer and a position embedding layer to obtain the word embedding and position embedding of the input sequence; The final vector representation is generated based on the word embedding, position embedding and role embedding. The role embedding is used to distinguish the dialogue subject in the dialogue context. The dialogue subject is either a user or an intelligent agent. The final vector representation is input into the Transformer encoder for processing to obtain the context representation.

4. The method as described in claim 1, characterized in that, The step of using the in-dialogue state iterative update learning module to perform in-dialogue state iterative updates on the emotional state and cognitive state corresponding to each sentence in the historical dialogue context, to obtain the user's final emotional state and the intelligent agent's final cognitive state, includes: Common sense knowledge is extracted from each sentence in the historical dialogue context, and the hidden vector of the common sense knowledge is obtained. The common sense knowledge includes emotional state and cognitive state. Using the hidden vectors of the aforementioned common-sense knowledge, an initial dialogue graph is generated through an image constructor function; The cognitive state and the emotional state are iteratively updated based on the initial dialogue graph to obtain the cognitive state and emotional state corresponding to each utterance; Based on the dialogue subjects in the historical dialogue context, the user's final emotional state and the intelligent agent's final cognitive state are determined.

5. The method as described in claim 4, characterized in that, The iterative update of the cognitive state and the emotional state based on the initial dialogue graph to obtain the cognitive state and the emotional state corresponding to each utterance includes: Determine the user's initial cognitive state User's initial emotional state The initial cognitive state of intelligent agents and the initial emotional state of the intelligent agent in, and It is randomly initialized. This indicates the cognitive state of the first sentence in the historical dialogue context. Enc represents the emotional state of the first sentence in the historical dialogue context. ini An initial encoder used to represent the user's cognitive and emotional states; Based on the user's initial cognitive state The user's initial emotional state The initial cognitive state of the intelligent agent and the initial emotional state of the intelligent agent The process involves iterative updates to obtain the emotional state and cognitive state corresponding to each sentence in the historical dialogue context. The iterative update process for the cognitive state is as follows: in, For the current discourse U m The cognitive state, m∈(1,M], where M is the number of utterances in the historical dialogue context, ⊙ represents element-wise multiplication, and σ represents the sigmoid activation function. For the trainable weight matrix of the linear layer, This is a trainable bias term; The iterative update process of the emotional state is as follows: in, For the current discourse U m emotional state, b emo W is a trainable bias term. emo This is the trainable weight matrix for the linear layer.

6. A response generation device for generating empathic responses, characterized in that, include: The context encoding module is used to encode the historical dialogue context between the user and the intelligent agent to obtain a context representation; The in-dialogue state iterative update learning module is used to perform in-dialogue state iterative update on the emotional state and cognitive state corresponding to each sentence in the historical dialogue context, so as to obtain the user's final emotional state and the intelligent agent's final cognitive state. A response generation module is used to obtain a target response based on the context representation, the user's final emotional state, and the intelligent agent's final cognitive state. The response generation device for generating empathic responses further includes: The training module is used to iteratively train the ININ model based on multiple training dialogue contexts to obtain the training response corresponding to the target training dialogue context. The multiple training dialogue contexts include the target training dialogue context. The ININ model includes the context encoding module, the in-dialogue state iterative update learning module, the response generation module, and the inter-dialogue emotion adjacency comparison learning module. The first determining module is used to determine the contrast loss in the current iteration training process based on the multiple training dialogue contexts and the inter-dialogue emotion adjacency contrast learning module, and to calculate the emotion prediction loss, generation loss and diversity loss in the current iteration training process based on the training response. The second determining module is used to determine the final loss value based on the contrast loss, the emotion prediction loss, the generation loss, and the diversity loss; The adjustment module is used to adjust the parameters of the ININ model based on the final loss value, terminate training when the training termination condition is met, and perform the next iteration of training when the training termination condition is not met. The step of determining the contrastive loss in the current training iteration based on the multiple training dialogue contexts and utilizing the inter-dialogue emotion adjacency contrastive learning module includes: The multiple training dialogue contexts are input into K parallel augmentation encoders to obtain K augmentation views, where K is an integer greater than 1; Generate the emotion adjacency matrix corresponding to the K augmented views. The emotion adjacency matrix is ​​used to characterize whether the emotion labels of any two training dialogue contexts in the plurality of training dialogue contexts are the same. Take any one of the K enhanced views as the target view, and calculate the contrast loss based on the neighbor contrast loss between each other enhanced view and the target view.

7. An electronic device, comprising: A memory, a processor, and a program stored in the memory and executable on the processor; characterized in that the processor is configured to read the program from the memory to implement the steps in the response generation method for generating an empathic response as claimed in any one of claims 1 to 5.

8. A readable storage medium for storing a program, characterized in that, When the program is executed by the processor, it implements the steps of the response generation method for generating empathic responses as described in any one of claims 1 to 5.

Citation Information

Patent Citations

  • Common-condition reply generation method and device, terminal and storage medium

    CN115934909A

  • Method and apparatus for determining a dialog state, dialog system, computer device, and storage medium

    US20200335104A1