Aspect sentiment analysis method and system for natural language
By using convolutional neural networks and span boundary prediction methods in natural language processing, combined with BiLSTM and BERT, the error problem of sub-task interactions and semantic relationships in the aspect emotion triple extraction task is solved, and more accurate emotion analysis is achieved. , which improves the practicality and accuracy of the model.
Patent Information
- Application Number
- CN202111436519.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-29
- Publication Date
- 2024-10-29
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
The existing emotional triple extraction task has problems such as error propagation and increased model search space when solving the interactions and semantic relationships between the three subtasks within a unified framework, and the sequence labeling method leads to emotional inconsistency.
Using a method based on convolutional neural network and span boundary prediction, the extraction and classification tasks are integrated within a unified framework. BiLSTM, BERT and attention mechanisms are combined to extract aspect terms and opinion terms through the semantic interaction module and span extraction module, and predict emotions. polarity.
It improves the accuracy and practicality of the model, provides more accurate sentiment analysis results, helps merchants understand user preferences and make timely adjustments, and grasp the tendencies of social public opinion in a timely manner, which has far-reaching impact.
Smart Images

Figure CN114357155B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of natural language processing, and in particular to a method and system for sentiment analysis based on natural language. Background Art
[0002] The statements in this section merely mention background art related to the present invention and do not necessarily constitute prior art.
[0003] Aspect-based Sentiment Analysis (ABSA), also known as fine-grained sentiment analysis or opinion mining, is a fundamental task in the field of Natural Language Processing (NLP). It aims to identify aspect words and opinion words in a sentence and then predict their corresponding sentiment polarity. In recent years, with the continuous application of deep learning in aspect-level sentiment analysis, this task has made breakthrough progress and has received widespread attention from academia and industry. Traditionally, aspect-level sentiment analysis consists of three basic subtasks, namely aspect term extraction (ATE), opinion term extraction (OTE), and aspect-level sentiment classification (ALSC). Previous studies usually combine two subtasks to solve aspect-level sentiment analysis, including the joint extraction task of aspect terms and opinion terms, the extraction of aspect terms and sentiment classification tasks, and the extraction task of aspect-opinion pairs. However, none of the above studies solves the ATE, OTE, and ALSC subtasks in a unified framework, thus largely ignoring the interaction between the three subtasks.
[0004] In order to strengthen the collaboration among the three subtasks, the researchers proposed the Aspect Sentiment Triplet Extraction (ASTE) task, which aims to adopt a complete solution to extract aspect terms and corresponding opinion terms and predict sentiment polarity to identify more complete triplet information. For example, in “Great food but the service was dreadful!”, (food, great, positive) and (service, dreadful, negative) are the extracted triplet information.
[0005] Since aspect-sentiment triple extraction includes two types of tasks: extraction and classification, it is very valuable and challenging to accurately extract aspects and opinions and use the relationship between them to predict sentiment. Previous researchers used a pipeline approach to divide the three subtasks into two stages and then combined them to form an overall model to solve the aspect-sentiment triple extraction task. However, this pipeline method destroys the interaction between words and has serious error propagation problems. Most recent studies have adopted an end-to-end approach to solve the above problems and proposed a new sequence labeling scheme to transform the extraction task into a unified labeling task. However, these methods still ignore the semantic and syntactic relationship between the three. In addition, the use of sequence labeling methods in extraction and classification tasks will also lead to problems such as an increase in the model search space and inconsistent sentiment of multi-word entities. Summary of the invention
[0006] In order to address the deficiencies of the prior art, the present invention provides a natural language-oriented aspect sentiment analysis method and system; the three subtasks of aspect extraction, opinion extraction and aspect sentiment analysis are solved within a unified framework, thereby realizing aspect-level sentiment analysis of the text.
[0007] In a first aspect, the present invention provides a natural language-oriented sentiment analysis method;
[0008] Aspect sentiment analysis methods for natural language, including:
[0009] Obtain natural language to be analyzed;
[0010] The natural language to be analyzed is input into the trained aspect sentiment extraction model to obtain the extracted aspect terms, opinion terms and aspect sentiment classification results;
[0011] Among them, the working principle of the aspect sentiment extraction model includes: encoding the natural language to obtain the context hidden vector of each word; extracting aspect-oriented features based on the context hidden vector of each word; obtaining the starting position and ending position prediction values of the aspect terms based on the aspect-oriented features; extracting opinion-oriented features based on the context hidden vector of each word; obtaining the starting position and ending position prediction values of the opinion terms based on the opinion-oriented features; and obtaining the sentiment polarity based on the two prediction values.
[0012] In a second aspect, the present invention provides a natural language-oriented aspect sentiment analysis system;
[0013] Aspect sentiment analysis system for natural language, including:
[0014] An acquisition module is configured to: acquire natural language to be analyzed;
[0015] The sentiment analysis module is configured to: input the natural language to be analyzed into the trained aspect sentiment extraction model to obtain the extracted aspect terms, opinion terms and aspect sentiment classification results;
[0016] Among them, the working principle of the aspect sentiment extraction model includes: encoding the natural language to obtain the context hidden vector of each word; extracting aspect-oriented features based on the context hidden vector of each word; obtaining the starting position and ending position prediction values of the aspect terms based on the aspect-oriented features; extracting opinion-oriented features based on the context hidden vector of each word; obtaining the starting position and ending position prediction values of the opinion terms based on the opinion-oriented features; and obtaining the sentiment polarity based on the two prediction values.
[0017] In a third aspect, the present invention further provides an electronic device, comprising:
[0018] a memory for non-transitory storage of computer-readable instructions; and
[0019] a processor for executing the computer readable instructions,
[0020] When the computer-readable instructions are executed by the processor, the method described in the first aspect is executed.
[0021] In a fourth aspect, the present invention further provides a storage medium that non-temporarily stores computer-readable instructions, wherein when the non-temporary computer-readable instructions are executed by a computer, the instructions of the method described in the first aspect are executed.
[0022] In a fifth aspect, the present invention further provides a computer program product, comprising a computer program, wherein the computer program is used to implement the method described in the first aspect when running on one or more processors.
[0023] Compared with the prior art, the present invention has the following beneficial effects:
[0024] The present invention provides a fine-grained sentiment analysis method based on convolutional neural network and span boundary prediction, which uses a unified framework to integrate the two tasks of extraction and classification, and simultaneously mines out the aspect words, opinion words and corresponding sentiment polarity involved in the comments, thereby enhancing the practicality of the model; secondly, CNN, BiLSTM, BERT, attention mechanism, semantic interaction module and span extraction module are adopted to make the extraction and classification results more accurate. Efficient sentiment analysis not only provides users with more accurate analysis results, but also enables businesses to better understand users' preferences, and then make adjustments in time according to feedback. In terms of social public opinion, it can help government departments grasp the public opinion trend of hot events and make timely response measures. Therefore, the research on sentiment analysis models can have a far-reaching impact on various fields. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] The accompanying drawings in the specification, which constitute a part of the present invention, are used to provide a further understanding of the present invention. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute improper limitations on the present invention.
[0026] Figure 1 It is the basic framework of the fine-grained sentiment analysis model E-AOSRA based on convolutional neural network and span boundary prediction provided by the embodiment of the present invention;
[0027] Figure 2 is a comparison diagram of the impact of the kernel K of the CNN in the E-AOSRA model provided by the embodiment of the present disclosure;
[0028] Figure 3 This is a comparison chart of the impact of the number of CNN layers L in the E-AOSRA model provided by an embodiment of the present disclosure. DETAILED DESCRIPTION
[0029] It should be noted that the following detailed descriptions are exemplary and are intended to provide further explanation of the present invention. Unless otherwise specified, all technical and scientific terms used herein have the same meanings as those commonly understood by those skilled in the art to which the present invention belongs.
[0030] In addition, in order to clearly describe the technical solutions of the embodiments of the present invention, in the embodiments of the present invention, the words "first", "second", etc. are used to distinguish the same items or similar items with substantially the same functions and effects. Those skilled in the art can understand that the words "first" and "second" do not limit the quantity and execution order, and the words "first", "second", etc. do not necessarily limit the difference.
[0031] It should be noted that the terms used herein are only for describing specific embodiments, and are not intended to limit exemplary embodiments according to the present invention. As used herein, unless the context clearly indicates otherwise, the singular form is also intended to include the plural form. In addition, it should be understood that the terms "include" and "have" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0032] In the absence of conflict, the embodiments of the present invention and the features of the embodiments may be combined with each other.
[0033] In this embodiment, all data is obtained in compliance with laws and regulations and based on the user's consent, and is used legally.
[0034] Embodiment 1
[0035] This embodiment provides a natural language-oriented sentiment analysis method;
[0036] like Figure 1 As shown in the figure, the sentiment analysis method for natural language includes:
[0037] S101: Obtain natural language to be analyzed;
[0038] S102: inputting the natural language to be analyzed into the trained aspect sentiment extraction model to obtain the extracted aspect terms, opinion terms and aspect sentiment classification results;
[0039] Among them, the working principle of the aspect sentiment extraction model includes: encoding the natural language to obtain the context hidden vector of each word; extracting aspect-oriented features based on the context hidden vector of each word; obtaining the starting position and ending position prediction values of the aspect terms based on the aspect-oriented features; extracting opinion-oriented features based on the context hidden vector of each word; obtaining the starting position and ending position prediction values of the opinion terms based on the opinion-oriented features; and obtaining the sentiment polarity based on the two prediction values.
[0040] Furthermore, the aspect sentiment extraction model includes: an embedding and encoding module, a semantic interaction and span extraction module, and an aspect viewpoint matching and sentiment classification module which are connected in sequence.
[0041] Exemplarily, the aspect sentiment extraction model is an aspect sentiment triple extraction model E-AOSRA based on convolutional neural network and span boundary prediction.
[0042] Furthermore, the embedding and encoding module is implemented by combining the Glove model and BiLSTM. Alternatively, the embedding and encoding module is implemented by using the BERT model.
[0043] Furthermore, the encoding process of the natural language to obtain the context hidden vector of each word specifically includes:
[0044] When the Glove model and BiLSTM are combined to achieve this, the Glove model is first used to embed each word in the sentence to obtain the word representation; then, the BiLSTM encoder is used to encode the word representation to obtain the context hidden vector of each word.
[0045] For example, the present invention first needs to use GloVe to analyze the sentence X = {w1, w2, ..., w n} to obtain word representation E = {e1, e2, …, e n Then use the BiLSTM encoder to obtain the context hidden vector H = {h1,h2,…,h n}, the formula is shown in (1):
[0046]
[0047] in and They are represented as forward LSTM, backward LSTM and the concatenation of the hidden vectors between the two.
[0048] Furthermore, the encoding process of the natural language to obtain the context hidden vector of each word specifically includes:
[0049] When the BERT model is used to implement it, the natural language input to the BERT model is first labeled, and the labeled sentence sequence is constructed into a set style and input into the BERT model to obtain three vectors: sentence tag embedding, paragraph embedding, and position embedding. The three vectors are added together to obtain the final word representation, and then the final word representation is input into the bidirectional Transformers encoder to obtain the contextual hidden vector of each word.
[0050] For example, when using BERT as an encoder, we first need to add [CLS] and [SEP] tags to the sentence input into BERT, and construct the sentence sequence into [CLS]w1,w2,…,w n [SEP] style is input to the BERT encoder. The final word representation E = {e1, e2, ..., e n}. Then it is input into a stacked bidirectional Transformers encoder to obtain the context hidden vector H = {h1,h2,…h n}, the formula is shown in (2):
[0051] h i =BERT(e i ),i∈[1,n] (2)
[0052] Among them, BERT(·) is assumed to be the BERT-base model.
[0053] Furthermore, the semantic interaction and span extraction module includes a convolutional neural network CNN, a splicing layer and a fully connected layer connected in sequence; wherein the output layer of the convolutional neural network CNN is also connected to the splicing layer through an attention mechanism module.
[0054] Furthermore, the method extracts aspect-oriented features based on the contextual hidden vector of each word; obtains the start position and end position prediction values of the aspect terms based on the aspect-oriented features; specifically includes:
[0055] Use convolutional neural network CNN to receive the context hidden vector of each word;
[0056] Extracting aspect-oriented features from the context hidden vector of each word; wherein the aspect-oriented features are context hidden vector features related to aspect terms;
[0057] Based on aspect-oriented features, an attention mechanism is used to define the semantic relationship between each word of aspect terms and opinion terms.
[0058] For each word in the aspect-oriented feature, extract useful information from the opinion-oriented feature by performing weighted summation of semantic relations of all words in the opinion-oriented feature except the current word;
[0059] The useful information extracted from the opinion-oriented features is concatenated with the aspect-oriented features to obtain the final aspect-oriented features, which are then input into the fully connected layer to obtain the starting position prediction score and probability distribution of the aspect-oriented terms, as well as the ending position prediction score and probability distribution of the aspect-oriented terms.
[0060] Aspect terms are also aspect words. For example, in the sentence "Great food but the service was dreadful!", food and service are aspect terms; similarly, great and dreadful are opinion terms.
[0061] Exemplarily, the semantic interaction and span extraction module uses the output hidden vector of the CNN accepting encoder to construct two encoding functions according to key features such as whether there are original words and adjacent words between aspect terms and opinion terms. To extract aspect-oriented features M A and opinion-oriented features M O , as shown in formula (3):
[0062]
[0063] The encoding function is a tool for extracting features in the convolutional neural network CNN. H represents the entire hidden vector feature, → represents extracting part of the feature to M A and M O .
[0064] Since the model of the present invention adopts a symmetrical structure to extract aspect terms and opinion terms respectively, the present invention can infer the opinion term extraction task from the aspect term extraction task, and vice versa. The present invention will take the aspect extraction task as an example to explain in detail the semantic correlation between aspect terms and opinion terms;
[0065] First, the attention mechanism is used to calculate the attention score of each word for both aspects and opinions Then normalize the attention weights Defined as follows (4)-(5):
[0066]
[0067]
[0068] Second, for each word w in the aspect-oriented feature i The present invention can remove w from the opinion-oriented features i All words except the word are weighted summed to extract useful semantic relationship information The formula is shown in (6):
[0069]
[0070] Finally, the present invention extracts useful semantic relationship information M from opinion-oriented features. O2A The original aspect-oriented feature information M A Concatenate and input the final features extracted from the aspects into a fully connected layer to obtain the prediction scores of the starting positions. and probability distribution Predicted score for the ending position and probability distribution The formulas are shown in (7)-(8):
[0071]
[0072]
[0073] in and is a trainable weight vector.
[0074] Furthermore, the method extracts opinion-oriented features based on the contextual hidden vector of each word; obtains the start position and end position prediction values of the opinion term based on the opinion-oriented features; specifically includes:
[0075] Use convolutional neural network CNN to receive the context hidden vector of each word;
[0076] Extract opinion-oriented features from the contextual hidden vector of each word;
[0077] Based on the opinion-oriented features, an attention mechanism is used to define the semantic relationship between aspect terms and opinion terms at each word time.
[0078] For each word in the opinion-oriented feature, extract useful information from the aspect-oriented feature by performing weighted summation of semantic relations of all words in the aspect-oriented feature except the current word;
[0079] The useful information extracted from the aspect-oriented features is concatenated with the opinion-oriented features to obtain the final opinion-oriented features. The final opinion-oriented features are input into the fully connected layer to obtain the starting position prediction score and probability distribution of the opinion-oriented terms, and the ending position prediction score and probability distribution of the opinion-oriented terms.
[0080] For the opinion term extraction task, the present invention only needs to calculate the formula (4) The transposed matrix of Since the present invention calculates the semantic relationship between each word of the aspect term and the opinion term, the semantic relationship is consistent whether from aspect to opinion or from opinion to aspect. Therefore, the present invention can use a similar method to obtain useful information in aspect extraction. Then we get the prediction scores of the start and end positions of the opinion terms. Probability distribution The formulas are shown in (9)-(10):
[0081]
[0082]
[0083] in and is a trainable weight matrix;
[0084] Furthermore, the aspect view matching and sentiment classification module is implemented by using a feedforward neural network (FFNN).
[0085] Furthermore, the training step of the trained aspect sentiment extraction model includes:
[0086] Constructing a training set; wherein the training set includes: natural language with known aspect terms, opinion terms and sentiment polarity;
[0087] Input the training set into the aspect sentiment extraction model; train the model, and stop training when the total loss function of the model no longer decreases, to obtain the trained aspect sentiment extraction model;
[0088] Among them, the total loss function is the sum of the first loss function, the second loss function and the third loss function;
[0089] The first loss function is the sum of the probability of the predicted starting position and ending position of the aspect term and the negative logarithmic probability of the actual starting position and ending position of the aspect term;
[0090] The second loss function is the sum of the negative logarithmic probability of the predicted starting and ending positions of the opinion term and the true starting and ending positions of the opinion term;
[0091] The third loss function is the cross entropy loss function for the sentiment classification task.
[0092] An aspect term is an aspect word in a natural language review sentence, an opinion term is an opinion word, and sentiment polarity is the sentiment expressed by the aspect word through the opinion word, which can be positive, neutral, or negative. For example, in "Great food but the service was dreadful!", (food, great, positive) and (service, dreadful, negative) food is an aspect term, great is an opinion term, and positive is the positive sentiment polarity expressed.
[0093] For example, the training set selects subjective product evaluation or service evaluation as the data set to be subjected to sentiment analysis. Given a sentence X = {w1, w2, ..., w n} as input, where n represents the length of the sentence. This embodiment uses four data sets. The first data set 14Lap comes from the comments on the notebook field of SemEval2014, and the remaining three data sets 14Rest, 15Rest and 16Rest come from the comments on restaurants of SemEval2014, SemEval2015 and SemEval2016 respectively. The sentiment polarity of each data set is divided into positive, negative and neutral.
[0094] Table 1 Dataset
[0095] Dataset Sentences Positive Neutral Negative 14Lap 1453 1350 225 774 14Rest 2068 2869 286 754 15Rest 1075 1285 61 401 16Rest 1393 1674 90 483
[0096] We put the real start and end of the aspect terms in the dataset that have been marked in advance into list A, and similarly put the real start and end of the opinion terms into list O. During the training process, we can get some vectors in the marked span boundary list A and in, and Respectively represent the actual start and end positions of the tag. Similarly, they can also be obtained in the tag's span boundary list O. and
[0097] Then, the present invention defines the training target loss as the sum of the predicted start and end position probabilities and the negative logarithmic probabilities of the true start and end positions, as shown in formulas (11)-(12):
[0098]
[0099]
[0100] in, represents the first loss function, represents the second loss function; Refers to the loss function of the model in extraction terms and opinion terms, respectively. In deep learning, the loss function is a function used to measure the quality of model parameters by comparing the difference between the output predicted by the model and the actual output.
[0101] The aspect view matching and sentiment classification module of the present invention obtains aspect candidate representation and opinion candidate representation After that, they need to be matched and combined into aspect-opinion pairs to jointly predict sentiment polarity. The present invention selects aspect representation vectors and opinion representation vectors from two candidate pools to couple and generate all possible aspect-opinion pairs. Since a sentence may contain multiple aspect terms and opinion terms, the present invention takes the span distance factor into account to obtain accurate aspect-opinion pairs. The present invention obtains the aspect-opinion span pair representation through the following formula (13):
[0102]
[0103] Among them, f distance (m,n,p,q) is a trainable feature embedding generated based on the distance between aspect and opinion span. The present invention uses the shortest span distance min(|np|,|mq|) to determine the sentiment relationship between aspect-opinion span pairs;
[0104] Finally, the present invention inputs the aspect-opinion span pair into a feed-forward neural network (FFNN) to predict the probability p of the sentiment relationship between the aspect and opinion r , the formula is shown in (14):
[0105]
[0106] For the sentiment classification task, the present invention uses cross entropy as the loss function, as shown in formula (15):
[0107]
[0108] Among them, y r is the one-hot vector of the true sentiment relationship label between aspects and opinions. k1 and k2 represent the number of aspects and opinions in the sentence, respectively. Represents the third loss function.
[0109] Optimize the model by jointly training the loss function;
[0110] The loss target of the entire model consists of three parts, namely, aspect extraction, opinion term extraction, and sentiment classification. The present invention adds these three losses to minimize the final joint training loss, as shown in formula (16):
[0111]
[0112] Among them, α, β, γ∈[0,1] are hyperparameters that control the objective contribution.
[0113] The dataset to be subjected to sentiment analysis is passed through the trained E-AOSRA model to extract triplets containing aspect terms, opinion terms, and sentiment polarity, thus achieving fine-grained sentiment analysis of the text.
[0114] In this embodiment, when using BERT as an encoder, the present invention adopts the BERT-base-uncased version, which includes 12 attention heads, 12 hidden layers, and the size of the hidden layer is 768, and 110M pre-trained parameters are obtained. The present invention uses AdamW as an optimizer, sets the maximum learning rate of the transformer weight to 2e-5, and the weight decay is 0.01. The number of samples selected for one training is 16. For these four data sets, the kernel K and the number of layers L of CNN are set to {3,3,5,5} and {3,4,4,4} respectively, and other hyperparameters are adjusted on the development set. In addition, the present invention sets the patience number to 5 so that when there is no further performance improvement on the validation set, the present invention can stop the learning process as soon as possible. For the BiLSTM context encoder, the present invention uses 300-dimensional pre-trained GloVe for word embedding. The hidden layer size is 300, and other hyperparameters are consistent with BERT. Use precision, recall and F1 value as evaluation indicators to test the performance of the model.
[0115] This example compares the aspect sentiment triple extraction model of the present invention with some existing aspect sentiment triple models. The results are shown in Table 2. The experimental results of the model E-AOSRA of the present invention show that whether the BiLSTM encoder or the BERT encoder is used, the model of the present invention always outperforms the previous work in the F1 metric. Among all the baseline models, two powerful pipeline baseline methods Li-unified-R and Two-stage are very competitive in terms of recall, but due to the low precision of the model, their overall performance is much worse than that of the model E-AOSRA of the present invention.
[0116] Compared with the existing end-to-end baselines, the present invention found that although the best performing methods JET and S3E2 are highly competitive in terms of precision, their overall performance is poor due to the uncompetitive recall of the model. Since the present invention takes both into account when designing the model parameters, the overall performance of the model of the present invention is more outstanding, exceeding all baseline models, which also shows that the model of the present invention is effective.
[0117] Table 2 Experimental results
[0118]
[0119] An important parameter affecting the performance of the model is the value of the CNN kernel K and the number of layers L. In this embodiment, the experiment is conducted on four data sets. First, the present invention fixes the value of L on the four data sets, and adjusts the value of K in the range of [1, 9] with a step size of 2. Then, the value of K is fixed, and the value of L is adjusted in the range of [1, 7] with a step size of 1. Figure 2 and Figure 3The results of ASTE-F1 of the BERT version of the model of the present invention are given. When K reaches {3, 3, 5, 5} on the four data sets, the F1 value of the model reaches the maximum. When L reaches {3, 4, 4, 4} on the four data sets, the F1 value of the model reaches the maximum. For simplicity, the present invention keeps this parameter setting to complete all other experiments.
[0120] Embodiment 2
[0121] This embodiment provides a natural language-oriented aspect sentiment analysis system;
[0122] Aspect sentiment analysis system for natural language, including:
[0123] An acquisition module is configured to: acquire natural language to be analyzed;
[0124] The sentiment analysis module is configured to: input the natural language to be analyzed into the trained aspect sentiment extraction model to obtain the extracted aspect terms, opinion terms and aspect sentiment classification results;
[0125] Among them, the working principle of the aspect sentiment extraction model includes: encoding the natural language to obtain the context hidden vector of each word; extracting aspect-oriented features based on the context hidden vector of each word; obtaining the starting position and ending position prediction values of the aspect terms based on the aspect-oriented features; extracting opinion-oriented features based on the context hidden vector of each word; obtaining the starting position and ending position prediction values of the opinion terms based on the opinion-oriented features; and obtaining the sentiment polarity based on the two prediction values.
[0126] It should be noted that the acquisition module and sentiment analysis module described above correspond to steps S101 to S102 in Embodiment 1, and the examples and application scenarios implemented by the modules and corresponding steps are the same, but are not limited to the contents disclosed in Embodiment 1. It should be noted that the modules described above as part of the system can be executed in a computer system such as a set of computer executable instructions.
[0127] The description of each embodiment in the above embodiments has different emphases. For parts not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0128] The proposed system can be implemented in other ways. For example, the system embodiment described above is only illustrative, and the division of the modules is only a logical function division. In actual implementation, there may be other division methods, such as multiple modules can be combined or integrated into another system, or some features can be ignored or not executed.
[0129] Embodiment 3
[0130] This embodiment also provides an electronic device, including: one or more processors, one or more memories, and one or more computer programs; wherein the processor is connected to the memory, and the one or more computer programs are stored in the memory. When the electronic device is running, the processor executes the one or more computer programs stored in the memory so that the electronic device executes the method described in the above embodiment one.
[0131] It should be understood that in this embodiment, the processor may be a central processing unit CPU, and the processor may also be other general-purpose processors, digital signal processors DSP, application-specific integrated circuits ASIC, off-the-shelf programmable gate arrays FPGA or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.
[0132] The memory may include a read-only memory and a random access memory, and provide instructions and data to the processor. A portion of the memory may also include a non-volatile random access memory. For example, the memory may also store information about the device type.
[0133] In the implementation process, each step of the above method can be completed by an integrated logic circuit of hardware in a processor or an instruction in the form of software.
[0134] The method in the first embodiment can be directly embodied as a hardware processor, or a combination of hardware and software modules in the processor. The software module can be located in a mature storage medium in the field such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory, or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory, and the processor reads the information in the memory and completes the steps of the above method in combination with its hardware. To avoid repetition, it will not be described in detail here.
[0135] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with this embodiment can be implemented in electronic hardware or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.
[0136] Embodiment 4
[0137] This embodiment further provides a computer-readable storage medium for storing computer instructions. When the computer instructions are executed by a processor, the method described in the first embodiment is completed.
[0138] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. Aspect sentiment analysis method for natural language, characterized by: include: Obtain natural language to be analyzed; The natural language to be analyzed is input into the trained aspect sentiment extraction model to obtain the extracted aspect terms, opinion terms and aspect sentiment classification results; The aspect sentiment extraction model has the following working principles: encoding the natural language to obtain the context hidden vector of each word; extracting aspect-oriented features based on the context hidden vector of each word; obtaining the start position and end position prediction values of the aspect terms based on the aspect-oriented features; extracting opinion-oriented features based on the context hidden vector of each word; obtaining the start position and end position prediction values of the opinion terms based on the opinion-oriented features; obtaining the sentiment polarity according to the two prediction values; The aspect sentiment extraction model comprises: an embedding and encoding module, a semantic interaction and span extraction module and an aspect view matching and sentiment classification module which are connected in sequence; The embedding and encoding module is implemented by combining the Glove model and the BiLSTM, or the embedding and encoding module is implemented by the BERT model; The semantic interaction and span extraction module includes a convolutional neural network CNN, a splicing layer and a fully connected layer connected in sequence; wherein the output layer of the convolutional neural network CNN is also connected to the splicing layer through an attention mechanism module; The aspect view matching and sentiment classification module is implemented by using a feed-forward neural network; The method extracts aspect-oriented features based on the context hidden vector of each word; obtains the start position and end position prediction values of aspect terms based on the aspect-oriented features; specifically includes: Use convolutional neural network CNN to receive the context hidden vector of each word; Extracting aspect-oriented features from the context hidden vector of each word; wherein the aspect-oriented features are context hidden vector features related to aspect terms; Based on aspect-oriented features, an attention mechanism is used to define the semantic relationship between each word of aspect terms and opinion terms. For each word in the aspect-oriented feature, extract useful information from the opinion-oriented feature by performing weighted summation of semantic relations of all words in the opinion-oriented feature except the current word; The useful information extracted from the opinion-oriented features is concatenated with the aspect-oriented features to obtain the final aspect-oriented features, and the final aspect-oriented features are input into the fully connected layer to obtain the starting position prediction score and probability distribution of the aspect-oriented terms, and the ending position prediction score and probability distribution of the aspect-oriented terms; The attention mechanism is used to calculate the attention score of each word for both aspects and opinions. Then normalize the attention weights Defined as follows (4)-(5): in, For aspect-oriented features, is the opinion-oriented feature. Secondly, for each word w in the aspect-oriented feature i The present invention can remove w from the opinion-oriented features i All words except the word are weighted summed to extract useful semantic relationship information The formula is shown in (6):
2. The natural language-oriented aspect sentiment analysis method according to claim 1, characterized in that: The encoding process of the natural language to obtain the context hidden vector of each word specifically includes: When the Glove model and BiLSTM are combined to achieve this, the Glove model is first used to embed each word in the sentence to obtain the word representation; then, the BiLSTM encoder is used to encode the word representation to obtain the context hidden vector of each word.
3. The natural language-oriented aspect sentiment analysis method according to claim 1, characterized in that: The encoding process of the natural language to obtain the context hidden vector of each word specifically includes: When the BERT model is used to implement it, the natural language input to the BERT model is first labeled, and the labeled sentence sequence is constructed into a set style and input into the BERT model to obtain three vectors: sentence tag embedding, paragraph embedding, and position embedding. The three vectors are added together to obtain the final word representation, and then the final word representation is input into the bidirectional Transformers encoder to obtain the contextual hidden vector of each word.
4. The natural language-oriented aspect sentiment analysis method according to claim 1, characterized in that: The extracting opinion-oriented features based on the contextual hidden vector of each word; Based on the opinion-oriented features, the start and end position prediction values of the opinion terms are obtained; specifically, the following are included: Use convolutional neural network CNN to receive the context hidden vector of each word; Extract opinion-oriented features from the contextual hidden vector of each word; Based on the opinion-oriented features, an attention mechanism is used to define the semantic relationship between aspect terms and opinion terms at each word time. For each word in the opinion-oriented feature, extract useful information from the aspect-oriented feature by performing weighted summation of semantic relations of all words in the aspect-oriented feature except the current word; The useful information extracted from the aspect-oriented features is concatenated with the opinion-oriented features to obtain the final opinion-oriented features. The final opinion-oriented features are input into the fully connected layer to obtain the starting position prediction score and probability distribution of the opinion-oriented terms, and the ending position prediction score and probability distribution of the opinion-oriented terms.
5. The natural language-oriented aspect sentiment analysis method according to claim 1, characterized in that: The trained aspect sentiment extraction model, the training steps include: Constructing a training set; wherein the training set includes: natural language with known aspect terms, opinion terms and sentiment polarity; Input the training set into the aspect sentiment extraction model; train the model, and stop training when the total loss function of the model no longer decreases, to obtain the trained aspect sentiment extraction model; Among them, the total loss function is the sum of the first loss function, the second loss function and the third loss function; The first loss function is the sum of the probability of the predicted starting position and ending position of the aspect term and the negative logarithmic probability of the actual starting position and ending position of the aspect term; The second loss function is the sum of the negative logarithmic probability of the predicted starting and ending positions of the opinion term and the true starting and ending positions of the opinion term; The third loss function is the cross entropy loss function for the sentiment classification task.
6. A natural language-oriented sentiment analysis system, characterized by: include: An acquisition module is configured to: acquire natural language to be analyzed; The sentiment analysis module is configured to: input the natural language to be analyzed into the trained aspect sentiment extraction model to obtain the extracted aspect terms, opinion terms and aspect sentiment classification results; The aspect sentiment extraction model has the following working principles: encoding the natural language to obtain the context hidden vector of each word; extracting aspect-oriented features based on the context hidden vector of each word; obtaining the start position and end position prediction values of the aspect terms based on the aspect-oriented features; extracting opinion-oriented features based on the context hidden vector of each word; obtaining the start position and end position prediction values of the opinion terms based on the opinion-oriented features; obtaining the sentiment polarity according to the two prediction values; The aspect sentiment extraction model comprises: an embedding and encoding module, a semantic interaction and span extraction module and an aspect view matching and sentiment classification module which are connected in sequence; The embedding and encoding module is implemented by combining the Glove model and the BiLSTM, or the embedding and encoding module is implemented by the BERT model; The semantic interaction and span extraction module includes a convolutional neural network CNN, a splicing layer and a fully connected layer connected in sequence; wherein the output layer of the convolutional neural network CNN is also connected to the splicing layer through an attention mechanism module; The aspect view matching and sentiment classification module is implemented by using a feed-forward neural network; The method extracts aspect-oriented features based on the context hidden vector of each word; obtains the start position and end position prediction values of aspect terms based on the aspect-oriented features; specifically includes: Use convolutional neural network CNN to receive the context hidden vector of each word; Extracting aspect-oriented features from the context hidden vector of each word; wherein the aspect-oriented features are context hidden vector features related to aspect terms; Based on aspect-oriented features, an attention mechanism is used to define the semantic relationship between each word of aspect terms and opinion terms. For each word in the aspect-oriented feature, extract useful information from the opinion-oriented feature by performing weighted summation of semantic relations of all words in the opinion-oriented feature except the current word; The useful information extracted from the opinion-oriented features is concatenated with the aspect-oriented features to obtain the final aspect-oriented features, and the final aspect-oriented features are input into the fully connected layer to obtain the starting position prediction score and probability distribution of the aspect-oriented terms, and the ending position prediction score and probability distribution of the aspect-oriented terms; The attention mechanism is used to calculate the attention score of each word for both aspects and opinions. Then normalize the attention weights Defined as follows (4)-(5): in, For aspect-oriented features, is the opinion-oriented feature. Secondly, for each word w in the aspect-oriented feature i The present invention can remove w from the opinion-oriented features i All words except the word are weighted summed to extract useful semantic relationship information The formula is shown in (6):
7. An electronic device, comprising: a memory for non-transitory storage of computer readable instructions; as well as a processor for executing the computer readable instructions, When the computer-readable instructions are executed by the processor, the method described in any one of claims 1 to 5 is executed.
8. A storage medium, characterized in that: The computer-readable instructions are non-transitory stored, wherein when the non-transitory computer-readable instructions are executed by a computer, the instructions of the method according to any one of claims 1 to 5 are executed.
