Dialogue-level sentiment analysis method based on multi-scale sliding window and dynamic aggregation
By adopting multi -scale sliding windows and dynamic aggregation technology in dialogue -level emotional analysis, the traditional method is difficult to capture multiple rounds of conversation information information, realize more accurate conversation emotional predictions, and maintain an efficient and simple model structure.
Patent Information
- Application Number
- CN202410273102.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-03-11
- Publication Date
- 2025-01-24
- Estimated Expiration
- 2044-03-11
AI Technical Summary
Traditional sentiment analysis techniques are difficult to effectively capture semantic interactions and rich contextual information in multiple rounds of conversations, especially in conversation-level sentiment analysis.
Adopt a dialogue -level emotional analysis method based on multi -scale sliding windows and dynamic aggregation. By constructing a dialogue tree and using a pre -training language model to encode the multi -scale discourse window, the output distribution of the dynamic aggregation multi -scale window sex.
This method can effectively capture the multi -scale context information from a single discourse to the entire dialogue range, improve the accuracy of dialogue emotional prediction, and does not need to design complex neural network structures, maintaining efficient and accurate emotional analysis.
Smart Images

Figure CN118132710B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of natural language processing, and in particular to a conversation-level sentiment analysis method based on multi-scale sliding windows and dynamic aggregation. Background Art
[0002] Sentiment analysis has received increasing attention in recent years. There are coarse-grained document-level sentiment analysis and aspect-based sentence-level sentiment analysis. With the development and application of dialogue tasks, the scope of sentiment analysis has also expanded to the dialogue level, aiming to reflect more realistic dialogue-driven user review scenarios. Traditional research faces the challenge of capturing semantic interactions and rich contextual information in multi-round dialogues. Summary of the invention
[0003] The purpose of the present invention is to provide a conversation-level sentiment analysis method based on multi-scale sliding windows and dynamic aggregation, which can improve the prediction effect of sentiment analysis in multi-round conversations without designing a complex network.
[0004] To achieve the above purpose, the technical solution adopted by the present invention is as follows:
[0005] A conversation-level sentiment analysis method based on multi-scale sliding windows and dynamic aggregation includes the following steps:
[0006] S1: Construct a dialogue tree based on the dialogue structure of the comment data. Each tree branch is a dialogue thread. A multi-scale discourse window is constructed for each dialogue thread through a sliding window.
[0007] S2: Use the pre-trained language model to encode the multi-scale discourse window and obtain the multi-scale discourse window feature representation;
[0008] S3: Input the multi-scale speech window feature representation into the dialogue sentiment prediction model for prediction, and dynamically aggregate the prediction results of the generated multi-scale speech windows;
[0009] S4: In the training phase, the comment data with real labels is processed through steps S1 to S3, and the dialogue sentiment prediction model is trained and optimized by using multi-task learning with the minimum total loss at the window level, thread level, and dialogue level as the training goal;
[0010] S5: During the use phase, the target comment data is processed through steps S1 to S3, wherein the dialogue sentiment prediction model is the model trained in step S4, and a dialogue-level sentiment prediction result is generated.
[0011] Furthermore, in step S1, a dialogue tree is constructed based on the speaker and reply relationship of each conversation in the comment data set, the value of the tree node is the speaker information, and the connection between the nodes is the reply relationship with time sequence information.
[0012] Furthermore, in step S1, for each conversation thread, a sliding window of variable size is used to generate a subset of continuous utterances from the thread, namely, the utterance window.
[0013] Furthermore, the relationship between the discourse window and the number of sentences is: for a conversation thread with n sentences, we can generate A speech window.
[0014] Furthermore, the step of encoding the multi-scale utterance window using the pre-trained language model in step S2 includes:
[0015] Add marker tokens before and after several sentences in each sliding window to mark the start and end positions;
[0016] The RoBERTa encoder is used to encode each utterance window to obtain a multi-scale window feature representation.
[0017] Furthermore, the Chinese dataset uses the RoBERTa-Chinese-wmt model, and the English dataset uses the RoBERTa-Large model.
[0018] Furthermore, the dialogue emotion prediction model in step S3 mainly includes a multi-layer perceptron, a softmax function and a dynamic hierarchical aggregation module.
[0019] Furthermore, the specific processing steps of the dialogue emotion prediction model in step S3 include:
[0020] The multi-scale utterance window feature representation is processed by a multi-layer perceptron and multiplied by features to generate a predicted distribution value;
[0021] The predicted distribution values of the multi-scale discourse windows in each conversation thread are dynamically iterated and aggregated through the dynamic hierarchical aggregation module, from small windows to large windows, until the predicted distribution values of the thread-level windows are obtained;
[0022] Aggregate the predicted distribution values of each thread-level window to obtain the predicted distribution value of the conversation level;
[0023] The predicted distribution value of the dialogue level is processed by the softmax function to generate the dialogue level emotion prediction result.
[0024] Furthermore, during the training phase, the specific processing steps of the conversation emotion prediction model include:
[0025] The multi-scale window feature representation of the training data with real labels is passed through a multi-layer perceptron and feature product to generate a predicted distribution value, which is processed by a softmax function to generate a window-level sentiment prediction result;
[0026] Calculate the credibility score of each utterance window based on the window-level sentiment prediction results and the true label;
[0027] The predicted distribution values of the discourse windows in each conversation thread are dynamically iterated and aggregated based on the above-mentioned credibility scores, from small windows to large windows, until they are aggregated to a window of the thread size, to obtain the predicted distribution value of the thread-level window;
[0028] Calculate the credibility score of each thread based on the window-level sentiment prediction results, the true label, and the number of conversation windows;
[0029] According to the predicted distribution value of the thread-level window and the trust score of each thread, the predicted distribution value of the conversation level is obtained by selective aggregation;
[0030] The predicted distribution value of the dialogue level is processed by the softmax function to generate the dialogue level emotion prediction result.
[0031] Furthermore, the real labels include tgt, asp, opi, h2h, t2t, positive, negative and other; among them, in word entity boundary detection, labels tgt, asp and opi are used to represent the head and tail relations of target, aspect and opinion items between any two respectively; in entity relationship pair detection, labels h2h and t2t are used to align the head and tail tags between two types of entities; in sentiment polarity detection, sentiment label sets positive, negative and other are used.
[0032] Furthermore, the calculation step of the total loss in step S4 includes:
[0033] The loss of each dialogue window is calculated using the cross entropy loss function;
[0034] The cross entropy loss function is used to calculate the loss of each conversation thread after aggregation;
[0035] Use the cross entropy loss function to calculate the loss of the entire conversation after aggregation;
[0036] The above three losses are added according to the preset weights to get the total loss.
[0037] Furthermore, the dialogue-level sentiment prediction result is a sentiment quadruple consisting of four elements: target, aspect, opinion word, and sentiment polarity.
[0038] The beneficial effects achieved by the present invention are as follows: ① By creating a sliding window of variable size, multi-scale context information from a single utterance to the entire conversation can be captured, which helps to fully capture the conversation context; windows of different scales capture different information, smaller windows focus on local details, and larger windows emphasize context understanding. ② By dynamically aggregating the output distribution of multi-scale windows, the accuracy of conversation sentiment quadruple prediction is improved, promoting the context interaction of the conversation, without the need to build a complex neural network structure, while maintaining efficient and accurate sentiment analysis. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] Figure 1 This is a flow chart of a conversation sentiment analysis method based on multi-scale sliding windows and dynamic aggregation.
[0040] Figure 2 This is a principle framework diagram of a conversation sentiment analysis method based on multi-scale sliding windows and dynamic aggregation.
[0041] Figure 3 Generate schematics for multi-scale sliding windows.
[0042] Figure 4 This is a schematic diagram of dynamic aggregation. DETAILED DESCRIPTION
[0043] In order to make the various technical features and advantages or technical effects in the above technical solutions of the present invention more obvious and easy to understand, they are described in detail below with reference to the accompanying drawings.
[0044] Figure 1 This is a flow chart of a method for conversation sentiment analysis based on multi-scale sliding windows and dynamic aggregation proposed in an embodiment of the present invention. The method includes the following main steps:
[0045] S1: Construct a dialogue tree based on the dialogue structure of the comment data. Each tree branch is a dialogue thread, and discourse windows of different scales are constructed through sliding windows.
[0046] S2: Use the pre-trained language model to encode discourse windows of different scales to obtain multi-scale discourse window feature representation.
[0047] S3: Input the multi-scale speech window feature representation into the dialogue sentiment prediction model for prediction, and dynamically aggregate the prediction results of the generated multi-scale speech windows.
[0048] S4: During the training phase, the comment data with real labels is processed through steps S1 to S3, and the dialogue sentiment prediction model is trained and optimized using multi-task learning with the minimum total loss at the window level, thread level, and dialogue level as the training goal.
[0049] S5: During the use phase, the target comment data is processed through steps S1 to S3, wherein the dialogue sentiment prediction model is the model trained in step S4, and a dialogue-level sentiment prediction result is generated.
[0050] Figure 2 Schematic diagram of the principle framework of the conversation sentiment analysis method based on multi-scale sliding window and dynamic aggregation provided by an embodiment of the present invention, in which u represents a sentence, w represents a window, and n represents a i represents the total number of words in the i-th thread, Indicates size n i The sum of the cross entropy loss values of the windows, represents the cross entropy loss value of the nth thread, L d represents the cross entropy loss value of the entire conversation, and f represents the window aggregation algorithm. The following is a detailed description of the specific implementation of this method:
[0051] For step S1, Figure 3 The schematic diagram of generating a multi-scale sliding window provided in the example of the present invention includes the following specific steps:
[0052] S101: Based on the relationship between the speaker and the reply in each conversation in the microblog comment dataset, a dialogue tree is constructed, where the value of the tree node is the speaker information, and the connection between the nodes is the reply relationship with time sequence information.
[0053] S102: Each branch of the tree is regarded as a conversation thread. There is a direct reply relationship between each adjacent node in the thread. Different threads (branches) can be regarded as independent of each other.
[0054] S103: Use sliding windows to construct multi-scale discourse windows for each thread. For each conversation thread, a sliding window of variable size is used to generate a continuous discourse subset (called a discourse window) from the thread. A conversation thread with n sentences can generate N w Speech windows:
[0055]
[0056] For step S2, the specific steps of generating the multi-scale utterance window feature representation include:
[0057] S201: For each sentence u j The tokens [CLS] and [SEP] are added before and after the content of the speech window to mark the start and end positions.
[0058]
[0059] in is the final input of the wth utterance window in the tth thread, and k represents the number of sentences that make up the utterance window.
[0060] S202: Encode each speech window using the RoBERTa encoder to obtain the speech window feature representation Since the sizes of each utterance window are different and there are multiple scales, a multi-scale utterance window feature representation is obtained. The Chinese dataset uses the RoBERTa-Chinese-wmt model, and the English dataset uses the RoBERTa-Large model.
[0061]
[0062]
[0063] Where N w is the total number of words in the conversation, and h represents the word feature.
[0064] For step S3, the dialogue sentiment prediction model mainly includes a multi-layer perceptron, a softmax function, and a dynamic hierarchical aggregation module. Figure 4 For the dynamic aggregation diagram, the specific steps of the training phase include:
[0065] S301: In the dialogue sentiment prediction model training phase, training data with true labels τ are required to be processed in the above steps and then input into the model. In word entity boundary detection, labels tgt, asp and opi are used to represent the head and tail relationships of the target, aspect and opinion items between any two, respectively. In entity relationship pair detection, labels h2h and t2t are used to align the head and tail tags between two types of entities. In sentiment polarity detection, sentiment labels positive, negative and other are used. When the model is officially used, it is not necessary to label the comment data to be processed.
[0066] S302 obtains the utterance window features Each word feature h in i , through multi-layer perceptron MLP processing and feature product, the predicted distribution value is obtained Then processed by the softmax function Get window-level sentiment prediction results The calculation formula involved in this step is as follows:
[0067]
[0068]
[0069]
[0070]
[0071]
[0072]
[0073] where τ∈{tgt,asp,opi,h2h,t2t,positive,negative,other}, and b τ is the weight matrix; [·; ·] represents the vector concatenation operation.
[0074] S303: Calculate the credibility score CS of each utterance window according to the sentiment prediction result p and the true label value y of the true label τ. The dynamic hierarchical aggregation module calculates the predicted distribution value S = ∑s of all utterance windows in each conversation thread. ij Based on the window's trust score CS, dynamic iterative aggregation is performed, from small windows to large windows, until the predicted distribution value of the thread-level window is obtained. The trust score calculation formula is as follows:
[0075] CS=-CrossEntropy(p,y)
[0076] Among them, the credible score CS is the negative value of the cross entropy loss function between the sentiment prediction result p and the corresponding true label value y.
[0077] S304: Similarly, the credibility score of each thread is calculated, and the predicted distribution value of each thread-level window is aggregated according to the credibility score of each thread, and finally the aggregated dialogue-level predicted distribution value R is obtained. R is processed by the softmax function to obtain the dialogue-level emotion prediction result P. The calculation formula of the aggregated dialogue-level predicted distribution value R is as follows:
[0078]
[0079]
[0080]
[0081] in, is the vector addition symbol, is a thread-level window W containing l sentences i The predicted distribution value of . γ is the preset parameter. for In the thread-level window W i The predicted distribution value subset of the overlapping sentences, y is the true label value, is an intermediate variable.
[0082] For step S4, it is necessary to construct window-level, thread-level, and conversation-level loss functions, and then obtain the total loss. The steps include:
[0083] S401: Use the cross entropy loss function to calculate the loss L of each window w :
[0084]
[0085] Among them, |W| is the number of sentences contained in a single window, N w is the length of the wth sentence; y ij represents the true label value; p ij It is the sentiment prediction result; the log base is not limited.
[0086] S402: Use the cross entropy loss function to calculate the loss L of each thread after aggregation t :
[0087]
[0088] Among them, |T| is the sum of sentences in all windows of the thread, N t is the length of the sentence.
[0089] S403: Use the cross entropy loss function to calculate the loss L of the entire conversation after aggregation d :
[0090]
[0091] Where N is the number of tokens in the entire conversation.
[0092] S404: The above three losses are added according to the set weights to obtain the total loss, and the minimum total loss is used as the overall optimization goal.
[0093] L total =L d +L t +L w
[0094] Among them, L total is the total loss function.
[0095] For step S5, when it is officially used, the trained dialogue sentiment prediction model is used to predict the sentiment of the target comment data, and a dialogue-level sentiment prediction result is generated. The dialogue-level sentiment prediction result is a sentiment quadruple composed of four elements: target, aspect, opinion word, and sentiment polarity. Among them, when it is officially used, the multi-scale discourse window feature representation must be processed by step S3, but because the real label is no longer needed, the trust score does not need to be calculated, and the dynamic aggregation final prediction of the discourse window can be directly performed.
[0096] Experimental test:
[0097] The present invention experiments with the method of the present invention and the current most advanced method (baseline model) on two public datasets based on Weibo comment data. In order to quantitatively evaluate the prediction results of the emotional dialogue quadruple, micro-F1 and Identification-F1 are used as evaluation indicators. The test results are shown in Table 1.
[0098] Table 1 Model performance test results
[0099]
[0100] The results in Table 1 show that the method of the present invention is significantly better than the current most advanced methods in the emotion quadruple extraction tasks on the two datasets, which proves the superiority of the method of the present invention.
[0101] Although the present invention has been disclosed as above by way of embodiments, it is not intended to limit the present invention. Appropriate modifications or equivalent substitutions of the technical solutions of the present invention made by ordinary technicians in the field should all be included in the protection scope of the present invention. The protection scope of the present invention shall be based on what is defined in the claims.
Claims
1. A conversation-level sentiment analysis method based on multi-scale sliding windows and dynamic aggregation, characterized in that: The following steps are involved: S1: Based on the speaker and reply relationship of each conversation in the comment dataset, a dialogue tree is constructed. The value of the tree node is the speaker information, and the connection between the nodes is the reply relationship with time sequence information. Each tree branch is a dialogue thread. A continuous discourse subset is generated for each dialogue thread through a sliding window of variable size to construct a multi-scale discourse window. S2: Use the pre-trained language model to encode the multi-scale discourse window and obtain the multi-scale discourse window feature representation; S3: Input the multi-scale speech window feature representation into the dialogue sentiment prediction model for prediction, and dynamically aggregate the prediction results of the generated multi-scale speech windows; S4: In the training phase, the comment data with real labels is processed through steps S1 to S3, and the dialogue sentiment prediction model is trained and optimized by using multi-task learning with the minimum total loss at the window level, thread level, and dialogue level as the training goal; S5: During the use phase, the target comment data is processed by steps S1 to S3, and then input into the dialogue sentiment prediction model trained by step S4 to generate a dialogue-level sentiment prediction result, i.e., a sentiment quadruple consisting of the four elements of target, aspect, opinion word, and sentiment polarity.
2. The method according to claim 1, characterized in that The relationship between the discourse window and the number of sentences in step S1 is: for a conversation thread with n sentences, A speech window.
3. The method according to claim 1, characterized in that The step of encoding the multi-scale utterance window using the pre-trained language model in step S2 includes: Add marker tokens before and after several sentences in each sliding window to mark the start and end positions; The RoBERTa encoder is used to encode each utterance window to obtain a multi-scale window feature representation.
4. The method according to claim 1, characterized in that The dialogue emotion prediction model in step S3 mainly includes a multi-layer perceptron, a softmax function, and a dynamic hierarchical aggregation module.
5. The method according to claim 4, characterized in that The specific processing steps of the dialogue emotion prediction model in step S3 include: The multi-scale utterance window feature representation is processed by a multi-layer perceptron and multiplied by features to generate a predicted distribution value; The predicted distribution values of the multi-scale discourse windows in each conversation thread are dynamically iterated and aggregated through the dynamic hierarchical aggregation module, from small windows to large windows, until the predicted distribution values of the thread-level windows are obtained; Aggregate the predicted distribution values of each thread-level window to obtain the predicted distribution value of the conversation level; The predicted distribution value of the dialogue level is processed by the softmax function to generate the dialogue level emotion prediction result.
6. The method according to claim 4, characterized in that During the training phase, the specific processing steps of the dialogue sentiment prediction model include: The multi-scale window feature representation of the training data with real labels is passed through a multi-layer perceptron and feature product to generate a predicted distribution value, which is processed by a softmax function to generate a window-level sentiment prediction result; Calculate the credibility score of each utterance window based on the window-level sentiment prediction results and the true label; The predicted distribution values of the discourse windows in each conversation thread are dynamically iterated and aggregated based on the above-mentioned credibility scores, from small windows to large windows, until they are aggregated to a window of the thread size, to obtain the predicted distribution value of the thread-level window; Calculate the credibility score of each thread based on the window-level sentiment prediction results, the true label, and the number of conversation windows; According to the predicted distribution value of the thread-level window and the trust score of each thread, the predicted distribution value of the conversation level is obtained by selective aggregation; The predicted distribution value of the dialogue level is processed by the softmax function to generate the dialogue level emotion prediction result.
7. The method according to claim 6, characterized in that The real labels include tgt, asp, opi, h2h, t2t, positive, negative and other; among them, in word entity boundary detection, the labels tgt, asp and opi are used to represent the head and tail relationship of the target, aspect and opinion items between any two respectively; in entity relationship pair detection, the labels h2h and t2t are used to align the head and tail tags between two types of entities; in sentiment polarity detection, the sentiment label sets positive, negative and other are used.
8. The method according to claim 1, characterized in that The calculation steps of the total loss in step S4 include: The loss of each dialogue window is calculated using the cross entropy loss function; The cross entropy loss function is used to calculate the loss of each conversation thread after aggregation; Use the cross entropy loss function to calculate the loss of the entire conversation after aggregation; The above three losses are added according to the preset weights to get the total loss.
Citation Information
Patent Citations
Aspect-level emotion tetrad extraction method and system based on tree structure information perception
CN117312559A