Knowledge distillation-based common-estrus reply generation model training method and device

By employing a knowledge distillation-based training method for empathic response generation, which combines emotional and cognitive common sense knowledge, this approach addresses the shortcomings of existing models in tracking emotional changes and understanding context. It enables the generation of responses with greater emotional resonance and diversity, thereby improving the quality and naturalness of dialogue.

CN121543664APending Publication Date: 2026-02-17NORTHWESTERN POLYTECHNICAL UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511664878.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-11-13
Publication Date
2026-02-17

AI Technical Summary

Technical Problem

Existing empathic response generation models struggle to effectively identify and track users' emotional changes during conversations, neglecting users' underlying intentions. The generated responses lack relevance and emotional resonance, and the insufficient understanding of the conversational context results in responses that are neither diverse nor relevant.

Method used

We employ a knowledge distillation-based empathic response generation model training method. The teacher model guides the student model, combining emotional and cognitive common sense knowledge. We use the emotional encoder and cognitive encoder to obtain global representation vectors and fuse them. We then train the model using knowledge distillation techniques and external common sense knowledge to generate responses that are more emotionally resonant and diverse.

Benefits of technology

It significantly improves the ability to capture users' emotional changes and potential intentions, generates more emotionally resonant and targeted responses, enhances the naturalness and affinity of the conversation, avoids monotonous and repetitive dialogue, ensures that the generated responses are closely related to the context, and improves the quality of the conversation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121543664A_ABST
    Figure CN121543664A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of natural language processing, and discloses a common-situation reply generation model training method and device based on knowledge distillation. The method comprises the steps that a first sample sequence is input into a teacher model for reply generation, and a first reply sequence is obtained; inputting the emotional common sense sequence into an emotional encoder, and inputting the cognitive common sense sequence into a cognitive encoder to obtain an emotional global representation vector and a cognitive global representation vector; inputting the fusion representation vector into a decoder of the student model for reply generation to obtain a second reply sequence; performing emotion classification prediction to obtain emotion classification probability distribution; and carrying out joint training on the student model and the teacher model to obtain a common-situation reply generation model. According to the scheme, emotional changes and potential intentions of the user can be accurately captured, and personalized and diversified replies are generated in combination with a knowledge distillation technology and external common knowledge; dialogue historical information can be comprehensively and deeply analyzed, and it is ensured that generated replies are closely related to contexts, and logic coherence is achieved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of natural language processing technology, specifically to a training method and apparatus for an empathic response generation model based on knowledge distillation. Background Technology

[0002] With the rapid development of artificial intelligence technology, the field of Natural Language Processing (NLP) has made significant progress in recent years, especially in dialogue systems and affective computing. Empathic response generation, as an important task in open-domain dialogue systems, aims to generate natural language responses that understand and respond to user emotions. Empathic responses not only require the system to understand the user's literal meaning but also to capture the user's emotional state and generate responses with emotional resonance. However, existing empathic response generation methods face many challenges in practical applications.

[0003] During their research into related technologies, the inventors discovered that most existing methods for generating empathetic responses suffer from the following problems: (1) Existing generative models often struggle to effectively identify and track users' emotional changes during conversations, especially in multi-turn dialogues where users' emotions may change as the conversation progresses. Furthermore, users' underlying intentions (such as seeking comfort or advice) are often overlooked, resulting in generated responses that lack relevance and emotional resonance. (2) Generative models often tend to generate generalized responses in open-domain dialogues, resulting in a lack of diversity in the generated responses; (3) Due to insufficient understanding of the dialogue context, it is easy to generate responses that are irrelevant to the dialogue context. Summary of the Invention

[0004] The purpose of this invention is to provide a training method and apparatus for an empathic response generation model based on knowledge distillation, in order to solve the problem of poor response quality in existing methods.

[0005] To achieve the above objectives, the present invention employs the following technical solution: The first aspect of this invention proposes a training method for an empathic response generation model based on knowledge distillation, the method comprising: The utterances of each party in the dialogue context sample are spliced ​​together in chronological order to obtain a spliced ​​sequence. A first tag for aggregating global semantic information is added before the spliced ​​sequence to obtain a first sample sequence. The first sample sequence is input into the teacher model to generate a response, resulting in the first response sequence; The first sample sequence is split into multiple word vectors, and the multiple word vectors are input into the encoder of the student model to obtain the first global representation vector of the first sample sequence; Obtain the sentiment common sense sequence representing sentiment-type relationships and the cognitive common sense sequence representing cognitive-type relationships from the dialogue context sample, and input the sentiment common sense sequence into the sentiment encoder and the cognitive common sense sequence into the cognitive encoder to obtain the sentiment global representation vector and the cognitive global representation vector, respectively. The first global representation vector, the emotion global representation vector, and the cognition global representation vector are fused to obtain a fused representation vector; The fusion representation vector is input into the decoder of the student model to generate a response, resulting in a second response sequence; The first global representation vector is input into the linear classification layer of the student model to perform emotion classification prediction, thereby obtaining the emotion classification probability distribution of the dialogue context sample. The student model and the teacher model are jointly trained based on the first loss value between the first response sequence and the second response sequence, the second loss value between the second response sequence and the real response label, and the third loss value between the emotion classification probability distribution and the real emotion label. The trained student model is then used as the empathic response generation model.

