A method and system for generating emotional dialogue
Through the processing of dialogue history text data sets and the integration of common sense knowledge, combined with multi-head attention and cross-attention mechanism, the problem of emotional dialogue generation in the existing technology is solved, and the generation of emotional dialogue responses with high accuracy and diversity is achieved.
Patent Information
- Application Number
- CN202411360011.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-27
- Publication Date
- 2025-04-01
- Estimated Expiration
- 2044-09-27
AI Technical Summary
The existing emotional dialogue generation methods are difficult to accurately understand the user's emotional state, resulting in a small amount of reply information generated and inconsistent with the user's emotions.
By obtaining the dialogue history text data set, word embedding representation and encoding processing are performed, and combining common sense inference models and two-way long and short attention networks, the extraction of dialogue emotional characteristics and the integration of common sense knowledge is achieved. The multi-headed attention mechanism and cross-headed attention mechanism are used to interact with emotions and knowledge, and appropriate common sense knowledge is selected for reply generation.
It improves the accuracy of identifying user emotions, the generated replies are diverse and emotionally resonant, and improves the user experience of human-computer interaction.
Smart Images

Figure SMS_37 
Figure SMS_70 
Figure SMS_80
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of natural language processing, and in particular relates to a method and system for generating emotional dialogue. Background Art
[0002] With the rapid development of artificial intelligence technology, emotional dialogue generation, as an important branch of natural language processing, is gradually becoming an indispensable part of human-computer interaction. Emotional dialogue is not only the transmission of information, but also the exchange and resonance of emotions. It requires the system to accurately understand the user's emotional state and generate emotional responses that are in line with the user's emotions.
[0003] However, in practical applications, existing research methods for emotional dialogue generation mainly include emotion-driven emotional dialogue generation and emotion dialogue generation based on multi-factor fusion. The lack of common sense knowledge leads to the inability of the dialogue system to accurately understand the user's emotional state and produces responses with less information; (2) only the overall recognition of user emotions is performed, ignoring the fine-grained sentence-level emotion recognition, resulting in the low accuracy of the dialogue system in recognizing user emotions; (3) the knowledge graph is used as the common sense knowledge base, but the common sense knowledge is not effectively selected based on the emotional information, resulting in the selection of inappropriate common sense knowledge in the response process, causing the model to generate responses that do not match the user's emotional state. Summary of the invention
[0004] In view of the defects or shortcomings of the prior art, the purpose of the present invention is to provide a method and system for generating emotional dialogue to solve the technical problem in the prior art that the generation of the emotional dialogue model is inconsistent with the emotional state of the user.
[0005] In order to solve the above technical problems, the technical solution adopted by the present invention is:
[0006] On the one hand, this aspect provides a method for generating an emotional dialogue, comprising the following steps:
[0007] Step 1: Obtain a conversation history text dataset, wherein the conversation history text dataset includes multiple conversation history texts; each conversation history text includes multiple conversation sentences and one reply sentence, and each conversation sentence of each history text includes multiple words;
[0008] Step 2: Perform word embedding for each word in each dialogue sentence in each historical text to obtain the word vector representation of each word, and concatenate the word vector representations of all words in each dialogue sentence to obtain the input representation of each dialogue sentence sequence. ; The input of each dialogue sentence sequence is represented as Perform encoding processing to obtain the comprehensive semantic representation of the dialogue sentence ;in, iIndicates the sequence number of the dialogue sentence in the history text;
[0009] Step 3: Input the input representation of each dialogue sentence sequence, the preset common sense knowledge relationship category and the character sequence [GEN] into the common sense reasoning model COMET to obtain the common sense knowledge text set of the dialogue sentence. , and then obtain the comprehensive common sense knowledge vector of the dialogue sentence ;
[0010] Step 4: Comprehensive semantic representation of each dialogue sentence and the comprehensive common sense knowledge vector of the dialogue sentence After concatenation and encoding, the dialogue history sequence after the common sense knowledge of the dialogue sentence is obtained through the bidirectional long and short attention network. ;
[0011] Step 5: The dialogue history sequence after integrating the common sense knowledge of all dialogue sentences in each historical text The multi-head attention mechanism is used to process and obtain the dialogue emotion feature vector of the historical text. ; Conversational sentiment feature vector for each historical text Perform linear transformation and softmax normalization processing in turn to obtain the predicted results of the emotional category label distribution of this historical text. ;
[0012] Step 6: Transform the conversation emotion feature vector of each historical text into Perform a linear transformation to obtain the starting mark [SOS] of the sequence generation process, add the starting mark [SOS] to the starting position of the input representation of each dialogue sentence sequence in the historical text, and obtain the reply sequence of each dialogue sentence in the historical text Y , ,in, , is the first The word vector representation of each word;
[0013] Step 7: Use the masked multi-head attention mechanism to respond to each dialogue sentence Y The word vectors of each word in are weighted summed, and then processed by residual connection and layer normalization in turn to obtain the self-attention output of the reply sequence of the dialogue sentence ;
[0014] Step 8: Output the self-attention of the reply sequence of each dialogue sentence The dialogue history sequence after merging with the common sense knowledge of the dialogue sentence By integrating the attention mechanism, residual connection and normalization processing, the enhanced representation of the reply sequence of the dialogue sentence combined with the dialogue history information is obtained. ;
[0015] Step 9: Enhance the representation of each dialogue sentence by combining the reply sequence with the dialogue history information and the common sense knowledge text set of the dialogue sentence After being processed by the attention mechanism, it is processed by the feedforward neural network, residual connection and normalization in turn to obtain the knowledge-enhanced reply representation of the dialogue sentence. ;
[0016] Step 10: Represent the knowledge-enhanced response for each dialogue sentence After linear transformation and softmax normalization processing, the probability distribution of the generated words of the dialogue sentence is obtained; the word corresponding to the maximum probability in the probability distribution of the generated words of each dialogue sentence is added as the generated word to the reply sequence of the dialogue sentence Y At the end of , we get the updated reply sequence of the dialogue sentence Y ;
[0017] Step 11: Iterate and repeat steps 7 to 10 until the target loss function reaches the optimal value. At this time, the updated dialogue statement reply sequence obtained in the current iteration is Y Save as the dialogue reply text for the corresponding dialogue sentence.
[0018] Furthermore, the step 3 specifically includes the following sub-steps:
[0019] Step 3.1: Input the input representation of the dialogue sentence sequence obtained in step 2, the preset common sense knowledge relationship category and the character sequence [GEN] into the common sense reasoning model COMET to obtain the common sense knowledge text set of each dialogue sentence. ;
[0020] Step 3.2: Common sense knowledge text collection of all dialogue sentences under each common sense knowledge relationship category Splice to get common sense sequence text ;
[0021] Step 3.3: Use the BART model to classify common sense sequence text Perform encoding and average pooling processing in sequence to obtain a comprehensive common sense knowledge vector .
[0022] Furthermore, the objective loss function described in step 11 is:
[0023] ,
[0024] In the formula,
[0025] is the dialogue loss function;
[0026] is the sentiment loss function;
[0027] , are all hyperparameters, and .
[0028] Furthermore, the dialogue loss function is:
[0029]
[0030] In the formula,
[0031] T The reply sequence of the updated dialogue statement in the current iteration Y The number of words in the sentence;
[0032] is the generated word obtained in the current iteration;
[0033] Y is the reply sequence of the dialogue statements in the current iteration, ;
[0034] For existing The condition for generating the first The conditional probability of a word.
[0035] Furthermore, the sentiment loss function is:
[0036] ,
[0037] In the formula,
[0038] P dia Predict the distribution of sentiment category labels for a piece of historical text;
[0039] The overall sentiment category label for a piece of historical text;
[0040] On the other hand, the present invention provides an emotional dialogue generation system, comprising the following modules:
[0041] A dialogue history text data set acquisition module is used to acquire a dialogue history text data set, wherein the dialogue history text data set includes multiple dialogue history texts; each dialogue history text includes multiple dialogue sentences and one reply sentence, and each dialogue sentence of each history text includes multiple words;
[0042] The module for acquiring the comprehensive semantic representation of dialogue sentences is used to embed each word of each dialogue sentence in each historical text to obtain the word vector representation of each word, and to concatenate the word vector representations of all words in each dialogue sentence to obtain the input representation of each dialogue sentence sequence. ; The input of each dialogue sentence sequence is represented as Perform encoding processing to obtain the comprehensive semantic representation of the dialogue sentence ;in, i Indicates the sequence number of the dialogue sentence in the history text;
[0043] The comprehensive common sense knowledge vector acquisition module of the dialogue sentence is used to input the input representation of each dialogue sentence sequence, the preset common sense knowledge relationship category and the character sequence [GEN] into the common sense reasoning model COMET to obtain the common sense knowledge text set of the dialogue sentence , and then obtain the comprehensive common sense knowledge vector of the dialogue sentence ;
[0044] The dialogue history sequence acquisition module is used to comprehensively represent the semantics of each dialogue sentence. and the comprehensive common sense knowledge vector of the dialogue sentence Concatenate and encode (using Transformer encoder for encoding), and then pass through the bidirectional long and short attention network to obtain the dialogue history sequence after the common sense knowledge of the dialogue sentence is integrated ;
[0045] The emotion category label distribution prediction result acquisition module is used to integrate the common sense knowledge of all dialogue sentences in each historical text into the dialogue history sequence The multi-head attention mechanism is used to process and obtain the dialogue emotion feature vector of the historical text. ; Conversational sentiment feature vector for each historical text Perform linear transformation and softmax normalization processing in turn to obtain the predicted results of the emotional category label distribution of this historical text. ;
[0046] The dialogue sentence reply sequence acquisition module is used to convert the dialogue emotion feature vector of each historical text into Perform a linear transformation to obtain the starting mark [SOS] of the sequence generation process, add the starting mark [SOS] to the starting position of the input representation of each dialogue sentence sequence in the historical text, and obtain the reply sequence of each dialogue sentence in the historical text Y , ,in, , is the first The word vector representation of the word;
[0047] Self-attention output acquisition module, used to respond to each dialogue sentence through the masked multi-head attention mechanism Y The word vectors of each word in are weighted summed, and then processed by residual connection and layer normalization in turn to obtain the self-attention output of the reply sequence of the dialogue sentence ;
[0048] The reply sequence enhanced representation acquisition module is used to output the self-attention of the reply sequence of each dialogue sentence. The dialogue history sequence after merging with the common sense knowledge of the dialogue sentence By integrating the attention mechanism, residual connection and normalization processing, the enhanced representation of the reply sequence of the dialogue sentence combined with the dialogue history information is obtained. ;
[0049] The knowledge-enhanced reply representation acquisition module for dialogue sentences is used to enhance the reply sequence representation of each dialogue sentence combined with dialogue history information. and the common sense knowledge text set of the dialogue sentence After being processed by the attention mechanism, it is processed by the feedforward neural network, residual connection and normalization in turn to obtain the knowledge-enhanced reply representation of the dialogue sentence. ;
[0050] The updated dialogue statement reply sequence acquisition module is used to represent the knowledge-enhanced reply of each dialogue statement. After linear transformation and softmax normalization processing, the probability distribution of the generated words of the dialogue sentence is obtained; the word corresponding to the maximum probability in the probability distribution of the generated words of each dialogue sentence is added as the generated word to the reply sequence of the dialogue sentence Y At the end of , we get the updated reply sequence of the dialogue sentence Y ;
[0051] The dialogue reply text acquisition module of the dialogue sentence is used to iteratively and repeatedly execute the self-attention output acquisition module, the reply sequence enhancement representation acquisition module, the dialogue sentence knowledge enhancement reply representation acquisition module and the updated dialogue sentence reply sequence acquisition module until the target loss function obtains the optimal value. At this time, the updated dialogue sentence reply sequence obtained in the current iteration is Y Save as the dialogue reply text for the corresponding dialogue sentence.
[0052] Compared with the prior art, the beneficial technical effects of the present invention are:
[0053] (1) The method of the present invention not only performs fine-grained emotion recognition on each sentence in the dialogue history text, but also performs macro-dialogue-level emotion recognition on the dialogue history text, thereby improving the system's overall recognition ability of user emotions; the method of the present invention adopts a knowledge selection mechanism based on the interaction between emotion and knowledge, and adopts a cross-attention mechanism to realize the interaction between dialogue emotions and common sense knowledge, thereby achieving logical selection of common sense knowledge.
[0054] (2) The present invention can generate emotional dialogue responses during human-computer dialogue, making the response text diverse. This can not only be used to improve the quality of machine-generated responses, but also improve the user experience in human-computer interaction. DETAILED DESCRIPTION
[0055] It should be noted that, in the embodiments of the present invention, the emotional dialogue model is constructed and trained with the aid of a computer.
[0056] In the present invention, the emotional dialogue dataset can be obtained from a web crawler or a public dataset can be used. For example, an existing dataset can be obtained from customer service dialogues on platforms such as Didi, Gaode, and Meituan, and a dialogue history text dataset can be obtained after preprocessing of the existing dataset. For the raw data directly obtained from the network, emotion classification is also required after preprocessing to determine the emotion category of each sentence.
[0057] Specific embodiments of the present invention are given below. It should be noted that the present invention is not limited to the following specific embodiments, and all equivalent changes made on the basis of the technical solution of this application fall within the protection scope of the present invention.
[0058] Example 1
[0059] The dataset used in this embodiment is the EmpatheticDialogues public dataset. This dataset originates from the Amazon crowdsourcing platform and is a multi-round empathetic dialogue set. We regard each round of empathetic dialogue as a historical text. During the data collection process, a specific scene or theme is set for each dialogue sentence instance in each round of empathetic dialogue, and then two annotators are assigned to play the roles of narrator and listener respectively. Under the guidance of a specific scene or theme, the narrator starts the conversation by describing the personal situation in emotional language, and the listener needs to infer the narrator's emotions and semantics through the narrator's expression and respond in an empathetic way. The dataset finally brings together about 25,000 one-to-one open-domain dialogues, and the dialogue sentences cover 32 evenly distributed emotion labels (as emotion category labels). In the EmpatheticDialogues dataset, the overall emotion category label of each historical text is known. The specific emotion types are shown in Table 1.
[0060] Table 1 Emotional category labels in the EmpatheticDialogues dataset (32 types)
[0061]
[0062] In accordance with the above technical solution, this embodiment discloses a method for generating emotional dialogue, which specifically includes the following steps:
[0063] Step 1: Obtain a conversation history text dataset, wherein the conversation history text dataset includes multiple conversation history texts; each conversation history text includes multiple conversation sentences and one reply sentence, and each conversation sentence of each history text includes multiple words;
[0064] Step 2: Perform word embedding for each word in each dialogue sentence in each historical text to obtain the word vector representation of each word, and concatenate the word vector representations of all words in each dialogue sentence to obtain the input representation of each dialogue sentence sequence. ; The input of each dialogue sentence sequence is represented as Perform encoding processing (in this embodiment, the BART model is used for encoding processing) to obtain a comprehensive semantic representation of the dialogue sentence ;in, i Indicates the sequence number of the dialogue sentence in the history text;
[0065] Step 3: Input the input representation of each dialogue sentence sequence, the preset common sense knowledge relationship category and the character sequence [GEN] into the common sense reasoning model COMET to obtain the common sense knowledge text set of the dialogue sentence. , and then obtain the comprehensive common sense knowledge vector of the dialogue sentence ;
[0066] Step 3.1: Input the input representation of the dialogue sentence sequence obtained in step 2, the preset common sense knowledge relationship category and the character sequence [GEN] into the common sense reasoning model COMET to obtain the common sense knowledge text set of each dialogue sentence. ;
[0067] The COMET model infers five types of common sense knowledge based on the events experienced by individuals, which are related to the behavioral motivations related to individuals ( xIntent ), emotional response ( xReact ), event-related requirements ( xNeed )、Consequences of the incident( xEffect ) and individual needs ( xWant ), so the common sense knowledge relationship category preset in this embodiment r =5, that is, .
[0068] Step 3.2: Common sense knowledge text collection of all dialogue sentences under each common sense knowledge relationship category Splice to get common sense sequence text ;
[0069]
[0070] Among them, the common sense knowledge text set of each sentence in each common sense knowledge category, such as Refers to the common sense knowledge text set of each sentence under the event-related demand category.
[0071] Step 3.3: Use the BART model to classify common sense sequence text Perform encoding and average pooling processing in sequence to obtain a comprehensive common sense knowledge vector .
[0072] Step 4: Comprehensive semantic representation of each dialogue sentence and the comprehensive common sense knowledge vector of the dialogue sentence Concatenate and encode (using Transformer encoder for encoding), and then pass through the bidirectional long and short attention network to obtain the dialogue history sequence after the common sense knowledge of the dialogue sentence is integrated ;
[0073] The BiLSTM model (Bidirectional Long-Short Attention Network) can effectively capture the contextual dependencies of each word in the time series by simultaneously considering the forward (left to right) and reverse (right to left) sequence information. In addition, BiLSTM models the interactions between sentences in the dialogue sequence and their dynamic characteristics over time, and has the ability to detect and track emotional changes during the dialogue. This method of modeling emotional dynamics is of great value for a deeper understanding of how individuals express and transform their emotional states in a dialogue.
[0074] Step 5: The dialogue history sequence after integrating the common sense knowledge of all dialogue sentences in each historical text The multi-head attention mechanism is used to process and obtain the dialogue emotion feature vector of the historical text. ; Conversational sentiment feature vector for each historical text Perform linear transformation and softmax normalization processing in turn to obtain the predicted results of the emotional category label distribution of this historical text. ;
[0075] Step 6: Transform the conversation emotion feature vector of each historical text into Perform a linear transformation to obtain the starting mark [SOS] of the sequence generation process, add the starting mark [SOS] to the starting position of the input representation of each dialogue sentence sequence in the historical text, and obtain the reply sequence of each dialogue sentence in the historical text Y , ,in, , is the first The word vector representation of each word;
[0076] Step 7: Use the masked multi-head attention mechanism to respond to each dialogue sentence Y The word vectors of each word in are weighted summed, and then processed by residual connection and layer normalization in turn to obtain the self-attention output of the reply sequence of the dialogue sentence ;
[0077] Step 8: Output the self-attention of the reply sequence of each dialogue sentence The dialogue history sequence after merging with the common sense knowledge of the dialogue sentence By integrating the attention mechanism, residual connection and normalization processing, the enhanced representation of the reply sequence of the dialogue sentence combined with the dialogue history information is obtained. ;
[0078] Step 9: Enhance the representation of each dialogue sentence by combining the reply sequence with the dialogue history information and the common sense knowledge text set of the dialogue sentence After being processed by the attention mechanism, it is processed by the feedforward neural network, residual connection and normalization in turn to obtain the knowledge-enhanced reply representation of the dialogue sentence. ;
[0079] In this step, the reply sequence is enhanced by combining the conversation history information and the common sense knowledge text set for each sentence , which can give higher weights to the most relevant knowledge and lower weights to the less relevant knowledge, thereby achieving the selection of common sense knowledge; the vector representation ability is enhanced by sequentially performing feedforward neural network and residual connection processing, thereby improving the stability and efficiency of the method.
[0080] Step 10: Represent the knowledge-enhanced response for each dialogue sentence After linear transformation and softmax normalization processing, the probability distribution of the generated words of the dialogue sentence is obtained; the word corresponding to the maximum probability in the probability distribution of the generated words of each dialogue sentence is added as the generated word to the reply sequence of the dialogue sentence Y At the end of , we get the updated reply sequence of the dialogue sentence Y ;
[0081] Step 11: Iterate and repeat steps 7 to 10 until the target loss function reaches the optimal value. At this time, the updated dialogue statement reply sequence obtained in the current iteration is Y Save as the dialogue reply text for the corresponding dialogue sentence.
[0082] Preferably, the objective loss function is:
[0083] ,
[0084] In the formula,
[0085] is the dialogue loss function;
[0086] is the sentiment loss function;
[0087] , are all hyperparameters, and .
[0088] Among them, the dialogue loss function is:
[0089]
[0090] In the formula,
[0091] T The reply sequence of the updated dialogue statement in the current iteration Y The number of words in the sentence;
[0092] is the generated word obtained in the current iteration process, which can be obtained in step 10;
[0093] Y is the reply sequence of the dialogue statements in the current iteration, ;
[0094] For existing The condition for generating the first The conditional probability of a word is obtained by the probability distribution of the generated words of the dialogue sentence in step 10.
[0095] The sentiment loss function is:
[0096] ,
[0097] In the formula,
[0098] P diais the predicted result of the emotional category label distribution of a historical text. This parameter can be obtained from step 5.
[0099] is the overall sentiment category label of a historical text. This parameter is already available in the public dataset.
[0100] Effect verification:
[0101] The method of obtaining the emotional response dialogue text in this embodiment is compared with the method of obtaining the emotional response using the existing baseline model, and the comparison results are shown in Table 2. Among them, the PPL index is used to evaluate the fluency of the generated dialogue. The lower the PPL, the more fluent and natural the generated dialogue is; Distinct-n is used to measure the diversity of the generated text. The higher the Dist-n index, the more diverse the generated dialogue is in vocabulary or phrases; BLEU-N and ROUGE-N are used to measure the accuracy and coherence of the generated dialogue, respectively. The higher the value, the more accurate and coherent the generated response is.
[0102] Table 2 Comparison results between the method of the present invention and the existing method
[0103]
[0104] From the results in Table 2, it can be seen that the PPL index, Dist-n index, BLEU-N and ROUGE-N obtained by the method of the present invention are better than other existing methods, indicating that the method of the present invention can significantly improve the quality of generating empathy dialogues.
[0105] In emotional dialogue generation, understanding and responding to user emotions is crucial, but existing automatic evaluation indicators are usually unable to accurately evaluate user emotions, while the method of the present invention can accurately evaluate user emotions.
[0106] In this embodiment, the method of the present invention is compared with other baseline models (MIME, EmpDG, KEMP and CEM) in terms of empathy, relevance and fluency. The comparison results are shown in Table 3. It can be seen from the comparison results that the method of the present invention has better results.
[0107] Table 3 Comparison of empathy, relevance and fluency between the method of the present invention and the existing methods
[0108]
[0109] Example 2
[0110] This embodiment provides an emotional dialogue generation system, including the following modules:
[0111] A dialogue history text data set acquisition module is used to acquire a dialogue history text data set, wherein the dialogue history text data set includes multiple dialogue history texts; each dialogue history text includes multiple dialogue sentences and one reply sentence, and each dialogue sentence of each history text includes multiple words;
[0112] The module for acquiring the comprehensive semantic representation of dialogue sentences is used to embed each word of each dialogue sentence in each historical text to obtain the word vector representation of each word, and to concatenate the word vector representations of all words in each dialogue sentence to obtain the input representation of each dialogue sentence sequence. ; The input of each dialogue sentence sequence is represented as Perform encoding processing to obtain the comprehensive semantic representation of the dialogue sentence ;in, i Indicates the sequence number of the dialogue sentence in the history text;
[0113] The comprehensive common sense knowledge vector acquisition module of the dialogue sentence is used to input the input representation of each dialogue sentence sequence, the preset common sense knowledge relationship category and the character sequence [GEN] into the common sense reasoning model COMET to obtain the common sense knowledge text set of the dialogue sentence , and then obtain the comprehensive common sense knowledge vector of the dialogue sentence ;
[0114] The dialogue history sequence acquisition module is used to comprehensively represent the semantics of each dialogue sentence. and the comprehensive common sense knowledge vector of the dialogue sentence Concatenate and encode (using Transformer encoder for encoding), and then pass through the bidirectional long and short attention network to obtain the dialogue history sequence after the common sense knowledge of the dialogue sentence is integrated ;
[0115] The emotion category label distribution prediction result acquisition module is used to integrate the common sense knowledge of all dialogue sentences in each historical text into the dialogue history sequence The multi-head attention mechanism is used to process and obtain the dialogue emotion feature vector of the historical text. ; Conversational sentiment feature vector for each historical text Perform linear transformation and softmax normalization processing in turn to obtain the predicted results of the emotional category label distribution of this historical text. ;
[0116] The dialogue sentence reply sequence acquisition module is used to convert the dialogue emotion feature vector of each historical text into Perform a linear transformation to obtain the starting mark [SOS] of the sequence generation process, add the starting mark [SOS] to the starting position of the input representation of each dialogue sentence sequence in the historical text, and obtain the reply sequence of each dialogue sentence in the historical text Y , ,in, , is the first The word vector representation of each word;
[0117] Self-attention output acquisition module, used to respond to each dialogue sentence through the masked multi-head attention mechanism Y The word vectors of each word in are weighted summed, and then processed by residual connection and layer normalization in turn to obtain the self-attention output of the reply sequence of the dialogue sentence ;
[0118] The reply sequence enhanced representation acquisition module is used to output the self-attention of the reply sequence of each dialogue sentence. The dialogue history sequence after merging with the common sense knowledge of the dialogue sentence By integrating the attention mechanism, residual connection and normalization processing, the enhanced representation of the reply sequence of the dialogue sentence combined with the dialogue history information is obtained. ;
[0119] The knowledge-enhanced reply representation acquisition module for dialogue sentences is used to enhance the reply sequence representation of each dialogue sentence combined with dialogue history information. and the common sense knowledge text set of the dialogue sentence After being processed by the attention mechanism, it is processed by the feedforward neural network, residual connection and normalization in turn to obtain the knowledge-enhanced reply representation of the dialogue sentence. ;
[0120] The updated dialogue statement reply sequence acquisition module is used to represent the knowledge-enhanced reply of each dialogue statement. After linear transformation and softmax normalization processing, the probability distribution of the generated words of the dialogue sentence is obtained; the word corresponding to the maximum probability in the probability distribution of the generated words of each dialogue sentence is added as the generated word to the reply sequence of the dialogue sentence Y At the end of , we get the reply sequence of the updated dialogue sentence Y ;
[0121] The dialogue reply text acquisition module of the dialogue sentence is used to iteratively and repeatedly execute the self-attention output acquisition module, the reply sequence enhancement representation acquisition module, the dialogue sentence knowledge enhancement reply representation acquisition module and the updated dialogue sentence reply sequence acquisition module until the target loss function obtains the optimal value. At this time, the updated dialogue sentence reply sequence obtained in the current iteration is Y Save as the dialogue reply text for the corresponding dialogue sentence.
[0122] The functional modules in this embodiment may be integrated together to form an independent part, or each module may exist independently, or two or more modules may be integrated to form an independent part.
[0123] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A method for generating emotional dialogue, characterized in that: The following steps are involved: Step 1: Obtain a conversation history text dataset, wherein the conversation history text dataset includes multiple conversation history texts; each conversation history text includes multiple conversation sentences and one reply sentence, and each conversation sentence of each history text includes multiple words; Step 2: Perform word embedding for each word in each dialogue sentence in each historical text to obtain the word vector representation of each word, and concatenate the word vector representations of all words in each dialogue sentence to obtain the input representation of each dialogue sentence sequence. ; The input of each dialogue sentence sequence is represented as Perform encoding processing to obtain the comprehensive semantic representation of the dialogue sentence ;in, i Indicates the sequence number of the dialogue sentence in the history text; Step 3: Input the input representation of each dialogue sentence sequence, the preset common sense knowledge relationship category and the character sequence [GEN] into the common sense reasoning model COMET to obtain the common sense knowledge text set of the dialogue sentence. , and then obtain the comprehensive common sense knowledge vector of the dialogue sentence ; Step 4: Comprehensive semantic representation of each dialogue sentence and the comprehensive common sense knowledge vector of the dialogue sentence After concatenation and encoding, the dialogue history sequence after the common sense knowledge of the dialogue sentence is obtained through the bidirectional long and short attention network. ; Step 5: The dialogue history sequence after integrating the common sense knowledge of all dialogue sentences in each historical text The multi-head attention mechanism is used to process and obtain the dialogue emotion feature vector of the historical text. ; Conversational sentiment feature vector for each historical text Perform linear transformation and softmax normalization processing in turn to obtain the predicted results of the emotional category label distribution of this historical text. ; Step 6: Transform the conversation emotion feature vector of each historical text into Perform a linear transformation to obtain the starting mark [SOS] of the sequence generation process, add the starting mark [SOS] to the starting position of the input representation of each dialogue sentence sequence in the historical text, and obtain the reply sequence of each dialogue sentence in the historical text Y , ,in, , is the first The word vector representation of the word; Step 7: Use the masked multi-head attention mechanism to respond to each dialogue sentence Y The word vectors of each word in are weighted summed, and then processed by residual connection and layer normalization in turn to obtain the self-attention output of the reply sequence of the dialogue sentence ; Step 8: Output the self-attention of the reply sequence of each dialogue sentence The dialogue history sequence after merging with the common sense knowledge of the dialogue sentence By integrating the attention mechanism, residual connection and normalization processing, the enhanced representation of the reply sequence of the dialogue sentence combined with the dialogue history information is obtained. ; Step 9: Enhance the representation of each dialogue sentence by combining the reply sequence with the dialogue history information and the common sense knowledge text set of the dialogue sentence After being processed by the attention mechanism, it is processed by the feedforward neural network, residual connection and normalization in turn to obtain the knowledge-enhanced reply representation of the dialogue sentence. ; Step 10: Represent the knowledge-enhanced response for each dialogue sentence After linear transformation and softmax normalization processing, the probability distribution of the generated words of the dialogue sentence is obtained; the word corresponding to the maximum probability in the probability distribution of the generated words of each dialogue sentence is added as the generated word to the reply sequence of the dialogue sentence Y At the end of , we get the updated reply sequence of the dialogue sentence Y ; Step 11: Iterate and repeat steps 7 to 10 until the target loss function reaches the optimal value. At this time, the updated dialogue statement reply sequence obtained in the current iteration is Y Save as the dialogue reply text for the corresponding dialogue sentence.
2. The emotional dialogue generation method according to claim 1, characterized in that: The step 3 specifically includes the following sub-steps: Step 3.1: Input the input representation of the dialogue sentence sequence obtained in step 2, the preset common sense knowledge relationship category and the character sequence [GEN] into the common sense reasoning model COMET to obtain the common sense knowledge text set of each dialogue sentence. ; Step 3.2: Common sense knowledge text collection of all dialogue sentences under each common sense knowledge relationship category Splice to get common sense sequence text ; Step 3.3: Use the BART model to classify common sense sequence text Perform encoding and average pooling processing in sequence to obtain a comprehensive common sense knowledge vector .
3. The emotional dialogue generation method according to claim 2, characterized in that: The objective loss function described in step 11 is: , In the formula, is the dialogue loss function; is the sentiment loss function; , are all hyperparameters, and .
4. The emotional dialogue generation method according to claim 3, characterized in that: The dialogue loss function is: , In the formula, T The reply sequence of the updated dialogue statement in the current iteration Y The number of words in the sentence; is the generated word obtained in the current iteration; Y is the reply sequence of the dialogue statements in the current iteration, ; For existing The condition for generating the first The conditional probability of a word.
5. The emotional dialogue generation method according to claim 3, characterized in that: The sentiment loss function is: , In the formula, P dia Predict the distribution of sentiment category labels for a piece of historical text; is the overall sentiment category label of a historical text.
6. An emotional dialogue generation system, characterized in that: Includes the following modules: A dialogue history text data set acquisition module is used to acquire a dialogue history text data set, wherein the dialogue history text data set includes multiple dialogue history texts; each dialogue history text includes multiple dialogue sentences and one reply sentence, and each dialogue sentence of each history text includes multiple words; The module for acquiring the comprehensive semantic representation of dialogue sentences is used to embed each word of each dialogue sentence in each historical text to obtain the word vector representation of each word, and to concatenate the word vector representations of all words in each dialogue sentence to obtain the input representation of each dialogue sentence sequence. ; The input of each dialogue sentence sequence is represented as Perform encoding processing to obtain the comprehensive semantic representation of the dialogue sentence ;in, i Indicates the sequence number of the dialogue sentence in the history text; The comprehensive common sense knowledge vector acquisition module of the dialogue sentence is used to input the input representation of each dialogue sentence sequence, the preset common sense knowledge relationship category and the character sequence [GEN] into the common sense reasoning model COMET to obtain the common sense knowledge text set of the dialogue sentence , and then obtain the comprehensive common sense knowledge vector of the dialogue sentence ; The dialogue history sequence acquisition module is used to comprehensively represent the semantics of each dialogue sentence. and the comprehensive common sense knowledge vector of the dialogue sentence After concatenation and encoding, the dialogue history sequence after the common sense knowledge of the dialogue sentence is obtained through the bidirectional long and short attention network. ; The emotion category label distribution prediction result acquisition module is used to integrate the common sense knowledge of all dialogue sentences in each historical text into the dialogue history sequence The multi-head attention mechanism is used to process and obtain the dialogue emotion feature vector of the historical text. ; Conversational sentiment feature vector for each historical text Perform linear transformation and softmax normalization processing in turn to obtain the predicted results of the emotional category label distribution of this historical text. ; The dialogue sentence reply sequence acquisition module is used to convert the dialogue emotion feature vector of each historical text into Perform a linear transformation to obtain the starting mark [SOS] of the sequence generation process, add the starting mark [SOS] to the starting position of the input representation of each dialogue sentence sequence in the historical text, and obtain the reply sequence of each dialogue sentence in the historical text Y , ,in, , is the first The word vector representation of the word; Self-attention output acquisition module, used to respond to each dialogue sentence through the masked multi-head attention mechanism Y The word vectors of each word in are weighted summed, and then processed by residual connection and layer normalization in turn to obtain the self-attention output of the reply sequence of the dialogue sentence ; The reply sequence enhanced representation acquisition module is used to output the self-attention of the reply sequence of each dialogue sentence. The dialogue history sequence after merging with the common sense knowledge of the dialogue sentence By integrating the attention mechanism, residual connection and normalization processing, the enhanced representation of the reply sequence of the dialogue sentence combined with the dialogue history information is obtained. ; The knowledge-enhanced reply representation acquisition module for dialogue sentences is used to enhance the reply sequence representation of each dialogue sentence combined with dialogue history information. and the common sense knowledge text set of the dialogue sentence After being processed by the attention mechanism, it is processed by the feedforward neural network, residual connection and normalization in turn to obtain the knowledge-enhanced reply representation of the dialogue sentence. ; The updated dialogue statement reply sequence acquisition module is used to represent the knowledge-enhanced reply of each dialogue statement. After linear transformation and softmax normalization processing, the probability distribution of the generated words of the dialogue sentence is obtained; the word corresponding to the maximum probability in the probability distribution of the generated words of each dialogue sentence is added as the generated word to the reply sequence of the dialogue sentence Y At the end of , we get the reply sequence of the updated dialogue sentence Y ; The dialogue reply text acquisition module of the dialogue sentence is used to iteratively and repeatedly execute the self-attention output acquisition module, the reply sequence enhancement representation acquisition module, the dialogue sentence knowledge enhancement reply representation acquisition module and the updated dialogue sentence reply sequence acquisition module until the target loss function obtains the optimal value. At this time, the updated dialogue sentence reply sequence obtained in the current iteration is Y Save as the dialogue reply text for the corresponding dialogue sentence.
Citation Information
Patent Citations
Dialogue reply generation method and dialogue reply generation method model
CN115357698A
Conversation generation method and system for enhancing text features
CN115495566A