Dialogue generation method and system based on sentiment analysis and generative adversarial network

Through methods based on emotion analysis and generative adversarial networks, the generative dialogue system is optimized to make the generated dialogue closer to real emotions, solving the problems of lack of emotion and excessive security in replies in the existing technology, and realizing emotion perception and Diversity-enhanced dialogue generation.

CN114492462BActive Publication Date: 2024-10-22HUNAN UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202111646947.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-30
Publication Date
2024-10-22
Estimated Expiration
2041-12-30

AI Technical Summary

Technical Problem

The responses generated by existing generative dialogue systems lack emotion, are too safe, and cannot make adaptive adjustments according to changes in user input.

Method used

Using methods based on emotion analysis and generative adversarial networks, by building a basic dialogue model and dialogue emotion classifier, the generative adversarial network optimizes the network parameters of the generator, so that the emotion of the output answer approaches the emotion of the real answer, combined with multi-modal Use emotional input to identify and adjust emotions.

Benefits of technology

The generated dialogue is realized to be closer to the real emotions, and the generated sentences can be adjusted according to the user's emotional changes, which improves the diversity and adaptability of the dialogue.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114492462B_ABST
    Figure CN114492462B_ABST
Patent Text Reader

Abstract

The present invention discloses a method and system for generating dialogues based on emotion analysis and generative adversarial networks, by constructing and training a basic dialogue model and a dialogue emotion classifier; using the basic dialogue model and the dialogue emotion classifier to construct a generative adversarial network, the generative adversarial network generates a generator based on the basic dialogue model, and generates a discriminator based on the dialogue emotion classifier, the discriminator is used to discriminate the emotional similarities and differences between the generator output answer and the real answer, and optimizes the network parameters of the generator according to the emotional similarities and differences, so that the emotion of the generator output answer approaches the emotion of the real answer; train the generative adversarial network, and use the trained generative adversarial network to generate dialogues. The present invention uses the basic dialogue model and the dialogue emotion classifier to construct a generative adversarial network; the trained generative adversarial network model has the ability to match the user's emotions, and can adjust the generated sentences according to the user's emotions when using it, so as to be closer to the real dialogue.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of dialogue generation, and in particular to a dialogue generation method and system based on sentiment analysis and a generative adversarial network. Background Art

[0002] Dialogue generation technology is an important direction of deep learning application. In current research, the main technical solutions used in the field of dialogue generation can be divided into two types. One is retrieval dialogue. Retrieval dialogue calculates and matches similar questions in the corpus based on the sentences input by the user, and sorts and scores them. The highest score in the candidate set is selected as the reply of the dialogue system. The other is generative dialogue. According to the sentences input by the user, the sentences are segmented and normalized and sent to the pre-trained dialogue model to generate a dialogue based on the words in the corpus. The final replies selected by the two mainstream technical solutions have a great difference in user experience. The retrieval reply is easy for users to understand because its reply content comes from preset fixed sentences. The disadvantage is that it lacks reply diversity and can only achieve good results for preset questions. The generative reply content comes from the sentences generated by the dialogue model based on the words in the corpus after learning the data set of human dialogue. It is rich in diversity, but the generative dialogue system is more inclined to generate security replies, lacks specific and effective information, and will not make adaptive adjustments according to changes in user input.

[0003] Generative dialogue systems are a hot topic in current research. How to make generative dialogue systems generate more valuable sentences that are rich in human emotions has become an important issue that needs to be solved urgently. Summary of the invention

[0004] The present invention provides a dialogue generation method and system based on sentiment analysis and generative adversarial networks, which are used to solve the technical problems that the responses generated by the existing generative dialogue system lack emotion and have too many security responses.

[0005] In order to solve the above technical problems, the technical solution proposed by the present invention is:

[0006] A method for generating dialogue based on sentiment analysis and generative adversarial network, comprising the following steps:

[0007] Constructing a basic dialogue model, and obtaining multiple groups of dialogue sample data with labeled real answers to train the basic dialogue model;

[0008] Constructing a conversation emotion classifier, and obtaining multiple groups of conversation sample data with labeled emotion categories to train the conversation emotion classifier;

