A method and system for sentiment analysis of microblog comment dialogues based on graph neural network
Through the graph neural network method, the dialogue tree and syntactic graph are integrated to model dialogue sentiment analysis, which solves the problem of traditional methods ignoring syntactic details and semantic relationships, and achieves a deep understanding of complex dialogue emotions and a more accurate prediction effect.
Patent Information
- Application Number
- CN202410221099.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-02-28
- Publication Date
- 2024-12-17
- Estimated Expiration
- 2044-02-28
AI Technical Summary
Traditional dialogue emotion analysis methods ignore syntactic details within discourse and the fine-grained semantic relationship between discourse, resulting in limitations in understanding deep emotional dynamics in complex dialogue.
Using a graph neural network-based method, by constructing dialogue trees and syntactic graphs, using graph convolution neural network to model syntactic information of comments, and using graph attention neural network to model semantic information between comments, fusing syntactic and semantic features, The characteristic representation of the conversation is generated and finally input into the dialogue emotion prediction model for prediction.
It significantly improves the prediction effect of dialogue-level emotion analysis, can more accurately understand and analyze emotional information in complex dialogue scenarios, and promotes the development of dialogue-emotional quadruple tasks.
Smart Images

Figure CN118228733B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the fields of natural language processing and graph neural networks, and in particular to a sentiment analysis method and system applied to a dialogue scenario consisting of multiple rounds of utterances. Background Art
[0002] With the popularity of dialogue systems and chatbots, dialogue-level sentiment analysis has become a hot topic. Traditional research mainly focuses on analyzing the coarse-grained relationship between utterances, ignoring the syntactic details within utterances and the fine-grained semantic relationship between utterances, resulting in limitations in understanding the deep emotional dynamics in complex dialogues. Summary of the invention
[0003] The purpose of the present invention is to provide a method and system for analyzing the sentiment of microblog comment dialogues based on graph neural networks, which integrates syntax and semantics to more comprehensively capture and analyze the sentiment in dialogues. It not only focuses on the relationship between discourses, but also deeply explores the syntactic structure within discourses, so as to more accurately understand and analyze the sentiment information in complex dialogue scenarios and improve the prediction effect of dialogue-level sentiment analysis.
[0004] To achieve the above purpose, the technical solution adopted by the present invention is as follows:
[0005] A method for sentiment analysis of microblog comment dialogues based on graph neural networks includes the following steps:
[0006] S1: Obtain Weibo comment data and construct a dialogue tree. Each branch of the dialogue tree is regarded as a thread. The comments and threads are encoded using an encoder to generate the encoded representation of the discourse and the features of the dialogue thread.
[0007] S2: Use graph convolutional neural networks to model the syntactic information of comments and generate a syntactic representation of the entire conversation;
[0008] S3: Use graph attention neural network to model the semantic information between comments, generate and update the enhanced representation of speaker perception and discourse structure perception;
[0009] S4: The above-mentioned conversation thread features, the syntactic representation of the entire conversation, the updated enhanced representation of speaker perception and the enhanced representation of discourse structure perception are fused to obtain conversation features; the conversation features are input into the trained conversation sentiment prediction model for prediction to generate conversation sentiment prediction results for microblog comments.
[0010] Furthermore, in step S1, a RoBERTa encoder is used for encoding.
[0011] Furthermore, the step of using the graph convolutional neural network to model the syntactic information of the review in step S2 includes:
[0012] Perform part-of-speech dependency analysis on each comment to generate part-of-speech tags and syntactic dependencies of the words in the comment;
[0013] Obtain word embeddings of part-of-speech tags through the Word2Vec model to obtain a learnable continuous embedding vector;
[0014] The BiLSTM model is used to process continuous embedding vectors to obtain part-of-speech feature representations with rich contextual information;
[0015] Construct a syntactic graph, where the vertices are initialized by part-of-speech feature representations and the edges are initialized by the syntactic dependency matrix;
[0016] According to the syntactic graph, the syntactic dependency and part-of-speech feature representation are integrated through the graph convolutional neural network to obtain the syntactic feature representation of the comment;
[0017] Integrate the syntactic feature representations of all comments to obtain the syntactic representation of the entire conversation.
[0018] Furthermore, SpaCy tool is used to perform part-of-speech analysis and dependency analysis on each comment.
[0019] Furthermore, the step of using the graph attention neural network to model the semantic information between comments in step S3 includes:
[0020] Construct a speaker-perceived graph, where the utterance nodes of the graph are initialized by the encoded representation of the utterance, and the edges of the graph represent the relationship between the speaker and the utterance nodes;
[0021] Based on the speaker-aware graph, a graph attention neural network is used to capture speaker-aware contextual information and generate speaker-aware enhanced representations.
[0022] Construct a discourse structure-aware graph, where the vertices of the graph are initialized by the encoded representation of the discourse, and the edges of the graph represent the structural relationships between discourses;
[0023] Based on the discourse structure-aware graph, a graph attention neural network is used to capture the dialogue structure information and generate discourse structure-aware enhanced representations.
[0024] The enhanced representation of speaker perception and the enhanced representation of discourse structure perception are semantically integrated through an interactive module to obtain an updated feature representation.
[0025] Furthermore, the relationship types of the edges of the speaker-aware graph include self-loop, same speaker-previous, same speaker-next, different speaker-previous, and different speaker-next.
[0026] Furthermore, the relationship types of the edges of the discourse structure-aware graph include self-loop, reply relationship-before, reply relationship-after, thread relationship-before and thread relationship-after.
[0027] Furthermore, the step of performing feature fusion in step S4 includes:
[0028] The syntactic representation of the entire conversation, the updated speaker-aware enhanced representation, and the discourse structure-aware enhanced representation are expanded to the same dimension, concatenated, and processed through a linear layer;
[0029] The features processed by the linear layer are concatenated with the conversation thread features to obtain the conversation features.
[0030] Furthermore, in step S4, the conversation emotion prediction model is composed of a multi-layer perceptron MLP and a softmax function. During prediction, the conversation features are input into the trained multi-layer perceptron MLP for processing to generate intermediate variables.
[0031] The intermediate variables are transformed and multiplied from column vectors to matrix vectors, and then decoded through the softmax function to generate the conversation emotion prediction results.
[0032] Furthermore, the multi-layer perceptron MLP is trained by microblog comment data containing known tags, and the cross entropy loss function is calculated according to the tags and the prediction results, and AdamW is used as the optimizer to optimize the model parameters with the goal of minimizing the loss.
[0033] Furthermore, the dialogue sentiment prediction result is a sentiment quadruple consisting of four elements: target, aspect, opinion word, and sentiment polarity.
[0034] A microblog comment dialogue sentiment analysis system based on graph neural network, including:
[0035] A feature extraction module is used to encode microblog comments and threads using an encoder to generate encoded representations of discourse and conversation thread features;
[0036] The syntactic modeling module is used to model the syntactic information of comments using graph convolutional neural networks and generate the syntactic representation of the entire conversation;
[0037] The semantic modeling module is used to use the graph attention neural network to model the semantic information between comments, generate and update the enhanced representation of speaker perception and discourse structure perception;
[0038] The fusion decoding module is used to fuse the features of the conversation thread, the syntactic representation of the entire conversation, the updated enhanced representation of speaker perception and the enhanced representation of discourse structure perception to obtain the conversation features; the conversation features are input into the trained conversation sentiment prediction model for prediction to generate the conversation sentiment prediction results of Weibo comments.
[0039] The advantages of the present invention are as follows: the present invention models the syntactic information of comments and provides structural feature information within the discourse; the present invention uses speaker information and the structure between discourses to enrich the semantic information between discourses and promote the contextual interaction of dialogues. The effects of the present invention on two public microblog datasets have been significantly improved, promoting the development of dialogue sentiment quadruple tasks. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] Figure 1 A flow chart of a method for conversation sentiment analysis based on a graph neural network provided in an embodiment of the present invention.
[0041] Figure 2 A schematic diagram of the microblog comment data structure provided by an embodiment of the present invention.
[0042] Figure 3 A framework diagram of a conversation sentiment analysis system based on a graph neural network provided in an embodiment of the present invention.
[0043] Figure 4 Schematic diagram of a semantic dual graph attention neural network provided for an embodiment of the present invention. DETAILED DESCRIPTION
[0044] 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.
[0045] Figure 1 This is a flow chart of a method for analyzing conversational sentiment based on a graph neural network proposed in an embodiment of the present invention. Figure 2 A schematic diagram of the microblog comment data structure provided by an embodiment of the present invention. The method comprises the following steps:
[0046] S1: Using the Weibo comment dataset, construct a dialogue tree for each group of comments, and use the pre-trained model RoBERTa as the encoder to encode the comment text and comment thread to obtain the basic word vector representation of the text.
[0047] S101: Obtain a Weibo comment dataset. The dataset contains 7452 comments, which form a total of 1000 groups of comment dialogues. The dataset, validation set, and test set are divided in a ratio of 8:1:1. The average number of speakers in each dialogue in the dataset is 5, and it contains an average of about 6 groups of sentiment quadruplets.
[0048] S102: Use the speaker information and reply information provided in the data set to construct a dialogue tree. Each branch of the tree is a thread T t , threads can be considered independent of each other.
[0049] S103: Use RoBERTa encoder to convert the dialogue D = {u1, u2, ..., u n}, each comment is encoded independently to obtain the encoded representation of the discourse:
[0050] h i =RoBERTa(u i )
[0051] S104: Use the RoBERTa encoder to independently encode each thread to obtain the conversation thread features:
[0052] g i =RoBERTa(T i )
[0053] Among them, RoBERTa-Chinese and RoBERTa-Large encoders are used for Chinese and English datasets respectively.
[0054] S2: Modeling syntactic information within reviews using a single graph convolutional neural network.
[0055] S201: First, use the Spacy tool to generate a i Comments i Perform syntactic analysis (i.e., part-of-speech analysis and dependency analysis) to obtain the part-of-speech tags of the words in the comments {p i} and the syntactic dependency matrix a ij is the dependency label between words.
[0056] S202: Pass the part-of-speech tags through the Word2Vec model to obtain a learnable continuous embedding vector:
[0057]
[0058] S203: In order to obtain rich context information, the continuous embedding vector Through Bi-LSTM network processing, the part-of-speech feature representation with rich contextual information is obtained:
[0059]
[0060] S204: Construct a syntactic graph G syn =(V syn ,E syn), which is used to integrate the part-of-speech feature representation and syntactic dependency. syn is the vertex set of the graph, represented by the part-of-speech feature c i Initialization is obtained; E syn is an edge set, represented by the syntactic dependency matrix A syn Initialization is obtained. After the comments are processed by the lth layer of graph convolution (GCN), the syntactic feature representation of the comments is obtained:
[0061]
[0062] Where W l , b l is the weight parameter of the lth layer, and By c i Initialized.
[0063] Finally, we can get the syntactic representation of the entire conversation
[0064] S3: Use dual graph attention neural network to model the semantic information between microblog comments. Construct speaker-aware graph attention SpkGAT module and discourse structure-aware graph attention StructureGAT. And use the interaction module to merge and update these two types of information.
[0065] S301: First, construct the speaker-perceived graph G spk =(V spk ,E spk ), node set V spk represents the set of utterances in the conversation, and the representation of these nodes is represented by the encoding of the utterance h i Initialization. Edge E spk Represents the relationship between the speaker and the utterance node. The edge relationship types include: self-loop, same speaker-before, same speaker-after, different speaker-before, different speaker-after. Same speaker means that the two sentences are issued by the same speaker. Before and after represent the time relationship between utterances. Self-loop is used to define the diagonal of the graph.
[0066] Based on the speaker-aware graph, a graph attention neural network is used to propagate and aggregate speaker-aware contextual information to generate speaker-aware enhanced representations:
[0067]
[0068] Where W i , W j , W k and a T is a trainable parameter, σ is the LeakyReLU activation function, It is the vertex at the i-th position in the vertex set, that is, the adjacent set of node i.
[0069] S302: Constructing a graph G for discourse structure perception str =(V str ,E str ), node set V str Represents the discourse structure in the conversation. The representation of these nodes is represented by the encoding of the discourse h i Initialization. Edge E str Represents the structural relationship between discourses, including 5 types of relationships: self-loop, reply relationship-before, reply relationship-after, thread relationship-before, thread relationship-after. Based on the discourse structure-aware graph, the enhanced representation of discourse structure awareness is obtained after processing with the graph attention neural network The specific process is similar to that of S301.
[0070]
[0071] Where W i , W j , W k and a T is a trainable parameter, σ is the LeakyReLU activation function, V str The adjacency set of the i-th vertex.
[0072] S303: The two enhanced representations obtained in S301 and S302 are After the interaction module integrates the semantics, the updated feature representation is obtained:
[0073] H spk′ =softmax(H str W1(H str ) T )H spk
[0074] H str′ =softmax(H str W2(H spk ) T )H str
[0075] Where W1 and W2 are trainable parameters.
[0076] S4: The features obtained from S1, S2 and S3 are fused using the fusion module to obtain features with rich syntax and semantics. Finally, the emotion quadruple result is obtained by decoding the dialogue emotion prediction model decoding matrix.
[0077] S401: Feature fusion: First, the dimensions of the syntactic features and the two semantic features are expanded to the same dimension, and then these three features are concatenated and passed through a linear layer, and finally combined with the basic conversation thread feature G obtained in S1 = {g i} to obtain the conversation feature H containing rich information D :
[0078]
[0079] S402: Using the enhanced conversation feature to represent H D To calculate the score of each word pair, according to the relationship type, these features are processed by a label-specific multi-layer perceptron MLP and a softmax function is used to make the final sentiment quadruple element prediction:
[0080]
[0081]
[0082] in, V is an intermediate variable. The sentiment quadruple elements of this embodiment include target, aspect, opinion word, and sentiment polarity, τ∈{target word, aspect word, opinion word, beginning, end, positive, negative, other}.
[0083] S403: According to the label and prediction results Calculate the cross entropy loss function:
[0084]
[0085] in, is the square of the number of words in the entire conversation; the prediction result p is the probability; the label It is 0 or 1, indicating whether the relationship between the i-th and j-th words is τ; the log base is 2.
[0086] In this embodiment, the conversation emotion prediction model uses AdamW as the optimizer, the learning rate is set to 0.00005, and the dropout is set to 0.4.
[0087] The embodiment of the present invention also proposes a microblog comment dialogue sentiment analysis system based on graph neural network to implement the above method, such as Figure 3 As shown, the whole system consists of four main modules: feature extraction module, syntactic modeling module, semantic modeling module and fusion decoding module, which respectively implement the above four steps.
[0088] Experimental test:
[0089] The technical solution of the present invention (Ours) is experimentally tested and compared with the prior art CRF-Extract-Classify, SpERT, ParaPhrase, Span-ASTE, and DiaASQ. Experiments are conducted on Chinese Weibo datasets and translated English Weibo datasets to quantitatively evaluate the prediction results of sentiment quadruple, with micro-F1 and identification-F1 as evaluation indicators, and average-F1 as the average F1 value indicator of the two.
[0090] Table 1 Experimental test results
[0091]
[0092] The results in Table 1 show that the technical solution proposed in the present invention is significantly superior to the existing technology on both data sets. Compared with the existing most advanced DiaASQ method, the average F1 value is improved by 7.92% and 4.55% on the Chinese and English Weibo data sets, respectively, which proves the superiority of the technical solution proposed in the present invention.
[0093] 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 method for sentiment analysis of microblog comment dialogues based on graph neural networks, characterized in that: The following steps are involved: S1: Obtain Weibo comment data and construct a dialogue tree. Each branch of the dialogue tree is regarded as a thread. The comments and threads are encoded using an encoder to generate the encoded representation of the discourse and the features of the dialogue thread. S2: Use graph convolutional neural networks to model the syntactic information of comments and generate a syntactic representation of the entire conversation; S3: Use graph attention neural network to model the semantic information between comments, generate and update the enhanced representation of speaker perception and discourse structure perception; The steps of using a graph attention neural network to model the semantic information between comments include: constructing a speaker-perceived graph, wherein the discourse nodes of the graph are initialized by the encoded representation of the discourse, the edges of the graph represent the relationship between the speaker and the discourse nodes, and the relationship types of the edges of the speaker-perceived graph include self-loop, same speaker-before, same speaker-after, different speaker-before and different speaker-after; based on the speaker-perceived graph, using a graph attention neural network to capture contextual information that is aware of the speaker, and generating a speaker-perceived enhanced representation; constructing a discourse structure-aware graph, wherein the vertices of the graph are initialized by the encoded representation of the discourse, the edges of the graph represent the structural relationship between the discourses, and the relationship types of the edges of the discourse structure-aware graph include self-loop, reply relationship-before, reply relationship-after, thread relationship-before and thread relationship-after; based on the discourse structure-aware graph, using a graph attention neural network to capture dialogue structure information, and generating a discourse structure-aware enhanced representation; integrating the semantics of the speaker-perceived enhanced representation and the discourse structure-aware enhanced representation through an interactive module to obtain an updated feature representation; S4: The above-mentioned conversation thread features, the syntactic representation of the entire conversation, the updated enhanced representation of speaker perception and the enhanced representation of discourse structure perception are fused to obtain conversation features; the conversation features are input into the trained conversation sentiment prediction model for prediction to generate conversation sentiment prediction results for microblog comments.
2. The method according to claim 1, characterized in that In step S1, the RoBERTa encoder is used for encoding.
3. The method according to claim 1, characterized in that The steps of using the graph convolutional neural network to model the syntactic information of the review in step S2 include: Perform part-of-speech dependency analysis on each comment to generate part-of-speech tags and syntactic dependencies of the words in the comment; Obtain word embeddings of part-of-speech tags through the Word2Vec model to obtain a learnable continuous embedding vector; The BiLSTM model is used to process continuous embedding vectors to obtain part-of-speech feature representations with rich contextual information; Construct a syntactic graph, where the vertices are initialized by part-of-speech feature representations and the edges are initialized by the syntactic dependency matrix; According to the syntactic graph, the syntactic dependency and part-of-speech feature representation are integrated through the graph convolutional neural network to obtain the syntactic feature representation of the comment; Integrate the syntactic feature representations of all comments to obtain the syntactic representation of the entire conversation.
4. The method according to claim 3, characterized in that SpaCy tool was used to perform part-of-speech analysis and dependency analysis on each comment.
5. The method according to claim 1, characterized in that The steps of feature fusion in step S4 include: The syntactic representation of the entire conversation, the updated speaker-aware enhanced representation, and the discourse structure-aware enhanced representation are expanded to the same dimension, concatenated, and processed through a linear layer; The features processed by the linear layer are concatenated with the conversation thread features to obtain the conversation features.
6. The method according to claim 1, characterized in that In step S4, the conversation emotion prediction model is composed of a multi-layer perceptron MLP and a softmax function. During prediction, the conversation features are input into the trained multi-layer perceptron MLP for processing to generate intermediate variables. The intermediate variables are transformed and multiplied from column vectors to matrix vectors, and then decoded through the softmax function to generate the dialogue sentiment prediction result, which is a sentiment quadruple consisting of four elements: target, aspect, opinion word, and sentiment polarity.
7. The method according to claim 6, characterized in that The training of the multi-layer perceptron MLP is to train the multi-layer perceptron MLP through the microblog comment data containing known tags, calculate the cross entropy loss function according to the tags and the prediction results, and use AdamW as the optimizer to optimize the model parameters with the goal of minimizing the loss.
8. A microblog comment dialogue sentiment analysis system based on graph neural network, implementing the method described in any one of claims 1 to 7, characterized in that: The system includes: A feature extraction module is used to encode microblog comments and threads using an encoder to generate encoded representations of discourse and conversation thread features; The syntactic modeling module is used to model the syntactic information of comments using graph convolutional neural networks and generate the syntactic representation of the entire conversation; The semantic modeling module is used to use the graph attention neural network to model the semantic information between comments, generate and update the enhanced representation of speaker perception and discourse structure perception; The fusion decoding module is used to fuse the features of the conversation thread, the syntactic representation of the entire conversation, the updated enhanced representation of speaker perception and the enhanced representation of discourse structure perception to obtain the conversation features; the conversation features are input into the trained conversation sentiment prediction model for prediction to generate the conversation sentiment prediction results of Weibo comments.
Citation Information
Patent Citations
Aspect-level sentiment analysis method and system based on dependency type and phrase structure tree
CN116956824A
