Model training method and device for realizing emotional conversation, medium and product
By screening and optimizing the common sense knowledge feature vector, the problem that existing emotional dialogue systems are difficult to understand user emotions is solved, and a deeper level of emotional communication and improvement of the understanding ability of the dialogue system is achieved.
Patent Information
- Application Number
- CN202411830330.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-12
- Publication Date
- 2025-04-04
AI Technical Summary
The existing emotional dialogue system is difficult to fully understand the user emotions reflected in the dialogue, and cannot express empathy with the user's situation in the dialogue, resulting in insufficient emotional communication.
By obtaining the collection of historical dialogue texts and common sense relationships, using the common sense knowledge generation model to generate common sense knowledge texts, combining the emotional type distribution of dialogue statements and replies statements, the common sense knowledge feature vector that is consistent with the emotions of historical dialogue and the common sense knowledge feature vector that is consistent with the emotions of empathy replies are selected, and the model parameters are optimized to achieve empathy dialogue.
It improves the understanding ability of the dialogue system, allowing it to perceive the user's emotions more accurately and generate emotionally consistent responses, enhancing the depth of emotional communication.
Smart Images

Figure CN119761510A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of artificial intelligence technology, and in particular to a model training method, device, medium and product for realizing empathetic dialogue. Background Art
[0002] Dialogue systems have always been a hot topic in the field of natural language processing. As the times change, users' needs are not limited to simple conversations with machines, but they hope to have in-depth emotional exchanges with machines. Therefore, emotional dialogue systems have gradually become a research focus for researchers. Early emotional dialogue systems can only communicate with users under certain specific emotions. Such systems cannot fully understand the user's emotions reflected in the dialogue, and cannot show empathy with the user's situation in the dialogue, which deviates from the original intention of the design of emotional dialogue systems. Summary of the invention
[0003] In view of the above problems, the present disclosure is proposed. The present disclosure provides a model training method, device, medium and product for realizing empathy dialogue.
[0004] According to a first aspect of the present disclosure, a model training method for implementing empathy dialogue is provided, comprising:
[0005] Acquire a historical dialogue text and a common sense relationship set, wherein dialogue sentences in the historical dialogue text are annotated with dialogue sentence emotion types, and reply sentences in the historical dialogue text are annotated with empathy reply emotion types;
[0006] Using the common sense knowledge generation model included in the model, generating a common sense knowledge text set of the historical dialogue text according to the common sense relationship types included in the common sense relationship set, each dialogue sentence and reply sentence in the historical dialogue text corresponds to a plurality of common sense knowledge texts;
[0007] Using the dialogue sentence emotion type distribution obtained based on the dialogue sentence emotion type and the empathy reply emotion type distribution obtained based on the empathy reply emotion type, and using the emotion consistency selection model included in the model, the common sense knowledge text set is screened to obtain a first common sense knowledge feature vector consistent with the historical dialogue emotion and a second common sense knowledge feature vector consistent with the empathy reply emotion;
[0008] The loss of the model is calculated using the first common sense knowledge feature vector, the second common sense knowledge feature vector and the historical conversation text, and the parameters of the model are optimized using the loss until the model converges.
[0009] In addition, according to the model training method for realizing empathetic dialogue in the first aspect of the present disclosure, the dialogue sentence emotion type distribution obtained based on the dialogue sentence emotion type and the empathetic reply emotion type distribution obtained based on the empathetic reply emotion type are adopted, and the emotion consistency selection model included in the model is used to screen the common sense knowledge text set to obtain a first common sense knowledge feature vector consistent with the historical dialogue emotion and a second common sense knowledge feature vector consistent with the empathetic reply emotion, including:
[0010] Using the neural network encoder included in the model to encode each common sense knowledge text in the common sense knowledge text set to obtain an original common sense knowledge feature encoding vector of each common sense knowledge text;
[0011] Using the sentiment consistency selection model to process each of the original common sense knowledge feature encoding vectors to obtain the predicted sentiment type distribution of each of the common sense knowledge texts;
[0012] Calculating a first cross entropy loss between a target dialogue sentence emotion type distribution and a predicted dialogue sentence emotion type distribution included in the predicted emotion type distribution, and calculating a second cross entropy loss between a target empathy reply emotion type distribution and a predicted empathy reply emotion type distribution included in the predicted emotion type distribution; the target dialogue sentence emotion type distribution and the predicted dialogue sentence emotion type distribution correspond to the same target dialogue sentence, and the target empathy reply emotion type distribution and the predicted empathy reply emotion type distribution correspond to the same target reply sentence;
[0013] The first common sense knowledge feature vector is obtained from the original common sense knowledge feature encoding vector of the target dialogue sentence using the first cross entropy loss; and the second common sense knowledge feature vector is obtained from the original common sense knowledge feature encoding vector of the target reply sentence using the second cross entropy loss.
[0014] In addition, according to the model training method for realizing empathetic dialogue of the first aspect of the present disclosure, the loss of the model is calculated using the first common sense knowledge feature vector, the second common sense knowledge feature vector and the historical dialogue text, including:
[0015] Using the first common sense knowledge feature vector and the historical conversation text, predicting context emotion prediction distribution and conversation sentence emotion prediction distribution, and using the second common sense knowledge feature vector and the historical conversation text, predicting empathy response prediction distribution and empathy response conversation text;
[0016] The first model loss is calculated using the context emotion prediction distribution and the annotated context emotion distribution of the historical dialogue text; the second model loss is calculated using the dialogue sentence emotion prediction distribution and the dialogue sentence emotion type distribution; the third model loss is calculated using the empathy reply prediction distribution and the empathy reply emotion type distribution of the reply sentence; and the fourth model loss is calculated based on the empathy reply dialogue text and the standard empathy reply dialogue text in the historical dialogue text;
[0017] The first model loss, the second model loss, the third model loss and the fourth model loss are used as the model loss.
[0018] In addition, according to the model training method for realizing empathetic dialogue in the first aspect of the present disclosure, using the first common sense knowledge feature vector and the historical dialogue text, predicting context emotion prediction distribution and dialogue sentence emotion prediction distribution includes:
[0019] Using the memory neural network included in the model to fuse the first common sense knowledge feature vector and the original historical dialogue feature encoding vector of the historical dialogue text to obtain a dialogue mixed feature encoding vector;
[0020] The context emotion classifier included in the model is used to predict the dialogue mixed feature encoding vector to obtain the context emotion prediction distribution; and the dialogue sentence emotion classifier included in the model is used to predict the dialogue mixed feature encoding vector to obtain the dialogue sentence emotion prediction distribution.
[0021] In addition, according to the model training method for realizing empathy dialogue in the first aspect of the present disclosure, using the second common sense knowledge feature vector and the historical dialogue text, predicting empathy reply prediction distribution and empathy reply dialogue text includes:
[0022] Using the memory neural network included in the model to fuse the second common sense knowledge feature vector and the original historical dialogue feature encoding vector of the historical dialogue text to obtain an empathy response hybrid encoding feature;
[0023] Using the empathy reply sentiment classifier included in the model to predict the empathy reply mixed coding feature to obtain the empathy reply sentiment prediction distribution;
[0024] The empathy response dialogue text is obtained by using the neural network decoder and the cross attention module included in the model, and based on the empathy response sentiment prediction distribution, the empathy response mixed encoding features and the original common sense knowledge feature encoding vector of the historical dialogue text.
[0025] In addition, according to the model training method for realizing empathy dialogue of the first aspect of the present disclosure, the neural network decoder and the cross attention module included in the model are adopted, and based on the empathy reply sentiment prediction distribution, the empathy reply hybrid encoding feature and the original common sense knowledge feature encoding vector of the historical dialogue text, the empathy reply dialogue text is obtained, including:
[0026] Using the original common sense knowledge feature encoding vector as the key and value of the cross attention module, using the empathy response mixed feature encoding feature as the query vector of the cross attention module, processing the original common sense knowledge feature encoding vector to obtain a vector representation of the cross attention module output;
[0027] The vector representation and the empathy response sentiment prediction distribution are input into the neural network decoder to obtain the empathy response text.
[0028] According to a second aspect of the present disclosure, a model training device for implementing empathy dialogue is provided, comprising:
[0029] An acquisition module, used to acquire a historical dialogue text and a common sense relationship set, wherein the dialogue sentences in the historical dialogue text are annotated with dialogue sentence emotion types, and the reply sentences in the historical dialogue text are annotated with empathy reply emotion types;
[0030] A generation module, configured to generate a common sense knowledge text set of the historical dialogue text by using the common sense knowledge generation model included in the model and according to the common sense relationship types included in the common sense relationship set, wherein each dialogue sentence and reply sentence in the historical dialogue text corresponds to a plurality of common sense knowledge texts;
[0031] A screening module, for using the dialogue sentence emotion type distribution obtained based on the dialogue sentence emotion type and the empathy reply emotion type distribution obtained based on the empathy reply emotion type, and using the emotion consistency selection model included in the model, to screen the common sense knowledge text set to obtain a first common sense knowledge feature vector consistent with the historical dialogue emotion and a second common sense knowledge feature vector consistent with the empathy reply emotion;
[0032] An optimization module is used to calculate the loss of the model using the first common sense knowledge feature vector, the second common sense knowledge feature vector and the historical conversation text, and optimize the parameters of the model using the loss until the model converges.
[0033] According to a third aspect of the present disclosure, an electronic device is provided, comprising a memory, a processor, and a computer program stored in the memory, wherein the processor executes the computer program to implement the steps of the method described in the first aspect.
[0034] According to a fourth aspect of the present disclosure, a computer-readable storage medium is provided, on which a computer program / instruction is stored, and when the computer program / instruction is executed by a processor, the steps of the method described in the first aspect are implemented.
[0035] According to a fifth aspect of the present disclosure, there is provided a computer program product, comprising a computer program / instruction, which implements the steps of the method described in the first aspect when executed by a processor.
[0036] As will be described in detail below, according to the model training method for realizing empathetic dialogue in the embodiment of the present disclosure, the common sense knowledge text set generated by the common sense knowledge generation model is screened using the emotion type distribution of dialogue sentences and the emotion type distribution of empathetic replies in the historical dialogue text to obtain a first common sense knowledge feature vector and a second common sense knowledge feature vector. This allows the screened common sense knowledge feature vector to conform to the dialogue content and improve the comprehension ability of the dialogue system.
[0037] It is to be understood that both the foregoing general description and the following detailed description are exemplary, and are intended to provide further explanation of the technology as claimed. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] The above and other purposes, features and advantages of the present disclosure will become more apparent by describing the embodiments of the present disclosure in more detail in conjunction with the accompanying drawings. The accompanying drawings are used to provide a further understanding of the embodiments of the present disclosure and constitute a part of the specification. Together with the embodiments of the present disclosure, they are used to explain the present disclosure and do not constitute a limitation of the present disclosure. In the accompanying drawings, the same reference numerals generally represent the same components or steps.
[0039] Figure 1 It is a flowchart illustrating a model training method for implementing empathetic dialogue according to an embodiment of the present disclosure.
[0040] Figure 2 is another flowchart illustrating the model training method for implementing empathetic dialogue according to an embodiment of the present disclosure.
[0041] Figure 3 It is a diagram illustrating the overall structure of a model according to an embodiment of the present disclosure.
[0042] Figure 4 is a schematic diagram illustrating a dialog example of applying an embodiment of the present disclosure.
[0043] Figure 5 It is a schematic diagram illustrating the application of common sense knowledge of the xReact type corresponding to the last user utterance according to an embodiment of the present disclosure.
[0044] Figure 6FIG. 2 is a schematic diagram illustrating a model training device for implementing empathetic dialogue according to an embodiment of the present disclosure.
[0045] Figure 7 is a hardware block diagram illustrating an electronic device according to an embodiment of the present disclosure.
[0046] Figure 8 is a schematic diagram illustrating a computer-readable storage medium according to an embodiment of the present disclosure. DETAILED DESCRIPTION
[0047] In order to make the purpose, technical scheme and advantages of the embodiments of the present disclosure clearer, the technical scheme in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the drawings in the embodiments of the present disclosure. Obviously, the described embodiments are only part of the embodiments of the present disclosure, rather than all of the embodiments. The components of the embodiments of the present disclosure generally described and shown in the drawings here can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present disclosure provided in the drawings is not intended to limit the scope of the present disclosure for protection, but merely represents the selected embodiments of the present disclosure. Based on the embodiments of the present disclosure, all other embodiments obtained by those skilled in the art without making creative work belong to the scope of protection of the present disclosure.
[0048] It should be noted that similar reference numerals and letters denote similar items in the following drawings, and therefore, once an item is defined in one drawing, further definition and explanation thereof is not required in subsequent drawings.
[0049] The term "and / or" herein only describes an association relationship, indicating that three relationships may exist. For example, A and / or B may represent the following three situations: A exists alone, A and B exist at the same time, and B exists alone. In addition, the term "at least one" herein represents any combination of at least two of any one or more of a plurality of. For example, including at least one of A, B, and C may represent including any one or more elements selected from the set consisting of A, B, and C.
[0050] Empathy is the most basic cognitive ability of humans in the process of communication. If a dialogue system wants to have this ability, it must be able to understand the user's emotions and have a certain amount of human common sense knowledge. Therefore, the current empathy dialogue system focuses on using common sense knowledge to perceive human emotions in human-computer interaction. To this end, researchers trained the common sense knowledge generation model COMET. After inputting the dialogue context and special words, the model will generate human common sense knowledge related to the dialogue. Although the amount of common sense knowledge is large, due to the performance problems of the common sense knowledge generation model itself, the generated common sense knowledge does not completely conform to the dialogue content, which leads to deviations in the understanding of the dialogue system.
[0051] In order to alleviate the technical problems existing in the related art, the embodiments of the present disclosure provide a model training method, device, medium and product for realizing empathetic dialogue. The method uses the emotional type distribution of dialogue sentences and the emotional type distribution of empathetic responses of historical dialogue texts to screen the common sense knowledge text set generated by the common sense knowledge generation model, and obtains a first common sense knowledge feature vector and a second common sense knowledge feature vector, so that the screened common sense knowledge feature vector can be consistent with the dialogue content and improve the understanding ability of the dialogue system.
[0052] To facilitate understanding of this embodiment, a model training method for realizing empathy dialogue disclosed in an embodiment of the present disclosure is first introduced in detail. The execution subject of the model training method for realizing empathy dialogue provided in the embodiment of the present disclosure is generally an electronic device with certain computing capabilities, and the electronic device includes, for example, a terminal device or a server or other processing device. In some possible implementations, the model training method for realizing empathy dialogue can be implemented by a processor calling computer-readable instructions stored in a memory.
[0053] See also Figure 1 FIG. 1 is a flowchart of a model training method for implementing empathy dialogue provided by an embodiment of the present disclosure, and the method includes the following steps:
[0054] Step 101: Obtain historical dialogue texts and common sense relationship sets, dialogue sentences in the historical dialogue texts are annotated with dialogue sentence emotion types, and reply sentences in the historical dialogue texts are annotated with empathy reply emotion types.
[0055] In this embodiment, the historical conversation text includes multiple rounds of contextual conversations, and each round of contextual conversations includes a previous conversation and a next conversation.
[0056] In this embodiment, the common sense relationship set includes a plurality of pre-set common sense relationship types, each of which is used to represent the parsing angle of the historical dialogue text. For example, the common sense relationship type is used to represent the impact of an event on a user, the user's reaction, the user's intention, the user's needs, and / or what the user wants after speaking, etc. In practical applications, the dialogue statement set D can be obtained by adding a special tag CLS in front of each dialogue statement text in the historical dialogue text, and adding five different special tags xEffect, xReact, xIntent, xNeed, and xWant at the end. Among them, each special tag represents a type of knowledge, xEffect represents the impact of an event on a user, xReact represents the user's reaction, xIntent represents the user's intention, xNeed represents the user's needs, and xWant represents what the user wants after speaking. After encoding the dialogue statement through a neural network encoder, the vector representation of the CLS tag can be used to represent the entire sentence.
[0057] In this embodiment, the dialogue sentence emotion type is used to represent the emotion of the user who issued the previous dialogue, and the empathy reply emotion type is used to represent the emotion of the user who issued the following dialogue.
[0058] Step 102: using the common sense knowledge generation model included in the model, and generating a common sense knowledge text set of the historical dialogue text according to the common sense relationship types included in the common sense relationship set, each dialogue sentence and reply sentence in the historical dialogue text corresponds to a plurality of common sense knowledge texts.
[0059] The obtained dialogue sentence set D is input into the pre-trained common sense knowledge generation model COMET. When the dialogue sentence is input into the model, the model will generate knowledge text according to the pre-defined common sense knowledge type and obtain the common sense knowledge text set K related to the dialogue.
[0060] Step 103: Using the dialogue sentence emotion type distribution obtained based on the dialogue sentence emotion type and the empathy reply emotion type distribution obtained based on the empathy reply emotion type, and using the emotion consistency selection model included in the model, the common sense knowledge text collection is screened to obtain a first common sense knowledge feature vector consistent with the historical dialogue emotion and a second common sense knowledge feature vector consistent with the empathy reply emotion.
[0061] In one or more embodiments, step 103 may include the following steps:
[0062] Using a neural network encoder included in the model to encode the common sense knowledge texts in the common sense knowledge text set, and obtaining an original common sense knowledge feature encoding vector of each common sense knowledge text;
[0063] The sentiment consistency selection model is used to process the feature encoding vectors of each original common sense knowledge to obtain the predicted sentiment type distribution of each common sense knowledge text;
[0064] Calculating a first cross entropy loss between a target dialogue sentence emotion type distribution and a predicted dialogue sentence emotion type distribution included in the predicted emotion type distribution, and calculating a second cross entropy loss between a target empathy reply emotion type distribution and a predicted empathy reply emotion type distribution included in the predicted emotion type distribution; the target dialogue sentence emotion type distribution and the predicted dialogue sentence emotion type distribution correspond to the same target dialogue sentence, and the target empathy reply emotion type distribution and the predicted empathy reply emotion type distribution correspond to the same target reply sentence;
[0065] A first common sense knowledge feature vector is obtained from an original common sense knowledge feature encoding vector of a target dialogue sentence using a first cross entropy loss; and a second common sense knowledge feature vector is obtained from an original common sense knowledge feature encoding vector of a target reply sentence using a second cross entropy loss.
[0066] Among them, the first cross entropy loss is used to characterize the correlation between the distribution of dialogue emotion sentences and the distribution of emotion types of each predicted dialogue sentence, and the second cross entropy loss is used to characterize the correlation between the distribution of empathy response emotion types and the distribution of each predicted empathy response emotion types. The larger the cross entropy loss value, the greater the gap between the two emotion type distributions and the greater the emotional difference.
[0067] Whether obtaining the first common sense knowledge feature vector based on the first cross entropy loss or obtaining the second common sense knowledge feature vector based on the second cross entropy loss, the sequence numbers of the common sense knowledge can be rearranged from large to small according to the cross entropy loss value, and the first z sequence numbers Index before the arrangement are recorded. uttr , the knowledge corresponding to these z numbers is regarded as the knowledge least relevant to the dialogue, and the original common sense knowledge feature encoding vector corresponding to these z numbers is removed.
[0068] Step 104: Calculate the loss of the model using the first common sense knowledge feature vector, the second common sense knowledge feature vector and the historical conversation text, and use the loss to optimize the parameters of the model until the model converges.
[0069] In one or more embodiments, step 104 may include the following steps:
[0070] Using the first common sense knowledge feature vector and the historical dialogue text, predicting the context emotion prediction distribution and the dialogue sentence emotion prediction distribution, and using the second common sense knowledge feature vector and the historical dialogue text, predicting the empathy response prediction distribution and the empathy response dialogue text;
[0071] The first model loss is calculated using the context emotion prediction distribution and the context emotion distribution of the historical dialogue texts annotated; the second model loss is calculated using the dialogue sentence emotion prediction distribution and the dialogue sentence emotion type distribution; the third model loss is calculated using the empathy reply prediction distribution and the empathy reply emotion type distribution of the reply sentence; and the fourth model loss is calculated based on the empathy reply dialogue text and the standard empathy reply dialogue text in the historical dialogue texts;
[0072] The first model loss, the second model loss, the third model loss and the fourth model loss are taken as model losses.
[0073] Among them, the contextual sentiment prediction distribution is used to represent the overall emotional tone of the historical dialogue text, and the empathy response dialogue text is the dialogue context of the dialogue context to be predicted in the historical dialogue text.
[0074] In this embodiment, the context emotion prediction distribution can be obtained based on the context emotion classifier. In specific implementation, in one or more embodiments, using the first common sense knowledge feature vector and the historical dialogue text to predict the context emotion prediction distribution and the dialogue sentence emotion prediction distribution can include the following steps:
[0075] The memory neural network included in the model is used to fuse the first common sense knowledge feature vector and the original historical dialogue feature encoding vector of the historical dialogue text to obtain a dialogue mixed feature encoding vector;
[0076] The context emotion classifier included in the model is used to predict the dialogue mixed feature coding vector to obtain the context emotion prediction distribution; and the dialogue sentence emotion classifier included in the model is used to predict the dialogue mixed feature coding vector to obtain the dialogue sentence emotion prediction distribution.
[0077] By fusing the first common sense knowledge feature vector with the original historical dialogue feature encoding vector of the historical dialogue text, the historical dialogue text can be endowed with common sense features.
[0078] In this embodiment, the empathy reply dialogue text can be obtained based on the neural network decoder and the cross attention module. In specific implementation, in one or more embodiments, using the second common sense knowledge feature vector and the historical dialogue text to predict the empathy reply prediction distribution and the empathy reply dialogue text can include the following steps:
[0079] The memory neural network included in the model is used to fuse the second common sense knowledge feature vector and the original historical dialogue feature encoding vector of the historical dialogue text to obtain the empathy response mixed encoding feature;
[0080] The empathy reply sentiment classifier included in the model is used to predict the mixed coding features of the empathy reply to obtain the empathy reply sentiment prediction distribution;
[0081] The model includes a neural network decoder and a cross-attention module, and the empathetic reply dialogue text is obtained based on the empathetic reply sentiment prediction distribution, the empathetic reply hybrid encoding features and the original common sense knowledge feature encoding vector of the historical dialogue text.
[0082] In this embodiment, when using the neural network decoder and the cross-attention module to obtain the empathetic response dialogue text, the original common sense knowledge feature encoding vector can be used as the key and value of the cross-attention module, and the empathetic response mixed feature encoding feature can be used as the query vector of the cross-attention module. The original common sense knowledge feature encoding vector is processed to obtain the vector representation output by the cross-attention module; the vector representation and the empathetic response emotion prediction distribution are input into the neural network decoder to obtain the empathetic response text.
[0083] In the solution provided in this embodiment, for the common sense knowledge text set generated by the common sense knowledge generation model, the emotion type distribution of the dialogue sentences and the emotion type distribution of the empathy response of the historical dialogue text are used for screening to obtain the first common sense knowledge feature vector and the second common sense knowledge feature vector. In this way, the screened common sense knowledge feature vector can be made consistent with the dialogue content and the understanding ability of the dialogue system can be improved.
[0084] The present application also provides a model training method for realizing empathy dialogue, such as Figure 2 As shown, the method may include the following steps:
[0085] Step s1: Input the historical dialogue text D and the pre-specified common sense relationship set into the common sense knowledge generation model to obtain the common sense knowledge text set K related to the dialogue. Then, input the historical dialogue text D and the common sense knowledge text set K into the neural network encoder respectively to obtain the original historical dialogue feature encoding vector and the original common sense knowledge feature encoding vector H K The common sense knowledge text set obtained in this step can provide a reference for the dialogue model and enhance the dialogue model's understanding of the chat content, which is similar to human conversation habits. Encoding the historical dialogue text D and the common sense knowledge text set K into vector representation using a neural network encoder can facilitate subsequent operations, and finally using a neural network decoder to generate empathic response text.
[0086] Step s2: In order to ensure the emotional consistency between historical dialogues, common sense knowledge and empathetic responses, the original common sense knowledge feature encoding vector H K , dialogue sentence sentiment type distribution P uttr And the distribution of empathy response sentiment type P resThe data is input into the emotion consistency knowledge selection module to obtain two common sense knowledge feature encoding vectors after emotion consistency knowledge selection, one of which is a common sense knowledge feature vector consistent with the emotion of the historical dialogue, and the other is a common sense knowledge feature vector consistent with the emotion of the empathetic response.
[0087] It should be understood that the emotion type distribution of the dialogue sentences here is the emotion type distribution of the historical dialogue text D that is pre-annotated, and the emotion type distribution of the dialogue sentences is used to represent the emotion or mood of the user who issued each dialogue context in the historical dialogue text D. The emotion type distribution of the empathy reply is also the emotion type distribution pre-annotated in the historical dialogue text D, and the emotion type distribution of the empathy reply is used to represent the emotion or mood of the user who issued each dialogue context in the historical dialogue text D.
[0088] Through step s1, each dialogue sentence will have multiple corresponding common sense knowledge texts, but not every common sense knowledge is related to the dialogue, so it needs to be screened. In this step, the feature representation of multiple common sense knowledge texts of each dialogue sentence (i.e., the original common sense knowledge feature encoding vector) is passed through a fully connected layer to obtain the emotional type distribution of the knowledge, and the cross entropy loss value is calculated with the emotional type distribution of the dialogue sentence and the emotional type distribution of the empathetic response. The loss result is used to screen the knowledge to ensure that the common sense knowledge is consistent with the dialogue context and the emotion of the empathetic response.
[0089] Step s3: The two common sense knowledge feature encoding vectors obtained in step s2 after the selection of emotional consistency knowledge are combined with the original historical dialogue feature encoding vectors and input into the bidirectional long short-term memory neural network (Bi-LSTM) to obtain the dialogue mixed feature encoding vector and the empathy reply mixed encoding feature. The dialogue mixed feature encoding vector is input into the context emotion classifier and the dialogue sentence emotion classifier to obtain the context emotion prediction distribution and the dialogue sentence emotion prediction distribution. The empathy reply mixed feature encoding vector is input into the empathy reply emotion classifier to obtain the empathy reply emotion prediction distribution. The function of this step is to improve the model's emotion understanding ability by modeling emotions from different angles of historical dialogues. The accuracy of the emotion type distribution predicted by the dialogue model is not high at the beginning. It is necessary to construct the emotion cross entropy loss function using the predicted emotion distribution and the emotion distribution of the labeled emotion tags to train the dialogue model and continuously improve the emotion prediction accuracy of the model.
[0090] Step s4: Input the empathy reply hybrid feature encoding vector, the original common sense knowledge feature encoding vector and the empathy reply sentiment prediction distribution into the neural network decoder to obtain the empathy dialogue reply text that is consistent with the historical dialogue sentiment. The neural network decoder can use the input feature information to predict the output result. Therefore, the function of this step is to combine the common sense knowledge feature information and the sentiment prediction feature information to generate a reply text with consistent sentiment and appropriate content.
[0091] The overall structure of the model involved in the embodiment of the present application is as follows Figure 3 As shown in the figure, it is divided into four modules, namely context and knowledge encoding module, emotion consistency knowledge selection module, emotion prediction module and empathy response generation module. First, the common sense knowledge generation model is used to obtain the common sense knowledge text related to the dialogue; then, the common sense knowledge text and dialogue context are encoded into vectors and input into the emotion consistency knowledge selection module to obtain the filtered common sense knowledge vector representation; then, the context vector representation, empathy response vector representation and selected common sense knowledge vector representation are fused through the bidirectional long short-term memory network to predict the emotion type distribution of context, dialogue sentences and empathy response; finally, the neural network decoder is used to generate empathy response text for the predicted emotion type distribution and common sense knowledge vector representation of empathy response.
[0092] The following combination Figure 3 The four modules shown introduce the model training method for realizing empathetic dialogue in an embodiment of the present application.
[0093] 1. Context and Knowledge Encoding Module
[0094] In order to obtain human common sense knowledge, this model uses the common sense knowledge generation model COMET to obtain common sense knowledge. In addition, in order to integrate the vector representation of context and knowledge, a neural network encoder is used to encode the historical dialogue text and common sense knowledge text.
[0095] Step s1 includes the following sub-steps:
[0096] Step s1-1, add a special tag CLS in front of each dialogue sentence text u in the historical dialogue text, and add five different special tags xEffect, xReact, xIntent, xNeed and xWant at the end to obtain the dialogue sentence set D. Each special tag represents a type of knowledge, xEffect represents the impact of the event on the user, xReact represents the user's reaction, xIntent represents the user's intention, xNeed represents the user's needs, and xWant represents what the user wants after speaking. After encoding the dialogue sentence through the neural network encoder, the vector representation of the CLS tag can be used to represent the entire sentence.
[0097] Step s1-2, input the obtained dialogue sentence set D into the common sense knowledge generation model COMET. The model has been pre-trained. When the dialogue sentence is input into the model, the model will generate knowledge text according to the pre-defined common sense knowledge type, and obtain the original common sense knowledge text set K related to the dialogue. Then, the historical dialogue text and the original common sense knowledge text set are input into the neural network encoder to obtain the original historical dialogue feature encoding vector and the original common sense knowledge feature encoding vector. The subsequent operations are all performed on the vector representation.
[0098] (II) Emotional consistency knowledge selection module
[0099] Since the common sense knowledge model itself cannot generate knowledge that fully meets the requirements, it is necessary to screen the generated knowledge and filter out the knowledge that does not meet the dialogue requirements. Otherwise, it is easy for the dialogue model to be misled by wrong knowledge and generate empathic responses that are inconsistent with the facts of historical dialogues. In order to select knowledge that is consistent with the emotions of historical dialogues, the present invention uses an emotional consistency knowledge selection module to select knowledge based on the consistency between the knowledge and the emotional type of the dialogue and empathic response. This module can filter out common sense knowledge that is inconsistent with the emotions of historical dialogues.
[0100] Step s2 includes the following sub-steps:
[0101] Step s2-1, encode the original common sense knowledge feature vector H K , dialogue sentence sentiment type distribution P uttr And the distribution of empathy response sentiment type P res as input.
[0102] Step s2-2, each dialogue sentence includes 5 types of common sense knowledge, each type includes 5 common sense knowledge texts, each text corresponds to a common sense knowledge feature encoding sub-vector, and the knowledge sequence number can be 0, 1, 2, 3, 4. The high-dimensional original common sense knowledge feature encoding vector is used as the input of the fully connected layer to obtain the low-dimensional common sense knowledge sentiment type distribution set P kno The cross entropy loss is constructed for the predicted common sense knowledge emotion type distribution and the real dialogue sentence emotion type distribution. The cross entropy loss is used to measure the similarity between the two:
[0103] Loss uttr = -log(P kno (P uttr ))
[0104] The larger the cross entropy loss value, the larger the gap between the two sentiment types and the greater the difference in sentiment. Rearrange the sequence numbers of common sense knowledge from large to small according to the cross entropy loss value, and record the index of the first z sequence numbers in the arrangement.uttr , and take the knowledge corresponding to these z numbers as the knowledge least relevant to the dialogue:
[0105] Index uttr =top z {Sort(Loss uttr )}
[0106] Step s2-3, in the original common sense knowledge feature encoding vector H K In , the feature encoding vector value of the knowledge corresponding to the sequence number is set to 0. This means that in subsequent operations, this knowledge will no longer affect the final generation result, which is equivalent to removing knowledge that is irrelevant to the emotion of the dialogue context.
[0107] Step s2-4: Step s2-2 considers the consistency between common sense knowledge and the emotion of the dialogue context. Next, we need to consider the consistency between common sense knowledge and the emotion of the empathetic response. The common sense knowledge emotion type distribution has been obtained in step s2-2. The empathetic response emotion type is provided in the dataset during the training phase. Therefore, the common sense knowledge emotion type distribution P is directly constructed. kno And the distribution of empathy response sentiment type P res The cross entropy loss function is:
[0108] Loss res = -log(P kno (P res ))
[0109] And rearrange the sequence numbers from large to small according to the cross entropy loss value, and record the first z sequence numbers Index res :
[0110] Index res =top z {Sort(Loss res )}
[0111] Step s2-5, in the original common sense knowledge feature coding vector, the feature coding vector value of the knowledge corresponding to the sequence number is set to 0, which is equivalent to removing knowledge that is irrelevant to the empathetic response emotion.
[0112] During the test, the dialogue data did not provide the empathy response text and the distribution of empathy response sentiment types P. res According to the habits of human conversation, the emotional expressions between the closest conversations are often similar, so it is assumed that P res is the sentiment type distribution of the last conversation sentence in the historical conversation.
[0113] Step s2-6: After the iterative process of s2-2 to s2-5, the common sense knowledge feature encoding vector H that is consistent with the historical dialogue emotion can be obtained. Kdiaand the common sense knowledge feature encoding vector H that is consistent with the empathetic response Kres .
[0114] Please refer to Figure 4 , Figure 4 This is a conversation instance in the dataset, which is used as an example to illustrate the knowledge selection process.
[0115] Each dialogue sentence in the dialogue instance is marked with the corresponding emotion. According to step s1, the dialogue is input into the common sense knowledge model, and each dialogue sentence can obtain a series of common sense knowledge texts. The knowledge selection of all dialogue sentences is a unified process, so here we take one type of knowledge as an example for discussion. Figure 5 The common sense knowledge of xReact type corresponding to the last user's utterance is shown in , which are "tired", "angry", "frustrated", "annoyed" and "lost". According to step s2-2, the common sense knowledge is first input into the sentiment classifier to obtain the sentiment type distribution of the knowledge, and then the knowledge consistent with the sentiment of the dialogue sentence is selected according to step s2-2. The sentiment of the last user's dialogue sentence is "sad". The cross entropy loss between "sad" and the sentiment type distribution of the 5 pieces of knowledge is calculated. The results after sorting are as follows: Figure 4 As shown on the right. If z is taken as 2, the two pieces of knowledge "depressed" and "lost" should be removed. Then, according to step s2-4, select the knowledge that is consistent with the emotion of the empathetic response. The emotion of the empathetic response is "neutral". Calculate the cross entropy loss between "neutral" and the emotional type distribution of the 5 pieces of knowledge, sort them and take the first z pieces of knowledge. The specific process will not be repeated here.
[0116] (III) Emotion prediction module
[0117] In order to improve the dialogue model's ability to understand the emotions of historical dialogues and predict the emotions of empathetic replies, it is necessary to analyze the emotions of historical dialogues from multiple dimensions. This embodiment will jointly train the model's emotion analysis capabilities through three subtasks: context emotion prediction, discourse emotion prediction, and empathetic reply emotion prediction. In addition, the results of empathetic reply emotion prediction will also be used for the final empathetic reply generation.
[0118] Step s3 includes the following sub-steps:
[0119] s3-1: Encode the common sense knowledge features consistent with the historical dialogue into a vector and the original historical conversation feature encoding vector H D Input the bidirectional long short-term memory network (Bi-LSTM) to obtain the mixed feature encoding vector of the dialogue, and convert the common sense knowledge feature encoding vector consistent with the empathy reply into The original historical dialogue vector representation is input into the bidirectional long short-term memory network to obtain the empathy response mixed feature encoding vector. Bidirectional long short-term memory network has a wide range of applications in modeling tasks of sequence data, such as speech recognition, natural language processing, handwriting recognition, etc. By utilizing past and future contextual information, Bi-LSTM can better capture long-term dependencies in the sequence and improve the performance and accuracy of the model. Therefore, Bi-LSTM can effectively integrate dialogue information and knowledge information.
[0120] s3-2, input the dialogue mixed feature encoding vector into the context emotion classifier to obtain the context emotion prediction distribution P dia . Construct contextual sentiment prediction distribution P dia The contextual sentiment classifier is trained by the cross entropy loss function of the original contextual sentiment type distribution e. The sentiment predicted by the initial sentiment classifier is quite different from the real annotated contextual sentiment, so it is necessary to optimize it in the training phase by minimizing the cross entropy loss, and the subsequent sentiment prediction also needs to do so:
[0121]
[0122] s3-3: Divide the dialogue mixed feature encoding vector by dialogue sentence, input the dialogue sentence sentiment classifier, obtain the dialogue sentence sentiment prediction distribution, and construct the dialogue sentence sentiment prediction distribution P uttr The cross entropy loss function of the original dialogue sentence emotion type distribution u is used to train the dialogue sentence emotion classifier:
[0123]
[0124] s3-4: Input the empathy reply mixed feature encoding vector into the empathy reply sentiment classifier, obtain the empathy reply sentiment prediction distribution, and construct the empathy reply sentiment prediction distribution P res The cross entropy loss function with the original empathy reply sentiment type distribution r is used to train the empathy reply sentiment classifier:
[0125]
[0126] (IV) Empathy Response Generation Module
[0127] After training on the emotion prediction task, the model's emotion understanding ability can be improved. Finally, this model will use common sense knowledge and empathetic responses to predict the distribution of emotions, and combine the neural network decoder and cross-attention mechanism to generate empathetic response text that is consistent with the historical dialogue emotions.
[0128] Step s4 includes the following sub-steps:
[0129] s4-1: Encode the original common sense knowledge feature vector HK As the key and value of the cross-attention module, the empathy reply hybrid feature encoding vector is used as the query of the cross-attention module to process the original common sense knowledge feature encoding vector. The cross-attention mechanism can help the model establish global connections between different sequences, so that the model can take into account all the information in the source sequence that is relevant to the current position of the target sequence. In addition, the cross-attention mechanism can also help the model focus on the part of the source sequence that is most relevant to the current position of the target sequence, which can ensure that the model focuses on the source language information that plays a key role in the generation of the current position.
[0130] s4-2: Combine the vector representation obtained after processing the cross-attention module with the empathy response sentiment prediction distribution P res Input the neural network decoder to obtain the final empathy response text. After obtaining the final empathy response text, the model loss can be calculated based on the final empathy response text and the standard empathy response text corresponding to the final empathy response text in the historical dialogue text, and the model loss can be used to optimize the model parameters.
[0131] The present disclosure also provides a model training device for implementing empathy dialogue, which is used to execute the model training method for implementing empathy dialogue provided in any of the above embodiments. Figure 6 As shown, the device comprises:
[0132] An acquisition module 61 is used to acquire a historical dialogue text and a common sense relationship set, wherein the dialogue sentences in the historical dialogue text are annotated with dialogue sentence emotion types, and the reply sentences in the historical dialogue text are annotated with empathy reply emotion types;
[0133] A generation module 62, configured to generate a common sense knowledge text set of the historical dialogue text by using the common sense knowledge generation model included in the model and according to the common sense relationship types included in the common sense relationship set, wherein each dialogue sentence and reply sentence in the historical dialogue text corresponds to a plurality of common sense knowledge texts;
[0134] A screening module 63 is used to use the dialogue sentence emotion type distribution obtained based on the dialogue sentence emotion type and the empathy reply emotion type distribution obtained based on the empathy reply emotion type, and use the emotion consistency selection model included in the model to screen the common sense knowledge text set to obtain a first common sense knowledge feature vector consistent with the historical dialogue emotion and a second common sense knowledge feature vector consistent with the empathy reply emotion;
[0135] The optimization module 64 is used to calculate the loss of the model using the first common sense knowledge feature vector, the second common sense knowledge feature vector and the historical conversation text, and optimize the parameters of the model using the loss until the model converges.
[0136] In one or more embodiments, the screening module 63 is used to:
[0137] Using the neural network encoder included in the model to encode the common sense knowledge texts in the common sense knowledge text set to obtain the original common sense knowledge feature encoding vector of each common sense knowledge text;
[0138] Using the sentiment consistency selection model to process each of the original common sense knowledge feature encoding vectors to obtain the predicted sentiment type distribution of each of the common sense knowledge texts;
[0139] Calculating a first cross entropy loss between a target dialogue sentence emotion type distribution and a predicted dialogue sentence emotion type distribution included in the predicted emotion type distribution, and calculating a second cross entropy loss between a target empathy reply emotion type distribution and a predicted empathy reply emotion type distribution included in the predicted emotion type distribution; the target dialogue sentence emotion type distribution and the predicted dialogue sentence emotion type distribution correspond to the same target dialogue sentence, and the target empathy reply emotion type distribution and the predicted empathy reply emotion type distribution correspond to the same target reply sentence;
[0140] The first common sense knowledge feature vector is obtained from the original common sense knowledge feature encoding vector of the target dialogue sentence using the first cross entropy loss; and the second common sense knowledge feature vector is obtained from the original common sense knowledge feature encoding vector of the target reply sentence using the second cross entropy loss.
[0141] In one or more embodiments, the optimization module 64 is used to:
[0142] Using the first common sense knowledge feature vector and the historical dialogue text, predicting context emotion prediction distribution and dialogue sentence emotion prediction distribution, and using the second common sense knowledge feature vector and the historical dialogue text, predicting empathy response dialogue text;
[0143] The first model loss is calculated using the context emotion prediction distribution and the annotated context emotion distribution of the historical dialogue text; the second model loss is calculated using the dialogue sentence emotion prediction distribution and the dialogue sentence emotion type distribution; the third model loss is calculated using the empathy reply prediction distribution and the empathy reply emotion type distribution of the reply sentence; and the fourth model loss is calculated based on the empathy reply dialogue text and the standard empathy reply dialogue text in the historical dialogue text;
[0144] The first model loss, the second model loss, the third model loss and the fourth model loss are used as the model loss.
[0145] In one or more embodiments, the optimization module 64 is used to:
[0146] Using the memory neural network included in the model to fuse the first common sense knowledge feature vector and the original historical dialogue feature encoding vector of the historical dialogue text to obtain a dialogue mixed feature encoding vector;
[0147] The context emotion classifier included in the model is used to predict the dialogue mixed feature encoding vector to obtain the context emotion prediction distribution; and the dialogue sentence emotion classifier included in the model is used to predict the dialogue mixed feature encoding vector to obtain the dialogue sentence emotion prediction distribution.
[0148] In one or more embodiments, the optimization module 64 is used to:
[0149] Using the memory neural network included in the model to fuse the second common sense knowledge feature vector and the original historical dialogue feature encoding vector of the historical dialogue text to obtain an empathy response hybrid encoding feature;
[0150] Using the empathy reply sentiment classifier included in the model to predict the empathy reply mixed coding feature to obtain the empathy reply sentiment prediction distribution;
[0151] The empathy response dialogue text is obtained by using the neural network decoder and the cross attention module included in the model, and based on the empathy response sentiment prediction distribution, the empathy response mixed encoding features and the original common sense knowledge feature encoding vector of the historical dialogue text.
[0152] In one or more embodiments, the optimization module 64 is used to:
[0153] Using the original common sense knowledge feature encoding vector as the key and value of the cross attention module, using the empathy response mixed feature encoding feature as the query vector of the cross attention module, processing the original common sense knowledge feature encoding vector to obtain a vector representation of the cross attention module output;
[0154] The vector representation and the empathy response sentiment prediction distribution are input into the neural network decoder to obtain the empathy response text.
[0155] The model training device for realizing empathy dialogue provided by the embodiment of the present disclosure and the model training method for realizing empathy dialogue provided by the embodiment of the present disclosure are based on the same inventive concept and have the same beneficial effects as the methods adopted, operated or implemented by them.
[0156] The disclosed embodiment also provides an electronic device to execute the above-mentioned model training method for realizing empathy dialogue. Figure 7 It shows a schematic diagram of an electronic device provided by some embodiments of the present disclosure. Figure 7 As shown, the electronic device 7 includes: a processor 800, a memory 801, a bus 802 and a communication interface 803, and the processor 800, the communication interface 803 and the memory 801 are connected via the bus 802; the memory 801 stores a computer program that can be run on the processor 800, and when the processor 800 runs the computer program, it executes the model training method for realizing empathetic dialogue provided by any of the aforementioned embodiments of the present disclosure.
[0157] The memory 801 may include a high-speed random access memory (RAM), and may also include a non-volatile memory, such as at least one disk storage. The communication connection between the device network element and at least one other network element is realized through at least one communication interface 803 (which may be wired or wireless), and the Internet, wide area network, local area network, metropolitan area network, etc. may be used.
[0158] The bus 802 may be an ISA bus, a PCI bus, or an EISA bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. Among them, the memory 801 is used to store programs, and the processor 800 executes the program after receiving the execution instruction. The model training method for realizing empathy dialogue disclosed in any implementation of the aforementioned embodiment of the present disclosure may be applied to the processor 800, or implemented by the processor 800.
[0159] The processor 800 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the hardware integrated logic circuit in the processor 800 or the instruction in the form of software. The above processor 800 can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The methods, steps and logic block diagrams disclosed in the embodiments of the present disclosure can be implemented or executed. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor. The steps of the method disclosed in conjunction with the embodiments of the present disclosure can be directly embodied as a hardware decoding processor to be executed, or the hardware and software modules in the decoding processor can be executed. The software module can be located in a mature storage medium in the field such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory 801, and the processor 800 reads the information in the memory 801 and completes the steps of the above method in combination with its hardware.
[0160] The electronic device provided by the embodiment of the present disclosure and the model training method for realizing empathetic dialogue provided by the embodiment of the present disclosure are based on the same inventive concept and have the same beneficial effects as the methods adopted, run or realized by them.
[0161] The present disclosure also provides a computer-readable storage medium corresponding to the model training method for implementing empathy dialogue provided in the above-mentioned embodiment. Figure 8 The computer-readable storage medium shown is a CD 30 on which a computer program (i.e., a program product) is stored. When the computer program is run by a processor, it will execute the model training method for realizing empathetic dialogue provided by any of the aforementioned embodiments.
[0162] It should be noted that examples of the computer-readable storage medium may also include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other optical or magnetic storage media, which are not listed here one by one.
[0163] The computer-readable storage medium provided by the above-mentioned embodiments of the present disclosure and the model training method for realizing empathetic dialogue provided by the embodiments of the present disclosure are based on the same inventive concept, and have the same beneficial effects as the methods adopted, run or implemented by the application programs stored therein.
[0164] It should be noted that:
[0165] In the description provided herein, a large number of specific details are described. However, it is understood that the embodiments of the present disclosure can be practiced without these specific details. In some instances, well-known structures and technologies are not shown in detail so as not to obscure the understanding of this description.
[0166] Similarly, it should be understood that in order to streamline the present disclosure and aid in understanding one or more of the various inventive aspects, in the above description of the exemplary embodiments of the present disclosure, the various features of the present disclosure are sometimes grouped together into a single embodiment, figure, or description thereof. However, the disclosed method should not be interpreted as reflecting the following schematic diagram: the claimed disclosure requires more features than the features explicitly recited in each claim. More specifically, as reflected in the claims below, the inventive aspects lie in less than all the features of the single embodiment disclosed above. Therefore, the claims that follow the specific embodiment are hereby expressly incorporated into the specific embodiment, with each claim itself serving as a separate embodiment of the present disclosure.
[0167] In addition, those skilled in the art will appreciate that, although some embodiments described herein include certain features included in other embodiments but not other features, the combination of features of different embodiments is meant to be within the scope of this disclosure and form different embodiments. For example, in the claims below, any one of the claimed embodiments may be used in any combination.
[0168] The above is only a preferred specific implementation of the present disclosure, but the protection scope of the present disclosure is not limited thereto. Any changes or substitutions that can be easily thought of by any technician familiar with the technical field within the technical scope disclosed in the present disclosure should be included in the protection scope of the present disclosure. Therefore, the protection scope of the present disclosure should be based on the protection scope of the claims.
Claims
1. A model training method for realizing empathy dialogue, characterized in that: include: Acquire a historical dialogue text and a common sense relationship set, wherein dialogue sentences in the historical dialogue text are annotated with dialogue sentence emotion types, and reply sentences in the historical dialogue text are annotated with empathy reply emotion types; Using the common sense knowledge generation model included in the model, according to the common sense relationship types included in the common sense relationship set, a common sense knowledge text set of the historical dialogue text is generated, wherein each dialogue sentence and reply sentence in the historical dialogue text corresponds to a plurality of common sense knowledge texts; Using the dialogue sentence emotion type distribution obtained based on the dialogue sentence emotion type and the empathy reply emotion type distribution obtained based on the empathy reply emotion type, and using the emotion consistency selection model included in the model, the common sense knowledge text set is screened to obtain a first common sense knowledge feature vector consistent with the historical dialogue emotion and a second common sense knowledge feature vector consistent with the empathy reply emotion; The loss of the model is calculated using the first common sense knowledge feature vector, the second common sense knowledge feature vector and the historical conversation text, and the parameters of the model are optimized using the loss until the model converges.
2. The method according to claim 1, characterized in that The common sense knowledge text set is screened by using the dialogue sentence emotion type distribution obtained based on the dialogue sentence emotion type and the empathy reply emotion type distribution obtained based on the empathy reply emotion type, and using the emotion consistency selection model included in the model to obtain a first common sense knowledge feature vector consistent with the historical dialogue emotion and a second common sense knowledge feature vector consistent with the empathy reply emotion, including: Using the neural network encoder included in the model to encode each common sense knowledge text in the common sense knowledge text set to obtain an original common sense knowledge feature encoding vector of each common sense knowledge text; Using the sentiment consistency selection model to process each of the original common sense knowledge feature encoding vectors to obtain the predicted sentiment type distribution of each of the common sense knowledge texts; Calculating a first cross entropy loss between a target dialogue sentence emotion type distribution and a predicted dialogue sentence emotion type distribution included in the predicted emotion type distribution, and calculating a second cross entropy loss between a target empathy reply emotion type distribution and a predicted empathy reply emotion type distribution included in the predicted emotion type distribution; the target dialogue sentence emotion type distribution and the predicted dialogue sentence emotion type distribution correspond to the same target dialogue sentence, and the target empathy reply emotion type distribution and the predicted empathy reply emotion type distribution correspond to the same target reply sentence; The first common sense knowledge feature vector is obtained from the original common sense knowledge feature encoding vector of the target dialogue sentence using the first cross entropy loss; and the second common sense knowledge feature vector is obtained from the original common sense knowledge feature encoding vector of the target reply sentence using the second cross entropy loss.
3. The method according to claim 1, characterized in that Calculating the loss of the model using the first common sense knowledge feature vector, the second common sense knowledge feature vector, and the historical conversation text includes: Using the first common sense knowledge feature vector and the historical conversation text, predicting context emotion prediction distribution and conversation sentence emotion prediction distribution, and using the second common sense knowledge feature vector and the historical conversation text, predicting empathy response prediction distribution and empathy response conversation text; The first model loss is calculated using the context emotion prediction distribution and the annotated context emotion distribution of the historical dialogue text; the second model loss is calculated using the dialogue sentence emotion prediction distribution and the dialogue sentence emotion type distribution; the third model loss is calculated using the empathy reply prediction distribution and the empathy reply emotion type distribution of the reply sentence; and the fourth model loss is calculated based on the empathy reply dialogue text and the standard empathy reply dialogue text in the historical dialogue text; The first model loss, the second model loss, the third model loss and the fourth model loss are used as the model loss.
4. The method according to claim 3, characterized in that Using the first common sense knowledge feature vector and the historical dialogue text, predicting context emotion prediction distribution and dialogue sentence emotion prediction distribution, including: Using the memory neural network included in the model to fuse the first common sense knowledge feature vector and the original historical dialogue feature encoding vector of the historical dialogue text to obtain a dialogue mixed feature encoding vector; The context emotion classifier included in the model is used to predict the dialogue mixed feature encoding vector to obtain the context emotion prediction distribution; and the dialogue sentence emotion classifier included in the model is used to predict the dialogue mixed feature encoding vector to obtain the dialogue sentence emotion prediction distribution.
5. The method according to claim 3, characterized in that: Using the second common sense knowledge feature vector and the historical dialogue text, predicting an empathy response prediction distribution and an empathy response dialogue text, including: Using the memory neural network included in the model to fuse the second common sense knowledge feature vector and the original historical dialogue feature encoding vector of the historical dialogue text to obtain an empathy response hybrid encoding feature; Using the empathy reply sentiment classifier included in the model to predict the empathy reply mixed coding feature to obtain the empathy reply sentiment prediction distribution; The empathy response dialogue text is obtained by using the neural network decoder and the cross attention module included in the model, and based on the empathy response sentiment prediction distribution, the empathy response mixed encoding features and the original common sense knowledge feature encoding vector of the historical dialogue text.
6. The method according to claim 5, characterized in that The empathy reply dialogue text is obtained by using the neural network decoder and the cross attention module included in the model, and based on the empathy reply sentiment prediction distribution, the empathy reply hybrid encoding feature and the original common sense knowledge feature encoding vector of the historical dialogue text, including: Using the original common sense knowledge feature encoding vector as the key and value of the cross attention module, using the empathy response mixed feature encoding feature as the query vector of the cross attention module, processing the original common sense knowledge feature encoding vector to obtain a vector representation of the cross attention module output; The vector representation and the empathy response sentiment prediction distribution are input into the neural network decoder to obtain the empathy response text.
7. A model training device for realizing empathy dialogue, characterized in that: include: An acquisition module, used to acquire a historical dialogue text and a common sense relationship set, wherein the dialogue sentences in the historical dialogue text are annotated with dialogue sentence emotion types, and the reply sentences in the historical dialogue text are annotated with empathy reply emotion types; A generation module, configured to generate a common sense knowledge text set of the historical dialogue text by using the common sense knowledge generation model included in the model and according to the common sense relationship types included in the common sense relationship set, wherein each dialogue sentence and reply sentence in the historical dialogue text corresponds to a plurality of common sense knowledge texts; A screening module, for using the dialogue sentence emotion type distribution obtained based on the dialogue sentence emotion type and the empathy reply emotion type distribution obtained based on the empathy reply emotion type, and using the emotion consistency selection model included in the model, to screen the common sense knowledge text set to obtain a first common sense knowledge feature vector consistent with the historical dialogue emotion and a second common sense knowledge feature vector consistent with the empathy reply emotion; An optimization module is used to calculate the loss of the model using the first common sense knowledge feature vector, the second common sense knowledge feature vector and the historical conversation text, and optimize the parameters of the model using the loss until the model converges.
8. An electronic device comprising a memory, a processor and a computer program stored in the memory, characterized in that: The processor executes the computer program to implement the steps of the method according to any one of claims 1 to 6.
9. A computer-readable storage medium having a computer program / instruction stored thereon, characterized in that: When the computer program / instructions are executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.
10. A computer program product comprising a computer program / instructions, characterized in that When the computer program / instructions are executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.