[0006] Optionally, the first loss value is the KL divergence between the first response sequence and the second response sequence, the second loss value is the cross-entropy loss between the second response sequence and the true response label, and the third loss value is the cross-entropy loss between the emotion classification probability distribution and the true emotion label.

[0007] Optionally, obtaining the sentiment commonsense sequence representing sentiment-related relationships and the cognitive commonsense sequence representing cognitive-related relationships from the dialogue context sample includes: A second tag is added after the last utterance of the dialogue context sample to enhance the model's understanding of common sense knowledge, resulting in a second sample sequence; The second sample sequence is input into the COMET model for common sense knowledge labeling to obtain various common sense knowledge contained in the dialogue context sample; The common sense knowledge representing emotional relationships from the various common sense knowledge is concatenated, and the first mark is added to the front of the concatenated sequence to obtain the emotional common sense sequence; The common sense knowledge representing cognitive relationships among the various common sense knowledge is concatenated, and the first mark is added before the concatenated sequence to obtain the cognitive common sense sequence.

[0008] Optionally, the step of inputting the emotional common sense sequence into the emotional encoder and the cognitive common sense sequence into the cognitive encoder to obtain the emotional global representation vector and the cognitive global representation vector, respectively, includes: The emotional common sense sequence and the cognitive common sense sequence are respectively input into the preset emotional encoder and cognitive encoder for processing to obtain the corresponding emotional common sense hidden layer representation vector and cognitive common sense hidden layer representation vector; The average value of the hidden layer representation vector of emotional common sense is used as the global representation vector of emotion; The 0th dimension of the cognitive common sense hidden layer representation vector is taken as the cognitive global representation vector.

[0009] Optionally, fusing the first global representation vector, the emotion global representation vector, and the cognition global representation vector to obtain a fused representation vector includes: Obtain the first shape of the first global representation vector; The global representation vector of emotion and the global representation vector of cognition are respectively converted into a first tensor and a second tensor with the same shape as the first shape; The first global representation vector, the first tensor, and the second tensor are fused at the token level to obtain a fused representation vector.

[0010] Optionally, the step of splitting the first sample sequence into multiple word vectors and inputting the multiple word vectors into the encoder of the student model to obtain the first global representation vector of the first sample sequence includes: The dialogue context sample is split into multiple word vectors, and the multiple word vectors are further divided into word vectors, position vectors, and speaker vectors; The word vectors, position vectors, and speaker vectors are concatenated and input into the encoder of the student model to obtain the representation vector of the first marker position in the last hidden layer of the encoder. The representation vector of the first marked position is used as the first global representation vector of the dialogue context sample.

[0011] A second aspect of the present invention provides a training apparatus for an empathic response generation model based on knowledge distillation, the apparatus comprising: The first splicing module is used to splice the utterances of each party in the dialogue context sample in chronological order to obtain a spliced ​​sequence. A first tag for aggregating global semantic information is added before the spliced ​​sequence to obtain a first sample sequence. The first generation module is used to input the first sample sequence into the teacher model to generate a response, thereby obtaining the first response sequence. The first input module is used to split the first sample sequence into multiple word vectors, input the multiple word vectors into the encoder of the student model, and obtain the first global representation vector of the first sample sequence. The second input module is used to obtain the emotional common sense sequence representing the emotional relationship and the cognitive common sense sequence representing the cognitive relationship in the dialogue context sample, and input the emotional common sense sequence into the emotional encoder and the cognitive common sense sequence into the cognitive encoder to obtain the emotional global representation vector and the cognitive global representation vector, respectively. The fusion module is used to fuse the first global representation vector, the emotion global representation vector, and the cognition global representation vector to obtain a fused representation vector; The second generation module is used to input the fused representation vector into the decoder of the student model to generate a response, thereby obtaining a second response sequence; The classification prediction module is used to input the first global representation vector into the linear classification layer of the student model to perform emotion classification prediction, and obtain the emotion classification probability distribution of the dialogue context sample. The joint training module is used to jointly train the student model and the teacher model based on the first loss value between the first response sequence and the second response sequence, the second loss value between the second response sequence and the real response label, and the third loss value between the emotion classification probability distribution and the real emotion label, and uses the trained student model as the empathic response generation model.

[0012] Optionally, the second input module is specifically used for: The first tagging module is used to add a second tag after the last utterance of the dialogue context sample to enhance the model's understanding of common sense knowledge, thereby obtaining a second sample sequence; The second labeling module is used to input the second sample sequence into the COMET model for common sense knowledge labeling, thereby obtaining various common sense knowledge contained in the dialogue context sample; The second splicing module is used to splice the common sense knowledge representing emotional relationships from the various common sense knowledge, and add the first mark before the spliced ​​sequence to obtain the emotional common sense sequence; The third splicing module is used to splice the common sense knowledge representing cognitive relationships among the various common sense knowledge, and add the first mark before the spliced ​​sequence to obtain a cognitive common sense sequence.

[0013] A third aspect of the present invention provides an electronic device comprising a processor and a memory, wherein the memory stores at least one instruction, at least one program, a code set, or an instruction set, wherein the at least one instruction, the at least one program, the code set, or the instruction set is loaded and executed by the processor to implement the empathic response generation model training method based on knowledge distillation as described in the first aspect.

