A text sentiment analysis method based on public opinion big data
The text sentiment analysis method based on public opinion big data solves the problem of accuracy and consistency of text sentiment scoring in the existing technology. Through emotional tendency sorting and vocabulary importance weight calculation, the accuracy and consistency of text sentiment scoring are improved. , suitable for massive data processing.
Patent Information
- Application Number
- CN202311347848.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-10-18
- Publication Date
- 2024-09-20
- Estimated Expiration
- 2043-10-18
AI Technical Summary
Existing text emotion scoring methods are difficult to accurately describe the degree of emotion, and due to differences in scoring standards between different people, there is a large deviation in the model results and cannot meet user needs.
The text sentiment analysis method based on public opinion big data is used to obtain public opinion text data, perform emotional tendency sorting, word segmentation processing, vectorization processing, calculate the vocabulary importance weight, construct a loss function, adjust model parameters until the model converges, and solve different problems. Issues with labeling discrepancies in ratings.
It improves the accuracy and consistency of model scoring, can better handle massive data, and improves the effect of text emotion scoring.
Smart Images

Figure CN117350287B
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of natural language processing, and specifically relates to a text sentiment analysis method based on public opinion big data. Background Art
[0002] In recent years, with the rapid development of the Internet, netizens have been discussing public opinion events more and more widely. Online public opinion is diverse and pluralistic, and it spreads widely and quickly, and is mixed with the complex emotions of netizens. When monitoring online public opinion, it is very important to conduct sentiment analysis on the text on the Internet, which helps to understand the public's emotions, help decision makers make more reasonable and effective judgments, and assist government departments in guiding public emotions to avoid public opinion crises. However, the existing text sentiment scoring methods are more direct classification, but the classification method divides the text into predefined categories, which is difficult to accurately characterize the degree of text emotion. However, training through direct manual scoring may result in large differences in the results due to differences in the scoring standards of different people, resulting in large deviations in the final trained scoring model, which cannot meet user needs. Summary of the invention
[0003] In order to solve the problems existing in the above prior art, the present invention proposes a text sentiment analysis method based on public opinion big data, the method comprising: inputting text data into a trained text sentiment analysis model based on public opinion analysis to obtain a text sentiment analysis result;
[0004] Training a text sentiment analysis model based on public opinion analysis includes:
[0005] S1. Obtain public opinion text data and divide the public opinion text data into a group;
[0006] S2, sort the sentiment tendency of the data in the group, and use the sorted data as the training data set;
[0007] S3, perform word segmentation on the text in the training data set, and delete the words in the sentence according to the word segmentation results to obtain sentences with the same number of words;
[0008] S4, using the pre-trained model to vectorize the sentences after the words are deleted to obtain the text vectors of each sentence;
[0009] S5, calculating the similarity between each text vector and the original text vector;
[0010] S6. Calculate the vocabulary importance weight according to the similarity value, input the vocabulary importance weight into the scoring model, obtain the sentiment relationship score of the word vector, and sort the words by sentiment relationship according to the scoring result;
[0011] S7, constructing the loss function of the model according to the sentiment relationship ranking results;
[0012] S8. Continuously adjust the model parameters. When the loss function converges, the model training is completed.
[0013] Preferably, the data in a group includes k texts, where k is any integer greater than 3 and less than M, and the calculation formula of M is:
[0014]
[0015] Among them, m all Indicates the size of the machine's video memory, m model Indicates the size of video memory occupied by the model, lenth is the average sentence length, m x The size of video memory occupied by a token.
[0016] Preferably, deleting words in the word segmentation result one by one includes: deleting a word from the text data after word segmentation, and concatenating the remaining words with the start marker to generate a sentence; and inputting the sentence into a pre-trained model to obtain a text vector.
[0017] Preferably, the formula for calculating the similarity between the text vector and the original text vector is:
[0018]
[0019] Among them, a and b represent a vector and b vector respectively, ai represents the value of the i-th latitude in a vector, bi represents the value of the i-th latitude in b vector, and d is the vector latitude.
[0020] Preferably, sorting the sentiment relationship of word vectors according to the weight of word importance includes: using text similarity to represent word importance, and using a weighted summation method of word vectors to represent text features; wherein the text vector feature calculation formula is:
[0021] Seq_emb=∑μ*tanh(word_emb)
[0022]
[0023] Among them, word_emb is the word vector after inputting the pre-training model, tanh is the activation function, μ is the weight, sim(ei,et) means calculating the text similarity of ei,et, ei means deleting the first word and representing the similarity of each word, ∑sim(ej,et) means the sum of the similarities calculated after deleting words one by one.
[0024] Preferably, the scoring model processes the input data including:
[0025] X'=W1⊙R(G1(x))⊙W2⊙R(G2(x))
[0026] K=W3⊙σ(X')
[0027] V=W4⊙tanh(X')
[0028] Output=G3(σ(K⊙X'+V⊙X'))
[0029] Among them, x represents the input text feature vector, ⊙ represents the multiplication of corresponding elements, W1, W2, W3, W4 represent learnable parameters, G1, G2, G3 represent linear layers, σ represents the sigmoid activation function, tanh represents the tangent activation function, and R represents the Relu activation function.
[0030] Preferably, the loss function expression of the model is:
[0031]
[0032] Among them, k is the group size, α, β, and λ are all hyperparameters, xi represents the model's score for the i-th text, xj represents the model's score for the j-th text, and σ represents the sigmoid activation function.
[0033] Beneficial effects of the present invention:
[0034] The present invention uses a sorting sentiment annotation method to alleviate the differences in scores among different annotators, uses the sentence vector after deleting a word as the weight of the word, and weights the word vector as a text feature to increase the importance of different words as text features and improve the model scoring effect. The model has consistency in the scoring criteria for big data public opinion texts, making it convenient to process massive data. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] Figure 1 It is the overall flow chart of the present invention. DETAILED DESCRIPTION
[0036] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0037] A text sentiment analysis method based on public opinion big data, the method comprising: acquiring text data, inputting the text data into a trained text sentiment analysis model based on public opinion analysis, and obtaining a text sentiment analysis result.
[0038] like Figure 1 As shown, training a text sentiment analysis model based on public opinion analysis includes:
[0039] S1. Obtain public opinion text data and divide the public opinion text data into a group;
[0040] S2, sort the sentiment tendency of the data in the group, and use the sorted data as the training data set;
[0041] S3, perform word segmentation on the text in the training data set, and delete the words in the sentence according to the word segmentation results to obtain sentences with the same number of words;
[0042] S4, using the pre-trained model to vectorize the sentences after the words are deleted to obtain the text vectors of each sentence;
[0043] S5, calculating the similarity between each text vector and the original text vector;
[0044] S6. Calculate the vocabulary importance weight according to the similarity value, input the vocabulary importance weight into the scoring model, obtain the sentiment relationship score of the word vector, and sort the words by sentiment relationship according to the scoring result;
[0045] S7, constructing the loss function of the model according to the sentiment relationship ranking results;
[0046] S8. Continuously adjust the model parameters. When the loss function converges, the model training is completed.
[0047] In this embodiment, public opinion text data is obtained, and after grouping, the text data is sorted according to the positive and negative tendencies of emotions, including: obtaining public opinion-related text data from Weibo, Zhihu, Xiaohongshu and other networks, randomly dividing the text data into groups of 8, and then having labelers sort the data in each group, with the data with positive emotional tendencies ranked first and the data with negative emotional tendencies ranked last.
[0048] Using a ranking method instead of a direct scoring method can make the annotation of text data more consistent. If the labeling is performed directly by scoring, the scores may vary greatly due to different labelers. However, this situation can be alleviated well by labeling sorting, and the ranking relationship can be directly used for calculation when calculating the loss function later, which facilitates model learning.
[0049] Process the text data and use the pre-trained model to vectorize the text to obtain word vectors and sentence vector features, including: concatenating the [CLS] marker at the beginning of all texts and the [SEP] marker at the end of all texts. At the same time, convert the text into the corresponding digital ID according to the vocabulary, and set the maximum length to 128. The part greater than 128 is directly truncated, and the part less than 128 is padded with 0 as padding. The Mac-Bert pre-trained model is input to map each word and the start and end symbols into a 768-dimensional vector. The vector mapped by the beginning [CLS] is used as the sentence vector feature of the text whose similarity needs to be calculated later.
[0050] Each sentence is segmented, and the words in the segmentation results are deleted one by one. The similarity between the feature vector after deleting the words and the original text vector is calculated, which includes: using the Jieba library in Python to directly segment the words to obtain the segmentation results, and then deleting the segmented words one by one. After deleting one word for each word, the remaining words are reconnected to obtain a new text, and the text is input into the Mac-BERT model in the above way to obtain the processed text feature vector.
[0051] Each word corresponds to a feature vector of the text. The similarity between the vector and the original text vector is calculated. The similarity calculation formula is as follows:
[0052]
[0053] Where a and b represent vector a and vector b respectively, ai represents the value of the i-th latitude in vector a, d is the latitude of the vector, and d is added after the value. It can introduce vector position information. After calculation, each word gets a similarity value, which can reflect the role of the word in the text. When the text vector after deleting a word is very similar to the original text vector feature, that is, the larger the similarity calculation result, the smaller the role of the word in the text, and vice versa. The word and similarity mapping relationship is stored in the dictionary for later use.
[0054] The process of using the calculated similarity as weighted information to incorporate the word vector feature as the text vector feature includes: calculating the text vector feature by weighted summation of the word vectors, wherein the text vector feature calculation formula is:
[0055] Seq_emb = μ*tanh(word_emb)
[0056] Among them, sim(ei,et) means calculating the similarity of ei,et vectors, ei means deleting the first word, and ... each word. When the sentence vector after deleting a word is similar to the original vector, it means that the importance of the word is lower, otherwise it means that the importance is higher. This calculation formula can make good use of this property.
[0057] The calculation formula of μ is as follows:
[0058]
[0059] Among them, sim(ei,et) means calculating the similarity of ei,et vectors, ei means deleting the first word, and ... each word. When the sentence vector after deleting a word is similar to the original vector, it means that the importance of the word is lower, otherwise it means that the importance is higher. This calculation formula can make good use of this property.
[0060] The scoring model calculation formula is:
[0061] X'=W1⊙R(G1(x))⊙W2⊙R(G2(x))
[0062] K=W3⊙σ(X')
[0063] V=W4⊙tanh(X')
[0064] Output=G3(σ(K⊙X'+V⊙X'))
[0065] Among them, x represents the input text feature vector, ⊙ represents the multiplication of corresponding elements, W1, W2, W3, W4 represent learnable parameters, G1, G2, G3 represent linear layers, σ represents the sigmoid activation function, tanh represents the tangent activation function, and R represents the Relu activation function.
[0066] The loss function expression of the model is:
[0067]
[0068] Where k is the group size, α, β, and λ are all hyperparameters, where α and β can be set to any value greater than 0, and λ is set to a value greater than 1. xi represents the model's score for the i-th text, and xj represents the model's score for the j-th text. i,j takes all combinations of the i-th sentence before the j-th sentence. Compared with the original -log(σ(xi-xj), the introduction of α and β hyperparameters in training can better control the model training process. When xi≤xj, it means that the score is completely wrong and the penalty needs to be increased, so λ is introduced. xj-xi Amplify this loss.
[0069] To subsequently score the text sentiment, you only need to input the text into the model to get the corresponding text sentiment score. The more positive the text sentiment, the higher the score.
[0070] The present invention uses a sorting sentiment annotation method to alleviate the differences in scores among different annotators, uses the sentence vector after deleting a word as the weight of the word, and weights the word vector as a text feature to increase the importance of different words as text features and improve the model scoring effect. The model has consistency in the scoring criteria for big data public opinion texts, making it convenient to process massive data.
[0071] The above embodiments further illustrate the purpose, technical solutions and advantages of the present invention in detail. It should be understood that the above embodiments are only preferred implementation modes 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 in the protection scope of the present invention.
Claims
1. A text sentiment analysis method based on public opinion big data, characterized in that: include: Obtain text data, input the text data into the trained text sentiment analysis model based on public opinion analysis, and obtain the text sentiment analysis results; Training a text sentiment analysis model based on public opinion analysis includes: S1. Obtain public opinion text data and divide the public opinion text data into a group; the data in a group includes k texts, where k is any integer greater than 3 and less than M, and the calculation formula of M is: Among them, m all Indicates the size of the machine's video memory, m model Indicates the size of video memory occupied by the model, lenth is the average sentence length, m x The size of video memory occupied by a token; S2, sort the sentiment tendency of the data in the group, and use the sorted data as the training data set; S3, perform word segmentation on the text in the training data set, and delete the words in the sentence according to the word segmentation results to obtain sentences with the same number of words; S4, using the pre-trained model to vectorize the sentences after the words are deleted to obtain the text vectors of each sentence; S5. Calculate the similarity between each text vector and the original text vector; the calculation formula is: Where a and b represent a vector and b vector respectively, ai represents the value of the i-th latitude in a vector, bi represents the value of the i-th latitude in b vector, and d is the vector latitude; S6. Calculate the vocabulary importance weight according to the similarity, input the vocabulary importance weight into the scoring model, obtain the sentiment relationship score of the word vector, and sort the words by sentiment relationship according to the scoring result; specifically including: using text similarity to represent vocabulary importance, using the weighted summation method of word vectors to represent text vector features; wherein the text vector feature calculation formula is: Seq_emb=∑μ*tanh(word_emb) Where, word_emb is the word vector after inputting the pre-trained model, tanh is the activation function, μ is the weight, sim(ei,et) means calculating the text similarity of ei,et, ei means deleting the i-th word, ∑sim(ej,et) means the sum of the similarities calculated after deleting words one by one; S7, constructing the loss function of the model according to the sentiment relationship ranking results; S8. Continuously adjust the model parameters. When the loss function converges, the model training is completed.
2. According to the text sentiment analysis method based on public opinion big data according to claim 1, it is characterized in that: Deleting words in the word segmentation result one by one includes: deleting a word from the text data after word segmentation, and concatenating the remaining words with the start marker to generate a sentence; inputting the sentence into the pre-trained model to obtain a text vector.
3. According to a text sentiment analysis method based on public opinion big data according to claim 1, it is characterized in that: The scoring model processes the input data including: X'=W1⊙R(G1(x))⊙W2⊙R(G2(x)) K=W3⊙σ(X') V=W4⊙tanh(X') Output=G3(σ(K⊙X'+V⊙X')) Among them, x represents the input text feature vector, ⊙ represents the multiplication of corresponding elements, W1, W2, W3, W4 represent learnable parameters, G1, G2, G3 represent linear layers, σ represents the sigmoid activation function, tanh represents the tangent activation function, and R represents the Relu activation function.
4. According to a text sentiment analysis method based on public opinion big data according to claim 1, it is characterized in that: The loss function expression of the model is: Among them, k is the group size, α, β, and λ are all hyperparameters, xi represents the model's score for the i-th text, xj represents the model's score for the j-th text, and σ represents the sigmoid activation function.
Citation Information
Patent Citations
Method and system for text sentiment analysis and processing
CN107247702A
Public opinion risk monitoring method and system based on natural language processing
CN112395539A
Multi-label text classification method based on public opinion big data analysis
CN112487143A
Public opinion monitoring and analysis system and method based on big data
CN115098773A
Text sentiment analysis method based on multi-level graph pooling
US20220405480A1
