Aspect-level sentiment classification method based on attention mechanisms and capsule networks

By employing an attention mechanism and an aspect-level sentiment classification method using capsule networks, this approach addresses the problem of existing models neglecting local text features, achieving more efficient text sentiment analysis.

CN117251775BActive Publication Date: 2025-11-14XIAN UNIV OF TECH
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202311090699.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-08-28
Publication Date
2025-11-14
Estimated Expiration
2043-08-28

AI Technical Summary

Technical Problem

Existing sentiment classification models ignore key local features in text and cannot accurately identify the sentiment in the text.

Method used

An aspect-level sentiment classification method based on attention mechanism and capsule network is adopted. By obtaining the internal relationship between local text features and overall sentiment polarity, feature parameters are updated using multi-head attention encoding and dynamic routing mechanism to extract deep text features.

Benefits of technology

It improves the accuracy of sentiment analysis, effectively extracts deep text features, and enhances the efficiency of network parameter updates and final classification accuracy.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117251775B_ABST
    Figure CN117251775B_ABST
Patent Text Reader

Abstract

This invention provides an aspect-level sentiment classification method based on an attention mechanism and capsule networks. The method involves inputting the comment text into a pre-defined BERT encoder to obtain word vectors corresponding to the context and aspect words; inputting these word vectors into a pre-defined gating unit and a Long Short-Term Memory (LSTM) network to obtain hidden state vectors; inputting these hidden state vectors into an attention encoding layer to obtain semantic information encodings for the context and aspect words; compressing these semantic information encodings to obtain primary feature capsules for the context and aspect words; updating the parameters of these primary feature capsules using a routing mechanism to obtain a new contextual feature representation that fuses the aspect words; and finally, obtaining the sentiment classification result for the aspect words based on this new feature representation. This invention fully leverages the semantic information of the context and aspect words, improving the interactivity between them and thus enhancing the accuracy of sentiment analysis.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of sentiment analysis technology, specifically involving an aspect-level sentiment classification method based on attention mechanisms and capsule networks. Background Technology

[0002] Aspect-level sentiment classification is a text classification task that aims to identify the sentiment polarity (e.g., positive, negative, or neutral) associated with specific aspects in text. An existing sentiment classification model training and classification device for comment text employs the following technical solution: acquiring aspect words from the text corpus; extracting sentence and aspect word feature representations using an LSTM network; fusing the sentence and aspect word feature representations using an attention mechanism, assigning weights to the sentence representation to obtain a new sentence feature representation; mapping the sentence feature representation to the sentiment category space using a hyperbolic tangent nonlinear mapping function; using Softmax classification; training and updating the parameters in the model to obtain the optimal sentiment classification model.

[0003] Existing sentiment classification models mostly use pre-trained models to extract text features and classify directly based on these features, ignoring key local features in the text and failing to accurately identify the sentiment of the text. Summary of the Invention

[0004] The purpose of this invention is to propose an aspect-level sentiment classification method based on attention mechanisms and capsule networks. This method obtains the internal relationship between local text features and overall sentiment polarity, effectively improving the accuracy of sentiment analysis.

[0005] The technical solution adopted in this invention is an aspect-level sentiment classification method based on attention mechanisms and capsule networks, and the specific steps are as follows:

[0006] Step 1: Obtain the word vectors corresponding to the context and the word vectors corresponding to the aspect words in the corpus;

[0007] Step 2: Input the context word vectors into the gated recurrent unit to obtain the hidden state vectors corresponding to the context. Simultaneously, input the aspect word vectors into the long short-term memory network to obtain the hidden state vectors corresponding to the aspect words.

[0008] Step 3: Perform multi-head attention encoding on the hidden state vectors corresponding to the context and aspect words respectively to obtain the information encoding of the context and aspect words;

[0009] Step 4: Encode the information of the context and aspect words and compress it using a compression function to obtain the primary feature capsules of the context and aspect words;

[0010] Step 5: Update the parameters of the context primary feature capsule and aspect word primary feature capsule using a dynamic routing mechanism to obtain the preset advanced classification capsule vector features;

[0011] Step 6: Obtain the sentiment classification results of aspect words based on the advanced classification capsule vector features.