[0009] A generative adversarial network is constructed using the basic dialogue model and the dialogue emotion classifier. The generative adversarial network generates a generator based on the basic dialogue model and generates a discriminator based on the dialogue emotion classifier. The discriminator is used to discriminate the emotional similarities and differences between the generator output answer and the real answer, and optimize the network parameters of the generator according to the emotional similarities and differences, so that the emotion of the generator output answer approaches the emotion of the real answer;

[0010] The generative adversarial network is trained, and a dialogue is generated using the trained generative adversarial network.

[0011] Preferably, the generator of the generative adversarial network includes two basic dialogue models, namely a first basic dialogue model and a second basic dialogue model; the output end of the first basic dialogue model is respectively connected to the input end of the second basic dialogue model and the input end of the generator; the output end of the second basic dialogue model is respectively connected to the input end of the first basic dialogue model and the input end of the generator; training the generative adversarial network includes the following steps:

[0012] Inputting external real dialogue data into the first basic dialogue model as initial stimulation, and the iteration begins;

[0013] In each iteration:

[0014] The first basic dialogue model generates first answer data of the input amount of this round of iteration; and inputs the first answer data into the second basic dialogue model as the input amount of the second basic dialogue model in this round of iteration; and also inputs the first answer data into the discriminator;

[0015] The second basic dialogue model generates second answer data for the first answer data, and inputs the second answer data into the first basic dialogue model as input for the next iteration of the first basic dialogue model; and also inputs the second answer data into the discriminator;

[0016] The discriminator uses the dialogue emotion classifier to calculate the first emotion vector of the first answer data as the true answer emotion, calculates the second emotion vector of the second answer data as the emotion of the generator output answer, and calculates the output loss of the second basic dialogue model based on the first emotion vector and the second emotion vector, and uses the output loss to update the network parameters of the second basic dialogue model.

[0017] Preferably, the output loss of the second basic dialogue model is calculated according to the first emotion vector and the second emotion vector, and the network parameters of the second basic dialogue model are updated using the output loss, specifically:

[0018] The first emotion vector and the second emotion vector are input into a cross entropy loss calculation formula to calculate the output loss of the second basic dialogue model; and the output loss is back-propagated to the second basic dialogue model to update the gradient parameters of the second basic dialogue model.

[0019] Preferably, the termination condition of the iterative training of the generative adversarial network is:

[0020] The first basic dialogue model and the second basic dialogue model generate the same emotion or the same dialogue in three consecutive iterations.

[0021] Preferably, the basic dialogue model is a Seq2Seq model based on a gate loop control unit; the encoder of the basic dialogue model is a bidirectional gate loop control network; the decoder of the basic dialogue model is a unidirectional gate loop control network based on an attention mechanism; the decoding formula of the unidirectional gate loop control network is as follows:

[0022] e t′t =a(s t′-1 ,h t )

[0023]

[0024]

[0025] s t′ =GRU(y t′-1 ,s t′-1 ,c t′ )

[0026] Among them, t′ is the decoding time of the decoder, t is the encoding time of the encoder, and s t′-1 is the decoder hidden state at t′-1; h t is the intermediate state of the encoder at encoding time t; e t′t is the importance of attention between the decoder hidden state at decoding time t′-1 and the encoder intermediate state at encoding time t; a t′t is the attention weight of the decoder at decoding time t′ to the hidden state of the encoder at encoding time t, T is the total time step; c t′ is the context variable of the decoder at decoding time t′.

[0027] Preferably, generating a dialogue using the trained generative adversarial network specifically includes the following steps:

[0028] The target question is input into the second basic dialogue model to obtain an answer to the target question.

[0029] Preferably, the modal type of the input quantity of the basic dialogue model includes: one or a combination of any several of speech, text, and video; the modal type of the output quantity of the basic dialogue model includes: one or a combination of any several of speech, text, and video; the modal type of the dialogue sample data of the basic dialogue model includes: one or a combination of any several of speech, text, and video; the modal type of the input quantity of the dialogue emotion classifier includes: one or a combination of any several of speech, text, and video; the modal type of the dialogue sample data of the dialogue classifier includes: one or a combination of any several of speech, text, and video.

