Adaptive empathic dialogue method based on quantitative sentiment analysis
By adopting an adaptive empathic dialogue method based on quantitative sentiment analysis, this paper addresses the shortcomings of existing dialogue systems in sentiment recognition and dynamic sentiment processing, achieving accurate identification and personalized response to user emotions, thereby improving user experience and system performance.
Patent Information
- Application Number
- CN202511455678.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-10-13
- Publication Date
- 2025-12-30
- Estimated Expiration
- 2045-10-13
AI Technical Summary
Existing dialogue systems struggle to accurately identify and quantify user emotional cues when processing complex emotional information, resulting in poor emotional resonance and insufficient response to dynamic emotional changes, thus impacting user experience.
An adaptive empathic dialogue method based on quantitative sentiment analysis is adopted. The semantics and syntax of user input are captured by a pre-trained language model encoder, global sentiment representation is calculated and mapped to sentiment polarity and sentiment probability space. Combined with a large language model, personalized empathic dialogue is generated, and response strategies are updated in real time to adapt to changes in user sentiment.
It achieves accurate identification and quantification of user emotions, reduces noise introduction, improves the response accuracy and user experience of the dialogue system, and can dynamically respond to emotional changes, providing personalized emotional support.
Smart Images

Figure CN120910227B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of artificial intelligence, and in particular to an adaptive empathic dialogue method based on quantitative sentiment analysis. Background Technology
[0002] With the rapid development of artificial intelligence technology, large language models are increasingly widely used in the field of natural language processing and have made significant progress. For example, some studies have demonstrated the superior performance of large language models in dialogue generation, text analysis, and language understanding. Large language models have driven the development of intelligent interactive systems, making emotional support systems and empathic dialogue systems research hotspots. These empathic dialogue systems based on large language models have shown great potential in application scenarios such as psychological counseling, emotional companionship, and intelligent customer service. Through natural language processing technology, dialogue systems can engage in deep emotional interaction with users and provide personalized support and suggestions.
[0003] However, existing dialogue systems still face numerous challenges in processing complex emotional information. A key issue is how to accurately identify and quantify users' emotional cues to optimize the dialogue generation process and achieve more efficient emotional resonance from the dialogue system. The limitations of traditional dialogue systems in emotion recognition and response lead to a poor user experience, which is particularly evident in scenarios such as emotional support and psychological counseling.
[0004] To overcome these challenges, researchers have proposed the Retrieval-Augmented Generation (RAG) method. This RAG method improves the problem of large language models easily generating erroneous responses by retrieving information from external knowledge sources and integrating the retrieved information into the dialogue generation process. However, existing RAG methods typically employ a uniform retrieval strategy for each user input dialogue. While this improves dialogue accuracy to some extent, it introduces noise or contradictory information when internal knowledge is sufficient, reducing the response quality of the dialogue system. Furthermore, although the adaptive retrieval strategy used in existing RAG methods can dynamically adjust the retrieval process, it fails to effectively handle dynamic emotions in dialogue, thus degrading the user's dialogue experience. Summary of the Invention
[0005] The technical problem this invention aims to solve is to provide an adaptive empathic dialogue method based on quantitative sentiment analysis, addressing the shortcomings of the prior art. This adaptive empathic dialogue method based on quantitative sentiment analysis can not only accurately identify and quantify user emotional cues, optimize the emotional resonance process, and improve response accuracy, but also respond to user emotional changes in a personalized way, providing more precise emotional support and suggestions.
[0006] The technical solution adopted by this invention to solve the above-mentioned technical problems is: an adaptive empathic dialogue method based on quantitative sentiment analysis, characterized by including the following steps S1 to S7:
[0007] Step S1: Receive the dialogue statement input by the user;
[0008] Step S2 involves encoding the user-input dialogue statement using a pre-trained language model encoder to convert the dialogue statement into a context-sensitive hidden state sequence, capturing the semantics and grammar of each word in the dialogue statement; wherein, the hidden state sequence is labeled as... H ;
[0009] Step S3: Quantify the sentiment contribution of each word in the current dialogue statement to the dialogue history to obtain global sentiment representation data; wherein, the dialogue history is marked as... D Global sentiment representation data is labeled as s ;
[0010] Step S4 involves mapping the generated global sentiment representation data to sentiment spaces of different polarities to obtain sentiment polarity probability data; and mapping the global sentiment representation data to a fine-grained sentiment category space to obtain sentiment probability data; wherein, the sentiment polarity probability data is labeled as P. polarity The probability data of emotions is labeled as P. category ;
[0011] Step S5: Using global sentiment representation data, sentiment polarity probability data, and emotion probability data, quantitative calculations are performed on sentiment cues in the current dialogue sentence; wherein, sentiment cues in the current dialogue sentence are marked as... c ;
[0012] Step S6: Using a large language model based on the current response strategy, and according to the dialogue history, combined with the obtained sentiment polarity probability data and emotion probability data, a dialogue target is generated. This dialogue target is then encoded using a pre-trained language model encoder. The similarity data representing the sentiment cues and the encoded dialogue target is then calculated. The generated dialogue target is denoted as... g The target of the dialogue after encoding is denoted as h g Emotional clues c Dialogue target obtained after encoding h g Similarity data for matching is labeled R weighted ;
[0013] Step S7: Utilize the large language model and optimize the response strategy based on the obtained similarity data to generate a personalized empathetic dialogue that matches the user's current dialogue statement; wherein, the personalized empathetic dialogue that matches the user's current dialogue statement is tagged as y. gen .
[0014] As an improvement, the adaptive empathic dialogue method based on quantitative sentiment analysis further includes, after generating the personalized empathic dialogue:
[0015] Receive feedback information input by the user; wherein, the feedback information input by the user is marked as Feedback;
[0016] The large language model adaptively optimizes and updates its response strategy based on this feedback information;
[0017] The large language model generates dialogue targets for the next conversation based on the real-time updated response strategy.
[0018] Furthermore, in the aforementioned adaptive empathic dialogue method based on quantitative sentiment analysis, the large language model updates its response strategy as follows:
[0019] ;
[0020] Where θ' represents the parameters of the large language model after the response policy update, θ represents the parameters of the large language model before the response policy update, and η is the learning rate. The gradient of parameter θ is also the gradient of the loss function L(Feedback, y). gen The vector of partial derivatives of L(Feedback,y) with respect to the parameter θ gen ) is a measure of generating personalized, empathetic dialogues. gen The loss function is the difference between user expectations and user feedback information.
[0021] Further improvements are made to the adaptive empathic dialogue method based on quantitative sentiment analysis. In step S2, the process of encoding the user-input dialogue statements using a pre-trained language model encoder includes the following steps S21-S22:
[0022] Step S21: The dialogue statements are segmented using the built-in word segmenter of the pre-trained language model encoder to obtain a dialogue statement sequence; wherein, the dialogue statement sequence is tagged as... X , X ={ x i , x 2,…, x n}, x iLet i represent the i-th word in the dialogue statement sequence; 1≤i≤n, where n is the total number of words in the dialogue statement sequence;
[0023] Step S22: Encode the obtained dialogue statement sequence using a pre-trained language model encoder to obtain a set of hidden state sequences; wherein, the hidden state sequences are labeled as... H , H =Encoder(X)= {h i , h 2,…, h n}, h i For vocabulary x i The context embedding representation, and h i Characterizes vocabulary x i Semantic and syntactic information in the context of dialogue.
[0024] Furthermore, in the adaptive empathic dialogue method based on quantitative sentiment analysis, after completing step S2, the attention weight representing the contribution of each word in the current dialogue statement to the overall sentiment of the current dialogue statement is calculated; wherein, the calculation process of the attention weight includes the following steps:
[0025] Step Sa involves computing the sentiment representation of the current sentence using a feedforward neural network in the pre-trained language model encoder; wherein the sentiment representation of the current sentence is labeled as... h T = W T ·H + b T , W T It is the training weight matrix. H This is the hidden state sequence corresponding to the current statement. b T It is a bias term;
[0026] Step Sb, based on the adaptive attention mechanism in the pre-trained language model encoder, calculates the similarity between the context embedding representation and the sentiment representation corresponding to each word in the current dialogue sentence sequence, and generates the attention weights corresponding to each word; where, words x i The corresponding attention weights are labeled as α i :
[0027] ,and ;
[0028] in, W ɑ It is the weight matrix obtained during training.
[0029] In a further improvement, in the adaptive empathic dialogue method based on quantitative sentiment analysis, the calculation process of the global sentiment representation data in step S3 includes steps S31 to S33:
[0030] Step S31, calculate the overall sentiment tendency representation corresponding to the dialogue history; wherein, the overall sentiment tendency representation corresponding to the dialogue history D is as follows: h D ;
[0031] Step S32: Calculate the similarity between the context embedding representation corresponding to each word in the current dialogue sentence sequence and the overall sentiment tendency representation, and generate attention weights representing the contribution of each word in the current dialogue sentence to the overall sentiment of the dialogue history; wherein, words x i The attention weight for the overall emotional contribution of the dialogue history is labeled γ. i :
[0032] ,and ;in, W c It is the weight matrix of the emotional c;
[0033] Step S33: Calculate the global sentiment representation data based on the context embedding representation corresponding to each word and the corresponding attention weights; wherein, the global sentiment representation data... .
[0034] Improvedly, in the adaptive empathic dialogue method based on quantitative sentiment analysis, in step S4, the sentiment spaces of different polarities include a positive sentiment space, a negative sentiment space, and a neutral sentiment space; wherein:
[0035] The emotional polarity probability data P polarity The calculation method includes the following steps S41 and S42:
[0036] Step S41: Calculate the emotional polarity score corresponding to each emotional polarity space; whereby the emotional polarity score is labeled z. polarity,j :
[0037] z polarity,j = W polarity · s +b polarity ; 1≤j≤3;
[0038] Where j represents the category number of the emotional polarity; Wpolarity The weight matrix representing the sentiment polarity classification. s For global sentiment representation data, b polarity Bias terms representing the emotional polarity classification;
[0039] Step S42: The obtained sentiment polarity scores are normalized using the softmax function to obtain the sentiment polarity probability distribution mapped to each sentiment polarity space; whereby the sentiment polarity probability distribution is labeled P. polarity (Y polarity ):
[0040] ; 1≤j≤3;
[0041] Y polarity =[positive, negative, neutral];
[0042] P polarity =[P positive , P negative, P neutual ];
[0043] Among them, Y polarity The categories representing the polarity of emotions are: positive (positive polarity), negative (negative polarity), and neutral (neutral polarity), with j representing the category number of the emotional polarity.
[0044] The emotion probability data P category The calculation method includes the following steps S4a and S4b:
[0045] Step S4a: Calculate the emotion category score corresponding to each polarity emotion space; whereby the emotion category score is labeled z. category,k :
[0046] z category,k = W category · s +b category ; 1≤k≤K;
[0047] Among them, W category The weight matrix for classifying emotion categories, where s is the global sentiment representation data, and b... category The bias term for classifying emotion categories; k is the category number of the emotion category, and K is the total number of emotion categories;
[0048] Step S4b: Normalize the scores of each emotion category using the softmax function to obtain the probability distribution of each emotion category; whereby the probability distribution of the emotion category is labeled P. category :
[0049] ;
[0050] Y category =[happy,angry,…, category K ];
[0051] P category =[P happy ,P angry ,…,P categoryK ];
[0052] Among them, Y category Indicates the emotion category.
[0053] Furthermore, in the adaptive empathic dialogue method based on quantitative sentiment analysis, in step S5, the method for calculating the sentiment cues is as follows:
[0054] Step S51: Make a judgment based on the probability distribution corresponding to any obtained emotion category and the preset probability threshold.
[0055] If the probability distribution corresponding to any emotion category is greater than the preset probability threshold, proceed to step S52; otherwise, proceed to step S53.
[0056] Step S52: Calculate the sum of attention weights between the attention weights of each word in the current dialogue statement on its overall emotional contribution to the current dialogue statement and its overall emotional contribution to the dialogue history. The context embedding representation of the word corresponding to the word with the maximum value in the obtained attention weight sum is used as the emotional cue. Wherein, any word in the previous dialogue statement... x i The corresponding attention weights and values are labeled as follows ;
[0057] Step S53, using the global sentiment representation data as the sentiment cue; wherein, sentiment cue c=s ;
[0058] In step S6, the method for calculating the similarity data representing the matching between emotional cues and the encoded dialogue target includes the following steps S61 to S64:
[0059] Step S61: Using a large language model, based on the dialogue history and combined with sentiment polarity probability data and emotion probability data, a dialogue target is generated; whereby this dialogue target is denoted as g:
[0060] G=LLM(D, P polarity , P category ); D={u1,r1,…,u t ,rt};
[0061] Where D represents the dialogue history, u t Let r represent the user input in the t-th round. t This is the corresponding system response, where t is the current round;
[0062] Step S62: The generated dialogue target is encoded using a pre-trained language model encoder to obtain the encoded dialogue target, and this encoded dialogue target is used as the sentiment representation corresponding to the dialogue target; wherein, the encoded dialogue target corresponding to dialogue target g is denoted as... h g ;
[0063] Step S63: Calculate the cosine similarity between the sentiment c and the obtained encoded dialogue target; where the sentiment c and the obtained encoded dialogue target... h g The cosine similarity between them is denoted as R (c,g):
[0064] ;
[0065] in, The vector norm representing the emotional c. Indicates the target of the coded dialogue h g The vector norm;
[0066] Step S64: The obtained cosine similarity is weighted to calculate the similarity data representing the matching between emotional cues and the encoded dialogue target; wherein, this similarity data is labeled as R. weighted :
[0067] R weighted (c, g)= β·R (c,g);
[0068] Where β is the weighting factor for the ambiguity of the emotional cue; c=h i When c=s, β=β1; when c=s, β=β2; β1 and β2 are the pre-set weight factor values.
[0069] Furthermore, in the adaptive empathic dialogue method based on quantitative sentiment analysis, step S7, the method for generating the personalized response empathic dialogue includes the following steps:
[0070] Step S71, calculate the adaptive retrieval trigger value; wherein, this adaptive retrieval trigger value is marked as Trigger:
[0071] Trigger=σ(R weighted (c,h g )+ ɑ · Context_Deficiency);
[0072] Where σ(·) is the Sigmoid activation function, representing the probability of adaptive retrieval being triggered; c represents the sentiment cue. h g This indicates the target of the encoded dialogue; ɑ is a control parameter, and Context_Deficiency indicates the degree of context missing in the current dialogue statement;
[0073] Step S72: Make a judgment based on the calculated adaptive retrieval trigger value:
[0074] When the adaptive retrieval trigger value exceeds the set threshold, external knowledge retrieval is triggered to execute step S73; otherwise, step S76 is executed.
[0075] Step S73: Calculate the retrieval query vector using the query decision formula; whereby the retrieval query vector is labeled Retrieval_Query:
[0076] ;
[0077] in, W c Here is the weight matrix for the sentiment c. W hg For the coded dialogue target h g The weight matrix, d represents the weights of c and c. h g Dimensions W r The output weights of the query results; W hg · h g ) T express W hg · h g Transpose of;
[0078] Step S74: Perform external knowledge retrieval based on the obtained retrieval query vector, and input the retrieval results obtained from the external knowledge retrieval into the large language model;
[0079] Step S75: The large language model generates an empathetic dialogue to respond to the user's current dialogue statement based on the retrieval result and the current response strategy.
[0080] Step S76: The large language model jointly generates an empathetic dialogue to respond to the user's current dialogue statement based on the current response strategy.
[0081] Compared with the prior art, the advantages of the present invention are as follows:
[0082] (1) Precise quantitative sentiment cue analysis
[0083] Compared to existing technologies, which often rely on predefined rules or simple emotion classification methods and struggle to capture subtle emotional changes in user expressions, this invention's adaptive empathetic dialogue method based on quantitative sentiment analysis introduces a quantitative sentiment cue analysis method. This method quantitatively evaluates the relevance of each cue to the target dialogue statement, thereby achieving accurate identification of the user's emotional state. In contrast, existing methods typically lack this fine-grained sentiment analysis capability, making it difficult to provide personalized emotional support. Therefore, this invention's adaptive empathetic dialogue method can more efficiently achieve emotional resonance and enhance user experience.
[0084] (2) Adaptive retrieval strategy reduces noise introduction
[0085] In Retrieval Enhanced Generation (RAG) technology, existing methods typically employ a uniform retrieval strategy for each user input. This can introduce unnecessary noise or contradictory information when the model's internal knowledge is already sufficient, thereby reducing the accuracy of the system's response. The adaptive retrieval strategy proposed in this invention, based on an adaptive empathic dialogue method using quantitative sentiment analysis, dynamically assesses the necessity of external knowledge and retrieves it only when truly needed, effectively reducing the introduction of noise and contradictory information. By analyzing user input content and emotional state in real time and dynamically adjusting the retrieval process, the timeliness and relevance of retrieved information are ensured, significantly optimizing the dialogue generation process and improving the overall performance of the system.
[0086] (3) Real-time processing of emotional dynamics
[0087] Existing technologies have significant limitations in handling emotional dynamics during dialogues, often neglecting real-time changes in user emotions that are crucial in applications such as emotional support and psychological counseling. This invention presents an adaptive empathic dialogue method based on quantitative emotion analysis. By monitoring and analyzing user emotional changes in real time, it dynamically adjusts dialogue content and strategies to ensure the system can continuously and consistently respond to users' emotional needs. In contrast, existing methods often struggle to achieve such nuanced emotional dynamic processing, resulting in a poor user experience. This invention's adaptive empathic dialogue method not only improves the effectiveness of emotional resonance but also significantly enhances user satisfaction and the system's empathic capabilities. Attached Figure Description
[0088] Figure 1 This is a flowchart of the adaptive empathic dialogue method based on quantitative sentiment analysis in an embodiment of the present invention. Detailed Implementation
[0089] The present invention will be further described in detail below with reference to the accompanying drawings and embodiments.
[0090] like Figure 1 As shown, the adaptive empathic dialogue method based on quantitative sentiment analysis in this embodiment includes the following steps S1 to S7:
[0091] Step S1: Receive the dialogue statement input by the user; wherein the dialogue statement input by the user is marked as X;
[0092] Step S2 involves encoding the user-input dialogue statement using a pre-trained language model encoder to convert the dialogue statement into a context-dependent hidden state sequence, capturing the semantics and grammar of each word in the dialogue statement; this hidden state sequence is denoted as H.
[0093] Specifically, in this embodiment, the process of encoding the user-input dialogue statement X using a pre-trained language model encoder includes the following steps S21~S22:
[0094] Step S21: The dialogue statements are segmented using the built-in word segmenter of the pre-trained language model encoder to obtain a dialogue statement sequence; wherein, the dialogue statement sequence is tagged as... X , X ={ x i , x 2,…, x n}, x i Let i represent the i-th word in the dialogue statement sequence; 1≤i≤n, where n is the total number of words in the dialogue statement sequence;
[0095] For example, if a user inputs the dialogue phrase "I'm happy today," after word segmentation, the sequence "I," "today," "very," and "happy" is obtained, with each word acting as an independent word. x i ;
[0096] Step S22: Encode the obtained dialogue statement sequence using a pre-trained language model encoder to obtain a set of hidden state sequences; wherein, the hidden state sequences are labeled as... H , H =Encoder(X)= {h i , h 2,…, h n}, h i For vocabulary xi The contextual embedding representation, where these embedding vectors represent the semantics of the words themselves, captures the interaction between the currently processed word and other words in the sequence, reflecting its emotional and contextual features in the dialogue context, and thus characterizing the words. x i The semantic and grammatical information within the context of the dialogue; that is to say... h i Characterizes vocabulary x i Semantic and syntactic information within the context of the dialogue; but hidden state sequences H It fails to fully reflect emotional characteristics and needs further optimization in subsequent steps;
[0097] It should be noted that the pre-trained language model encoder in this embodiment is a pre-trained language model based on the Transformer architecture. This model consists of multiple Transformer layers, each containing a self-attention mechanism and a feedforward neural network. In the self-attention mechanism, the model calculates the relevance of each word in the sequence to other words, generating attention weights to capture long-range dependencies between words.
[0098] In this embodiment, after completing step S2 and before proceeding to step S3, steps Sa to Sb can be performed to clarify the relevance of each word in the dialogue sentence sequence X to other words in the same sequence. For example, in "I'm very happy today," the self-attention mechanism analyzes the modifying relationship between "happy" and "very," as well as the contextual association between "today" and the entire sentence. This mechanism generates a context-related representation for each word by performing multiple weighted combinations on the input sequence. Specifically, for each word... x i The pre-trained language model first takes its initial embedding as input and performs multi-head self-attention computation to generate a new representation that captures its semantic and grammatical relationships with other words in the sequence. This representation is then further processed by a feedforward neural network to extract more abstract features. This process is repeated multiple times, with each layer refining the word representation to include richer contextual information.
[0099] Specifically, after completing step S2, attention weights representing the overall emotional contribution of each word in the current dialogue statement to the current dialogue statement are calculated. α i Attention weight α i The calculation method includes the following steps: Sa~Sb.
[0100] Step Sa involves computing the sentiment representation of the current sentence using a feedforward neural network in the pre-trained language model encoder; wherein the sentiment representation of the current sentence is labeled as... h T = W T ·H + b T , W T It is the training weight matrix. H This is the hidden state sequence corresponding to the current statement. b T It is a bias term;
[0101] Step Sb, based on the adaptive attention mechanism in the pre-trained language model encoder, calculates the similarity between the context embedding representation and the sentiment representation corresponding to each word in the current dialogue sentence sequence, and generates the attention weights corresponding to each word; where, words x i The corresponding attention weights are labeled as α i :
[0102] ,and ;
[0103] in, W ɑ The weight matrix (or learnable weight matrix) is obtained through training; it is automatically generated during model training. W ɑ The shape is usually based on "contextual embedding" h i "Dimensions" and "Sentimental Tendency" h T Designed using "dimensions" (e.g.) h i It is d-dimensional. h T It's d-dimensional, then... W ɑ It could be a d×d matrix);
[0104] Step S3: Quantify the sentiment contribution of each word in the current dialogue statement to the dialogue history to obtain global sentiment representation data; wherein, the dialogue history is marked as... D The global sentiment representation data is labeled as s; wherein, in this embodiment, the calculation method of the global sentiment representation data s includes steps S31~S33:
[0105] Step S31: Calculate the overall sentiment representation corresponding to the dialogue history; wherein, the dialogue history DThe corresponding overall sentiment tendency is expressed as h D ;
[0106] Step S32: Calculate the similarity between the context embedding representation corresponding to each word in the current dialogue sentence sequence and the overall sentiment tendency representation, and generate attention weights representing the contribution of each word in the current dialogue sentence to the overall sentiment of the dialogue history; wherein, words x i The attention weight for the overall emotional contribution of the dialogue history is labeled γ. i :
[0107] ,and ;in, W c It is the weight matrix of the emotional c;
[0108] Step S33: Calculate the global sentiment representation data based on the context embedding representation corresponding to each word and the corresponding attention weights; wherein, the global sentiment representation data... .
[0109] As mentioned earlier, the hidden state sequence H While the contextual information of words has been captured, it hasn't clearly distinguished which words contribute more to the sentiment (e.g., positive, negative) of the dialogue. The adaptive attention mechanism is introduced to address this issue; this embodiment introduces a global sentiment representation h. D Evaluate each h i The relevance of the word to the overall sentiment of the conversation history is used to assign an attention weight γ to each word. i These weights reflect the relative importance of words in emotional expression. For example, "happy" may receive a higher weight due to its strong positive emotional characteristics, while "today," as a neutral word, may receive a lower weight.
[0110] Global sentiment representation (also known as overall sentiment tendency representation) h D It is a high-dimensional vector representing the sentiment tendency of the entire dialogue. The parameters of the transformation layer are optimized during the training of the pre-trained language model using supervised signals (sentiment labels). h D To more accurately reflect the emotional inclination of historical dialogue. For example, in positive emotional dialogue, W c They might learn to amplify features associated with words like "happy" and "like." For example, regarding "I'm very happy today," h DIt leans towards positive emotions, including features related to words like "happy" and "very." Similarity calculation is the core operation of the adaptive attention mechanism, and the formula... h i · W c · h D This indicates that a trainable weight matrix is used. W c Will h i and h D Mapped to a scalar similarity value. W c Used for adjustment h i and h T The comparison method in high-dimensional space enables the model to learn feature patterns related to emotion. Specifically, h i · W c First of all h i Project it onto a new vector space, and then intersect this projected vector with... h D Performing the dot product yields a scalar, which represents... h i and h D Relevance in the emotional dimension. For example, "happiness". h i With positive emotions h D The dot product value is relatively high, while "today's" is... h i The similarity may be low. To ensure that the attention weights form a probability distribution, the formula uses a softmax function to normalize the similarity values of all words. γ i It becomes a value between 0 and 1, quantifying the vocabulary. x i Contribution to the overall emotional tone of the dialogue.
[0111] In the aforementioned calculation process, W a and W c Trainability is key. W a , W c The parameters are optimized through backpropagation during model training, enabling it to learn patterns of emotional cues in dialogue. For example, in positive emotional dialogue, Wa , W c It may learn to amplify features associated with positive words such as "happy" and "like," while focusing on features of words like "sad" and "angry" in negative emotional dialogues. This learning ability allows the adaptive attention mechanism to dynamically adapt to different dialogue contexts, rather than solely relying on the general contextual representation provided by the encoder. Furthermore, the use of an exponential function enhances the contrast of similarity values, making them more relevant to different situations. h D Highly related h i This results in significantly higher weights for irrelevant words, while the weights for irrelevant words approach zero. This non-linear transformation helps focus on a few key emotional cues, reducing interference from noisy words such as neutral words or stop words. The generated attention weights γ i It has an intuitive explanatory quality.
[0112] Global sentiment representation (s) comprehensively reflects the overall tendency of all emotional cues in the dialogue. s It can be seen as h i The weighted average is biased towards words that contribute more to emotional expression. For example, in "I'm very happy today," "happy" and "very" correspond to... h i Because of higher γ i right s Contribute more, generate s The vector will primarily reflect positive sentiment characteristics, while "today" and "I" will contribute less due to their lower weights. This weighting method ensures... s It can focus on key emotional cues in the overall dialogue, reducing interference from neutral or irrelevant words, thereby more accurately representing the overall emotional tendency of the dialogue.
[0113] Step S4 involves mapping the generated global sentiment representation data to sentiment spaces of different polarities to obtain sentiment polarity probability data; and mapping the global sentiment representation data to a fine-grained sentiment category space to obtain sentiment probability data; wherein, the sentiment polarity probability data is labeled as P. polarity The probability data of emotions is labeled as P. category ;
[0114] Specifically, this emotional space of different polarities includes a positive emotional space, a negative emotional space, and a neutral emotional space, which will be used to represent global emotional data. s Mapped to a three-dimensional sentiment polarity space, generating a sentiment polarity score vector z. polarity The three components represent the tendency of the dialogue statements in the positive, negative, and neutral sentiment dimensions, respectively. These scores are then transformed into a probability distribution P using a softmax function.polarity This provides the probability that a dialogue belongs to each sentiment category. These two phases enable the pre-trained language model to quantify the sentiment tendency of a dialogue in an interpretable way, providing clear direction for sentiment understanding and response generation in dialogue systems.
[0115] In this embodiment, the emotional polarity probability data P polarity The calculation method includes the following steps S41~S42:
[0116] Step S41: Calculate the emotional polarity score corresponding to each emotional polarity space; whereby the emotional polarity score is labeled z. polarity,j :
[0117] z polarity,j = W polarity · s +b polarity ; 1≤j≤3;
[0118] Where j represents the category number of the emotional polarity; W polarity The weight matrix representing the sentiment polarity classification. s For global sentiment representation data, b polarity Bias terms representing the emotional polarity classification;
[0119] Bias term b polarity It is a three-dimensional vector that provides an adjustable offset for each emotion category; W polarity · s The calculation involves mapping s from a high-dimensional space to a three-dimensional space, generating a three-dimensional vector z that represents the emotional polarity score in the three emotional spaces. polarity =[z positive , z negative , z neutual ]; Each component z polarity This represents the raw score of the dialogue statement in the corresponding sentiment category. For example, in "I'm happy today," z positive It may be higher, while z negative and z neutual Lower; bias term b polarity This is used to correct model bias and ensure that the score distribution conforms to the pattern of the training data; W polarity and b polarity The parameters are optimized through supervised learning during model training, typically using a dataset of dialogue statements labeled with three sentiment polarities: positive, negative, and neutral. The parameters are adjusted using cross-entropy loss to make z... polarity It can accurately reflect the emotional tone of dialogue statements;
[0120] Step S42: The obtained sentiment polarity scores are normalized using the softmax function to obtain the sentiment polarity probability distribution mapped to each sentiment polarity space; whereby the sentiment polarity probability distribution is labeled P. polarity (Y polarity ):
[0121] ; 1≤j≤3;
[0122] Y polarity =[positive, negative, neutral];
[0123] P polarity =[P positive , P negative , P neutual ];
[0124] Among them, Y polarity The categories representing the polarity of emotions are: positive (positive polarity), negative (negative polarity), and neutral (neutral polarity), with j representing the category number of the emotional polarity.
[0125] The softmax function affects z. polarity The three components are normalized to map the original score to probability values, generating P. polarity =[P positive , P negative, P neutual [z] is a three-dimensional probability distribution representing the probability that a conversation belongs to each emotion category. For example, for "I'm happy today," suppose z... polarity =[5.2, -2.1, 0.3], after softmax, P may be obtained. polarity =[0.95, 0.02, 0.03] indicates that the dialogue has a 95% probability of being positive in sentiment, a 2% probability of being negative, and a 3% probability of being neutral. This probability distribution provides a clear classification result for the dialogue system.
[0126] From a semantic and emotional perspective, this process compresses the high-dimensional emotional information of a dialogue into a concise three-dimensional representation, while preserving key emotional inclinations. For example, in "I'm very happy today," s It may contain positive features of "happiness". After linear transformation, z polarityHighlighting the positive component, softmax further quantifies it into a high-probability positive classification. This compression and quantification process not only simplifies sentiment analysis but also provides a clear decision-making basis for dialogue systems. For example, a 95% probability of positive sentiment may trigger the system to generate a positive response, such as "You sound like you're in a good mood today!" In multi-turn dialogues, sentiment polarity analysis can capture dynamic changes in sentiment, such as a shift from positive to neutral, guiding the system to adjust its response strategy.
[0127] Fine-grained emotion category spaces represent more nuanced emotions within different polarity emotional spaces, such as happiness, excitement, anger, sadness, and surprise. This refinement process can reveal deeper emotional states behind dialogue, supporting the generation of more personalized and empathetic responses by the dialogue system.
[0128] Specifically, the emotion probability data P category The calculation method includes the following steps S4a~S4b:
[0129] Step S4a: Calculate the emotion category score corresponding to each polarity emotion space; whereby the emotion category score is labeled z. category,k :
[0130] z category,k = W category · s+ b category ; 1≤k≤K;
[0131] Among them, W category The weight matrix for classifying emotion categories, where s is the global sentiment representation data, and b... category The bias term for classifying emotion categories; k is the category number of the emotion category, and K is the total number of emotion categories;
[0132] Weight matrix W category It is a trainable matrix, where each row corresponds to a weight vector for an emotion category, used to project the vector onto the feature space of that category; the bias term b category W is a K-dimensional vector that provides an adjustable offset for each emotion category. category · s The process is to s The score vector z is generated by mapping from a high-dimensional space to a K-dimensional emotion category space. category =[z happy ,z angry ,z sad ,…,z K Each component z category This indicates the predictive strength of the conversation for the corresponding emotion category. For example, for "I'm very happy today," z happy It may be higher, andz angry and z sad Lower. W category and b category The parameters are optimized during training through supervised learning, using a dialogue dataset labeled with specific emotion categories. The parameters are adjusted using cross-entropy loss to ensure that z... category It can accurately distinguish between different emotion categories.
[0133] Step S4b: Normalize the scores of each emotion category using the softmax function to obtain the probability distribution of each emotion category; whereby the probability distribution of the emotion category is labeled P. category :
[0134] ;
[0135] Y category =[happy,angry,…, category K ];
[0136] P category =[P happy ,P angry ,…,P categoryK ];
[0137] Among them, Y category Indicates the emotion category, k It is the category number of the emotion category. K It represents the total number of emotion categories.
[0138] It should be noted that, in other words, in generating z category Then, the model will z category Transform it into an interpretable probability distribution of emotion categories to quantify the likelihood that a conversation belongs to each emotion category.
[0139] For example, for "I am happy today", suppose z category =[4.8,-1.5,-0.9,0.2,-2.3,-1.0], corresponding to scores for the emotions of happiness, anger, sadness, surprise, fear, and disgust, respectively. The calculation may yield... P category =[0.92,0.01,0.02,0.04,0.01,0.01] indicates that there is a 92% probability that the dialogue belongs to the "happy" category. This probability distribution provides the dialogue system with fine-grained emotion classification results, which can be directly used to guide response generation, such as selecting positive responses that match the "happy" emotion.
[0140] This process is similar to the aforementioned sentiment polarity analysis, but the goal is to refine the coarse-grained positive, negative, and neutral classifications into more specific sentiment categories, increasing the complexity and granularity of the classification.
[0141] The aforementioned sentiment polarity analysis provides the overall sentiment direction of the conversation, such as positive or negative, but it cannot distinguish between "happiness" and "excitement" within positive sentiment, or "anger" and "sadness" within negative sentiment. Then, by mapping to a 3D sentiment space, these subtle differences can be captured. For example, in "I'm very happy today," P category This might indicate that "happiness" is dominant, while in "I finally succeeded," "excitement" might be more likely. This fine-grained classification is crucial for dialogue systems because different emotions require different response strategies: happiness might trigger encouraging responses, such as "That's great!", while sadness might require comforting responses, such as "Don't be sad, I'm here for you."
[0142] Step S5: Using global sentiment representation data, sentiment polarity probability data, and emotion probability data, perform quantitative calculations on sentiment cues in the current dialogue sentence; whereby the sentiment c in the current dialogue sentence is denoted as c; the calculation method for sentiment c includes the following steps S51~S53:
[0143] Step S51: Make a judgment based on the probability distribution corresponding to any obtained emotion category and the preset probability threshold.
[0144] When the probability distribution corresponding to any sentiment category P category,k When the probability is greater than the preset probability threshold δ, that is... P category,k > If δ is reached, proceed to step S52; otherwise, proceed to step S53.
[0145] Step S52: Calculate the sum of attention weights between the attention weights of each word in the current dialogue statement on its overall emotional contribution to the current dialogue statement and its overall emotional contribution to the dialogue history. The context embedding representation of the word corresponding to the word with the maximum value in the obtained attention weight sum is used as the emotional cue. Wherein, any word x in the previous dialogue statement... i The corresponding attention weights and values are labeled as follows Specifically, c=x i i is The corresponding i value;
[0146] Step S53, using the global sentiment representation data as the sentiment cue; wherein, sentiment cue c = s .
[0147] Step S6: Using a large language model based on the current response strategy, the dialogue history, and the obtained sentiment polarity probability data and emotion probability data, a dialogue target is generated. This dialogue target is then encoded using a pre-trained language model encoder. Similarity data representing the sentiment cues and the encoded dialogue target is then calculated. The generated dialogue target is denoted as g, and the encoded dialogue target is denoted as... h g Emotional c and the encoded dialogue target h g Similarity data for matching is labeled R weighted ;
[0148] Specifically, in this embodiment, the similarity data R representing the matching between emotional cues and the encoded dialogue target is... weighted The calculation method includes the following steps S61~S64:
[0149] Step S61: Using a large language model, based on the dialogue history and combined with sentiment polarity probability data and emotion probability data, a dialogue target is generated; whereby this dialogue target is denoted as g:
[0150] G=LLM(D, P polarity , P category ); D={u1,r1,…,u t ,r t};
[0151] Where D represents the dialogue history, u t Let r represent the user input in the t-th round. t Here, t represents the corresponding system response, and t represents the current turn. Assuming the current dialogue is "I'm very happy today" and the history includes phrases like "I was a little sad yesterday" and "System: Hope you're in a better mood today!", the model needs to extract a dialogue target g from these statements that summarizes the direction of the dialogue. First, the dialogue history is... D Format it into a uniform text sequence, for example, by concatenating the content of all rounds and separating different rounds or roles with special tags. For example, the formatted... D The input sequence might be "[CLS] I was a little sad yesterday [SEP] I hope you feel better today! [SEP] I'm very happy today [SEP]". This sequence is then used to generate the dialogue target g using a large language model. After analysis by the large language model, g might be generated as "sharing and discussing the user's current emotional state".
[0152] Step S62: The generated dialogue target is encoded using a pre-trained language model encoder to obtain the encoded dialogue target, and this encoded dialogue target is used as the sentiment representation corresponding to the dialogue target; wherein, the encoded dialogue target corresponding to dialogue target g is denoted as... h g ;
[0153] Step S63: Calculate the cosine similarity between the sentiment c and the obtained encoded dialogue target; where the sentiment c and the obtained encoded dialogue target h are similar. g The cosine similarity between them is denoted as R (c,g):
[0154] ;in, The vector norm representing the emotional c. Indicates the encoded dialogue target h g The vector norm;
[0155] In this embodiment, cosine similarity measures the directional consistency of two vectors in a high-dimensional space, and the calculation process includes the dot product c·h. g (Vector dot product) and normalization term .
[0156] dot product c·h g Quantified c and h g The degree of semantic overlap, for example, the 'c' in "happy" and the 'h' in "provide emotional support". g The dot product may be high because both are correlated with positive sentiment. The normalization term ensures that the similarity value is in the range [-1, 1], with close to 1 indicating high correlation, close to -1 indicating negative correlation, and close to 0 indicating no correlation. For example, if c represents "happy", h... g It means "to provide emotional support". R (c,g) is likely close to 0.8, indicating a strong correlation; if c represents "today", then R (c,g) may be close to 0, indicating low correlation. However, simple cosine similarity cannot distinguish the importance of different types of sentiment cues, so the model introduces a weighting mechanism to perform the weighted calculation in step S64;
[0157] Step S64: The obtained cosine similarity is weighted to calculate the similarity data representing the matching between emotional cues and the encoded dialogue target; wherein, this similarity data is labeled as R. weighted :
[0158] R weighted (c, g)= β·R (c,g);
[0159] Where β is the weighting factor for the ambiguity of the emotional cue; c=h i When c=s, β=β1; when c=s, β=β2; β1 and β2 are the pre-set weight factor values.
[0160] Emotional cues are categorized into two types: "explicit cues" and "vague cues." Explicit cues, such as "anger" in "I feel very angry," directly express the emotional state and have high emotional intensity, thus receiving a higher weighting factor β, for example, β=1.5. Vague cues, such as "not very good" in "My day didn't go well," rely on contextual inference, and their emotional expression is more indirect, therefore receiving a lower β, for example, β=1.0. The choice of the weighting factor β is determined through model learning. For example, in "I'm happy today," the "happy" c is an explicit cue, with β=1.5, and its... R (c,g)=0.8 is amplified to R weighted (c,g)=1.5·0.8=1.2; while the c for "today" is a vague clue, β=1.0, its R (c,g)=0.1 remains unchanged. R weighted (c,g)=0.1. This weighting mechanism ensures that the model prioritizes explicit emotional cues while still considering the contribution of ambiguous cues, thereby dynamically adjusting the focus of strategy generation in multi-turn dialogues.
[0161] Sentiment cue relevance quantification further deepens the results of previous sentiment analysis steps. It aims to support the dialogue system in generating accurate and empathetic response strategies by quantifying the relevance of sentiment cues to the dialogue objective. Steps preceding this one primarily focus on the inherent emotional characteristics of the dialogue, without considering the contextual goals such as user encouragement or problem-solving. Step S6 assesses the degree of match between the sentiment cues expressed in the dialogue and specific dialogue objectives, and dynamically adjusts the priority of different types of sentiment cues through a weighting mechanism. Similarity data (Rweighted) is used to rank the importance of sentiment cues, ensuring the system prioritizes cues most relevant to the dialogue objective.
[0162] Step S7: Utilize the large language model and optimize the response strategy based on the obtained similarity data to generate a personalized empathetic dialogue that matches the user's current dialogue statement; wherein, the personalized empathetic dialogue that matches the user's current dialogue statement is tagged as y. gen Step S7 aims to transform the aforementioned sentiment analysis results into personalized dialogue responses, ensuring that the system can generate empathetic and semantically relevant replies based on the user's emotional state and dialogue goals.
[0163] Specifically, in this embodiment, step S7 integrates the information obtained from the preceding steps, determines whether external knowledge is needed through an adaptive retrieval triggering mechanism, retrieves relevant content through a query generation model, and then, based on the sub-processes of retrieval triggering, query generation, and strategy optimization, ensures that the system can dynamically respond to user needs and improve the quality of emotional interaction in multi-turn dialogues.
[0164] Specifically, in step S7, the method for generating the aforementioned personalized response empathetic dialogue includes the following steps:
[0165] Step S71, calculate the adaptive retrieval trigger value; wherein, this adaptive retrieval trigger value is marked as Trigger:
[0166] Trigger=σ(R weighted (c, h g )+ ɑ · Context_Deficiency);
[0167] Where σ(·) is the Sigmoid activation function, representing the probability of adaptive retrieval being triggered; c represents the sentiment cue. h g This represents the encoded dialogue goal; α is a control parameter, and Context_Deficiency represents the degree of contextual lack in the current dialogue statement, calculated through the sparsity or uncertainty of the dialogue history; for example, if the dialogue history... D Context_Deficiency is high when only short phrases (e.g., "I'm unhappy") lack specific context; it is low when the history is detailed (e.g., "I lost my job and I'm very upset"). Sparsity is estimated by information entropy, while uncertainty is estimated by the sentiment probability P. category The entropy is calculated. The coefficient α controls the weight of the impact of missing context and is determined by hyperparameter tuning.
[0168] sigmoid function The trigger condition is mapped to [0,1], representing the probability of a retrieval being triggered. If the trigger exceeds a threshold, an external retrieval is initiated; otherwise, a response is generated based on the existing context. This mechanism avoids unnecessary retrievals and reduces computational overhead. For example, for "I am happy", a high R... weighted Low Context_Deficiency may result in low Trigger, making retrieval unnecessary.
[0169] Step S72: Make a judgment based on the calculated adaptive retrieval trigger value:
[0170] When the adaptive retrieval trigger value exceeds the set threshold, external knowledge retrieval is triggered to execute step S73; otherwise, step S76 is executed.
[0171] Step S73: Calculate the retrieval query vector using the query decision formula; whereby the retrieval query vector is labeled Retrieval_Query:
[0172] ;
[0173] in, W c Here is the weight matrix for the sentiment c. W hg For the coded dialogue target h g The weight matrix, d represents the weights of c and c. h g Dimensions W r The output weights of the query results; W hg · h g ) T express W hg · h g Transpose of;
[0174] weight matrix W c and W hg c and h g Projecting onto a new semantic space enhances its emotional or target specificity; inner product ( W c ·c) ·( W hg · h g ) T Calculate the similarity between the two in the projection space, and the scaling factor. To prevent the inner product value from becoming too large, the softmax function normalizes the similarity, generating a scalar weight representing c and h g The degree of matching; weight matrix W r The weighted results are mapped to the final retrieval query vector `Retrieval_Query`, used to query external knowledge bases (such as sentiment response templates or knowledge graphs). For example, for c= h happy and h g = Encoder("Providing emotional support"), the query vector may be biased towards retrieving positive response templates. The retrieved results (e.g., "I'm so glad you had a good day!") are fused with the dialogue context and input into the generative model;
[0175] Step S74: Perform external knowledge retrieval based on the obtained retrieval query vector, and input the retrieval results obtained from the external knowledge retrieval into the large language model;
[0176] Step S75: The large language model generates an empathetic dialogue to respond to the user's current dialogue statement based on the retrieval result and the current response strategy.
[0177] Step S76: The large language model jointly generates an empathetic dialogue to respond to the user's current dialogue statement based on the current response strategy.
[0178] In addition, according to actual needs, the adaptive empathic dialogue method based on quantitative sentiment analysis in this embodiment further includes the following steps: after generating the personalized empathic dialogue, it further includes:
[0179] Receive feedback information input by the user; the content of the feedback information input by the user is marked as Feedback;
[0180] The large language model adaptively optimizes and updates its response strategy based on this feedback information;
[0181] The large language model generates dialogue targets for the next conversation based on the real-time updated response strategy. In this embodiment, the large language model updates the response strategy as follows:
[0182] ;
[0183] Where θ' represents the parameters of the large language model after the response policy update, θ represents the parameters of the large language model before the response policy update, and η is the learning rate. The gradient of parameter θ is also the gradient of the loss function L(Feedback, y). gen The vector of partial derivatives of L(Feedback,y) with respect to the parameter θ gen ) is a measure of generating personalized, empathetic dialogues. gen The loss function is the difference between user expectations and user feedback information.
[0184] User feedback (such as "I really liked this response" or "Not very relevant") is quantified as Feedback through explicit actions (such as ratings) or implicit signals (such as continuing the conversation), for example, 1 represents positive feedback and -1 represents negative feedback. The loss function L is the mean squared error, and y is calculated. gen The discrepancy between expectations and user expectations. Gradient. The learning rate η guides the updating of model parameters θ, while the update step size is controlled by the learning rate η. For example, positive feedback reinforces the current policy, while negative feedback adjusts parameters to generate more relevant responses. In multi-turn dialogues, feedback accumulates to optimize the model, learning user preferences, such as a preference for encouraging responses. Feedforward neural networks are used to generate... h T The generation of g using a large language model enhances... s , c , h g The semantic quality of y was indirectly improved. gen The accuracy.
[0185] Compared with existing technologies, the adaptive empathic dialogue method in this embodiment has the following advantages:
[0186] (1) Precise quantitative sentiment cue analysis
[0187] Compared to existing technologies, which often rely on predefined rules or simple emotion classification methods and struggle to capture subtle emotional changes in user expressions, the adaptive empathetic dialogue method in this embodiment introduces a quantitative emotion cue analysis method. This method quantitatively evaluates the relevance of each cue to the target dialogue statement, thereby achieving accurate identification of the user's emotional state. In contrast, existing methods typically lack this fine-grained emotion analysis capability, making it difficult to provide personalized emotional support. Therefore, the adaptive empathetic dialogue method in this embodiment can more efficiently achieve emotional resonance and improve user experience.
[0188] (2) Adaptive retrieval strategy reduces noise introduction
[0189] In Retrieval Enhanced Generation (RAG) technology, existing methods typically employ a uniform retrieval strategy for each user input. This can introduce unnecessary noise or contradictory information when the model's internal knowledge is already sufficient, thereby reducing the accuracy of the system's response. The adaptive empathic dialogue method proposed in this embodiment proposes an adaptive retrieval strategy that dynamically assesses the necessity of external knowledge and retrieves it only when truly needed, effectively reducing the introduction of noise and contradictory information. By analyzing user input content and emotional state in real time and dynamically adjusting the retrieval process, the timeliness and relevance of retrieved information are ensured, significantly optimizing the dialogue generation process and improving the overall performance of the system.
[0190] (3) Real-time processing of emotional dynamics
[0191] The adaptive empathic dialogue method in this embodiment pays special attention to the dynamic processing of emotions during dialogue. It can analyze and respond to changes in user emotions in real time, ensuring that the system can continuously and coherently respond to emotional needs. Traditional dialogue systems often neglect real-time fluctuations in emotions, which are crucial in applications such as emotional support and psychological counseling. This invention combines quantitative emotional cue analysis with an adaptive retrieval strategy to monitor and analyze changes in user emotions in real time, dynamically adjusting dialogue content and strategies to ensure that the system can continuously and coherently respond to user emotional needs and achieve sustained emotional resonance. This solves the problem that existing methods often struggle to achieve such detailed emotional dynamic processing, leading to poor user experience. The adaptive empathic dialogue method in this embodiment not only improves the effect of emotional resonance but also significantly enhances user satisfaction and the system's empathic capabilities, making it widely applicable to multiple fields such as psychological counseling, emotional companionship, and intelligent customer service.
Claims
1. An adaptive empathic dialogue method based on quantitative sentiment analysis, characterized in that, The method comprises the following steps S1-S7: Step S1, receiving a user input dialogue sentence; Step S2, using a pre-trained language model encoder to encode the user input dialogue sentence, to convert the dialogue sentence into a context-related hidden state sequence, and capture the semantics and syntax of each word in the dialogue sentence; Step S3, quantitatively calculating the emotional contribution of each word in the current dialogue sentence to the dialogue history to obtain global emotional representation data; Step S4, mapping the generated global emotional representation data to different polarity emotion spaces to obtain emotion polarity probability data; and mapping the global emotional representation data to a fine-grained emotion category space to obtain emotion probability data; Step S5, using global emotional representation data, emotion polarity probability data, and emotion probability data to quantitatively calculate emotional cues in the current dialogue sentence; Step S6, using a large language model to generate a dialogue target based on the current response strategy, according to the dialogue history, and combining the obtained emotion polarity probability data and emotion probability data, and using a pre-trained language model encoder to encode the dialogue target, and calculating similarity data representing the matching of emotional cues and the encoded dialogue target; Step S7, using a large language model and optimizing the response strategy based on the obtained similarity data to generate a personalized empathetic dialogue that matches the user's current dialogue sentence; wherein: In step S3, the calculation process of the global emotional representation data comprises steps S31-S33: Step S31, calculating an overall emotional tendency representation corresponding to the dialogue history; Step S32, calculating the similarity between the context embedding representation corresponding to each word in the current dialogue sentence sequence and the overall emotional tendency representation, to generate attention weights representing the overall emotional contribution of each word in the current dialogue sentence to the dialogue history; Step S33, calculating the global emotional representation data according to the context embedding representation corresponding to each word and the obtained attention weights; In step S5, the calculation method of the emotional cues is: Step S51, judging the probability distribution corresponding to any emotion category and the preset probability threshold: When the probability distribution corresponding to any emotion category is greater than the preset probability threshold, go to step S52; otherwise, go to step S53; Step S52, calculating the attention weight sum value between the attention weights of each word in the current dialogue sentence to the overall emotional contribution of the current dialogue sentence and the overall emotional contribution of the dialogue history, and taking the context embedding representation corresponding to the word with the maximum attention weight sum value as the emotional cue; Step S53, taking the global emotional representation data as the emotional cue. 2.The adaptive empathic dialogue method based on quantitative sentiment analysis of claim 1, wherein, After generating the personalized empathetic dialogue, it further comprises: Receiving user input feedback information; The large language model self-adaptively optimizes and updates the response strategy based on the feedback information; The large language model generates a dialogue target for the next dialogue based on the real-time updated response strategy. 3.The adaptive empathic dialogue method based on quantitative sentiment analysis of claim 1 or 2, wherein, In step S2, the process of encoding the user input dialogue sentence using the pre-trained language model encoder includes steps S21-S22 as follows: Step S21, using the self-built tokenizer of the pre-trained language model encoder to tokenize the dialogue sentence to obtain a dialogue sentence sequence; Step S22, using the pre-trained language model encoder to encode the obtained dialogue sentence sequence to obtain a set of hidden state sequences. 4.The adaptive empathic dialogue method based on quantitative sentiment analysis of claim 3, wherein, After step S2 is executed, the attention weight representing the contribution of each word in the current dialogue sentence to the overall sentiment of the current dialogue sentence is calculated; wherein the calculation process of the attention weight includes the following steps: Step Sa, calculating the sentiment tendency representation of the current sentence through the feedforward neural network in the pre-trained language model encoder; Step Sb, based on the adaptive attention mechanism in the pre-trained language model encoder, calculating the similarity between the context embedding representation corresponding to each word in the current dialogue sentence sequence and the sentiment tendency representation, and generating the attention weight corresponding to each word.
5. The adaptive empathic conversational method based on quantitative emotional analysis according to claim 4, characterized in that, In step S4, the different polarity sentiment spaces include positive sentiment space, negative sentiment space and neutral sentiment space; wherein: The calculation method of the sentiment polarity probability data includes steps S41 and S42 as follows: Step S41, calculating the sentiment polarity score corresponding to each polarity sentiment space; Step S42, using the softmax function to normalize each obtained sentiment polarity score to obtain the sentiment polarity probability distribution mapped to each polarity sentiment space; The calculation method of the emotion probability data includes steps S4a and S4b as follows: Step S4a, calculating the emotion category score corresponding to each polarity sentiment space; Step S4b, using the softmax function to normalize each obtained emotion category score to obtain the probability distribution of each emotion category.
6. The adaptive empathic conversational method based on quantitative emotional analysis according to claim 5, characterized in that, In step S6, the calculation method of the similarity data representing the matching of the sentiment clues and the encoded dialogue target includes steps S61-S64 as follows: Step S61, using the large language model to generate a dialogue target according to the dialogue history and combining the sentiment polarity probability data and the emotion probability data; Step S62, using the pre-trained language model encoder to encode the generated dialogue target to obtain an encoded dialogue target, and taking the encoded dialogue target as the sentiment tendency representation corresponding to the dialogue target; Step S63, calculating the cosine similarity between the sentiment clues and the obtained encoded dialogue target; Step S64, weighting the obtained cosine similarity to obtain the similarity data representing the matching of the sentiment clues and the encoded dialogue target.
Citation Information
Patent Citations
Robot emotion response method based on attention neural network
CN116341568A
Power grid customer service co-emotional dialogue reply generation method based on emotion subtle perception
CN117591648A