Social network review text sentiment analysis method and system fusing user sentiment tendency
By integrating user sentiment and social network comment text features into an analytical approach, and utilizing GAT and Transformers models, this study addresses the shortcomings of existing technologies in comprehensively judging user emotions, achieving more accurate sentiment analysis and supporting mental health interventions.
Patent Information
- Application Number
- CN202210054262.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-01-18
- Publication Date
- 2025-11-11
- Estimated Expiration
- 2042-01-18
AI Technical Summary
Existing technologies lack a comprehensive method for judging user emotions and fail to effectively combine psychological intervention factors among users, resulting in insufficient accuracy of sentiment analysis.
This paper proposes a sentiment analysis method for social network comment text that integrates user sentiment tendencies. It uses the graph attention network model (GAT) to extract user sentiment tendency features and combines them with the comment text features of the Transformers model to construct a logistic regression model for sentiment polarity prediction, taking into account the social relationships between users and the linguistic features of the comment text.
It improves the accuracy of sentiment analysis, enabling more precise identification of users' emotional tendencies, supporting mental health institutions in providing targeted interventions for adolescents, and promoting mental health development.
Smart Images

Figure CN114443844B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of adolescent mental health tracking technology, specifically a method and system for sentiment analysis of social network comment text that integrates users' emotional tendencies. Background Technology
[0002] With rapid socio-economic development and increasing social competition, the psychological pressure on teenagers is also growing. Because teenagers are generally in adolescence, their mental state is relatively more vulnerable, and they also bear psychological pressure from academics, social interactions, family, emotions, self-awareness, and employment. Excessive pressure can easily lead to mental health problems. When the pressure exceeds their capacity and is not addressed promptly and effectively, teenagers may resort to self-harm or harming others to release stress, potentially leading them down a path of crime. Offline psychological counseling institutions typically require family members to first assess the teenager's mental health before persuading them to accept counseling. However, some teenagers are not fully open with their families, leading to a significant lag in family perception of their mental state, and teenagers often exhibit some resistance to counseling.
[0003] In today's online world, teenagers are more willing to share their feelings and opinions on social networks than with their families. On many social networking platforms such as Amazon and Yelp, the volume of social network comment text is increasing as the number of users, especially teenagers, and the amount of comment content generated grows. Sentiment analysis of social network comment text can help us understand the emotional changes of users on social networks, particularly teenagers. Research in this area can help relevant institutions understand the mental health of contemporary teenagers and provide corresponding intervention measures. Therefore, sentiment analysis of user comment text on social networks is significant for the cause of adolescent mental health development. On social networks, the text content of comments is generated by users. Users can express their emotions by posting online comments. Users on social networks can exert psychological influence on other users. Each user has a unique emotional tendency, and a user's emotional tendency can affect the emotional tendencies of other users, thus influencing the sentiment of their posted comments.
[0004] Currently, some technologies exist for perceiving user sentiment through online comment text. For example, application number 201610475678.4 discloses a sentiment analysis method based on social network data, which includes: extracting user posting data on social network platforms; segmenting and labeling the posting data using a labeler; performing text preprocessing and dependency parsing on the segmented and labeled posting data; dividing the preprocessed and parsed posting data into training and prediction sets; extracting sentiment classification features from the posting data in the training or prediction set respectively; training the sentiment classification features extracted from the training set using a linear support vector machine model to obtain a sentiment analysis classifier; and using the sentiment analysis classifier to analyze the sentiment classification features in the prediction set to predict the sentiment tendency of the target data posted by the user on the social network platform. This invention, targeting the characteristics of social network data, can effectively improve the accuracy of sentiment tendency prediction. However, this method only focuses on analyzing the complexity of textual language features, without considering the influence of psychological intervention between users, and ignores the connection between text content and user sentiment tendency.
[0005] For example, in the master's thesis of Chongqing University of Posts and Telecommunications, "Research on User Sentiment Analysis Method Based on Social Networks" (Chen Qiang D-10617-308-(2016)-02004), page 35, "Chapter 4: User Sentiment Prediction Based on Probabilistic Factor Graphical Model," a "user sentiment state learning model" is disclosed. Three factor functions influencing user sentiment state are introduced: attribute factor, time factor, and friend factor. The friend factor indicates that the user's sentiment state is influenced by their friends to a certain extent. The purpose of this method is to study the accuracy of user sentiment prediction under different weightings and to investigate the patterns of influence of the three factors on user sentiment. However, this method cannot directly determine the user's sentiment state, and relevant institutions cannot use the results of this method to conduct targeted interventions for users. Summary of the Invention
[0006] The technical problem to be solved by this invention is that there is a lack of methods for comprehensively judging user emotions in the prior art.
[0007] The present invention solves the above-mentioned technical problems through the following technical means:
[0008] A method for sentiment analysis of social network comment text that incorporates user sentiment includes the following steps:
[0009] Step 1: First, based on the UNFPA's definition of adolescents as those aged 14-25, the social network user dataset is divided into adolescent users aged 14-25 according to their profile information. Then, their respective comment text datasets are divided into training and testing samples. Next, the star ratings of each user's comments are used as sentiment classification information. Finally, the social relationship information between users is analyzed to calculate the sentiment tendency score for each user. Specifically, the process involves: analyzing social network user comments and categorizing them into negative and positive comments based on their star ratings. Assuming each user has p positive comments and n negative comments, the social relationships of the users in the data set are analyzed, and their number is counted as f. The formula for calculating the sentiment tendency score is:
[0010]
[0011] Where N is the number of users, It is the number of social relationships of the i-th user. It is the number of positive comments from the i-th user. s is the number of negative comments from the i-th user. i This represents the sentiment score of the i-th user;
[0012] Step 2: Using users' sentiment scores as user attribute information and social network relationship information between users as edge information, construct a graph network structure of user-user social networks.
[0013] Step 3: Use the Graph Attention Network (GAT) model to extract user sentiment features from the graph network structure described by the user;
[0014] Step 4: Encode the comment text using the Transformers model to obtain comment text features;
[0015] Step 5: Obtain the joint features of each comment by combining user sentiment characteristics and comment text features through a joint strategy, then construct a logistic regression model, train the model parameters using the joint features of comments from the training samples, and then perform sentiment polarity prediction analysis on the test samples.
[0016] This invention's sentiment analysis of comments not only considers the linguistic features of the comment text but also incorporates user psychological intervention factors. By integrating user emotional tendency characteristics into the text features, the resulting enhanced joint features, used for sentiment analysis of social network texts, achieve higher accuracy compared to traditional sentiment analysis that only analyzes text features. Based on the sentiment analysis results, formal adolescent psychological counseling institutions or adolescent psychological consultation rooms in hospitals can identify adolescent users with psychological problems. They can then use social network tools to provide positive and healthy comments on these users' comments, or even directly contact them for positive and healthy psychological counseling, guiding them towards healthy psychological development. If the problems are severe, they can directly seek psychological treatment from the adolescents with psychological problems, guiding them to face and correct their psychological issues, and promoting their mental health development.
[0017] Furthermore, the specific process of step 2 is as follows: using the calculated sentiment scores s of all users... i Form a set s = {s1, s2, ..., s} N Let set s represent the user's attribute information. Calculate the social relationships between users i and j, forming combinations [i, j]. Finally, construct an E×2 matrix A among the users, where E is the total number of edges, and matrix A represents the social relationship matrix between users.
[0018] Furthermore, the specific process of step 3 is as follows: Define the initial node vector for each user as h, with dimension h. h = [f, p, n], and all users form a set h = {h1, h2, ..., hn}. N}, Based on the relationships in matrix A, construct matrix [h] i h j User j is a neighbor of user i. The importance of user j to user i, i.e., the attention value, is calculated using an attention mechanism. The specific steps are as follows:
[0019]
[0020] Where, α ij It is the attention value between user i and user j. These are the weight parameters of the feedforward neural network, and F is the dimension of the user-output vector. The weights of h are the values to be transformed first, || represents the concatenation operation, and the activation function is LeaKyReLU;
[0021] The model employs a multi-head attention mechanism with K attention heads. Each attention head updates the vector of node i, and finally, all vectors of node i are concatenated and averaged to obtain the user sentiment feature h′. iThe calculation formula is as follows:
[0022]
[0023] Using the tanh activation function, we obtain h′ i That is, the sentiment tendency feature of the i-th user, with dimensions of
[0024] Furthermore, the specific process of step 4 is as follows: For a comment text, add the [CLS] flag before the comment text and the [SEP] flag at the punctuation marks. Perform one-hot encoding on the comment text according to the authoritative Google NLP corpus to obtain the one-hot embedding of the comment text, defined as x. L is the sequence length. According to the Self-Attention principle of Transformers, x is used as input to calculate the embedding vector of the comment text. The calculation adopts a multi-head attention mechanism, and the single-head attention value calculation process is as follows:
[0025]
[0026] Q i Q W i K W i V The weight matrix has dimensions of . d k Let K be the dimension, and adjust the inner product to prevent it from becoming too large. Let i represent the label of the attention head. There are a total of q attention heads. i The final attention value obtained after SoftMax activation;
[0027] The final comment text feature x′ is obtained by concatenating multiple attention values. The calculation formula is as follows:
[0028] MultiHead=concat(head1, head2,..., head q W O
[0029] By concatenating multiple head values and then multiplying them by the weight matrix... H represents the vector dimension of the comment text features, and MultiHead represents the word embedding matrix of the comment text with dimension H. The first dimension, [CLS], is taken as the embedding vector of the comment text feature, and is defined as x′.
[0030] Furthermore, the specific process of step 5 is as follows: A logistic regression model is constructed for sentiment prediction. First, a joint strategy is used to connect the user's sentiment tendency features and the comment text features to obtain the joint features of the target comment. The calculation formula is as follows:
[0031]
[0032] Where x′ i , h′ i Let W3 and W4 be the text features of the i-th comment and the user sentiment features of the comment author, respectively. W3 and W4 are weight matrices with dimensions of [dimensions missing]. division b2 is the bias value, with dimensions of... Finally, we get c. i Let c be the joint feature of the i-th comment. There are M comments in total, so let c be the vector matrix of the joint feature of the comments, with dimension M. 2 represents a binary classification result; then, SoftMax activation is applied to c to obtain the predicted sentiment polarity, calculated using the following formula:
[0033] y′=softmax(c)
[0034] The predicted sentiment value y′ and the true sentiment label y are compared using the CrossEntropy loss function to calculate the loss value. The calculation formula is as follows:
[0035]
[0036] The model parameters are updated by backpropagation based on the loss value to obtain the optimized model with the minimum and stable loss value. Then, prediction analysis is performed on the test set, and the evaluation metric is MacroF1, the formula of which is:
[0037]
[0038]
[0039]
[0040] Among them, negprecision and negrecall are the precision and recall rates for correctly identifying the polarity as negative emotion, while posprecision and posrecall are the precision and recall rates for correctly identifying the polarity as positive emotion. Finally, MacroF1 is calculated as the evaluation index for sentiment analysis.
[0041] Corresponding to the above method, the present invention also provides a social network comment text sentiment analysis system that integrates user sentiment tendencies, including:
[0042] The sentiment tendency calculation module calculates a user's sentiment tendency score based on the sentiment polarity distribution of comments posted on social networks, i.e., the number of friends the user has. The specific process is as follows: Comments from social network users are statistically analyzed, categorized into negative and positive comments based on their star rating. Assuming each user has p positive comments and n negative comments, the social relationships of the user are statistically analyzed, and their number is counted as f. The formula for calculating the sentiment tendency score is:
[0043]
[0044] Where N is the number of users, It is the number of social relationships of the i-th user. It is the number of positive comments from the i-th user. s is the number of negative comments from the i-th user. i This represents the sentiment score of the i-th user;
[0045] The user social network graph network structure construction module uses the user's sentiment tendency score as the user's attribute information and the social network relationship information between users as the edge information to construct a user-user social network graph network structure.
[0046] The user sentiment feature extraction module uses the graph attention network model GAT to extract user sentiment features from the user's social network structure.
[0047] The comment text feature representation module uses the Transformers model to encode the comment text to obtain comment text features;
[0048] The comment text feature model training module constructs a comment text feature model, trains the comment text feature model based on comment text and corpus, obtains all comment text features in the dataset, and summarizes and processes them to obtain a vector matrix of all comment text features in the data;
[0049] The Joint Strategy Comment Sentiment Analysis module constructs a joint strategy comment sentiment analysis model. By fusing user sentiment characteristics and comment text characteristics through a joint strategy, the joint features of the comment are obtained. The joint strategy comment sentiment analysis model is iteratively trained, and the trained joint strategy comment sentiment analysis model is used to predict and analyze the sentiment polarity of comment texts on test data.
[0050] Furthermore, the specific process of the user sentiment tendency model training module is as follows: using the calculated sentiment tendency scores s of all users... i Form a set s = {s1, s2, ..., s} NLet set s represent the user's attribute information. Calculate the social relationships between users i and j, forming combinations [i, j]. Finally, construct an E×2 matrix A among the users, where E is the total number of edges, and matrix A represents the social relationship matrix between users.
[0051] Furthermore, the specific process of the comment text feature model training module is as follows: define the initial node vector for each user as h, with dimension [missing information]. h = [f, p, n], and all users form a set h = {h1, h2, ..., hn}. N}, Based on the relationships in matrix A, construct matrix [h] i h j User j is a neighbor of user i. The importance of user j to user i, i.e., the attention value, is calculated using an attention mechanism. The specific steps are as follows:
[0052]
[0053] Where, α ij It is the attention value between user i and user j. These are the weight parameters of the feedforward neural network, and F is the dimension of the user-output vector. The weights of h are the values to be transformed first, || represents the concatenation operation, and the activation function is LeaKyReLU;
[0054] The model employs a multi-head attention mechanism with K attention heads. Each attention head updates the vector of node i, and finally, all vectors of node i are concatenated and averaged to obtain the user sentiment feature h′. i The calculation formula is as follows:
[0055]
[0056] Using the tanh activation function, we obtain h′ i That is, the sentiment tendency feature of the i-th user, with dimensions of
[0057] Furthermore, the specific process of the comment text feature model training module is as follows: For a comment text, add the [CLS] flag before the comment text and the [SEP] flag at the sentence breaks. Perform one-hot encoding on the comment text according to the authoritative Google NLP corpus to obtain the one-hot embedding of the comment text, defined as x. L is the sequence length. According to the Self-Attention principle of Transformers, x is used as input to calculate the embedding vector of the comment text. The calculation adopts a multi-head attention mechanism, and the single-head attention value calculation process is as follows:
[0058]
[0059] Among them W i Q W i K W i V The weight matrix has dimensions of . d k Let K be the dimension, and adjust the inner product to prevent it from becoming too large. Let i represent the label of the attention head. There are a total of q attention heads. i The final attention value obtained after SoftMax activation;
[0060] The final comment text feature x′ is obtained by concatenating multiple attention values. The calculation formula is as follows:
[0061] MultiHead=concat(head1, head2,..., head q W O
[0062] By concatenating multiple head values and then multiplying them by the weight matrix... H represents the vector dimension of the comment text features, and MultiHead represents the word embedding matrix of the comment text with dimension H. The first dimension, [CLS], is taken as the embedding vector of the comment text feature, and is defined as x′.
[0063] Furthermore, the specific process of the joint strategy comment sentiment analysis module is as follows: A logistic regression model is constructed for sentiment prediction. First, the user's sentiment tendency features and comment text features are connected through a joint strategy to obtain the joint features of the target comment. The calculation formula is as follows:
[0064]
[0065] Where x′ i , h′ i Let W3 and W4 be the text features of the i-th comment and the user sentiment features of the comment author, respectively. W3 and W4 are weight matrices with dimensions of [dimensions missing]. and b2 is the bias value, with dimensions of... Finally, we get c. i Let c be the joint feature of the i-th comment. There are M comments in total, so let c be the vector matrix of the joint feature of the comments, with dimension M. 2 represents a binary classification result; then, SoftMax activation is applied to c to obtain the predicted sentiment polarity, calculated using the following formula:
[0066] y′=softmax(c)
[0067] The predicted sentiment value y′ and the true sentiment label y are compared using the CrossEntropy loss function to calculate the loss value. The calculation formula is as follows:
[0068]
[0069] The model parameters are updated by backpropagation based on the loss value to obtain the optimized model with the minimum and stable loss value. Then, prediction analysis is performed on the test set, and the evaluation metric is MacroF1, the formula of which is:
[0070]
[0071]
[0072]
[0073] Among them, negprecision and negrecall are the precision and recall rates for correctly identifying the polarity as negative emotion, while posprecision and posrecall are the precision and recall rates for correctly identifying the polarity as positive emotion. Finally, MacroF1 is calculated as the evaluation index for sentiment analysis.
[0074] The advantages of this invention are:
[0075] The advantages of the social network comment text sentiment analysis method and system that integrates user sentiment tendencies provided by this invention are as follows: This invention not only considers the linguistic features of the comment text, but also incorporates user psychological intervention factors. By integrating user sentiment tendencies into the text features, the resulting enhanced joint features used for social network text sentiment analysis have higher accuracy compared to traditional sentiment analysis that only analyzes text features. Attached Figure Description
[0076] Figure 1 This is a flowchart of a social network comment text sentiment analysis method that integrates user sentiment tendencies, as described in this embodiment of the invention.
[0077] Figure 2 This is a flowchart illustrating the user sentiment tendency feature learning process in an embodiment of the present invention.
[0078] Figure 3 This is a flowchart of the joint strategy comment sentiment analysis in an embodiment of the present invention. Detailed Implementation
[0079] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below in conjunction with the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, 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.
[0080] Reference Figure 1 The social network comment text sentiment analysis method that integrates user sentiment tendencies proposed in this embodiment specifically includes the following steps:
[0081] Step 1: Compile a dataset of comments from social network users. First, based on the United Nations Population Fund's definition of adolescents as those aged 14-25, the social network user dataset is divided into adolescent users aged 14-25 according to the age information in their personal profiles. Then, their respective comment text datasets are divided into training samples and test samples. The comment set includes comment star ratings (1-5 stars) and comment content text. This invention mainly focuses on judging and analyzing the sentiment polarity of comments based on social network data information.
[0082] This step specifically includes: dividing the user review dataset into two categories based on their star ratings and content: 1 and 2 stars represent negative sentiment, 4 and 5 stars represent positive sentiment, and 3 stars represent neutral sentiment. Neutral sentiment comments are ignored. Each user has p positive comments and n negative comments. Next, the social relationships of users in the data set are analyzed, identifying which users each user has social relationships with and counting the number of such relationships as f. The sentiment tendency is calculated using the following formula:
[0083]
[0084] Where N is the number of users, It is the number of social relationships of the i-th user. It is the number of positive comments from the i-th user. s is the number of negative comments from the i-th user. i This represents the sentiment score of the i-th user.
[0085] The user's sentiment score ranges from -1 to +1, with -1 to +1 representing a range from extremely negative sentiment to extremely positive sentiment.
[0086] Step 2: Construct the user social network structure, using user attribute information [number of friends, positive comments, negative comments] as the attributes of the network structure, and the social relationships between users as the edges.
[0087] This step specifically includes: using the calculated sentiment scores s of all users. i Form a set s = {s1, s2, ..., s} N Let set s be the set of users' sentiment scores. The social relationships between users i and j are statistically analyzed, forming combinations [i, j]. Finally, an E×2 matrix A is constructed between users, where E is the total number of edges, and matrix A represents the social relationship matrix between users.
[0088] Step 3 involves unsupervised learning of the user's social network structure. This involves calculating and learning the user's sentiment characteristics based on their own attributes and the weights between the user and their neighbors. The specific implementation process is as follows:
[0089] Reference Figure 2 This step specifically includes: defining the initial node vector for each user as h, with dimension [missing information]. h = [f, p, n], and all users form a set h = {h1, h2, ..., hn}. N}, Based on the relationships in matrix A, construct matrix [h] i h j User j is a neighbor of user i. The importance of user j to user i, i.e., the attention value, is calculated using an attention mechanism. The specific steps are as follows:
[0090]
[0091] Where, α ij It is the attention value between user i and user j. These are the weight parameters of the feedforward neural network, and F is the dimension of the user-output vector. The weights of h are the values to be transformed first. || represents the concatenation operation. The activation function is LeaKyReLU.
[0092] The model employs a multi-head attention mechanism with K attention heads. Each attention head updates the vector of node i, and finally, all vectors of node i are concatenated and averaged to obtain the user sentiment feature h′. i The calculation formula is as follows:
[0093]
[0094] Using the tanh activation function, we obtain h′ i That is, the sentiment tendency feature of the i-th user, with dimensions of
[0095] Step 4: Perform unsupervised learning on the user's comment text content to learn the feature representation of each comment text.
[0096] This step specifically includes: for a comment text, adding the [CLS] flag before the comment text and the [SEP] flag at sentence breaks; performing one-hot encoding on the comment text using the authoritative Google NLP corpus to obtain the one-hot embedding of the comment text, defined as x. L is the sequence length. According to the Transformers' Self-Attention mechanism, x is used as input to calculate the embedding vector of the comment text. The calculation adopts a multi-head attention mechanism, and the single-head attention value calculation process is as follows:
[0097]
[0098] Among them W i Q W i K W i V The weight matrix has dimensions of . d k Let K be the dimension, and adjust the inner product to prevent it from becoming too large. Let i represent the label of the attention head. There are a total of q attention heads. i This is the attention value obtained after SoftMax activation.
[0099] The final comment text feature x′ is obtained by concatenating multiple attention values. The calculation formula is as follows:
[0100] MultiHead=concat(head1, head2,..., head q W O
[0101] By concatenating multiple head values and then multiplying them by the weight matrix... H represents the vector dimension of the comment text features, and MultiHead represents the word embedding matrix of the comment text with dimension H. The first dimension, [CLS], is taken as the embedding vector of the comment text and defined as x′.
[0102] Step 5: For the learned user sentiment features and comment text features, fuse their feature vectors together to obtain a new joint feature, namely the enhanced comment joint feature, so that the comment joint feature also includes the user sentiment features. Then, use the comment joint feature as input to train the sentiment analysis model. The training data and real sentiment polarity labels are responsible for training. The trained and optimized model is used to perform sentiment analysis on the test set data. The specific process is as follows:
[0103] Reference Figure 3This step specifically includes: constructing a logistic regression model for sentiment prediction. First, a joint strategy is used to connect user sentiment characteristics and comment text features to obtain joint comment features, the calculation formula of which is:
[0104]
[0105] Where x′ i , h′ i Let W3 and W4 be the text features of the i-th comment and the user sentiment features of the comment author, respectively. W3 and W4 are weight matrices with dimensions of [dimensions missing]. and b2 is the bias value, with dimensions of... Finally, we get c. i Let c be the joint feature of the i-th comment. There are M comments in total, so let c be the vector matrix of the joint feature of the comments, with dimension M. 2 represents a binary classification result. Then, SoftMax activation is applied to c to obtain the predicted sentiment polarity, calculated using the following formula:
[0106] y′=softmax(c)
[0107] The predicted sentiment value y′ and the true sentiment label y are compared using the CrossEntropy loss function to calculate the loss value. The calculation formula is as follows:
[0108]
[0109] The model parameters are updated by backpropagation based on the loss value to obtain the optimized model with the minimum and stable loss value. Then, prediction analysis is performed on the test set, and the evaluation metric is MacroF1, the formula of which is:
[0110]
[0111]
[0112]
[0113] Among them, negprecision and negrecall are the precision and recall rates for correctly identifying the polarity as negative emotion, while posprecision and posrecall are the precision and recall rates for correctly identifying the polarity as positive emotion. Finally, MacroF1 is calculated as the evaluation index for sentiment analysis.
[0114] This implementation method considers not only the content of the comment text itself but also user psychological intervention factors in its sentiment analysis of comment texts. It trains and learns user sentiment characteristics based on user emotional tendencies and social relationships, resulting in user sentiment characteristics. This social network comment text sentiment analysis, which incorporates both user sentiment characteristics and comment text features, has higher accuracy compared to traditional sentiment analysis that only analyzes the text. Based on the sentiment analysis results, formal adolescent psychological counseling institutions or adolescent psychological counseling rooms in hospitals can identify adolescents with psychological problems. They can then use social network tools to provide positive and healthy comments on these users' comments, or even directly contact them for positive and healthy psychological counseling, guiding them towards healthy psychological development. If the problems are severe, they can directly seek psychological treatment from the adolescents with psychological problems, guiding them to face and correct their psychological issues, and promoting their mental health development.
[0115] The social network comment text sentiment analysis system proposed in this invention integrates user sentiment tendencies, including:
[0116] The sentiment tendency score calculation module calculates a user's sentiment tendency value based on the user's social relationships, i.e., the number of friends the user has, and the sentiment polarity distribution of comments posted on social networks. Specifically, it involves: statistically analyzing a dataset of comments from social network users, where social relationship information indicates which users the user is friends with or follows, and the comment set includes comment star ratings (1-5 stars) and comment text. This invention mainly focuses on judging and analyzing the sentiment polarity of comments based on this social network data information.
[0117] This step specifically includes: dividing the user review dataset into two categories based on their star ratings and content: 1 and 2 stars represent negative sentiment, 4 and 5 stars represent positive sentiment, and 3 stars represent neutral sentiment. Neutral sentiment comments are ignored. Each user has p positive comments and n negative comments. Next, the social relationships of users in the data set are analyzed, identifying which users each user has social relationships with and counting the number of such relationships as f. The sentiment tendency is calculated using the following formula:
[0118]
[0119] Where N is the number of users, It is the number of social relationships of the i-th user. It is the number of positive comments from the i-th user. s is the number of negative comments from the i-th user. i This represents the sentiment score of the i-th user.
[0120] The user's sentiment score ranges from -1 to +1, with -1 to +1 representing a range from extremely negative sentiment to extremely positive sentiment.
[0121] The user social network graph network structure construction module uses users' sentiment scores as user attribute information and the social network relationship information between users as edge information to construct a user-user social network graph network structure; specifically, it uses the calculated sentiment scores s of all users... i Form a set s = {s1, s2, ..., s} N Let set s represent the user's attribute information. Calculate the social relationships between users i and j, forming combinations [i, j]. Finally, construct an E×2 matrix A among the users, where E is the total number of edges, and matrix A represents the social relationship matrix between users.
[0122] The user sentiment tendency model training module constructs a user sentiment tendency model based on users' social relationships and sentiment tendency scores. It acquires all user sentiment tendency features from the dataset and aggregates them to obtain a vector matrix of all user sentiment tendency features. Specifically, it defines the initial node vector for each user as h, with dimensions [missing information]. h = [f, p, n], and all users form a set h = {h1, h2, ..., hn}. N}, Based on the relationships in matrix A, construct matrix [h] i h j User j is a neighbor of user i. The importance of user j to user i, i.e., the attention value, is calculated using an attention mechanism. The specific steps are as follows:
[0123]
[0124] Where, α ij It is the attention value between user i and user j. These are the weight parameters of the feedforward neural network, and F is the dimension of the user-output vector. The weights of h are the values to be transformed first. || represents the concatenation operation. The activation function is LeaKyReLU.
[0125] The model employs a multi-head attention mechanism with K attention heads. Each attention head updates the vector of node i, and finally, all vectors of node i are concatenated and averaged to obtain the user sentiment feature h′. i The calculation formula is as follows:
[0126]
[0127] Using the tanh activation function, we obtain h′ i That is, the i-th user's sentiment tendency feature, with dimensions of
[0128] The comment text feature representation module uses the Transformers model to encode the comment text to obtain comment text features;
[0129] The comment text feature model training module constructs a comment text feature model based on comment texts and a corpus. It acquires all comment text features from the dataset and processes them to obtain a vector matrix of all comment text features. Specifically, for each comment text, it adds a [CLS] flag before the text and a [SEP] flag at sentence breaks. It then performs one-hot encoding on the comment text using the authoritative Google NLP corpus to obtain the one-hot embedding, defined as x. L is the sequence length. According to the Self-Attention principle of Transformers, x is used as input to calculate the embedding vector of the comment text. The calculation adopts a multi-head attention mechanism, and the single-head attention value calculation process is as follows:
[0130]
[0131] Among them W i Q W i K W i V The weight matrix has dimensions of . d k Let K be the dimension, and adjust the inner product to prevent it from becoming too large. Let i represent the label of the attention head. There are a total of q attention heads. i This is the attention value obtained after SoftMax activation.
[0132] The final comment text feature x′ is obtained by concatenating multiple attention values. The calculation formula is as follows:
[0133] MultiHead=concat(head1, head2,..., head q W O
[0134] By concatenating multiple head values and then multiplying them by the weight matrix... H represents the vector dimension of the comment text features, and MultiHead represents the word embedding matrix of the comment text features, with dimension H = 1. The embedding vector of its first dimension, [CLS], is taken as the feature representation of the comment text and defined as x′.
[0135] The joint strategy comment sentiment analysis module constructs a joint strategy comment sentiment analysis model. This model integrates user sentiment characteristics and comment text features through a joint strategy to obtain joint comment features. The joint strategy comment sentiment analysis model is then iteratively trained, and the trained model is used to predict and analyze the sentiment polarity of comment texts on test data. Specifically, this includes: constructing a logistic regression model for sentiment prediction. First, a joint strategy is used to connect user sentiment characteristics and comment text features to obtain joint comment features, calculated using the following formula:
[0136]
[0137] Where x′ i , h′ i Let W3 and W4 be the text features of the i-th comment and the user sentiment features of the comment author, respectively. W3 and W4 are weight matrices with dimensions of [dimensions missing]. and b2 is the bias value, with dimensions of... Finally, we get c. i Let c be the joint feature of the i-th comment. There are M comments in total, so let c be the vector matrix of the joint feature of the comments, with dimension M. 2 represents a binary classification result. Then, SofiMax activation is applied to c to obtain the predicted sentiment polarity, calculated using the following formula:
[0138] y′=softmax(c)
[0139] The predicted sentiment value y′ and the true sentiment label y are compared using the CrossEntropy loss function to calculate the loss value. The calculation formula is as follows:
[0140]
[0141] The model parameters are updated by backpropagation based on the loss value to obtain the optimized model with the minimum and stable loss value. Then, prediction analysis is performed on the test set, and the evaluation metric is MacroF1, the formula of which is:
[0142]
[0143]
[0144]
[0145] Among them, negprecision and negrecall are the precision and recall rates for correctly identifying the polarity as negative emotion, while posprecision and posrecall are the precision and recall rates for correctly identifying the polarity as positive emotion. Finally, MacroF1 is calculated as the evaluation index for sentiment analysis.
[0146] The above embodiments are only used to illustrate the technical solutions of the present invention, and are not intended to limit it. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A sentiment analysis method for social network comment text that integrates user emotional tendencies, characterized in that, Includes the following steps: S1. First, based on the UNFPA's definition of adolescents as those aged 14-25, the social network user dataset is divided into adolescent users aged 14-25 according to their personal profiles. Then, their respective comment text datasets are divided into training samples and test samples. Next, the star ratings of each user's comments are used as sentiment classification information. Finally, the social relationship information between users is analyzed to calculate the sentiment tendency score for each user. Specifically, the process is as follows: Comments from social network users are analyzed, and comments are categorized into negative and positive comments based on their star ratings. Assuming each user has p positive comments and n negative comments, the social relationships of users in the data set are analyzed, and their number is counted as f. The formula for calculating the sentiment tendency score is: Where N is the number of users, It is the number of social relationships of the i-th user. It is the number of positive comments from the i-th user. s is the number of negative comments from the i-th user. i This represents the sentiment score of the i-th user; S2. Calculate the sentiment scores s of all users. i Form a set s = {s1, s2, ..., s} N Let s be the set of user attribute information; count the social relationships between users i and j, and form combinations [i,j] based on these social relationships. Finally, construct an E×2 matrix A representing the social relationships between users, where E is the total number of edges. S3. Extract user sentiment features from matrix A using the graph attention network model GAT. Among them, h j Let α be the initial node vector for the j-th user. ij It is the attention value between user i and user j, where user j is a neighbor of user i, and K is the K attention heads; using the tanh activation function, h is obtained. i i That is, the sentiment tendency feature of the i-th user, with dimensions of S4. Encode the comment text using the Transformers model to obtain comment text features; S5. By combining user sentiment characteristics and comment text characteristics through a joint strategy, the joint features of each comment are obtained. Then, a logistic regression model is constructed. The parameters of the model are trained using the joint features of the comments from the training samples. Finally, sentiment polarity prediction analysis is performed on the test samples.
2. The social network comment text sentiment analysis method integrating user sentiment tendencies according to claim 1, characterized in that, The specific process of step 3 is as follows: Define the initial node vector for each user as h. i , dimension h i = [f, p, n], and all users form a set h = {h1, h2, ..., hn}. N }, Based on the relationships in matrix A, construct matrix [h] i ,h j User j is a neighbor of user i. The importance of user j to user i, i.e., the attention value, is calculated using an attention mechanism. The specific steps are as follows: Where, α ij It is the attention value between user i and user j. These are the weight parameters of the feedforward neural network, and F is the dimension of the user-output vector. The weights of h are the values to be transformed first, || represents the concatenation operation, and the activation function is LeaKyReLU; The model employs a multi-head attention mechanism with K attention heads. Each attention head updates the vector of node i, and finally, all vectors of node i are concatenated and averaged to obtain the user sentiment feature h. i i .
3. The social network comment text sentiment analysis method integrating user sentiment tendencies according to claim 2, characterized in that, The specific process of step 4 is as follows: For a comment text, add the [CLS] flag before the comment text and the [SEP] flag at the sentence breaks. Perform one-hot encoding on the comment text according to the authoritative Google NLP corpus to obtain the one-hot embedding of the comment text, defined as x. L is the sequence length. According to the Self-Attention principle of Transformers, x is used as input to calculate the embedding vector of the comment text. The calculation adopts a multi-head attention mechanism, and the single-head attention value calculation process is as follows: Among them W i Q W i K W i v The weight matrix has dimensions of . d k Let K be the dimension, and adjust the inner product to prevent it from becoming too large. Let i represent the label of the attention head. There are a total of q attention heads. i The final attention value obtained after SoftMax activation; The final comment text feature x′ is obtained by concatenating and calculating multiple attention values. The calculation formula is as follows: MultiHead=concat(head1,head2,…,head q )W O By concatenating multiple head values and then multiplying them by the weight matrix... H represents the vector dimension of the comment text features, and MultiHead represents the word embedding matrix of the comment text with dimension H. The first dimension, [CLS], is taken as the embedding vector of the comment text feature, and is defined as x′.
4. The social network comment text sentiment analysis method integrating user sentiment tendencies according to claim 3, characterized in that, The specific process of step 5 is as follows: A logistic regression model is constructed for sentiment prediction. First, a joint strategy is used to connect the user's sentiment tendency features and the comment text features to obtain the joint features of the target comment. The calculation formula is as follows: Where x′ i ,h′ i Let W3 and W4 be the text features of the i-th comment and the user sentiment features of the comment author, respectively. W3 and W4 are weight matrices with dimensions of [dimensions missing]. and h2 is the bias value, with dimensions of... Finally, we get c. i Let c be the joint feature of the i-th comment. There are M comments in total, so let c be the vector matrix of the joint feature of the comments, with dimension M. 2 represents a binary classification result; then, SoftMax activation is applied to c to obtain the predicted sentiment polarity, calculated using the following formula: y′=softmax(c) The predicted sentiment value y′ and the true sentiment label y are compared using the CrossEntropy loss function to calculate the loss value. The calculation formula is as follows: The model parameters are updated by backpropagation based on the loss value to obtain the optimized model with the minimum and stable loss value. Then, prediction analysis is performed on the test set, and the evaluation metric is MacroF1, the formula of which is: Among them, negprecision and negrecall are the precision and recall rates for correctly identifying the polarity as negative emotion, while posprecision and posrecall are the precision and recall rates for correctly identifying the polarity as positive emotion. Finally, MacroF1 is calculated as the evaluation index for sentiment analysis.
5. A social network comment text sentiment analysis system that integrates user emotional tendencies, characterized in that: include: The sentiment tendency calculation module calculates a user's sentiment tendency score based on the sentiment polarity distribution of comments posted on social networks, i.e., the number of friends the user has. The specific process is as follows: Comments from social network users are statistically analyzed, categorized into negative and positive comments based on their star rating. Assuming each user has p positive comments and n negative comments, the social relationships of the user are statistically analyzed, and their number is counted as f. The formula for calculating the sentiment tendency score is: Where N is the number of users, It is the number of social relationships of the i-th user. It is the number of positive comments from the i-th user. s is the number of negative comments from the i-th user. i This represents the sentiment score of the i-th user; The graph network structure building module of the user's social network uses the calculated sentiment scores s of all users. i Form a set s = {s1, s2, ..., s} N Let s be the set of user attribute information; count the social relationships between users i and j, and form combinations [i,j] with social relationships. Finally, construct an E×2 matrix A among the users, where E is the total number of edges. Matrix A represents the social relationship matrix between users, that is, a graph network structure that constructs a user-to-user social network; The user sentiment feature extraction module utilizes the Graph Attention Network (GAT) model to extract user sentiment features from the graph network structure. Among them, h j Let α be the initial node vector for the j-th user. ij h′ is the attention value between user i and user j, where user j is a neighbor of user i, and K are K attention heads; using the tanh activation function, h′ is obtained. i That is, the sentiment tendency feature of the i-th user, with dimensions of The comment text feature representation module uses the Transformers model to encode the comment text to obtain comment text features; The comment text feature model training module constructs a comment text feature model, trains the comment text feature model based on comment text and corpus, obtains all comment text features in the dataset, and summarizes and processes them to obtain a vector matrix of all comment text features in the data; The Joint Strategy Comment Sentiment Analysis module constructs a joint strategy comment sentiment analysis model. By fusing user sentiment characteristics and comment text characteristics through a joint strategy, the joint features of the comment are obtained. The joint strategy comment sentiment analysis model is iteratively trained, and the trained joint strategy comment sentiment analysis model is used to predict and analyze the sentiment polarity of comment texts on test data.
6. The social network comment text sentiment analysis system integrating user sentiment tendencies according to claim 5, characterized in that, The specific process of the comment text feature model training module is as follows: Define the initial node vector for each user as h, with dimension h. h = [f, p, n], and all users form a set h = {h1, h2, ..., hn}. N }, Based on the relationships in matrix A, construct matrix [h] i ,h j User j is a neighbor of user i. The importance of user j to user i, i.e., the attention value, is calculated using an attention mechanism. The specific steps are as follows: Where, α ij It is the attention value between user i and user j. These are the weight parameters of the feedforward neural network, and F is the dimension of the user-output vector. The weights of h are the values to be transformed first, || represents the concatenation operation, and the activation function is LeaKyReLU; The model employs a multi-head attention mechanism with K attention heads. Each attention head updates the vector of node i, and finally, all vectors of node i are concatenated and averaged to obtain the user sentiment feature h′. i .
7. The social network comment text sentiment analysis method integrating user sentiment tendencies according to claim 6, characterized in that, The specific process of the comment text feature model training module is as follows: For a comment text, add the [CLS] flag before the comment text and the [SEP] flag at the sentence breaks. Perform one-hot encoding on the comment text according to the authoritative Google NLP corpus to obtain the one-hot embedding of the comment text, defined as x. L is the sequence length. According to the Self-Attention principle of Transformers, x is used as input to calculate the embedding vector of the comment text. The calculation adopts a multi-head attention mechanism, and the single-head attention value calculation process is as follows: Among them W i Q W i K W i V The weight matrix has dimensions of . d k Let K be the dimension, and adjust the inner product to prevent it from becoming too large. Let i represent the label of the attention head. There are a total of q attention heads. i The final attention value obtained after SoftMax activation; The final comment text feature x′ is obtained by concatenating and calculating multiple attention values. The calculation formula is as follows: MultiHead=concat(head1,head2,…,head q )W O By concatenating multiple head values and then multiplying them by the weight matrix... H represents the vector dimension of the comment text features, and MultiHead represents the word embedding matrix of the comment text with dimension H. The first dimension, [CLS], is taken as the embedding vector of the comment text feature, and is defined as x′.
8. The method for sentiment analysis of social network comment text that integrates user sentiment tendencies according to claim 7, characterized in that, The specific process of the joint strategy comment sentiment analysis module is as follows: A logistic regression model is constructed for sentiment prediction. First, the user's sentiment tendency features and comment text features are connected through a joint strategy to obtain the joint features of the target comment. The calculation formula is as follows: Where x′ i ,h′ i Let W3 and W4 be the text features of the i-th comment and the user sentiment features of the comment author, respectively. W3 and W4 are weight matrices with dimensions of [dimensions missing]. and b2 is the bias value, with dimensions of... Finally, we get c. i Let c be the joint feature of the i-th comment. There are M comments in total, so let c be the vector matrix of the joint feature of the comments, with dimension M. 2 represents a binary classification result; then, SoftMax activation is applied to c to obtain the predicted sentiment polarity, calculated using the following formula: y′=softmax(c) The predicted sentiment value y′ and the true sentiment label y are compared using the CrossEntropy loss function to calculate the loss value. The calculation formula is as follows: The model parameters are updated by backpropagation based on the loss value to obtain the optimized model with the minimum and stable loss value. Then, prediction analysis is performed on the test set, and the evaluation metric is MacroF1, the formula of which is: Among them, negprecision and recall are the precision and recall rates for correctly identifying the polarity as negative emotion. Posprecision and posrecall are the precision and recall rates for correctly identifying positive sentiment polarity, respectively. Finally, MacroF1 is calculated as an evaluation metric for sentiment analysis.
Citation Information
Patent Citations
A Sentiment Analysis Method Based on Social Network Data
CN106096664B