A text sentiment analysis method and device combined with graph regularization
By extracting the correlation information of the training samples in the social network and introducing graph regularization, building a cross-entropy loss function and optimizing the text emotion classification model, the problem of insufficient accuracy of text emotion classification in social networks is solved, and high recognition accuracy under a small amount of data is achieved.
Patent Information
- Application Number
- CN202411678117.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-22
- Publication Date
- 2025-08-19
- Estimated Expiration
- 2044-11-22
AI Technical Summary
In the prior art, the accuracy of text sentiment classification in social networks is insufficient, especially when unstructured text and training data are insufficient, the recognition accuracy is low.
By extracting the correlation information between training samples, building a cross entropy loss function and introducing graph regularization terms, the text sentiment classification model is trained to minimize the prediction label gap of the associated training samples, and optimize the model to improve recognition accuracy.
While reducing the need for training data, the recognition accuracy of text sentiment classification is improved, and the model's recognition and generalization ability of unstructured text is enhanced.
Smart Images

Figure CN119179785B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of text recognition technology, and in particular to a text sentiment analysis method and device combined with graph regularization. Background Art
[0002] In recent years, with the rapid development of internet technology, numerous social networks have emerged, becoming a vital platform for users to disseminate information, learn about current events, and express their opinions. With a vast array of opinions, social networks have become a vast resource, attracting the attention of scholars, businesses, and governments. For example, companies can leverage the vast amount of data on social networks to understand user attitudes toward their products and improve them. Mining sentiment within social networks can detect emergencies online, providing opportunities for governments to guide public opinion. Faced with the massive and complex volume of text on social networks, conducting sentiment analysis to provide a data foundation for important applications such as recommendation systems and public opinion guidance has become a critical need.
[0003] Sentiment analysis, a branch of natural language processing, aims to classify text information into categories of positive, negative, neutral, or emotions such as joy, anger, sadness, or happiness. Currently, there are two main approaches to sentiment analysis. Dictionary-based sentiment analysis uses dictionaries such as WordNet and SenticNet to assign sentiment scores to words in a text. The final sentiment category of the text is then determined by combining the sentiment scores of all words. However, these approaches perform poorly in sentiment classification for text on social networks. This is because text on social networks is often unstructured and contains a large amount of non-standard expressions such as internet slang, special symbols, abbreviations, and typos. Sentiment dictionaries cannot accurately assign sentiment to non-standard expressions in text, nor can they handle the situation where the same word can have different sentiments in different contexts. Another approach is machine learning-based sentiment analysis. These methods use various feature extraction methods, such as bag-of-words and word embedding, to map text into vectors, which are then fed into machine learning models such as SVM, CNN, LSTM, and Transformer. However, machine learning-based sentiment analysis methods require a large amount of training data, and can suffer from overfitting when training data is insufficient.
[0004] It can be seen that the current sentiment classification of texts appearing in social networks has the problem of insufficient recognition accuracy. Summary of the Invention
[0005] In an embodiment of the present application, a text sentiment analysis method and apparatus combined with graph regularization are provided to solve the technical problem of low accuracy in sentiment classification of text appearing in social networks in the prior art.
[0006] To achieve the above objectives, the embodiments of the present application adopt the following technical solutions:
[0007] In a first aspect, an embodiment of the present application provides a text sentiment analysis method combined with graph regularization, the method comprising:
[0008] Obtaining training samples and true labels of the training samples;
[0009] Extracting association information between the training samples;
[0010] Constructing a cross entropy loss function based on the association information to measure the gap between the predicted label of the training sample and the true label;
[0011] On the basis of the cross entropy loss function, a graph regularization term is introduced, and the training goal is to minimize the gap between the predicted labels corresponding to two associated training samples, thereby training a text sentiment classification model;
[0012] The text to be identified is analyzed by the text sentiment classification model to determine the classification result.
[0013] In combination with the first aspect, in a possible design, the method further includes: obtaining a test sample and a true label of the test sample;
[0014] After the text sentiment classification model is obtained through training, the method further includes:
[0015] Using the text sentiment classification model, predicting the sentiment category probability of the test sample;
[0016] An MSE loss function is constructed between the target probability and the emotion category probability. Based on the MSE loss function, a graph regularization term is introduced again, and the text emotion classification model is optimized and tested with the goal of minimizing the gap between the target probabilities of two associated test samples.
[0017] In conjunction with the first aspect, in a possible design, the optimization test of the text sentiment classification model with the goal of minimizing the gap between the target probabilities of two associated test samples includes:
[0018] The MSE loss function is represented by a matrix, and the Lagrange multiplier method is applied to the matrixed MSE loss function to obtain a Lagrange function;
[0019] The FISTA algorithm is used to optimize the Lagrangian function, and the search point is iteratively updated to obtain an optimized MSE loss function. Based on the model parameters in the optimized MSE loss function, an optimized and tested text sentiment classification model is obtained.
[0020] In combination with the first aspect, in a possible design manner, constructing a cross entropy loss function based on the association information includes:
[0021] Determining whether the two training samples are associated based on the association information;
[0022] According to the fact that a first gap between the predicted labels corresponding to the two associated training samples is smaller than a first gap between the predicted labels corresponding to the two unassociated training samples, a cross entropy loss function is constructed.
[0023] In conjunction with the first aspect, in one possible design, extracting the association information between the training samples includes:
[0024] Extracting comparison results between users corresponding to the training samples;
[0025] The association information between the training samples is determined according to the comparison result.
[0026] In conjunction with the first aspect, in a possible design, extracting comparison results between users corresponding to the training samples includes:
[0027] For any two training samples: a comparison result is determined based on whether the two training samples are posted by the same user and whether the users corresponding to the two training samples are similar.
[0028] In conjunction with the first aspect, in one possible design, determining the association information between the training samples according to the comparison results includes:
[0029] If the comparison result indicates that the two users are the same or similar, the association information indicates that there is an association between the two training samples. If the comparison result indicates that the two users are not similar, the association information indicates that there is no association between the two training samples.
[0030] In a second aspect, an embodiment of the present application provides a text sentiment analysis device combined with graph regularization, comprising:
[0031] A sample acquisition module is used to obtain training samples and true labels of the training samples;
[0032] A correlation information extraction module, used to extract correlation information between the training samples;
[0033] A function construction module, configured to construct a cross entropy loss function based on the association information, for measuring the gap between the predicted label of the training sample and the true label;
[0034] A model training module is used to introduce a graph regularization term based on the cross entropy loss function, and to train a text sentiment classification model with the goal of minimizing the gap between the predicted labels corresponding to two associated training samples;
[0035] The model application module is used to analyze the text to be identified through the text sentiment classification model to determine the classification result.
[0036] In a third aspect, an embodiment of the present application provides a terminal comprising a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to execute the method of the first aspect and its possible design methods.
[0037] In a fourth aspect, an embodiment of the present application provides a storage medium storing a computer program, wherein the computer program is configured to execute the method of the first aspect and its possible design methods when running.
[0038] Compared with the existing technology, the method obtains training samples and the real labels of the training samples; extracts the correlation information between the training samples; constructs a cross-entropy loss function based on the correlation information to measure the gap between the predicted labels and the real labels of the training samples; introduces a graph regularization term on the basis of the cross-entropy loss function, and takes minimizing the gap between the predicted labels corresponding to two related training samples as the training goal to train a text sentiment classification model; analyzes the text to be recognized through the text sentiment classification model to determine the classification result. The present application extracts the correlation information between the two training samples, considers the influence of the correlation information on the sentiment analysis when training the model, and trains the model with minimizing the gap between the predicted labels corresponding to the related texts as the training goal. Therefore, the trained text sentiment classification model can recognize unstructured text and can achieve a high recognition accuracy without relying on a large number of samples, thereby solving the current problem of insufficient recognition accuracy in sentiment classification of text.
[0039] The details of one or more embodiments of the present application are set forth in the following drawings and description to make other features, objects, and advantages of the present application more readily apparent. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0041] Figure 1 The following is a block diagram showing the hardware structure of a terminal provided in an embodiment of the present application;
[0042] Figure 2A flowchart of a text sentiment analysis method combined with graph regularization provided in an embodiment of the present application is shown;
[0043] Figure 3 A flowchart of a method for testing a text sentiment classification model provided by an embodiment of the present application is shown;
[0044] Figure 4 A schematic diagram of a microblog sentiment analysis system combined with graph regularization provided in an embodiment of the present application is shown;
[0045] Figure 5 A flowchart of a method for executing a service based on sentiment classification provided by an embodiment of the present application is shown;
[0046] Figure 6 A flowchart of a method for extracting association relationships provided by an embodiment of the present application is shown;
[0047] Figure 7 A schematic diagram of a text sentiment analysis method combined with graph regularization provided in an embodiment of the present application is shown;
[0048] Figure 8 A structural block diagram of a text sentiment analysis device combined with graph regularization provided in an embodiment of the present application is shown. DETAILED DESCRIPTION
[0049] In order to more clearly understand the purpose, technical solutions and advantages of the present application, the present application is described and illustrated below in conjunction with the accompanying drawings and embodiments.
[0050] Unless otherwise defined, the technical terms or scientific terms involved in this application should have the general meaning understood by people with ordinary skills in the technical field to which this application belongs. The words "one", "an", "a", "the", "these" and the like in this application do not indicate quantitative restrictions, and they can be singular or plural. The terms "include", "comprise", "have" and any variants thereof involved in this application are intended to cover non-exclusive inclusions; for example, a process, method and system, product or device comprising a series of steps or modules (units) is not limited to the listed steps or modules (units), but may include unlisted steps or modules (units), or may include other steps or modules (units) inherent to these processes, methods, products or devices. The words "connect", "connected", "coupled" and the like involved in this application are not limited to physical or mechanical connections, but may include electrical connections, whether direct or indirect. The "plurality" involved in this application refers to two or more. "And / or" describes the relationship between related objects, indicating that three possible relationships exist. For example, "A and / or B" can represent: A exists alone, A and B exist simultaneously, and B exists alone. Generally, the character " / " indicates that the related objects are in an "or" relationship. The terms "first," "second," "third," etc. used in this application are only used to distinguish similar objects and do not represent a specific ordering of the objects.
[0051] Sentiment analysis technology stems from the need to efficiently utilize massive amounts of text and technological advancements. With the rapid development of internet technology, social networks have become a vast resource. Mining sentiment within social networks provides a data foundation for important applications such as recommendation systems and public opinion guidance. Most text on social networks is unstructured, containing numerous irregularities such as internet slang, special symbols, abbreviations, and typos. This results in low recognition accuracy, whether using sentiment dictionaries or machine learning.
[0052] Social networks have their own unique environmental factors. For example, if text posted by one user tends to be emotionally consistent, then text posted by similar users tends to be emotionally consistent. However, related technologies ignore the impact of social network environmental factors on text sentiment, resulting in poor sentiment analysis results.
[0053] In view of this, an embodiment of the present application provides a text sentiment analysis method combined with graph regularization. By extracting the correlation information between training samples, a text sentiment classification model is trained with the goal that the predicted labels corresponding to two related training samples should be consistent. In this way, the identified sentiment classification is more accurate, and the data analysis based on the classification results is more effective.
[0054] This method can be applied to social media regulation. For example, businesses and governments can use it to monitor public sentiment on social media and respond promptly to social hot spots and crises. It can also be used in marketing, for example, by analyzing consumer emotional responses to marketing campaigns to optimize advertising and promotional strategies. It can also be used to analyze the sentiment of competitors' social media activity to gain a competitive advantage. Furthermore, it can be applied to financial analysis, for example, by analyzing social media sentiment about the stock market, currency, or other financial products to assist in investment decisions. High accuracy in text sentiment classification yields better results in these scenarios.
[0055] This method can be executed on a terminal, a computer or a similar test system. Taking running on a terminal as an example, Figure 1 FIG1 shows a hardware structure block diagram of a terminal provided by an embodiment of the present application. Figure 1 As shown, the terminal may include one or more ( Figure 1 Only one is shown in the figure) processor 102, and memory 104 for storing data. Processor 102 may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA. The above terminal may also include a transmission device 106 and an input and output device 108 for communication functions. It will be understood by those skilled in the art that Figure 1 The structure shown is only for illustration and does not limit the structure of the above terminal. Figure 1 More or fewer components than shown, or with Figure 1 Different configurations shown.
[0056] The memory 104 can be used to store computer programs, such as software programs and modules of application software. The processor 102 executes various functional applications and data processing by running the computer programs stored in the memory 104, that is, to implement the above-mentioned method. The memory 104 can be used to store data, such as training samples, true labels, etc. The memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 104 may further include a memory remotely located relative to the processor 102, and these remote memories can be connected to the terminal via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0057] The transmission device 106 is used to receive or send data via a network. A specific example of the aforementioned network may include a wireless network provided by the terminal's communications provider. In one embodiment, the transmission device 106 includes a network interface controller (NIC), which can be connected to other network devices via a base station to enable communication with the Internet. In another embodiment, the transmission device 106 may be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.
[0058] Figure 2 A flowchart of a text sentiment analysis method combined with graph regularization provided by an embodiment of the present application is shown. Figure 2 As shown, the method includes steps S201 to S205.
[0059] Step S201: Obtain training samples and true labels of the training samples.
[0060] Among them, the training samples can be pre-processed texts. Specifically, the training samples are generated by converting the text symbols of the original text into English symbols, removing URL information, filtering out connection symbols and user names from Weibo, removing words such as "reply" and "forward Weibo" and forwarded content, etc.
[0061] Among them, the real label can be an emotional category marked manually or automatically, such as sad, happy, excited, calm, etc. These emotional categories can be represented by characters, such as sad corresponds to the number 1, happy corresponds to the number 2, excited corresponds to the number 3, and calm corresponds to the number 4.
[0062] The training samples and true labels obtained in step S201 are used to train a model to obtain a text sentiment classification model that can identify a classification result based on a text. The specific training process can be referred to the following description.
[0063] Step S202: extract the correlation information between training samples.
[0064] The association information between training samples refers to the set of association information between any two training samples in all training samples.
[0065] This step uses the sentiment labels corresponding to the associated texts to train the model so that it can learn richer features, such as those subtle sentiment differences that are difficult to extract directly from a single text, in order to strengthen feature learning. Not only that, by effectively utilizing the correlation between texts and borrowing label information between associated texts, the dependence on a large amount of labeled data can be reduced. In other words, the sentiment analysis method based on machine learning requires a large amount of training data, and when there is less training data, it will produce overfitting and other phenomena. This step helps to reduce the labeling cost by extracting the correlation information between the training samples, and at the same time there will be no overfitting problem, so the recognition accuracy of the trained model is high. In addition, when the number of samples of different emotion categories is unbalanced, the distribution of emotion labels can be balanced during the training process by extracting the correlation between the training samples, thereby enhancing the model's recognition ability for a minority of categories and improving the model's generalization ability.
[0066] The following further explains how to extract correlation information. The impact of correlation information on sentiment analysis is considered during model training: if correlation information exists between two training samples, the model's predicted sentiment labels tend to be similar. Based on this, the correlation information between each training sample is represented, either manually or automatically. If there is a correlation between two training samples, it is labeled as 1, and if there is no correlation between the two training samples, it is labeled as 0.
[0067] Specifically, extracting the association information between one training sample and another training sample includes: extracting a comparison result between the user corresponding to one training sample and the user corresponding to the other training sample; and determining the association information between the two training samples based on the comparison result. For example, the comparison result between users may include the same user, similar users, and users in the same social organization (e.g., family members, students, office workers), etc.
[0068] In some embodiments, based on the emotion consistency theory, whether two training samples are related is determined by whether they are posted by the same user, and the emotion labels of two related training samples tend to be consistent.
[0069] Specifically, if two training samples are posted by the same user, it is determined that there is a correlation between the two training samples, and thus the sentiment labels of the training samples posted by the same user tend to be consistent; conversely, if the two training samples are posted by different users, it is determined that there is no correlation between the two training samples.
[0070] More specifically, the training samples come from social platforms, so the user emotions corresponding to the training samples posted by the same user collected in a short period of time tend to be consistent. For example, a user posts multiple Weibo posts about a certain event on a certain day, and each Weibo post is equivalent to a training sample. The relevance of these training samples comes from the fact that they are posted by the same user, and the user's emotions when posting these Weibo posts tend to be consistent, so the emotional labels corresponding to these Weibo posts tend to be consistent.
[0071] In other embodiments, based on the theory of emotional contagion, whether two training samples are related is determined by whether they are posted by similar users, and the emotional labels of two related training samples tend to be consistent.
[0072] Specifically, if two training samples are posted by similar users, it is determined that there is a correlation between the two training samples, so the sentiment labels of the training samples posted by similar users tend to be consistent; conversely, if the two training samples are posted by dissimilar users, it is determined that there is no correlation between the two training samples.
[0073] More specifically, social platforms have their own unique environmental factors, that is, a group of people will post similar views on the same event or hot topic. For example, two students in the same class posted a Weibo about tutoring on the same day on the Weibo platform. These two Weibo posts are equivalent to two training samples. Since the two students in the same class are similar, and the correlation between these two training samples comes from the fact that they were posted by similar users, and the emotions of similar users when posting Weibo posts tend to be consistent, then the emotional labels corresponding to these Weibo posts tend to be consistent.
[0074] In some embodiments, a user relationship matrix can be established to represent the comparison results between users. This can be achieved through model training: if the comparison result indicates that two users are the same or similar, the association information indicates a relationship between the two training samples; if the comparison result indicates that the two users are dissimilar, the association information indicates no relationship between the two training samples. This trained model leverages label information from text posted by similar or identical users, maintaining a high recognition rate with a small amount of annotated data. This reduces reliance on the quantity and distribution of annotated data, resulting in improved model performance.
[0075] It should be noted that the above example of microblogs posted within a day is merely illustrative. In practice, the collection period can be one hour, one minute, six hours, half a month, one month, etc. Text (including input samples, test samples, and real-time text data) can be collected from social networks such as Weibo and Twitter, and this application does not impose any restrictions on this.
[0076] Step S203: construct a cross entropy loss function based on the association information to measure the gap between the predicted label and the true label of the training sample.
[0077] The true label refers to the annotated emotion category, while the predicted label refers to the probability of the training sample identified by the model under each emotion category. For example, the predicted label of the emotion identified by the model for a text is: sad 70%, happy 10%, excited happy 10%, calm 10%.
[0078] It can be understood that the smaller the gap between the predicted label and the true label, the closer the model's prediction is to the true label. Conversely, the larger the gap between the predicted label and the true label, the farther the model's prediction is from the true label. During the training process, by minimizing the cross-entropy loss, the model parameters are continuously adjusted to make the model better fit the training data.
[0079] Step S204: Based on the cross entropy loss function, a graph regularization term is introduced, and the training goal is to minimize the gap between the predicted labels corresponding to two related training samples, so as to obtain a text sentiment classification model through training.
[0080] Part of the cross-entropy loss function is the difference between the predicted labels for two related training samples. Therefore, minimizing the cross-entropy loss function can be seen as minimizing the difference between the predicted labels for two related training samples. As mentioned above, the impact of correlation information on sentiment analysis is considered during model training: if there is correlation information between two training samples, the sentiment labels predicted by the model tend to be similar. Therefore, in this step, the model is trained with the goal of minimizing the difference between the predicted labels for related texts. This ensures that the trained model can maintain a high recognition accuracy even when the number of samples is insufficient or the number of samples is biased.
[0081] Among them, on the basis of the cross entropy loss function, introducing the graph regularization term means that the cross entropy loss function used to train the model includes the graph regularization term. For the construction method of the cross entropy loss function, please refer to the description of step S505 below.
[0082] Step S205: Analyze the text to be recognized through the text sentiment classification model to determine the classification result.
[0083] The classification result refers to the probability of the training samples identified by the model under each emotion category. For example, the model identifies the predicted labels of the emotion of a text as: sad 70%, happy 10%, excited happy 10%, and calm 10%.
[0084] The trained text sentiment classification model has a good recognition accuracy, and the classification results obtained by sentiment classification of the text to be recognized are closer to the true label of the text.
[0085] In the embodiment recorded in the above steps S201 to S205, by obtaining training samples and the true labels of the training samples; extracting the correlation information between the training samples; constructing a cross-entropy loss function based on the correlation information to measure the gap between the predicted labels and the true labels of the training samples; on the basis of the cross-entropy loss function, introducing a graph regularization term, and taking minimizing the gap between the predicted labels corresponding to two related training samples as the training goal, a text sentiment classification model is trained; the text to be recognized is analyzed by the text sentiment classification model to determine the classification result. The present application extracts the correlation information between the two training samples, and considers the influence of the correlation information on the sentiment analysis when training the model, and trains the model with minimizing the gap between the predicted labels corresponding to the related texts as the training goal. Therefore, the trained text sentiment classification model can recognize unstructured text and can achieve a high recognition accuracy without relying on a large number of samples, thereby solving the problem of insufficient recognition accuracy in the current sentiment classification of text.
[0086] In some embodiments, a test sample and a true label of the test sample are also obtained. After the above step S204, the text sentiment classification model is tested based on the test sample to further improve the recognition accuracy of the text sentiment classification model. Figure 3 A flowchart of a method for testing a text sentiment classification model provided by an embodiment of the present application is shown. Figure 3 As shown, the method includes step S301 and step S302.
[0087] Step S301: Use the text sentiment analysis model to predict the sentiment category probability of the test sample.
[0088] Step S302: construct an MSE loss function between the target probability and the emotion category probability. Based on the MSE loss function, introduce the graph regularization term again, and optimize the text emotion classification model with the goal of minimizing the gap between the target probabilities of two related test samples.
[0089] Among them, the MSE loss function is used to characterize the sum of the first distance and the second distance. The first distance refers to the difference between the predicted label output by each test sample in the test phase and the predicted label output in the training phase. The second distance refers to the difference between the predicted labels corresponding to two related test samples.
[0090] Specifically, the impact of the correlation information between texts on the sentiment analysis results is also considered in the testing phase. Specifically, if there is a correlation between two texts, the predicted labels output by the text sentiment classification model should tend to be similar. Therefore, the optimization goal is to minimize the sum of the first distance and the second distance to further optimize the model parameters of the text sentiment classification model, so that the recognition results of the text sentiment classification model after the test optimization are more accurate.
[0091] It is understandable that related technologies often use minimizing the first distance as the optimization goal. Specifically, when the gap between the predicted label output for each test sample during the testing phase and the predicted label output during the training phase is small, the model is considered optimized. This results in low recognition accuracy when performing sentiment classification on text in social networks. This embodiment considers the impact of correlation information between texts on sentiment analysis results, introduces a second distance into the MSE loss function, and minimizes the sum of the first and second distances as the optimization goal. This allows the model obtained from the optimized test to maintain high accuracy and generalization even with a small number of samples and uneven distribution.
[0092] In some embodiments, the second distance in the above step S301 is represented by a quadratic loss function with a first weight and a regularization term with a second weight; step S302 further includes: optimizing the MSE loss function with the regularization term based on the FISTA algorithm, with the goal of minimizing the regularization term in the MSE loss function, to obtain an optimized MSE loss function; and testing the text sentiment classification model based on the optimized MSE loss function.
[0093] Specifically, the MSE loss function is represented by a matrix, and the Lagrange multiplier method is applied to the matrixed MSE loss function to obtain the Lagrangian function; the FISTA algorithm is used to optimize the Lagrangian function, and the search point is iteratively updated to obtain the optimized MSE loss function.
[0094] In this embodiment, the MSE loss function is optimized using the FISTA algorithm. FISTA leverages the results of previous iterations in each iteration, accelerating convergence to the optimal solution and significantly improving convergence speed. Furthermore, in each iteration, FISTA forces certain coefficients to zero through a thresholding step, directly achieving a sparse solution. This reduces unnecessary features and improves the model's generalization ability to unseen data, thereby avoiding overfitting of the trained model and improving the model's recognition accuracy.
[0095] The following uses a microblog as an example to further illustrate the method of the embodiment of the present application. Figure 4 A schematic diagram of a microblog sentiment analysis system combined with graph regularization provided in an embodiment of the present application is shown in FIG. Figure 4 Shown, including:
[0096] The text preprocessing module 41 preprocesses the collected original microblogs to obtain microblog samples (hereinafter referred to as microblogs). For the preprocessing steps, please refer to the description of step S201 above.
[0097] The microblog association extraction module 42 calculates the microblog association information from the user microblog relationship matrix and the user relationship matrix through the emotion consistency and emotion contagion theory. For the steps of extracting the association information, please refer to the description of step S202 above.
[0098] Model training module 43 based on graph regularization: Combined with the text content of Weibo, the model optimization target is regularized by taking advantage of the fact that Weibo with related relationships tend to have the same emotional labels, and the model is trained. For the process of training the model, please refer to the description of steps S203 to S204 above.
[0099] Model testing module 44 based on graph regularization: considers the correlation between test data during testing, and further optimizes the test set sentiment labels output by the model. For the test steps, please refer to the description of steps S301 to S302 above.
[0100] The above is a brief description of the analysis system. The following text will continue to describe and illustrate the method of using the analysis system to perform sentiment analysis using Weibo as an example.
[0101] Figure 5 A flowchart of a service execution method based on emotion classification provided by an embodiment of the present application is shown as follows: Figure 5 As shown, the method includes:
[0102] Step S501: pre-process the microblog.
[0103] Among them, the preprocessed data set is represented as X dataset , and the sentiment label corresponding to the dataset is represented as Y dataset , the preprocessed data corresponding to the i-th text is x i , the sentiment label corresponding to the i-th text is represented as y i .
[0104] Extract the preprocessed microblog text features, denoted as F dataset , the feature extracted from the i-th text is represented as f i .
[0105] Step S502: extracting correlation information between microblogs.
[0106] Among them, the correlation information is represented by matrix C, C ij =1 means if and only if there is a correlation between the i-th text and the j-th text. Figure 6 A flowchart of a method for extracting association relationships provided by an embodiment of the present application is shown. Figure 6 , step S502 may further include:
[0107] S502a. Extract correlation relationships based on the emotional consistency theory in sociology.
[0108] Specifically, if two microblogs are posted by the same user on the same topic, then the sentiment labels of the two microblogs are more likely to be consistent. Assuming that the user microblog relationship matrix is U, the microblog relationship matrix C is obtained from the sentiment consistency theory sc =U T U, If and only if the i-th text and the j-th text are posted by the same user.
[0109] S502b. Extract correlation relationships based on the emotional contagion theory in sociology.
[0110] Specifically, if two microblogs are posted by similar users on the same topic, then the emotional labels of the two microblogs are more likely to be consistent. Assuming that the user microblog relationship matrix is U and the user relationship matrix is F, the matrix C is obtained from the emotional contagion theory ec =U T FU, If and only if the i-th text and the j-th text are posted by similar users.
[0111] S502c. Combining the emotion consistency theory and the emotion contagion theory, obtain the microblog related information matrix.
[0112] The microblog related information matrix is calculated based on the theory of emotional consistency and emotional contagion, that is, C = C ec +C sc .
[0113] The above explains how to extract correlation relationships. After obtaining the correlation relationships, the impact of the correlation relationships on sentiment analysis is considered during model training. Specifically, if two Weibo posts are related, the sentiment labels predicted by the machine model should be similar, so modeling is performed accordingly. Please refer to the following instructions for details.
[0114] S503: Build a model based on the correlation information matrix.
[0115] The optimization goals of building a relational model are: in represents the sentiment label predicted by the machine, and c represents the category of the sentiment label.
[0116] S504: Modeling based on Weibo content.
[0117] S505: Combine the relationship model and the microblog content model to train a text sentiment analysis model.
[0118] Specifically, the objective function of the model is:
[0119]
[0120] Where α represents the weight of graph regularization, N represents the number of microblogs, and θ represents the parameters of the machine model.
[0121] S506: Test the text sentiment analysis model by combining the relationship model and the microblog content model.
[0122] Similar to step S503, if there is correlation information between the two microblogs, the sentiment labels predicted by the model should be similar. The optimization goal of this process is:
[0123]
[0124] In the testing phase, in order to simultaneously utilize text content information, a linear optimizer is constructed. The optimization objectives of this process are:
[0125]
[0126] Among them, α and β represent the weights of different graph regularizations. Represents the final output sentiment label of the test phase, The sentiment labels predicted by the machine refer to the sentiment labels obtained by testing using only the model obtained in the training phase.
[0127] S507. Optimize model test results.
[0128] Specifically, this step is used to optimize the function proposed in S506 using the FISTA algorithm, and specifically includes the following steps:
[0129] The function mentioned in S506 is expressed in a matrix form, and we get:
[0130]
[0131] in, N nz represents the number of non-zero elements in the Weibo relationship matrix C. Assume that C ij is non-zero and ranks nth among all elements of C, then A ni =C ij , A nj =-C ij , all other elements in the nth row of A are 0.
[0132] Then transform the matrix function to get:
[0133]
[0134] Applying the Lagrange multiplier method to the transformed function gives the Lagrange function:
[0135]
[0136] Where μ is the Lagrange multiplier vector and ρ is a positive penalty factor.
[0137] Furthermore, in order to improve the optimization speed, the Lagrangian function is split into two parts, f(z) and g(z), where:
[0138]
[0139] The function becomes min z f(z)+g(z).
[0140] Then use the FISTA algorithm to optimize the function and iteratively update the search point:
[0141] w k+1 =z k +θ k (z k -z k-1 )
[0142] Among them, θ k Represents the linear combination coefficient in the iterative process. The approximate search point z is obtained by the formula
[0143]
[0144] Update, 1 / L k >0 represents the step size of gradient descent, and we get:
[0145]
[0146] because The approximate search point can be transformed into:
[0147]
[0148] Gradient descent step size 1 / L k By satisfying the following formula:
[0149]
[0150] To choose.
[0151] Then pass Update v t , where S is the soft threshold function.
[0152] Finally through ut =u t-1 +AX t -v t Update u t .
[0153] An embodiment of the present application provides a method for sentiment analysis that combines graph regularization and the correlation between microblogs. This method improves the model training and testing stages by utilizing the correlation information of microblogs, thereby improving the effect of microblog sentiment analysis. At the same time, the optimization of the regularization term by the FISTA algorithm improves the iteration speed, accelerates convergence, and increases the generalization of the model.
[0154] Continue to refer Figure 4 The above-mentioned text preprocessing module 41 is used to execute the above step S501.
[0155] The microblog association relationship extraction module 42 is used to execute the above step S502.
[0156] The above-mentioned graph regularization-based model training module 43 is used to execute the above steps S503 to S505.
[0157] The graph regularization-based model testing module 44 is used to execute the above steps S506 to S507.
[0158] Figure 7 A schematic diagram of a text sentiment analysis method combined with graph regularization provided in an embodiment of the present application is shown in FIG. Figure 7 As shown, the method provided in the embodiment of the present application preprocesses text features and extracts Weibo text relationships, models Weibo text relationships, inputs text features and text relationships into sentiment classifier training, and tests the sentiment classifier with the text to be tested, and then optimizes the test results based on the text relationships, and finally outputs the sentiment analysis results. Through this method, the problem of insufficient recognition accuracy in sentiment classification of texts appearing in social networks is solved.
[0159] The present application also provides an embodiment of a text sentiment analysis device combined with graph regularization, which is used to implement the above-mentioned embodiments and preferred implementation modes, and will not be repeated hereafter. The terms "module", "unit", "sub-unit", etc. used below may refer to a combination of software and / or hardware that implements predetermined functions. Although the devices described in the following embodiments are preferably implemented in software, implementation in hardware, or a combination of software and hardware, is also possible and conceivable.
[0160] Figure 8 A structural block diagram of a text sentiment analysis device combined with graph regularization provided in an embodiment of the present application is shown. Figure 8 As shown, the device includes:
[0161] The sample acquisition module 81 is used to obtain training samples and true labels of the training samples.
[0162] The correlation information extraction module 82 is used to extract the correlation information between training samples.
[0163] The function construction module 83 is used to construct a cross entropy loss function based on the association information, which is used to measure the gap between the predicted label and the true label of the training sample.
[0164] The model training module 84 is used to introduce a graph regularization term based on the cross entropy loss function, and to train a text sentiment classification model with the goal of minimizing the gap between the predicted labels corresponding to two associated training samples.
[0165] The model application module 85 is used to analyze the text to be identified through the text sentiment classification model and determine the classification result.
[0166] In some embodiments, the association information extraction module 82 is further used to determine whether two training samples are associated based on the association information; and construct a cross-entropy loss function based on the first gap between the predicted labels corresponding to the two associated training samples being smaller than the first gap between the predicted labels corresponding to the two unassociated training samples.
[0167] In some embodiments, the association information extraction module 82 is further configured to extract comparison results between users corresponding to the training samples; and determine association information between the training samples based on the comparison results.
[0168] In some embodiments, the associated information extraction module 82 is further configured to determine a comparison result based on whether the two training samples are posted by the same user and whether the users corresponding to the two training samples are similar.
[0169] In some embodiments, the association information extraction module 82 is further configured to: if the comparison result indicates that the two users are the same or similar, then the association information indicates that there is an association between the two training samples; if the comparison result indicates that the two users are not similar, then the association information indicates that there is no association between the two training samples.
[0170] It should be noted that the above modules can be functional modules or program modules, and can be implemented through software or hardware. For modules implemented through hardware, the above modules can be located in the same processor; or the above modules can be located in different processors in any combination.
[0171] It should be noted that the above modules can be functional modules or program modules, and can be implemented through software or hardware. For modules implemented through hardware, the above modules can be located in the same processor; or the above modules can be located in different processors in any combination.
[0172] This embodiment further provides an electronic device, including a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.
[0173] Optionally, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor, and the input / output device is connected to the processor.
[0174] Optionally, in this embodiment, the processor may be configured to execute the following steps S1 to S5 through a computer program.
[0175] S1. Obtain training samples and the true labels corresponding to the training samples.
[0176] S2. Extract the correlation information between training samples.
[0177] S3. Construct a cross entropy loss function based on the correlation information to measure the gap between the predicted label and the true label of the training sample.
[0178] S4. Based on the cross-entropy loss function, a graph regularization term is introduced, and the training goal is to minimize the gap between the predicted labels corresponding to two related training samples to obtain a text sentiment classification model.
[0179] S5. Analyze the text to be identified through the text sentiment classification model to determine the classification result.
[0180] It should be noted that, for specific examples in this embodiment, reference may be made to the examples described in the above embodiments and optional implementation modes, and will not be repeated in this embodiment.
[0181] In addition, in conjunction with the methods provided in the above embodiments, a storage medium may also be provided in this embodiment to implement the method. The storage medium stores a computer program; when the computer program is executed by a processor, it implements any of the text sentiment analysis methods combined with graph regularization in the above embodiments.
[0182] The embodiment of the present application further provides a computer program product. When the computer program product is run on a computer, it enables the computer to execute the various functions or steps executed by the processor in the above method embodiment.
[0183] It should be understood that the specific embodiments described herein are only used to explain this application and are not used to limit it. Based on the embodiments provided in this application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0184] Obviously, the accompanying drawings are merely examples or embodiments of the present application. A person skilled in the art can also apply the present application to other similar situations based on these drawings without inventive effort. Furthermore, it is understandable that, although the work involved in this development process may be complex and lengthy, certain design, manufacturing, or production changes based on the technical content disclosed in this application are merely routine technical means for a person skilled in the art and should not be considered to constitute a deficiency in the disclosure of the present application.
[0185] The term "embodiment" as used in this application refers to specific features, structures, or characteristics described in conjunction with the embodiment that can be included in at least one embodiment of this application. The appearance of this phrase in various places in the specification does not necessarily mean that the embodiment is the same, nor does it mean that it is mutually exclusive with other embodiments and is independent or optional. It is understood, either explicitly or implicitly, by those skilled in the art that the embodiments described in this application can be combined with other embodiments when there is no conflict.
[0186] The above embodiments merely illustrate several implementation methods of the present application. While the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the patent. It should be noted that a person skilled in the art could make various modifications and improvements without departing from the spirit of the present application, all of which fall within the scope of protection of the present application. Therefore, the scope of protection of the present application shall be determined by the appended claims.
Claims
1. A text sentiment analysis method combined with graph regularization, characterized in that: The method comprises: Obtaining training samples, true labels of the training samples, and test samples; Extract the correlation information between all samples and annotate the samples with correlation information; wherein the correlation information is obtained by comparing whether they are posted by the same user, similar users, or users in the same social organization; Constructing a cross entropy loss function to measure the gap between the predicted label of the training sample and the true label; Based on the cross entropy loss function, a graph regularization term is introduced, and the training goal is to minimize the gap between the predicted labels corresponding to two related training samples, thereby training a text sentiment classification model; Utilize the text sentiment classification model to predict the sentiment category probability of the test sample and obtain the initial predicted sentiment category probability of each test sample; optimize the initial predicted sentiment category probability based on the association information to obtain the optimized initial predicted sentiment category probability, wherein the optimization method includes: initializing all the optimized initial predicted sentiment category probabilities; constructing the MSE loss function of the optimized initial predicted sentiment category probability and the initial predicted sentiment category probability; calculating the sum of the MSE loss function and the test graph regularization term constructed based on the association information to obtain the target test loss function; wherein the test graph regularization term is the weighted sum of two graph regularization terms, wherein the first graph regularization term is the sum of the absolute values of the differences of the initial predicted sentiment category probabilities of all associated texts after optimization, and the second graph regularization term is the sum of the squares of the differences of the initial predicted sentiment category probabilities of all associated texts after optimization; The target test loss function is optimized using the Lagrange multiplier method and the FISTA algorithm to obtain the target emotion type classification results, including: The target test loss function is represented by a matrix, and the Lagrangian multiplier method is applied to the matrixed target test loss function to obtain the Lagrangian function; the FISTA algorithm is used to optimize the Lagrangian function, and the search point is iteratively updated to obtain the optimized target prediction emotion category probability, and the classification with the largest probability among the optimized target prediction emotion category probabilities is taken as the target emotion type classification result.
2. The text sentiment analysis method combined with graph regularization according to claim 1, characterized in that The constructing a cross entropy loss function based on the association information includes: Determining whether the two training samples are associated based on the association information; According to the fact that a first gap between the predicted labels corresponding to the two associated training samples is smaller than a first gap between the predicted labels corresponding to the two unassociated training samples, a cross entropy loss function is constructed.
3. The text sentiment analysis method combined with graph regularization according to any one of claims 1 to 2, characterized in that: The extracting the association information between the training samples includes: Extracting comparison results between users corresponding to the training samples; The association information between the training samples is determined according to the comparison result.
4. The text sentiment analysis method combined with graph regularization according to claim 3, characterized in that: The extracting comparison results between users corresponding to the training samples includes: For any two training samples: a comparison result is determined based on whether the two training samples are posted by the same user and whether the users corresponding to the two training samples are similar.
5. The text sentiment analysis method combined with graph regularization according to claim 3, characterized in that: Determining the association information between the training samples according to the comparison results includes: If the comparison result indicates that the two users are the same or similar, the association information indicates that there is an association between the two training samples. If the comparison result indicates that the two users are not similar, the association information indicates that there is no association between the two training samples.
6. A text sentiment analysis device combined with graph regularization, characterized in that: include: A sample acquisition module is used to obtain training samples, true labels of the training samples, and test samples; The associated information extraction module is used to extract the associated information between all samples and annotate the samples with associated information. The associated information is obtained by comparing whether the samples are posted by the same user, similar users, or users in the same social organization. A function construction module, used to construct a cross entropy loss function, used to measure the gap between the predicted label of the training sample and the true label; A model training module is used to introduce a graph regularization term based on the cross entropy loss function, and to train a text sentiment classification model with the goal of minimizing the gap between the predicted labels corresponding to two associated training samples; A classification result testing module is used to use the text sentiment classification model to predict the sentiment category probability of the test sample and obtain the initial predicted sentiment category probability of each test sample; optimize the initial predicted sentiment category probability based on the associated information to obtain the optimized initial predicted sentiment category probability, wherein the optimization method includes: initializing all the optimized initial predicted sentiment category probabilities; constructing an MSE loss function of the optimized initial predicted sentiment category probability and the initial predicted sentiment category probability; calculating the sum of the MSE loss function and the test graph regularization term constructed based on the associated information to obtain a target test loss function; wherein the test graph regularization term is a weighted sum of two graph regularization terms, wherein the first graph regularization term is the sum of the absolute values of the differences between the initial predicted sentiment category probabilities of all associated texts after optimization, and the second graph regularization term is the sum of the squares of the differences between the initial predicted sentiment category probabilities of all associated texts after optimization; The target test loss function is optimized using the Lagrange multiplier method and the FISTA algorithm to obtain the target emotion type classification results, including: The target test loss function is represented by a matrix, and the Lagrangian multiplier method is applied to the matrixed target test loss function to obtain the Lagrangian function; the FISTA algorithm is used to optimize the Lagrangian function, and the search point is iteratively updated to obtain the optimized target prediction emotion category probability, and the classification with the largest probability among the optimized target prediction emotion category probabilities is taken as the target emotion type classification result.
7. A terminal comprising a memory, a processor and a display screen, characterized in that: A computer program is stored in the memory, and the processor is configured to run the computer program to perform the text sentiment analysis method combined with graph regularization according to any one of claims 1 to 5.
8. A storage medium, characterized in that: The storage medium stores a computer program, wherein the computer program is configured to execute the text sentiment analysis method combined with graph regularization according to any one of claims 1 to 5 when running.
Citation Information
Patent Citations
Emotion data classifying method and system
CN104199829A
Text recognition method and device based on intersection-parallel ratio loss optimization model
CN114997153A