Fine-grained sentiment analysis method based on bert and machine reading comprehension

By using the BERT model and machine reading comprehension methods, and utilizing part-of-speech embedding, attention layers, and graph convolutional networks, an aspect-centric adjacency graph is constructed. This addresses the problem of insufficient utilization of syntactic structure information in existing technologies and improves the accuracy and robustness of sentiment analysis.

CN117708335BActive Publication Date: 2026-11-20CHONGQING UNIV OF POSTS & TELECOMM
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202311826672.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-12-28
Publication Date
2026-11-20
Estimated Expiration
2043-12-28

AI Technical Summary

Technical Problem

Existing GCN-based methods fail to effectively utilize second-order nodes, third-order nodes, and global information in syntactic structure during sentiment analysis. Furthermore, their reliance on the relationships between words in the tree introduces noise into sentiment analysis, affecting the accuracy of the model.

Method used

Using the BERT model and machine reading comprehension methods, we construct an aspect-centric adjacency graph through part-of-speech embedding, attention layers, and graph convolutional networks. By leveraging multi-head attention mechanisms and graph convolutional layers, we reduce the impact of noise and extract fine-grained sentiment analysis features.

Benefits of technology

It improves the accuracy and robustness of sentiment analysis, reduces the noise impact of dependency trees, and enhances the model's performance in fine-grained sentiment analysis.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117708335B_ABST
    Figure CN117708335B_ABST
Patent Text Reader

Abstract

The application belongs to the field of natural language processing technology and sentiment analysis, and particularly relates to a sentiment analysis method based on a BERT model and machine reading comprehension, which comprises the following steps: obtaining sentiment analysis data, and pre-processing the data; inputting the pre-processed data into a BERT model to obtain a context-related vector; splicing the context vector and its corresponding part of speech, and then putting the spliced result into a classifier to obtain a word that influences an aspect word sentiment; putting the context vector into an attention layer to obtain an attention score matrix; then combining the relationship obtained by a sentiment word classifier with the attention score matrix to obtain a graph network between an aspect word and a sentiment word, and finally outputting a prediction result through a graph convolutional neural network; the application uses the method of machine reading comprehension based on the BERT to solve the sentiment analysis task.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of natural language processing technology and sentiment analysis, specifically involving a fine-grained sentiment analysis method based on the BERT model and machine reading comprehension. Background Technology

[0002] Sentiment analysis has become a hot research topic both domestically and internationally in recent years. Its task is to help users quickly acquire, organize, and analyze relevant evaluative information, and to analyze, process, summarize, and infer subjective texts with emotional overtones. Aspect-based sentiment analysis (ABSA) aims to determine the sentiment polarity of given aspect words in a sentence, where sentiment polarity includes positive, negative, and neutral.

[0003] Previous studies have used attention mechanisms to model the relevance between aspects and context. However, attention mechanisms are susceptible to noise in sentences, i.e., irrelevant words.

[0004] Recent work on ABSA utilizes graph neural networks to leverage syntactic structure on the dependency tree of sentences. Among these works, a 2019 proposal used graph convolutional networks (GCNs) to integrate syntactic information. Sun et al. (2019) proposed a GCN model to enhance the feature representation of aspects learned by bidirectional long short-term memory (Bi-LSTM). However, both studies treat all neighboring nodes of the current node in the graph equally, lacking an effective mechanism to distinguish the importance of neighboring nodes. Therefore, noisy nodes may lead to misjudgment of sentiment polarity by the model. To address this issue, Huang and Carley (2019) designed a target-dependent graph attention network that updates the representation of each node by utilizing multi-head attention. The attention mechanism is used to consider the semantic relevance of each neighboring node. Notably, existing GCN-based methods do not fully utilize syntactic structure, only considering information from neighboring nodes. How to capture information from second-order nodes, third-order nodes, and even the global syntactic structure simultaneously remains a challenge.

[0005] Currently, most methods employ multi-layered GCNs with dependency trees to extract the expression of opinion words. However, only a small portion of the relationships between words in the dependency tree are useful for sentiment analysis. Other relationships introduce potential noise into the sentiment analysis process. Summary of the Invention

[0006] To address the problems existing in the prior art, this invention proposes a fine-grained sentiment analysis method based on the BERT model and machine reading comprehension, characterized in that the model training process includes:

[0007] S1: Obtain the original sentiment analysis dataset, divide the sentiment analysis dataset into training and test sets; preprocess the data in the training set;

