A method for extracting triples of comment sentiment reasons
Through the deep learning model and the double affine attention mechanism, emotional sentences, reason sentences and emotion types are extracted to form emotional reason triples, which solves the shortcomings of emotional reason extraction in the existing technology and improves the utilization rate and efficiency of emotional reasons. The application effect realizes fine-grained comment classification and information display.
Patent Information
- Application Number
- CN202110973766.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-08-24
- Publication Date
- 2024-09-10
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
Existing emotional reason pair extraction technology ignores the characteristics of emotion types, resulting in the extracted emotional reason pairs not being effectively utilized. Moreover, the two-step extraction method has problems such as error propagation, complexity, and time consumption, and the comment classification method is coarse-grained. Unable to provide fine-grained, high-quality information.
An end-to-end method for extracting emotional reason triplets from reviews is proposed. Through a deep learning model and a double affine attention mechanism, emotional sentences, reason sentences and emotion types are comprehensively extracted to form emotional reason triples, and keyword matching is used to extract them. Improve the accuracy and efficiency of extraction.
It overcomes the problems of low practicality of extraction results and limited application scenarios of emotional reasons, realizes end-to-end extraction of emotional reason triples, improves the utilization rate and application effect of emotional reasons, and improves the granularity and information of comment classification. Show quality.
Smart Images