[0030] Preferably, during training, the initial input of the first basic dialogue model is dialogue data in a plurality of different modalities; the modality of the output of the first basic dialogue model is text; and the modality of the output of the second basic dialogue model is text.

[0031] Preferably, the initial input of the first basic dialogue model is dialogue data of multiple different modes. Wherein, x represents the dialogue data, the superscript number represents the sequence number of the corresponding dialogue data, n represents the number of the input dialogue data; the subscript letter represents the category of the corresponding dialogue data; the first basic dialogue model includes a modal conversion unit and a dialogue generation unit; the modal conversion unit is used to convert the dialogue data of multiple different modes initially input into Unified conversion into preset single-mode data The dialogue generation unit is used to generate the unimodal data First answer data Wherein, y represents the first answer data; the second basic dialogue model is used to generate the first answer data Second answer data z represents the second answer data; the dialogue emotion classifier is used to output the first answer data The first emotion vector Wherein, α represents the first emotion vector; the dialogue emotion classifier is used to output the second answer data The second emotion vector β represents the second emotion vector.

[0032] Preferably, the input and output of the first basic dialogue model are both in multimodal form; the input and output of the second basic dialogue model are both in multimodal form; the dialogue emotion classifier includes a plurality of different types of unimodal emotion classification units and an emotion fusion unit; the dialogue emotion classifier is used to distribute each unimodal data in the multimodal form of the first answer data or the second answer data to the emotion classification unit of the corresponding modality, each emotion classification unit outputs the emotion of each unimodal data to the emotion fusion unit, and the emotion fusion unit adopts a decision fusion method to fuse the emotions of each unimodal data in the first answer data or the second answer data to obtain a comprehensive emotion vector of the first answer data or the second answer data.

[0033] A computer system comprises a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the steps of the above method are implemented when the processor executes the computer program.

[0034] The present invention has the following beneficial effects:

[0035] 1. The dialogue generation method and system based on emotion analysis and generative adversarial network in the present invention, by constructing and training a basic dialogue model and a dialogue emotion classifier; using the basic dialogue model and the dialogue emotion classifier to construct a generative adversarial network, the generative adversarial network generates a generator based on the basic dialogue model, and generates a discriminator based on the dialogue emotion classifier, the discriminator is used to discriminate the emotional similarities and differences between the generator output answer and the real answer, and optimizes the network parameters of the generator according to the emotional similarities and differences, so that the emotion of the generator output answer approaches the emotion of the real answer; train the generative adversarial network, and use the trained generative adversarial network to generate dialogue. The present invention uses the basic dialogue model and the dialogue emotion classifier to construct a generative adversarial network; the trained generative adversarial network model has the ability to cooperate with the user's emotions, and can adjust the generated sentences according to the user's emotions when using it, so as to be closer to the real dialogue.

[0036] 2. In the preferred embodiment, the present invention combines a dialogue generation model with multimodal input emotion discrimination. After the model training is completed, it can receive multimodal user input, so that the model has the ability to identify the changes in user emotions at the time of use through multimodality. The model can be applied to more scenarios to adapt to systems facing different fields.

[0037] In addition to the above-described purposes, features and advantages, the present invention has other purposes, features and advantages. The present invention will be further described in detail below with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS

[0038] The drawings constituting a part of this application are used to provide a further understanding of the present invention. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the drawings:

[0039] Figure 1 It is a flowchart of the dialogue emotion discriminator model training in the preferred embodiment of the present invention.

[0040] Figure 2 It is a flowchart of the basic dialogue generation model pre-training in the preferred embodiment of the present invention.

[0041] Figure 3 is a training flow chart of a generative adversarial network in a preferred embodiment of the present invention;

[0042] Figure 4 It is a flowchart of a method for generating dialogue based on sentiment analysis and generative adversarial network in a preferred embodiment of the present invention. DETAILED DESCRIPTION

[0043] The embodiments of the present invention are described in detail below with reference to the accompanying drawings, but the present invention can be implemented in many different ways as defined and covered by the claims.

[0044] Embodiment 1:

