A method, device, equipment and readable storage medium for analyzing sentiment polarity
The sentiment analysis model, composed of feature extraction and neural network models, solves the problems of low efficiency and low accuracy in sentiment polarity analysis on social media, achieving efficient and accurate sentiment polarity analysis and providing detailed sentiment analysis results and visualizations.
Patent Information
- Application Number
- CN202210360748.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-04-07
- Publication Date
- 2024-11-08
- Estimated Expiration
- 2042-04-07
AI Technical Summary
Existing technologies for analyzing the sentiment polarity of social media are inefficient and inaccurate, making it difficult to effectively handle rapidly updated and personalized, colloquial social media comments.
A sentiment analysis model consisting of a feature extraction model and a neural network model is used. The feature extraction model generates feature vectors of the text to be analyzed, and the neural network model outputs the sentiment polarity. Preprocessing and a polarity dictionary are combined to train the model to improve the accuracy and efficiency of the analysis.
It improves the accuracy and efficiency of sentiment polarity analysis, enabling more accurate acquisition of the sentiment polarity of the object being analyzed. The analysis results are more comprehensive and visually presented, intuitively indicating the reasons for the sentiment.
Smart Images

Figure CN114706954B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and in particular to a sentiment polarity analysis method, device, equipment and readable storage medium. Background Art
[0002] Social media is a virtual community and network platform for people to create, share, and exchange opinions, views, and experiences. Therefore, social media generates a large number of valuable comments about people, events, products, etc., which are participated by users. These comments express people's various emotional colors and emotional tendencies, such as joy, anger, sadness, happiness, criticism, praise, etc. Based on this, the emotional polarity analysis of comments helps to obtain the public opinion on a certain object (event or product).
[0003] Since the speech generated by social media is characterized by fast updating, personalization, and colloquialism, the traditional sentiment polarity analysis method has low efficiency and low accuracy. Therefore, how to improve the efficiency and accuracy of the sentiment polarity analysis method is a technical problem that needs to be urgently solved by technical personnel in this field. Summary of the invention
[0004] The present application provides a sentiment polarity analysis method, apparatus, device, and readable storage medium, as follows:
[0005] Acquire multiple texts to be analyzed, where the texts to be analyzed are texts related to the object to be analyzed;
[0006] Inputting the text to be analyzed into a sentiment analysis model to obtain the sentiment polarity of the text to be analyzed output by the sentiment analysis model, wherein the sentiment polarity is one of preset polarities, and the preset polarities include positive, neutral, and negative;
[0007] The sentiment analysis model includes a feature extraction model and a neural network model, wherein the feature extraction model is used to generate a feature vector of the text to be analyzed, and the neural network model is used to take the feature vector of the text to be analyzed as input and output the sentiment polarity of the text to be analyzed;
[0008] According to the sentiment polarity of each of the texts to be analyzed, a sentiment analysis result of the object to be analyzed is obtained, wherein the sentiment analysis result includes the sentiment polarity.
[0009] Optionally, the sentiment analysis model also includes:
[0010] A coding model, wherein the coding model is used to obtain a text vector of the text to be analyzed, and the coding model includes a GloVe model;
[0011] The feature extraction model is an LSTM model, and the neural network model is a convolutional neural network model; the LSTM model is used to extract long-distance features of the text vector of the text to be analyzed, generate and output the feature vector of the text to be analyzed, and the feature extraction model includes the LSTM model.
[0012] Optionally, before inputting the text to be analyzed into the sentiment analysis model to obtain the sentiment polarity of the text to be analyzed output by the sentiment analysis model, the method further includes:
[0013] Acquire a preset text associated with the text to be analyzed as a sample text;
[0014] Based on a preset polarity dictionary, obtaining the sentiment polarity of the sample text;
[0015] The sample text is input into the initial model of the sentiment analysis model, the sentiment polarity of the sample text is used as the target output, the initial model is trained, and the sentiment analysis model is obtained.
[0016] Optionally, the polarity dictionary includes a correspondence between preset words, word attributes, and polarity values, wherein the word attributes include positive words, negative words, and neutral words;
[0017] The acquiring the sentiment polarity of the sample text based on a preset polarity dictionary includes:
[0018] Performing a preset preprocessing on the sample text to obtain a word segmentation set of the sample text, wherein the word segmentation set includes at least one word segmentation, and the preprocessing includes data cleaning and word segmentation operations;
[0019] According to the word attribute of the word segmentation, query from the polarity dictionary to obtain the polarity value of the word segmentation;
[0020] Calculating the polarity value of the sample text according to the polarity value of each of the segmented words;
[0021] The sentiment polarity of the sample text is obtained according to the polarity value of the sample text.
[0022] Optionally, obtain multiple texts to be analyzed, including:
[0023] Acquire key information of the object to be analyzed, wherein the key information includes name and object attributes;
[0024] A web crawler is used to obtain texts published on preset social media that meet preset crawling rules as texts to be analyzed. The crawling rules include: containing the key information and having a heat greater than a preset heat threshold.
[0025] Optionally, obtaining a sentiment analysis result of the object to be analyzed according to the sentiment polarity of each of the texts to be analyzed includes:
[0026] Obtaining preset measurement values of each of the sentiment polarities;
[0027] Obtaining a statistical value of a measure of sentiment polarity of each of the texts to be analyzed, wherein the statistical value includes any one of an arithmetic mean, a weighted mean, and a mode;
[0028] The sentiment polarity of the object to be analyzed is determined according to the statistical value.
[0029] Optionally, the sentiment analysis result also includes a feature word and a feature type of any sentiment polarity; and obtaining the sentiment analysis result of the object to be analyzed according to the sentiment polarity of each of the texts to be analyzed further includes:
[0030] Extracting keywords from a first type of text, where the first type of text is text to be analyzed whose sentiment polarity is a first polarity, where the first polarity is any sentiment polarity;
[0031] The keywords whose frequency is greater than a preset frequency threshold are used as the feature words of the first polarity;
[0032] All the keywords are clustered to obtain at least one keyword set and a type of the keyword set, and the type of the keyword set is used as a feature type of the first polarity.
[0033] A device for analyzing sentiment polarity, comprising:
[0034] A text acquisition unit, used to acquire a plurality of texts to be analyzed, wherein the texts to be analyzed are texts related to the object to be analyzed;
[0035] A model prediction unit, used for inputting the text to be analyzed into a sentiment analysis model to obtain the sentiment polarity of the text to be analyzed output by the sentiment analysis model, wherein the sentiment polarity is one of preset polarities, and the preset polarities include positive, neutral, and negative;
[0036] The sentiment analysis model includes a feature extraction model and a neural network model, wherein the feature extraction model is used to generate a feature vector of the text to be analyzed, and the neural network model is used to take the feature vector of the text to be analyzed as input and output the sentiment polarity of the text to be analyzed;
[0037] The analysis result acquisition unit is used to acquire the sentiment analysis result of the object to be analyzed according to the sentiment polarity of each text to be analyzed, and the sentiment analysis result includes the sentiment polarity.
[0038] A device for analyzing sentiment polarity, comprising: a memory and a processor;
[0039] The memory is used to store programs;
[0040] The processor is used to execute the program to implement each step of the sentiment polarity analysis method.
[0041] A readable storage medium stores a computer program, which, when executed by a processor, implements various steps of a method for analyzing sentiment polarity.
[0042] It can be seen from the above technical scheme that the present application provides a method, device, equipment and readable storage medium for analyzing sentiment polarity, obtains multiple texts to be analyzed, inputs the texts to be analyzed into the sentiment analysis model, and obtains the sentiment polarity of the texts to be analyzed output by the sentiment analysis model, where the sentiment polarity is one of the preset polarities, and the preset polarities include positive, neutral, and negative. Further, according to the sentiment polarity of each text to be analyzed, the sentiment analysis result of the object to be analyzed is obtained. Since the sentiment analysis model includes a feature extraction model and a neural network model, wherein the feature extraction model is used to generate a feature vector of the text to be analyzed, and the neural network model is used to output the sentiment polarity of the text to be analyzed with the feature vector of the text to be analyzed as input. It can be seen that the sentiment analysis model pre-generates the feature vector of the text to be analyzed through the feature extraction model, and then outputs the result according to the feature vector through the neural network model, thereby improving the accuracy and efficiency of obtaining the sentiment polarity of the text to be analyzed. Further, since the text to be analyzed is a text related to the object to be analyzed, the sentiment analysis result includes the sentiment polarity, and therefore, the accuracy of the sentiment polarity of the object to be analyzed obtained through the sentiment polarity of multiple texts to be analyzed is high. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0044] Figure 1 A flowchart of a specific implementation method of a sentiment polarity analysis method provided in an embodiment of the present application;
[0045] Figure 2 A schematic diagram of a method for training a sentiment analysis model provided in an embodiment of the present application;
[0046] Figure 3 A schematic diagram of a flow chart of a method for analyzing sentiment polarity provided in an embodiment of the present application;
[0047] Figure 4 A schematic diagram of the structure of a sentiment polarity analysis device provided in an embodiment of the present application;
[0048] Figure 5 A schematic diagram of the structure of a sentiment polarity analysis device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0049] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0050] It should be noted that the analysis method, device, equipment and readable storage medium of sentiment polarity provided by the present invention can be used in the field of artificial intelligence or finance. The above is only an example and does not limit the application field of the analysis method, device, equipment and readable storage medium of sentiment polarity provided by the present invention.
[0051] Specifically, the method for analyzing sentiment polarity provided in the embodiment of the present application is applied to, but not limited to, the process of conducting public opinion analysis on public statements generated by social media or conducting research on products. Taking the application scenario of conducting public opinion analysis on public statements generated by social media as an example, public opinion on specific objects (events, people, or regions, etc.) can be obtained through sentiment analysis of public statements. The user objects of social media are different, and the language of their public statements will be different, which is not limited in this embodiment. The method for analyzing sentiment polarity provided in the embodiment of the present application is applicable to smart mobile devices (such as smart phones or smart tablets), computers, or servers (single servers or server clusters).
[0052] Figure 1 A specific implementation method of a sentiment polarity analysis method provided in an embodiment of the present application is as follows: Figure 1 As shown, the method includes:
[0053] S101. Obtain key information of the object to be analyzed.
[0054] In this embodiment, the key information includes the name and object attributes, and the object attributes include words used to describe the characteristics of the object to be analyzed. For example, if the object to be analyzed is a hot topic, the object attributes of the hot topic include the names and codes of the people involved, as well as specific action description words. Specifically, if the hot topic on social media is "punishment measures for high-altitude throwing", the object attributes include the keywords "high-altitude throwing" and "punishment" of the hot topic, as well as the names of the communities and abandoned objects related to the topic of "punishment measures for high-altitude throwing".
[0055] S102: Using a web crawler, obtain texts that meet preset crawling rules from texts published on preset social media as texts to be analyzed.
[0056] In this embodiment, the crawling rules include: containing key information and the heat is greater than a preset heat threshold.
[0057] It should be noted that social media includes domestic social media and / or overseas social media, and the crawling rules are preset based on actual needs. It can be understood that the text containing key information is used to express opinions on the object to be analyzed, and the popularity represents the number of readings, likes and collections of the text. Texts with a popularity greater than the preset threshold can better reflect the public's attitude towards the analysis object.
[0058] S103: input the text to be analyzed into the sentiment analysis model to obtain the sentiment polarity of the text to be analyzed output by the sentiment analysis model.
[0059] In this embodiment, the emotion polarity is one of the preset polarities, which include positive, neutral, and negative. It should be noted that the preset polarity can be further divided according to degree, for example, negative includes criticism, disgust, and hatred, etc., which is not limited in this embodiment.
[0060] In this embodiment, the sentiment analysis model includes an encoding model, a feature extraction model and a neural network model, and the feature extraction model is used to generate a feature vector of the text to be analyzed. The encoding model is used to obtain the text vector of the text to be analyzed, and the encoding model includes a GloVe (Global Vectors for Word Representation) model. The neural network model is used to take the feature vector of the text to be analyzed as input and output the sentiment polarity of the text to be analyzed. Specifically, the neural network model includes an embedding layer, a convolution layer, a maximum pooling layer softmax layer, and a fully connected layer. Among them, the convolution network of the convolution layer is connected to at least one filter, for example, the convolution network is sequentially connected to filters with a filter depth of 3, 5, and 2. Each filter is used to output the key vector of the input vector.
[0061] In this embodiment, the feature extraction model is an LSTM (Long Short-Term Memory) model, and the neural network model is a CNN (Convolutional Neural Networks) model.
[0062] In this embodiment, the text to be analyzed is first subjected to a preset preprocessing, which includes data cleaning (for example, removing various impurities with less correlation with sentiment, such as punctuation marks, special characters, stop words, etc., replacing emoticons with words, performing stem extraction and word segmentation) and word segmentation operations, and then the preprocessed data is used as the input of the sentiment analysis model to improve the efficiency and accuracy of the model.
[0063] In this embodiment, taking the English text as an example, the text to be analyzed is input into the sentiment analysis model, and the specific method of obtaining the sentiment polarity of the text to be analyzed output by the sentiment analysis model includes:
[0064] 1. Map the input English text into a 256-dimensional text vector based on the GloVe model. Optionally, obtain the word vectors of the words contained in the English text and concatenate them to obtain the text vector.
[0065] 2. Use the LSTM model to extract long-distance features from the text vector output by the GloVe model, generate and output a feature vector indicating contextual semantics;
[0066] 3. The output of the LSTM model is used as the input of the CNN model. The convolution layer of the CNN model is further used to convolve the feature vector of the LSTM model output, extract the features of the feature vector and iterate using multiple filters to obtain the filtered feature vector. The filtered feature vector is used as the input of the maximum pooling layer. The maximum pooling layer uses the dropout regularization to process the filtered feature vector and outputs the processing result to the softmax layer. The features are further classified through the fully connected layer to output the sentiment polarity of the English text.
[0067] It should be noted that the sentiment analysis model takes sample text as input and the sentiment polarity of the sample text as the target output for training. During the training process, the parameters of each structure in the sentiment analysis model are iteratively optimized. For a specific training method, see Figure 3 The process shown.
[0068] S104: Obtain preset measurement values of various sentiment polarities.
[0069] In this embodiment, the measure value of the sentiment polarity is a quantitative value of the sentiment polarity. Optionally, the larger the measure value, the higher the positivity. For example, positive sentiment polarity is 1, neutral sentiment polarity is 0, and negative sentiment polarity is -1.
[0070] S105: Obtain the statistical value of the sentiment polarity measurement value of each text to be analyzed,
[0071] In this embodiment, the statistical value includes any one of an arithmetic mean, a weighted mean, and a mode.
[0072] It should be noted that when the statistical value is a weighted average, optionally, the weight of the text to be analyzed is obtained based on the length of the text to be analyzed, the source of the text to be analyzed (social media type), or the popularity of the text to be analyzed. For example, the greater the number of users of the source of the text to be analyzed, the greater the weight of the text to be analyzed, or the higher the popularity of the text to be analyzed, the greater the weight of the text to be analyzed.
[0073] S106. Determine the sentiment polarity of the object to be analyzed based on the statistical value.
[0074] Specifically, a preset numerical range corresponding to the sentiment polarity is obtained, and the sentiment polarity whose numerical range contains the statistical value is taken as the sentiment polarity of the object to be analyzed.
[0075] Continuing with the above example, the number of texts to be analyzed is 1000, of which 600 have positive sentiment polarity, 220 have negative sentiment polarity, and 180 have neutral sentiment polarity. The arithmetic mean of the sentiment polarity measurement values of the texts to be analyzed is 0.38, and the numerical range of positive sentiment polarity is [0.5, 1], the numerical range of neutral sentiment polarity is [-0.5, 0.5], and the numerical range of negative sentiment polarity is [-1, 0.5]. Therefore, the sentiment polarity of the object to be analyzed is neutral. It should be noted that the fine granularity of sentiment polarity can be preset. For example, according to the rule from negative to positive, sentiment polarity can be divided into 10 levels of polarity. For details, please refer to the prior art.
[0076] S107: extract keywords from the first category of text, and use keywords with a frequency greater than a preset frequency threshold as feature words of the first polarity.
[0077] In this embodiment, the first type of text is a text to be analyzed whose sentiment polarity is a first polarity, and the first polarity is any sentiment polarity.
[0078] S108. Cluster all keywords to obtain at least one keyword set and a type of the keyword set, and use the type of the keyword set as a feature type of the first polarity.
[0079] It should be noted that the feature words of the first polarity and the feature types of the first polarity indicate the reasons for the emotions indicated by the first polarity for the object to be analyzed from different dimensions. For example, the object to be analyzed is a refrigerator product, the first polarity is negative, and the feature words of the first polarity include ice, power consumption, and capacity. Then the reasons for the negative emotions for the refrigerator product are related to ice, power consumption, and capacity. The feature type of the first polarity is performance. It can be understood that the performance of the refrigerator product is the reason for the negative emotions for the refrigerator product.
[0080] S109: The sentiment polarity of the object to be analyzed, the feature type of each preset polarity, and the keyword of each preset polarity are used as the sentiment analysis result of the object to be analyzed, and are displayed visually.
[0081] It should be noted that the visualization method can be referred to in the prior art, for example, by means of a chart or a trend chart. The specific visualization method can be referred to in the prior art.
[0082] It can be seen from the above technical solution that the present embodiment provides a method for analyzing sentiment polarity. Since the sentiment analysis model includes a feature extraction model and a neural network model, the feature extraction model is used to generate a feature vector of the text to be analyzed, and the neural network model is used to output the sentiment polarity of the text to be analyzed using the feature vector of the text to be analyzed as input. It can be seen that the sentiment analysis model pre-generates the feature vector of the text to be analyzed through the feature extraction model, and then outputs the result based on the feature vector through the neural network model, thereby improving the accuracy and efficiency of obtaining the sentiment polarity of the text to be analyzed. Furthermore, since the text to be analyzed is a text related to the object to be analyzed, the sentiment analysis result includes the sentiment polarity. Therefore, the accuracy of the sentiment polarity of the object to be analyzed obtained through the sentiment polarities of multiple texts to be analyzed is high.
[0083] Furthermore, at least one filter is set in the convolutional layer to extract key features, which further improves the accuracy of the model output.
[0084] Furthermore, a web crawler is used to obtain texts published on preset social media that meet preset crawling rules as texts to be analyzed. Since the crawling rules include containing key information and having a heat value greater than a preset heat threshold, where the key information is the name and object attributes of the object to be analyzed, the text to be analyzed obtained by this application has a strong correlation with the object to be analyzed, and is widely spread or has a large impact (generally, heat can indicate the degree of spread or impact of the text). Based on this, the sentiment analysis result obtained by performing sentiment analysis on the object to be analyzed based on the text to be analyzed of this application is highly accurate.
[0085] Furthermore, the sentiment analysis result of the object to be analyzed not only includes the sentiment polarity of the object to be analyzed, but also includes the feature type of each preset polarity and the keyword of each preset polarity as the object to be analyzed. The analysis result is more comprehensive, and visualization makes the analysis result more intuitive and helpful for analyzing the reasons for different sentiment polarities.
[0086] Figure 2 A schematic diagram illustrating a training method for a sentiment analysis model is shown below. Figure 2 As shown, including:
[0087] S201: Obtain a preset text associated with the text to be analyzed as a sample text.
[0088] In this embodiment, the method of obtaining a preset text associated with the text to be analyzed as a sample text includes: obtaining a text that meets the crawling rules from a preset corpus as the sample text.
[0089] S202: Preprocess the sample text to obtain a word segmentation set of the sample text.
[0090] In this embodiment, the word segmentation set includes at least one word segmentation, and the word segmentation is obtained based on a word segmentation operation on a sample text. The preprocessing includes data cleaning and word segmentation operations. For details, refer to the above embodiment.
[0091] S203: According to the word attribute of the word segmentation, the polarity value of the word segmentation is obtained by searching the polarity dictionary.
[0092] In this embodiment, a polarity dictionary is pre-constructed, and the polarity dictionary includes a correspondence between preset words, word attributes, and polarity values, and the word attributes include positive words, negative words, and neutral words.
[0093] Specifically, taking English text as an example, the data annotation process is a combination of Stanford corpus and expert analysis. Expert analysis is proposed by English natural language processing experts based on negative logical relationship words such as but, nevertheless, etc. Strong words include verb nouns, and negative words include none, never, etc. A set of dictionaries suitable for English text sentiment analysis is established based on this, and data labeling is performed based on this.
[0094] S204: Calculate the polarity value of the sample text according to the polarity value of each word segment.
[0095] In this embodiment, there are multiple methods for calculating the polarity value of the sample text. For example, the polarity value of each word is weightedly added to obtain the polarity value of the sample text. The polarity value of the word is obtained by the word's part of speech or its position in the sample text.
[0096] S205: Obtain the sentiment polarity of the sample text according to the polarity value of the sample text.
[0097] In this embodiment, the sentiment polarity including the polarity value is used as the sentiment polarity of the sample text.
[0098] S206: Input the sample text into the initial model of the sentiment analysis model, use the sentiment polarity of the sample text as the target output, train the initial model, and obtain the sentiment analysis model.
[0099] In this embodiment, during the process of training the model, 80% of the data is randomly selected from the sample text as a training set, and 20% of the data is randomly selected as a test set, and the training data is cross-validated. For the specific process of training the initial model, refer to the prior art.
[0100] It should be noted that the sample text is text related to the object to be analyzed, which improves the accuracy of the sentiment analysis model for the object to be analyzed. The sentiment polarity of the sample text obtained by considering the word attributes, part of speech, and position of the word segmentation is highly accurate and more suitable for texts expressed in colloquial language on social media.
[0101] Figure 1 This is only an optional specific implementation of a method for analyzing sentiment polarity. The method for analyzing sentiment polarity provided in an embodiment of the present application also includes other specific implementations.
[0102] For example, the specific structure of the sentiment analysis model is not limited to the structure provided in the above embodiment. Optionally, the feature extraction model is not limited to the LSTM model, the neural network model is not limited to the convolutional neural network model, and the encoding model is not limited to the GloVe model.
[0103] For another example, S101 to S102 are a method for optionally obtaining multiple texts to be analyzed. The present application also includes other methods for obtaining multiple texts to be analyzed. Optionally, the crawling rules also include that the number of users of social media who publish the text is greater than a preset threshold.
[0104] In summary, the analysis method of sentiment polarity provided in the embodiment of the present application is summarized as follows: Figure 4 The process shown is as follows Figure 3 As shown, the method includes:
[0105] S301, obtaining multiple texts to be analyzed.
[0106] In this embodiment, the text to be analyzed is text related to the object to be analyzed. The text related to the object to be analyzed refers to text used to comment on or explain the object to be analyzed.
[0107] It should be noted that the specific method for obtaining multiple texts to be analyzed is shown in the above embodiment.
[0108] S302: input the text to be analyzed into a sentiment analysis model to obtain the sentiment polarity of the text to be analyzed output by the sentiment analysis model.
[0109] In this embodiment, the sentiment polarity is one of the preset polarities, and the preset polarities include positive, neutral, and negative. The sentiment analysis model includes a feature extraction model and a neural network model, the feature extraction model is used to generate a feature vector of the text to be analyzed, and the neural network model is used to take the feature vector of the text to be analyzed as input and output the sentiment polarity of the text to be analyzed.
[0110] It should be noted that there are multiple specific structures of the sentiment analysis model, and an optional specific structure can be found in the above embodiment.
[0111] S303: Obtain sentiment analysis results of the object to be analyzed based on the sentiment polarity of each text to be analyzed.
[0112] In this embodiment, the sentiment analysis result includes sentiment polarity. Each text to be analyzed is a text related to the object to be analyzed. Therefore, the sentiment polarity of the object to be analyzed is obtained by counting the sentiment polarities of the texts to be analyzed. For example, the sentiment polarity with the largest number of corresponding texts to be analyzed is used as the sentiment polarity of the object to be analyzed.
[0113] It can be seen from the above technical solution that the sentiment polarity analysis method provided in the embodiment of the present application, since the sentiment analysis model includes a feature extraction model and a neural network model, wherein the feature extraction model is used to generate a feature vector of the text to be analyzed, and the neural network model is used to output the sentiment polarity of the text to be analyzed using the feature vector of the text to be analyzed as input. It can be seen that the sentiment analysis model pre-generates the feature vector of the text to be analyzed through the feature extraction model, and then outputs the result based on the feature vector through the neural network model, thereby improving the accuracy and efficiency of obtaining the sentiment polarity of the text to be analyzed. Furthermore, since the text to be analyzed is a text related to the object to be analyzed, the sentiment analysis result includes the sentiment polarity. Therefore, the accuracy of the sentiment polarity of the object to be analyzed obtained through the sentiment polarities of multiple texts to be analyzed is high.
[0114] Figure 4 A schematic diagram of the structure of a sentiment polarity analysis device provided in an embodiment of the present application is shown. Figure 4 As shown, the device may include:
[0115] The text acquisition unit 401 is used to acquire a plurality of texts to be analyzed, wherein the texts to be analyzed are texts related to the object to be analyzed;
[0116] A model prediction unit 402 is used to input the text to be analyzed into a sentiment analysis model to obtain the sentiment polarity of the text to be analyzed output by the sentiment analysis model, wherein the sentiment polarity is one of preset polarities, and the preset polarities include positive, neutral, and negative;
[0117] The sentiment analysis model includes a feature extraction model and a neural network model, wherein the feature extraction model is used to generate a feature vector of the text to be analyzed, and the neural network model is used to take the feature vector of the text to be analyzed as input and output the sentiment polarity of the text to be analyzed;
[0118] The analysis result acquisition unit 403 is used to acquire the sentiment analysis result of the object to be analyzed according to the sentiment polarity of each text to be analyzed, and the sentiment analysis result includes the sentiment polarity.
[0119] Optionally, the sentiment analysis model also includes:
[0120] A coding model, wherein the coding model is used to obtain a text vector of the text to be analyzed, and the coding model includes a GloVe model;
[0121] The feature extraction model is an LSTM model, and the neural network model is a convolutional neural network model; the LSTM model is used to extract long-distance features of the text vector of the text to be analyzed, generate and output the feature vector of the text to be analyzed, and the feature extraction model includes the LSTM model.
[0122] Optionally, it also includes a training unit, which is used to obtain a preset text associated with the text to be analyzed as a sample text before inputting the text to be analyzed into the sentiment analysis model to obtain the sentiment polarity of the text to be analyzed as an output of the sentiment analysis model; obtain the sentiment polarity of the sample text based on a preset polarity dictionary; input the sample text into the initial model of the sentiment analysis model, use the sentiment polarity of the sample text as the target output, train the initial model, and obtain the sentiment analysis model.
[0123] Optionally, the polarity dictionary includes a correspondence between preset words, word attributes, and polarity values, wherein the word attributes include positive words, negative words, and neutral words;
[0124] The training unit is used to obtain the sentiment polarity of the sample text based on a preset polarity dictionary, including: the training unit is specifically used to:
[0125] Performing a preset preprocessing on the sample text to obtain a word segmentation set of the sample text, wherein the word segmentation set includes at least one word segmentation, and the preprocessing includes data cleaning and word segmentation operations;
[0126] According to the word attribute of the word segmentation, query from the polarity dictionary to obtain the polarity value of the word segmentation;
[0127] Calculating the polarity value of the sample text according to the polarity value of each of the segmented words;
[0128] The sentiment polarity of the sample text is obtained according to the polarity value of the sample text.
[0129] Optionally, the text acquisition unit is used to acquire multiple texts to be analyzed, including: the text acquisition unit is specifically used to:
[0130] Acquire key information of the object to be analyzed, wherein the key information includes name and object attributes;
[0131] A web crawler is used to obtain texts published on preset social media that meet preset crawling rules as texts to be analyzed. The crawling rules include: containing the key information and having a heat greater than a preset heat threshold.
[0132] The analysis result acquisition unit is used to acquire the sentiment analysis result of the object to be analyzed according to the sentiment polarity of each of the texts to be analyzed, including: the analysis result acquisition unit is specifically used to:
[0133] Obtaining preset measurement values of each of the sentiment polarities;
[0134] Obtaining a statistical value of a measure of sentiment polarity of each of the texts to be analyzed, wherein the statistical value includes any one of an arithmetic mean, a weighted mean, and a mode;
[0135] The sentiment polarity of the object to be analyzed is determined according to the statistical value.
[0136] Optionally, the sentiment analysis result also includes a feature word and a feature type of any sentiment polarity; the sentiment analysis result of the object to be analyzed is obtained according to the sentiment polarity of each of the texts to be analyzed, and the analysis result acquisition unit is further used to:
[0137] Extracting keywords from a first type of text, where the first type of text is text to be analyzed whose sentiment polarity is a first polarity, where the first polarity is any sentiment polarity;
[0138] The keywords whose frequency is greater than a preset frequency threshold are used as the feature words of the first polarity;
[0139] All the keywords are clustered to obtain at least one keyword set and a type of the keyword set, and the type of the keyword set is used as a feature type of the first polarity.
[0140] Figure 5A schematic diagram of the structure of the emotion polarity analysis device is shown, and the device may include: at least one processor 501, at least one communication interface 502, at least one memory 503 and at least one communication bus 504;
[0141] In the embodiment of the present application, the number of the processor 501, the communication interface 502, the memory 503, and the communication bus 504 is at least one, and the processor 501, the communication interface 502, and the memory 503 communicate with each other through the communication bus 504;
[0142] The processor 501 may be a central processing unit (CPU), or an application-specific integrated circuit (ASIC), or one or more integrated circuits configured to implement the embodiments of the present invention;
[0143] The memory 503 may include a high-speed RAM memory, and may also include a non-volatile memory, such as at least one disk memory;
[0144] The memory stores a program, and the processor can execute the program stored in the memory to implement the steps of a sentiment polarity analysis method provided in an embodiment of the present application, as follows:
[0145] Acquire multiple texts to be analyzed, where the texts to be analyzed are texts related to the object to be analyzed;
[0146] Inputting the text to be analyzed into a sentiment analysis model to obtain the sentiment polarity of the text to be analyzed output by the sentiment analysis model, wherein the sentiment polarity is one of preset polarities, and the preset polarities include positive, neutral, and negative;
[0147] The sentiment analysis model includes a feature extraction model and a neural network model, wherein the feature extraction model is used to generate a feature vector of the text to be analyzed, and the neural network model is used to take the feature vector of the text to be analyzed as input and output the sentiment polarity of the text to be analyzed;
[0148] According to the sentiment polarity of each of the texts to be analyzed, a sentiment analysis result of the object to be analyzed is obtained, wherein the sentiment analysis result includes the sentiment polarity.
[0149] Optionally, the sentiment analysis model also includes:
[0150] A coding model, wherein the coding model is used to obtain a text vector of the text to be analyzed, and the coding model includes a GloVe model;
[0151] The feature extraction model is an LSTM model, and the neural network model is a convolutional neural network model; the LSTM model is used to extract long-distance features of the text vector of the text to be analyzed, generate and output the feature vector of the text to be analyzed, and the feature extraction model includes the LSTM model.
[0152] Optionally, before inputting the text to be analyzed into the sentiment analysis model to obtain the sentiment polarity of the text to be analyzed output by the sentiment analysis model, the method further includes:
[0153] Acquire a preset text associated with the text to be analyzed as a sample text;
[0154] Based on a preset polarity dictionary, obtaining the sentiment polarity of the sample text;
[0155] The sample text is input into the initial model of the sentiment analysis model, the sentiment polarity of the sample text is used as the target output, the initial model is trained, and the sentiment analysis model is obtained.
[0156] Optionally, the polarity dictionary includes a correspondence between preset words, word attributes, and polarity values, wherein the word attributes include positive words, negative words, and neutral words;
[0157] The acquiring the sentiment polarity of the sample text based on a preset polarity dictionary includes:
[0158] Performing a preset preprocessing on the sample text to obtain a word segmentation set of the sample text, wherein the word segmentation set includes at least one word segmentation, and the preprocessing includes data cleaning and word segmentation operations;
[0159] According to the word attribute of the word segmentation, query from the polarity dictionary to obtain the polarity value of the word segmentation;
[0160] Calculating the polarity value of the sample text according to the polarity value of each of the segmented words;
[0161] The sentiment polarity of the sample text is obtained according to the polarity value of the sample text.
[0162] Optionally, obtain multiple texts to be analyzed, including:
[0163] Acquire key information of the object to be analyzed, wherein the key information includes name and object attributes;
[0164] A web crawler is used to obtain texts published on preset social media that meet preset crawling rules as texts to be analyzed. The crawling rules include: containing the key information and having a heat greater than a preset heat threshold.
[0165] Optionally, obtaining a sentiment analysis result of the object to be analyzed according to the sentiment polarity of each of the texts to be analyzed includes:
[0166] Obtaining preset measurement values of each of the sentiment polarities;
[0167] Obtaining a statistical value of a measure of sentiment polarity of each of the texts to be analyzed, wherein the statistical value includes any one of an arithmetic mean, a weighted mean, and a mode;
[0168] The sentiment polarity of the object to be analyzed is determined according to the statistical value.
[0169] Optionally, the sentiment analysis result also includes a feature word and a feature type of any sentiment polarity; and obtaining the sentiment analysis result of the object to be analyzed according to the sentiment polarity of each of the texts to be analyzed further includes:
[0170] Extracting keywords from a first type of text, where the first type of text is text to be analyzed whose sentiment polarity is a first polarity, where the first polarity is any sentiment polarity;
[0171] The keywords whose frequency is greater than a preset frequency threshold are used as the feature words of the first polarity;
[0172] All the keywords are clustered to obtain at least one keyword set and a type of the keyword set, and the type of the keyword set is used as a feature type of the first polarity.
[0173] The present application also provides a readable storage medium, which can store a computer program suitable for execution by a processor. When the computer program is executed by the processor, the steps of the sentiment polarity analysis method provided in the present application are implemented as follows:
[0174] Acquire multiple texts to be analyzed, where the texts to be analyzed are texts related to the object to be analyzed;
[0175] Inputting the text to be analyzed into a sentiment analysis model to obtain the sentiment polarity of the text to be analyzed output by the sentiment analysis model, wherein the sentiment polarity is one of preset polarities, and the preset polarities include positive, neutral, and negative;
[0176] The sentiment analysis model includes a feature extraction model and a neural network model, wherein the feature extraction model is used to generate a feature vector of the text to be analyzed, and the neural network model is used to take the feature vector of the text to be analyzed as input and output the sentiment polarity of the text to be analyzed;
[0177] According to the sentiment polarity of each of the texts to be analyzed, a sentiment analysis result of the object to be analyzed is obtained, wherein the sentiment analysis result includes the sentiment polarity.
[0178] Optionally, the sentiment analysis model also includes:
[0179] A coding model, wherein the coding model is used to obtain a text vector of the text to be analyzed, and the coding model includes a GloVe model;
[0180] The feature extraction model is an LSTM model, and the neural network model is a convolutional neural network model; the LSTM model is used to extract long-distance features of the text vector of the text to be analyzed, generate and output the feature vector of the text to be analyzed, and the feature extraction model includes the LSTM model.
[0181] Optionally, before inputting the text to be analyzed into the sentiment analysis model to obtain the sentiment polarity of the text to be analyzed output by the sentiment analysis model, the method further includes:
[0182] Acquire a preset text associated with the text to be analyzed as a sample text;
[0183] Based on a preset polarity dictionary, obtaining the sentiment polarity of the sample text;
[0184] The sample text is input into the initial model of the sentiment analysis model, the sentiment polarity of the sample text is used as the target output, the initial model is trained, and the sentiment analysis model is obtained.
[0185] Optionally, the polarity dictionary includes a correspondence between preset words, word attributes, and polarity values, wherein the word attributes include positive words, negative words, and neutral words;
[0186] The acquiring the sentiment polarity of the sample text based on a preset polarity dictionary includes:
[0187] Performing a preset preprocessing on the sample text to obtain a word segmentation set of the sample text, wherein the word segmentation set includes at least one word segmentation, and the preprocessing includes data cleaning and word segmentation operations;
[0188] According to the word attribute of the word segmentation, query from the polarity dictionary to obtain the polarity value of the word segmentation;
[0189] Calculating the polarity value of the sample text according to the polarity value of each of the segmented words;
[0190] The sentiment polarity of the sample text is obtained according to the polarity value of the sample text.
[0191] Optionally, obtain multiple texts to be analyzed, including:
[0192] Acquire key information of the object to be analyzed, wherein the key information includes name and object attributes;
[0193] A web crawler is used to obtain texts published on preset social media that meet preset crawling rules as texts to be analyzed. The crawling rules include: containing the key information and having a heat greater than a preset heat threshold.
[0194] Optionally, obtaining a sentiment analysis result of the object to be analyzed according to the sentiment polarity of each of the texts to be analyzed includes:
[0195] Obtaining preset measurement values of each of the sentiment polarities;
[0196] Obtaining a statistical value of a measure of sentiment polarity of each of the texts to be analyzed, wherein the statistical value includes any one of an arithmetic mean, a weighted mean, and a mode;
[0197] The sentiment polarity of the object to be analyzed is determined according to the statistical value.
[0198] Optionally, the sentiment analysis result also includes a feature word and a feature type of any sentiment polarity; and obtaining the sentiment analysis result of the object to be analyzed according to the sentiment polarity of each of the texts to be analyzed further includes:
[0199] Extracting keywords from a first type of text, where the first type of text is text to be analyzed whose sentiment polarity is a first polarity, where the first polarity is any sentiment polarity;
[0200] The keywords whose frequency is greater than a preset frequency threshold are used as the feature words of the first polarity;
[0201] All the keywords are clustered to obtain at least one keyword set and a type of the keyword set, and the type of the keyword set is used as a feature type of the first polarity.
[0202] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0203] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.
[0204] The above description of the disclosed embodiments enables those skilled in the art to implement or use the present application. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to the embodiments shown herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A method for analyzing sentiment polarity, characterized in that: include: Acquire multiple texts to be analyzed, where the texts to be analyzed are texts related to the object to be analyzed; Inputting the text to be analyzed into a sentiment analysis model to obtain the sentiment polarity of the text to be analyzed output by the sentiment analysis model, wherein the sentiment polarity is one of preset polarities, and the preset polarities include positive, neutral, and negative; The sentiment analysis model includes a feature extraction model and a neural network model, wherein the feature extraction model is used to generate a feature vector of the text to be analyzed, and the neural network model is used to take the feature vector of the text to be analyzed as input and output the sentiment polarity of the text to be analyzed; According to the sentiment polarity of each of the to-be-analyzed texts, obtaining a sentiment analysis result of the to-be-analyzed object, wherein the sentiment analysis result includes a sentiment polarity; The sentiment analysis result also includes a feature word and a feature type of any sentiment polarity; the sentiment analysis result of the object to be analyzed is obtained according to the sentiment polarity of each of the texts to be analyzed, and further includes: Extracting keywords from a first type of text, where the first type of text is text to be analyzed whose sentiment polarity is a first polarity, where the first polarity is any sentiment polarity; The keywords whose frequency is greater than a preset frequency threshold are used as the feature words of the first polarity; All the keywords are clustered to obtain at least one keyword set and a type of the keyword set, and the type of the keyword set is used as a feature type of the first polarity.
2. The method according to claim 1, characterized in that: The sentiment analysis model also includes: A coding model, wherein the coding model is used to obtain a text vector of the text to be analyzed, and the coding model includes a GloVe model; The feature extraction model is an LSTM model, and the neural network model is a convolutional neural network model; the LSTM model is used to extract long-distance features of the text vector of the text to be analyzed, generate and output the feature vector of the text to be analyzed, and the feature extraction model includes the LSTM model.
3. The method according to claim 2, characterized in that Before inputting the text to be analyzed into the sentiment analysis model to obtain the sentiment polarity of the text to be analyzed output by the sentiment analysis model, the method further includes: Acquire a preset text associated with the text to be analyzed as a sample text; Based on a preset polarity dictionary, obtaining the sentiment polarity of the sample text; The sample text is input into the initial model of the sentiment analysis model, the sentiment polarity of the sample text is used as the target output, the initial model is trained, and the sentiment analysis model is obtained.
4. The method according to claim 3, characterized in that The polarity dictionary includes a correspondence between preset words, word attributes, and polarity values, and the word attributes include positive words, negative words, and neutral words; The acquiring the sentiment polarity of the sample text based on a preset polarity dictionary includes: Performing a preset preprocessing on the sample text to obtain a word segmentation set of the sample text, wherein the word segmentation set includes at least one word segmentation, and the preprocessing includes data cleaning and word segmentation operations; According to the word attribute of the word segmentation, query from the polarity dictionary to obtain the polarity value of the word segmentation; Calculating the polarity value of the sample text according to the polarity value of each of the segmented words; The sentiment polarity of the sample text is obtained according to the polarity value of the sample text.
5. The method according to claim 1, characterized in that The obtaining of multiple texts to be analyzed includes: Acquire key information of the object to be analyzed, wherein the key information includes name and object attributes; A web crawler is used to obtain texts published on preset social media that meet preset crawling rules as texts to be analyzed. The crawling rules include: containing the key information and having a heat greater than a preset heat threshold.
6. The method according to claim 1, characterized in that The step of obtaining the sentiment analysis result of the object to be analyzed according to the sentiment polarity of each of the texts to be analyzed includes: Obtaining preset measurement values of each of the sentiment polarities; Obtaining a statistical value of a measure of sentiment polarity of each of the texts to be analyzed, wherein the statistical value includes any one of an arithmetic mean, a weighted mean, and a mode; The sentiment polarity of the object to be analyzed is determined according to the statistical value.
7. A device for analyzing sentiment polarity, characterized in that: include: A text acquisition unit, used to acquire a plurality of texts to be analyzed, wherein the texts to be analyzed are texts related to the object to be analyzed; A model prediction unit, used for inputting the text to be analyzed into a sentiment analysis model to obtain the sentiment polarity of the text to be analyzed output by the sentiment analysis model, wherein the sentiment polarity is one of preset polarities, and the preset polarities include positive, neutral, and negative; The sentiment analysis model includes a feature extraction model and a neural network model, wherein the feature extraction model is used to generate a feature vector of the text to be analyzed, and the neural network model is used to take the feature vector of the text to be analyzed as input and output the sentiment polarity of the text to be analyzed; An analysis result acquisition unit, configured to acquire a sentiment analysis result of the object to be analyzed according to the sentiment polarity of each of the texts to be analyzed, wherein the sentiment analysis result includes the sentiment polarity; Among them, the sentiment analysis result also includes the feature words and feature types of any sentiment polarity; the sentiment analysis result of the object to be analyzed is obtained based on the sentiment polarity of each text to be analyzed, and also includes: extracting keywords of a first category of text, the first category of text is the text to be analyzed with a sentiment polarity of a first polarity, and the first polarity is any sentiment polarity; using keywords with a word frequency greater than a preset word frequency threshold as feature words of the first polarity; clustering all the keywords to obtain at least one keyword set and a type of the keyword set, and using the type of the keyword set as the feature type of the first polarity.
8. A device for analyzing sentiment polarity, characterized in that: include: Memory and processor; The memory is used to store programs; The processor is used to execute the program to implement each step of the emotion polarity analysis method as described in any one of claims 1 to 6.
9. A readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, each step of the method for analyzing sentiment polarity according to any one of claims 1 to 6 is implemented.