Figure CN113779245B
Abstract
Description
Technical Field
[0001] The invention relates to a method for extracting triples of comment sentiment reasons, and belongs to the technical field of sentiment analysis and information extraction in natural language processing. Background Art
[0002] The development and rapid start of sentiment analysis is due to the rapid development of social media on the Internet, such as product reviews, forum discussions, Weibo, and WeChat. It is the first time in human history that such a huge amount of digital records have been recorded. At present, sentiment analysis has grown into one of the most active research areas in natural language processing (NLP), and has been widely studied in data mining, Web mining, text mining, and information retrieval.
[0003] Traditional sentiment analysis techniques can only obtain the sentiment polarity of a text (positive, neutral, negative). However, more in-depth information (such as the cause of the emotion, the object of the emotion, etc.) is still worth further exploration.
[0004] The extraction of sentiment-cause pairs aims to extract both the sentiment in the text and the causes of the sentiment, so as to obtain richer and deeper information. For example, "This laptop is really hard to use, and the fan is very noisy, so don't buy it." Among them, "This laptop is really hard to use" is an emotional sentence, and "The fan is very noisy" is the cause sentence corresponding to the aforementioned emotional sentence. These two sentences can form a sentiment-cause pair. The extraction results of sentiment-cause pairs have a good auxiliary role in tasks such as public opinion analysis, text classification, and recommendation systems.
[0005] At present, the extraction of emotion-cause pairs focuses more on the extraction of emotion sentences and cause sentences, and most of them adopt a two-step extraction method. The first step: extract the emotion sentence set and cause sentence from the document, and do a Cartesian product of the two sets to convert them into an emotion-cause pair set. The second step: classify the emotion-cause pair set to determine whether the emotion sentence is caused by the corresponding cause sentence.
[0006] However, the existing sentiment-reason pair extraction task ignores the feature of "sentiment type", resulting in that the extracted sentiment-reason pairs cannot be well utilized, which greatly limits the application of sentiment-reason pairs in practice. For example, for a large amount of text, simply extracting sentiment sentences and reason sentences, such as making decisions based on sentiment-reason pairs (improving a certain point of the product, maintaining a certain point, or using a certain point as a promotional point) or text classification, is not possible. However, if the sentiment type is extracted at the same time, such as "This laptop is really hard to use, the fan is very noisy, don't buy it", the sentiment type of the sentiment-reason pair is: anger, which can help merchants understand the aspects of the product that need improvement: the fan.
[0007] At the same time, the two-step method has many disadvantages, such as error propagation between steps, complex use (need to save intermediate results), and time-consuming.
[0008] In addition, most of the current comment classification methods are based on coarse-grained methods such as ratings, good and bad reviews, and keyword extraction, and can only simply display the full text of the user's complete review. The classification method based on ratings, good and bad reviews relies more on the scores given by users, but there may be both good and bad descriptions in the comments, and the score is only an overall indicator. The classification method based on keyword extraction often requires the same phrases in multiple comment texts, but each person uses different words, and the same semantics can be expressed in different ways, which leads to low quality and small quantity of keyword extraction. More fine-grained classification and more concentrated high-quality information often need to be displayed to users. Summary of the invention
[0009] The purpose of the present invention is to overcome the defects of the prior art in solving the problem of sentiment reason extraction, and to improve the utilization rate and application effect of sentiment reasons, and propose an end-to-end comment sentiment reason triple extraction method.
[0010] The innovation of this method lies in: integrating sentiment reason extraction technology, sentiment analysis technology and information extraction technology, and simultaneously extracting sentiment sentences, reason sentences and sentiment type triplets, namely sentiment reason triplets, and demonstrating its specific application in the comment scenario.
[0011] Firstly, the emotion-cause triple of <emotion-cause-emotion type> is proposed: the emotion sentence, the cause sentence corresponding to the emotion sentence and the emotion type are extracted from the document at the same time; then, the deep learning model and the double affine attention mechanism are used to model the relationship between the emotion sentence, the cause sentence and the emotion type, and the three-dimensional probability matrix of the emotion-cause triple is obtained; according to the three-dimensional probability matrix, the model is trained and the emotion-cause triple is extracted with any document as input; finally, the object for which the user wants to express emotion is matched with the sentences in all the emotion-cause triples by keywords. If there is a corresponding keyword in the sentence, it means that this emotion-cause triple is related to the keyword.
[0012] like Figure 1 As shown, the present invention specifically comprises the following steps:
[0013] Step 1: Design a model to extract sentiment reason triplets.
[0014] Specifically, step 1 includes the following steps:
[0015] Step 1.1: Input each document in the dataset and output the dataset with the sentiment reason triples annotated. The dataset includes a training set and a test set.
[0016] Specifically, step 1.1 includes the following steps:
[0017] Step 1.1.1: Segment the sentences in each document in the dataset, with words separated by spaces.
[0018] Step 1.1.2: For each document in the dataset, mark the emotion-reason pairs it contains. For example, (0, 1) means that the 0th sentence is the emotion sentence, and the 1st sentence is its corresponding reason sentence.
[0019] Step 1.1.3: For each sentiment sentence in the document in the dataset, label its sentiment type. This can be done in the following way:
[0020] Happy: 0, Surprise: 1, Disgusted: 2, Angry: 3.
[0021] Step 1.2: Select training documents W from the dataset output in step 1.1.
[0022] Each W contains n sentences S, and each sentence S contains m words C. The number of documents W ranges from 1 to K, with a total of K training documents.
[0023] Step 1.3: Encode the sentences of the training document obtained in step 1.2 to obtain the sentence vector s n ;
[0024] Specifically, step 1.3 includes the following steps:
[0025] Step 1.3.1: Use the word embedding function of formula 1 to embed each word C in the sentence m Convert to word embedding vector c m :
[0026] c m =embed(C m ) (1)
[0027] Where embed(·) is the embedding function. For each input word C m , find the corresponding word embedding vector c in the trained word embedding vector table m (Vectors are uniformly represented by bold lowercase letters).
[0028] Step 1.3.2: Using equations 2, 3, and 4, embed the word vector c obtained in step 1.3.1 m As the input of the deep learning model (bidirectional LSTM and attention), the contextual relationship between words is modeled to obtain the sentence vector s of each sentence n :
[0029]
[0030] score j =v T tanh(W′h m ) (3)
[0031]
[0032] in, Respectively represent the forward and backward LSTM (long short-term memory neural network); h m yes The vector after splicing the forward and backward LSTM output; score j is the score output by the attention mechanism, v T , W′ are trainable parameters, T represents the transposition operation; softmax(·) is a normalization function that limits the sum of the output results to 1; M represents the number of words;
[0033] Step 2: Use the bi-affine attention mechanism to model the connection between sentiment sentences, reason sentences, and sentiment types, and obtain a three-dimensional probability matrix of sentiment-reason triplets.
[0034] Specifically, step 2 includes the following sub-steps:
[0035] Step 2.1: In order to speed up training and prevent overfitting, two fully connected networks are used to train the sentence vector s obtained in step 1 n Perform dimension compression, remove redundant information, and obtain sentiment sentence vectors and reason sentence vector
[0036] Step 2.2: Model sentiment sentence vectors using the dual affine attention mechanism Reason Sentence Vector and the connection between emotional types.
[0037] Using formula 5, we get a three-dimensional matrix U p,q,r ,The three dimensions represent emotional sentences, reason sentences and emotional types respectively.
[0038]
[0039] in, and is a trainable parameter, They are the p-th sentiment sentence vector and the q-th reason sentence vector respectively; T represents the transposition operation.
[0040] Matrix U p,q,rIn , each bit is passed through the sigmoid function and outputs a value from 0 to 1, indicating the probability that this bit is an emotion-cause triple. For example, (0, 1, 0) indicates the probability that the 0th sentence is an emotion sentence, the 1st sentence is a cause sentence, and the emotion type is "happy". The sigmoid function is shown in Formula 6:
[0041]
[0042] Among them, sigmoid(·) represents normalization, which normalizes each bit in the matrix U to a value between 0 and 1 to represent the probability; is the probability value of the triplet that needs to be extracted for the pth emotional sentence, the qth reason sentence, and the rth emotional type in the final emotional three-dimensional matrix.
[0043] Here, a threshold of 0.5 is set. Any probability value greater than the threshold is considered to be an emotional reason triple that needs to be extracted, otherwise it does not need to be extracted.
[0044] Step 3: Train the model based on the three-dimensional probability matrix obtained in step 2, take any document as input, and extract the sentiment reason triples;
[0045] Specifically, step 3 includes the following steps:
[0046] Step 3.1: Use binary cross entropy to measure the true probability Y p,q,r The model predicts the probability The difference in distribution between them is used as the objective function L of the model for training, as shown in Formula 7:
[0047]
[0048] Among them, the true probability Y p,q,r It refers to the probability of the emotional reason triple label. If it is an emotional reason triple, the probability is 1, otherwise it is 0; ∑ p,q,r Represents the sum of the binary cross entropy results for different p, q, and r.
[0049] Step 3.2: Use the batch stochastic gradient descent method to optimize the objective function of step 3.1, perform batch iterative training on all training samples in the training set, and output the trained emotion reason triple extraction model.
[0050] Step 3.3: Use the extraction model trained in step 3.2, input any document, and output the extracted sentiment reason triples.
[0051] Step 4: Take the relevant documents of the object for which the user wants to express emotion (such as a product that the user is interested in) as input, and use the keywords of different aspects of the object (such as the characteristics of the product, etc.) to match the sentences in all emotion reason triples. If the corresponding keyword exists in the sentence, it means that this emotion reason triple is related to the keyword.
[0052] Furthermore, the specific reasons for the user's emotion type for the object to be expressed can be displayed in a visual way (the emotion sentence and the reason sentence in the triplet).
[0053] Beneficial Effects
[0054] Compared with the prior art, the present invention has the following advantages:
[0055] 1. This method overcomes the shortcomings of low practicality of the extraction results of emotional reasons and limited application scenarios, and simultaneously extracts emotional sentences, reason sentences and emotional type triplets (emotional reason triplets).
[0056] 2. This method solves the shortcomings of existing sentiment reason extraction methods, such as error propagation, complex use, and time-consuming. It proposes a dual-affine-based extraction method to achieve end-to-end extraction of sentiment reason triplets.
[0057] 3. This method improves the existing problems of coarse classification granularity and excessive information in commenting methods, and can greatly improve the user experience. BRIEF DESCRIPTION OF THE DRAWINGS
[0058] Figure 1 It is a flow chart of a method for extracting triples of comment sentiment reasons according to the present invention;
[0059] Figure 2 This is a schematic diagram of users using traditional review categories based on good and bad ratings;
[0060] Figure 3 This is a schematic diagram of user comments using traditional keyword extraction;
[0061] Figure 4 It is a schematic diagram of comments by users using the method of the present invention. DETAILED DESCRIPTION
[0062] The method of the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments.
[0063] Example
[0064] A method for extracting triples of comment sentiment reasons includes the following steps:
[0065] Step 1: Mark the sentiment-reason pairs in each document in the dataset and mark the sentiment type of the sentiment sentence. Use the Chinese word segmentation tool jieba to segment words, and separate words with spaces.
[0066] For example, the following documents:
[0067] The computer just arrived.
[0068] Can't wait to open it and try it out.
[0069] The appearance is really amazing to me,
[0070] Thin and technological, 4
[0071] It's even more beautiful than the picture shows. 5
[0072] It's good overall after using it, 6
[0073] But there are some minor problems when using it.
[0074] The fan is very noisy.
[0075] A bit annoying. 9
[0076] Among them, the third sentence is an emotional sentence, the emotional type is surprise, and the corresponding reason sentences are sentences 4 and 5. The ninth sentence is an emotional sentence, the emotional type is disgust, and the corresponding reason sentences are sentences 7 and 8. The corresponding annotations are (3, 4, 1)(3, 5, 1)(9, 7, 2)(9, 8, 2), among which surprise is marked with 1 and disgust is marked with 2.
[0077] Step 2: Divide the data set into a training set and a test set. The training set is used to train the model, and the test set is used to test the performance of the model.
[0078] Step 3: Use the 300-dimensional word vector trained by the skip-gram algorithm to obtain the word vector c of each word in the training set m , if a word in the document does not exist in the trained word vector, a randomly initialized word vector of the same dimension is used to represent it;
[0079] Step 4: Use the word vector c obtained in step 3 m Encode the sentences as the input of the bidirectional LSTM and attention model to obtain the sentence vector of each sentence sn ;
[0080] Step 5: Use sentence vector s n As input, two fully connected networks are used to obtain vectors representing emotions respectively. and the vector representing the cause Using the dual affine attention mechanism to vector and Model the relationship between For example, after the above steps for the document in step 1, a 9*9*4 three-dimensional probability matrix will be obtained, where 9 is the number of sentences and 4 is the four types of emotions; each digit is a value from 0 to 1, indicating probability;
[0081] Step 6: Use binary cross entropy to measure the true probability Y p,q,r The model predicts the probability The difference in distribution between them is used as the objective function L of the model for training. For example, the true probability of the document in step 1 is: (3, 4, 1) (3, 4, 1) (9, 7, 2) (9, 8, 2) four positions are 1, and the rest are 0, indicating that there are emotional reason triplets in these four positions that need to be extracted:
[0082] Step 7: Use the batch stochastic gradient descent method to optimize the objective function of step 6, perform batch iterative training on all training samples in the training set, and obtain a trained emotion reason triple extraction model;
[0083] Step 8: Use the trained extraction model obtained in step 7, input any document, and output the extracted sentiment reason triples;
[0084] For example, talking about two documents on the same phone:
[0085] 1. My previous phone was broken, so I wanted to get a new one. I spent a long time choosing and finally chose this one. The screen is very good, with high resolution and refresh rate, and a super high screen-to-body ratio. The camera function is my favorite, the optical zoom and anti-shake functions are very practical, and the quality of night photography really shocked me. But the camera is protruding, which is a bit bad, and it is easy to bump and so on.
[0086] 2. This is my first time using this brand of mobile phone. The screen is good in all aspects, but one bad thing is that it is not hard enough and it is easy to break. It is a pity to break such a good mobile phone screen. I like the camera being changed to a round shape, which is very beautiful and distinguishes it from other mobile phones.
[0087] In the above document 1, the model will extract 5 emotional reason triplets, including "The screen of the phone is very good - the resolution and refresh rate are both very high - happy", "The screen of the phone is very good - and the screen-to-body ratio is super high - happy", "The camera function is my favorite - the optical zoom and anti-shake functions are very practical - happy", "The camera function is my favorite - the quality of night photography really shocked me - happy" and "But the camera is protruding, which is not good - it is easy to bump and so on - disgusted"; in document 2, the model will extract 3 emotional reason triplets, including "But one bad thing is that the hardness is not enough - disgusted", "But one bad thing is that it is easy to break - disgusted" and "The camera has been changed to a round shape and I like it very much - it is beautiful and has a good distinction from other mobile phones - happy";
[0088] Step 9: The sentiment sentence of the triple extracted in step 8 contains the three keywords "screen", "photograph", and "camera";
[0089] Step 10: Classify the reason sentences according to keywords. Sentences containing the same keywords (i.e., sentences describing the same aspect of the product) belong to the same category.
[0090] Furthermore, a visualization method can be used to show the specific reasons (emotional sentences and reason sentences in the triplet) for the user's liking (emotional types are happiness and surprise) or disliking (emotional types are disgust and anger) a certain aspect of the product (i.e., the keyword).
[0091] For the above two documents, the reasons for liking the screen are: the resolution and refresh rate are very high, and the screen-to-body ratio is super high. The reasons for not liking the screen are: the hardness is not enough and it is easy to break.
[0092] For users or buyers, based on the above information, they can quickly understand the advantages and disadvantages of the product and choose whether to buy it according to their needs. For example, some people are careless and often drop their phones, so they may not buy the above-mentioned mobile phone. Some people pay much attention to the screen resolution and use their phones carefully, so they may buy it.
[0093] For merchants or sellers, the above information can quickly help them understand consumers' evaluation of each part of the product and the reasons why they like or dislike it. With this information, merchants can make corresponding decisions. For example, if many people are more concerned about the screen's lack of hardness, merchants can choose to improve it by using a harder screen, or even sacrificing some of the screen's performance; for example, if many people like the round camera design, merchants can keep this design and use it as one of the promotional points.
[0094] Figure 2A schematic diagram of reviews based on good and bad ratings is shown. The "good reviews" and "bad reviews" at the top of the picture are different classification labels. The classification labels are determined based on the ratings and star ratings given by users. High ratings and high star ratings are good reviews, while low ratings are bad reviews. Clicking on a specific label will display the full text of reviews from different users in the corresponding category.
[0095] Figure 3 A schematic diagram of comments extracted based on keywords is shown. The "good-looking" and "battery durability" at the top of the picture are different classification labels. The classification labels are determined based on common keywords extracted from user comments. All comments related to this keyword, whether good or bad, will be displayed. Clicking on a specific label will display the full text of comments from different users in the corresponding category.
[0096] Figure 4 A schematic diagram of comments using the method of the present invention is shown. The classification labels on the upper part of the picture are divided into two parts. The "screen" and "camera" in the upper part are certain features and partial labels of the product, which are obtained by matching keywords with sentences in the extracted emotion-reason triples; the labels in the lower part, such as "happy" and "surprise", are the user's emotion types for the product. The same user can show different emotion types for the same product. For example, user A***rew expressed happiness for the "screen", but expressed disgust for the "camera". In this way, the information contained in the comments can be displayed in a more fine-grained manner; the present invention displays more condensed information, that is, only the emotion sentences and reason sentences in the user comments are displayed, rather than the full text, so that many words irrelevant to the product selection can be filtered out; at the same time, we also provide a "show original text" option so that users can also choose to view the full text; clicking on a specific label will display the emotion sentences and reason sentences in the comments of different users of the corresponding category;
[0097] The above description is only a preferred embodiment of the present invention, wherein the emotion types are not limited to the four categories of happiness, surprise, disgust and anger, and any emotion type is applicable to the present invention.
[0098] The present invention should not be limited to the contents disclosed in the embodiments and drawings. Any equivalent or modification completed without departing from the spirit disclosed in the present invention shall fall within the protection scope of the present invention.
Claims
1. A method for extracting triples of comment sentiment reasons. It is characterized in that Firstly, the emotion-cause triple of <emotion-cause-emotion type> is proposed: the emotion sentence, the cause sentence corresponding to the emotion sentence and the emotion type are extracted from the document at the same time; then, the deep learning model and the double affine attention mechanism are used to model the relationship between the emotion sentence, the cause sentence and the emotion type, and the three-dimensional probability matrix of the emotion-cause triple is obtained; the model is trained according to the three-dimensional probability matrix, and the emotion-cause triple is extracted with any document as input; finally, the object to which the user wants to express emotion is matched with the sentences in all emotion-cause triples by keywords. If the corresponding keyword exists in the sentence, it means that this emotion-cause triple is related to the keyword; Step 1: Design a model to extract sentiment reason triplets, including the following steps: Step 1.1: Input each document in the data set and output the data set with the sentiment reason triples annotated; the data set includes a training set and a test set; Step 1.2: Select training document W from the dataset output in step 1.1; Each W contains n sentences S, and each sentence S contains m words C. The number of documents W ranges from 1 to K, with a total of K training documents. Step 1.3: Encode the sentences of the training document obtained in step 1.2 to obtain the sentence vector s n ; Step 2: Use the bi-affine attention mechanism to model the connection between the sentiment sentence, reason sentence, and sentiment type, and obtain a three-dimensional probability matrix of sentiment-reason triplets, including the following sub-steps: Step 2.1: Use two fully connected networks to train the sentence vector s obtained in step 1 n Perform dimension compression, remove redundant information, and obtain sentiment sentence vectors and reason sentence vector Step 2.2: Model sentiment sentence vectors using the dual affine attention mechanism Reason Sentence Vector and the connection between emotional types; Using formula 5, we get a three-dimensional matrix U p,q,r , the three dimensions represent emotional sentences, reason sentences and emotional types respectively: in, and is a trainable parameter, are the pth sentiment sentence vector and the qth reason sentence vector respectively; T represents the transposition operation; Matrix U p,q,r In , each bit passes through the sigmoid function and outputs a value from 0 to 1, indicating the probability that this bit is the emotion reason triplet. The sigmoid function is shown in Formula 6: Among them, sigmoid(·) represents normalization, which normalizes each bit in the matrix U to a value between 0 and 1 to represent the probability; is the probability value of the triplet that needs to be extracted for the pth emotional sentence, the qth reason sentence, and the rth emotional type in the final three-dimensional emotional matrix; Here, a threshold of 0.5 is set. Any probability value greater than the threshold is considered to be a sentiment reason triple that needs to be extracted, otherwise it does not need to be extracted; Step 3: Based on the three-dimensional probability matrix obtained in step 2, the model is trained, and any document is used as input to extract the sentiment reason triples, including the following steps: Step 3.1: Use binary cross entropy to measure the true probability Y p,q,r The model predicts the probability The difference in distribution between them is used as the objective function L of the model for training, as shown in Formula 7: Among them, the true probability Y p,q,r It refers to the probability of the emotional reason triple label. If it is an emotional reason triple, the probability is 1, otherwise it is 0; ∑ p,q,r Represents the sum of the binary cross entropy results for different p, q, and r; Step 3.2: Use the batch stochastic gradient descent method to optimize the objective function of step 3.1, perform batch iterative training on all training samples in the training set, and output the trained emotion reason triple extraction model; Step 3.3: Use the extraction model trained in step 3.2, input any document, and output the extracted sentiment reason triples; Step 4: Take the relevant documents of the object for which the user wants to express emotions as input, and use the keywords of different aspects of the object to match the sentences in all emotion reason triples; if the corresponding keyword exists in the sentence, it means that this emotion reason triple is related to the keyword.
2. A method for extracting triples of comment sentiment reasons as described in claim 1, It is characterized in that Step 1.1 includes the following steps: First, the sentences in each document in the dataset are tokenized, with words separated by spaces; Then, for each document in the dataset, the sentiment reason pairs contained are annotated; Finally, for each sentiment sentence in the document in the dataset, its sentiment type is marked.
3. A method for extracting triples of comment sentiment reasons as described in claim 1, It is characterized in that Step 1.3 includes the following steps: Step 1.3.1: Use the word embedding function of formula 1 to embed each word C in the sentence m Convert to word embedding vector c m : c m =embed(C m ) (1) Where embed(·) is the embedding function; for each input word C m , find the corresponding word embedding vector c in the trained word embedding vector table m ; Step 1.3.2: Using equations 2, 3, and 4, embed the word vector c obtained in step 1.3.1 m As the input of the deep learning model, namely the bidirectional long short-term memory neural network LSTM and attention, the contextual relationship between words is modeled to obtain the sentence vector s of each sentence n : score j =v T tanh(W′h m ) (3) in, Respectively represent the forward and backward LSTM; h m It is the vector after the concatenation of the forward and backward LSTM outputs; score j is the score output by the attention mechanism, v T , W′ are both trainable parameters, T represents the transposition operation; softmax(·) is a normalization function that limits the sum of the output results to 1; M represents the number of words.
4. A method for extracting triples of comment sentiment reasons as described in claim 1, It is characterized in that After step 4, the specific reasons for the user's emotion type for the object to be expressed are further displayed in a visual way.