[0045] like Figure 4 As shown, this embodiment discloses a dialogue generation method based on sentiment analysis and generative adversarial network, comprising the following steps:

[0046] Constructing a basic dialogue model, and obtaining multiple groups of dialogue sample data with labeled real answers to train the basic dialogue model;

[0047] Constructing a conversation emotion classifier, and obtaining multiple groups of conversation sample data with labeled emotion categories to train the conversation emotion classifier;

[0048] A generative adversarial network is constructed using the basic dialogue model and the dialogue emotion classifier. The generative adversarial network generates a generator based on the basic dialogue model and generates a discriminator based on the dialogue emotion classifier. The discriminator is used to discriminate the emotional similarities and differences between the generator output answer and the real answer, and optimize the network parameters of the generator according to the emotional similarities and differences, so that the emotion of the generator output answer approaches the emotion of the real answer;

[0049] The generative adversarial network is trained, and a dialogue is generated using the trained generative adversarial network.

[0050] In addition, in this embodiment, a computer system is also disclosed, including a memory, a processor, and a computer program stored in the memory and executable on the processor, and the processor implements the steps of the above method when executing the computer program.

[0051] The present invention uses a basic dialogue model and a dialogue emotion classifier to construct a generative adversarial network; the trained generative adversarial network model has the ability to cooperate with user emotions, and can adjust the generated sentences according to the user's emotions during use, making it closer to real dialogue.

[0052] Embodiment 2:

[0053] Embodiment 2 is a preferred embodiment of Embodiment 1. The difference between Embodiment 2 and Embodiment 1 is that the specific steps of the dialogue generation method based on sentiment analysis and generative adversarial network are introduced:

[0054] In this embodiment, a method for generating dialogue based on sentiment analysis and generative adversarial network is disclosed, comprising the following steps:

[0055] S1. Obtain multiple groups of emotion classification sample data, each group of sample data includes at least audio, video, and emotion annotations matching the group of data;

[0056] S2. Use a neural network to train an emotion classifier. The resulting model can identify the emotion corresponding to the input dialogue based on multimodal dialogue input.

[0057] S3. Acquire multiple groups of dialogue sample data, including real questions and real answers matching the real questions;

[0058] S4. Use a neural network to train an end-to-end basic dialogue generation model. The obtained model can generate a response based on the input question according to the input encoded data;

[0059] S5. Use two basic dialogue generation models as dialogue generators, and combine them with the emotion classification model as the discriminator to form a training model based on the generative adversarial network. Take the generator part after adversarial model training as the final model.

[0060] S6. Generate dialogue using the trained final model.

[0061] Among them, Figure 2 As shown in the figure, the training process of the basic dialogue generation model pre-training is as follows:

[0062] The acquired data is preprocessed into an easily recognizable word segmentation form X = (x1, x2, x3, ..., x n), where each x is the smallest non-empty subset of the set of non-repeating word segments of all data, and the subset of the set of non-repeating word segments of all data is used as the corpus for dialogue generation by this model.

[0063] The basic dialogue generation model is trained through the Seq2Seq model. The Seq2Seq model includes an encoder and a decoder. The encoder is used to encode sequence information and encode sequence information of any length into a vector H = (h1,h2,h3,...,h m ). The decoder is a decoder. After the decoder obtains the context information vector H, it can decode the information and output it as a sequence Y = (y1, y2, y3, ..., y k ) and translated into the final generated sentence through the encoding rules of the word segmentation process.

[0064] There are many ways to implement the Sea2Seq model. This embodiment is implemented by a gated recurrent control unit (GRU). In practice, it can be processed by a bidirectional gated recurrent control unit to control the complete past and future context information of the current moment in the input sequence.

[0065] The update gate and reset gate calculation process of the gate loop control unit is as follows:

[0066] z=σ(W z x t +U z h t-1 )

[0067] r=σ(W r x t +U r h t-1 )

[0068] Among them, x t is the input vector of the t-th time step, that is, the t-th component of the input sequence X, h t-1 What is saved is the information of the previous time step t-1.