[0008] S2: Input the preprocessed data into the BERT model to generate word embedding representation data for each word;

[0009] S3: Input the part-of-speech tags into the BERT model to generate part-of-speech embeddings;

[0010] S4: Put the sentence and its corresponding part of speech into the Concat layer. In the Concat layer, each word is concatenated with its corresponding part of speech and then input into the Softmax layer to obtain the sentiment words that affect the other side.

[0011] S5: Embed the words of the sentence obtained from the BERT layer into the input attention layer to obtain the attention score matrix;

[0012] S6: Construct a layer from the aspect-centric graph obtained from the Softmax layer and the attention score input aspect graph to obtain the weight graph;

[0013] S7: The obtained graph and the word embeddings of the sentence are put into the graph convolutional layer for convolution, and the result is input into the Softmax layer;

[0014] S8: The model is trained using the cross-entropy loss function;

[0015] S9: The Adam algorithm is used to optimize the model, that is, the parameters of the BERT model are adjusted during the training process;

[0016] Preferably, the data preprocessing process includes: setting the length of each sentence to 110, and padding sentences shorter than 110; generating a question sentence for each sentence, appending a question to the end of each sentence: 'what effect [aspect] emotion?', where '[aspect]' is replaced with the aspect term from the original sentence; combining the question sentences and original sentences from the dataset; the format of the combined sentence is:

[0017]

[0018] Where S represents the original sentence and Q represents the question sentence. Words that indicate questions [CLS] indicates a word in the original sentence, [SEP] indicates a category marker, the first [SEP] indicates a separator, and the last [SEP] indicates an end marker.

[0019] 1. Preferably, the process of classifying sentiment words includes: inputting the part of speech of each word in the order of the original text input, according to the following format:

[0020]

[0021] in, Indicates the part of speech of the nth word.

[0022] Each word has a corresponding part-of-speech tag. By concatenating each word in the original sentence with its corresponding part-of-speech tag at the Concat layer, a word vector containing part-of-speech tag information is obtained. Then, each word containing part-of-speech information is classified, and the resulting word vectors containing part-of-speech information are fed into a Softmax layer to generate a probability distribution of whether it is a sentiment word.

[0023]

[0024] in, This indicates a sentence that incorporates parts of speech. and These are the learnable weights and biases.

[0025] Furthermore, at the attention layer, the process of processing word embedding representations using a multi-head attention mechanism includes:

[0026] Step 1: Determine the parameter matrix of the multi-head attention mechanism layer , , ;

[0027] Step 2: Convert the parameter matrix , Compare with the word embedding representation of the i-th word generated by the BERT model. Multiply to obtain the query vector Key vector , and aspect words Multiplication yields the aspect query vector ;

[0028]

[0029]

[0030]

[0031] Step 3: Based on the query vector Key vector Aspect query vector Find ;

[0032] Step 4: and The multi-head attention weight matrix is ​​obtained by summing the results.

[0033] in, This represents the query vector parameter matrix. Represents the key vector parameter matrix. Represents the aspect vector parameter matrix , Let represent the aspect attention matrix for the h-th sentence and the aspect perception attention matrix for the h-th sentence.

[0034] 2. Furthermore, the formula for calculating attention to a sentence aspect is as follows:

[0035]

[0036] in, Represents the query vector. Represents the transpose of the query vector.

[0037] The formula for aspect perception attention is:

[0038]

[0039] Representation aspect query vector, This represents the transpose of the key vector.

[0040] The multi-head attention calculation method is as follows:

[0041]

[0042] in, The h-th attention matrix in the multi-head attention matrix.

[0043] Preferred construction of an adjacency graph centered on an aspect:

[0044] After obtaining the sentiment words related to the influence, the connection relationship between the sentiment words and the aspect words is established, resulting in an adjacency graph centered on the aspect. Then, based on the obtained attention score matrix, the attention score between the aspect word and the i-th sentiment word is used as the weight of the edge between them.

[0045]

[0046] in It is an adjacency graph centered on the aspect. It is the attention score between the aspect word and the word i.

[0047] Preferably, the formula for the graph convolutional layer is:

[0048]

[0049] in These are the linear transformation weights of the l-th layer. It is the level l bias term. It is a non-linear function. It is an adjacency graph centered on aspects. It is the word embedding output by the BERT model.