[0014] A fourth aspect of the present invention provides a computer-readable storage medium storing at least one instruction, at least one program, a code set, or an instruction set, wherein the at least one instruction, the at least one program, the code set, or the instruction set is loaded and executed by a processor to implement the empathic response generation model training method based on knowledge distillation as described in the first aspect.

[0015] Compared with the prior art, the present invention has the following technical features: This invention can accurately capture users' emotional changes and potential intentions in multi-turn conversations, generating more emotionally resonant and targeted responses, enhancing the naturalness and approachability of the conversation; and by combining knowledge distillation technology and external common sense knowledge, it generates personalized and diverse responses, avoiding monotonous and repetitive conversations; in addition, it comprehensively and deeply analyzes the history of the conversation to ensure that the generated responses are closely related to the context and logically coherent, thereby improving the quality of the conversation. Attached Figure Description

[0016] Figure 1 This is a flowchart illustrating the steps of a training method for an empathic response generation model based on knowledge distillation, as provided in an embodiment of the present invention. Figure 2 This is an overall architecture diagram of an empathic response generation model provided in an embodiment of the present invention; Figure 3 This is a structural block diagram of a training method for an empathic response generation model based on knowledge distillation, provided in an embodiment of the present invention. Detailed Implementation

[0017] During their research into related technologies, the inventors discovered that existing methods for generating empathic responses face numerous challenges in practical applications.

[0018] First, existing empathic response generation models typically rely on large amounts of sentiment-annotated data for training. However, acquiring sentiment-annotated data is costly, and the annotation process is easily influenced by subjective factors, resulting in inconsistent data quality. Furthermore, the scale of sentiment-annotated data is often limited, making it difficult to cover diverse emotional expressions and contexts. This causes the models to perform poorly when faced with new emotional expressions or complex contexts, making it difficult to generate empathetic responses.

[0019] Secondly, most existing empathic response generation models are based on end-to-end deep learning architectures, such as Transformer-based models. While these models excel at generating fluent responses, they often lack effective utilization of external common-sense knowledge. Common-sense knowledge plays a crucial role in empathic response generation because it helps the model better understand the user's context and emotional state. For example, when a user expresses "I just lost my job," the model needs to understand the potential emotional impact of losing a job, such as anxiety and frustration, and generate a corresponding empathic response. However, existing models often struggle to effectively integrate external common-sense knowledge into the generation process, resulting in responses lacking emotional depth and contextual understanding.

[0020] To address these issues, researchers have proposed several knowledge-enhanced empathic response generation methods. These methods enhance the model's emotion understanding and generation capabilities by introducing external knowledge bases. Li et al. utilized common-sense knowledge from ConceptNet to improve the model's understanding of implicit emotions within context. Furthermore, Li et al. explored methods for constructing emotion context graphs based on multimodal knowledge to enhance the emotion perception capabilities of dialogue agents. Wang et al. further used ConceptNet for common-sense reasoning to analyze the causal relationships of emotions, providing deeper emotional understanding support for empathic response generation. Sabour et al., on the other hand, leveraged another common-sense knowledge base, ATOMIC, to help dialogue systems more accurately understand users' context and emotions.

[0021] In recent years, knowledge distillation, as an effective method for model compression and knowledge transfer, has been widely applied in the field of natural language processing. The core idea of ​​knowledge distillation is to use a complex teacher model to guide the training process of a simple student model, thereby transferring knowledge from the teacher model to the student model. This method not only improves the performance of the student model but also reduces its dependence on large-scale labeled data, thus lowering the training cost. This solution proposes an empathic response generation model based on knowledge distillation technology and the integration of knowledge distillation technology with external common sense knowledge. Compared with existing response generation models, this model can achieve superior results.

[0022] Figure 1 This is a flowchart illustrating the steps of a training method for an empathic response generation model based on knowledge distillation, provided in an embodiment of the present invention. Figure 1 As shown, the method includes the following steps: Step 101: Concatenate the utterances of each party in the dialogue context sample in chronological order to obtain a concatenated sequence. Add a first tag for aggregating global semantic information before the concatenated sequence to obtain a first sample sequence.

[0023] Given a dialogue context ,in and They represent the first The speech of the speaker and the speech of the listener in the turn. Here, the speaker can be a user interacting with the system or model, and the listener can be the system or model. For dialogue rounds.

[0024] All utterances in the dialogue context are concatenated in chronological order, and a first marker is added before the concatenated sequence. The first marker is used to aggregate global information, such as [CLS].

[0025] [CLS] is a special label in Transformer models, primarily used to aggregate global semantic information. During pre-training and fine-tuning, the hidden layer output of [CLS] is used as a semantic summary of the entire sequence.

[0026] The first sample sequence obtained after splicing As shown below: ; in, This indicates a splicing operation.

[0027] Step 102: Input the first sample sequence into the teacher model to generate a response, and obtain the first response sequence.

[0028] The knowledge distillation module consists of two parts: a teacher model and a student model. The teacher model can use the large-scale pre-trained language model T5-base, containing 220M parameters. The student model can use the more lightweight T5-small as its base model. Compared to the teacher model, the student model has approximately 73% fewer parameters. The knowledge distillation module aims to make the output of the student model mimic the output of the teacher model, compressing the model size while maintaining high model performance, thus ensuring high usability and generalization ability in real-world applications.

[0029] To train a model with stronger empathy generation capabilities as a teacher model, this approach first trains two classifiers separately to construct more granular discourse-level emotion and intent labels for the dataset. It also uses dense paragraph retrieval technology to retrieve the most relevant response examples to the current context to guide response generation, thereby enabling the teacher model to generate diverse empathetic responses.