[0069] The gated recurrent control network captures short-term dependencies in the time series by resetting the gate, and captures long-term relationships in the time series by updating the gate. The gated recurrent network has excellent performance in solving long- and short-range dependencies and is used as the implementation network of the encoder Encoder and decoder Decoder of the Seq2Seq model.

[0070] In order to solve the problem of the decoder's attention at different times, the attention mechanism is introduced. When the decoder is calculating at time t, in addition to the hidden state at time t-1 and the input at the current time, the attention mechanism can also refer to the input of the encoder at all times. Common attention is a soft attention, that is, an attention calculation with a probability of 1. Assuming that the input is five words, the attention will be expressed in the form of probability as an attention vector, such as (0.4, 0.1, 0.2, 0.2, 0.1). This shape of the vector means that for the current input, the attention mechanism requires the decoder to focus on the first word.

[0071] It is worth noting that the encoder can input the entire sequence to obtain the intermediate vector H during the encoding process, but the decoder takes the output at time t-1 as input when calculating at time t, so it can only process the data at the current time each time. Therefore, the encoder can use a bidirectional gate loop control network from the perspective of considering the past and future contexts when designing, while the decoder can only use a unidirectional gate loop control network. The calculation process of the decoder with the attention mechanism is as follows:

[0072] e t′t =a(s t′-1 ,h t )

[0073]

[0074]

[0075] s t′ =GRU(y t′-1 ,s t′-1 ,c t′ )

[0076] Where t′ is the different time of the decoder, t is the different time of the encoder, e t′t That is the decoder hidden state s at the previous moment t′-1 At different times t and the encoder intermediate state h t The importance of the calculated attention, a t′t Given the current time step t′ of the decoder, the weighted average of the hidden states of the encoder at different time steps t is the attention weight, T is the total time step, c t′ is the context variable of the decoder at time step t′.

[0077] The pre-trained basic dialogue generation model is retained and another identical agent is copied using the same parameters. In future adversarial training, one of the agents remains unchanged, and the other is continuously optimized based on the results of emotion discrimination. The dialogue of one of the agents is generated using a more random mechanism to avoid the two models learning the same tricky strategy in adversarial learning, such as tending to generate dialogue expressions of the same type to achieve the goal.

[0078] like Figure 1 As shown in Figure 1, the training process of the emotion classification model is as follows:

[0079] The emotion classification model is based on multimodal emotion recognition. Data acquisition requires multimodal sources. Experiments have shown that the accuracy of multimodal emotion recognition is much higher than that of single-modal emotion recognition. This embodiment briefly explains the three modes of audio, video, and text. When implementing it, technicians can modify the content used according to specific business requirements.

[0080] For video source data, an open source tool such as ffmpeg is used to extract a certain number of images from each video for subsequent feature extraction operations. There are many excellent networks in the field of image recognition that can extract facial expression features. This embodiment uses VGG16 and DenseNet networks to extract facial features.

[0081] For audio source data, openSmile (open Speech and Music Interpretation by Large Space Extraction) is a feature extraction tool that can be used to extract offline data features in large quantities. It also supports real-time online feature extraction and has the characteristics of high speed, high efficiency, high modularity and flexibility.

[0082] For text source data, based on a large number of text emotion recognition datasets at this stage, a long short-term memory network was trained to obtain a basic text unimodal emotion recognition network.

[0083] After extracting the features of the three modalities of image, speech, and text, the features extracted in the previous steps are used to train two emotion classifiers for the three modalities of image, audio, and text. There are generally two strategies for multimodal emotion recognition methods: feature fusion and decision fusion. The feature fusion method has the disadvantages that the fusion of features of different modalities will cause the dimension of the feature vector to become very large and the features of different modalities will affect each other. Therefore, it is decided to use the decision fusion method for multimodal fusion. Decision fusion is to superimpose and fuse the confidence scores output by multiple single-modal classifiers through some method to obtain the final confidence score, that is, the probability of each emotion category after modal fusion.