[0050] After passing through the graph convolutional neural network, the final feature representation is obtained. Non-aspectual terms in the output representation of the graph convolutional layer are masked to obtain aspectual term representations. .

[0051]

[0052] f(·) is an average pooling function. This refers to the m-th character in the term "the first aspect".

[0053] Will Input a linear layer, then use a Softmax layer to generate a probability distribution over the sentiment polarity decision space:

[0054]

[0055] and These are the learnable weights and biases.

[0056] Preferably, the loss function is:

[0057]

[0058] D contains all sentences, a represents the aspect appearing in sentence s, θ represents all trainable parameters, and C is the set of sentiment polarities.

[0059] This invention utilizes the BERT model to obtain context-dependent word embeddings; this invention uses machine reading comprehension methods to obtain sentiment words related to influence, which can reduce the impact of noise generated by dependency trees to a certain extent. Attached Figure Description

[0060] Figure 1 This is an overall flowchart of the present invention;

[0061] Figure 2 This is a structural diagram of the model of the present invention. Detailed Implementation

[0062] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0063] A fine-grained sentiment analysis method based on BERT model and machine reading comprehension, such as Figure 1 The method includes: acquiring sentiment analysis data and preprocessing the data; inputting the preprocessed data into a BERT model to obtain a context-related vector; concatenating the context vector with its corresponding part-of-speech tag and then feeding it into a classifier to obtain words that influence aspect-level sentiment; feeding the context vector into an attention layer to obtain an attention score matrix; then combining the relationship obtained by the sentiment word classifier with the attention score matrix to obtain a graph network between aspect-level words and sentiment words, and finally outputting the prediction result through a graph convolutional neural network.

[0064] like Figure 2 The process of training a sentiment analysis model based on the BERT model and machine reading comprehension includes:

[0065] S1: Obtain the original sentiment analysis dataset, divide the sentiment analysis dataset into training and test sets; preprocess the data in the training set;

[0066] S2: Input the preprocessed data into the BERT model to generate word embedding representation data for each word;

[0067] S3: Input the part-of-speech tags into the BERT model to generate part-of-speech embeddings;

[0068] S4: Put the sentence and its corresponding part of speech into the Concat layer. In the Concat layer, each word is concatenated with its corresponding part of speech and then input into the Softmax layer to obtain the sentiment words that affect the other side.

[0069] S5: Embed the words of the sentence obtained from the BERT layer into the input attention layer to obtain the attention score matrix;

[0070] S6: Construct a layer from the aspect-centric graph obtained from the Softmax layer and the attention score input aspect graph to obtain the weight graph;

[0071] S7: The obtained graph and the word embeddings of the sentence are put into the graph convolutional layer for convolution, and the result is input into the Softmax layer;

[0072] S8: The model is trained using the cross-entropy loss function;

[0073] S9: The Adam algorithm is used to optimize the model, that is, the parameters of the BERT model are adjusted during the training process;

[0074] The original sentiment analysis dataset was taken from Twitter comments and the original question and answer dataset was taken from Wikipedia. The dataset was divided into two parts: the training set contained 6051 data points and the test set contained 667 data points.

[0075] Preferably, the data preprocessing process includes: setting the length of each sentence to 110, and padding sentences shorter than 110; generating a question sentence for each sentence, appending a question to the end of each sentence: 'what effect [aspect] emotion?', where '[aspect]' is replaced with the aspect term from the original sentence; combining the question sentences and original sentences from the dataset; the format of the combined statement is:

[0076]

[0077] Where S represents the original sentence, Indicates a question sentence, Words that indicate questions [CLS] indicates a word in the original sentence, [SEP] indicates a category marker, the first [SEP] indicates a separator, and the last [SEP] indicates an end marker.

[0078] The BERT model is used to process the data to obtain context-dependent word embeddings.

[0079] The BERT model is:

[0080]

[0081] in, This represents the input of the i-th word in the input sequence. This represents the embedding representation of the i-th word in the sequence generated by BERT.

[0082] After obtaining the word embedding representation for each word, it is input into the sentiment classification layer, and then the following operations are performed:

[0083] Enter the part of speech for each word in the order it appears in the original text, following the format below:

[0084]

[0085] in, Indicates the part of speech of the nth word.

[0086]

[0087] Each word and its corresponding part of speech are concatenated in the Concat layer to obtain a word vector containing part-of-speech information. A key factor affecting sentiment word extraction is the part of speech of the word.