[0030] The first sample sequence is input into the classroom model to generate responses. The first response sequence output by the teacher model is shown below: ; in, Indicates the first response sequence. Indicates the first One generated word, This indicates the context of the input dialogue. The number of words generated. The generation model generates the first word. When dealing with a single word, it requires relying on the previously generated 1~ -1 word, This means the first All words generated before the given word, This represents the teacher model.

[0031] Step 103: Split the first sample sequence into multiple word vectors, and input the multiple word vectors into the encoder of the student model to obtain the first global representation vector of the first sample sequence.

[0032] To utilize speaker information, this scheme uses a word segmentation tool to split the speech of the speaker and the listener in the first sample sequence into multiple word vectors.

[0033] Multiple word vectors are input into the encoder of the student model. The encoder captures the contextual relationships between words, converts the word vector sequence into a high-level feature representation, and summarizes the high-level feature representation to output the first global representation vector.

[0034] As an optional embodiment, step 103 includes: Step 1031: Split the dialogue context sample into multiple word vectors, and divide the multiple word vectors into word vectors, position vectors and speaker vectors; Step 1032: After concatenating the word vector, position vector, and speaker vector, input them into the encoder of the student model to obtain the representation vector of the first marker position in the last hidden layer of the encoder; Step 1033: Use the representation vector of the first marked position as the first global representation vector of the dialogue context sample.

[0035] In steps 1031-1033, word vectors, positional word vectors, and speaker word vectors are several different embedding methods in natural language processing. Word vectors are a method of representing words by mapping them to a high-dimensional vector space. Each word is represented as a fixed-length vector that captures the semantic and syntactic features of the word.

[0036] Positional word vectors are a method of encoding the positional information of words in a sentence into vectors. They are used to address the problem that word vectors cannot distinguish the semantics of the same word in different positions. Speaker word vectors are a method of encoding speaker information into vectors. They are used to distinguish the utterances of different speakers and are particularly suitable for multi-speaker dialogue scenarios.

[0037] Contextual word vectors It consists of three parts, and its form is as follows: ; in , , These represent word vectors, position vectors, and speaker vectors, respectively.

[0038] In the Transformer architecture, each encoder layer outputs a hidden layer representation. The last hidden layer has the richest representation because it contains contextual information about the entire input sequence. In some models, a special marker [CLS] is added to the beginning of the input sequence. After processing by the encoder, the hidden layer representation at the [CLS] position is considered a global representation of the entire input sequence. This representation captures the contextual information of the entire sequence and can be used for subsequent tasks such as classification and question answering.

[0039] After being processed by the encoder, the input to the student model encoder is used as the global representation vector of the entire context sequence, i.e., the first global representation vector, which is the representation vector at the [CLS] position of the last hidden layer. ; in, This is the first global representation vector. , Indicates the length of the input sequence. This represents the dimension of the encoder's hidden layer. For the real number space, This represents the student model encoder.

[0040] Step 104: Obtain the sentiment common sense sequence representing sentiment-type relationships and the cognitive common sense sequence representing cognitive-type relationships from the dialogue context sample, and input the sentiment common sense sequence into the sentiment encoder and the cognitive common sense sequence into the cognitive encoder to obtain the sentiment global representation vector and the cognitive global representation vector, respectively.

[0041] Emotional common sense sequence refers to background knowledge related to emotional tendencies and states in a dialogue. Cognitive common sense sequence refers to background knowledge related to logic, facts, and causality in a dialogue.

[0042] An emotion encoder is a model specifically designed to process emotion-related text, while a cognitive encoder is a model specifically designed to process logic and facts.

[0043] In acquiring the sequence of emotional common sense and cognitive common sense sequence Then, these two sequences are input into independent emotion encoders and cognitive encoders for processing to obtain their corresponding hidden layer representation vectors. Finally, global representation is performed on the hidden layer representation vectors to obtain the global emotion representation vector. and cognitive global representation vector .

[0044] As an optional embodiment, step 104, obtaining the emotional commonsense sequence representing emotional relationships and the cognitive commonsense sequence representing cognitive relationships from the dialogue context sample, includes: Step 1041: Add a second tag after the last utterance of the dialogue context sample to enhance the model's understanding of common sense knowledge, and obtain the second sample sequence; Step 1042: Input the second sample sequence into the COMET model for common sense knowledge labeling to obtain the various common sense knowledge contained in the dialogue context sample; Step 1043: Concatenate the common sense knowledge representing emotional relationships from the various common sense knowledge, and add the first mark before the concatenated sequence to obtain the emotional common sense sequence; Step 1044: Concatenate the common sense knowledge representing cognitive relationships among the various common sense knowledge, and add the first mark before the concatenated sequence to obtain the cognitive common sense sequence.

[0045] In steps 1041-1044, common-sense knowledge refers to knowledge or information that is generally recognized and accepted by people and is associated with the context and relationships of the input dialogue. This knowledge typically reflects people's general understanding of the world, including but not limited to facts, logical relationships, social norms, and emotional responses in daily life. This knowledge can help the model better understand the dialogue content and generate more reasonable and natural responses.

[0046] A second tag is added after the last utterance in the dialogue context to enhance the model's understanding of common-sense knowledge, resulting in a second sample sequence.