[0012] The invention is further characterized in that,

[0013] Furthermore, the comment text mentioned in step 1 is a Yelp compressed file, and preprocessing refers to removing redundant punctuation and words.

[0014] Furthermore, in step 2, the word vector w = {w1, w2, w3, ..., w} corresponding to the context is... n The specific steps for obtaining the hidden state vector corresponding to the context through the preset gate loop unit (GRU) are as follows:

[0015] Step 2.1, generate the context word vector w = {w1, w2, w3, ..., w n The input sequence is fed into the GRU. In the first-level GRU, the input sequence serves as the current state X. t and the hidden state h of the previous layer t-1 ;

[0016] Step 2.2, Current state X t and the hidden state h of the previous layer t-1 After the "reset gate" process, r was obtained. t The processing procedure is as follows:

[0017] r t =σ(W r ·[h t-1 ,X t (1)

[0018] W r This represents the weight matrix for the "reset gate".

[0019] Step 2.3, Current state X t and the hidden state h of the previous layer t-1 Z was obtained after the "update gate" process. t The processing procedure is as follows:

[0020] Z t =σ(W z ·[h t-1 ,X t (2)

[0021] W z This represents the weight matrix of the "update gate".

[0022] Step 2.4, based on the update gate r t The expected output of the current layer is calculated as follows:

[0023] h′=tanh(W·[r t *h t-1 ,X t (3)

[0024] Step 2.5, according to "Update Gate" Z t Compared with the current layer prediction output The final hidden state vector of the current layer is updated as follows:

[0025] H c =(1-Z) t )*h t-1 +Z t *h′ (4)

[0026] Furthermore, in step 2, the word vector A = {a1, a2, a3, ..., a...} corresponding to the aspect words is... m The specific steps for obtaining the hidden state vectors corresponding to aspect words through a preset bidirectional long short-term memory neural network are as follows:

[0027] Step 2.6, assign the word vector A = {a1, a2, a3, ..., a...} corresponding to the aspect words. m Input a preset bidirectional long short-term memory neural network;

[0028] Step 2.7: The Long Short-Term Memory Neural Network updates the word vectors through forward propagation to obtain the forward hidden state vector. The update process is as follows:

[0029]

[0030] m represents the dimension of the word vector corresponding to the aspect word.

[0031] Step 2.8: The Long Short-Term Memory Neural Network updates the word vectors through backpropagation to obtain the backpropagation hidden state vector. The update process is as follows:

[0032]

[0033] Step 2.9: Concatenate the forward hidden state vector and the backward hidden state vector to obtain the final hidden state vector H of the aspect words. t .

[0034] Furthermore, step 3 involves setting the hidden state vector H corresponding to the context. c The specific steps for obtaining the context semantic information encoding Hca by inputting a preset attention encoding formula are as follows:

[0035] Step 3.1, H c The input attention encoding layer is compared with the parameter matrix W.V W K W Q Multiply them to get V, K, and Q;

[0036] Step 3.2: Input V, K, and Q into the attention calculation layer to obtain the context hidden state vector H with assigned weights. ca The calculation process is as follows:

[0037]

[0038] H ca =Attention(K) ca Q ca (9)

[0039] Furthermore, in step 3, the hidden state vector H corresponding to the aspect word is... a Input the preset attention encoding formula to obtain the semantic information encoding H of aspect words. ta The specific implementation steps are:

[0040] Step 3.3, H t The input attention encoding layer is compared with the parameter matrix W. V W K W Q Multiply them to get V, K, and Q;

[0041] Step 3.4: Input V, K, and Q into the attention calculation layer to obtain the weighted context hidden state vector H. ta The calculation process is as follows:

[0042] H ta =Attention(K) ta Q ta (10)

[0043] Furthermore, the specific implementation steps of step 4 are as follows:

[0044] Step 4.1, encode the contextual semantic information H ca Encoding of semantic information of aspect words H ta Horizontal compression is performed using average pooling to obtain features within the context subspace. Features within the subspace of terms The average pooling process is as follows:

[0045]

[0046]

[0047] Step 4.2, the features within the context subspace Features within the subspace of terms Perform a linear transformation to obtain the contextual primary feature capsule. and aspect words primary feature capsule The linear transformation is shown below:

[0048]

[0049]

[0050]

[0051] Furthermore, the specific implementation steps of step 5 are as follows:

[0052] Step 5.1: The primary feature capsule is processed by the weight transformation matrix to obtain the prediction vector for the advanced classification capsule. The process is as follows:

[0053]

[0054] Step 5.2, the predicted vector for the high-level classification capsule is... Weighted summation is performed to obtain a new vector representation of this type of capsule. When the number of iterations meets the preset iteration requirement, the parameter update of the primary feature capsule ends, and the preliminary representation S of the preset advanced classification capsule is obtained. j .

[0055]

[0056]

[0057]

[0058] Among them, c ij Table of coupling coefficients between primary feature capsules and advanced classification capsules, u j This indicates a high-grade capsule category.

[0059] Step 5.3: Use the Squash function to compress the vector, making its length between 0 and 1 while maintaining its direction, to obtain the final vector representation V of this class of high-level classification capsules. j .

[0060]

[0061] Furthermore, step 6 is based on vector V j The modulus length is |V j | Determine the sentiment polarity of the corpus based on the current aspect of the words. When 0.1 < |V j When | < 0.4, the emotional polarity of this aspect of the word is negative; when 0.4 ≤ |V jWhen | < 0.5, the emotional polarity of this aspect of the word is neutral; when 0.5 ≤ |V j At that time, the emotional polarity of the word in that aspect was positive;

[0062] The beneficial effects of this invention are:

[0063] Compared with existing technologies, this invention considers the relationship between local text features and overall sentiment polarity, uses a routing mechanism to update feature parameters, and enables highly correlated features to be highly aggregated, effectively extracting deep text features and improving network parameter update efficiency and final classification accuracy. Attached Figure Description

[0064] Figure 1 This is a flowchart of a sentiment analysis method based on dependency analysis and multi-attribute joint embedding according to the present invention.

[0065] Figure 2 This is a schematic diagram of a gated loop unit provided in an exemplary embodiment of the present invention;

[0066] Figure 3 This is a schematic diagram of a bidirectional long short-term memory neural network provided in an exemplary embodiment of the present invention;

[0067] Figure 4 This is a schematic diagram illustrating the routing mechanism for updating primary feature capsule parameters according to an exemplary embodiment of the present invention. Detailed Implementation

[0068] The present invention will now be described in detail with reference to the accompanying drawings and specific embodiments.

[0069] Example 1

[0070] This invention presents an aspect-level sentiment classification method based on attention mechanisms and capsule networks, specifically comprising the following steps:

[0071] Step 1: Input the preprocessed comment text into the preset BERT encoder to obtain the word vectors corresponding to the context and aspect words in the comment text;

[0072] Step 2: Input the word vectors corresponding to the context and aspect words into the preset gating unit and the long short-term memory network respectively to obtain the hidden state vectors corresponding to the context and aspect words;

[0073] Step 3: Input the hidden state vectors corresponding to the context and aspect words into the attention encoding layer to obtain the semantic information encoding of the context and aspect words;

[0074] Step 4: Encode the semantic information and compress it to obtain the primary feature capsules corresponding to the context and aspect words;

[0075] Step 5: Update the parameters of the primary feature capsules corresponding to the context and aspect words using the dynamic routing mechanism to obtain the advanced classification capsule, which is a new vector of context features fused with aspect words;

[0076] Step 6: Obtain the sentiment classification results of aspect words based on the new feature vectors.

[0077] Example 2

[0078] The network structure used in this invention includes, from bottom to top, a BERT encoding layer, a preset network layer, an attention encoding layer, a primary feature capsule layer, a high-level classification capsule layer, and a classification result output layer;

[0079] The BERT encoding layer is responsible for extracting the initial embedded word vectors of context and aspect words in the corpus;

[0080] The pre-defined network layers include gating units and a bidirectional long short-term memory network. The gating units further extract sentence hidden features based on context-embedded word vectors; the long short-term memory network further extracts aspect-word hidden features.

[0081] The attention encoding layer completes the information interaction between context and aspect words based on the hidden features of the context and aspect words, and generates information encoding of the context and aspect words;

[0082] The primary feature capsule layer encodes the information of context and aspect words and compresses it using a compression function to obtain primary feature capsules of context and aspect words;

[0083] The advanced classification capsule layer uses a dynamic routing mechanism to update the parameters of the primary capsule features of context and aspect words, and aggregates them into the corresponding advanced classification capsules based on the final parameter results;

[0084] The classification result output layer is based on vector V j The modulus length is |V j | Determine the sentiment polarity of the current aspect words in the corpus to complete the classification task.

[0085] Example 3

[0086] See appendix Figure 1 This invention provides an aspect-level sentiment classification method based on attention mechanisms and capsule networks, specifically including the following steps:

[0087] In step 1, the preprocessed text is input into the BERT encoder to obtain word vectors corresponding to context and aspect words.

[0088] Word embedding is a digital representation of words that can be directly processed by neural network models. It is achieved by mapping a word to a high-dimensional real-valued continuous vector, which is called a word vector.

[0089] In this embodiment, the context of the sentiment classification device can be a sentence, and the aspect words are at least one word in the context. For example, if the context is "the price is reasonable while the service is poor," the aspect words are "price" and "service." The sentiment classification device uses a word embedding tool to convert the context and aspect words into corresponding word vectors. If the number of words in the context is n and the number of aspect words is m, the vector corresponding to the context will be n high-dimensional vectors, and the vector corresponding to the aspect words will be m high-dimensional vectors.

[0090] Word embedding tools include word2vec, glove, and BERT. In this embodiment, based on the efficiency of BERT in processing sequence data, BERT is used to perform word vector transformation on context and aspect words to obtain the word vectors corresponding to the context and aspect words.

[0091] In step 2, the context and aspect words are input into a preset gated recurrent unit and a preset bidirectional long short-term memory neural network, respectively, to obtain the hidden state vectors corresponding to the context and aspect words.

[0092] Gate Recurrent Unit (GRU) and Bidirectional Long Short Term Memory Network (Bi-LSTM) both belong to Recurrent Neural Network (RNN), which is a type of recurrent neural network that takes sequential data as input, recurses in the direction of sequence evolution, and all nodes are connected in a chain-like manner.

[0093] In this embodiment, a gated loop unit is used to process the word vectors corresponding to the context to obtain the hidden state vectors corresponding to the context. Please refer to [link to relevant documentation]. Figure 2 , Figure 2 This is a schematic diagram of a gated loop unit provided as an exemplary embodiment of the present invention. The specific steps are as follows:

[0094] Step 2.1, create the context word vector w = {w1, w2, w3, ..., w...} n The input sequence is fed into the GRU. The first layer input sequence of the GRU serves as the current state X. t and the hidden state h of the previous layer t-1 ;

[0095] Step 2.2, Current state X t and the hidden state h of the previous layer t-1 After processing through the "reset gate" r, r is obtained. t The processing procedure is as follows:

[0096] r t =σ(W r ·[h t-1 X t (1)

[0097] W r σ represents the weight matrix of the "reset gate" and σ represents the Sigmoid function, which can transform data into values ​​in the range of 0-1 to serve as a gating signal.

[0098] Step 2.3, Current state X t and the hidden state h of the previous layer t-1 Z is obtained after the "update gate" process. t The processing procedure is as follows:

[0099] Z t =σ(W z ·[h t-1 X t (2)

[0100] W z Let represent the "update gate" weight matrix, and σ represent the Sigmoid function.

[0101] Step 2.4, based on r t The expected output h′ of the current layer is calculated as follows:

[0102] h′=tanh(W·[r t *h t-1 X t (3)

[0103] Step 2.5: Update the final hidden state vector of the current layer based on the "update gate" and the current layer's prediction output h′. The update process is as follows:

[0104] H c =(1-Z) t )*h t-1 +Z t *h′ (4)

[0105] In this embodiment, a bidirectional long short-term memory neural network is used to process the word vectors corresponding to aspect words to obtain the hidden state vectors corresponding to the aspect words. Please refer to [link to documentation]. Figure 3 , Figure 3 This is a schematic diagram of a bidirectional long short-term memory neural network provided as an exemplary embodiment of the present invention. The specific steps are as follows:

[0106] Step 2.6, assign the word vector A = {a1, a2, a3, ..., a...} corresponding to the aspect words. m Input a preset bidirectional long short-term memory neural network;

[0107] Step 2.7: The Long Short-Term Memory Neural Network updates the word vectors through forward propagation to obtain the forward hidden state vector. The update process is as follows:

[0108]

[0109] m represents the dimension of the word vector corresponding to the aspect word.

[0110] Step 2.8: The Long Short-Term Memory Neural Network updates the word vectors through backpropagation to obtain the backpropagation hidden state vector. The update process is as follows:

[0111]

[0112] Step 2.9: Concatenate the forward hidden state vector and the backward hidden state vector to obtain the final hidden state vector H of the aspect words. t ;

[0113]

[0114] In step 3, multi-head self-attention encoding is performed on the hidden state vector corresponding to the context and the hidden state vector corresponding to the aspect word to obtain the context semantic information encoding and the aspect word semantic information encoding, respectively.

[0115] The essence of the attention mechanism comes from the human visual attention mechanism. Applying the attention mechanism to sentiment classification aims to allow the model to focus its attention on the parts most relevant to the sentiment classification. Specifically, a sentence of text can be assumed to consist of a series of...<Key,Value> These are key-value pairs. Given a query for a given element, the weight coefficient of the value corresponding to each key is obtained by calculating the similarity or relevance between the query and each key. In the current research, the initial values ​​of value, key, and query are equal.

[0116] In this embodiment, the emotion classification device uses the hidden state vectors corresponding to the context as Value, Key, and Query, and performs multi-head autonomous intentional encoding to obtain the semantic information encoding corresponding to the context. The specific steps are as follows:

[0117] Step 3.1, H c The input attention encoding layer serves as the initial value for Value, Key, and Query, respectively, and is associated with the parameter matrix W. V W K W Q Multiply them to get V, K, and Q;

[0118] Step 3.2: Input V, K, and Q into the attention calculation layer to obtain the context hidden state vector H with assigned weights. ca The calculation process is as follows:

[0119]

[0120] H ca =Attention(K) ca Q ca (9)

[0121] d k This represents the dimension of K.

[0122] The sentiment classification device uses the hidden state vectors corresponding to aspect words as Value, Key, and Query, and performs multi-head autonomous intentional encoding to obtain the semantic information encoding corresponding to the aspect words. The specific steps are as follows:

[0123] Step 3.1, H t The input attention encoding layer is compared with the parameter matrix W. V W K W Q Multiply them to get V, K, and Q;

[0124] Step 3.2: Input V, K, and Q into the attention calculation layer to obtain the context hidden state vector H with assigned weights. ta The calculation process is as follows:

[0125] H ta =Attention(K) ta Q ta (10)

[0126] d k This represents the dimension of K.

[0127] In step 4, the sentiment classification device encodes the information of context and aspect words and compresses it using a compression function to obtain primary feature capsules of context and aspect words. The specific steps are as follows:

[0128] Step 4.1, encode the context semantic information H ca and the semantic information encoding H of the aspect words ta Horizontal compression is performed using average pooling to obtain features within the context subspace. Features within the subspace of terms

[0129]

[0130]

[0131] The average pooling process is as follows:

[0132] Step 4.1.1, define the pooling window size;

[0133] Typically, the pooling window is square or rectangular in size, and the window size can be customized or determined by the network structure.

[0134] Step 4.1.2, define the pooling step size;

[0135] The pooling stride refers to the step size by which the pooling operation moves through the input data in a certain direction. The pooling stride is generally determined together with the pooling window size.

[0136] Step 4.1.3: Perform average pooling on the input data according to the pooling step size;

[0137] For each pooling window, calculate the average of all elements within the window, and use the result as an element of the output data.

[0138] Step 4.1.4, repeat step 4.1.3 until the pooling window can no longer be moved, and the final output data is obtained.

[0139] Step 4.2, the features within the context subspace Features within the subspace of terms Perform a linear transformation to obtain the contextual primary feature capsule. and aspect words primary feature capsule The linear transformation is shown below:

[0140]

[0141]

[0142]

[0143] In step 5, the sentiment classification device uses a dynamic routing mechanism to update the parameters of the primary capsule features of context and aspect words, and aggregates them into the corresponding advanced classification capsules based on the final parameter results.

[0144] Please see Figure 4 , Figure 4 This diagram illustrates a routing mechanism for updating primary feature capsule parameters, provided as an exemplary embodiment of the present invention. The specific steps are as follows:

[0145] Step 5.1: The primary feature capsule is processed by the weight transformation matrix to obtain the prediction vector for the high-level classification capsule j. The process is as follows:

[0146]

[0147] Step 5.2, Predict the vector By performing a weighted summation, we obtain the preliminary representation S of the higher-level classification capsules. j ;

[0148]

[0149]

[0150]

[0151] c ij Table of coupling coefficients between primary feature capsules and advanced classification capsules, u j Indicates a high-grade capsule category; b ij b is the routing offset between nodes i and j; ik It is the routing bias between nodes i and k.

[0152] Step 5.3: Use the Squash function to compress the vector, making its length between 0 and 1 while maintaining its direction, to obtain the final vector representation V of this class of high-level classification capsules. j .

[0153]

[0154] In step 6, according to vector V j The module length determines the probability of activity in the corpus for a specific sentiment category. A longer module length generally indicates a higher probability of activity, and the corpus is closer to that sentiment category. When 0.1 < |V j When | < 0.4, the emotional polarity of the aspect word is negative; when 0.4 ≤ |V j When | < 0.5, the sentiment polarity of the aspect word is neutral; when 0.5 ≤ |V j When the aspect word's sentiment polarity is positive, the sentiment classification result for that aspect word is obtained.

[0155] An aspect-level sentiment classification method based on attention mechanisms and capsule networks encodes contextual information and aspect word information respectively. It then uses the attention mechanism to extract semantic information corresponding to the context and aspect words, compresses the extracted semantic information horizontally to obtain a feature representation that can be processed by the capsule network, and inputs this representation into the capsule network. Within the capsule network, a routing mechanism updates the parameters of the feature capsules, and finally, the sentiment classification result is obtained based on the preset activity probabilities of the high-level classification capsules.

Claims

1. An aspect-level sentiment classification method based on attention mechanisms and capsule networks, characterized in that, S1: Input the preprocessed comment text into the preset BERT encoder to obtain the word vectors corresponding to the context and aspect words in the comment text; S2: Input the word vectors corresponding to the context and aspect words into the preset gating unit and the long short-term memory network, respectively, to obtain the hidden state vectors corresponding to the context and aspect words; as follows: The word vector w = {w1, w2, w3, ..., w3} corresponding to the context is... n The process of obtaining the hidden state vector corresponding to the context through the preset gate loop unit (GRU) is as follows: r t =σ(W r ·[h t-1 ,X t ]) (1) Z t =σ(W z ·[h t-1 ,X t ]) (2) h′=tanh(W·[r t *h t-1 ,X t ]) (3) H c =(1-Z t )*h t-1 +Z t *h′ (4) Among them, W r H represents the reset gate weight matrix. t-1 X represents the output result of the previous level of the preset gate loop unit. t r represents the input of the current layer of the preset gate loop unit. t Indicates resetting the gate coefficient. W represents the expected output of the current layer. z H represents updating the gate weight matrix. c represents the context hidden state vector obtained after processing by a preset gated loop unit, σ represents the activation function Sigmoid, and [] represents the connection operation; The word vector A = {a1, a2, a3, ..., a...} corresponding to the aforementioned aspect words is... m The process of inputting a preset bidirectional long short-term memory neural network and obtaining the hidden state vectors corresponding to aspect words through the preset bidirectional long short-term memory neural network is as follows: Where m represents the dimension of the word vector corresponding to the aspect word, LSTM R This represents the forward update process of a pre-defined Long Short-Term Memory (LSTM) neural network. L H represents the reverse update process of a Long Short-Term Memory (LSTM) neural network. t This represents the hidden state vector corresponding to the aspect term; S3: Input the hidden state vectors corresponding to the context and aspect words into the attention encoding layer to obtain the semantic information encoding of the context and aspect words; S4: Encode and compress the semantic information to obtain the primary feature capsules corresponding to the context and aspect words; S5: Update the parameters of the primary feature capsules corresponding to the context and aspect words using the dynamic routing mechanism to obtain the advanced classification capsule, which is a new vector of context features fused with aspect words; S6: Sentiment classification results of aspect words are obtained based on the new feature vectors.

2. The aspect-level sentiment classification method based on attention mechanisms and capsule networks according to claim 1, characterized in that, The comment text mentioned in S1 is a Yelp compressed file. Preprocessing refers to removing redundant punctuation and words.

3. The aspect-level sentiment classification method based on attention mechanisms and capsule networks according to claim 1, characterized in that, Step S3 is as follows: The hidden state vector H corresponding to the context c The hidden state vector H corresponding to the aspect words t By inputting the preset attention encoding formulas respectively, we can obtain the contextual semantic information encoding H. ca Encoding of semantic information of aspect words H ta The preset attention encoding formula is as follows: H ca =Attention(K ca ,Q ca ) (9) H ta =Attention(K) ta Q ta (10)W V W K W Q These represent the key-value parameter matrix, the critical value parameter matrix, and the query value parameter matrix, respectively; all three are trainable parameter matrices in the network. i This represents the hidden state value output by the upper-layer network, which serves as the input value for the preset attention encoding layer; V, K, and Q represent the key value, critical value, and query value in the preset attention encoding layer, respectively; Q = H i ·W Q K = H i ·W K V = H i ·W V ; d k This represents the dimension of K.

4. The aspect-level sentiment classification method based on attention mechanisms and capsule networks according to claim 1, characterized in that, Step S4 is as follows: S4.1: Encode the contextual semantic information H ca Encoding of semantic information of aspect words H ta Horizontal compression is performed using average pooling to obtain features within the context subspace. Features within the subspace of terms The average pooling process is as follows: S4.2: The features within the context subspace Features within the subspace of terms Perform a linear transformation to obtain the contextual primary feature capsule. and aspect words primary feature capsule The linear transformation is shown below:

5. The aspect-level sentiment classification method based on attention mechanisms and capsule networks according to claim 1, characterized in that, S5 is detailed below: S5.1, capsule the primary context features and aspect words primary feature capsule The parameter is updated using a routing mechanism to obtain the corresponding preset high-level classification capsule vector feature V. j The routing process is as follows: Among them, u i Indicates a primary characteristic capsule, W ij This represents the weight transformation matrix corresponding to the high-level classification capsule j and the primary feature capsule i. This represents the prediction vector for the high-level classification capsule j; S5.2, the prediction vector for the high-level classification capsule. Weighted summation is performed to obtain a new vector representation of this type of capsule; when the number of iterations meets the preset iteration requirement, the parameter update of the primary feature capsule ends, and the preliminary representation S of the preset advanced classification capsule is obtained. j The weighted summation process is shown below: Among them, c ij Table of coupling coefficients between primary feature capsules and advanced classification capsules, u j Indicates a high-grade capsule category; b ij b is the routing offset between nodes i and j; ik It is the routing offset between nodes i and k; S5.3 uses the Squash function to compress the vector, making its length between 0 and 1 while maintaining its direction, thus obtaining the final vector representation V of this class of high-level classification capsules. j :

6. The aspect-level sentiment classification method based on attention mechanisms and capsule networks according to claim 1, characterized in that, S6 is as follows: Based on vector V j The modulus length is |V j | Determine the sentiment polarity of the corpus based on the current aspect of the words; when 0.1 <|V j When | < 0.4, the emotional polarity of the aspect word is negative; when 0.4 ≤ |V j When | < 0.5, the sentiment polarity of the aspect word is neutral; when 0.5 ≤ |V j When | the emotional polarity of the word is positive.

Citation Information

Patent Citations

  • Emotion classification method and system, storage medium and equipment

    CN110826336A

  • Aspect-level sentiment classification method based on multi-level feature attention

    CN112579778A