[0088]

[0089] Then, each word containing part-of-speech information is classified, and the word vectors containing part-of-speech information are fed into a Softmax layer to generate a probability distribution of whether it is a sentiment word:

[0090]

[0091] in, This indicates a sentence that incorporates parts of speech. and These are the learnable weights and biases.

[0092] After obtaining the word embedding representation for each word, it is input into the attention layer to obtain the attention score matrix. Multi-head attention can more fully represent the relationships between words. The multi-head attention calculation process is as follows:

[0093]

[0094]

[0095]

[0096] in This represents the word embedding representation of the i-th word in the sequence generated by BERT. Aspects in a sequence are represented by word embeddings generated by BERT. This represents the query vector parameter matrix. Represents the key vector parameter matrix. The representation of the query vector parameter matrix is ​​updated during the training process.

[0097] The aspect attention of the sentence is calculated as follows:

[0098]

[0099] in, This represents the aspect attention matrix for the h-th sentence. Represents the query vector. This represents the transpose of the key vector. These are learnable weights.

[0100] The formula for aspect perception attention is:

[0101]

[0102] in, Let h represent the attention matrix of the h-th aspect. Representation aspect query vector, This represents the transpose of the key vector. These are learnable weights.

[0103] The multi-head attention calculation method is as follows:

[0104]

[0105] in, The h-th attention matrix in the multi-head attention matrix.

[0106] Multi-head attention representation Then, it is used in the process of constructing an adjacency graph centered on an aspect.

[0107] By establishing connections between sentiment words and aspect words, an adjacency graph centered on the aspect is obtained. Then, based on the attention score matrix, the attention score between aspect words and sentiment word i is used as the weight of the edge between them.

[0108]

[0109] in It is an adjacency graph centered on the aspect. The attention score between the aspect word and the word i

[0110] After obtaining the word embedding representation of each word and the adjacency graph centered on one side, it is fed into the graph convolutional layer for convolution.

[0111]

[0112] in These are the linear transformation weights of the l-th layer. It is the level l bias term. It is a non-linear function. It is an adjacency graph centered on aspects. It is the word embedding output by the BERT model.

[0113] After passing through the graph convolutional neural network, the final feature representation is obtained. Non-aspectual terms in the output representation of the graph convolutional layer are masked to obtain aspectual term representations. .

[0114]

[0115] f(·) is an average pooling function. This refers to the m-th character in the term "the first aspect".

[0116] Will Input a linear layer, then use a Softmax layer to generate a probability distribution over the polarity decision space:

[0117]

[0118] and The learnable weights and biases are the learnable weights and biases.

[0119] The loss function is:

[0120]

[0121] D contains all sentences, a represents the aspect appearing in sentence s, θ represents all trainable parameters, and C is the set of sentiment polarities.

[0122] Model evaluation metrics:

[0123] The model is primarily evaluated using accuracy and F1 score.

[0124] Accuracy is expressed as the number of correct predictions on the test data divided by the total number of test data points, as follows:

[0125]

[0126] Here, accuracy represents the level of precision. `totalData` represents the total number of data points. This indicates that the actual label matches the predicted label.

[0127] The F1 score is defined on a class-by-class basis and includes two main concepts: precision and recall. Precision is the proportion of individuals predicted to belong to a particular class that actually belong to that class. Recall is the proportion of individuals correctly predicted to belong to a particular class out of the total number of individuals in that class in the dataset. Calculating the F1 score first requires calculating precision and recall; the F1 score is the harmonic mean of precision and recall. The basic formula for calculating the F1 score is as follows:

[0128]

[0129] Here, precision refers to the proportion of individuals predicted to belong to a certain class that actually belong to that class. Recall refers to the proportion of individuals correctly predicted to belong to a certain class out of the total number of individuals of that class in the dataset.

[0130] The above-described embodiments further illustrate the purpose, technical solution, and advantages of the present invention. It should be understood that the above-described embodiments are merely preferred embodiments of the present invention and are not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc., made to the present invention within the spirit and principles of the present invention should be included within the protection scope of the present invention.

Claims

