A text sarcasm identification method integrating multiple sentiment polarities
By constructing an emotional dictionary for sarcasm recognition and a sarcasm recognition network that integrates multiple emotional polarities, and using the BERT model to extract emotional and contextual features, we solve the problems of low sarcasm recognition accuracy and loss of contextual information in the existing technology, and achieve higher performance. Sarcasm recognition accuracy and deep semantic feature extraction.
Patent Information
- Application Number
- CN202410353006.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-03-26
- Publication Date
- 2024-09-06
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
Existing text sarcasm recognition methods based on rules and statistical machine learning have low accuracy. A single deep neural network model is prone to losing contextual information, resulting in insufficient generalization capabilities and difficulty in achieving high accuracy.
Construct a sarcasm recognition method that integrates multiple emotional polarities. By constructing a sarcastic recognition emotional dictionary and an sarcastic recognition network IMEPSI that integrates multiple emotional polarities, the BERT model is used to extract emotional features and contextual information features, and the Softmax activation function is used to determine whether the text is Ironic.
It improves the accuracy of text sarcasm recognition, can more accurately extract deep semantic feature information, reduces data sparsity and irrelevant word interference, and enhances the model's classification ability.
Smart Images

Figure CN118313385B
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of natural language processing, and further relates to a text sarcasm recognition method, device, equipment and storage medium integrating multiple emotional polarities. Background Art
[0002] Sarcasm is a common way for people to express emotions in daily life. The actual meaning to be expressed is often the opposite of the literal meaning. Because of this characteristic of sarcasm, its sarcastic expression is complex and ambiguous. Therefore, sarcasm recognition is a challenging task in natural language processing.
[0003] At present, the research on sarcasm recognition methods can be divided into three categories, namely, rule-based sarcasm recognition methods, statistical machine learning-based sarcasm recognition methods, and neural network-based sarcasm recognition methods.
[0004] The rule-based sarcasm identification method mainly uses key words that appear frequently in sarcastic texts to determine whether the text contains sarcastic expressions. Bharti et al. proposed a rule-based classifier to build a parse tree for the target sentence and identify phrases with emotions in the sentence. If a phrase with negative emotions appears in a sentence with positive emotions, it is identified as sarcastic. However, with the development of Internet buzzwords, phrases with negative emotions may also express positive emotions in different contexts, and the accuracy of rule-based sarcasm identification methods is low.
[0005] Sarcasm identification methods based on statistical machine learning generally extract text features through the bag-of-words model, and then classify them through classification algorithms such as naive Bayes and logistic regression.
[0006] Compared with the sarcasm recognition method based on statistical machine learning, the sarcasm recognition method based on a single deep neural network can directly use word embedding expression to replace the manual feature extraction process in statistical machine learning, and has better generalization performance. However, using only a single deep neural network model is prone to losing context information and the lack of connection between each word and the context, which can easily lead to insufficient generalization ability of the model, causing overfitting and difficulty in achieving high accuracy.
[0007] The Chinese patent document with publication number CN116402063A discloses a multimodal sarcasm recognition method. The method extracts and analyzes global features and semantic features of each modal content in a hierarchical manner, obtains cross-modal similarity scores and homomodal similarity scores based on the obtained global features, and uses cross-modal interaction and homomodal interaction to perform collaborative recognition using the extracted global features, semantic features, cross-modal similarity scores, and homomodal similarity scores.
[0008] The Chinese patent document with publication number CN116402063A discloses a cross-platform multi-topic satire and motivation identification method. The method first obtains the cross-platform text to be identified, and obtains the target data in a preset format according to the text to be identified and its publishing platform; uses the preset language representation model to encode and represent the preset cross-platform tag set and the target data respectively, and obtains the text representation vector and the tag representation vector, wherein the preset cross-platform tag set includes multiple topic tags; calculates the text representation vector and the tag representation vector, and obtains the satire recognition result corresponding to the text to be identified, wherein the satire recognition result includes the topic recognition result, the satire determination result and the satire motivation. Summary of the invention
[0009] The purpose of the present invention is to address the problem that the accuracy of rule-based text sarcasm recognition methods and statistical machine learning-based text sarcasm recognition methods is low, and the problem that the text sarcasm recognition method based on a single deep neural network is prone to lose context information and lacks the connection between each word and the context. A text sarcasm recognition method that integrates multiple emotional polarities is proposed, which can improve the accuracy of text sarcasm recognition.
[0010] The present invention also provides a text sarcasm recognition device that integrates multiple emotion models. After the text information to be recognized is input into the system, the system can use the recognition model to identify whether it is sarcastic, which is conducive to analyzing the real opinions and attitudes of the text and further helping computers understand human language.
[0011] Terminology explanation:
[0012] BERT model (Bidirectional Encoder Representations from Transformers): an unsupervised pre-trained language model (PLM) for natural language processing.
[0013] Word Frequency-Inverse Document Frequency (WF): A statistical method used to assess the importance of each word to a document set or a document in a corpus.
[0014] N-gram (NGram): An algorithm based on a statistical language model that uses the probabilities of n-1 words that have already appeared to predict the probability of the next word.
[0015] Target word: a word in the corpus that is used to distinguish words in the initial sentiment dictionary.
[0016] Pointwise Mutual Information (PMI): used to measure the correlation between two things.
[0017] Semantic Orientation Pointwise Mutual Information (SOPMI): Determines the degree of association between an unfamiliar word and a benchmark word. If the degree of association with a positive benchmark word is high, then the word is positive; if the degree of association with a negative benchmark word is high, then the word is negative.
[0018] Smooth-Semantic Orientation Pointwise MutualInformation (SSOPMI): Re-estimate the probability x of a word that appears 0 or very few times in the corpus using NGram * , to prevent unknown words from appearing in the corpus, resulting in the co-occurrence frequency of the sentiment seed word and the target word in the same comment being 0, making it impossible to calculate the PMI of the target word and the sentiment seed word, and thus making it impossible to judge the sentiment tendency of the target word.
[0019] Integrating Multiple Emotional Polarities-Satirical Identification (IMEPSI): used to extract and fuse emotional features with contextual information in text.
[0020] Good-Turing smoothing estimation method: Use the frequency category information to smooth the frequency. For any NGram that occurs r times, it is assumed that it occurs r times. * This can effectively reduce the data sparsity and make the probability estimates of all words look smooth.
[0021] The idea of achieving the purpose of the present invention is to construct a sentiment dictionary for sarcasm recognition; secondly, construct IMEPSI to extract and fuse sentiment features with contextual information in the text; then use the Softmax activation function to determine whether the comment is sarcastic; then initialize the weights and bias items of the model, set the model-related hyperparameters, including the size of the dropout rate, the size of the learning rate, the size of the batch, and the choice of the optimizer; load the training set and the validation set into the model for training to obtain the optimal parameters of the model after training; finally, use the sarcasm recognition model to identify comments on the social platform to determine whether they are sarcastic. The specific steps implemented by the present invention are as follows: Figure 1 As shown, the model framework is as Figure 2 shown.
[0022] S100: Constructing a sarcasm recognition dataset: First, integrate existing relevant datasets to obtain original sarcasm data, and annotate the original sarcasm data; construct each original sarcasm data and its corresponding annotation into a bigram, and all bigrams constitute a sarcasm recognition dataset; finally, divide the sarcasm recognition dataset into a training set, a validation set, and a test set according to a certain ratio;
[0023] S200: Constructing a sentiment dictionary for sarcasm identification: First, select N comments with sentiment polarity from comments on multiple social platforms and the constructed sarcasm identification dataset, calculate the word frequency W, inverse document frequency F, and word frequency and its inverse document frequency WF of each word, and select n words with higher WF as the seed words of the initial sarcasm identification sentiment dictionary; then construct a smooth sentiment tendency point mutual trust function SSOPMI to expand the sarcasm identification sentiment dictionary;
[0024] S300: Constructing a sarcasm identification model: First, the input text is split into a positive emotional polarity part, a negative emotional polarity part, and a non-emotional polarity part according to the sarcasm identification sentiment dictionary. Then, a sarcasm identification network IMEPSI that integrates multiple emotional polarities is constructed to extract the emotional features of the positive emotional part and the negative emotional part and the contextual information features of the text respectively, and then the emotional features and the contextual information features are integrated and the fusion feature vector is reduced in dimension; finally, the activation function is used to determine whether the text is sarcastic;
[0025] S400: Set all relevant parameters of the model: set the size of the discard rate, the size of the learning rate, the size of the batch processing, the selection of the optimizer and other parameters related to the model; load the training set and the validation set into the model for training to obtain the optimal parameters of the model after training.
[0026] S500: Use the sarcasm recognition model to perform sarcasm recognition on the text, input the test set into the trained sarcasm recognition model for testing, use the accuracy and MMR in machine learning as evaluation indicators of the sarcasm recognition model when performing the sarcasm recognition task, and then apply the sarcasm recognition model to the sarcasm recognition tasks of different data sets.
[0027] Furthermore, step S100 constructs the sarcasm recognition dataset as follows:
[0028] The original sarcastic data is obtained by crawling data with a crawler and integrating existing relevant data sets. The category label sarcasm is constructed to label each text txt of the original sarcastic data as "sarcasm" or "non-sarcasm". Then, the txt and its corresponding sarcasm are combined to construct a tuple d=<txt,sarcasm> ; All d constitute a data set D = {d1, d2, ..., d n}, where n is the number of data sets;
[0029] Furthermore, the method for constructing the sarcasm recognition sentiment dictionary described in step S200 is as follows:
[0030] S210: Calculate W, F, and WF for each word. First, select N comments with sentiment polarity C = (C1, C2, ..., C i , …, C n ), where each comment is represented by C i ={w1, w2, ..., w i ,…,w n}, calculate each word w x The frequency of occurrence of W in C x :
[0031]
[0032] in Represents word w x The number of occurrences in C, length(x) represents the function that calculates the number of words in each comment.
[0033] At the same time, in order to prevent some common words from having too high a frequency and affecting the experimental performance, C is used as the original corpus to simulate the use environment of sarcasm and calculate the inverse document frequency F of each word in the original corpus. x :
[0034]
[0035] Where len(x) represents the function for calculating the number of comments. Indicates that it contains the word w x The number of comments.
[0036] If certain words are used more frequently and exist in the vast majority of comments, it means that the word does not have a good ability to distinguish sarcasm categories, and its F is closer to 0.
[0037] Then multiply the word frequency of each word by its inverse document frequency to calculate WF x :
[0038] WF x =W x ·F x
[0039] WF x A larger value means that the word has a higher weight on the review.
[0040] Finally, n words with higher WF are extracted from the original corpus, and then manually screened to obtain a initial sentiment dictionary seed words with positive sentiment polarity and b initial sentiment dictionary seed words with negative sentiment polarity. The two are combined to construct the initial sentiment dictionary, which is expressed as OriginED = {POS w , NEG w}, each word in OriginED is a sentiment seed word.
[0041] S220: Expand the sentiment dictionary for sarcasm identification. Calculate the correlation between the sentiment seed word and each word in the corpus. The greater the probability that two words appear in a comment at the same time, the greater the correlation. The calculation formula is as follows:
[0042]
[0043] Where w is the target word and o is the sentiment seed word; PMI(w, o) can express the semantic similarity between w and o by the frequency of co-occurrence between words. P(w) and P(o) are the probabilities of the target word w and the sentiment seed word o appearing respectively, and P(w, o) is the probability that the target word w and the sentiment seed word o appear in the same comment.
[0044] Then calculate the sentiment tendency of each word in the corpus, and the calculation formula is as follows:
[0045]
[0046] Where SOPMI(w) is the sentiment tendency point mutual information value of the target word.
[0047] However, unknown words may appear in the corpus of this paper, and there may be a situation where the frequency of co-occurrence of sentiment seed words and target words in the same comment is 0. At this time, the PMI of the target word and the sentiment seed word cannot be calculated, and thus the sentiment tendency of the target word cannot be judged. Therefore, the present invention proposes the SSOPMI algorithm to calculate the PMI of the target word and the sentiment seed word, and expand the sentiment dictionary for sarcasm recognition.
[0048] Furthermore, the steps to construct the SSOPMI function to expand the sentiment dictionary for sarcasm recognition are as follows:
[0049] S221: First, for words that appear 0 or very few times in the corpus, use N-gram NGram to re-estimate the number of times they appear in the corpus:
[0050]
[0051] Where x represents the number of times a word appears in the corpus; N xrepresents the number of words that appear x times in the corpus; x * Indicates the number of times a word appears in the corpus after being re-estimated by NGram.
[0052] S222: Calculate the number of comments where the target word w appears in the corpus, the number of comments where the sentiment seed word o appears in the corpus, and the probability that the number of comments where the target word w and the sentiment seed word o co-occur in the corpus accounts for the total number of comments in the corpus, that is:
[0053]
[0054]
[0055]
[0056] Where Count(w, o) is the number of comments in which the target word w and the sentiment seed word o co-occur in the corpus; Count(w) is the number of comments in which the target word w appears in the corpus; Count(o) is the number of comments in which the sentiment seed word o appears in the corpus; Sum is the total number of comments in the corpus.
[0057] S223: In order to avoid the situation where the co-occurrence frequency of the sentiment seed word and the target word in the same comment is 0, that is, when Count(w, o) is 0, which will make PMI(w, o) meaningless, a smooth sentiment tendency point mutual trust function is designed to reduce the data sparsity of o and w, so that the probability curve of the sentiment seed word and the target word appearing in the same comment is smoother; the frequency of P(w, o) is substituted into NGram to obtain the number of times w and o co-occur in the corpus Count re-estimated by NGram * (w, o):
[0058]
[0059] Where N count(w,o) is the number of comments that occur exactly Count(w,o) times in the corpus;
[0060] Finally, the above formula is substituted into the SSOPMI algorithm to calculate the sentiment tendency of each word in the corpus. The formula is as follows:
[0061]
[0062] If SSOPMI(w)>0, it means that the word has a positive sentiment tendency, and it is added to the positive sentiment dictionary of sarcasm recognition; if SSOPMI(w)=0, it means that the word has no sentiment tendency; if SSOPMI(w)<0, it means that the word has a negative sentiment tendency, and it is added to the negative sentiment dictionary of sarcasm recognition;
[0063] The sarcasm identification sentiment dictionary is composed of the sarcasm identification positive sentiment dictionary and the sarcasm identification negative sentiment dictionary.
[0064] Furthermore, the specific steps of constructing the sarcasm recognition model described in step S300 are as follows:
[0065] S310: Based on the constructed sarcasm recognition sentiment dictionary, the input text is divided into positive sentiment polarity parts W pos , Negative emotional part W neg and the non-emotional polarity part W null .
[0066] S320: Construct a sarcasm recognition network IMEPSI that integrates multiple emotional polarities to extract the emotional features of the positive emotional part and the negative emotional part and the contextual information features of the text respectively, then fuse the emotional features with the contextual information features and reduce the dimension of the fused feature vector.
[0067] Furthermore, the steps of constructing IMEPSI to extract and fuse sentiment features and context information features are as follows:
[0068] S321: Use the BERT model to extract W pos and W neg First, W pos and W null Splice and then extract W pos+null The positive emotional characteristics of Similarly, follow the above steps to convert W neg and W null Splice and then extract W neg+null The negative sentiment feature of
[0069] S322:W pos+null With W neg+null It only contains part of the original text, and the context information may be lost after extracting its features. Therefore, the context information features of the input text are first extracted, which is expressed as Then the positive sentiment word feature vector V x and the feature vector V of the sarcastic sentence z Concatenate and use a linear layer and RELU activation function to reduce the dimension of the concatenated feature vector to obtain the positive emotion feature vector V containing context information pos :
[0070] V pos =RELU[Linear(concatenate(V x , V z ))]
[0071] Among them, Concatenate is the vector concatenation function, and Linear represents the linear layer.
[0072] Similarly, according to step S322, the negative sentiment feature vector V containing context information is obtained. neg :
[0073] V neg =RELU[Linear(Concatenate(V y , V z ))]
[0074] Concatenate is a vector concatenation function, and Linear represents a linear layer.
[0075] S323: Fusion V pos and V neg , using the Softmax activation function, calculate the probability P that the text is sarcastic sarcasm , and its calculation formula is as follows:
[0076] P sarcasm =Softmax(W p [V pos , V neg ]+b p )
[0077] Where W p is the weight matrix, b p is the bias term, P sarcasm is the probability that the statement is sarcastic.
[0078] If P sarcasm If the value of is greater than or equal to a certain threshold r, it is judged to be ironic, otherwise it is not ironic. The value of r is usually 0.5.
[0079] The present invention also provides a text irony recognition device integrating multiple emotional polarities, comprising:
[0080] The module for constructing the sarcasm recognition dataset is configured to: integrate the existing relevant datasets to obtain the original sarcasm data, annotate the original sarcasm data; construct each original sarcasm data and its corresponding annotation into a bigram, and all the bigrams constitute a sarcasm recognition dataset. Finally, the sarcasm recognition dataset is divided into a training set, a validation set, and a test set according to a certain ratio.
[0081] The module for constructing a sentiment dictionary for sarcasm identification is configured as follows: first, N comments with sentiment polarity are selected from comments on multiple social platforms and the constructed sarcasm identification dataset as a corpus, W, F and WF of each word are calculated, and n words with higher WF are selected as seed words of the initial sentiment dictionary for sarcasm identification; then, a smooth sentiment tendency point mutual trust function SSOPMI is constructed to expand the sentiment dictionary for sarcasm identification;
[0082] A text sarcasm recognition module integrating multiple emotional polarities is constructed, which is configured as follows: first, the input text is split into a positive emotional polarity part, a negative emotional polarity part and a non-emotional polarity part according to the sarcasm recognition emotional dictionary; then, a sarcasm recognition network IMEPSI integrating multiple emotional polarities is constructed to extract the emotional features of the positive emotional part and the negative emotional part and the contextual information features of the text respectively; then, the emotional features are fused with the contextual information features, and the fused feature vector is reduced in dimension using the RELU activation function; finally, the Softmax activation function is used to determine whether the text is sarcastic.
[0083] The model training module is configured to initialize the model weights, including the weight matrix W p and the bias term b p , set model-related hyperparameters, including the size of the dropout rate, the size of the learning rate, the batch size, and the choice of the optimizer.
[0084] The sarcasm recognition model application module is configured to use the sarcasm recognition model to perform sarcasm recognition on the text, input the test set into the trained sarcasm recognition model for testing, use the accuracy and MMR in machine learning as evaluation indicators of the sarcasm recognition model when performing the sarcasm recognition task, and then apply the sarcasm recognition model to the sarcasm recognition tasks of different data sets.
[0085] Compared with the prior art, the present invention has the following advantages:
[0086] First, the present invention can improve the speed of sarcasm recognition. Compared with other existing sentiment dictionaries, the SSOPMI function overfilled sarcasm recognition sentiment dictionary constructed by the present invention reduces the sparsity of data in the sarcasm recognition sentiment dictionary, and the probability estimation of all words will look very smooth, while reducing the interference of a large number of irrelevant words, so that the present invention can more quickly and accurately extract sentiment polarity words in sentences, and also avoid the problem that a word has only one sentiment polarity in the sentiment dictionary, thereby improving the accuracy of model classification.
[0087] Second, the present invention can extract deep semantic ironic feature information. Compared with other existing technologies that extract feature information using single-structure deep learning models, the IMEPSI constructed by the present invention can extract the deep meaning of sentiment words with different sentiment polarities in the same context from sentences, thereby more accurately obtaining rich sentiment information in comments and improving the accuracy of model classification. BRIEF DESCRIPTION OF THE DRAWINGS
[0088] Figure 1 It is a flow chart for implementing the present invention.
[0089] Figure 2 This is a diagram of the framework of the sarcasm recognition model that integrates multiple emotional polarities.
[0090] Figure 3 This is a graph showing the experimental results of the comparison between the model of the present invention and other benchmark models.
[0091] Figure 4 This is a diagram of the ablation experiment results of the model of the present invention.
[0092] Figure 5 This is a graph showing the effect of batch processing parameters of different sizes on the performance of the model of the present invention.
[0093] Figure 6 This is a graph showing the effect of learning rate parameters of different sizes on the performance of the model of the present invention.
[0094] Figure 7 This is a graph showing the effect of discard rate parameters of different sizes on the performance of the model of the present invention. DETAILED DESCRIPTION
[0095] The present invention will be further defined below in conjunction with the accompanying drawings and embodiments, but is not limited thereto.
[0096] Example 1
[0097] Those skilled in the art will appreciate that the following examples are only used to illustrate the present invention and should not be considered to limit the scope of the present invention. If no specific techniques or conditions are specified in the examples, the techniques or conditions described in the literature in the art or the product specifications are used. If the manufacturer of the materials or equipment used is not specified, they are all conventional products that can be purchased.
[0098] A flowchart of the implementation of a sarcasm identification method integrating multiple emotional polarities is shown in Figure 1, which includes the following steps:
[0099] S100: Constructing a sarcasm recognition dataset: first, integrating existing relevant datasets to obtain original sarcasm data, and annotating the original sarcasm data; constructing each original sarcasm data and its corresponding annotation into a bigram, and all the bigrams constitute a sarcasm recognition dataset; finally, dividing the constructed sarcasm recognition dataset into a training set, a validation set, and a test set in a ratio of 6:2:2, and the division of the dataset may include but is not limited to a ratio of 6:2:2;
[0100] S200: Constructing a sentiment dictionary for sarcasm identification: First, select N comments with sentiment polarity from comments on multiple social platforms and the constructed sarcasm identification dataset as a corpus, calculate the word frequency W, inverse document frequency F, and word frequency and its inverse document frequency WF of each word, and select n words with higher WF as the seed words of the initial sarcasm identification sentiment dictionary; then construct the SSOPMI function to expand the sarcasm identification sentiment dictionary.
[0101] S300: Constructing a sarcasm identification model: First, the input text is split into a positive emotional polarity part, a negative emotional polarity part, and a non-emotional polarity part according to the sarcasm identification sentiment dictionary. Then, a sarcasm identification network IMEPSI that integrates multiple emotional polarities is constructed to extract the emotional features of the positive emotional part and the negative emotional part and the contextual information features of the text respectively, and then the emotional features and the contextual information features are integrated and the fusion feature vector is reduced in dimension; finally, the activation function is used to determine whether the text is sarcastic;
[0102] S400: Set all relevant parameters of the model: set the size of the discard rate, the size of the learning rate, the size of the batch processing, the selection of the optimizer and other parameters related to the model; load the training set and the validation set into the model for training to obtain the optimal parameters of the model after training.
[0103] S500: Use the sarcasm recognition model to perform sarcasm recognition on the text, input the test set into the trained sarcasm recognition model for testing, use the accuracy and MMR in machine learning as evaluation indicators of the sarcasm recognition model when performing the sarcasm recognition task, and then apply the sarcasm recognition model to the sarcasm recognition tasks of different data sets.
[0104] Preferably, step S100 of constructing a sarcasm recognition data set is specifically:
[0105] Obtaining raw satire data from multiple channels using crawlers to crawl data and integrate existing relevant data sets;
[0106] Construct the category label sarcasm, label each original satirical data text txt as "sarcasm" or "non-sarcasm"; then construct a tuple d = txt and its corresponding sarcasm<txt,sarcasm> ; All d constitute a data set D = {d1, d2, ..., d n}, where n is the number of data sets;
[0107] Take corpus c=['This is the first document.', 'This document is the second document.', 'And this is the third one.', 'Is this the first document? ', 'You are awesome and you can come up with this bad idea! '] as a simple example.
[0108] Preferably, step S200 constructs a sentiment dictionary for sarcasm recognition as follows:
[0109] Step S210: Calculate the word frequency, inverse document frequency, and word frequency and its inverse document frequency for each word. First, calculate the corpus C = {C1, C2, ..., C i , …, C n} for each word w x The frequency of occurrence of W in C x :
[0110] >>>W=Counter(C).most_common(15)
[0111] #Get the top 15 words in the corpus by frequency
[0112] [(′the′, 4), (′document′, 4), (′is′, 3), (′this′, 3), (′This′, 2), (′first′, 2), (′second′, 1), ( 'up', 1), ('third', 1), ('one', 1), ('ls', 1), ('bad', 1), ('are', 1), ('awesome', 1), ('and', 1)]
[0113] Then calculate the inverse document frequency F x :
[0114] >>>n_contain=sum([1for count in list ifword in count])
[0115] >>>F=math.log(len(list) / (1+n_contain))
[0116] Finally, the word frequency of each word is multiplied by its inverse document frequency to calculate WF x :
[0117] >>>X=ectorizer.TfidfVectorizer().transform(list)
[0118] >>>WF=pd.dataFrame(data).sort_values(ascending=False)
[0119] [('document', 1.627), ('the', 1.627), ('is', 1.316), ('this', 1.316), ('first', 1.161), ('This', 1.161), ('second', 0.539), (' up, 0.539), (′third′, 0.539), (′one′, 0.539), (′Is′, 0.539), (′are′, 0.539), (′bad′, 0.539), (′awesome′, 0.539), (′and′, 0.539)]
[0120] Finally, three words with higher WF were extracted from the original corpus, and then manually screened to obtain two initial sentiment dictionary seed words POS with positive sentiment polarity. w = {'awesome', 'up'} and 1 initial sentiment dictionary seed word NEG with negative sentiment polarity w ={'bad'}, the initial sentiment dictionary is represented by OriginED = {POS w , NEG w}.
[0121] Step S220: Expanding the sarcasm recognition sentiment dictionary. Calculate the correlation between the sentiment seed words and the words in the new corpus, and construct the SSOPMI function to expand the sarcasm recognition sentiment dictionary.
[0122] Preferably, the steps of constructing the SSOPMI function to expand the sarcasm recognition sentiment dictionary are as follows:
[0123] Step S221: First, for words that appear 0 times or very few times in the corpus, use N-gram NGram to re-estimate the number of times they appear in the corpus:
[0124]
[0125] Where x represents the number of times a word appears in the corpus; N x represents the number of words that appear x times in the corpus; x * Indicates the number of times a word appears in the corpus after being re-estimated by NGram.
[0126] Step S222: Calculate the number of comments in which the target word w appears in the corpus, the number of comments in which the sentiment seed word o appears in the corpus, and the probability that the number of comments in which the target word w and the sentiment seed word o co-occur in the corpus accounts for the total number of comments in the corpus.
[0127] Take the corpus [“Blowing your nose so hard your ears pop is the greatest way to start a Wenesday.”, “How much more stupid can people get..?”] as a simple example.
[0128]
[0129]
[0130]
[0131] Among them, Count(greatest, awesome) is the number of comments in which the target word greatest and the sentiment seed word awesome co-occur in the corpus; Count(greatest) is the number of comments in which the target word greatest appears in the corpus; Count(awesome) is the number of comments in which the sentiment seed word awesome appears in the corpus; Sum is the total number of comments in the corpus.
[0132] Step S223: constructing the SSOPMI function to calculate the sentiment tendency of each word in the corpus.
[0133]
[0134] The SSOPMI function calculates that the word greatest has a positive sentiment tendency, and adds it to the positive sentiment dictionary for sarcasm identification. Similarly, the sentiment tendencies of other words in the new corpus are calculated and divided into the positive sentiment dictionary for sarcasm identification or the negative sentiment dictionary for sarcasm identification, and finally the sarcasm identification sentiment dictionary is obtained.
[0135] Preferably, step S300 of constructing a sarcasm recognition model specifically includes:
[0136] Step S310: Based on the constructed sarcasm recognition sentiment dictionary, the input text is divided into positive sentiment polarity parts W pos , Negative emotional part W neg and the non-emotional polarity part W null .
[0137] Take "You are awesome and you can come up with this bad idea" as a simple example. Split the input text into positive sentiment polarity parts W pos ={′awesome′, ′up′}, negative sentiment polarity part W neg = {'bad'} and no sentiment polarity part W null ={'You', 'are', 'and', 'you', 'can', 'come', 'with', 'this', 'idea'}.
[0138] Step S320: constructing a sarcasm recognition network IMEPSI that integrates multiple emotional polarities to extract emotional features of the positive emotional part and the negative emotional part and context information features of the text respectively, and then integrating the emotional features with the context information features and reducing the dimension of the integrated feature vector.
[0139] Preferably, the steps of constructing IMEPSI to extract and fuse sentiment features and context information features are as follows:
[0140] Step S321: Use the BERT model to extract W pos and W neg The following is the emotional characteristics of W pos For example:
[0141] First, W pos and W null Splicing to get W pos+null , and then perform word segmentation:
[0142] >>>txt='You are awesome and you can come up with this bad idea'
[0143] >>>tokenized_txt=tokenizer.tokenize(txt)
[0144] #Tokenized_txt obtained by word segmentation operation
[0145] >>>tokenized_txt
[0146] ['awesome', 'up', 'You', 'are', 'and', 'you', 'can', 'come', 'with', 'this', 'idea']
[0147] The BERT model then adds a start tag [CLS] at the beginning of tokenized_txt and an end tag [SEP] at the end of each sentence:
[0148] #Add a mark to tokenized_txt to get marked_tokenized_txt
[0149] >>>marked_tokenized_txt
[0150] [[CLS], 'awesome', 'up', 'You', 'are', 'and', 'you', 'can', 'come', 'with', 'this', 'idea', [SEP]]
[0151] Convert marked_tokenized_txt into a word embedding vector E through the word generator provided by the BERT model token .
[0152] Then, the BERT model generates a fragment embedding vector E alternating between all 0s and all 1s for each sentence according to the end tag in marked_tokenized_txt. segment :
[0153] #Fragment embedding vector generated based on marked_tokenized_txt
[0154] >>>Bert.segments_ids(marked_tokenized_txt)
[0155] [1,1,1,1,1,1,1,1,1,1,1,1,1]
[0156] The BERT model maps marked_tokenized_txt to a position embedding vector E according to its own dictionary. position .
[0157] Finally, E token 、E segment and E position To overlay:
[0158] E sentence =E token +E segment +E position
[0159] The superposition vector is the BERT model from W pos+null Extracted positive sentiment feature vector:
[0160] [101, 11722, 8505, 8644, 8995, 8256, 8357, 9109, 11385, 8663, 8554, 11834, 102]
[0161] The W extracted by the BERT model pos+null The positive emotion feature vector E sentence Expressed as
[0162] Similarly, follow the above steps to convert W neg and W null Splice and then extract W neg+null The negative sentiment feature of
[0163] Step S322: Use the BiLSTM model to extract the context information features of the input text, expressed as
[0164] V x and V z After splicing, we get:
[0165] Then use a linear layer and RELU activation function to temp Perform dimensionality reduction to obtain the positive sentiment feature vector V containing context information pos :
[0166] V pos =RELU[Linear(V temp )]
[0167] Similarly, according to step S322, the negative sentiment feature vector V containing context information is extracted. neg :
[0168] V neg =RELU[Linear(Concatenate(V y , V z ))]
[0169] Step S323: Fusion V pos and V neg , using the Softmax activation function, calculate the probability P that the text is sarcastic sarcasm , and its calculation formula is as follows:
[0170] P sarcasm=softmax(W p [V pos , V neg ]+b p )
[0171] Where W p is the weight matrix, b p is the bias term, P sarcasm is the probability that the statement is sarcastic.
[0172] If P sarcasm If the value of is greater than or equal to a certain threshold r, it is judged to be ironic, otherwise it is not ironic. The value of r is usually 0.5.
[0173] Example 2
[0174] The present invention uses Twitter dataset, takes accuracy, precision, recall and F1 value as experimental result judgment indicators, and compares the present invention model with other benchmark models. The experimental results are as follows: Figure 3 shown.
[0175] In order to verify that the model of the present invention splits the text into emotional polarity parts, it is effective for sarcasm recognition. Therefore, the positive emotional polarity part, the negative emotional polarity part, the positive and negative emotional polarity parts at the same time, and other emotional dictionaries are removed for ablation experiments. The experimental results are as follows: Figure 4 shown.
[0176] In order to further improve the accuracy and effectiveness of the model, the experiment studied the hyperparameters of the model. First, the batch processing parameter Bach_size of the model was experimented. The experimental results are as follows: Figure 5 When the batch size is set to 32, it is the optimal parameter of the model. If the batch size is too large, the model accuracy, precision, recall rate and F1 value will decrease. If the batch size is too small, it will cause overfitting.
[0177] Then we experimented with the learning rate parameters. The experimental results are as follows: Figure 6 As shown in the figure, the performance is best when the learning rate is set to 3e-5, and the performance is worst when it is increased to 8e-5. A learning rate that is too small will cause the model to converge slowly and make it difficult to find the optimal solution, while a learning rate that is too large will easily make it difficult for the model to converge.
[0178] Finally, the discard rate parameters were experimented, and the experimental results are shown as follows: Figure 7 As shown in the figure. When the discard rate is set to 0.3, the accuracy, precision, recall and F1 value of the model are the largest, and the model training effect is the best. A discard rate that is too small will cause the model to overfit easily, and a discard rate that is too large will cause the model to underfit easily.
[0179] Example 3
[0180] The present invention also provides a text irony recognition device integrating multiple emotional polarities, comprising:
[0181] The module for constructing a sarcasm recognition dataset is configured as follows: integrating existing relevant datasets to obtain original sarcasm data, and annotating the original sarcasm data; constructing each original sarcasm data and its corresponding annotation into a bigram, and all the bigrams constitute a sarcasm recognition dataset; finally, dividing the sarcasm recognition dataset into a training set, a validation set, and a test set according to a certain ratio;
[0182] The module for constructing a sentiment dictionary for sarcasm identification is configured as follows: first, N comments with sentiment polarity are selected from comments on multiple social platforms and the constructed sarcasm identification dataset as a corpus, W, F and WF of each word are calculated, and n words with higher WF are selected as seed words of the initial sentiment dictionary for sarcasm identification; then, a smooth sentiment tendency point mutual trust function SSOPMI is constructed to expand the sentiment dictionary for sarcasm identification;
[0183] The module for text sarcasm recognition that integrates multiple emotional polarities is constructed. It is configured to first split the input text into positive emotional polarity part, negative emotional polarity part and no emotional polarity part according to the sarcasm recognition emotional dictionary. Then, the BERT model is used to extract the emotional features of the positive emotional part and the negative emotional part respectively; then the BiLSTM bidirectional long short-term memory model is used to extract the context information features of the text; then the emotional features are fused with the context information features, and the RELU activation function is used to reduce the dimension of the fused feature vector; finally, the Softmax activation function is used to determine whether the text is sarcastic.
[0184] The model training module is configured to initialize the model weights, including the weight matrix W p and the bias term b p , set model-related hyperparameters, including the size of the dropout rate, the size of the learning rate, the batch size, and the choice of the optimizer.
[0185] The sarcasm recognition model application module is configured to use the sarcasm recognition model to perform sarcasm recognition on the text, input the test set into the trained sarcasm recognition model for testing, use the accuracy and MMR in machine learning as evaluation indicators of the sarcasm recognition model when performing the sarcasm recognition task, and then apply the sarcasm recognition model to the sarcasm recognition tasks of different data sets.
[0186] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0187] In the embodiments provided in the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.
[0188] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0189] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0190] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program codes.
[0191] The above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A text sarcasm recognition method integrating multiple sentiment polarities, characterized in that: The method comprises the following steps: S1. Constructing a sarcasm recognition dataset: first, integrating existing relevant datasets to obtain original sarcasm data, annotating the original sarcasm data, and then constructing each original sarcasm data and its corresponding annotation into a bigram, all bigrams constitute a sarcasm recognition dataset, and finally dividing the sarcasm recognition dataset into a training set, a validation set, and a test set according to a certain ratio; S2. Constructing a sentiment dictionary for sarcasm identification: First, select N comments with sentiment polarity from comments on multiple social platforms and the sarcasm identification dataset as a corpus; then calculate the frequency of each word W , Inverse Document Frequency F and term frequency and its inverse document frequency WF , select WF The first n words after sorting are used as the seed words of the initial sarcasm recognition sentiment dictionary; finally, the sarcasm recognition sentiment dictionary is expanded; The step of expanding the sarcasm recognition sentiment dictionary includes: S21. Calculate the value of each word W , F as well as WF ; S22. Constructing mutual trust function of emotional tendency points SSOPMI Expand the sentiment dictionary for sarcasm identification; The construction of emotional tendency point mutual trust function SSOPMI The steps to expand the sentiment dictionary for sarcasm identification include: S221. For words that appear 0 or very few times in the corpus, use N-gram NGram to re-estimate the number of times they appear in the corpus: Where x represents the number of times a word appears in the corpus; Indicates the number of words that appear x times in the corpus; Indicates the number of times a word appears in the corpus after being re-estimated by NGram; S222, calculate target words separately w The number of comments and sentiment seed words that appear in the corpus o The number of comments that appear in the corpus, w and o The probability that the number of co-occurring comments in the corpus accounts for the total number of comments in the corpus, that is: in Count ( w , o )for w and o The number of comments that co-occur in the corpus; Count ( w )for w The number of comments that appear in the corpus; Count ( o )for o The number of comments that appear in the corpus; Sum is the total number of comments in the corpus; S223. Design of mutual trust function of emotional tendency points SSOPMI Used to reduce o and w The data sparsity of o and w The probability curve of appearing in the same comment is smoother; P ( w , o ) is substituted into NGram to obtain the re-estimated value by NGram. w and o The number of times a word co-occurs in the corpus : C o u n t * w o = C o u n t w o + 1 N C o u n t w o + 1 N C o u n t w o in is what happens in the corpus Count ( w , o ) comments; S224. Calculate the sentiment tendency of each word in the corpus. The formula is as follows: in is the initial sentiment dictionary seed word with positive sentiment polarity, is the initial sentiment dictionary seed word with negative sentiment polarity; like SSOPMI ( w )>0, it means that the word has a positive sentiment tendency, and it is added to the positive sentiment dictionary for sarcasm recognition; if SSOPMI ( w )=0, it means that the word has no sentiment tendency; if SSOPMI ( w )<0, it means that the word has a negative sentiment tendency, and it is added to the sarcasm identification negative sentiment dictionary; the sarcasm identification positive sentiment dictionary and the sarcasm identification negative sentiment dictionary constitute the sarcasm identification sentiment dictionary; S3, build a sarcasm recognition model: first, split the input text into positive emotional polarity part, negative emotional polarity part and no emotional polarity part according to the sarcasm recognition sentiment dictionary; then build a sarcasm recognition network IMEPSI that integrates multiple emotional polarities to extract the emotional features of the positive emotional polarity part and the negative emotional polarity part, and the context information features of the text; then fuse the emotional features with the context information features, and reduce the dimensionality of the fused features; finally, determine whether the text is sarcastic based on the activation function; The steps of constructing the sarcasm recognition model include: S31. Based on the constructed sarcasm recognition sentiment dictionary, the input text is divided into positive sentiment polarity parts , Negative sentiment polarity part and the non-emotional polarity part ; S32, build a satire recognition network IMEPSI that integrates multiple emotional polarities, extract and The sentiment features and the context information features of the text are then fused together, and the fused features are reduced in dimension. The steps of constructing a satire recognition network IMEPSI that integrates multiple emotional polarities and extracting and integrating emotional features and context information features include: S321, Extraction using BERT model and Emotional characteristics: First, and Splice to get Then extract The positive emotional characteristics of ; Then and Splice to get , and finally extract The negative sentiment feature of ; S322, first extract the context information features of the input text, expressed as ; then and Concatenate and use a linear layer and RELU activation function to reduce the dimension of the concatenated features to obtain positive sentiment features containing contextual information : V p o s = R E L U L i n e a r C o n c a t e n a t e V x V z Then and Concatenate and use a linear layer and RELU activation function to reduce the dimension of the concatenated features to obtain negative sentiment features containing contextual information : V n e g = R E L U L i n e a r C o n c a t e n a t e V y V z in Concatenate is the vector concatenation function, Linear represents a linear layer; S323, Fusion and ,use Softmax Activation function, calculating the probability that the text is sarcastic , and its calculation formula is as follows: P s a r c a s m = S o f t m a x W p V p o s V n e g + b p in is the weight matrix, is the bias term; like The value is greater than or equal to a threshold r , judge it to be ironic, otherwise it is not ironic; S4. Set all relevant parameters of the model: set the size of the discard rate, the size of the learning rate, the size of the batch processing, the selection of the optimizer and other parameters related to the model; load the training set and the validation set into the model for training to obtain the optimal parameters of the model after training; S5. Use the sarcasm recognition model to perform sarcasm recognition on the input text, input the test set into the trained sarcasm recognition model for testing, use the accuracy and average missed detection rate in machine learning as evaluation indicators of the sarcasm recognition model when performing the sarcasm recognition task, and then apply the sarcasm recognition model to the sarcasm recognition task of different data sets.
2. A text sarcasm recognition device integrating multiple emotional polarities, characterized in that: Used to run the text sarcasm recognition method integrating multiple emotional polarities as described in claim 1.
