Text sentiment analysis method and device, computing device and readable medium
By combining the feature processing of word segmentation and negative words in the sentiment analysis model, the attention mechanism of recurrent neural networks and convolutional neural networks is used to solve the problem of insufficient accuracy of sentiment analysis in the existing technology, and higher classification accuracy is achieved.
Patent Information
- Application Number
- CN202111436442.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2019-05-28
- Publication Date
- 2025-08-08
- Estimated Expiration
- 2039-05-28
AI Technical Summary
The existing sentiment analysis model only focuses on sentimental words in the text and fails to effectively process negative words, resulting in poor analysis accuracy.
By obtaining the word participle expression and negative words and affective words expressions of the text to be analyzed, it is input into the trained emotion analysis model, and the characteristics of word participle and negative emotions are processed using recurrent neural networks and convolutional neural networks to process the characteristics of word participle and negative emotions, and combining the attention mechanism to classify tendencies.
The accuracy of emotional classification is improved, and the prediction ability of the model is enhanced by considering the relationship between negative words and emotional words.
Smart Images

Figure CN114168732B_ABST
Abstract
Description
[0001] This application is a divisional application of a patent application with application date of May 28, 2019, application number 201910451510.3, and titled “Text sentiment analysis method, apparatus, computing device and readable medium thereof”. Technical Field
[0002] The present invention relates to the field of computer application technology, and in particular to a text sentiment analysis method and apparatus, a computing device, and a readable medium. Background Art
[0003] In the field of natural language processing, sentiment analysis of text can help us understand the text. Therefore, sentiment analysis of text is particularly important in natural language processing.
[0004] Existing text sentiment analysis solutions primarily utilize an attention mechanism to analyze sentiment. Specifically, a large amount of text corpus is first collected as training data. Then, based on the attention mechanism, a sentiment analysis model is trained using this training data. The trained sentiment analysis model is then used to analyze the sentiment of the text.
[0005] However, the existing sentiment analysis model uses an attention mechanism, which only pays attention to the sentiment words in the text. When the text also includes negative words, it may predict the opposite sentiment, resulting in poor analysis accuracy of the existing sentiment analysis scheme. Summary of the Invention
[0006] The present invention provides a text sentiment analysis method and apparatus, a computing device, and a readable medium thereof, for improving the accuracy of sentiment analysis.
[0007] The present invention provides a method for sentiment analysis of text, wherein the method comprises:
[0008] Get the word segmentation expression of the text to be analyzed;
[0009] Obtaining negative words and sentiment expressions of the text to be analyzed;
[0010] The segmentation expression, negation and sentiment word expression of the text to be analyzed are input into a trained sentiment analysis model to obtain the tendency sentiment classification of the text to be analyzed predicted and output by the sentiment analysis model.
[0011] The present invention also provides a method for training a sentiment analysis model, wherein the method comprises:
[0012] Get the training text set;
[0013] Extracting a training sample set based on the training text set, wherein each training sample in the training sample set includes a segmentation expression, a negation word and an emotion word expression, and a known emotion classification;
[0014] Based on the training sample set, a sentiment analysis model is trained.
[0015] The present invention also provides a text sentiment analysis device, wherein the device comprises:
[0016] A word segmentation information acquisition module, used to obtain the word segmentation expression of the text to be analyzed;
[0017] A module for acquiring information about negative words and sentiment words, used to acquire the negative words and sentiment words of the text to be analyzed;
[0018] The prediction module is used to input the segmentation expression, negation and sentiment word expression of the text to be analyzed into the trained sentiment analysis model, and obtain the tendency sentiment classification of the text to be analyzed predicted and output by the sentiment analysis model.
[0019] The present invention also provides a training device for a sentiment analysis model, wherein the device comprises:
[0020] An acquisition module is used to obtain a training text set;
[0021] An extraction module is used to extract a training sample set based on the training text set, wherein each training sample in the training sample set includes a segmentation expression, a negation word and an emotion word expression, and a known emotion classification;
[0022] The training module is used to train the sentiment analysis model based on the training sample set.
[0023] The present invention also provides a computing device, comprising:
[0024] processor; and
[0025] A memory having executable codes stored thereon, which, when executed by the processor, causes the processor to execute any one of the methods described above.
[0026] The present invention also provides a non-transitory machine-readable storage medium having executable code stored thereon. When the executable code is executed by a processor of an electronic device, the processor is caused to execute any of the above methods.
[0027] The text sentiment analysis method, apparatus, computing device, and readable medium of the present invention, by employing the aforementioned technical solutions, can predict the sentiment classification of a text based on its segmentation expressions, negation words, and sentiment words, using a trained sentiment analysis model. Compared to existing techniques, this method effectively improves the accuracy of sentiment classification by taking into account the negation words and sentiment words in the text. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] The above and other objects, features and advantages of the present disclosure will become more apparent through a more detailed description of exemplary embodiments of the present disclosure with reference to the accompanying drawings, wherein like reference numerals generally represent like components in the exemplary embodiments of the present disclosure.
[0029] Figure 1 This is a flowchart of Example 1 of the text sentiment analysis method of the present invention.
[0030] Figure 2 This is a structural diagram of a sentiment analysis model provided by the present invention.
[0031] Figure 3 This is a flowchart of Example 2 of the text sentiment analysis method of the present invention.
[0032] Figure 4 This is a structural diagram of another sentiment analysis model provided by the present invention.
[0033] Figure 5 This is a flowchart of Example 3 of the text sentiment analysis method of the present invention.
[0034] Figure 6 This is a flowchart of Example 1 of the training method for the sentiment analysis model of the present invention.
[0035] Figure 7 This is a flowchart of Example 2 of the training method for the sentiment analysis model of the present invention.
[0036] Figure 8 This is a structural diagram of an embodiment of the text sentiment analysis device of the present invention.
[0037] Figure 9 This is a structural diagram of an embodiment of a training device for a sentiment analysis model of the present invention.
[0038] Figure 10 A schematic structural diagram of a computing device that can be used to implement the above method according to an embodiment of the present invention is shown. DETAILED DESCRIPTION
[0039] The preferred embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although preferred embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be limited by the embodiments described herein. Rather, these embodiments are provided to make the present disclosure more thorough and complete, and to fully convey the scope of the present disclosure to those skilled in the art.
[0040] Figure 1 Flowchart of Example 1 of the text sentiment analysis method of the present invention. Figure 1 As shown, the sentiment analysis method of this embodiment may specifically include the following steps:
[0041] 100. Obtain the word segmentation expression of the text to be analyzed;
[0042] The execution subject of the text sentiment analysis method of this embodiment is a text sentiment analysis device, which can be an independent electronic entity or an integrated application that can be run on a computer device when in use.
[0043] For example, step 100 obtains the word segmentation expression of the text to be analyzed, which may specifically include: segmenting the text to be analyzed; mapping each word segment in the text to be analyzed according to a preset dictionary library and a mapping dictionary corresponding to the dictionary library to obtain the word segmentation expression of the text to be analyzed.
[0044] The dictionary library of this embodiment can be a library that is pre-collected and includes many segmented words. The mapping dictionary of the dictionary library can record the mapping relationship between each segmented word in the dictionary library and its mapping identifier. For example, a mapping such as A→A'. For example, a simplest mapping dictionary can include a one-to-one mapping between each segmented word in the dictionary library and a number. Different segmented words cannot correspond to the same mapping identifier. For example, the first segmented word in the dictionary library is mapped to 1, the second segmented word is mapped to 2, and so on. The nth segmented word can be mapped to n. Specifically in the mapping dictionary, numbers can be used as subscripts of segmented words to represent this mapping relationship. Of course, in actual applications, letters or a combination of numbers and letters can also be used as mapping identifiers, and the implementation principle is the same.
[0045] In this embodiment, after the text to be analyzed is segmented, each segmentation is mapped to a corresponding mapping identifier in the order in which it appears in the text to be analyzed using a mapping dictionary, thereby obtaining a segmentation representation of the text to be analyzed. Each segmentation in this segmentation representation is represented by a corresponding mapping identifier, and the segmentation representation generated in this embodiment can be a one-dimensional vector. In this way, the text to be analyzed can be converted into a processable segmentation representation.
[0046] 101. Obtain the negative words and sentiment expressions of the text to be analyzed;
[0047] The negative word and sentiment word expressions of this embodiment are used to represent the negative words and sentiment words in the text to be analyzed.
[0048] For example, step 101 of obtaining the negative words and sentiment expressions of the text to be analyzed may specifically include the following steps:
[0049] (a1) Segment the text to be analyzed;
[0050] (b1) obtaining negative words and sentiment words from all the word segments of the text to be analyzed according to a preset negative word library and a preset sentiment word library;
[0051] For example, in this embodiment, a lexicon containing countless negation words can be pre-collected, and then each segmented word in the text to be analyzed can be compared with each word in the lexicon of negation words to obtain all negation words in the text to be analyzed. Similarly, a lexicon containing countless sentiment words can be pre-collected, and each segmented word in the text to be analyzed can be compared with each word in the lexicon of sentiment words to obtain all sentiment words in the text to be analyzed.
[0052] (c1) According to a preset feature mapping strategy for negative words and a preset feature mapping strategy for sentiment words, feature mapping is performed on the negative words and sentiment words in the text to be analyzed respectively to obtain the negation and sentiment expressions of the text to be analyzed.
[0053] In this embodiment, the feature mapping strategy of the preset negation words and the feature mapping strategy of the preset sentiment words can be set according to actual needs. For example, the feature mapping that is neither a negation word nor a sentiment word can be mapped to 0, and the negation word can be mapped to 1. For sentiment polarity classification (such as binary classification), the positive sentiment words that appear in the sentiment word dictionary are mapped to 2, and the negative sentiment words are mapped to 3. The negation and sentiment expression obtained in this way are equivalent to word embeddings with only 4 words. Similarly, negation and sentiment expression can also be identified by a one-dimensional vector. Specifically, each word segment in the text to be analyzed is mapped to a one-dimensional vector in sequence according to the mapping rules of negation words and sentiment words, as the negation and sentiment expression of the text to be analyzed.
[0054] In addition, it should be noted that for the multi-emotion classification problem, multiple groups of binary classifiers can be trained separately to predict whether the corresponding emotion exists. When the corresponding emotion word exists in the emotion word dictionary, it is mapped to 2, which is equivalent to a word embedding with only 3 words.
[0055] 102. Input the word segmentation expression, negation and sentiment word expression of the text to be analyzed into the trained sentiment analysis model to obtain the tendency sentiment classification of the text to be analyzed predicted and output by the sentiment analysis model.
[0056] In this embodiment, the sentiment analysis model is pre-trained. When used, the segmentation expression, negation and sentiment word expression of the text to be analyzed are directly input into the sentiment analysis model. The sentiment analysis model can then predict and output the tendency sentiment classification of the text to be analyzed. Specifically, the tendency sentiment classification can be a 1×n vector, where n is the number of sentiment words in the sentiment word library. Each position in the vector corresponds to a sentiment classification, and the value of each position in the vector is the probability that the text to be analyzed belongs to the sentiment classification corresponding to that position. In actual applications, the sentiment classification corresponding to the probability greater than a preset probability threshold can be further taken as the final sentiment classification of the text to be analyzed. For example, the preset probability threshold can be set according to actual needs, such as 0.5, 0.6, or other values greater than 0.5 and less than 1, which are not limited here. Alternatively, in actual applications, a preset probability threshold can be pre-configured, and the sentiment analysis model directly outputs the probability greater than the preset probability threshold and the corresponding sentiment classification based on the preset probability threshold.
[0057] For example, the trained sentiment analysis model of this embodiment may include: a word segmentation processing layer based on recurrent neural networks (RNN) for processing word segmentation expressions; a negation word and sentiment word processing layer based on convolutional neural networks (CNN) for processing negation words and sentiment word expressions; and a splicing processing layer.
[0058] For example, Figure 2 A structural diagram of a sentiment analysis model provided by the present invention, such as Figure 2 As shown, in the sentiment analysis model of this embodiment, the word segmentation processing layer may include: a word embedding layer, an RNN layer, and a first attention mechanism layer in sequence; the negative word sentiment word processing layer may include: a sentiment embedding layer, a CNN layer, and a second attention mechanism layer in sequence; the splicing processing layer may include: a splicing layer, a fully connected layer, and a normalization layer in sequence;
[0059] At this time, correspondingly, step 102 inputs the segmentation expression and negation and sentiment word expression of the text to be analyzed into the trained sentiment analysis model to obtain the sentiment tendency classification of the text to be analyzed predicted and output by the sentiment analysis model, which may specifically include:
[0060] (a2) Inputting the word segmentation expression of the text to be analyzed into the word embedding layer to obtain the embedded expression of the word segmentation;
[0061] In this embodiment, the calculation method for obtaining the embedded expression of the word segmentation by the embedding layer includes but is not limited to Continuous Bag-of-Words (CBoW), Skip-Gram, Global Vectors (GloVe), fastText (an open source library), Bidirectional Language Model, ELMo (Embeddings from Language Models), GPT (Generative Pre-Training), BERT (Bidirectional Encoder Representations from Transformers), etc.
[0062] (b2) The RNN layer extracts the feature expression of the word segmentation containing context information based on the embedded expression of the word segmentation;
[0063] The RNN layer of this embodiment can be one layer, two layers, or multiple layers, and the number of layers is set according to specific needs.
[0064] (c2) The feature expression of the word segmentation obtained by the first attention mechanism layer based on the RNN layer is assigned different weights to each word segmentation, and the weighted sum is used to obtain the text feature expression;
[0065] (d2) Inputting the negative words and sentiment words into the sentiment embedding layer to obtain the embedded expressions of the negative words and sentiment words;
[0066] (e2) The CNN layer extracts the positional relationship feature expression of the negation words and the sentiment words based on their embedded expressions;
[0067] (f2) The second attention mechanism layer uses the positional relationship feature expression obtained by the CNN layer to assign different weights to each negative word or sentiment word, and the weighted summation is used to obtain the negative and sentiment feature expression;
[0068] (g2) The text feature expression and the negation and sentiment feature expressions are concatenated by the concatenation layer to obtain a concatenated global feature expression;
[0069] (h2) The fully connected layer performs a mapping operation on the global concatenated feature expression to enhance the feature fitting capability and obtain the transformed feature expression;
[0070] (i2) The normalization layer maps the transformed feature expression to the final classification and outputs the final classification result, which includes the tendency sentiment classification and the corresponding probability.
[0071] For example, after the final classification process, a 1×n one-dimensional vector is obtained, where n is the total number of sentiment categories. For binary classification, n is 2; for multi-level classification, n can be the total number of levels. The value of each position in the one-dimensional vector is the probability of the sentiment category corresponding to that position. The sentiment corresponding to the position with the highest probability is the sentiment category of the analyzed text. The final classification result can be controlled to output the sentiment category with the highest probability and the corresponding probability.
[0072] The sentiment analysis method of this embodiment, by employing the aforementioned technical solution, can predict the sentiment classification of a text based on its segmentation expressions, negation words, and sentiment words, using a trained sentiment analysis model. Compared to existing techniques, this method effectively improves the accuracy of sentiment classification by taking into account the negation words and sentiment words in the text.
[0073] Figure 3 Flowchart of Example 2 of the text sentiment analysis method of the present invention. Figure 3 As shown, the sentiment analysis method of this embodiment may specifically include the following steps:
[0074] 200. Obtaining the word segmentation expression and the positional expression of the word segmentation of the text to be analyzed;
[0075] With the above Figure 1 Unlike step 200 in the illustrated embodiment, this embodiment also requires obtaining positional representations of the word segments in the text to be analyzed. Specifically, the positional representations of the word segments can be mapped based on the positional information of each word segment in the text to be analyzed. Similarly, the positional representation of this embodiment can also take the form of a vector. The positional representation of this embodiment is used to represent the positional information of each word segment.
[0076] 201. Obtaining expressions of negation words and sentiment words of the text to be analyzed, as well as position expressions of the negation words and sentiment words;
[0077] With the above Figure 1 The difference from step 201 of the illustrated embodiment is that, in this embodiment, it is also necessary to obtain the positional expressions of the negative words and sentiment words of the text to be analyzed. Specifically, the positional expressions of negation and sentiment can be mapped based on the positional information of each negative word and sentiment word in the text to be analyzed.
[0078] 202. The word segmentation expression, word position expression, negation word and sentiment word expression, and position expression of the text to be analyzed are input into the sentiment analysis model, and the sentiment analysis model outputs the predicted tendency sentiment classification of the text to be analyzed.
[0079] With the above Figure 1The difference of step 202 in the illustrated embodiment is that, in this embodiment, the position expression of the input participle and the position expression of the attributive word and the sentiment word are added, and the rest of the implementation principles are the same as above and will not be repeated here.
[0080] With the above Figure 1 The same as the embodiment shown, the trained sentiment analysis model of this embodiment may also include: an RNN-based segmentation processing layer for processing segmentation expressions and segmentation position expressions; a CNN-based negation and sentiment word processing layer for processing negation and sentiment word expressions and the positional expressions of negation and sentiment words; and a splicing processing layer.
[0081] For example Figure 4 This is a structural diagram of another sentiment analysis model provided by the present invention, such as Figure 4 As shown, in the sentiment analysis model of this embodiment, Figure 1 Different from the embodiment shown, the word segmentation processing layer of this embodiment includes: word embedding layer, first position embedding layer, RNN layer and first attention mechanism layer in sequence; the negative word and emotion word processing layer includes: emotion embedding layer, second position embedding layer, CNN layer and second attention mechanism layer in sequence. Figure 2 The embodiment shown has a first position embedding layer and a second position embedding layer. Figure 2 The embodiment shown is the same, and includes in sequence: a concatenation layer, a fully connected layer, and a normalization layer;
[0082] At this time, correspondingly, step 202 inputs the word segmentation expression, word segmentation position expression, negation and sentiment word expression, and negation and sentiment word position expression of the text to be analyzed into the sentiment analysis model to obtain the tendency sentiment classification of the text to be analyzed predicted and output by the sentiment analysis model, which may specifically include the following steps:
[0083] (a3) Inputting the word segmentation expression of the text to be analyzed into the word embedding layer of the sentiment analysis model to obtain the embedded expression of the word segmentation;
[0084] (b3) inputting the embedded expressions and positional expressions of the word segmentations output by the word embedding layer into the first position embedding layer, so that the first position embedding layer adds the positional embedding expressions of each word segmentation on the basis of the embedded expressions of the word segmentations;
[0085] The first position embedding layer adds position information to the word embedding in step (a3). For example, the first word in the text to be analyzed has a subscript of 0, the second word has a subscript of 1, and so on. The embedding layer maps the subscripts to trainable vectors of the same length as the word embeddings. The corresponding positions of the two embeddings are added in sequence, and the position information is added to the word embeddings.
[0086] (c3) The RNN layer extracts the feature expression of the word segmentation containing context information based on the word segmentation embedding expression and the word segmentation position embedding expression;
[0087] In this embodiment, there may be one or more bidirectional RNN layers. Specifically, the RNN layer can extract features of corresponding positions containing context information.
[0088] (d3) The feature expression of the word segmentation obtained by the first attention mechanism layer based on the RNN layer is assigned different weights to each word segmentation, and the weighted sum is used to obtain the text feature expression;
[0089] For example, the first attention mechanism layer uses the following formula to assign different weights to each position and then sum them to obtain the final text feature:
[0090] e i =exp(Wx i +b)
[0091]
[0092]
[0093] Where x is the hidden state feature of the last layer of bidirectional RNN, vector x i is the feature corresponding to position i, the matrix W and the scalar b are trainable parameters, which together perform a linear transformation on the input feature and transform it into a positive scalar e through the exponential function i , represents the importance of position i. Scalar a i It is the result after normalization of the importance, and the final output vector j is the weighted sum of vector x and a.
[0094] (e3) Inputting the negation and sentiment word expressions into the sentiment embedding layer to obtain the embedding expressions of negation words and sentiment words;
[0095] (f3) inputting the embedded expressions of the negation words and the sentiment words and the positional expressions of the negation words and the sentiment words output by the sentiment embedding layer into the second positional embedding layer, so that the second positional embedding layer adds the positional embedding expressions of the negation words and the sentiment words on the basis of the embedded expressions of the negation words and the sentiment words;
[0096] (g3) The CNN layer extracts the positional relationship feature expression between the negation words and the sentiment words based on the embedding expression of the negation words and the sentiment words and the position embedding expression of the negation words and the sentiment words;
[0097] The CNN layer of this embodiment may also include one layer, two layers, or multiple layers.
[0098] (h3) The second attention mechanism layer uses the positional relationship feature expression obtained by the CNN layer to assign different weights to each negative word or sentiment word, and the weighted summation is used to obtain the feature expression of the negative word and sentiment word;
[0099] After processing through one or more CNN layers, the negative words and sentiment words are combined, and the final negative word and sentiment word feature expressions are obtained after the same second attention mechanism as text feature extraction.
[0100] (i3) The text feature expression and the negation word and sentiment word feature expressions are concatenated by the concatenation layer to obtain a concatenated global feature expression;
[0101] (j3) The fully connected layer performs a mapping operation on the global spliced feature expression to enhance the fitting capability of the feature and obtain the transformed feature expression;
[0102] (k3) The normalization layer maps the transformed feature expression to the final classification and outputs the final classification result, which includes the tendency sentiment classification and the corresponding probability.
[0103] The concatenation layer concatenates the text feature representation with the feature representations of negation words and sentiment words. Assuming the final text feature representation is a vector of length a, and the final negation word and sentiment word feature representations are vectors of length b, the resulting concatenation results in a vector of length a + b. A fully connected layer activated with tanh performs a transformation to enhance feature fitting, maintaining the vector length as a + b. A fully connected layer normalized with softmax activates the result, mapping it to two categories, creating a vector of length 2. At this point, the sentiment analysis model is binary, and the final output can also be a 2-dimensional vector. The value at each position represents the probability of the sentiment category at that position, and the sentiment category with the highest probability can be set as the preferred sentiment category for the text being analyzed.
[0104] The sentiment analysis method of this embodiment is similar to the above Figure 1 and Figure 2 Compared with the illustrated embodiment, the positional expression of word segments, as well as the positional expression of negation words and sentiment words are added, which can further improve the accuracy of the predicted tendency sentiment classification.
[0105] The sentiment analysis method of this embodiment, by employing the aforementioned technical solution, can predict the sentiment classification of a text based on a trained sentiment analysis model, using the text's segmentation representation, segmentation positional representation, negation and sentiment word representation, and positional representation of negation and sentiment words. Compared to existing techniques, this method effectively improves sentiment classification accuracy by taking into account negation and sentiment words in the text.
[0106] Figure 5Flowchart of Example 3 of the text sentiment analysis method of the present invention. Figure 5 As shown, the sentiment analysis method of this embodiment may specifically include the following steps:
[0107] 300. Obtain the feature expression of the word segmentation obtained by the first attention mechanism layer based on the RNN layer, assign different weights to each word segmentation, and normalize the weights of the word segmentations at each position, and then output the normalized weights of each word segmentation;
[0108] 301. According to the normalized weights of the segmented words, a target segmented word with the largest normalized weight is obtained from the multiple segmented words of the text to be analyzed;
[0109] 302. Determine whether the target word is included in the sentiment word library corresponding to the tendency sentiment classification; if not, execute step 303; otherwise, if included, end; that is, if included, it means that the target analysis is already a word in the sentiment word library, and no further processing is required.
[0110] 303. The target word is marked as a suspected sentiment word; and step 304 is executed.
[0111] 304 determines whether the normalized weight of the target word segment is greater than a preset weight threshold, and whether the total number of times the target word segment is marked as a suspected sentiment word is greater than a preset number threshold; if so, execute step 305; otherwise, do not perform any processing on the target word for the time being, and end;
[0112] That is to say, when the normalized weight of the target word is less than or equal to the preset weight threshold, and the total number of times the target word is marked as a suspected sentiment word is less than or equal to the preset number threshold, the target word cannot be listed as a sentiment word and cannot be merged into the sentiment word library corresponding to the tendency sentiment classification.
[0113] 305. Merge the target word segmentation into the sentiment word library corresponding to the sentiment classification.
[0114] In this embodiment, in the first attention mechanism layer, the weight a of each word that affects the result can be obtained. i By counting the words with the largest weight in different categories of emotions, new emotion words can be obtained and then added to the corresponding emotion word dictionary. For example, if a word has the largest weight in a sentence of a certain emotion category, In order to prevent the situation where attention is relatively even, the a i Exceeds the preset weight threshold a i≥σ, and to prevent accidental exceptions. When the total number of occurrences exceeds a preset threshold γ, the segmented word is considered to represent the corresponding emotion and is added to the corresponding sentiment word dictionary for expansion. For example, when processing polarity classification for a social application, positive sentiment words such as "like," "~," "hao," and "tears" may be obtained, while negative sentiment words such as "spicy chicken," "no thanks," "a pile," and "haha" may be obtained.
[0115] This embodiment can be combined with the above Figure 1 or Figure 3 It is executed on the basis of the embodiment shown. By adopting the above scheme, the emotional word library is expanded to make up for the problem that the emotional word library in the existing technology cannot be updated online in time. It can effectively enrich the emotional word library, so as to more accurately predict the tendency of text sentiment classification.
[0116] Figure 6 Flowchart of Example 1 of the training method of the sentiment analysis model of the present invention. Figure 6 As shown, the training method of the sentiment analysis model of this embodiment may specifically include the following steps:
[0117] 400. Obtain a training text set;
[0118] The training method of the sentiment analysis model of this embodiment is performed by a training device for the sentiment analysis model. The training device for the sentiment analysis model can be an independent entity or a software-integrated application.
[0119] Specifically, the training text set of this embodiment may be a set collected from the Internet and including several pieces of text data.
[0120] 401. Extracting a training sample set based on the training text set, where each training sample in the training sample set includes a segmentation expression, a negation word and an emotion word expression, and a known emotion classification;
[0121] The known emotion classification in this embodiment means that the probability corresponding to a certain known emotion classification is 1, and the probabilities of other emotion classifications are all 0.
[0122] For example, extracting a training sample set based on a training text set may include:
[0123] (a4) obtaining the word segmentation expression of each training text in the training text set;
[0124] For example, obtaining the word segmentation expression of each training text in the training text set may specifically include: segmenting each training text; mapping each word segmentation in each training text according to a preset dictionary library and a mapping dictionary corresponding to the dictionary library to obtain the word segmentation expression of the corresponding training text.
[0125] (b4) obtaining the negative words and sentiment words of each training text in the training text set;
[0126] (c4) Obtain the known sentiment classification of each training text in the training text set.
[0127] In practical applications, if each training text can correspond to only one known sentiment classification or multiple known sentiment classifications, for each known sentiment classification, the probability of the corresponding known sentiment classification can be marked as 1.
[0128] For example, step (b4) of obtaining the negative words and sentiment words of each training text in the training text set may specifically include the following steps:
[0129] (a5) Segment each training text;
[0130] (b5) obtaining negative words and emotional words from all the segmented words of each training text according to a preset negative word library and a preset emotional word library corresponding to a known emotional classification;
[0131] (c5) According to the preset feature mapping strategy for negation words and the preset feature mapping strategy for sentiment words, feature mapping is performed on the negation words and sentiment words in each training text respectively to obtain the negation and sentiment expressions of the corresponding training text.
[0132] Specifically, the specific implementation process of steps (a4) and (b4) can refer to the above Figure 1 The manner of obtaining the segmentation expression of the text to be analyzed and obtaining the negative word and sentiment word expression of the text to be analyzed in the illustrated embodiment will not be described in detail here.
[0133] 402. Train a sentiment analysis model based on the training sample set.
[0134] For example, step 402 may train a sentiment analysis model based on a training sample set, which may be implemented in the following two ways:
[0135] The first implementation does not refer to positional expression and may include the following steps:
[0136] (a5) Inputting the segmentation expression, negation word expression and sentiment word expression of each training sample into the sentiment analysis model, obtaining the sentiment analysis model prediction and outputting the tendency sentiment classification of the corresponding training sample;
[0137] (b5) Calculate the sentiment analysis model loss function based on the sentiment classification output by the sentiment analysis model and the known sentiment classification labels of the corresponding training samples, and adjust the parameters of the sentiment analysis model based on the calculation results of the loss function.
[0138] For example, the sentiment analysis model of this embodiment may include: an RNN-based segmentation processing layer for processing segmentation expressions; a CNN-based negation and sentiment word processing layer for processing negation and sentiment word expressions; and a splicing processing layer.
[0139] The word segmentation processing layer includes: a word embedding layer, an RNN layer, and a first attention mechanism layer; the negation word and sentiment word processing layer includes: a sentiment embedding layer, a CNN layer, and a second attention mechanism layer; the splicing processing layer includes: a splicing layer, a fully connected layer, and a normalization layer. Correspondingly, step (a5) inputs the word segmentation expression, as well as the negation and sentiment word expressions of each training sample into the sentiment analysis model, obtains the sentiment analysis model prediction, and outputs the corresponding tendency sentiment classification of the training sample. Specifically, the steps may include:
[0140] (a6) When training each training sample, the word segmentation expression of the training sample is input into the word embedding layer to obtain the word segmentation embedding expression;
[0141] (b6) The RNN layer extracts the feature expression of the word segmentation containing context information based on the word segmentation embedding expression;
[0142] (c6) The feature expression of the word segmentation obtained by the first attention mechanism layer based on the RNN layer is assigned different weights to each word segmentation, and the weighted sum is used to obtain the text feature expression;
[0143] (d6) Inputting the negation and sentiment word expressions into the sentiment embedding layer to obtain the embedding expressions of negation words and sentiment words;
[0144] (e6) The CNN layer extracts the positional relationship feature expression of the negation words and the sentiment words based on the embedding expression of the negation words and the sentiment words;
[0145] (f6) The second attention mechanism layer uses the positional relationship feature expression obtained by the CNN layer to assign different weights to each negative word or sentiment word, and the weighted summation is used to obtain the negative and sentiment feature expression;
[0146] (g6) The text feature expression and the negation and sentiment feature expression are concatenated by the concatenation layer to obtain a concatenated global feature expression;
[0147] (h6) The fully connected layer performs a mapping operation on the global concatenated feature expression to enhance the feature fitting capability and obtain the transformed feature expression;
[0148] (i6) The normalization layer maps the transformed feature expression to the final classification and outputs the result of the final classification, which includes the probability of tending to sentiment classification.
[0149] For details, please refer to the above Figure 1The descriptions of (a2)-(i2) in the illustrated embodiment will not be repeated here.
[0150] In the second implementation of step 402, the reference position expression is first extracted in the training sample set based on the training text set in step 401, which may also include: obtaining the position expression of the segmentation of each training text in the training text set; and obtaining the position expression of the negation words and sentiment words of each training text in the training text set. For example, obtaining the position expression of the segmentation of each training text in the training text set may include mapping the position expression of the segmentation of the corresponding training text according to the position information of each segmentation word in each training text. For example, obtaining the position expression of the negation words and sentiment words of each training text in the training text set may include mapping the position expression of the negation and sentiment of the corresponding training text according to the position information of each negation word and sentiment word in each training text.
[0151] Similarly, the trained sentiment analysis model at this time can also include: an RNN-based segmentation processing layer for processing segmentation expressions and segmentation position expressions; a CNN-based negation and sentiment word processing layer for processing negation and sentiment word expressions and the positional expressions of negation and sentiment words; and a splicing processing layer.
[0152] The word segmentation processing layer can include: word embedding layer, first position embedding layer, RNN layer and first attention mechanism layer in sequence; the negative word emotion word processing layer can include: emotion embedding layer, second position embedding layer, CNN layer and second attention mechanism layer in sequence; the splicing processing layer can include: splicing layer, fully connected layer and normalization layer in sequence.
[0153] Compared with the first implementation, the word segmentation processing layer and the negative word and sentiment word processing layer have the addition of a first position embedding layer and a second position embedding layer. The splicing processing layer is the same as that in the first implementation.
[0154] However, in the second implementation method, step 402 trains the sentiment analysis model based on the training sample set, which may specifically include: inputting the segmentation expression, segmentation position expression, negation word and sentiment word expression, and negation word and sentiment word position expression of each training sample into the sentiment analysis model, obtaining the sentiment analysis model prediction and outputting the corresponding tendency sentiment classification of the training sample.
[0155] For example, the segmentation expression, segmentation position expression, negation word and sentiment word expression, and position expression of each training sample are input into the sentiment analysis model, and the sentiment analysis model predicts and outputs the tendency sentiment classification of the corresponding training sample. Specifically, the following steps may be included:
[0156] (a7) When training each training sample, the word segmentation expression of the training sample is input into the word embedding layer of the sentiment analysis model to obtain the embedded expression of the word segmentation;
[0157] (b7) inputting the embedded expressions of the word segments and the positional expressions of the word segments output by the word embedding layer into the first positional embedding layer, so that the first positional embedding layer adds the positional embedding expressions of each word segment on the basis of the embedded expressions of the word segment;
[0158] (c7) The RNN layer extracts the feature expression of the word containing context information based on the word embedding expression and the position embedding expression of each word;
[0159] (d7) The feature expression of the word segmentation obtained by the first attention mechanism layer based on the RNN layer is assigned different weights to each word segmentation, and the weighted sum is used to obtain the text feature expression;
[0160] (e7) Inputting the negation and sentiment word expressions into the sentiment embedding layer to obtain the embedding expressions of negation words and sentiment words;
[0161] (f7) inputting the embedded expressions of the negation words and the sentiment words and the positional expressions of the negation words and the sentiment words output by the sentiment embedding layer into the second positional embedding layer, so that the second positional embedding layer adds the positional embedding expressions of the negation expressions and the sentiment words on the basis of the embedded expressions of the negation words and the sentiment words;
[0162] (g7) extracting the positional relationship feature expression between the negation words and the sentiment words based on the embedding expression of the negation words and the sentiment words and the position embedding expression of the negation words and the sentiment words by the CNN layer;
[0163] (h7) The second attention mechanism layer uses the positional relationship feature expression obtained by the CNN layer to assign different weights to each negation word or sentiment word, and the weighted summation is used to obtain the negation and sentiment word feature expression;
[0164] (i7) The text feature expression and the negation word and sentiment word feature expressions are concatenated by the concatenation layer to obtain a concatenated global feature expression;
[0165] (j7) The fully connected layer performs a mapping operation on the global spliced feature expression to enhance the fitting capability of the feature and obtain the transformed feature expression;
[0166] (k7) The normalization layer maps the transformed feature expression to the final classification and outputs the result of the final classification, which includes the probability of tending to sentiment classification.
[0167] For details, please refer to the above Figure 2 The description of (a3)-(k3) in the illustrated embodiment will not be repeated here.
[0168] The training method of the sentiment analysis model of this embodiment, by adopting the above-mentioned technical solution, can simultaneously train the sentiment analysis model based on the word segmentation expression of the text to be analyzed, as well as the negative word and sentiment word expression, so that the trained sentiment analysis model can improve the accuracy of the predicted tendency sentiment classification.
[0169] Figure 7 This is a flow chart of Example 2 of the training method for the sentiment analysis model of the present invention. Figure 7 As shown, the training method of the sentiment analysis model of this embodiment may specifically include the following steps:
[0170] 500. Get a sentence containing text and emoticons;
[0171] 501. Obtain the emotion classification corresponding to the expression;
[0172] 502. Use sentiment analysis model to predict the sentiment classification corresponding to the text;
[0173] 503. Determine whether the emotion classification corresponding to the expression and the emotion classification corresponding to the text are consistent; if they are consistent, execute step 504; otherwise, execute step 505;
[0174] 504. The sentence containing the text and the emoticon is used as a training text and added to the training text set; and step 506 is executed.
[0175] 505. Output the emotion classification corresponding to the expression and the emotion classification corresponding to the text, so that the staff can refer to the emotion classification corresponding to the expression and the emotion classification corresponding to the text, and manually mark the emotion classification of the sentence containing the text and the expression; end.
[0176] Furthermore, the manually annotated text and expression sentences may be used as training texts and added to the training text set.
[0177] For example, in this embodiment, step 500 is performed before obtaining the training text set, and is used to expand the training text set and enrich the corpus in the training text set.
[0178] 506. Configure a loss function weight for the added training text, so that when the added training text is used to train the sentiment analysis model, the loss function weight is used to adjust the corresponding loss function, and parameter adjustment is performed based on the adjusted loss function.
[0179] A loss function weight can be configured for the added training text relative to the training text already included in the training text set. The weight can be any number between 0 and 1. If the added training text is considered to be as important as the other training texts, the weight can be set to 1. Otherwise, if the added training text is considered not as important as the other training texts, a weight greater than 0 and less than 1 can be set. After calculating the loss function in the manner of the above embodiment, the weight is multiplied, and then parameter adjustment is performed based on the loss function after multiplication by the weight to reduce the influence of the training text on the model training.
[0180] Specifically, in order to solve the problem of insufficient training corpus, the training data can be increased by obtaining information containing emoticons. For example, when crawling texts in social applications, they may contain emoticons, and the emoticons themselves are relatively clear emotional expressions. For the problem of emotional polarity classification, emoticons can be classified into three categories: positive, negative, and no obvious emotions; for the problem of multi-emotion classification, different emoticons can also be mapped to different emotions. After removing these emoticons, a pure text corpus with emotional category information is obtained, which can be added to the training corpus to enhance the effect of the model. However, sometimes, the emotions of Weibo are completely expressed by emoticons, or they are actually speaking in a sarcastic way. In this case, the trained sentiment analysis model can be used to predict these texts first. If the prediction result is not biased towards the emotion corresponding to the emoticon, then these texts are removed. For example, the emoticon is positive, but the model predicts a text with a 51% probability of being negative. At the same time, for these newly added texts, the corresponding loss function weight is reduced according to the prediction of the existing sentiment analysis model:
[0181] The probability of the sense analysis model predicting the jth class, and the summation sign and the original cross entropy loss function are followed. i It is the probability that the sentiment analysis model predicts that the newly added text belongs to the corresponding sentiment classification. That is, the more certain it is that it belongs to a certain category, the greater the weight of the loss function (between 0.5 and 1.0). For the text determined by the original category, the probability of being in the corresponding category is p i =1.
[0182] In this embodiment, we can also select data that are different from the predicted category and the expression category, and sort them from small to large according to the probability of being classified into the corresponding category, that is, samples with larger differences are placed in the front, and manually review and mark a small number of samples in the front to obtain their correct categories. Add to the training text set, and set the probability of the corresponding text in the corresponding category as p i =1.
[0183] The sentiment analysis model training method of this embodiment, by employing the above-described technical solution, can enrich the corpus of training text sets, thereby overcoming the problem of limited training corpus in the prior art. Using the enriched training text set of this embodiment can further improve the prediction accuracy of the trained sentiment analysis model.
[0184] Figure 8 FIG. 1 is a structural diagram of an embodiment of a text sentiment analysis device of the present invention. Figure 8 As shown, the text sentiment analysis device of this embodiment includes:
[0185] The word segmentation information acquisition module 10 is used to obtain the word segmentation expression of the text to be analyzed;
[0186] The negative word and sentiment word information acquisition module 11 is used to obtain the negative word and sentiment word expressions of the text to be analyzed;
[0187] The prediction module 12 is used to input the word segmentation expression of the text to be analyzed obtained by the word segmentation information acquisition module 10, and the negation and emotion word expression obtained by the negation word and emotion word information acquisition module 11 into the trained sentiment analysis model, and obtain the tendency emotion classification of the text to be analyzed predicted and output by the sentiment analysis model.
[0188] Further optionally, the word segmentation information acquisition module 10 is used to:
[0189] Segment the text to be analyzed;
[0190] According to the preset dictionary library and the mapping dictionary corresponding to the dictionary library, each word segment in the text to be analyzed is mapped to obtain the word segment expression of the text to be analyzed.
[0191] Further optionally, the negative word and sentiment word information acquisition module 11 is used to:
[0192] Segment the text to be analyzed;
[0193] According to the preset negative word library and the preset sentiment word library, the negative words and sentiment words are obtained from all the word segments of the text to be analyzed;
[0194] According to the preset feature mapping strategy of negative words and the preset feature mapping strategy of sentiment words, feature mapping is performed on the negative words and sentiment words in the text to be analyzed respectively to obtain the negation and sentiment expression of the text to be analyzed.
[0195] Further optionally, in the text sentiment analysis device of this embodiment, the trained sentiment analysis model includes:
[0196] A word segmentation processing layer based on a recurrent neural network for processing word segmentation expressions;
[0197] A convolutional neural network-based negation and sentiment word processing layer for processing negation and sentiment word expressions; and
[0198] Splicing processing layer.
[0199] Further optionally, in the text sentiment analysis device of this embodiment, the word segmentation processing layer includes: a word embedding layer, a recurrent neural network layer, and a first attention mechanism layer in sequence; the negative word sentiment word processing layer includes: a sentiment embedding layer, a convolutional neural network layer, and a second attention mechanism layer in sequence; the splicing processing layer includes: a splicing layer, a fully connected layer, and a normalization layer in sequence;
[0200] The prediction module 12 is used to:
[0201] Input the word segmentation expression of the text to be analyzed into the word embedding layer to obtain the embedded expression of the word segmentation;
[0202] The recurrent neural network layer extracts the feature expression of the word segmentation containing context information based on the word segmentation embedding expression;
[0203] The feature expression of the word segmentation obtained by the first attention mechanism layer based on the recurrent neural network layer assigns different weights to each word segmentation, and the weighted sum is used to obtain the text feature expression;
[0204] Input the negative words and sentiment words into the sentiment embedding layer to obtain the embedding expressions of the negative words and sentiment words;
[0205] The convolutional neural network layer extracts the positional relationship feature expression of negation words and sentiment words based on their embedded expressions;
[0206] The second attention mechanism layer uses the positional relationship feature expression obtained by the convolutional neural network layer to assign different weights to each negative word or sentiment word, and the weighted summation is used to obtain the negative and sentiment feature expression;
[0207] The concatenation layer concatenates the text feature expression with the negation and sentiment feature expressions to obtain the concatenated global feature expression.
[0208] The fully connected layer uses mapping to change the global splicing feature expression to enhance the feature fitting ability and obtain the transformed feature expression;
[0209] The normalization layer maps the transformed feature expression to the final classification and outputs the final classification result, which includes the tendency sentiment classification and the corresponding probability.
[0210] Further optionally, in the text sentiment analysis device of this embodiment, the word segmentation information acquisition module 10 is further used to obtain the position expression of the word segmentation of the text to be analyzed;
[0211] The negative word and sentiment word information acquisition module 11 is also used to obtain the position expression of the negative words and sentiment words in the text to be analyzed;
[0212] The prediction module 12 is also used to input the segmentation expression of the text to be analyzed obtained by the segmentation information acquisition module 10, the position expression of the segmentation, the negation word and sentiment word expression and the position expression of the negation word and sentiment word obtained by the negation word and sentiment word information acquisition module 11 into the sentiment analysis model, and the sentiment analysis model outputs the predicted tendency sentiment classification of the text to be analyzed.
[0213] Further optionally, in the text sentiment analysis device of this embodiment, the word segmentation information acquisition module 10 is used to map the position expression of the word segmentation according to the position information of each word segmentation in the text to be analyzed;
[0214] Further optionally, in the text sentiment analysis device of this embodiment, the negation word and sentiment word information acquisition module 11 is used to map the positional expression of negation and sentiment according to the position information of each negation word and sentiment word in the text to be analyzed.
[0215] Further optionally, in the text sentiment analysis device of this embodiment, the trained sentiment analysis model includes:
[0216] A recurrent neural network-based word segmentation processing layer for processing word segmentation expressions and word position expressions;
[0217] A convolutional neural network-based negation and sentiment word processing layer for processing negation and sentiment word expressions and positional expressions of negation and sentiment words; and
[0218] Splicing processing layer.
[0219] Further optionally, in the text sentiment analysis device of this embodiment, the word segmentation processing layer includes, in sequence: a word embedding layer, a first position embedding layer, a recurrent neural network layer, and a first attention mechanism layer; the negative word sentiment word processing layer includes, in sequence: a sentiment embedding layer, a second position embedding layer, a convolutional neural network layer, and a second attention mechanism layer; the splicing processing layer includes, in sequence: a splicing layer, a fully connected layer, and a normalization layer;
[0220] The training module 12 is used to:
[0221] Input the word segmentation expression of the text to be analyzed into the word embedding layer of the sentiment analysis model to obtain the embedded expression of the word segmentation;
[0222] Input the embedded expressions of the word segments and the positional expressions of the word segments output by the word embedding layer into the first positional embedding layer, so that the first positional embedding layer adds the positional embedding expressions of each word segment on the basis of the embedded expressions of the word segment;
[0223] The recurrent neural network layer extracts the feature expression of the word segmentation containing contextual information based on the word segmentation embedding expression and position embedding expression;
[0224] The feature expression of the word segmentation obtained by the first attention mechanism layer based on the recurrent neural network layer assigns different weights to each word segmentation, and the weighted sum is used to obtain the text feature expression;
[0225] Input the negation and sentiment word expressions into the sentiment embedding layer to obtain the embedding expressions of negation words and sentiment words;
[0226] Input the embedded expressions of negation words and sentiment words and the positional expressions of negation words and sentiment words output by the sentiment embedding layer into the second positional embedding layer, so that the second positional embedding layer adds the positional embedding expressions of negation words and sentiment words on the basis of the embedded expressions of negation words and sentiment words;
[0227] The convolutional neural network layer extracts the positional relationship feature expression of negation words and sentiment words based on the embedding expression of negation words and sentiment words and the position embedding expression of negation words and sentiment words;
[0228] The second attention mechanism layer uses the positional relationship feature expression obtained by the convolutional neural network layer to assign different weights to each negative word or sentiment word, and the weighted summation is used to obtain the feature expression of negative words and sentiment words;
[0229] The concatenation layer concatenates the text feature expression with the negation word and sentiment word feature expressions to obtain the concatenated global feature expression;
[0230] The fully connected layer uses mapping to change the global splicing feature expression to enhance the feature fitting ability and obtain the transformed feature expression;
[0231] The normalization layer maps the transformed feature expression to the final classification and outputs the final classification result, which includes the tendency sentiment classification and the corresponding probability.
[0232] Further optionally, as Figure 8 As shown, the text sentiment analysis device of this embodiment further includes:
[0233] The weight acquisition module 13 obtains the feature expression of the word segmentation obtained by the first attention mechanism layer based on the recurrent neural network layer, assigns different weights to each word segmentation, and normalizes the weights of the word segmentation at each position, and outputs the normalized weights of each word segmentation;
[0234] The target segmentation acquisition module 14 is used to acquire the target segmentation with the largest normalized weight from the multiple segmentations of the text to be analyzed according to the normalized weights of the segmentations processed by the weight acquisition module 13;
[0235] The judgment module 15 is used to judge whether the target segmentation word obtained by the target segmentation word acquisition module 14 is included in the emotional word library corresponding to the tendency emotion classification; if not, the target segmentation word is marked as a suspected emotional word;
[0236] The judgment module 15 is further configured to judge whether the normalized weight of the target segmentation word obtained by the target segmentation word acquisition module 14 is greater than a preset weight threshold, and whether the total number of times the target segmentation word is marked as a suspected sentiment word is greater than a preset number threshold;
[0237] The merging module 16 is used to merge the target word segmentation into the sentiment word library corresponding to the tendency sentiment classification based on the judgment of the judging module 15.
[0238] In this way, the negative word and sentiment word information acquisition module 11 can be used to acquire negative words and sentiment words from all word segments of the text to be analyzed based on the preset negative word database and the sentiment word database updated by the merging module 16 .
[0239] The text sentiment analysis device of this embodiment realizes the implementation principle and implementation effect of text sentiment analysis by adopting the above-mentioned module, which is the same as the above-mentioned related method embodiments. For details, please refer to the records of the above-mentioned related method embodiments, which will not be repeated here.
[0240] Figure 9 FIG. 1 is a structural diagram of an embodiment of a training device for a sentiment analysis model of the present invention. Figure 9 As shown, the training device of the sentiment analysis model of this embodiment includes:
[0241] The acquisition module 20 is used to obtain a training text set;
[0242] The extraction module 21 is used to extract a training sample set based on the training text set obtained by the acquisition module 20, where each training sample in the training sample set includes a segmentation expression, a negation word and an emotion word expression, and a known emotion classification;
[0243] The training module 22 is used to train the sentiment analysis model based on the training sample set processed by the extraction module 21.
[0244] Further optionally, in the training device for the sentiment analysis model of this embodiment, the extraction module 21 is used to:
[0245] Acquisition Training Further optionally, in the training device for the sentiment analysis model of this embodiment, the extraction module 21 is used to:
[0246] The word segmentation expression of each training text in the text set;
[0247] Obtain the negative words and sentiment words of each training text in the training text set;
[0248] Get the known sentiment classification of each training text in the training text set.
[0249] Further optionally, in the training device for the sentiment analysis model of this embodiment, the extraction module 21 is used to:
[0250] Segment each training text;
[0251] According to the preset dictionary library and the mapping dictionary corresponding to the dictionary library, each word segment in each training text is mapped to obtain the corresponding word segment expression of the training text.
[0252] Further optionally, in the training device of the sentiment analysis model of this embodiment, the extraction module 21,
[0253] Segment each training text;
[0254] According to the preset negative word library and the preset emotional word library corresponding to the known emotional classification, the negative words and emotional words are obtained from all the word segments of each training text;
[0255] According to the preset feature mapping strategy for negative words and the preset feature mapping strategy for sentiment words, feature mapping is performed on the negative words and sentiment words in each training text respectively to obtain the negation and sentiment expression of the corresponding training text.
[0256] Further optionally, in the training device for the sentiment analysis model of this embodiment, the training module 22 is used to:
[0257] Input the segmentation expression, negation word and sentiment word expression of each training sample into the sentiment analysis model, obtain the sentiment analysis model prediction and output the corresponding tendency sentiment classification of the training sample;
[0258] According to the tendency sentiment classification output by the sentiment analysis model and the known sentiment classification labels of the corresponding training samples, the sentiment analysis model loss function is calculated, and the parameters of the sentiment analysis model are adjusted according to the calculation results of the loss function.
[0259] Further optionally, in the training device for the sentiment analysis model of this embodiment, the sentiment analysis model includes:
[0260] A word segmentation processing layer based on a recurrent neural network for processing word segmentation expressions;
[0261] A convolutional neural network-based negation and sentiment word processing layer for processing negation and sentiment word expressions; and
[0262] Splicing processing layer.
[0263] Further optionally, in the training device of the sentiment analysis model of this embodiment, the word segmentation processing layer includes: a word embedding layer, a recurrent neural network layer and a first attention mechanism layer in sequence; the negative word sentiment word processing layer includes: a sentiment embedding layer, a convolutional neural network layer and a second attention mechanism layer in sequence; the splicing processing layer includes: a splicing layer, a fully connected layer and a normalization layer in sequence; the training module is used to:
[0264] When training each training sample, the word segmentation expression of the training sample is input into the word embedding layer to obtain the embedded expression of the word segmentation;
[0265] The recurrent neural network layer extracts the feature expression of the word segmentation containing context information based on the word segmentation embedding expression;
[0266] The feature expression of the word segmentation obtained by the first attention mechanism layer based on the recurrent neural network layer assigns different weights to each word segmentation, and the weighted sum is used to obtain the text feature expression;
[0267] Input the negation and sentiment word expressions into the sentiment embedding layer to obtain the embedding expressions of negation words and sentiment words;
[0268] The convolutional neural network layer extracts the positional relationship feature expression of negation words and sentiment words based on their embedded expressions;
[0269] The second attention mechanism layer uses the positional relationship feature expression obtained by the convolutional neural network layer to assign different weights to each negative word or sentiment word, and the weighted summation is used to obtain the negative and sentiment feature expression;
[0270] The concatenation layer concatenates the text feature expression with the negation and sentiment feature expressions to obtain the concatenated global feature expression.
[0271] The fully connected layer uses mapping to change the global splicing feature expression to enhance the feature fitting ability and obtain the transformed feature expression;
[0272] The normalization layer maps the transformed feature expression to the final classification and outputs the final classification result, which includes the tendency sentiment classification and the corresponding probability.
[0273] Further optionally, in the training device for the sentiment analysis model of this embodiment, the extraction module 21 is further configured to:
[0274] Obtain the positional expression of the word segmentation of each training text in the training text set;
[0275] Get the positional expression of the negative words and sentiment words for each training text in the training text set.
[0276] Further optionally, in the training device for the sentiment analysis model of this embodiment, the extraction module 21 is further configured to:
[0277] According to the position information of each word in each training text, the position expression of the word in the corresponding training text is mapped;
[0278] Get the positional expression of the negation words and sentiment words for each training text in the training text set, including:
[0279] According to the position information of each negation word and sentiment word in each training text, the position expression of the negation and sentiment of the corresponding training text is mapped out.
[0280] Further optionally, in the training device for the sentiment analysis model of this embodiment, the trained sentiment analysis model includes:
[0281] A recurrent neural network-based word segmentation processing layer for processing word segmentation expressions and word position expressions;
[0282] A convolutional neural network-based negation and sentiment word processing layer for processing negation and sentiment word expressions and positional expressions of negation and sentiment words; and
[0283] Splicing processing layer.
[0284] Further optionally, in the training device for the sentiment analysis model of this embodiment, the training module 22 is used to:
[0285] The segmentation expression, segmentation position expression, negation word and sentiment word expression, and position expression of negation word and sentiment word of each training sample are input into the sentiment analysis model to obtain the sentiment analysis model prediction and output the corresponding tendency sentiment classification of the training sample.
[0286] Further optionally, in the training device of the sentiment analysis model of this embodiment, the word segmentation processing layer includes, in sequence: a word embedding layer, a first position embedding layer, a recurrent neural network layer, and a first attention mechanism layer; the negative word sentiment word processing layer includes, in sequence: a sentiment embedding layer, a second position embedding layer, a convolutional neural network layer, and a second attention mechanism layer; the splicing processing layer includes, in sequence: a splicing layer, a fully connected layer, and a normalization layer;
[0287] Training modules for:
[0288] When training each training sample, the word segmentation expression of the training sample is input into the word embedding layer of the sentiment analysis model to obtain the embedded expression of the word segmentation;
[0289] Input the embedded expressions of the word segments and the positional expressions of the word segments output by the word embedding layer into the first positional embedding layer, so that the first positional embedding layer adds the positional embedding expressions of each word segment on the basis of the embedded expressions of the word segment;
[0290] The recurrent neural network layer extracts the feature expression of the word containing context information based on the word embedding expression and the position embedding expression of each word;
[0291] The feature expression of the word segmentation obtained by the first attention mechanism layer based on the recurrent neural network layer assigns different weights to each word segmentation, and the weighted sum is used to obtain the text feature expression;
[0292] Input the negation and sentiment word expressions into the sentiment embedding layer to obtain the embedding expressions of negation words and sentiment words;
[0293] Input the embedded expressions of negation words and sentiment words and the positional expressions of negation words and sentiment words output by the sentiment embedding layer into the second positional embedding layer, so that the second positional embedding layer adds the positional embedding expressions of negation words and sentiment words on the basis of the embedded expressions of negation words and sentiment words;
[0294] The convolutional neural network layer extracts the positional relationship feature expression of negation words and sentiment words based on the embedding expression of negation words and sentiment words and the position embedding expression of negation words and sentiment words;
[0295] The second attention mechanism layer uses the positional relationship feature expression obtained by the convolutional neural network layer to assign different weights to each negative word or sentiment word, and the weighted summation is used to obtain the negative and sentiment word feature expression;
[0296] The concatenation layer concatenates the text feature expression with the negation word and sentiment word feature expressions to obtain the concatenated global feature expression;
[0297] The fully connected layer uses mapping to change the global splicing feature expression to enhance the feature fitting ability and obtain the transformed feature expression;
[0298] The normalization layer maps the transformed feature expression to the final classification and outputs the final classification result, which includes the tendency sentiment classification and the corresponding probability.
[0299] Further optionally, as Figure 9 As shown in FIG. 2 , the training device for the sentiment analysis model of this embodiment further includes a prediction module 23, a judgment module 24, and an addition module 25;
[0300] The acquisition module 20 is further used to acquire a sentence containing text and emoticons;
[0301] The acquisition module 20 is also used to obtain the emotion classification corresponding to the expression;
[0302] The prediction module 23 is used to predict the sentiment classification corresponding to the text using the sentiment analysis model;
[0303] The judgment module 24 is used to judge whether the emotion classification corresponding to the expression obtained by the acquisition module 20 is consistent with the emotion classification corresponding to the text obtained by the prediction module 23;
[0304] The adding module 25 is used to add the sentence containing text and expression as training text to the training text set based on the judgment of the judging module 24, if they are consistent.
[0305] Further optionally, as Figure 9 As shown in FIG. 1 , the training device for the sentiment analysis model of this embodiment further includes:
[0306] The output module 26 is used to output the emotion classification corresponding to the expression and the emotion classification corresponding to the text based on the judgment of the judgment module 24. If the emotion classification corresponding to the expression and the emotion classification corresponding to the text are inconsistent, the staff can refer to the emotion classification corresponding to the expression and the emotion classification corresponding to the text to manually mark the emotion classification of the sentence carrying text and expression.
[0307] Further optionally, as Figure 9 As shown in FIG. 1 , the training device for the sentiment analysis model of this embodiment further includes:
[0308] The configuration module 27 is used to configure the loss function weight for the training text added by the adding module 25, so that when the added training text is used to train the sentiment analysis model, the loss function weight is used to adjust the corresponding loss function, and parameter adjustment is performed based on the adjusted loss function.
[0309] The training device for the sentiment analysis model of this embodiment realizes the implementation principle and implementation effect of the sentiment analysis model training by adopting the above-mentioned module, which is the same as that of the above-mentioned related method embodiments. For details, please refer to the records of the above-mentioned related method embodiments, which will not be repeated here.
[0310] Figure 10 The following is a schematic diagram showing the structure of a computing device that can be used to implement the above method according to an embodiment of the present invention. The computing device of this embodiment can be used not only to implement the above text sentiment analysis method, but also to implement the above sentiment analysis model training method.
[0311] See also Figure 10 , the computing device 1000 includes a memory 1010 and a processor 1020 .
[0312] Processor 1020 may be a multi-core processor or may include multiple processors. In some embodiments, processor 1020 may include a general-purpose main processor and one or more specialized coprocessors, such as a graphics processing unit (GPU) or a digital signal processor (DSP). In some embodiments, processor 1020 may be implemented using customized circuits, such as application-specific integrated circuits (ASICs) or field-programmable gate arrays (FPGAs).
[0313] The memory 1010 may include various types of storage units, such as system memory, read-only memory (ROM), and permanent storage devices. ROM may store static data or instructions required by the processor 1020 or other modules of the computer. The permanent storage device may be a readable and writable storage device. The permanent storage device may be a non-volatile storage device that retains stored instructions and data even when the computer is powered off. In some embodiments, the permanent storage device uses a large-capacity storage device (such as a magnetic or optical disk, flash memory) as the permanent storage device. In other embodiments, the permanent storage device may be a removable storage device (such as a floppy disk, optical drive). The system memory may be a readable and writable storage device or a volatile readable and writable storage device, such as dynamic random access memory. The system memory may store some or all instructions and data required by the processor during operation. In addition, the memory 1010 may include any combination of computer-readable storage media, including various types of semiconductor memory chips (DRAM, SRAM, SDRAM, flash memory, programmable read-only memory), and magnetic disks and / or optical disks may also be used. In some embodiments, the memory 1010 may include a readable and / or writable removable storage device, such as a compact disc (CD), a read-only digital versatile disc (e.g., DVD-ROM, double-layer DVD-ROM), a read-only Blu-ray disc, an ultra-density optical disc, a flash memory card (e.g., SD card, mini SD card, Micro-SD card, etc.), a magnetic floppy disk, etc. Computer-readable storage media do not include carrier waves and transient electronic signals transmitted wirelessly or wired.
[0314] The memory 1010 stores executable code. When the executable code is processed by the processor 1020, the processor 1020 can execute the above-mentioned text sentiment analysis method or sentiment analysis model training method.
[0315] The sentiment analysis method of text or the training method of a sentiment analysis model according to the present invention has been described in detail above with reference to the accompanying drawings.
[0316] In addition, the method according to the present invention may also be implemented as a computer program or a computer program product, which includes computer program code instructions for executing the above steps defined in the above method of the present invention.
[0317] Alternatively, the present invention can also be implemented as a non-transitory machine-readable storage medium (or computer-readable storage medium, or machine-readable storage medium) on which executable code (or computer program, or computer instruction code) is stored. When the executable code (or computer program, or computer instruction code) is executed by a processor of an electronic device (or computing device, server, etc.), the processor executes the various steps of the above-mentioned method according to the present invention.
[0318] Those skilled in the art will further appreciate that the various illustrative logical blocks, modules, circuits, and algorithm steps described in connection with the disclosure herein may be implemented as electronic hardware, computer software, or combinations of both.
[0319] The flowcharts and block diagrams in the accompanying drawings show the possible implementation architecture, functions and operations of the systems and methods according to multiple embodiments of the present invention. In this regard, each box in the flowchart or block diagram can represent a module, program segment or part of code, and the part of the module, program segment or code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order than that marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flowchart, and the combination of the boxes in the block diagram and / or flowchart, can be implemented with a dedicated hardware-based system that performs the specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0320] While various embodiments of the present invention have been described above, the foregoing description is intended to be illustrative, non-exhaustive, and not limited to the disclosed embodiments. Many modifications and variations will be apparent to those skilled in the art without departing from the scope and spirit of the described embodiments. The terminology used herein is selected to best explain the principles of the embodiments, their practical applications, or improvements to existing technologies, or to enable others skilled in the art to understand the embodiments disclosed herein.
Claims
1. A method for sentiment analysis of text, wherein: The method comprises: Obtaining a word segmentation expression of a text to be analyzed and a positional expression of the word segmentation of the text to be analyzed; Acquire the negative word and sentiment word expressions of the text to be analyzed and the position expressions of the negative word and sentiment word of the text to be analyzed; Inputting the segmentation expression, the positional expression of the segmentation, the negation word and sentiment word expression, and the positional expression of the negation word and sentiment word of the text to be analyzed into the sentiment analysis model, and outputting the predicted tendency sentiment classification of the text to be analyzed, wherein the positional expression of the segmentation is used to embed the embedding expression corresponding to the segmentation expression, and the positional expression of the negation word and sentiment word is used to embed the embedding expression corresponding to the negation word and sentiment word expression; The tendency sentiment classification is a vector, each position in the vector corresponds to a sentiment classification, and the value of each position in the vector is the probability that the text to be analyzed belongs to the sentiment classification corresponding to the corresponding position.
2. The method according to claim 1, wherein Get the word segmentation expression of the text to be analyzed, including: Performing word segmentation on the text to be analyzed; According to a preset dictionary library and a mapping dictionary corresponding to the dictionary library, each word segment in the text to be analyzed is mapped to obtain a word segment expression of the text to be analyzed.
3. The method according to claim 1, wherein Obtaining the negative words and sentiment expressions of the text to be analyzed, including: Performing word segmentation on the text to be analyzed; According to a preset negative word library and a preset sentiment word library, obtaining negative words and sentiment words from all the word segments of the text to be analyzed; According to a preset feature mapping strategy for negation words and a preset feature mapping strategy for sentiment words, feature mapping is performed on the negation words and sentiment words in the text to be analyzed respectively to obtain the negation and sentiment expression of the text to be analyzed.
4. The method according to claim 1, wherein The obtaining of the positional expression of the word segment of the text to be analyzed includes: mapping the positional expression of the word segment according to the position information of each word segment in the text to be analyzed; The obtaining of the positional expression of the negation words and sentiment words of the text to be analyzed includes: mapping the positional expression of the negation and sentiment words according to the positional information of each of the negation words and the sentiment words in the text to be analyzed.
5. The method according to claim 1, wherein The sentiment analysis model includes: A word segmentation processing layer based on a recurrent neural network for processing the word segmentation expression and the position expression of the word segmentation; A convolutional neural network-based negation and sentiment word processing layer for processing the negation and sentiment word expressions and the positional expressions of the negation and sentiment words; and Splicing processing layer.
6. The method according to claim 5, wherein: The word segmentation processing layer includes: a word embedding layer, a first position embedding layer, a recurrent neural network layer and a first attention mechanism layer in sequence; the negative word and sentiment word processing layer includes: a sentiment embedding layer, a second position embedding layer, a convolutional neural network layer and a second attention mechanism layer in sequence; the splicing processing layer includes: a splicing layer, a fully connected layer and a normalization layer in sequence; Inputting the segmentation expression, the position expression of the segmentation, the negation and sentiment word expression, and the position expression of the negation and sentiment word of the text to be analyzed into the sentiment analysis model, and obtaining the tendency sentiment classification of the text to be analyzed predicted and output by the sentiment analysis model, including: Inputting the word segmentation expression of the text to be analyzed into the word embedding layer of the sentiment analysis model to obtain an embedded expression of the word segmentation; Inputting the embedding expressions of the word segments output by the word embedding layer and the positional expressions of the word segments into the first positional embedding layer, so that the first positional embedding layer adds the positional embedding expressions of each word segment on the basis of the embedding expressions of the word segment; The recurrent neural network layer extracts a feature expression of the word containing context information based on the word embedding expression and the position embedding expression; The first attention mechanism layer assigns different weights to each word segmentation based on the feature expression of the word segmentation obtained by the recurrent neural network layer, and performs weighted summation to obtain the text feature expression; Inputting the negation and sentiment word expressions into the sentiment embedding layer to obtain the embedding expressions of the negation words and sentiment words; Inputting the embedded expressions of the negation words and the sentiment words and the positional expressions of the negation words and the sentiment words output by the sentiment embedding layer into the second positional embedding layer, so that the second positional embedding layer adds the positional embedding expressions of the negation words and the sentiment words on the basis of the embedded expressions of the negation words and the sentiment words; The convolutional neural network layer extracts a feature expression of the position relationship between the negation word and the sentiment word based on the embedding expression of the negation word and the sentiment word and the position embedding expression of the negation word and the sentiment word; The second attention mechanism layer assigns different weights to each negation word or sentiment word based on the positional relationship feature expression obtained by the convolutional neural network layer, and performs weighted summation to obtain the feature expression of the negation word and sentiment word; The splicing layer splices the text feature expression and the negation word and sentiment word feature expression to obtain a spliced global feature expression; The fully connected layer performs a transformation on the global splicing feature expression to enhance the feature fitting capability through mapping, thereby obtaining a transformed feature expression; The normalization layer maps the transformed feature expression to the final classification and outputs the result of the final classification, which includes the tendency emotion classification and the corresponding probability.
7. The method according to claim 6, wherein: The method further comprises: Obtaining the feature expression of the word segmentation obtained by the first attention mechanism layer based on the recurrent neural network layer, assigning different weights to each word segmentation, and normalizing the weights of the word segmentations at each position, and then outputting the normalized weights of the word segmentations; According to the normalized weights of the segmented words, a target segmented word with the largest normalized weight is obtained from the multiple segmented words of the text to be analyzed; Determining whether the target word is included in the sentiment word library corresponding to the tendency sentiment classification; If not included, the target word is marked as a suspected sentiment word; Further determining whether the normalized weight of the target participle is greater than a preset weight threshold, and whether the total number of times the target participle is marked as a suspected sentiment word is greater than a preset number threshold; If so, the target word segmentation is merged into the sentiment word library corresponding to the tendency sentiment classification.
8. A method for training a sentiment analysis model, wherein: The method comprises: Get the training text set; Extracting a training sample set based on a training text set, wherein each training sample in the training sample set includes a segmentation expression, a position expression of the segmentation, a negation word and an emotion word expression, a position expression of the negation word and the emotion word, and a known emotion classification; Training a sentiment analysis model based on the training sample set; Based on the training sample set, training a sentiment analysis model includes: Inputting the segmentation expression, the position expression of the segmentation, the negation word and sentiment word expression, and the position expression of the negation word and sentiment word of each training sample into the sentiment analysis model, obtaining the sentiment analysis model to predict and output the corresponding tendency sentiment classification of the training sample, the tendency sentiment classification is a vector, each position in the vector corresponds to a sentiment classification, and the value of each position in the vector is the probability that the training sample belongs to the sentiment classification corresponding to the corresponding position; The positional expression of the word segmentation is used to embed the embedding expression corresponding to the word segmentation expression, and the positional expression of the negation word and the sentiment word is used to embed the embedding expression corresponding to the negation word and the sentiment word expression.
9. The method according to claim 8, wherein Extracting a training sample set based on the training text set includes: Obtaining the word segmentation expression of each training text in the training text set; Obtaining the negative words and sentiment words expressions of each training text in the training text set; Obtain the known sentiment classification of each training text in the training text set.
10. The method according to claim 9, wherein: Obtaining the word segmentation expression of each training text in the training text set includes: Performing word segmentation on each of the training texts; According to a preset dictionary library and a mapping dictionary corresponding to the dictionary library, each word segment in each of the training texts is mapped to obtain a corresponding word segment expression of the training text.
11. The method according to claim 9, wherein Obtaining the negative word and sentiment word expressions of each training text in the training text set includes: Performing word segmentation on each of the training texts; According to a preset negative word library and a preset emotional word library corresponding to the known emotional classification, obtaining negative words and emotional words from all the word segments of each training text; According to the preset feature mapping strategy for negation words and the preset feature mapping strategy for sentiment words, feature mapping is performed on the negation words and sentiment words in each training text respectively to obtain the corresponding negation and sentiment expression of the training text.
12. The method according to claim 8, wherein Extracting a training sample set based on the training text set also includes: Obtaining the positional expression of the word segmentation of each training text in the training text set; Obtain the positional expressions of the negative words and sentiment words of each training text in the training text set.
13. The method according to claim 12, wherein: Obtaining the positional expression of the word segmentation of each training text in the training text set includes: According to the position information of each segmentation in each training text, mapping the position expression of the segmentation in the corresponding training text; Obtaining the positional expressions of the negation words and sentiment words of each training text in the training text set includes: According to the position information of each negation word and the sentiment word in each training text, the position expression of the negation and sentiment of the corresponding training text is mapped out.
14. The method according to claim 13, wherein The sentiment analysis model includes: A word segmentation processing layer based on a recurrent neural network for processing the word segmentation expression and the position expression of the word segmentation; A convolutional neural network-based negation and sentiment word processing layer for processing the negation and sentiment word expressions and the positional expressions of the negation and sentiment words; and Splicing processing layer.
15. The method according to claim 14, wherein The word segmentation processing layer includes: a word embedding layer, a first position embedding layer, a recurrent neural network layer and a first attention mechanism layer in sequence; the negative word and sentiment word processing layer includes: a sentiment embedding layer, a second position embedding layer, a convolutional neural network layer and a second attention mechanism layer in sequence; the splicing processing layer includes: a splicing layer, a fully connected layer and a normalization layer in sequence; Inputting the segmentation expression, the position expression of the segmentation, the negation word and the sentiment word expression, and the position expression of the negation word and the sentiment word of each training sample into the sentiment analysis model, obtaining the sentiment analysis model prediction and outputting the corresponding tendency sentiment classification of the training sample, including: When training each training sample, the word segmentation expression of the training sample is input into the word embedding layer of the sentiment analysis model to obtain the embedded expression of the word segmentation; Inputting the embedding expressions of the word segments output by the word embedding layer and the positional expressions of the word segments into the first positional embedding layer, so that the first positional embedding layer adds the positional embedding expressions of each word segment on the basis of the embedding expressions of the word segment; The recurrent neural network layer extracts a feature expression containing context information of the word segmentation based on the word segmentation embedding expression and the position embedding expression of each word segmentation; The first attention mechanism layer assigns different weights to each word segmentation based on the feature expression of the word segmentation obtained by the recurrent neural network layer, and performs weighted summation to obtain the text feature expression; Inputting the negation and sentiment word expressions into the sentiment embedding layer to obtain the embedding expressions of the negation words and sentiment words; Inputting the embedded expressions of negation words and sentiment words and the positional expressions of negation words and sentiment words output by the sentiment embedding layer into the second positional embedding layer, so that the second positional embedding layer adds the positional embedding expressions of negation words and sentiment words on the basis of the embedded expressions of negation words and sentiment words; The convolutional neural network layer extracts a feature expression of the position relationship between the negation word and the sentiment word based on the embedding expression of the negation word and the sentiment word and the position embedding expression of the negation word and the sentiment word; The second attention mechanism layer assigns different weights to each negation word or sentiment word based on the positional relationship feature expression obtained by the convolutional neural network layer, and performs weighted summation to obtain the negation and sentiment word feature expression; The splicing layer splices the text feature expression and the negation word and sentiment word feature expression to obtain a spliced global feature expression; The fully connected layer performs a feature fitting process on the global splicing feature expression through mapping to enhance the feature, thereby obtaining a transformed feature expression; The normalization layer maps the transformed feature expression to the final classification and outputs the result of the final classification, which includes the tendency emotion classification and the corresponding probability.
16. The method according to claim 9, wherein Before obtaining the training text set, include: Get sentences with text and emoticons; Obtaining the emotion classification corresponding to the expression; Using the sentiment analysis model to predict the sentiment classification corresponding to the text; Determine whether the emotion classification corresponding to the expression is consistent with the emotion classification corresponding to the text; If they are consistent, the sentence containing the text and the expression is used as a training text and added to the training text set.
17. The method according to claim 16, wherein The method further comprises: If the emotion classification corresponding to the expression and the emotion classification corresponding to the text are inconsistent, the emotion classification corresponding to the expression and the emotion classification corresponding to the text are output for the staff to refer to the emotion classification corresponding to the expression and the emotion classification corresponding to the text, and manually mark the emotion classification of the sentence carrying text and expression.
18. The method according to claim 16, wherein After adding the sentence containing the text and the emoticon as training text to the training text set, the method further includes: A loss function weight is configured for the added training text, so that when the added training text is used to train the sentiment analysis model, the corresponding loss function is adjusted using the loss function weight, and parameter adjustment is performed based on the adjusted loss function.
19. A text sentiment analysis device, wherein: The device comprises: A word segmentation information acquisition module, used to obtain the word segmentation expression of the text to be analyzed and the position expression of the word segmentation expression of the text to be analyzed; A module for acquiring information about negative words and sentiment words, configured to acquire the expressions of negative words and sentiment words in the text to be analyzed and the positional expressions of the negative words and sentiment words in the text to be analyzed; A prediction module is configured to input the segmentation expression, the positional expression of the segmentation, the negation word and sentiment word expressions, and the positional expression of the negation word and sentiment word of the text to be analyzed into the sentiment analysis model, and output a predicted tendency sentiment classification of the text to be analyzed, wherein the positional expression of the segmentation is used to embed the embedding expression corresponding to the segmentation expression, and the positional expression of the negation word and sentiment word is used to embed the embedding expression corresponding to the negation word and sentiment word expression; The tendency sentiment classification is a vector, each position in the vector corresponds to a sentiment classification, and the value of each position in the vector is the probability that the text to be analyzed belongs to the sentiment classification corresponding to the corresponding position.
20. The device according to claim 19, wherein The word segmentation information acquisition module is used to: Performing word segmentation on the text to be analyzed; According to a preset dictionary library and a mapping dictionary corresponding to the dictionary library, each word segment in the text to be analyzed is mapped to obtain a word segment expression of the text to be analyzed.
21. The apparatus according to claim 19, wherein The negative word and sentiment word information acquisition module is used to: Performing word segmentation on the text to be analyzed; According to a preset negative word library and a preset sentiment word library, obtaining negative words and sentiment words from all the word segments of the text to be analyzed; According to a preset feature mapping strategy for negation words and a preset feature mapping strategy for sentiment words, feature mapping is performed on the negation words and sentiment words in the text to be analyzed respectively to obtain the negation and sentiment expression of the text to be analyzed.
22. The apparatus according to claim 19, wherein The word segmentation information acquisition module is used to map the position expression of each word segmentation according to the position information of each word segmentation in the text to be analyzed; The negation word and sentiment word information acquisition module is used to map the positional expressions of the negation and sentiment according to the positional information of each of the negation words and the sentiment words in the text to be analyzed.
23. The apparatus according to claim 19, wherein The sentiment analysis model includes: A word segmentation processing layer based on a recurrent neural network for processing the word segmentation expression and the position expression of the word segmentation; A convolutional neural network-based negation and sentiment word processing layer for processing the negation and sentiment word expressions and the positional expressions of the negation and sentiment words; and Splicing processing layer.
24. The device according to claim 23, wherein The word segmentation processing layer includes: a word embedding layer, a first position embedding layer, a recurrent neural network layer and a first attention mechanism layer in sequence; the negative word and sentiment word processing layer includes: a sentiment embedding layer, a second position embedding layer, a convolutional neural network layer and a second attention mechanism layer in sequence; the splicing processing layer includes: a splicing layer, a fully connected layer and a normalization layer in sequence; The prediction module is used to: Inputting the word segmentation expression of the text to be analyzed into the word embedding layer of the sentiment analysis model to obtain an embedded expression of the word segmentation; Inputting the embedding expressions of the word segments output by the word embedding layer and the positional expressions of the word segments into the first positional embedding layer, so that the first positional embedding layer adds the positional embedding expressions of each word segment on the basis of the embedding expressions of the word segment; The recurrent neural network layer extracts a feature expression of the word containing context information based on the word embedding expression and the position embedding expression; The first attention mechanism layer assigns different weights to each word segmentation based on the feature expression of the word segmentation obtained by the recurrent neural network layer, and performs weighted summation to obtain the text feature expression; Inputting the negation and sentiment word expressions into the sentiment embedding layer to obtain the embedding expressions of the negation words and sentiment words; Inputting the embedded expressions of the negation words and the sentiment words and the positional expressions of the negation words and the sentiment words output by the sentiment embedding layer into the second positional embedding layer, so that the second positional embedding layer adds the positional embedding expressions of the negation words and the sentiment words on the basis of the embedded expressions of the negation words and the sentiment words; The convolutional neural network layer extracts a feature expression of the position relationship between the negation word and the sentiment word based on the embedding expression of the negation word and the sentiment word and the position embedding expression of the negation word and the sentiment word; The second attention mechanism layer assigns different weights to each negation word or sentiment word based on the positional relationship feature expression obtained by the convolutional neural network layer, and performs weighted summation to obtain the feature expression of the negation word and sentiment word; The splicing layer splices the text feature expression and the negation word and sentiment word feature expression to obtain a spliced global feature expression; The fully connected layer performs a feature fitting process on the global splicing feature expression through mapping to enhance the feature, thereby obtaining a transformed feature expression; The normalization layer maps the transformed feature expression to the final classification and outputs the result of the final classification, which includes the tendency emotion classification and the corresponding probability.
25. The apparatus according to claim 24, wherein The device further comprises: A weight acquisition module, which obtains the feature expression of the word segmentation obtained by the first attention mechanism layer based on the recurrent neural network layer, assigns different weights to each word segmentation, and normalizes the weights of the word segmentation at each position, and outputs the normalized weights of each word segmentation; A target segmentation acquisition module is used to acquire the target segmentation with the largest normalized weight from the multiple segmentations of the text to be analyzed according to the normalized weights of the segmentations; A judgment module, configured to judge whether the target word is included in the sentiment word library corresponding to the tendency sentiment classification; A marking module, configured to mark the target word as a suspected sentiment word if not included; The judgment module is further configured to judge whether the normalized weight of the target participle is greater than a preset weight threshold, and whether the total number of times the target participle is marked as a suspected sentiment word is greater than a preset number threshold; A merging module is used to merge the target segmented word into the sentiment word library corresponding to the tendency sentiment classification based on the judgment of the judgment module.
26. A training device for a sentiment analysis model, wherein: The device comprises: An acquisition module is used to obtain a training text set; An extraction module is used to extract a training sample set based on a training text set, wherein each training sample in the training sample set includes a segmentation expression, a position expression of the segmentation, a negation word and an emotion word expression, a position expression of the negation word and the emotion word, and a known emotion classification; A training module, configured to train a sentiment analysis model based on the training sample set; The training module is used to: Inputting the segmentation expression, the position expression of the segmentation, the negation word and sentiment word expression, and the position expression of the negation word and sentiment word of each training sample into the sentiment analysis model, obtaining the sentiment analysis model to predict and output the corresponding tendency sentiment classification of the training sample, the tendency sentiment classification is a vector, each position in the vector corresponds to a sentiment classification, and the value of each position in the vector is the probability that the training sample belongs to the sentiment classification corresponding to the corresponding position; The positional expression of the word segmentation is used to embed the embedding expression corresponding to the word segmentation expression, and the positional expression of the negation word and the sentiment word is used to embed the embedding expression corresponding to the negation word and the sentiment word expression.
27. The device according to claim 26, wherein The extraction module is used to: Obtaining the word segmentation expression of each training text in the training text set; Obtaining the negative words and sentiment words expressions of each training text in the training text set; Obtain the known sentiment classification of each training text in the training text set.
28. The apparatus according to claim 27, wherein The extraction module is used to: Performing word segmentation on each of the training texts; According to a preset dictionary library and a mapping dictionary corresponding to the dictionary library, each word segment in each of the training texts is mapped to obtain a corresponding word segment expression of the training text.
29. The apparatus according to claim 27, wherein The extraction module is used to: Performing word segmentation on each of the training texts; According to a preset negative word library and a preset emotional word library corresponding to the known emotional classification, obtaining negative words and emotional words from all the word segments of each training text; According to the preset feature mapping strategy for negation words and the preset feature mapping strategy for sentiment words, feature mapping is performed on the negation words and sentiment words in each training text respectively to obtain the corresponding negation and sentiment expression of the training text.
30. The apparatus of claim 27, wherein: The extraction module is further used to: Obtaining the positional expression of the word segmentation of each training text in the training text set; Obtain the positional expressions of the negative words and sentiment words of each training text in the training text set.
31. The device according to claim 30, wherein The extraction module is further configured to: According to the position information of each segmentation in each training text, mapping the position expression of the segmentation in the corresponding training text; Obtaining the positional expressions of the negation words and sentiment words of each training text in the training text set includes: According to the position information of each negation word and the sentiment word in each training text, the position expression of the negation and sentiment of the corresponding training text is mapped out.
32. The apparatus according to claim 31, wherein The sentiment analysis model includes: A word segmentation processing layer based on a recurrent neural network for processing the word segmentation expression and the position expression of the word segmentation; A convolutional neural network-based negation and sentiment word processing layer for processing the negation and sentiment word expressions and the positional expressions of the negation and sentiment words; and Splicing processing layer.
33. The apparatus according to claim 32, wherein The word segmentation processing layer includes: a word embedding layer, a first position embedding layer, a recurrent neural network layer and a first attention mechanism layer in sequence; the negative word and sentiment word processing layer includes: a sentiment embedding layer, a second position embedding layer, a convolutional neural network layer and a second attention mechanism layer in sequence; the splicing processing layer includes: a splicing layer, a fully connected layer and a normalization layer in sequence; The training module is used to: When training each training sample, the word segmentation expression of the training sample is input into the word embedding layer of the sentiment analysis model to obtain the embedded expression of the word segmentation; Inputting the embedding expressions of the word segments output by the word embedding layer and the positional expressions of the word segments into the first positional embedding layer, so that the first positional embedding layer adds the positional embedding expressions of each word segment on the basis of the embedding expressions of the word segment; The recurrent neural network layer extracts a feature expression containing context information of the word segmentation based on the word segmentation embedding expression and the position embedding expression of each word segmentation; The first attention mechanism layer assigns different weights to each word segmentation based on the feature expression of the word segmentation obtained by the recurrent neural network layer, and performs weighted summation to obtain the text feature expression; Inputting the negation and sentiment word expressions into the sentiment embedding layer to obtain the embedding expressions of the negation words and sentiment words; Inputting the embedded expressions of negation words and sentiment words and the positional expressions of negation words and sentiment words output by the sentiment embedding layer into the second positional embedding layer, so that the second positional embedding layer adds the positional embedding expressions of negation words and sentiment words on the basis of the embedded expressions of negation words and sentiment words; The convolutional neural network layer extracts a feature expression of the position relationship between the negation word and the sentiment word based on the embedding expression of the negation word and the sentiment word and the position embedding expression of the negation word and the sentiment word; The second attention mechanism layer assigns different weights to each negation word or sentiment word based on the positional relationship feature expression obtained by the convolutional neural network layer, and performs weighted summation to obtain the negation and sentiment word feature expression; The splicing layer splices the text feature expression and the negation word and sentiment word feature expression to obtain a spliced global feature expression; The fully connected layer performs a transformation on the global splicing feature expression to enhance the feature fitting capability through mapping, thereby obtaining a transformed feature expression; The normalization layer maps the transformed feature expression to the final classification and outputs the result of the final classification, which includes the tendency emotion classification and the corresponding probability.
34. The apparatus of claim 27, wherein: The device also includes a prediction module, a judgment module and an addition module; The acquisition module is further used to acquire sentences containing text and emoticons; The acquisition module is further used to obtain the emotion classification corresponding to the expression; The prediction module is used to predict the sentiment classification corresponding to the text using the sentiment analysis model; The judgment module is used to judge whether the emotion classification corresponding to the expression is consistent with the emotion classification corresponding to the text; The adding module is used to add the sentence carrying text and expression as training text to the training text set based on the judgment of the judging module, if they are consistent.
35. The apparatus of claim 34, wherein: The device further comprises: The output module is used to output the emotion classification corresponding to the expression and the emotion classification corresponding to the text if the emotion classification corresponding to the expression and the emotion classification corresponding to the text are inconsistent, so that the staff can refer to the emotion classification corresponding to the expression and the emotion classification corresponding to the text and manually mark the emotion classification of the sentence carrying text and expression.
36. The apparatus of claim 34, wherein: The device further comprises: A configuration module is used to configure a loss function weight for the added training text, so that when the added training text is used to train the sentiment analysis model, the corresponding loss function is adjusted using the loss function weight, and parameter adjustment is performed based on the adjusted loss function.
37. A computing device comprising: processor; as well as A memory having executable codes stored thereon, which, when executed by the processor, causes the processor to execute the method according to any one of claims 1 to 7, or to execute the method according to any one of claims 8 to 18.
38. A non-transitory machine-readable storage medium having executable code stored thereon, which, when executed by a processor of an electronic device, causes the processor to execute the method according to any one of claims 1 to 7, or the method according to any one of claims 8 to 18.