[0047] The second tag can include five relation tags: [xReact], [xWant], [xNeed], [xIntent], and [xEffect]. Here, [xReact] represents a character's reaction to an event, [xWant] represents a character's expectation after the event occurs, [xNeed] represents the conditions required for the event to occur, [xIntent] represents a character's intention before the event occurs, and [xEffect] represents the impact of the event on the character.

[0048] The COMET model is a model that generates commonsense inferences for a given event, fine-tuned based on a pre-trained GPT-2 model. This approach uses a BART-based variant of COMET to acquire commonsense knowledge relevant to the dialogue context. The COMET model outputs five corresponding commonsense knowledge statements for each relation, presented in natural language.

[0049] Using the second sample sequence as input to the COMET model, the COMET model generates various common-sense knowledge. For example, when the second identifier includes the five relational tags mentioned above, the COMET model generates five types of common-sense knowledge. .

[0050] This scheme categorizes five types of common-sense knowledge into common-sense knowledge representing emotional relationships and common-sense knowledge representing cognitive relationships. Among them, [xReact] represents emotional relationships, while [xWant], [xNeed], [xIntent], and [xEffect] represent cognitive relationships.

[0051] For common-sense knowledge representing sentiment-related relationships, concatenate them and add a [CLS] marker at the beginning of the sequence to generate a sentiment common-sense sequence. .

[0052] For common-sense knowledge representing cognitive relationships, these four types of common-sense knowledge are concatenated sequentially, with a [CLS] marker appended to the beginning of the sequence to obtain a cognitive common-sense sequence. .

[0053] As an optional embodiment, in step 104, the emotional common sense sequence is input into the emotional encoder, and the cognitive common sense sequence is input into the cognitive encoder to obtain the emotional global representation vector and the cognitive global representation vector, respectively, including: Step 1045: Input the emotional common sense sequence and the cognitive common sense sequence into the preset emotional encoder and cognitive encoder respectively for processing to obtain the corresponding emotional common sense hidden layer representation vector and cognitive common sense hidden layer representation vector; Step 1046: Take the average value of the hidden layer representation vector of emotion common sense as the global representation vector of emotion; Step 1047: Take the 0th dimension of the cognitive common sense hidden layer representation vector as the cognitive global representation vector.

[0054] In steps 1045-1047, the emotional common sense sequence is obtained. and cognitive common sense sequence Then, these two sequences are input into independent emotion encoders and cognitive encoders for processing to obtain their corresponding hidden layer representation vectors.

[0055] To obtain a global representation of each set of common sense knowledge, it is necessary to process the hidden layer representation vectors of emotional common sense and cognitive common sense separately.

[0056] For the hidden layer representation vector of the emotion encoder The average value is taken as the global representation vector. For the hidden layer representation vector of the cognitive encoder The representation of the 0th dimension (i.e., the [CLS] position) is taken as the global representation vector. The details are as follows: ; ; in, , for The 0th dimension, To calculate the average value.

[0057] Step 105: Fuse the first global representation vector, the emotion global representation vector, and the cognition global representation vector to obtain a fused representation vector.

[0058] The input to the student model encoder is consistent with that of the teacher model, which is the first sample sequence. Before decoding, the student model fuses the encoded first global representation vector with two types of common sense knowledge: the sentiment global representation vector and the cognitive global representation vector, to obtain a fused representation vector.

[0059] As an optional embodiment, step 105 includes: Step 1051: Obtain the first shape of the first global representation vector; Step 1052: Convert the global representation vector of emotion and the global representation vector of cognition into a first tensor and a second tensor with the same shape as the first shape, respectively; Step 1053: Fuse the first global representation vector, the first tensor, and the second tensor at the token level to obtain a fused representation vector.

[0060] In steps 1051-1053, before fusion, the dimensions of the global representation vector of emotion and the global representation vector of cognition need to be converted to be consistent with the first global representation vector.

[0061] because ,and Therefore, it is necessary to first extend and transform the global representation vectors of emotion and cognition to obtain the first and second tensors. The specific transformation method is as follows: ; ; in, This represents the first tensor. Indicates the second tensor; This means copying the commonsense representation vector along the length of the sequence. Next, obtain and Tensors with consistent shape.

[0062] Next, at the token level, the first global representation vector, the first tensor, and the second tensor are fused together, as shown below: ; in, This represents the fused representation vector. This represents the first global representation vector. This represents the first tensor. This represents the second tensor. In natural language processing, a token is the basic unit of text, which can be a word, subword, character, or other symbol. Token-level fusion refers to operating on the contextual and common-sense representations of each individual token, rather than operating on the global representation of the entire sentence or paragraph. This fusion approach can enhance the model's understanding of text at the token level, thereby improving the model's performance and robustness.

[0063] Step 106: Input the fused representation vector into the decoder of the student model to generate a response, and obtain the second response sequence.

[0064] The fused representation The input to the student model decoder generates responses, allowing the student model to incorporate external common-sense knowledge during the decoding process, ultimately resulting in the output distribution of the student model. As shown below: ; in, Indicates the second response sequence. Indicates the first One generated word, Indicates the context of the input dialogue; Indicates the generation of the first One word, This means the first All words generated before the given word, Indicates the first The output of the student model corresponding to each generated word.

[0065] Step 107: Input the first global representation vector into the linear classification layer of the student model to perform emotion classification prediction, and obtain the emotion classification probability distribution of the dialogue context sample.

