A sentiment analysis method based on keyword weighted information
By using keyword weighting and CRF models in natural language processing, the problem of uncaptured word correlation spectrum and high training cost in text sentiment analysis is solved, and more accurate and efficient sentiment classification is achieved.
Patent Information
- Application Number
- CN202111471099.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-03
- Publication Date
- 2024-08-23
- Estimated Expiration
- 2041-12-03
AI Technical Summary
Existing natural language processing technology cannot effectively capture the correlation spectrum between words in text sentiment analysis, and the training time cost of neural network methods is high, the feature expression ability is weak, and feature engineering requires human intervention.
Adopt a sentiment analysis method based on keyword-weighted information, extract keyword information through TF-IDF and increase its weight, combined with a two-way long short-term memory network and a conditional random field (CRF) model to capture the local and global features of the text, and fuse Contextual relationship features are used to classify text sentiment polarity.
It improves the accuracy and efficiency of text emotion classification. Through keyword weighting and contextual feature fusion, it reduces the dependence on feature engineering and reduces training costs.
Smart Images

Figure CN114417851B
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of natural language processing, and in particular to a sentiment analysis method based on keyword weighted information. Background Art
[0002] Text sentiment analysis in natural language processing (NLP) is an important application field, which is mostly used for evaluative user information feedback, such as movie reviews and shopping reviews.
[0003] Sentiment analysis methods are mainly divided into traditional methods and deep learning methods. Traditional methods mainly include expected cross entropy, KNN algorithm, principal component analysis, etc. Traditional methods have weak feature expression capabilities, and feature engineering needs to be done manually, which increases costs. However, since the emergence of neural network models, the accuracy of sentiment analysis has been refreshed. Among them, the RNN-based model regards text as a sequence of words, aiming to capture word dependencies and text structures for classification, and can achieve better performance in tasks that require understanding of remote semantics; the CNN-based model can capture obvious feature information in the information, thereby classifying sentiment polarity.
[0004] Many hybrid models have been developed to combine LSTM and CNN architectures to capture local and global features of sentences and documents. However, the above models do not take into account the relationship between words, the span between words, and the time cost of training the model using neural network methods is very high. Summary of the invention
[0005] In view of the above problems, the purpose of the present invention is to disclose a sentiment analysis method based on keyword weighted information, which extracts keyword information through TF-IDF and assigns greater weights to important words in the text, so that they have a greater impact on the classification results of the text. Finally, CRF is used to fuse the relational features of the context to more accurately classify the sentiment polarity of the text content.
[0006] Specifically, a sentiment analysis method based on keyword weighted information of the present invention comprises the following steps:
[0007] S1: Clean the text data and train the word vectors on the text data to obtain the word vector file as the input of the model;
[0008] S2: Input the word vector file into the bidirectional long short-term memory network to capture the context information of each word;
[0009] S3: Extract keywords from each paragraph of text using the TF-IDF method and add a larger weight to influence the polarity judgment of the entire sentence. At the same time, concatenate the extracted keyword matrix with the output of the bidirectional long short-term memory network to make the feature information of the keyword position more obvious. The concatenated matrix is used as input to the next layer.
[0010] S4: Use the CRF layer to correct the output of the upper layer to obtain a reasonable sequence with the maximum probability;
[0011] S5: Use the classifier to discriminate the category output of the text and compare it with the actual category to train the network;
[0012] S6: Use the trained model to predict the sentiment polarity of the text to be predicted, and take the category with the highest probability as the predicted category output.
[0013] Furthermore, in the step S1, the text is cleaned by segmenting the text and removing stop words, where the stop words are words that have no effect on the classification result, and the word vector training is performed using the open source tool Glove.
[0014] Further, the S1 step specifically includes the following steps:
[0015] S11: Use Jieba component to split each text into many individual words to complete the word segmentation operation;
[0016] S12: Remove stop words from the corpus before model training to obtain text data;
[0017] S13: Use the open source tool Glove to train word vectors on text data and obtain word vector files as the input of the model. Let the tth sentence be x t , the word vector w of the i-th word in the sentence i ∈R d , the length of the sentence is s, and the representation of a sentence is:
[0018] x t =[w1;w2;w3...w s ]
[0019] Let the kth sentence in the dataset D be represented as x k , the length of the corpus is n. After the text data is processed, the data input of the model is expressed as:
[0020] i t =[x1;x2;x3...x n ].
[0021] Furthermore, the S2 step is specifically as follows: for the data set D, the context vector of the document is obtained by using LSTM, and the forward sequence and the reverse sequence are combined by calculation to obtain the output of the BI-LSTM layer:
[0022]
[0023] Furthermore, the specific calculation method of LSTM in step S2 is as follows:
[0024] i t =σ(W i [h t-1 , v t ]+b i )
[0025] o t =σ(W o [h t-1 , v t ]+b o )
[0026] f t =σ(W f [h t-1 , v t ]+b f )
[0027]
[0028]
[0029] h t =o t ⊙tanh(c t )
[0030] Among them, h t-1 Indicates the last output, v t Indicates the input of this time, i t is the input gate, o t is the output gate, f t is the forget gate, c t is the unit state at the current moment, is the current input unit state, h t is the current output value, W i , W o , W f , is the weight matrix of different gates, b i , b i , b i , is the bias vector, d1+d2 and d hThey represent the input vector dimension and hidden state of LSTM respectively, ⊙ represents element multiplication, and σ represents the sigmoid function.
[0031] Further, the S3 step is specifically as follows:
[0032] S31: Let the tth sentence be x t , sentence x t The keyword is represented as key t , the number of extracted keywords is n, and TF-IDF is used to extract keyword information in each text. The calculation formula is as follows:
[0033]
[0034]
[0035] TF-IDF=TF*IDF
[0036] key t =[keyword1,keyword2...keyword n ]
[0037] S32: Concatenate the extracted keyword matrix with the output of the bidirectional long short-term memory network. The calculation formula is as follows:
[0038] o t =key t ⊙h t
[0039] Here, ⊙ represents element-wise multiplication.
[0040] Further, the S4 step specifically includes:
[0041] S41: Use CRF to model the sentence sequence, z′ represents the true label, and the conditional probability of the label sequence z given the sentence x is calculated as follows:
[0042]
[0043] where score(z, x) is the sum of the Bi-LSTM transition score and the emission score.
[0044] S42: Introduce a potential binary variable z∈{0,1} for each word, use the forward and backward algorithms to calculate the marginal distribution of the text, and get the sentence representation s as follows:
[0045]
[0046] S43: By concatenating the sentence representations of all CRFs, where n is the number of CRFs, the final representation q of the classification is obtained as follows:
[0047] q=[s1s2...;s n ].
[0048] Furthermore, the step S5 is specifically as follows: obtaining the classification result through the Softmax classifier, that is, the probability distribution on each classification label, the probability that the Softmax classifier classifies x into category j is as shown in the formula:
[0049]
[0050] Among them, θ represents all parameters in the training process, and k represents the number of categories.
[0051] Beneficial effects of the present invention:
[0052] The present invention discloses a sentiment analysis method based on keyword weighted information. The keyword information is extracted through TF-IDF, and a larger weight is assigned to important words in the text, so that they have a greater impact on the classification results of the text. Finally, the relational features of the CRF context are fused to more accurately classify the sentiment polarity of the text content. BRIEF DESCRIPTION OF THE DRAWINGS
[0053] Figure 1 is a flow chart of an embodiment of the present invention;
[0054] Figure 2 This is a network structure diagram of the sentiment analysis method based on keyword weighted information provided by the present invention. DETAILED DESCRIPTION
[0055] The present invention will be described in detail below with reference to specific embodiments:
[0056] The present invention provides a sentiment analysis method based on keyword weighted information, using Figure 1 The processing flow shown in the figure uses the knowledge base to find the entity set related to the document, such as Figure 2 As shown in the figure, by extracting keyword information through TF-IDF, important words in the text are assigned greater weights, so that they have a greater impact on the classification results of the text; finally, using CRF to integrate the relational features of the context, the sentiment polarity of the text content can be classified more accurately. The details are as follows:
[0057] S1: Clean the text data, i.e., perform word segmentation and remove stop words. Use the open source tool Glove to train word vectors on the text data and obtain word vector files as the input of the model. The steps are as follows.
[0058] S11: Jieba components are used to segment each text into many individual words to complete the word segmentation operation. Correct word segmentation directly affects the final classification result, and Jieba's word segmentation is accurate and has the ability to recognize new words.
[0059] S12: In the text corpus, there are a large number of words that have no effect on the classification results, including but not limited to "tomorrow", "not only", "in summary", etc. in the Chinese corpus, "the", "but", "only", etc. in the English corpus. These words do not contribute to the final classification results, but will greatly increase the training time. Therefore, before model training, it is necessary to remove the stop words in the corpus to obtain text data.
[0060] S13: Use the open source tool Glove to train word vectors on text data and obtain word vector files as the input of the model. Let the tth sentence be x t , the word vector w of the i-th word in the sentence i ∈R d , the length of the sentence is s, and finally, a sentence is represented as:
[0061] x t =[w1;w2;w3...w s ]
[0062] Let the kth sentence in the dataset D be represented as x k , the length of the corpus is n. After the text data is processed, the data input of the model is expressed as:
[0063] i t =[x1;x2;x3...x n ].
[0064] S2: Input the word vector file into the bidirectional long short-term memory network, i.e., LSTM, to capture the context information of each word. LSTM can effectively model the sequential features of the text and retain the memory of the context to a certain extent. Using a BI-LSTM neural network with shared weights, the positive semantic information and the negative semantic information in the text can be learned separately. The calculation method of LSTM is as follows:
[0065] i t =σ(W i [h t-1 , v t ]+b i )
[0066] o t =σ(W o [h t-1 , v t ]+b o )
[0067] f t =σ(W f [h t-1 , v t ]+b f )
[0068]
[0069]
[0070] h t =o t ⊙tanh(c t )
[0071] Among them, h t-1 Indicates the last output, v t Indicates the input of this time, i t is the input gate, o t is the output gate, f t is the forget gate, c t is the unit state at the current moment, is the current input unit state, h t is the current output value, W i , W o , W f , is the weight matrix of different gates, b i , b i , b i , is the bias vector, d1+d2 and d h They represent the input vector dimension and hidden state of LSTM respectively, ⊙ represents element multiplication, and σ represents the sigmoid function.
[0072] Specifically, for dataset D, LSTM is used to obtain the context vector of the document, and the forward sequence and reverse sequence are combined using the above calculation method to obtain the output of the BI-LSTM layer:
[0073]
[0074] S3: Extract keywords from each paragraph of text using the TF-IDF method and add greater weights to influence the polarity judgment of the entire sentence. Concatenate the extracted keyword matrix with the output of the bidirectional long short-term memory network (LSTM) to make the feature information of the keyword position more obvious. The concatenated matrix is used as input to the next layer, including the following steps:
[0075] S31: Let the tth sentence be x t , sentence x t The keyword is represented as key t, the number of extracted keywords is n, and TF-IDF is used to extract keyword information in each text. The calculation formula is as follows:
[0076]
[0077]
[0078] TF-IDF=TF*IDF
[0079] key t =[keyword1,keyword2...keyword n ]
[0080] S32: Concatenate the extracted keyword matrix with the output of the bidirectional long short-term memory network. The calculation formula is as follows:
[0081] o t =key t ⊙h t
[0082] Here, ⊙ represents element-wise multiplication.
[0083] S4: Use the CRF layer to correct the output of the upper layer to obtain a reasonable sequence with the maximum probability, including the following steps:
[0084] S41: Use CRF to model the sentence sequence, z′ represents the true label, and the conditional probability of the label sequence z given the sentence x is calculated as follows:
[0085]
[0086] where score(z, x) is the sum of the Bi-LSTM transition score and the emission score.
[0087] S42: Introduce a potential binary variable z∈{0,1} for each word, use the forward and backward algorithms to calculate the marginal distribution of the text, and get the sentence representation s as follows:
[0088]
[0089] S43: By concatenating the sentence representations of all CRFs, where n is the number of CRFs, the final representation q of the classification is obtained as follows:
[0090] q=[s1;s2...;s n ].
[0091] S5: Use the classifier to discriminate the category output of the text and compare it with the actual category to train the network, including the following steps:
[0092] S51: The classification result is obtained through the Softmax classifier, that is, the probability distribution on each classification label. The probability that the Softmax classifier classifies x into category j is shown as follows:
[0093]
[0094] Among them, θ represents all parameters in the training process, and k represents the number of categories.
[0095] S6: Use the trained model to predict the sentiment polarity of the text to be predicted, and take the category with the highest probability as the predicted category output.
[0096] The above embodiments are only used to illustrate the technical solutions of the present invention and are not intended to limit the present invention. Although the present invention is described in detail with reference to the preferred embodiments, it should be understood by those skilled in the art that the technical solutions of the present invention may be modified or replaced by equivalents without departing from the purpose and scope of the technical solutions of the present invention, which should be included in the scope of the claims of the present invention. The techniques, shapes, and structural parts not described in detail in the present invention are all known technologies.
Claims
1. A sentiment analysis method based on keyword weighted information, characterized in that: The steps include: S1: Clean the text data and perform word vector training on the text data to obtain a word vector file as the input of the model; the S1 step specifically includes the following steps: S11: Use Jieba component to split each text into many individual words to complete the word segmentation operation; S12: Remove stop words from the corpus before model training to obtain text data; S13: Use the open source tool Glove to train word vectors on text data and obtain word vector files as the input of the model. Let the tth sentence be x t , the word vector w of the i-th word in the sentence i ∈R d , the length of the sentence is s, and the representation of a sentence is: x t =[w1;w2;w3...w s ] Let the kth sentence in the dataset D be represented as x k , the length of the corpus is n. After processing the text data, the data input of the model is expressed as: i t =[x1;x2;x3...x n ]; S2: Input the word vector file into the bidirectional long short-term memory network to capture the context information of each word; the S2 step is specifically as follows: for the data set D, use LSTM to obtain the context vector of the document, and combine the forward sequence and the reverse sequence by calculation to obtain the output of the BI-LSTM layer: The specific calculation method of LSTM in the S2 step is as follows: i t =σ(W i [h t-1 ,v t ]+b i ) the t =σ(W o [h t-1 ,v t ]+b o ) f t =σ(W f [h t-1 ,v t ]+b f ) h t =o t ⊙tanh(c t ) Among them, h t-1 Indicates the last output, v t Indicates the input of this time, i t is the input gate, o t is the output gate, f t is the forget gate, c t is the unit state at the current moment, is the current input unit state, h t is the current output value, W i , W o , W f , is the weight matrix of different gates, b i , b i , b i , is the bias vector, d1+d2 and d h Respectively represent the input vector dimension and hidden state of LSTM, ⊙ represents element multiplication, and σ represents the sigmoid function; S3: Extract keywords from each paragraph of text using the TF-IDF method and add a larger weight to influence the polarity judgment of the entire sentence. At the same time, concatenate the extracted keyword matrix with the output of the bidirectional long short-term memory network to make the feature information of the keyword position more obvious. The concatenated matrix is used as input to the next layer. S4: Use the CRF layer to correct the output of the upper layer to obtain a reasonable sequence with the maximum probability; the S4 step specifically includes: S41: Use CRF to model the sentence sequence, z′ represents the true label, and the conditional probability of the label sequence z given the sentence x is calculated as follows: Where score(z, x) is the sum of the Bi-LSTM transition score and the emission score; S42: Introduce a potential binary variable z∈{0, 1} for each word, use the forward and backward algorithms to calculate the marginal distribution of the text, and get the sentence representation s as follows: S43: By concatenating the sentence representations of all CRFs, where n is the number of CRFs, the final representation q of the classification is obtained as follows: q=[s1;s2...;s n ]; S5: Use the classifier to discriminate the category output of the text and compare it with the actual category to train the network; S6: Use the trained model to predict the sentiment polarity of the text to be predicted, and take the category with the highest probability as the predicted category output.
2. The sentiment analysis method based on keyword weighted information according to claim 1, characterized in that: In the step S1, the text is cleaned by segmenting the text and removing stop words, where the stop words are words that have no effect on the classification results. The word vector training is performed using the open source tool Glove.
3. The sentiment analysis method based on keyword weighted information according to claim 2 is characterized in that: The S3 step is specifically as follows: S31: Let the tth sentence be x t , sentence x t The keyword is represented as key t , the number of extracted keywords is n, and TF-IDF is used to extract keyword information in each text. The calculation formula is as follows: TF-IDF=TF*IDF key t =[keyword1,keyword2...keyword n ] S32: Concatenate the extracted keyword matrix with the output of the bidirectional long short-term memory network. The calculation formula is as follows: o t key t ⊙h t Here, ⊙ represents element-wise multiplication.
4. The sentiment analysis method based on keyword weighted information according to claim 3 is characterized in that: The step S5 is specifically as follows: obtaining the classification result through the Softmax classifier, that is, the probability distribution on each classification label. The probability that the Softmax classifier classifies x into category j is as shown in the formula: Among them, θ represents all parameters in the training process, and k represents the number of categories.
