A method and system for sentiment analysis of specific target keywords in comment sentences
The multi-level attention mechanism and the bidirectional GRU network focus on the target keywords in the comment sentences, which solves the problem of ignoring the target keywords in the existing technology and improves the accuracy of sentiment analysis.
Patent Information
- Application Number
- CN202111574366.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-21
- Publication Date
- 2024-09-27
- Estimated Expiration
- 2041-12-21
AI Technical Summary
Existing deep learning models based on LSTM ignore the importance of target keywords in review sentences, resulting in poor sentiment analysis results.
A multi-level attention mechanism combined with a bidirectional GRU network is used to encode the mapping matrix of sentences and target keywords, and the sentence-level, target keyword-level and interaction-level attention mechanisms are used to perform multiple weighting operations to generate attention vectors. The discriminant probability of emotional polarity is calculated through the Softmax function.
Effectively paying attention to the words related to the target keywords in the review sentence enhances the accuracy and ability of sentiment analysis and overcomes the problem of ignoring the target keywords in the existing technology.
Smart Images

Figure CN114676692B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of natural language processing and text classification, and in particular to a method and system for sentiment analysis of specific target keywords in comment sentences. Background Art
[0002] On the Internet platform, comment sentences are an important carrier of user experience, and the emotional polarity of specific things in the comment sentences reflects the user's satisfaction. Among them, the sentiment classification of specific target keyword text is a fine-grained sentiment analysis task. Nowadays, there are various methods proposed for this research problem. Most models use machine learning algorithms to classify text in a supervised learning manner. Algorithms such as Naive Bayes and Support Vector Machine (SVM) are widely used for this problem. In recent years, neural networks have greatly promoted the richness of sentiment classification research methods. Neural network models are designed to automatically learn effective low-dimensional representations from targets and contexts, and are used for tasks such as prediction and recognition; some studies have used attention mechanisms to generate target-specific sentence representations based on target keywords, but these studies have not further studied the connection between target keywords and sentences.
[0003] In recent years, academic research has introduced a variety of neural network-based methods to solve the problem of sentiment classification of specific target keywords. Most methods are based on RNN-type neural networks. TD-LSTM solves this problem by using two LSTM networks in opposite directions to model the left and right contexts of target keywords. However, the LSTM-based deep learning model in the prior art mainly models sentences and ignores the importance of target keywords. Summary of the invention
[0004] Therefore, the technical problem to be solved by the present invention is to overcome the defect that the LSTM-based deep learning model in the prior art mainly models sentences but ignores the importance of target keywords, thereby providing a method and system for sentiment analysis of specific target keywords in comment sentences.
[0005] In order to achieve the above object, the present invention provides the following technical solutions:
[0006] In the first aspect, an embodiment of the present invention provides a method for sentiment analysis of specific target keywords in comment sentences, including: obtaining a sentence to be subjected to target keyword sentiment analysis and at least one target keyword; based on the sentence and the target keyword, obtaining a sentence mapping matrix and a target keyword mapping matrix; using a preset encoder to encode the sentence mapping matrix and the target keyword mapping matrix respectively to obtain a sentence mapping encoding matrix and a target keyword encoding matrix; based on the sentence mapping encoding matrix and the target keyword encoding matrix, using a multi-level attention mechanism to perform multiple weighted operations to obtain an attention vector; based on the attention vector, using a Softmax function to calculate the discrimination probability of each sentiment polarity.
[0007] In one embodiment, the process of obtaining a sentence mapping matrix and a target keyword mapping matrix based on sentences and target keywords includes: obtaining a sentence mapping matrix based on a first pre-trained word vector table and the distance between each word in the sentence and the target keyword; querying a second pre-trained word vector table to obtain a target keyword mapping matrix corresponding to the target keyword.
[0008] In one embodiment, the process of obtaining a sentence mapping matrix based on a first pre-trained vocabulary table and the distance between each word in the sentence and the target keyword includes: removing the target keyword from the sentence, and recording the distance between each word in the sentence and the target keyword to obtain the position information of the sentence from which the target keyword has been removed; querying the first pre-trained word vector table to obtain the mapping vector corresponding to the sentence from which the target keyword has been removed, and generating a word vector matrix; encoding and expanding the position information of the sentence from which the target keyword has been removed to obtain a position information matrix, and taking the product of the position information matrix and the preset position information mapping matrix as the position vector matrix; concatenating the word vector matrix with the position vector matrix to obtain a sentence mapping matrix.
[0009] In one embodiment, the preset encoder is a bidirectional GRU network encoder.
[0010] In one embodiment, a bidirectional GRU network encoder is used to encode a sentence mapping matrix and a target keyword mapping matrix respectively to obtain a sentence mapping encoding matrix and a target keyword encoding matrix, including: using a forward GRU network and a reverse GRU network to learn the sentence mapping matrix respectively to obtain a forward sentence mapping encoding matrix and a backward sentence mapping encoding matrix; using a forward GRU network and a reverse GRU network to learn the target keyword mapping matrix respectively to obtain a forward target keyword encoding matrix and a backward target keyword encoding matrix; adding the elements of the forward sentence mapping encoding matrix and the backward sentence mapping encoding matrix to obtain a sentence mapping encoding matrix; adding the elements of the forward target keyword encoding matrix and the backward target keyword encoding matrix to obtain a target keyword encoding matrix.
[0011] In one embodiment, the multi-level attention mechanism includes: a sentence-level attention mechanism, a target keyword-level attention mechanism, and an interaction-level attention mechanism.
[0012] In one embodiment, based on the sentence mapping encoding matrix and the target keyword encoding matrix, a multi-level attention mechanism is used to perform multiple weighted operations to obtain an attention vector, including: using the sentence-level attention mechanism to add weights to the sentence mapping encoding matrix; using the target keyword-level attention mechanism to add weights to the target keyword encoding matrix; taking the product of the sentence mapping encoding matrix with weight values and the transposed matrix of the target keyword encoding matrix with weight values as the interaction matrix; using the interaction-level attention mechanism to add weights to the interaction matrix to obtain an attention vector.
[0013] In the second aspect, an embodiment of the present invention provides a comment sentence specific target keyword sentiment analysis system, including: an input layer module, used to obtain a sentence to be subjected to target keyword sentiment analysis and at least one target keyword; a vector mapping layer module, used to obtain a sentence mapping matrix and a target keyword mapping matrix based on the sentence and the target keyword; an encoding layer module, used to encode the sentence mapping matrix and the target keyword mapping matrix respectively using a preset encoder to obtain a sentence mapping encoding matrix and a target keyword encoding matrix; a multi-level attention layer module, used to perform multiple weighted operations based on the sentence mapping encoding matrix and the target keyword encoding matrix using a multi-level attention mechanism to obtain an attention vector; a prediction layer module, used to calculate the discrimination probability of each sentiment polarity based on the attention vector using a Softmax function.
[0014] In a third aspect, an embodiment of the present invention provides a computer device, comprising: at least one processor, and a memory communicatively connected to the at least one processor, wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method for sentiment analysis of specific target keywords in comment sentences of the first aspect of the embodiment of the present invention.
[0015] In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium, which stores computer instructions, and the computer instructions are used to enable a computer to execute the method for sentiment analysis of specific target keywords in a comment statement of the first aspect of the embodiment of the present invention.
[0016] The technical solution of the present invention has the following advantages:
[0017] 1. The method and system for sentiment analysis of comment sentences with specific target keywords provided by the present invention obtain sentences and at least one target keyword to be subjected to sentiment analysis of the target keyword, obtain a sentence mapping matrix and a target keyword mapping matrix based on the sentence and the target keyword, use a preset encoder to encode the sentence mapping matrix and the target keyword mapping matrix respectively to obtain a sentence mapping encoding matrix and a target keyword encoding matrix, based on the sentence mapping encoding matrix and the target keyword encoding matrix, use a multi-level attention mechanism to perform multiple weighted operations to obtain an attention vector, and use a Softmax function to calculate the discrimination probability of each sentiment polarity based on the attention vector, thereby overcoming the defect of the prior art that the importance of target keywords is ignored while modeling sentences.
[0018] 2. The method and system for sentiment analysis of specific target keywords in comment sentences provided by the present invention use a multi-level attention mechanism with a bidirectional GRU network to build a model for analysis. It can focus on words in the comment sentences that are related to the target keywords and have emotional colors, thereby enhancing the sentiment analysis capability. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0020] Figure 1 A structural diagram of a sentiment analysis model provided by an embodiment of the present invention;
[0021] Figure 2 A flowchart of a specific example of a method for sentiment analysis of specific target keywords in a comment sentence provided by an embodiment of the present invention;
[0022] Figure 3 A flowchart of another specific example of a method for sentiment analysis of specific target keywords in a comment sentence provided by an embodiment of the present invention;
[0023] Figure 4 A flowchart of another specific example of a method for sentiment analysis of specific target keywords in a comment sentence provided by an embodiment of the present invention;
[0024] Figure 5 A flowchart of another specific example of a method for sentiment analysis of specific target keywords in a comment sentence provided by an embodiment of the present invention;
[0025] Figure 6A flowchart of another specific example of a method for sentiment analysis of specific target keywords in a comment sentence provided by an embodiment of the present invention;
[0026] Figure 7 A flowchart of another specific example of a method for sentiment analysis of specific target keywords in a comment sentence provided by an embodiment of the present invention;
[0027] Figure 8 A composition diagram of a specific example of a computer device provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0028] The technical solution of the present invention will be described clearly and completely below in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of them. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0029] In the description of the present invention, it should be noted that, unless otherwise clearly specified and limited, the terms "installed", "connected", and "connected" should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection, or it can be indirectly connected through an intermediate medium, it can also be the internal connection of two components, it can be a wireless connection, or it can be a wired connection. For ordinary technicians in this field, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.
[0030] In addition, the technical features involved in the different embodiments of the present invention described below can be combined with each other as long as they do not conflict with each other.
[0031] Example 1
[0032] The method for sentiment analysis of specific target keywords in comment sentences provided by the embodiment of the present invention is implemented by obtaining a sentiment analysis model based on a combination of a bidirectional GRU neural network and a multi-level attention mechanism. The GRU neural network is a variant of LSTM, which simplifies LSTM a lot while maintaining almost the same effect as LSTM. The structure of the sentiment analysis model is shown in the figure Figure 1 As shown by Figure 1 It can be seen that the sentiment analysis model includes: input layer, vector mapping layer, encoding layer, multi-level attention layer, and prediction layer.
[0033] The sentiment analysis model of the embodiment of the present invention has three different usage modes, as follows:
[0034] (1) Full training mode: The model is fully initialized, trained and tested in the given training set, and finally the trained model is used for prediction and actual tasks. This method is suitable for users who have a large number of labeled data sets and fully fit the performance of the model to their own business scenarios.
[0035] Specifically, the steps for implementing the full training module may include: ① Divide the data set into training data and test data in a certain ratio. ② Set whether to use pre-trained word vectors as the mapping vectors of the mapping layer. In this model, GloVe word vectors can be used as pre-trained mappings. ③ Complete the model parameter settings. ④ Apply the model to the sentences that require specific target sentiment analysis for sentiment polarity prediction and put it into the production environment.
[0036] (2) Pre-training mode: Use the model parameters that have been trained by the model operation and maintenance designer, without training, and use it directly in the business scenario. This method requires the lowest hardware conditions and reduces the time cost of a large number of model training. However, the model performance is completely determined by the model operation and maintenance designer, and it is unknown whether it is suitable in their own application scenario.
[0037] Specifically, the pre-training mode implementation steps may include: ① Obtain the pre-trained model weight parameters provided by the model operation and maintenance designer. ② Set the model hyperparameters according to the given pre-trained model and import the pre-trained model weights. ③ Step 3: Apply the model to the business scenario for sentiment polarity analysis.
[0038] (3) Migration training mode: Use the model parameters that have been trained by the model operation and maintenance designer to train only the final prediction layer (fine-tuning) on the data set specific to your business. This method is a combination of the first two methods and can fit the model to the data of your own application scenario at a low training cost.
[0039] Specifically, the implementation steps of the migration training mode may include: ① Obtain the pre-trained model weight parameters provided by the model operation and maintenance designer. ② Set the model hyperparameters according to the given pre-trained model and import the pre-trained model weights. ③ Fine-tune the model on the training data set specific to its own business scenario. ④ Apply the fine-tuned model to the business scenario for sentiment polarity analysis.
[0040] like Figure 2 As shown, based on the sentiment analysis model, the sentiment analysis method for specific target keywords in comment sentences according to the embodiment of the present invention includes:
[0041] Step S11: Obtain a sentence to be subjected to target keyword sentiment analysis and at least one target keyword.
[0042] Specifically, the input layer of the sentiment analysis model of the embodiment of the present invention inputs the sentence to be subjected to the target keyword sentiment analysis and the target keyword into the model.
[0043] Step S12: Based on the sentences and target keywords, a sentence mapping matrix and a target keyword mapping matrix are obtained.
[0044] Specifically, an embodiment of the present invention maps a sentence into a word vector matrix through a pre-trained vocabulary, and then maps the distance between each word in the sentence and the target keyword into a position vector matrix through a position information mapping table, and then concatenates the two matrices by column to generate a sentence mapping matrix; the target keyword will only be mapped into a target keyword mapping matrix through a pre-trained vocabulary.
[0045] Specifically, Figure 3 As shown, step S12 is implemented by steps S21 to S22 as follows:
[0046] Step S12: Obtain a sentence mapping matrix according to the first pre-trained word vector table and the distance between each word in the sentence and the target keyword.
[0047] Specifically, sentence mapping is different from target keyword mapping. Target keywords are generally phrases consisting of one word or multiple words, such as "dining environment" and "service", while sentences contain target keywords and are generally complete sentences containing subject, predicate and object components, which can fully represent an event, such as "the dining environment is so terrible". In addition, not all words in a sentence are related to the target keyword, and the positional relationship between each word in the sentence and the target keyword should also be considered; therefore, the positional information of each word in the sentence and the target keyword needs to be further vector mapped.
[0048] Specifically, Figure 4 As shown, step S12 is implemented by steps S31 to S34 as follows:
[0049] Step S31: remove the target keyword from the sentence, and record the distance between each word in the sentence and the target keyword to obtain the position information of the sentence from which the target keyword has been removed.
[0050] Specifically, when processing a sentence, it is necessary to remove the target keyword from the sentence and record the distance between each word in the sentence and the target keyword as the sentence position information. For example: the keyword is "diningenvironment" and the sentence is "the dining environment is so terrible", then the distance between the word "the" and the keyword "dining environment" is "1", the distance between the word "is" and the keyword "dining environment" is "1", the distance between the word "so" and the keyword "dining environment" is "2", and the distance between the word "terrible" and the keyword "dining environment" is "3".
[0051] Step S32: query the first pre-trained word vector table, obtain the mapping vector corresponding to the sentence from which the target keyword has been removed, and generate a word vector matrix.
[0052] Specifically, in the specific target sentiment analysis, the sentence is usually a complete sentence that contains a subject, a predicate, and an object in addition to the sentiment target word. The target keyword is used as the center to represent the sentiment polarity, and the sentence includes a large amount of information. When mapping each word vector of the sentence, the GloVe word vector model can be used to pre-train on a large corpus containing a large number of complete comment sentences, such as Twitter and Google News corpus, to generate a first pre-trained word vector table in the form of a matrix corresponding to each word. where d s Represents the dimension size after mapping each word, N s It is expressed as the number of all possible words.
[0053] Specifically, the sentences without the target keywords (where n represents the number of words in the sentence and m represents the number of target keywords), by querying the first pre-trained word vector table Get the corresponding mapping vector and generate the word vector matrix S of the sentence w .
[0054] Step S33: Encode and expand the position information of the sentence from which the target keyword has been removed to obtain a position information matrix, and use the product of the position information matrix and a preset position information mapping matrix as a position vector matrix.
[0055] Specifically, the position information p of the sentence from which the target keyword has been removed is {p1, p2, ..., p n-m} (where n represents the number of words in the sentence and m represents the number of target keywords) is expanded to the one-hot encoded position information matrix P s =[p1,p2,...,p n-m ], where p i (i=1,2,…,nm) represents the one-hot vector corresponding to each position information, P s ∈R (n-m)×dis , where dis is the maximum distance.
[0056] After that, initialize the preset position information mapping matrix W p , W p The matrix size is d p ×d is , d p Represents the size of the location information mapping dimension; the location information matrix P encoded by one-hot s =[p1,p2,...,p n-m ] and the preset position information mapping matrix W p Perform matrix multiplication to obtain the position vector matrix S p , as shown in formula (1), and set the preset position information mapping matrix W p The weight parameters will be updated during the training process.
[0057]
[0058] Step S34: concatenate the word vector matrix and the position vector matrix to obtain a sentence mapping matrix.
[0059] Specifically, the word vector matrix S w With the position vector matrix S p After concatenation, we get the sentence mapping matrix S, which is calculated as follows:
[0060]
[0061] Step S22: query the second pre-trained word vector table to obtain a target keyword mapping matrix corresponding to the target keyword.
[0062] Specifically, by querying the second pre-trained word vector table Acquisition and Target Keywords (where m represents the number of target keywords) The corresponding target keyword mapping matrix T = [t1, t2, ..., t m ], t i (i=1,2,…,m) where represents the mapped vector corresponding to each word in the target word, and the matrix size of T is dt×m.
[0063] Specifically, the embodiment of the present invention uses the GloVe word vector model to perform pre-training on a corpus related to the target keyword. For example, the target words related to catering can be pre-trained using restaurants and food reviews in the Yelp database; then, the pre-trained GloVe word vector model is used to generate a second pre-trained word vector table in the form of a matrix corresponding to each word. where d t Represents the dimension size of the vector after each word mapping of the target keyword, N t It is expressed as the number of all possible words.
[0064] Step S13: Encode the sentence mapping matrix and the target keyword mapping matrix respectively using a preset encoder to obtain a sentence mapping encoding matrix and a target keyword encoding matrix.
[0065] Specifically, the preset encoder of the embodiment of the present invention is a bidirectional GRU network encoder, but this is only an example and is not intended to be limiting. The embodiment of the present invention uses a bidirectional threshold recurrent network (Bi-GRU) to learn the sentence mapping matrix and the target keyword mapping matrix generated by the mapping layer, and then outputs the hidden layer state of the Bi-GRU network to achieve encoding of the mapping matrix.
[0066] Specifically, Figure 5 As shown, step S13 is implemented by steps S41 to S42 as follows:
[0067] Step S41: Use the forward GRU network and the reverse GRU network to learn the sentence mapping matrix respectively, and obtain the forward sentence mapping encoding matrix and the backward sentence mapping encoding matrix; use the forward GRU network and the reverse GRU network to learn the target keyword mapping matrix respectively, and obtain the forward target keyword encoding matrix and the backward target keyword encoding matrix.
[0068] Specifically, the forward sentence mapping encoding matrix Backward Sentence Mapping Encoding Matrix The calculation formulas are shown in formula (3) and formula (4), respectively. The forward target keyword encoding matrix Backward target keyword encoding matrix As shown in formula (5) and formula (6) respectively.
[0069]
[0070]
[0071]
[0072]
[0073] Step S42: Add the elements of the forward sentence mapping coding matrix and the backward sentence mapping coding matrix to obtain a sentence mapping coding matrix; add the elements of the forward target keyword coding matrix and the backward target keyword coding matrix to obtain a target keyword coding matrix.
[0074] Specifically, the sentence mapping encoding matrix E S and the target keyword encoding matrix E t The calculation formulas are shown in formula (7) and formula (8) respectively.
[0075]
[0076]
[0077] Step S14: Based on the sentence mapping encoding matrix and the target keyword encoding matrix, a multi-level attention mechanism is used to perform multiple weighted operations to obtain an attention vector.
[0078] Specifically, the multi-level attention mechanism of the embodiment of the present invention includes: sentence-level attention mechanism, target keyword-level attention mechanism, and interaction-level attention mechanism.
[0079] Specifically, Figure 6 As shown, step S14 is implemented by steps S51 to S53 as follows:
[0080] Step S51: Use the sentence-level attention mechanism to add weights to the sentence mapping encoding matrix; use the target keyword-level attention mechanism to add weights to the target keyword encoding matrix.
[0081] Specifically, the sentence-level attention mechanism is used to map the sentence encoding matrix E S Generate the sentence attention score vector f(E) as shown in formula (9) s ), where W st is the sentence attention weight vector, W st The size is 1×d GRU ; Then f(E s ) performs Softmax operation, as shown in formula (10), to generate the sentence attention weight β i (i=1,2,…,nm).
[0082] f(E s )=tanh(W st ·tanh(E s )),f(E s )∈R 1×(n-m) (9)
[0083]
[0084] The sentence attention weight β i And the corresponding sentence mapping encoding matrix E S Get the sentence mapping encoding matrix E with weight values st .
[0085]
[0086] Specifically, the target keyword level attention mechanism is used to map the target keyword encoding matrix E t Generate the target keyword attention score vector f(E) as shown in formula (12) t ), where W αt is the target keyword attention weight vector, W αt The size is 1×d GRU ; Then f(E t ) performs Softmax operation, as shown in formula (13), to generate the target keyword attention weight α i (i=1,2,…,m).
[0087] f(E t )=tanh(W αt ·tanh(E t )),f(E t )∈R 1×m (12)
[0088]
[0089] The target keyword attention weight α i Mapping encoding matrix E with the corresponding target keyword t Get the target keyword mapping encoding matrix E with weight values αt .
[0090]
[0091] Step S52: The product of the sentence mapping encoding matrix with weight values and the transposed matrix of the target keyword encoding matrix with weight values is taken as the interaction matrix.
[0092] Specifically, the calculation formula of the interaction matrix I is:
[0093] I=(E αt ) T ·E st ,I∈R m·(n-m) (15)
[0094] Step S53: Use the interaction-level attention mechanism to add weights to the interaction matrix to obtain an attention vector.
[0095] Specifically, the interaction-level attention mechanism is used to calculate each vector I in the interaction matrix I i (i=1,2,…,nm) generates the score value and obtains the score value vector f(I), as shown in formula (16), where W H is the interaction-level attention weight vector, whose size is 1×m; then the score value vector f(I) is subjected to a Softmax operation to generate the interaction-level attention weight γ corresponding to the interaction matrix I i (i=1,2,…,nm), as shown in formula (17).
[0096] f(I) = tanh(W H tanh(I)),f(I)∈R 1×(n-m) (16)
[0097]
[0098] According to the interaction-level attention weight γ i For the corresponding vector I in the interaction matrix I i Perform weighted summation to obtain the final attention vector Z, as shown in formula (18).
[0099]
[0100] Step S15: Based on the attention vector, the Softmax function is used to calculate the discrimination probability of each emotional polarity.
[0101] Specifically, the attention vector Z is input into a fully connected layer of a prediction layer, and the final probability vector P for each emotional polarity is obtained through the Softmax function, as shown in formula (19), where C represents the number of emotional polarities (for example, when the emotional polarity is negative, neutral, and positive, the number of emotional polarities is 3), and W pre is the weight matrix of the final prediction layer, W pre The matrix size is C×m, b pre is the bias term (Bias) of the final prediction layer, b pre ∈R^C.
[0102]
[0103] Example 2
[0104] The embodiment of the present invention provides a comment sentence specific target keyword sentiment analysis system, such as Figure 7 As shown, including:
[0105] The input layer module 1 is used to obtain the sentence to be subjected to the target keyword sentiment analysis and at least one target keyword; this mode is actually the input layer of the sentiment analysis model of the embodiment of the present invention. This module executes the method described in step S11 in embodiment 1, which will not be repeated here.
[0106] The vector mapping layer module 2 is used to obtain a sentence mapping matrix and a target keyword mapping matrix based on sentences and target keywords; this mode is actually the vector mapping layer of the sentiment analysis model of the embodiment of the present invention. This module executes the method described in step S12 in embodiment 1, which will not be repeated here.
[0107] The encoding layer module 3 is used to use a preset encoder to encode the sentence mapping matrix and the target keyword mapping matrix respectively to obtain a sentence mapping encoding matrix and a target keyword encoding matrix; this mode is actually the encoding layer of the sentiment analysis model of the embodiment of the present invention. This module executes the method described in step S13 in embodiment 1, which will not be repeated here.
[0108] The multi-level attention layer module 4 is used to perform multiple weighted operations based on the sentence mapping encoding matrix and the target keyword encoding matrix using the multi-level attention mechanism to obtain an attention vector; this mode is actually the multi-level attention layer of the sentiment analysis model of the embodiment of the present invention. This module executes the method described in step S14 in Example 1, which will not be repeated here.
[0109] The prediction layer module 5 is used to calculate the discrimination probability of each emotional polarity according to the attention vector using the Softmax function; this mode is actually the prediction layer of the sentiment analysis model of the embodiment of the present invention. This module executes the method described in step S15 in embodiment 1, which will not be repeated here.
[0110] Example 3
[0111] An embodiment of the present invention provides a computer device, such as Figure 8As shown, it includes: at least one processor 401, such as a CPU (Central Processing Unit), at least one communication interface 403, a memory 404, and at least one communication bus 402. Among them, the communication bus 402 is used to realize the connection and communication between these components. Among them, the communication interface 403 may include a display screen (Display), a keyboard (Keyboard), and the optional communication interface 403 may also include a standard wired interface and a wireless interface. The memory 404 may be a high-speed RAM memory (Ramdom Access Memory, volatile random access memory), or a non-volatile memory (non-volatile memory), such as at least one disk memory. The memory 404 may also be at least one storage device located away from the aforementioned processor 401. Among them, the processor 401 can execute the comment statement specific target keyword sentiment analysis method of embodiment 1. A set of program codes are stored in the memory 404, and the processor 401 calls the program code stored in the memory 404 to execute the comment statement specific target keyword sentiment analysis method of embodiment 1.
[0112] The communication bus 402 may be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus. The communication bus 402 may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 8 The fact that only one line is used in the diagram does not mean that there is only one bus or only one type of bus.
[0113] Among them, the memory 404 may include a volatile memory (English: volatile memory), such as a random access memory (English: random-access memory, abbreviated: RAM); the memory may also include a non-volatile memory (English: non-volatile memory), such as a flash memory (English: flash memory), a hard disk drive (English: hard disk drive, abbreviated: HDD) or a solid-state drive (English: solid-state drive, abbreviated: SSD); the memory 404 may also include a combination of the above types of memory.
[0114] The processor 401 may be a central processing unit (CPU), a network processor (NP), or a combination of a CPU and a NP.
[0115] The processor 401 may further include a hardware chip. The hardware chip may be an application-specific integrated circuit (ASIC), a programmable logic device (PLD), or a combination thereof. The PLD may be a complex programmable logic device (CPLD), a field-programmable gate array (FPGA), a generic array logic (GAL), or any combination thereof.
[0116] Optionally, the memory 404 is also used to store program instructions. The processor 401 can call the program instructions to implement the comment sentence specific target keyword sentiment analysis method in the implementation example 1 of the present application.
[0117] The embodiment of the present invention also provides a computer-readable storage medium, on which computer-executable instructions are stored, and the computer-executable instructions can execute the comment sentence specific target keyword sentiment analysis method of embodiment 1. Among them, the storage medium can be a magnetic disk, an optical disk, a read-only memory (ROM), a random access memory (RAM), a flash memory, a hard disk (HDD) or a solid-state drive (SSD), etc.; the storage medium can also include a combination of the above-mentioned types of memory.
[0118] Obviously, the above embodiments are merely examples for the purpose of clear explanation, and are not intended to limit the implementation methods. For those skilled in the art, other different forms of changes or modifications can be made based on the above description. It is not necessary and impossible to list all the implementation methods here. The obvious changes or modifications derived from these are still within the scope of protection of the invention.
Claims
1. A method for sentiment analysis of specific target keywords in comment sentences, characterized in that: include: Obtaining a sentence to be subjected to target keyword sentiment analysis and at least one target keyword; Based on the sentences and target keywords, a sentence mapping matrix and a target keyword mapping matrix are obtained; Using a preset encoder to encode the sentence mapping matrix and the target keyword mapping matrix respectively, to obtain a sentence mapping encoding matrix and a target keyword encoding matrix; Based on the sentence mapping encoding matrix and the target keyword encoding matrix, a multi-level attention mechanism is used to perform multiple weighted operations to obtain the attention vector; According to the attention vector, the Softmax function is used to calculate the probability of each emotional polarity; The process of obtaining a sentence mapping matrix and a target keyword mapping matrix based on the sentence and the target keyword includes: obtaining a sentence mapping matrix according to a first pre-trained word vector table and a distance between each word in the sentence and the target keyword; querying a second pre-trained word vector table to obtain a target keyword mapping matrix corresponding to the target keyword; The process of obtaining a sentence mapping matrix according to the first pre-trained word vector table and the distance between each word in the sentence and the target keyword includes: removing the target keyword from the sentence, and recording the distance between each word in the sentence and the target keyword to obtain the position information of the sentence from which the target keyword has been removed; querying the first pre-trained word vector table to obtain the mapping vector corresponding to the sentence from which the target keyword has been removed, and generating a word vector matrix; encoding and expanding the position information of the sentence from which the target keyword has been removed to obtain a position information matrix, and taking the product of the position information matrix and the preset position information mapping matrix as the position vector matrix; splicing the word vector matrix with the position vector matrix to obtain a sentence mapping matrix; The sentence-level attention mechanism is used to add weights to the sentence mapping encoding matrix; the target keyword-level attention mechanism is used to add weights to the target keyword encoding matrix; the product of the sentence mapping encoding matrix with weight values and the transposed matrix of the target keyword encoding matrix with weight values is used as the interaction matrix; the interaction-level attention mechanism is used to add weights to the interaction matrix to obtain an attention vector.
2. The method for sentiment analysis of specific target keywords in comment sentences according to claim 1 is characterized in that: The preset encoder is a bidirectional GRU network encoder.
3. The method for sentiment analysis of specific target keywords in comment sentences according to claim 2 is characterized in that: The process of respectively encoding the sentence mapping matrix and the target keyword mapping matrix by using a bidirectional GRU network encoder to obtain a sentence mapping encoding matrix and a target keyword encoding matrix includes: The sentence mapping matrix is learned using the forward GRU network and the reverse GRU network, respectively, to obtain the forward sentence mapping encoding matrix and the backward sentence mapping encoding matrix; the target keyword mapping matrix is learned using the forward GRU network and the reverse GRU network, respectively, to obtain the forward target keyword encoding matrix and the backward target keyword encoding matrix; The forward sentence mapping encoding matrix and the backward sentence mapping encoding matrix are added together to obtain a sentence mapping encoding matrix; the forward target keyword encoding matrix and the backward target keyword encoding matrix are added together to obtain a target keyword encoding matrix.
4. The method for sentiment analysis of specific target keywords in comment sentences according to claim 1 is characterized in that: The multi-level attention mechanism includes: sentence-level attention mechanism, target keyword-level attention mechanism, and interaction-level attention mechanism.
5. A comment sentence specific target keyword sentiment analysis system, characterized in that: include: An input layer module, used to obtain a sentence to be subjected to target keyword sentiment analysis and at least one target keyword; A vector mapping layer module, used to obtain a sentence mapping matrix and a target keyword mapping matrix based on the sentence and the target keyword; An encoding layer module, used to encode the sentence mapping matrix and the target keyword mapping matrix respectively using a preset encoder to obtain a sentence mapping encoding matrix and a target keyword encoding matrix; The multi-level attention layer module is used to perform multiple weighted operations based on the sentence mapping encoding matrix and the target keyword encoding matrix using the multi-level attention mechanism to obtain the attention vector; The prediction layer module is used to calculate the probability of each emotional polarity based on the attention vector using the Softmax function; The process of obtaining a sentence mapping matrix and a target keyword mapping matrix based on the sentence and the target keyword includes: obtaining a sentence mapping matrix according to a first pre-trained word vector table and a distance between each word in the sentence and the target keyword; querying a second pre-trained word vector table to obtain a target keyword mapping matrix corresponding to the target keyword; The process of obtaining a sentence mapping matrix according to the first pre-trained word vector table and the distance between each word in the sentence and the target keyword includes: removing the target keyword from the sentence, and recording the distance between each word in the sentence and the target keyword to obtain the position information of the sentence from which the target keyword has been removed; querying the first pre-trained word vector table to obtain the mapping vector corresponding to the sentence from which the target keyword has been removed, and generating a word vector matrix; encoding and expanding the position information of the sentence from which the target keyword has been removed to obtain a position information matrix, and taking the product of the position information matrix and the preset position information mapping matrix as the position vector matrix; splicing the word vector matrix with the position vector matrix to obtain a sentence mapping matrix; The sentence-level attention mechanism is used to add weights to the sentence mapping encoding matrix; the target keyword-level attention mechanism is used to add weights to the target keyword encoding matrix; the product of the sentence mapping encoding matrix with weight values and the transposed matrix of the target keyword encoding matrix with weight values is used as the interaction matrix; the interaction-level attention mechanism is used to add weights to the interaction matrix to obtain an attention vector.
6. A computer device, characterized in that: include: At least one processor, and a memory communicatively connected to the at least one processor, wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor executes the comment statement specific target keyword sentiment analysis method described in any one of claims 1-4.
7. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable the computer to execute the comment sentence specific target keyword sentiment analysis method described in any one of claims 1-4.