[0066] To classify the emotions in the dialogue context, the first global representation vector output by the student model encoder is used. As input, it is passed to a linear classification layer. The specific classification formula is as follows: ; in, This is the weight matrix of the linear classification layer; This is the bias vector for the linear classification layer; This is the probability distribution for classifying emotions in context samples. Each value corresponds to the probability of an emotion category, and there are a total of 32 emotion categories. This is a one-hot encoded vector of the true emotion label. This is the activation function.

[0067] Step 108: Based on the first loss value between the first response sequence and the second response sequence, the second loss value between the second response sequence and the real response label, and the third loss value between the emotion classification probability distribution and the real emotion label, jointly train the student model and the teacher model, and use the trained student model as the empathic response generation model to generate empathic responses.

[0068] In this scheme, the loss value for joint training consists of three parts: the first loss value between the first response sequence and the second response sequence, the second loss value between the second response sequence and the true response label, and the third loss value between the emotion classification probability distribution and the true emotion label.

[0069] During training, the three loss values ​​are weighted and summed to obtain the total loss value for this joint training. The student model calculates the gradient through backpropagation of the total loss function and updates the parameters through an optimization algorithm. Finally, the trained student model is used as the empathic response generation model.

[0070] As an optional embodiment, the first loss value is the KL divergence between the first response sequence and the second response sequence, the second loss value is the cross-entropy loss value between the second response sequence and the true response label, and the third loss value is the cross-entropy loss value between the emotion classification probability distribution and the true emotion label.

[0071] In this embodiment of the invention, the loss function for joint training... It consists of three parts, as shown below: ; in, The first loss value is the KL divergence between the first response sequence of the teacher model and the second response sequence of the student model, which measures how similar the distributions of the student model and the teacher model are.

[0072] The second loss value is the sum of the second response sequence of the student model and the true response label. The cross-entropy loss is used to ensure that the responses generated by the student model are consistent with the true labels.

[0073] This is the third loss value, namely the cross-entropy loss for emotion classification.

[0074] , , These are the weight parameters for the three parts of the loss, used to balance their contributions during training.

[0075] Specifically, the cross-entropy loss for emotion classification is defined as follows: ; in, For the first One-hot encoding of a real emotion label, The model predicts the first The probability of each emotion category. The total number of emotion categories. This indicates the context of the input dialogue.

[0076] Figure 2 This is an overall architecture diagram of an empathic response generation model provided in an embodiment of the present invention.

[0077] like Figure 2As shown, the first sample sequence corresponding to the dialogue context is input into the encoder of the teacher model to generate a response, resulting in the first response sequence. The first sample sequence is then split into multiple word vectors, which are input into the encoder of the student model to obtain the output distribution of the teacher model, i.e., the first global representation vector. The sentiment global representation vector and the cognitive global representation vector are obtained from the common sense knowledge acquisition module. These three global representation vectors are then fused to obtain the fused representation vector. This fused representation vector is input into the decoder of the student model to generate a response, resulting in the output distribution of the student model, i.e., the second response sequence. KL divergence is calculated on the first and second response sequences to obtain the first loss value.

[0078] In the common sense knowledge acquisition module, the COMET model is used to label common sense knowledge, obtaining five types of common sense knowledge contained in the dialogue context samples. These five types of common sense knowledge are divided into common sense knowledge representing sentiment-related relationships and common sense knowledge representing cognitive-related relationships. Specifically, [xReact] represents sentiment-related relationships, and [xWant], [xNeed], [xIntent], and [xEffect] represent cognitive-related relationships. The sentiment common sense sequence is input into the sentiment encoder, and the cognitive common sense sequence is input into the cognitive encoder, yielding the global sentiment representation vectors, respectively. and cognitive global representation vector .

[0079] Compared to existing response generation models, this model achieves superior results in four ways: First, it significantly enhances emotion recognition and tracking capabilities, accurately capturing users' emotional changes and potential intentions in multi-turn dialogues, generating more emotionally resonant and targeted responses, and enhancing the naturalness and approachability of the dialogue. Second, it greatly enhances response diversity, breaking through the limitations of generalized responses in open-domain dialogues, and combining knowledge distillation technology and external common sense knowledge to generate personalized and diverse responses, avoiding monotonous and repetitive dialogues. Third, it significantly improves contextual understanding capabilities, comprehensively and deeply analyzing historical dialogue information to ensure that generated responses are closely related to the context and logically coherent, thereby improving dialogue quality. Fourth, it enhances user satisfaction, providing users with a better emotional experience, increasing their trust in the model, and improving user retention and activity, thus possessing significant commercial and social value.