[0084] The traditional decision fusion stage adopts majority fusion, average fusion, weighted fusion or full connection layer fusion. Some of these fusion methods adopt the idea of ​​ensemble learning, vote according to the results of multiple single-modal emotion recognition, and use the result supported by the majority in the voting process as the result of the final modal fusion. The disadvantage is that the confidence score of the output of single-modal emotion recognition cannot be fully utilized, resulting in the classification of those categories that are easily misclassified. In this embodiment, SE-Block (Squeeze and Excitation Block) is used to implement the channel attention mechanism, and then the convolution layer with a 1*1 convolution kernel is used instead of the fully connected layer to fuse the results. SE-Block is an implementation method of the channel attention mechanism. It focuses on the channel dimension and can be modeled according to the information association between different channels. Through training, it can learn how much weight is assigned to each channel as the current optimal solution, and then adjust the weights between the channels. The operation of the SE module can be divided into three steps. The first step is the Squeeze operation, which compresses each channel in the spatial dimension, and the number after compression represents the channel. The dimension of the output of this step operation is consistent with the number of input channels. The second step is the Excitation operation, which generates a weight for each feature channel based on the dependencies between channels to represent the importance of the feature channel. The third step is to multiply the weight output in the second step by the original feature to complete the change of the original feature in the channel dimension. The role of the convolution layer with a 1*1 convolution kernel here is to superimpose and fuse the various feature channels, which can achieve dimensionality reduction of multiple feature channels and cross-channel data fusion, and ensure that spatial information is not affected. The result can achieve the same effect as the fully connected layer.

[0085] This embodiment divides the results of multimodal fusion emotion recognition into seven categories: anger, embarrassment, fear, happiness, sadness, surprise, and neutral. The accuracy of the multimodal fusion model after decision fusion is greatly improved compared to the single-modal emotion recognition model. It is the discriminator of the dialogue emotion recognition process generated for two independent agents (i.e., agent1 and agent2) in subsequent adversarial training.

[0086] like Figure 3 As shown in the figure, the training process of the dialogue generation adversarial model is as follows:

[0087] After pre-training of the basic dialogue generation model, a generative dialogue neural network model based on the Seq2Seq model can be obtained. It consists of an Encoder based on a bidirectional GRU and a Decoder based on a unidirectional GRU. We add an attention mechanism to it to solve the problem of its attention at different times during the decoding process. In the final stage of the present invention, two basic dialogue models generated by the above process will be used. In this embodiment, they are named agent1 (i.e., the first basic dialogue model) and agent2 (i.e., the second basic dialogue model). First, the basic model saved in the pre-training stage is read, and the two agents are combined into a model. The initial input of agent1 is the external real multimodal input, and the subsequent input is the unimodal output of agent2, that is, the text input, and the input of agent2 is the output of each dialogue of agent1. The two agents continuously communicate with each other and continuously optimize the dialogue model through the sentiment analyzer model.

[0088] Agent 1 of the two agents is used as a basic generator and is not optimized according to the results of sentiment analysis. This is to prevent the two agents from tending to produce a certain fixed and unified dialogue content in order to obtain higher evaluations. Since agent 1 is trained only through the most basic dialogue training method, the randomness of the content generated by agent 1 is also guaranteed. In the training phase, agent 2 is used as the final target model. It judges the dialogue results of the two agents according to the sentiment discriminator and updates the parameters of agent 2 in reverse order to make it produce more emotional sentences.

[0089] The method used by the emotion discrimination model during training is:

[0090] Except for the first round of dialogue in which the first input to agent 1 is the real external input, each subsequent round of dialogue is the dialogue content generated between the two agents in a generative manner. The output of each agent in each round of dialogue is taken, and basic emotion discrimination is performed on it according to the text emotion discriminator part of the emotion discriminator. In this embodiment, it is stipulated that the emotion of the sentence generated by agent 2 is the same as the emotion of the sentence generated by agent 1. If the emotion of the generated sentence is different, it means that agent 2 may have responded to agent 1 in the previous round of dialogue in the form of some safe response. The emotion vector of each round of dialogue is used as the output and the target for cross entropy calculation loss, and back-propagation is performed on agent 2 to update the gradient parameters.

[0091] That is, the real conversation data from the outside world is input into agent1 as the initial stimulus, and the iteration begins. In each round of iteration:

[0092] Agent 1 generates the first answer data of the input quantity of this round of iteration; and inputs the first answer data into agent 2 as the input quantity of agent 2 in this round of iteration; and also inputs the first answer data into the discriminator;

[0093] Agent 2 generates second answer data for the first answer data, and inputs the second answer data into the first basic dialogue model as the input of the next iteration of agent 1; and also inputs the second answer data into the discriminator;

[0094] The discriminator uses the dialogue emotion classifier to calculate the first emotion vector of the first answer data as the true answer emotion, calculates the second emotion vector of the second answer data as the emotion of the generator output answer, inputs the first emotion vector and the second emotion vector into the cross entropy loss calculation formula, calculates the output loss of the second basic dialogue model; and back-propagates the output loss to the second basic dialogue model to update the gradient parameters of the second basic dialogue model.

[0095] It is worth noting that during the training process, agent1 and agent2 will tend to produce the same sentences at a certain stage to escape the judgment of the emotion discriminator. It is generally believed that when agent2 and agent1 produce the same emotions or the same dialogue for three consecutive rounds at a certain stage of training, the training of this round is ended.

[0096] After multiple rounds of adversarial training, agent2 will be more inclined to generate sentences based on the dialogue sentiment of agent1. The training is now complete. The model of agent2 can be saved and used as the basic model of the generative dialogue Seq2Seq model in various scenarios and applied in actual systems.

[0097] Optionally, the discriminator based on emotion judgment can be adjusted in detail during training. In actual applications, the seven categories of anger, embarrassment, fear, happiness, sadness, surprise, and neutral do not necessarily have to correspond one to one. For example, in some scenarios, a user's angry emotion may want a sad or neutral response, and a user's embarrassed input may receive a comforting response. Therefore, in actual applications, technicians can selectively control the types of emotion generation targets corresponding to different emotions to adapt to applications in different scenarios.

[0098] 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 dialogue generation method based on sentiment analysis and generative adversarial network, characterized in that: The following steps are involved: Constructing a basic dialogue model, and obtaining multiple groups of dialogue sample data with labeled real answers to train the basic dialogue model; Constructing a conversation emotion classifier, and obtaining multiple groups of conversation sample data with labeled emotion categories to train the conversation emotion classifier; A generative adversarial network is constructed using the basic dialogue model and the dialogue emotion classifier. The generative adversarial network generates a generator based on the basic dialogue model and generates a discriminator based on the dialogue emotion classifier. The discriminator is used to discriminate the emotional similarities and differences between the generator output answer and the real answer, and optimize the network parameters of the generator according to the emotional similarities and differences, so that the emotion of the generator output answer approaches the emotion of the real answer; Training the generative adversarial network, and using the trained generative adversarial network to generate dialogues; The generator of the generative adversarial network includes two basic dialogue models, namely a first basic dialogue model and a second basic dialogue model; The output end of the first basic dialogue model is connected to the input end of the second basic dialogue model and the input end of the generator respectively; The output end of the second basic dialogue model is connected to the input end of the first basic dialogue model and the input end of the generator respectively; Training the generative adversarial network comprises the following steps: Inputting external real dialogue data into the first basic dialogue model as initial stimulation, and the iteration begins; In each iteration: The first basic dialogue model generates first answer data of the input amount of this round of iteration; and inputs the first answer data into the second basic dialogue model as the input amount of the second basic dialogue model in this round of iteration; and also inputs the first answer data into the discriminator; The second basic dialogue model generates second answer data for the first answer data, and inputs the second answer data into the first basic dialogue model as input for the next iteration of the first basic dialogue model; and also inputs the second answer data into the discriminator; The discriminator uses the dialogue emotion classifier to calculate the first emotion vector of the first answer data as the true answer emotion, calculates the second emotion vector of the second answer data as the emotion of the generator output answer, and calculates the output loss of the second basic dialogue model based on the first emotion vector and the second emotion vector, and uses the output loss to update the network parameters of the second basic dialogue model.