1. A fine-grained sentiment analysis method based on the BERT model and machine reading comprehension, characterized in that, The method includes: S1: Obtain the original sentiment analysis dataset, divide the sentiment analysis dataset into training and test sets; preprocess the data in the training set; S2: Input the preprocessed data into the BERT model to generate word embedding representation data for each word; S3: Input the part-of-speech tags into the BERT model to generate part-of-speech embeddings; S4: Put the sentence and its corresponding part of speech into the Concat layer. In the Concat layer, each word is concatenated with its corresponding part of speech and then input into the Softmax layer to obtain the sentiment words that affect the other side. S5: Embed the words of the sentence obtained from the BERT layer into the input attention layer to obtain the attention score matrix; S6: Construct a layer from the aspect-centric graph obtained from the Softmax layer and the attention score input aspect graph to obtain the weight graph; S7: The obtained graph and the word embeddings of the sentence are put into the graph convolutional layer for convolution, and the result is input into the Softmax layer; S8: The model is trained using the cross-entropy loss function; S9: The Adam algorithm is used to optimize the model, that is, the parameters in the BERT model are adjusted during the training process; Step S4 includes: inputting the part of speech of each word in the original sentence input order, according to the following format: in, Indicates the part of speech of the nth word; Each word has a corresponding part-of-speech tag. By concatenating each word in the original sentence with its corresponding part-of-speech tag in the Concat layer, a word vector containing part-of-speech tag information is obtained. Then, each word containing part-of-speech information is classified, and the word vectors containing part-of-speech information are fed into a Softmax layer to generate a probability distribution of whether it is a sentiment word: in, This indicates a sentence that incorporates parts of speech. and For learnable weights and biases; Step S5 specifically includes: Step 1: Determine the parameter matrix of the multi-head attention mechanism layer , , ; Step 2: Convert the parameter matrix , Compare with the word embedding representation of the i-th word generated by the BERT model. Multiply to obtain the query vector Key vector , and aspect words Multiplication yields the aspect query vector ; Step 3: Based on the query vector Key vector Aspect query vector Find , ; Step 4: and The multi-head attention weight matrix is ​​obtained by summing the results. in, This represents the query vector parameter matrix. Represents the key vector parameter matrix. Represents the aspect vector parameter matrix, , This represents the attention matrix for the h-th sentence and the bidirectional aspect-aware attention matrix. Step S7 specifically includes: The formula for graph convolutional layers is: in These are the linear transformation weights of the l-th layer. It is the level l bias term. It is a non-linear function. It is an adjacency graph centered on aspects. These are word embeddings output by the BERT model; After passing through the graph convolutional neural network, the final feature representation is obtained; non-aspect words in the output representation of the graph convolutional layer are masked to obtain aspect word representations. ; f(·) is an average pooling function. This refers to the m-th character in the term "the first aspect"; Will Input a linear layer, then use a Softmax layer to generate a probability distribution over the sentiment polarity decision space: and For learnable weights and biases, 'a' represents the aspect that appears in sentence 's'.

2. The fine-grained sentiment analysis method based on BERT model and machine reading comprehension as described in claim 1, characterized in that, The preprocessing of the training set data includes: setting the length of each sentence to 110 characters, padding sentences shorter than 110 characters; generating a question sentence for each sentence, appending a question to each sentence: 'What effect [aspect] emotion?', where 'aspect' in the question sentence is replaced with the aspect term from the original sentence; combining the question sentences and original sentences from the dataset, resulting in the following format: Where S represents the original sentence, Q represents the question sentence, and n represents the nth word in the question sentence. This indicates the nth word in the original sentence. [CLS] indicates a category marker, the first [SEP] indicates a separator, and the last [SEP] indicates an end marker.

3. The fine-grained sentiment analysis method based on BERT model and machine reading comprehension as described in claim 1, characterized in that, Step S6 specifically includes: After obtaining the sentiment words related to the influence, the connection relationship between the sentiment words and the aspect words is established, resulting in an adjacency graph centered on the aspect. Then, based on the attention score matrix obtained in step S5, the attention score between the aspect word and the i-th sentiment word is used as the weight of the edge between them: in It is an adjacency graph centered on the aspect. It is the attention score between the aspect word and the word i.

4. The fine-grained sentiment analysis method based on BERT model and machine reading comprehension as described in claim 1, characterized in that, The loss function used in step S8 is: D contains all sentences, a represents the aspect that appears in sentence s, θ represents all trainable parameters, and C is the set of sentiment polarities.

Citation Information

Patent Citations

  • Fine-grained sentiment analysis method based on BERT model and attention concentration network

    CN115730606A

  • GCN-based aspect-level text sentiment classification method

    CN116049393A