[0080] In summary, the empathic response generation model training method based on knowledge distillation provided in this embodiment of the invention includes: The utterances of each party in the dialogue context sample are concatenated in chronological order to obtain a concatenated sequence. A first tag for aggregating global semantic information is added before the concatenated sequence to obtain a first sample sequence. The first sample sequence is input into the teacher model to generate a response, resulting in a first response sequence. The first sample sequence is split into multiple word vectors, and the multiple word vectors are input into the encoder of the student model to obtain a first global representation vector of the first sample sequence. The emotional common sense sequence representing sentiment-related relationships and the cognitive common sense sequence representing cognitive-related relationships are obtained from the dialogue context sample. The emotional common sense sequence is input into the emotional encoder, and the cognitive common sense sequence is input into the cognitive encoder to obtain the emotional global representation vector and the cognitive global representation vector, respectively. The first global representation vector, the emotional global representation vector, and the cognitive global representation vector are fused to obtain a fused representation vector. This fused representation vector is then input into the decoder of the student model to generate a second response sequence. The first global representation vector is input into the linear classification layer of the student model for emotion classification prediction, resulting in an emotion classification probability distribution for the dialogue context samples. Based on a first loss value between the first and second response sequences, a second loss value between the second response sequence and the true response label, and a third loss value between the emotion classification probability distribution and the true emotion label, the student model and the teacher model are jointly trained. The trained student model is then used as the empathetic response generation model. This solution accurately captures users' emotional changes and potential intentions in multi-turn dialogues, generating more emotionally resonant and targeted responses, enhancing the naturalness and approachability of the dialogue. Furthermore, by combining knowledge distillation technology and external common sense knowledge, personalized and diverse responses are generated, avoiding monotonous and repetitive dialogue. In addition, a comprehensive and in-depth analysis of dialogue history information ensures that the generated responses are closely related to the context and logically coherent, improving dialogue quality.

[0081] Figure 3 This is a structural block diagram of a training device for an empathic response generation model based on knowledge distillation, provided in an embodiment of the present invention. Figure 3 As shown, the device 200 includes: The first splicing module 201 is used to splice the utterances of each party in the dialogue context sample in chronological order to obtain a spliced ​​sequence, and to add a first tag for aggregating global semantic information before the spliced ​​sequence to obtain a first sample sequence. The first generation module 202 is used to input the first sample sequence into the teacher model to generate a response, thereby obtaining a first response sequence; The first input module 203 is used to split the first sample sequence into multiple word vectors, input the multiple word vectors into the encoder of the student model, and obtain the first global representation vector of the first sample sequence. The second input module 204 is used to obtain the emotional common sense sequence representing the emotional relationship and the cognitive common sense sequence representing the cognitive relationship in the dialogue context sample, and input the emotional common sense sequence into the emotional encoder and the cognitive common sense sequence into the cognitive encoder to obtain the emotional global representation vector and the cognitive global representation vector, respectively. The fusion module 205 is used to fuse the first global representation vector, the emotion global representation vector, and the cognition global representation vector to obtain a fused representation vector; The second generation module 206 is used to input the fused representation vector into the decoder of the student model to generate a response, thereby obtaining a second response sequence; The classification prediction module 207 is used to input the first global representation vector into the linear classification layer of the student model to perform emotion classification prediction, and obtain the emotion classification probability distribution of the dialogue context sample. The joint training module 208 is used to jointly train the student model and the teacher model based on the first loss value between the first response sequence and the second response sequence, the second loss value between the second response sequence and the real response label, and the third loss value between the emotion classification probability distribution and the real emotion label, and use the trained student model as the empathic response generation model.

[0082] Regarding the apparatus in the above embodiments, the specific manner in which each module performs its operation has been described in detail in the embodiments related to the method, and will not be elaborated upon here.

[0083] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. This computer program can be stored in a non-volatile computer-readable storage medium. When executed, the computer program can include the processes of the embodiments of the above methods. Any references to memory, storage, databases, or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), RAMbus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and RAMbus dynamic RAM (RDRAM), etc.

[0084] The above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application 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 of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application, and should all be included within the protection scope of this application.

Claims

1. A method for training an empathetic reply generation model based on knowledge distillation, characterized in that, The method comprises: Splicing utterances of each dialogue party in a dialogue context sample in chronological order to obtain a spliced sequence; adding a first mark for aggregating global semantic information before the spliced sequence to obtain a first sample sequence; Inputting the first sample sequence into a teacher model to generate a reply to obtain a first reply sequence; Splitting the first sample sequence into a plurality of word vectors, and inputting the plurality of word vectors into an encoder of a student model to obtain a first global representation vector of the first sample sequence; Obtaining a sentiment common sense sequence representing a sentiment type relationship and a cognitive common sense sequence representing a cognitive type relationship in the dialogue context sample, inputting the sentiment common sense sequence into a sentiment encoder, and inputting the cognitive common sense sequence into a cognitive encoder to respectively obtain a sentiment global representation vector and a cognitive global representation vector; Fusing the first global representation vector, the sentiment global representation vector and the cognitive global representation vector to obtain a fused representation vector; Inputting the fused representation vector into a decoder of the student model to generate a reply to obtain a second reply sequence; Inputting the first global representation vector into a linear classification layer of the student model to perform emotion classification prediction to obtain an emotion classification probability distribution of the dialogue context sample; Jointly training the student model and the teacher model according to a first loss value between the first reply sequence and the second reply sequence, a second loss value between the second reply sequence and a real reply label, and a third loss value between the emotion classification probability distribution and a real emotion label, and taking the trained student model as an empathic reply generation model.

2. The method of claim 1, wherein, The first loss value is a KL divergence between the first reply sequence and the second reply sequence, the second loss value is a cross-entropy loss value between the second reply sequence and the real reply label, and the third loss value is a cross-entropy loss value between the emotion classification probability distribution and the real emotion label.