2. The method for generating dialogues based on sentiment analysis and generative adversarial networks according to claim 1, characterized in that: Calculating the output loss of the second basic dialogue model according to the first emotion vector and the second emotion vector, and using the output loss to update the network parameters of the second basic dialogue model, specifically: The first emotion vector and the second emotion vector are input into a cross entropy loss calculation formula to calculate the output loss of the second basic dialogue model; and the output loss is back-propagated to the second basic dialogue model to update the gradient parameters of the second basic dialogue model.

3. The method for generating dialogues based on sentiment analysis and generative adversarial networks according to claim 2, characterized in that: The basic dialogue model is a Seq2Seq model based on a gate loop control unit; the encoder of the basic dialogue model is a bidirectional gate loop control network; the decoder of the basic dialogue model is a unidirectional gate loop control network based on an attention mechanism; the decoding formula of the unidirectional gate loop control network is as follows: e t't =a(s t'-1 ,h t ) s t' =GRU(y t'-1 ,s t'-1 ,c t' ) Among them, t′ is the decoding time of the decoder, t is the encoding time of the encoder, and s t'-1 is the decoder hidden state at t′-1; h t is the intermediate state of the encoder at encoding time t; e t't is the importance of attention between the decoder hidden state at decoding time t′-1 and the encoder intermediate state at encoding time t; a t't is the attention weight of the decoder at decoding time t′ to the hidden state of the encoder at encoding time t, T is the total time step; c t' is the context variable of the decoder at decoding time t′.

4. The method for generating dialogues based on sentiment analysis and generative adversarial networks according to claim 1, characterized in that: Using the trained generative adversarial network to generate a dialogue specifically includes the following steps: The target question is input into the second basic dialogue model to obtain an answer to the target question.

5. The method for generating dialogue based on sentiment analysis and generative adversarial network according to claim 4, characterized in that: The modal types of the input quantity of the basic dialogue model include: one or a combination of any several of speech, text, and video; the modal types of the output quantity of the basic dialogue model include: one or a combination of any several of speech, text, and video; the modal types of the dialogue sample data of the basic dialogue model include: one or a combination of any several of speech, text, and video; the modal types of the input quantity of the dialogue emotion classifier include: one or a combination of any several of speech, text, and video; the modal types of the dialogue sample data of the dialogue classifier include: one or a combination of any several of speech, text, and video.

6. The method for generating dialogue based on sentiment analysis and generative adversarial network according to claim 5, characterized in that: During training, the initial input of the first basic dialogue model is dialogue data of multiple different modalities; The modality of the output of the first basic dialogue model is text; The modality of the output of the second basic dialogue model is text.

7. The method for generating dialogue based on sentiment analysis and generative adversarial network according to claim 5, characterized in that: The initial input of the first basic dialogue model is dialogue data of multiple different modes Wherein, x represents the dialogue data, the superscript number represents the sequence number of the corresponding dialogue data, n represents the number of the input dialogue data; the subscript letter represents the category of the corresponding dialogue data; the first basic dialogue model includes a modal conversion unit and a dialogue generation unit; the modal conversion unit is used to convert the dialogue data of multiple different modes initially input into Unified conversion into preset single-mode data The dialogue generation unit is used to generate the unimodal data First answer data Wherein, y represents the first answer data; the second basic dialogue model is used to generate the first answer data Second answer data z represents the second answer data; the dialogue emotion classifier is used to output the first answer data The first emotion vector Wherein, α represents the first emotion vector; the dialogue emotion classifier is used to output the second answer data The second emotion vector β represents the second emotion vector.

8. The method for generating dialogue based on sentiment analysis and generative adversarial network according to claim 5, characterized in that: The input and output of the first basic dialogue model are both in multimodal form; the input and output of the second basic dialogue model are both in multimodal form; the dialogue emotion classifier includes multiple different types of unimodal emotion classification units and an emotion fusion unit; the dialogue emotion classifier is used to distribute each unimodal data in the multimodal form of the first answer data or the second answer data to the emotion classification unit of the corresponding modality, and each emotion classification unit outputs the emotion of each unimodal data to the emotion fusion unit, and the emotion fusion unit adopts a decision fusion method to fuse the emotions of each unimodal data in the first answer data or the second answer data to obtain a comprehensive emotion vector of the first answer data or the second answer data.

9. A computer system comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 8 are implemented.