Text sentiment tendency analysis method, device, equipment and medium
By using the Transformer architecture and self-attention mechanism in text sentiment analysis, combined with gated recurrent units, features are extracted from the text and sentence vectors are generated, which solves the problems of long-distance dependencies and parallel training samples in the existing technology. Improved the accuracy of sentiment analysis.
Patent Information
- Application Number
- CN202210433270.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-04-24
- Publication Date
- 2024-09-27
- Estimated Expiration
- 2042-04-24
AI Technical Summary
It is difficult for the existing technology to effectively capture long-distance dependencies and parallel training samples in text sentiment analysis, resulting in limited accuracy of sentiment analysis.
Using the text emotional tendency analysis method based on the Transformer architecture, by extracting semantic features, part-of-speech features and co-occurring word features from the text to be analyzed, combined with the self-attention mechanism and gated recurrent units, sentence vectors are generated and input into the emotional tendency analysis. The model outputs the emotional tendency analysis results.
It improves the accuracy of text sentiment analysis, can better capture the correlation and semantic correlation of words at different distances, and solves the problems of long-distance dependencies and parallel training samples.
Smart Images

Figure CN114691836B
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of artificial intelligence technology, and more specifically to a method, device, equipment, medium and program product for analyzing the sentiment tendency of a text. Background Art
[0002] With the rapid development of Internet technology, especially the rise of social networks such as WeChat and Twitter, Internet users publish or disseminate a huge amount of information every day. Among them, a large part of the information contains user opinions and emotional tendencies, which is a very valuable resource of opinions, including people's different views and positions on various social phenomena. The topic not only involves all aspects of our lives, but also involves all fields. Therefore, the use of computer technology to automatically analyze and process emotional text information has great application value in inventions such as auxiliary prediction, precision marketing, and decision-making. Summary of the invention
[0003] In view of the above problems, the present disclosure provides a method, apparatus, device, medium and program product for analyzing the sentiment tendency of a text.
[0004] According to a first aspect of the present disclosure, a method for analyzing the sentiment tendency of a text is provided, comprising:
[0005] Extracting semantic features, part-of-speech features, and co-occurring word features from the text to be analyzed, respectively, wherein the text to be analyzed includes text content and comment content associated with the text content;
[0006] Concatenate semantic features, part-of-speech features, and co-occurring word features to obtain concatenated features;
[0007] Preprocess the concatenated features to obtain word sequence features in the text to be analyzed;
[0008] Aggregate the word sequence features in the text to be analyzed to obtain the sentence vector of the text to be analyzed; and
[0009] The sentence vector is input into the sentiment tendency analysis model, and the sentiment tendency analysis result of the text to be analyzed is output.
[0010] According to an embodiment of the present disclosure, the concatenation features are preprocessed to obtain word sequence features in the text to be analyzed, including:
[0011] Perform linear activation transformation on the concatenated features to generate linear activation features;
[0012] Perform nonlinear activation transformation on the concatenated features to generate nonlinear activation features;
[0013] Based on the concatenated features, the weight vector is obtained using the attention mechanism;
[0014] According to the weight vector, the linearly activated features and the nonlinearly activated features are combined to obtain the word sequence features in the text to be analyzed.
[0015] According to an embodiment of the present disclosure, based on the splicing feature, the weight vector is obtained by using the attention mechanism, including:
[0016] According to different mapping matrices, the concatenated features are converted into query vectors, key vectors, and value vectors;
[0017] Use the attention mechanism to obtain splicing features with different weight values;
[0018] The splicing features with different weight values are reduced in dimension through the forward propagation layer to obtain the splicing features with different weight values after dimension reduction;
[0019] The concatenated features with different weight values after dimensionality reduction are used to generate a weight vector through a nonlinear activation function.
[0020] According to an embodiment of the present disclosure, aggregating word sequence features in a text to be analyzed to obtain a sentence vector of the text to be analyzed includes:
[0021] Input the word sequence features in the text to be analyzed into the gated recurrent unit;
[0022] Output the sentence vector of the text to be analyzed.
[0023] According to an embodiment of the present disclosure, extracting semantic features, part-of-speech features, and co-occurrence word features from the text to be analyzed includes:
[0024] Input the text to be analyzed into the pre-trained language representation model and output semantic features;
[0025] Embed the words that co-occur in the text content and the comment content to obtain the co-occurrence word features;
[0026] The part of speech of each word in the text to be analyzed is embedded to obtain the part of speech feature.
[0027] According to an embodiment of the present disclosure, the sentiment tendency analysis model is obtained by pre-training; the pre-training method includes:
[0028] Extracting sample semantic features, sample part-of-speech features, and sample co-occurring word features from training samples, respectively, wherein the training samples include: text content samples, comment content samples associated with the text content samples, and sentiment labels;
[0029] Concatenate the sample semantic features, sample part-of-speech features, and sample co-occurring word features to obtain sample concatenation features;
[0030] Preprocess the sample concatenation features to obtain sample word sequence features in the training samples;
[0031] Aggregate the sample word sequence features in the training sample to obtain the sample sentence vector of the training sample;
[0032] Input the sample sentence vector into the classification model and output the sentiment tendency classification result of the training sample;
[0033] Based on the sentiment tendency classification results and sentiment labels, the parameters of the classification model are adjusted, and the trained classification model is used as a sentiment tendency analysis model.
[0034] A second aspect of the present disclosure provides a text sentiment tendency analysis device, comprising:
[0035] A feature extraction module, used to extract semantic features, part-of-speech features and co-occurrence word features from the text to be analyzed, wherein the text to be analyzed includes text content and comment content associated with the text content;
[0036] A feature concatenation module is used to concatenate semantic features, part-of-speech features, and co-occurring word features to obtain concatenated features;
[0037] A preprocessing module, used for preprocessing the splicing features to obtain word sequence features in the text to be analyzed;
[0038] An aggregation module, used to aggregate word sequence features in the text to be analyzed to obtain a sentence vector of the text to be analyzed; and
[0039] The analysis module is used to input the sentence vector into the sentiment tendency analysis model and output the sentiment tendency analysis result of the text to be analyzed.
[0040] The third aspect of the present disclosure provides an electronic device, comprising: one or more processors; and a memory for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors execute the above-mentioned method for analyzing the sentiment tendency of the text.
[0041] The fourth aspect of the present disclosure also provides a computer-readable storage medium having executable instructions stored thereon, which, when executed by a processor, causes the processor to execute the above-mentioned method for analyzing the sentiment tendency of the text.
[0042] The fifth aspect of the present disclosure also provides a computer program product, including a computer program, which implements the above-mentioned method for analyzing the sentiment tendency of the text when executed by a processor.
[0043] According to the embodiments of the present disclosure, the semantic features, co-occurrence word features and part-of-speech features of the text to be analyzed are extracted to obtain the splicing features; the splicing features are pre-processed to enhance the features and then aggregate them to obtain the sentence vector of the text to be analyzed, which is then input into the sentiment tendency analysis model to obtain the sentiment tendency analysis results. In order to fully explore the language features of the text to be analyzed, the co-occurrence word features and the part-of-speech features of the analyzed text are integrated to assist the sentiment tendency analysis. And the features are aggregated to obtain the sentence vector of the text to be analyzed, which improves the accuracy of the sentiment tendency analysis. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] The above contents and other objects, features and advantages of the present disclosure will become more apparent through the following description of the embodiments of the present disclosure with reference to the accompanying drawings, in which:
[0045] Figure 1 The application scenario diagram of the text sentiment tendency analysis method, device, equipment, medium and program product according to the embodiment of the present disclosure is schematically shown;
[0046] Figure 2 The flowchart of the method for analyzing the sentiment tendency of text according to the embodiment of the present disclosure is schematically shown;
[0047] Figure 3 A flowchart of a method for preprocessing concatenation features to obtain word sequence features in a text to be analyzed according to an embodiment of the present disclosure is schematically shown;
[0048] Figure 4 A schematic diagram of a model architecture for obtaining a sentence vector of a text to be analyzed in a method for analyzing the sentiment tendency of a text according to an embodiment of the present disclosure is shown;
[0049] Figure 5 The flowchart of the method of obtaining the sentiment tendency analysis model through pre-training according to the embodiment of the present disclosure is schematically shown;
[0050] Figure 6 A schematic diagram of a structure of a sentiment tendency analysis device according to an embodiment of the present disclosure is shown; and
[0051] Figure 7 A block diagram of an electronic device suitable for implementing the sentiment tendency analysis method according to an embodiment of the present disclosure is schematically shown. DETAILED DESCRIPTION
[0052] Hereinafter, embodiments of the present disclosure will be described with reference to the accompanying drawings. However, it should be understood that these descriptions are exemplary only and are not intended to limit the scope of the present disclosure. In the following detailed description, for ease of explanation, many specific details are set forth to provide a comprehensive understanding of the embodiments of the present disclosure. However, it is apparent that one or more embodiments may also be implemented without these specific details. In addition, in the following description, descriptions of known structures and technologies are omitted to avoid unnecessary confusion of the concepts of the present disclosure.
[0053] The terms used herein are only for describing specific embodiments and are not intended to limit the present disclosure. The terms "comprise", "include", etc. used herein indicate the existence of the features, steps, operations and / or components, but do not exclude the existence or addition of one or more other features, steps, operations or components.
[0054] All terms (including technical and scientific terms) used herein have the meanings commonly understood by those skilled in the art, unless otherwise defined. It should be noted that the terms used herein should be interpreted as having a meaning consistent with the context of this specification, and should not be interpreted in an idealized or overly rigid manner.
[0055] When using expressions such as "at least one of A, B, and C, etc.", they should generally be interpreted according to the meaning of the expression commonly understood by those skilled in the art (for example, "a system having at least one of A, B, and C" should include but is not limited to a system having A alone, B alone, C alone, A and B, A and C, B and C, and / or A, B, C, etc.).
[0056] In the technical solution disclosed in the present invention, the acquisition, storage and application of user personal information involved are in compliance with the provisions of relevant laws and regulations, necessary confidentiality measures are taken, and do not violate public order and good morals.
[0057] In the related technologies, there are three main types of text sentiment analysis methods. The first is the text dictionary plus statistical machine learning method. This type of method has a wide range of application scenarios and is simple to use. It mainly solves the sentiment analysis task by calculating word frequency and adding machine learning methods. Based on keywords, a dictionary is pre-established in combination with the target scenario. When used, the sentiment of the keyword is summarized to determine the sentiment of the sentence. This is a bottom-up method. The construction of a sentiment dictionary requires a lot of manual labor.
[0058] Sentiment tendency analysis methods based on deep learning are mainly based on CNN (convolutional neural network) structures and RNN (recurrent neural network), and the effect is greatly improved. However, for long-distance dependencies, the gradient disappears, and long-distance information cannot be captured when the sequence is long. Then LSTM (long short-term memory network) came into being. It has long-term memory function. It is simple to implement and has certain advantages in sequence modeling problems. But in general, the recurrent model (RNN) takes the position of the symbols of the input and output sequences as factors for calculation. In the process of aligning the position with the calculation time step, a series of hidden states are generated based on the input of the previous hidden state and the position. This inherent sequential nature makes it impossible to train training samples in parallel. This problem is particularly critical when facing longer sequences and the memory is insufficient to provide larger batch training. Although people have improved computational efficiency through factorization techniques and conditional computation (the latter also improves the performance of the model). However, the inherent sequential nature has not been solved.
[0059] In the process of implementing the present disclosure, it is found that the attention mechanism has become an integral part of various sequence modeling and transformation model tasks. It can model the dependencies between symbols without considering the symbol distance. However, in most cases, such an attention mechanism is used with RNN (recurrent neural network). The Transformer architecture abandons the RNN (recurrent neural network) structure and relies entirely on the attention mechanism to draw the global dependencies between input and output. The Transformer model has better parallelism and has achieved significant performance improvements in NLP (natural language processing) tasks.
[0060] Most NLP (natural language processing) related tasks also use the Transformer structure. Using BERT as the upstream model, taking advantage of its pre-trained generalization advantage, combined with CNN (convolutional neural network) / LSTM (long short-term memory network) for downstream classification, the effect will be greatly improved. The reason is that its internal multiple Attention mechanisms can better capture the correlation of words at different distances, and semantically related words are also closer in the vector space after mapping.
[0061] Based on this, an embodiment of the present disclosure provides a sentiment tendency analysis method, including: extracting semantic features, part-of-speech features and co-occurrence word features from a text to be analyzed, wherein the text to be analyzed includes text content and comment content associated with the text content; splicing the semantic features, part-of-speech features and co-occurrence word features to obtain splicing features; preprocessing the splicing features to obtain word sequence features in the text to be analyzed; aggregating the word sequence features in the text to be analyzed to obtain a sentence vector of the text to be analyzed; and inputting the sentence vector into a sentiment tendency analysis model to output a sentiment tendency analysis result of the text to be analyzed.
[0062] Figure 1 The application scenario diagram of the text sentiment tendency analysis method, device, equipment, medium and program product according to the embodiment of the present disclosure is schematically shown.
[0063] like Figure 1 As shown, the application scenario 100 according to this embodiment may include terminal devices 101, 102, 103, a network 104 and a server 105. The network 104 is used to provide a medium for a communication link between the terminal devices 101, 102, 103 and the server 105. The network 104 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.
[0064] Users can use terminal devices 101, 102, 103 to interact with server 105 through network 104 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 101, 102, 103, such as financial product applications, shopping applications, web browser applications, search applications, instant messaging tools, email clients, social platform software, etc. (only as examples).
[0065] The terminal devices 101 , 102 , and 103 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, and desktop computers.
[0066] The server 105 may be a server that provides various services, such as a background management server (only an example) that provides support for websites browsed by users using the terminal devices 101, 102, and 103. The background management server may analyze and process the received data such as user requests, and feed back the processing results (such as web pages, information, or data obtained or generated according to user requests) to the terminal device.
[0067] It should be noted that the text sentiment tendency analysis method provided in the embodiment of the present disclosure can generally be executed by the server 105. Accordingly, the text sentiment tendency analysis device provided in the embodiment of the present disclosure can generally be set in the server 105. The text sentiment tendency analysis method provided in the embodiment of the present disclosure can also be executed by a server or server cluster that is different from the server 105 and can communicate with the terminal devices 101, 102, 103 and / or the server 105. Accordingly, the text sentiment tendency analysis device provided in the embodiment of the present disclosure can also be set in a server or server cluster that is different from the server 105 and can communicate with the terminal devices 101, 102, 103 and / or the server 105.
[0068] The text sentiment tendency analysis method provided by the embodiment of the present disclosure may also be executed by the terminal devices 101, 102, 103. Accordingly, the text sentiment tendency analysis apparatus provided by the embodiment of the present disclosure may also be generally arranged in the terminal devices 101, 102, 103. The text sentiment tendency analysis method provided by the embodiment of the present disclosure may also be executed by other terminals different from the terminal devices 101, 102, 103. Accordingly, the text sentiment tendency analysis apparatus provided by the embodiment of the present disclosure may also be arranged in other terminals different from the terminal devices 101, 102, 103.
[0069] It should be understood that Figure 1 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.
[0070] The following will be based on Figure 1 The scene described by Figure 2 to Figure 5 The method for analyzing the sentiment tendency of text in an embodiment of the present disclosure is described in detail.
[0071] Figure 2 The flowchart of the method for analyzing the sentiment tendency of text according to an embodiment of the present disclosure is schematically shown.
[0072] like Figure 2 As shown, the text sentiment tendency analysis method 200 of this embodiment includes operations S201 to S205.
[0073] In operation S201 , semantic features, part-of-speech features, and co-occurring word features are respectively extracted from a text to be analyzed, wherein the text to be analyzed includes text content and comment content associated with the text content.
[0074] According to the embodiments of the present disclosure, the acquired text to be analyzed can be encoded by the BERT double sentence mode to obtain semantic features. The co-occurring words in the text content and the comments associated with the text content can be identified and then encoded to obtain co-occurring word features. The part of speech of the text to be analyzed can be annotated by the word segmentation tool jieba to construct part of speech features.
[0075] In operation S202, semantic features, part-of-speech features, and co-occurring word features are concatenated to obtain concatenated features.
[0076] In operation S203, the concatenated features are preprocessed to obtain word sequence features in the text to be analyzed.
[0077] According to an embodiment of the present disclosure, the concatenated features can be enhanced and transferred by using a Highway Network based on a self-attention mechanism to obtain word sequence features in the text to be analyzed.
[0078] It should be noted that Highway Network introduces Transform Gate and Carry Gate based on the gate mechanism, and the output consists of the corresponding transform input and carry input. When generating the Transform Gate, the traditional method directly performs linear transformation and nonlinear activation on the input vector to obtain the output value of the learnable gate unit, making the behavior of the gate mechanism between feature transformation and feature transfer. This traditional transformation gate generation method assigns equal weight to each dimension in the input vector, without considering the difference in the amount of information carried by different dimensions of the feature vector.
[0079] In operation S204, the word sequence features in the text to be analyzed are aggregated to obtain a sentence vector of the text to be analyzed.
[0080] According to an embodiment of the present disclosure, word sequence features in the text to be analyzed may be input into a gated recurrent unit (GRU), and the word information may be aggregated by capturing the dependency between word vectors to obtain a sentence vector of the text to be analyzed.
[0081] In operation S205, the sentence vector is input into the sentiment tendency analysis model, and the sentiment tendency analysis result of the text to be analyzed is output.
[0082] According to an embodiment of the present disclosure, the sentiment tendency analysis model can be obtained through pre-training, and the sentiment tendency analysis result of the text to be analyzed can be output after the sentence vector is input. The sentiment tendency analysis result can include positive, negative, neutral, etc.
[0083] According to the embodiments of the present disclosure, the semantic features, co-occurrence word features and part-of-speech features of the text to be analyzed are extracted to obtain the splicing features; the splicing features are pre-processed to enhance the features and then aggregate them to obtain the sentence vector of the text to be analyzed, which is then input into the sentiment tendency analysis model to obtain the sentiment tendency analysis results. In order to fully explore the language features of the text to be analyzed, the co-occurrence word features and the part-of-speech features of the analyzed text are integrated to assist the sentiment tendency analysis. And the features are aggregated to obtain the sentence vector of the text to be analyzed, which improves the accuracy of the sentiment tendency analysis.
[0084] Figure 3 A flowchart of a method for preprocessing concatenation features to obtain word sequence features in a text to be analyzed according to an embodiment of the present disclosure is schematically shown; Figure 4 The figure schematically shows a model architecture diagram for obtaining sentence vectors of a text to be analyzed in a method for analyzing the sentiment tendency of a text according to an embodiment of the present disclosure.
[0085] like Figure 3 As shown, the method 300 of preprocessing the splicing features to obtain the word sequence features in the text to be analyzed in this embodiment includes operations S301 to S304.
[0086] In the embodiments of the present disclosure, Figure 4 As shown, the semantic features (Bert_Out), part-of-speech features (tag_feature) and co-occurrence features (word_match) of the text to be analyzed can be concatenated to obtain concatenated features. The Highway Network based on the self-attention mechanism is used to enhance and transfer features and obtain word sequence features in the text to be analyzed.
[0087] For example, the sentence length of the text to be analyzed can be n, where n is a positive integer. It can be mapped to a sentence sequence vector W through a dictionary, as shown in the following formula (1):
[0088] W=[w1,w2,…,w n ] (1)
[0089] The sentence sequence vector W can be input into the BERT model encoding to obtain the semantic feature F w , as shown in the following formula (2):
[0090] F w =BERT(W) (2)
[0091] Among them, the w corresponding to the i-th word in the sentence sequence vector W is i , after BERT encoding, the semantic feature f can be obtained i , f iThe corresponding dimension is d h , so the semantic feature F w , can also be expressed as shown in the following formula (3):
[0092]
[0093] The semantic features F of the text to be analyzed can be w , part-of-speech feature F t And the co-occurrence feature F c Splicing, we get the splicing feature F, as shown in the following formula (4):
[0094] F=[F w :F t :F c ](4)
[0095] Among them, [:] represents the operation of splicing according to the sequence dimension; n c represents the length of the co-occurring word encoding after word embedding, n t Represents the length of the part-of-speech tag after embedding.
[0096] In operation S301, linear activation transformation is performed on the concatenated features to generate linear activation features.
[0097] According to an embodiment of the present disclosure, for example, the concatenated feature F may be subjected to a linear activation transformation to generate a linearly activated feature F L , as shown in the following formula (5): L =W L ·F+b L (5)
[0098] Among them, W L , b L denote the trainable parameter matrix and bias constant respectively.
[0099] In operation S302, nonlinear activation transformation is performed on the concatenated features to generate nonlinear activated features.
[0100] According to an embodiment of the present disclosure, for example, the concatenated feature F can be subjected to a nonlinear activation transformation to generate a nonlinearly activated feature F N , as shown in the following formula (6):
[0101]
[0102] Where σ(·) represents the nonlinear activation function used. Here, the tanh function can be used. N , Both represent trainable parameters.
[0103] In operation S303, based on the concatenated features, a weight vector is obtained using an attention mechanism.
[0104] According to an embodiment of the present disclosure, based on the splicing feature, the weight vector is obtained by using the attention mechanism, including:
[0105] According to different mapping matrices, the concatenated features are converted into query vectors, key vectors, and value vectors;
[0106] Use the attention mechanism to obtain splicing features with different weight values;
[0107] The splicing features with different weight values are reduced in dimension through the forward propagation layer to obtain the splicing features with different weight values after dimension reduction;
[0108] The concatenated features with different weight values after dimensionality reduction are used to generate a weight vector through a nonlinear activation function.
[0109] According to the embodiments of the present disclosure, Figure 4 As shown in the figure, a multi-head self-attention mechanism can be used to take the concatenated features as input, and different mapping matrices are used to linearly transform the concatenated features to generate Query (query vector), Key (key vector), and Value (value vector) vectors, and then the multi-head self-attention mechanism (Self Attention) is used to aggregate the different dimensions of the input features with different weights. After the multi-head output features are concatenated, they are reduced in dimension through the forward propagation layer (FeedForward), and finally the Gate Vector weight vector is generated through the nonlinear activation function softmax. Two layers of residual connections and normalization layers (Add&Norm) are added to the entire multi-head attention mechanism to prevent overfitting. The output GateVector weight vector contains the Transform Gate value and the corresponding Carry Gate value, which are used to aggregate the linearly activated features and the nonlinearly activated features in the next step, so that the word sequence features (feature sequence) in the text to be analyzed can be obtained by the gated recurrent unit (GRU), by capturing the dependency between word vectors, and aggregating the word information to obtain the sentence vector (sentence representation / feature) of the text to be analyzed.
[0110] For example, first use the concatenated feature F to get the i-th attention head (Head i ) Input: The query vector Q of the i-th attention head i , as shown in equation (7); the key vector K of the i-th attention head i , as shown in the following formula (8); the value vector V of the i-th attention head i, as shown in formula (9).
[0111] Q i =W q i ·F+b q i , (7)
[0112] K i =W k i ·F+b k i (8)
[0113] V i =W v i ·F+b v i (9)
[0114] Among them, W q i , W k i , W v i 、b q i 、b k i 、b v i Both represent trainable parameters.
[0115] Through the query vector Q i , the key vector K i , do similarity calculation, normalize the similarity score into weights through the softmax function, and then use the value vector V according to the similarity weight i Re-weighted, we get the i-th attention head (Head i ) output H i , as shown in the following formula (10):
[0116]
[0117] Where T represents the transpose operation of the matrix.
[0118] By calculating m times according to the above method, we can get the output H of m attention heads 1 ,H 2 ,…H m , and then concatenate to get the hidden representation H, through the linear matrix W h Do dimensionality reduction to get multi-head attention output And add residual connection and regularization between the concatenated feature F, as shown in the following formula (11):
[0119]
[0120] Among them, [:] represents the concatenation operation based on the sequence dimension.
[0121] Outputting multi-head attention After nonlinear mapping, residual connection and regularization are used again, and finally softmax normalization is performed to obtain the weight vector G, as shown in the following formula (12):
[0122]
[0123] Among them, σ2(·) represents the nonlinear mapping function used, and the RELU function W can be used here g , b g Represents a trainable parameter.
[0124] According to the embodiments of the present disclosure, the improved Highway Network can enable the gate mechanism to have stronger learning ability and make more reasonable behavior between feature conversion and feature transfer, thereby enabling the Highway Network to have stronger key feature capture ability.
[0125] In operation S304, the linearly activated features and the nonlinearly activated features are combined according to the weight vector to obtain word sequence features in the text to be analyzed.
[0126] According to an embodiment of the present disclosure, weight values may be assigned to linearly activated features and nonlinearly activated features according to a weight vector, and the features may be combined to obtain word sequence features in the text to be analyzed.
[0127] For example, the nonlinear feature F can be transformed into N and the linear feature F L We weight the word sequence feature F in the text to be analyzed. s , as shown in the following formula (13):
[0128] F s =G[0]⊙F N +G[1]⊙F L (13)
[0129] Among them, G[0] represents the element with G vector index 0; G[1] represents the element with G vector index 1.
[0130] According to an embodiment of the present disclosure, aggregating word sequence features in a text to be analyzed to obtain a sentence vector of the text to be analyzed includes:
[0131] Input the word sequence features in the text to be analyzed into the gated recurrent unit;
[0132] Output the sentence vector of the text to be analyzed.
[0133] For example, the word sequence feature F in the text to be analyzed can be s Input GRU encoding to obtain the sentence vector Rs of the text to be analyzed, as shown in the following formula (14):
[0134] R s =GRU(F s ) (14)
[0135] in,
[0136] According to an embodiment of the present disclosure, a text sentiment tendency analysis method based on BERT and an improved highway network combining a self-attention mechanism and GRU can improve the accuracy of text sentiment tendency analysis at the cost of increasing a small amount of computing resources.
[0137] According to an embodiment of the present disclosure, extracting semantic features, part-of-speech features, and co-occurrence word features from the text to be analyzed includes:
[0138] Input the text to be analyzed into the pre-trained language representation model and output semantic features;
[0139] Embed the words that co-occur in the text content and the comment content to obtain the co-occurrence word features;
[0140] The part of speech of each word in the text to be analyzed is embedded to obtain the part of speech feature.
[0141] According to the embodiments of the present disclosure, the traditional sentiment tendency analysis method uses pre-trained word vectors such as word2vec or glove as the word embedding of text words, which lacks the ability to capture the bidirectional relationship in the sentence and model the long-distance dependency relationship between words. The present disclosure uses a pre-trained language representation model (BERT model) based on the Transformer architecture as the semantic feature encoder of the text to be analyzed.
[0142] It should be noted that the encoder can be fine-tuned in pre-training, and the word embedding features obtained by running a self-supervised learning method based on a massive corpus can be used as the vector representation of the words in the text to be analyzed, and then fine-tuned in training. Finally, a text encoder that can be jointly adjusted according to the context is obtained as the semantic feature encoder of the text to be analyzed.
[0143] According to the embodiments of the present disclosure, the BERT double-sentence mode is adopted, which not only has a more powerful ability to capture the dependency relationship between words within a sentence at a fine-grained level, but also increases the ability to analyze and distinguish the consistency of sentiment tendencies between certain sentences at a broad granularity.
[0144] Figure 5 The flowchart schematically shows a method for obtaining a sentiment tendency analysis model through pre-training according to an embodiment of the present disclosure.
[0145] like Figure 5 As shown, the method 500 of obtaining the sentiment tendency analysis model of this embodiment through pre-training includes operations S501 to S506.
[0146] In operation S501, sample semantic features, sample part-of-speech features, and sample co-occurring word features are respectively extracted from training samples, wherein the training samples include: text content samples, comment content samples associated with the text content samples, and sentiment tags.
[0147] According to an embodiment of the present disclosure, an initial data sample may be first obtained, and then the initial data sample may be cleaned to obtain a training sample. Among them, cleaning the initial data sample may include first converting traditional Chinese characters into simplified Chinese characters and removing emoticons in the initial data sample to obtain a first processed data sample. Then, the format of the first processed data sample is unified to obtain a second processed data sample. The second processed data sample is divided into a training sample and a verification sample according to a certain ratio. The certain ratio can be determined according to the actual training model.
[0148] For example, we can obtain the sample of post (blog) text content and the sample of comments associated with it, and convert traditional Chinese characters into simplified Chinese characters through the functions defined in longcon.py and the dictionary defined in zh_wiki.py. Then we filter out the emoji emoticons in the text by calling the functions in the emoji library. We reunite the data in the format of [content, comment, publisher, politics], i.e. [blog content, blog comment, blog publisher, sentiment label], separated by English commas. For example, it can be: [This laptop is very easy to use and runs very fast. I recommend everyone to buy it. The same computer, in addition to running fast, is also very cheap and very cost-effective! , user 1111, +1], where +1 represents that the sentiment label is positive. Sentiment labels can be represented by -1 for negative and 0 for neutral.
[0149] Finally, the unified data is divided into training samples and verification samples in a ratio of 3:1.
[0150] According to an embodiment of the present disclosure, the BERT two-sentence mode can be used to encode the training sample, which consists of four parts: guid, the current training sample index; text_a: blog content sample; text_b: comment text associated with the blog content sample; label: sentiment label, to obtain the sample semantic features.
[0151] For characters that appear in both text_a and text_b, they can be marked as 1, otherwise they can be marked as 0; this method can be used to obtain sample co-occurrence word features to assist in sentiment tendency analysis.
[0152] For example, if text_a is: This laptop is very easy to use and runs very fast. I recommend you to buy it.
[0153] The corresponding text_b is: The same model of computer, in addition to running fast, is also very cheap, very cost-effective!
[0154] Then the sample co-occurrence word feature can be expressed as: 01000111100111111000000
[0155] Among them, it means that the characters such as "computer, runs fast, very" in text_a appear in text_b.
[0156] By introducing the Jieba word segmentation tool, sample part-of-speech features can be constructed to assist in sentiment analysis.
[0157] It should be noted that words of different parts of speech carry different emotional information. For example, adjectives such as "happy" and "angry" and verbs such as "oppose" and "resist" express obvious approval or opposition and contain obvious emotional tendencies. However, some conjunctions such as "and" and "then" can be considered to carry very little emotional information. Based on this, sample part-of-speech features are constructed to assist in emotional tendency analysis.
[0158] In operation S502, the sample semantic features, the sample part-of-speech features, and the sample co-occurring word features are concatenated to obtain a sample concatenated feature.
[0159] According to an embodiment of the present disclosure, the sample co-occurrence word features can be input into an embedding layer with a dimension of 2*1 and mapped into a single-valued vector, for example
[0160] [[0.0427],[0.0427],[-0.0015],[0.0427]……], the shape is 1*512*1.
[0161] The sample part-of-speech features can be input into the embedding layer with a dimension of 30*16, and the part-of-speech information of each character can be mapped to a 16-dimensional continuous vector. For example, the adjective 'a' is mapped to:
[0162] [0.0133, -0.0248, -0.0248, 0.0067……, -0.0092], the dimension of the part-of-speech feature vector of the entire sample is 1*512*16.
[0163] The sample semantic features can be represented as a vector of 1*512*768 dimensions through the BERT model.
[0164] The sample semantic features, sample part-of-speech features, and sample co-occurring word features can be concatenated in the third dimension to obtain a sample concatenated feature with a dimension of 1*512*785.
[0165] In operation S503, the sample concatenation features are preprocessed to obtain sample word sequence features in the training sample.
[0166] According to an embodiment of the present disclosure, the sample concatenation features can be input into the Highway Network for further feature extraction. The module in the Highway Network can be, for example, a 785*785 fully connected layer, which does not change the vector shape and outputs the sample word sequence features in the training sample.
[0167] In operation S504, sample word sequence features in the training sample are aggregated to obtain a sample sentence vector of the training sample.
[0168] According to an embodiment of the present disclosure, sample word sequence features in a training sample may be input into a GRU code to obtain a sample sentence vector of the training sample, for example, the dimension may be 1*785.
[0169] In operation S505, the sample sentence vector is input into the classification model, and the sentiment tendency classification result of the training sample is output.
[0170] According to the embodiments of the present disclosure, the sample sentence vector can be input into the 785*3 fully connected layer to output the score of each sentiment tendency category. For example, for the training sample: [This laptop is very easy to use and runs very fast. I recommend everyone to buy the same model of computer. In addition to running fast, it is also very cheap and very cost-effective! , user abcd, +1], for example, the probability that can be output is tensor ([-2.8360, -3.6533, 5.5173]), the third category has the highest probability, and the corresponding sentiment label is +1, which means that the sentiment tendency classification result of the training sample is positive.
[0171] In operation S506, based on the sentiment tendency classification result and the sentiment label, the parameters of the classification model are adjusted, and the trained classification model is used as a sentiment tendency analysis model.
[0172] According to an embodiment of the present disclosure, the loss can be calculated using the CrossEntropy loss function according to the probability (logits) and the emotional label (label) in the emotional tendency classification result, for example, Loss = CrossEntropy (logits, label) = 10.2660. The parameters of the classification model are adjusted according to the loss value, and the trained classification model is used as the emotional tendency analysis model.
[0173] According to the embodiments of the present disclosure, the embedding of each character, the BERT model, and model parameters such as Highway Network and GRU can be updated during the loss back propagation process, and the adam optimizer can be used with the initial learning rate set to 1e-5. The update and iteration are continuously performed to reduce the loss to below 1, and a converged model can be obtained for prediction.
[0174] Based on the above text sentiment tendency analysis method, the present disclosure also provides a text sentiment tendency analysis device. Figure 6 The device is described in detail.
[0175] Figure 6 The structural block diagram of the text sentiment tendency analysis device according to an embodiment of the present disclosure is schematically shown.
[0176] like Figure 6 As shown, the text sentiment tendency analysis device 600 of this embodiment includes a feature extraction module 610, a feature splicing module 620, a preprocessing module 630, an aggregation module 640 and an analysis module 650.
[0177] The feature extraction module 610 is used to extract semantic features, part-of-speech features, and co-occurrence word features from the text to be analyzed, wherein the text to be analyzed includes text content and comment content associated with the text content. In one embodiment, the feature extraction module 610 can be used to perform the operation S201 described above, which will not be repeated here.
[0178] The feature concatenation module 620 is used to concatenate the semantic features, the part-of-speech features and the co-occurring word features to obtain concatenated features. In one embodiment, the feature concatenation module 620 can be used to perform the operation S202 described above, which will not be described in detail here.
[0179] The preprocessing module 630 is used to preprocess the splicing features to obtain word sequence features in the text to be analyzed. In one embodiment, the preprocessing module 630 can be used to perform the operation S203 described above, which will not be described in detail here.
[0180] Aggregation module 640 is used to aggregate word sequence features in the text to be analyzed to obtain a sentence vector of the text to be analyzed. In one embodiment, aggregation module 640 can be used to perform operation S204 described above, which will not be described in detail here.
[0181] The analysis module 650 is used to input the sentence vector into the sentiment tendency analysis model and output the sentiment tendency analysis result of the text to be analyzed. In one embodiment, the analysis module 650 can be used to perform the operation S205 described above, which will not be described in detail here.
[0182] According to an embodiment of the present disclosure, any multiple modules of the feature extraction module 610, the feature splicing module 620, the preprocessing module 630, the aggregation module 640 and the analysis module 650 can be combined in one module for implementation, or any one of the modules can be split into multiple modules. Alternatively, at least part of the functions of one or more of these modules can be combined with at least part of the functions of other modules and implemented in one module. According to an embodiment of the present disclosure, at least one of the feature extraction module 610, the feature splicing module 620, the preprocessing module 630, the aggregation module 640 and the analysis module 650 can be at least partially implemented as a hardware circuit, such as a field programmable gate array (FPGA), a programmable logic array (PLA), a system on a chip, a system on a substrate, a system on a package, an application specific integrated circuit (ASIC), or can be implemented by hardware or firmware such as any other reasonable way of integrating or packaging the circuit, or implemented in any one of the three implementation methods of software, hardware and firmware or in an appropriate combination of any of them. Alternatively, at least one of the feature extraction module 610, the feature stitching module 620, the preprocessing module 630, the aggregation module 640 and the analysis module 650 may be at least partially implemented as a computer program module, which may perform corresponding functions when executed.
[0183] Figure 7 A block diagram of an electronic device suitable for a method for analyzing the sentiment tendency of text according to an embodiment of the present disclosure is schematically shown.
[0184] like Figure 7As shown, the electronic device 700 according to an embodiment of the present disclosure includes a processor 701, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 702 or a program loaded from a storage part 708 into a random access memory (RAM) 703. The processor 701 may include, for example, a general-purpose microprocessor (e.g., a CPU), an instruction set processor and / or a related chipset and / or a special-purpose microprocessor (e.g., an application-specific integrated circuit (ASIC)), etc. The processor 701 may also include an onboard memory for caching purposes. The processor 701 may include a single processing unit or multiple processing units for performing different actions of the method flow according to an embodiment of the present disclosure.
[0185] In RAM 703, various programs and data required for the operation of electronic device 700 are stored. Processor 701, ROM 702 and RAM 703 are connected to each other via bus 704. Processor 701 performs various operations of the method flow according to the embodiment of the present disclosure by executing the program in ROM 702 and / or RAM 703. It should be noted that the program can also be stored in one or more memories other than ROM 702 and RAM 703. Processor 701 can also perform various operations of the method flow according to the embodiment of the present disclosure by executing the program stored in the one or more memories.
[0186] According to an embodiment of the present disclosure, the electronic device 700 may further include an input / output (I / O) interface 705, which is also connected to the bus 704. The electronic device 700 may further include one or more of the following components connected to the I / O interface 705: an input portion 706 including a keyboard, a mouse, etc.; an output portion 707 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage portion 708 including a hard disk, etc.; and a communication portion 709 including a network interface card such as a LAN card, a modem, etc. The communication portion 709 performs communication processing via a network such as the Internet. A drive 710 is also connected to the I / O interface 705 as needed. A removable medium 711, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 710 as needed, so that a computer program read therefrom is installed into the storage portion 708 as needed.
[0187] The present disclosure also provides a computer-readable storage medium, which may be included in the device / apparatus / system described in the above embodiments; or may exist independently without being assembled into the device / apparatus / system. The above computer-readable storage medium carries one or more programs, and when the above one or more programs are executed, the method according to the embodiment of the present disclosure is implemented.
[0188] According to an embodiment of the present disclosure, the computer-readable storage medium may be a non-volatile computer-readable storage medium, for example, may include but is not limited to: a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present disclosure, a computer-readable storage medium may be any tangible medium containing or storing a program, which may be used by or in combination with an instruction execution system, an apparatus or a device. For example, according to an embodiment of the present disclosure, a computer-readable storage medium may include the ROM 702 and / or RAM 703 described above and / or one or more memories other than ROM 702 and RAM 703.
[0189] The embodiment of the present disclosure also includes a computer program product, which includes a computer program, and the computer program contains program code for executing the method shown in the flowchart. When the computer program product is run in a computer system, the program code is used to enable the computer system to implement the method provided by the embodiment of the present disclosure.
[0190] The above functions defined in the system / device of the embodiment of the present disclosure are performed when the computer program is executed by the processor 701. According to the embodiment of the present disclosure, the system, device, module, unit, etc. described above can be implemented by a computer program module.
[0191] In one embodiment, the computer program may rely on tangible storage media such as optical storage devices, magnetic storage devices, etc. In another embodiment, the computer program may also be transmitted and distributed in the form of signals on a network medium, and downloaded and installed through the communication part 709, and / or installed from the removable medium 711. The program code contained in the computer program may be transmitted using any appropriate network medium, including but not limited to: wireless, wired, etc., or any suitable combination of the above.
[0192] In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 709, and / or installed from the removable medium 711. When the computer program is executed by the processor 701, the above functions defined in the system of the embodiment of the present disclosure are performed. According to the embodiment of the present disclosure, the system, device, means, module, unit, etc. described above can be implemented by a computer program module.
[0193] According to an embodiment of the present disclosure, the program code for executing the computer program provided by the embodiment of the present disclosure can be written in any combination of one or more programming languages. Specifically, these computing programs can be implemented using high-level process and / or object-oriented programming languages, and / or assembly / machine languages. Programming languages include, but are not limited to, Java, C++, python, "C" language or similar programming languages. The program code can be executed entirely on the user computing device, partially on the user device, partially on the remote computing device, or entirely on the remote computing device or server. In the case of a remote computing device, the remote computing device can be connected to the user computing device through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computing device (for example, using an Internet service provider to connect through the Internet).
[0194] The flow charts and block diagrams in the accompanying drawings illustrate the possible architecture, functions and operations of the systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of a 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 from the order marked in the accompanying drawings. For example, two boxes represented in succession 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 or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0195] It will be appreciated by those skilled in the art that the features described in the various embodiments and / or claims of the present disclosure may be combined and / or combined in a variety of ways, even if such combinations and / or combinations are not explicitly described in the present disclosure. In particular, the features described in the various embodiments and / or claims of the present disclosure may be combined and / or combined in a variety of ways without departing from the spirit and teachings of the present disclosure. All of these combinations and / or combinations fall within the scope of the present disclosure.
[0196] The embodiments of the present disclosure are described above. However, these embodiments are only for illustrative purposes and are not intended to limit the scope of the present disclosure. Although the embodiments are described above separately, this does not mean that the measures in the various embodiments cannot be used in combination to advantage. The scope of the present disclosure is defined by the attached claims and their equivalents. Without departing from the scope of the present disclosure, those skilled in the art may make a variety of substitutions and modifications, which should all fall within the scope of the present disclosure.
Claims
1. A method for analyzing the sentiment tendency of a text, comprising: Extracting semantic features, part-of-speech features, and co-occurring word features from the text to be analyzed, respectively, wherein the text to be analyzed includes text content and comment content associated with the text content; Concatenate the semantic feature, the part-of-speech feature, and the co-occurrence word feature to obtain a concatenated feature; Preprocessing the concatenated features to obtain word sequence features in the text to be analyzed; Aggregating word sequence features in the text to be analyzed to obtain a sentence vector of the text to be analyzed; and Input the sentence vector into a sentiment tendency analysis model, and output a sentiment tendency analysis result of the text to be analyzed; The preprocessing of the concatenated features to obtain word sequence features in the text to be analyzed includes: Performing linear activation transformation on the concatenated features to generate linear activation features; Performing nonlinear activation transformation on the concatenated features to generate nonlinear activated features; Based on the splicing features, a weight vector is obtained using an attention mechanism; Combining the linearly activated features and the nonlinearly activated features according to the weight vector to obtain word sequence features in the text to be analyzed; The extracting of semantic features, part-of-speech features and co-occurring word features from the text to be analyzed includes: Inputting the text to be analyzed into a pre-trained language representation model and outputting the semantic features; Embedding the words that co-occur in the text content and the comment content to obtain the co-occurrence word features; The part of speech of each word in the text to be analyzed is embedded to obtain the part of speech feature.
2. The method according to claim 1, wherein: The method of obtaining a weight vector based on the splicing feature using an attention mechanism includes: According to different mapping matrices, the concatenated features are converted into a query vector, a key vector, and a value vector; Using the attention mechanism, splicing features with different weight values are obtained; The splicing features with different weight values are reduced in dimension through a forward propagation layer to obtain splicing features with different weight values after dimension reduction; The weight vector is generated by applying the concatenated features with different weight values after dimensionality reduction to a nonlinear activation function.
3. The method according to claim 1, wherein: The step of aggregating the word sequence features in the text to be analyzed to obtain the sentence vector of the text to be analyzed includes: Inputting the word sequence features in the text to be analyzed into a gated recurrent unit; Output the sentence vector of the text to be analyzed.
4. The method according to claim 1, wherein: The sentiment tendency analysis model is obtained through pre-training; The pre-training method comprises: Extracting sample semantic features, sample part-of-speech features, and sample co-occurring word features from training samples, respectively, wherein the training samples include: text content samples, comment content samples associated with the text content samples, and sentiment labels; splicing the sample semantic feature, the sample part-of-speech feature and the sample co-occurrence word feature to obtain a sample splicing feature; Preprocessing the sample concatenation features to obtain sample word sequence features in the training sample; Aggregating sample word sequence features in the training sample to obtain a sample sentence vector of the training sample; Inputting the sample sentence vector into a classification model, and outputting the sentiment tendency classification result of the training sample; Based on the sentiment tendency classification result and the sentiment label, the parameters of the classification model are adjusted, and the trained classification model is used as the sentiment tendency analysis model.
5. A device for analyzing the sentiment tendency of a text, comprising: A feature extraction module, used to extract semantic features, part-of-speech features and co-occurring word features from a text to be analyzed, wherein the text to be analyzed includes text content and comment content associated with the text content; A feature concatenation module, used for concatenating the semantic feature, the part-of-speech feature and the co-occurrence word feature to obtain a concatenated feature; A preprocessing module, used for preprocessing the splicing features to obtain word sequence features in the text to be analyzed; an aggregation module, used to aggregate word sequence features in the text to be analyzed to obtain a sentence vector of the text to be analyzed; and An analysis module, used for inputting the sentence vector into a sentiment tendency analysis model and outputting a sentiment tendency analysis result of the text to be analyzed; The preprocessing of the concatenated features to obtain word sequence features in the text to be analyzed includes: Performing linear activation transformation on the concatenated features to generate linear activation features; Performing nonlinear activation transformation on the concatenated features to generate nonlinear activated features; Based on the splicing features, a weight vector is obtained using an attention mechanism; Combining the linearly activated features and the nonlinearly activated features according to the weight vector to obtain word sequence features in the text to be analyzed; The extracting of semantic features, part-of-speech features and co-occurring word features from the text to be analyzed includes: Inputting the text to be analyzed into a pre-trained language representation model and outputting the semantic features; Embedding the words that co-occur in the text content and the comment content to obtain the co-occurrence word features; The part of speech of each word in the text to be analyzed is embedded to obtain the part of speech feature.
6. An electronic device comprising: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors execute the method according to any one of claims 1 to 4.
7. A computer-readable storage medium having executable instructions stored thereon, which, when executed by a processor, causes the processor to execute the method according to any one of claims 1 to 4.
8. A computer program product, comprising a computer program, wherein when the computer program is executed by a processor, the method according to any one of claims 1 to 4 is implemented.