3. The method of claim 1, wherein, The obtaining of the sentiment common sense sequence representing the sentiment type relationship and the cognitive common sense sequence representing the cognitive type relationship in the dialogue context sample comprises: Adding a second mark for enhancing the understanding of the model to common sense knowledge after the last utterance of the dialogue context sample to obtain a second sample sequence; Inputting the second sample sequence into a COMET model to mark common sense knowledge to obtain a plurality of common sense knowledge contained in the dialogue context sample; Splicing common sense knowledge representing the sentiment type relationship in the plurality of common sense knowledge, and adding the first mark before the spliced sequence to obtain a sentiment common sense sequence; Splicing common sense knowledge representing the cognitive type relationship in the plurality of common sense knowledge, and adding the first mark before the spliced sequence to obtain a cognitive common sense sequence.

4. The method of claim 1, wherein, The inputting of the sentiment common sense sequence into the sentiment encoder and the inputting of the cognitive common sense sequence into the cognitive encoder to respectively obtain the sentiment global representation vector and the cognitive global representation vector comprise: inputting the emotion common sense sequence and the cognition common sense sequence into preset emotion encoders and cognition encoders respectively for processing to obtain corresponding emotion common sense hidden layer representation vectors and cognition common sense hidden layer representation vectors; taking an average value of the emotion common sense hidden layer representation vectors as an emotion global representation vector; taking a representation vector in the 0th dimension of the cognition common sense hidden layer representation vectors as a cognition global representation vector.

5. The method of claim 1, wherein, The fusion module is configured to fuse the first global representation vector, the emotion global representation vector, and the cognition global representation vector to obtain a fusion representation vector. The first input module is configured to split the first sample sequence into a plurality of word vectors, and input the plurality of word vectors into an encoder of a student model to obtain a first global representation vector of the first sample sequence. The second input module is configured to obtain an emotion common sense sequence representing an emotion type relationship and a cognition common sense sequence representing a cognition type relationship in the dialogue context sample, input the emotion common sense sequence into an emotion encoder, and input the cognition common sense sequence into a cognition encoder to respectively obtain an emotion global representation vector and a cognition global representation vector. The fusion module is configured to fuse the first global representation vector, the emotion global representation vector, and the cognition global representation vector to obtain a fusion representation vector.

6. The method of claim 1, wherein, The second generation module is configured to input the fusion representation vector into a decoder of the student model to generate a second reply sequence. The classification prediction module is configured to input the first global representation vector into a linear classification layer of the student model to perform emotion classification prediction to obtain an emotion classification probability distribution of the dialogue context sample. The device comprises: The first splicing module is configured to splice speeches of dialogue parties in the dialogue context sample in chronological order to obtain a spliced sequence, add a first mark for aggregating global semantic information in front of the spliced sequence to obtain a first sample sequence. 7.A knowledge distillation based empathetic reply generation model training apparatus, characterized in that, The first generation module is configured to input the first sample sequence into a teacher model to generate a first reply sequence. The first input module is configured to split the first sample sequence into a plurality of word vectors, and input the plurality of word vectors into an encoder of a student model to obtain a first global representation vector of the first sample sequence. The second input module is configured to obtain an emotion common sense sequence representing an emotion type relationship and a cognition common sense sequence representing a cognition type relationship in the dialogue context sample, input the emotion common sense sequence into an emotion encoder, and input the cognition common sense sequence into a cognition encoder to respectively obtain an emotion global representation vector and a cognition global representation vector. The fusion module is configured to fuse the first global representation vector, the emotion global representation vector, and the cognition global representation vector to obtain a fusion representation vector. The second generation module is configured to input the fusion representation vector into a decoder of the student model to generate a second reply sequence. The classification prediction module is configured to input the first global representation vector into a linear classification layer of the student model to perform emotion classification prediction to obtain an emotion classification probability distribution of the dialogue context sample. ​ ​ The joint training module is configured to jointly train the student model and the teacher model according to a first loss value between the first reply sequence and the second reply sequence, a second loss value between the second reply sequence and a real reply label, and a third loss value between the emotion classification probability distribution and a real emotion label, and to use the trained student model as the empathetic reply generation model.

8. The apparatus of claim 7, wherein, The second input module is specifically configured to: The first marking module is configured to add a second mark for enhancing the understanding of common sense knowledge of the model after the last utterance of the dialogue context sample, to obtain a second sample sequence; The second marking module is configured to input the second sample sequence into a COMET model to mark common sense knowledge, to obtain a plurality of common sense knowledge contained in the dialogue context sample; The second splicing module is configured to splice common sense knowledge representing emotional relationships in the plurality of common sense knowledge, and add the first mark in front of the spliced sequence, to obtain an emotional common sense sequence; The third splicing module is configured to splice common sense knowledge representing cognitive relationships in the plurality of common sense knowledge, and add the first mark in front of the spliced sequence, to obtain a cognitive common sense sequence.

9. An electronic device, comprising: The electronic device includes a processor and a memory, and the memory stores at least one instruction, at least one program, a code set or an instruction set, and the at least one instruction, the at least one program, the code set or the instruction set are loaded and executed by the processor to implement the knowledge distillation-based empathetic reply generation model training method according to any one of claims 1-6.

10. A computer-readable storage medium, characterized in that, The storage medium stores at least one instruction, at least one program, a code set or an instruction set, and the at least one instruction, the at least one program, the code set or the instruction set are loaded and executed by the processor to implement the knowledge distillation-based empathetic reply generation model training method according to any one of claims 1-6.