An irony recognition model based on convolutional neural network and attention mechanism

By adopting convolutional neural network and attention mechanism in the irony recognition model, combined with the pre-trained language model BERT, the high-level semantic features of sentence phrase fragments are extracted, and the problem that existing models are difficult to capture semantic conflict information is solved, achieving higher irony recognition accuracy.

CN114722798BActive Publication Date: 2025-03-18DALIAN NATIONALITIES UNIVERSITY
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210108214.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-01-28
Publication Date
2025-03-18
Estimated Expiration
2042-01-28

AI Technical Summary

Technical Problem

Existing ironic recognition models are difficult to accurately capture semantic conflict information within sentences, resulting in limited accuracy of ironic recognition tasks.

Method used

Using an ironic recognition model based on convolutional neural network and attention mechanism, the word vectors of words are generated by pre-training language model BERT, and the convolution operation is used to implicitly segment the sentences into phrase fragments to extract higher-level semantic features. Attention mechanisms are used to assist the model in capturing semantic features related to the ironic task and performing reweighting combinations.

Benefits of technology

This model can more accurately capture semantic inconsistency information between sentence phrase fragments, improve the accuracy of ironic recognition tasks, and make up for the shortcomings of traditional sequence models.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114722798B_ABST
    Figure CN114722798B_ABST
Patent Text Reader

Abstract

The present invention belongs to the field of natural language processing, and relates to an irony recognition model based on convolutional neural networks and attention mechanisms. It includes: S1. Text representation layer; S2. Semantic feature extraction layer; S3. Irony semantic relationship modeling layer; S4. Irony intention discrimination layer. Beneficial effects: The present invention can identify potential ironic expressions in social media and mine the real emotional tendencies of users. The model makes up for the shortcomings of traditional sequence models and realizes the modeling of emotional semantic relationships between sequences within sentences. At the same time, compared with the existing irony recognition method based on word pair contradictions, the model is more likely to capture the semantic contradiction information generated by the irony effect, improve the accuracy of the irony recognition task, and implicitly divide the sentence into phrase fragments through convolution operations to extract higher-level semantic features; it can more accurately capture the semantic inconsistency information between sentence phrase fragments.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of natural language processing and relates to an irony recognition model based on a convolutional neural network and an attention mechanism. Background Art

[0002] Irony, as a common metaphorical language in human social life, is widely loved by social media users due to its strong and unique linguistic effect when expressed. However, due to many factors such as the ambiguity of irony in emotional expression and the difference between literal meaning and real emotions, it brings certain difficulties and challenges to the task of text sentiment analysis. If the real emotional information contained in the text cannot be accurately identified, it will seriously affect the accuracy of tasks such as text sentiment analysis and opinion mining.

[0003] Intra-sentence semantic conflict is an important feature of ironic rhetoric. When using traditional sequence models such as long short-term memory networks to model ironic semantics, it is often difficult to accurately capture the emotional semantic relationship embedded in the sentence, which has led to the difficulty in improving the performance of the model. In recent years, a small number of researchers have proposed improved algorithms to address the shortcomings of sequence models. The main idea is to capture the semantic conflict relationship of ironic text by modeling the semantic relationship between words within the sentence. This method overcomes the shortcomings of traditional sequence models and can accurately focus on the semantic joint information between sequences within the sentence, which greatly improves the accuracy of irony recognition tasks. However, after research, it is found that in the process of using the above method to model the semantic relationship between words, it is sometimes difficult to capture the semantic conflict information between words because the semantic information contained in the words is too little. For example, in the ironic sentence "Going in to work for 2 hours was totally worth the 50min drive", if only the semantic relationship between words is observed, it is difficult to find the semantic conflict in the sentence. However, by observing the phrase fragments "work for2hours" and "worth the 50min drive", it can be found that the two phrases have a strong emotional contrast in semantics.

[0004] Therefore, when modeling the language structure features that produce irony effects, it is more reasonable to capture the semantic inconsistency information between sentence phrase fragments rather than between words, because phrase fragments contain much more semantic information than single words. Summary of the invention

[0005] In order to overcome some shortcomings and deficiencies of the existing irony recognition model, the present invention proposes the following technical solution: an irony recognition model based on a convolutional neural network and an attention mechanism, comprising:

[0006] S1. Text representation layer: used to generate word vectors through the pre-trained language model BERT;

[0007] S2. Semantic feature extraction layer: It is used to extract semantic features by implicitly segmenting sentences into phrases using the text convolutional neural network (CNN) layer. It helps the model capture features related to the irony task through the Attention layer mechanism, assigns different weight scores according to the importance of the features, and re-weights the features and weights.

[0008] S3. Irony semantic relationship modeling layer: by modeling the semantic joint information between the semantic features within the sentence, the semantic conflict information within the sentence is captured;

[0009] S4. Irony intention discrimination layer: The feature dimension of irony semantics is reduced through the linear layer, and the output of the linear layer is predicted through the softmax layer to determine whether the text sequence contains irony rhetoric;

[0010] The model takes the input text sequence S through the text representation layer, adds segmentation tags, converts, and trains to obtain the word vector representation matrix E of the text sequence;

[0011] The word vector representation matrix E is used as the input of the semantic feature extraction layer, and the convolution operation is used to extract features. The obtained single phrase fragment features are spliced ​​into a feature matrix M. The importance of different semantic features of the matrix M is analyzed through the attention network, and corresponding weights are assigned to them. Finally, the weights and features are re-weighted and combined to obtain the final semantic feature V.

[0012] The semantic feature V is used as the input of the ironic semantic relationship modeling layer. The ironic semantic representation f of the text sequence is obtained by modeling, pooling, and weighted summation of semantic joint information. a ;

[0013] Ironic semantic representation of text sequences a As the input of the irony discriminant layer, the feature representation f of irony semantics is reduced through a linear layer a The softmax layer predicts the output of the linear layer to determine whether the text sequence contains irony and obtain the classification result of the model.

[0014] Furthermore, in the text representation layer: the pre-trained language model BERT is used to train ironic texts under different context information to obtain word embedding representations containing context information;

[0015] The steps to use the pre-trained language model BERT are as follows:

[0016] First, define the input text sequence S, S = {s1, s2, ..., s n}, where si represents the i-th word in the text sequence, and n represents the number of words contained in the text sequence;

[0017] Secondly, add "[CLS]" and "[SEP]" segmentation markers at the beginning and end of the text sequence respectively to convert the text sequence into a specific format that the BERT model can process;

[0018] Finally, the processed text sequence is sent to the BERT model for training to obtain the word vector representation matrix E of the text sequence. The specific process is as shown in Formula 3.1:

[0019] E=BERT(“[CLS]”+s1,s2,s3,...s n + "[SEP]") (3.1)

[0020] Where E = {e1, e2, e3..., e n},e i ∈R k Represents the word vector representation of the i-th word in the text sequence, and k represents the dimension of the word vector.

[0021] Furthermore, the pre-trained language model BERT includes a token embedding model Token Embedding, a position embedding model Position Embedding, and a segmentation embedding model Segment Embedding.

[0022] Furthermore, the CNN layer feature extraction step includes:

[0023] (1) Two-dimensional word embedding matrix of input text sequence;

[0024] (2) Use different convolution kernels to continuously perform convolution operations with the word vector matrix to extract the feature graph of the text sequence;

[0025] (3) Use the maximum pooling method to process feature maps of different sizes to obtain a single feature of fixed length;

[0026] (4) Concatenate all single features into a simple feature vector;

[0027] The process is as follows:

[0028] First, input the two-dimensional word vector matrix E of the text sequence, E = {e1, e2, e3..., e n}, where n represents the number of words contained in the text sequence, e i ∈R k Represents the word vector representation of the i-th word in the text sequence, and k is the dimension of the word vector;

[0029] Secondly, the two-dimensional word vector matrix E is input into the convolution module, and the features of the phrase fragments are extracted by convolution operation between the convolution kernel and the text sequence in the convolution window. In the experiment, the size of the convolution kernel W is defined as h*k, where h represents the size of the convolution kernel window, which determines the number of words contained in the phrase fragment. The feature extraction process of the phrase fragment can be expressed as follows:

[0030] c i =f(W·E i:i+h-1 +b) (3.2)

[0031] Here we define a convolution function operation f, c i represents the phrase features extracted after the convolution kernel W is convolved with the phrase fragment consisting of the i-th word to the i+h-1-th word in the word vector matrix E, and b is the bias;

[0032] Again, after the convolution kernel W completes the convolution operation with the entire word vector matrix E from top to bottom, a single feature map c of all phrase fragments in the text sequence is obtained, c = (c1, c2, c3, ... c n-h+1 );

[0033] Finally, use k convolution kernels with the same size as W to repeat the above operation, and concatenate the obtained feature maps to obtain the semantic feature matrix M∈R of the phrase fragment (n-h+1)*k ,M=(m1,m2,m3,...,m n-h+1 ), where m i ∈R k Represents the semantic feature representation of the i-th phrase fragment in the text sequence.

[0034] Furthermore, the Attention layer strengthens the key semantic features by assigning weight scores to different semantic features. The steps are as follows:

[0035] First, the semantic features mi extracted from the feature extraction layer are input into a linear layer, and then the tanh function processes the result to obtain the hidden feature representation m′ of the i-th phrase. i , where b is the bias, the specific process can be expressed as shown in formula (3.3):

[0036] m′i =tanh(W·m i +b) (3.3)

[0037] Secondly, according to the semantic feature m′ i The similarity with the context vector q is used to calculate the semantic feature m′ i The weight score s i , and then use the softmax function to normalize the weight scores of all features to obtain the final weight matrix a. The specific calculation process is as shown in formulas 3.4, 3.5, and 3.6:

[0038]

[0039] a=Soft max(s1,s2,s3,...,s n-h+1 ) (3.5)

[0040] a=(a1,a2,a3,...,a n-h+1 ) (3.6)

[0041] Finally, the weight score a i With semantic feature m i The final semantic feature V is obtained by associating them. The specific calculation method is as shown in formulas 3.7 and 3.8:

[0042] v i =a i *m i (3.7)

[0043] V=(v1,v2,v3,...,v n-h+1 ), V∈R (n-h+1)*k (3.8)

[0044] Beneficial effects: The present invention can identify potential ironic expressions in social media and mine the real emotional tendencies of users. The model makes up for the shortcomings of traditional sequence models and realizes the modeling of emotional semantic relationships between sequences within sentences. At the same time, compared with the existing irony recognition method based on word pair contradictions, the model is more likely to capture the semantic contradiction information generated by the irony effect, improve the accuracy of the irony recognition task, and implicitly divide the sentences into phrase fragments through convolution operations to extract higher-level semantic features; it can more accurately capture the semantic inconsistency information between sentence phrase fragments. BRIEF DESCRIPTION OF THE DRAWINGS

[0045] Figure 1 Irony recognition model structure diagram;

[0046] Figure 2 BERT model structure diagram;

[0047] Figure 3 Input structure diagram of the BERT model;

[0048] Figure 4 Text convolutional neural network structure diagram;

[0049] Figure 5 Semantic feature extraction structure diagram;

[0050] Figure 6 Attention layer model structure diagram;

[0051] Figure 7 Structure diagram of the irony semantic modeling module. DETAILED DESCRIPTION

[0052] The present invention proposes an irony recognition model based on convolutional neural network and attention mechanism. In the model of the present invention, semantic information is no longer extracted with words as the smallest unit, but sentences are implicitly divided into phrase fragments through convolution operation to extract higher-level semantic features; at the same time, after the feature extraction is completed, an attention model is added to further process all features, strengthen the semantic information related to the current irony recognition task and assign them higher weights, weaken other irrelevant information and assign them lower weights; then, according to the inherent language structure characteristics of ironic rhetoric, the semantic joint information between features is modeled, so that the model captures the emotional inconsistency information embedded in the internal sequences of the sentence, and forms a sentence-level irony representation; finally, the irony representation of the text sequence is sent to the classifier for irony discrimination.

[0053] 1. Overall framework of irony recognition model

[0054] 1.1 Problem Definition

[0055] In the field of natural language processing, irony detection is usually defined as a binary classification task, which aims to identify whether a given text contains irony. Usually, given a text sequence S and a category set Y = {0,1}, the model can correctly predict the input text S as an ironic category, that is, {y = 1}, or a non-ironic category, that is, {y = 0}. For example, "I like my son rolling his eyes at me" is predicted by the model as an ironic expression, while "I like my son giving me gifts" is predicted as a non-ironic expression.

[0056] 1.2 Overall Framework

[0057] In order to identify potential ironic expressions in social media and tap into users' true emotional tendencies, the present invention proposes an irony recognition model based on convolutional neural networks and attention mechanisms. This model makes up for the shortcomings of traditional sequence models and realizes the modeling of emotional semantic relationships between sequences within sentences. Compared with existing irony recognition methods based on word pair contradictions, this model is more likely to capture the semantic contradiction information generated by irony effects.

[0058] The overall framework of the model is as follows Figure 1 As shown in the figure, it consists of four parts: the first part is the text representation layer; the second part is the semantic feature extraction layer; the third part is the irony semantic relationship modeling layer; and the fourth part is the irony intention discrimination layer.

[0059] In the entire model, the pre-trained language model BERT is first used to train ironic texts under different contextual information to obtain word embedding representations containing contextual information; secondly, the text vector matrix obtained by BERT training is input into the convolutional neural network and the attention network in turn, and the convolution operation and attention operation are used to extract semantic features with richer emotional information and assign corresponding weights to the features; thirdly, according to the language structure characteristics of ironic rhetoric, the semantic joint information between different semantic features is modeled, the semantic contradiction information that forms the ironic effect is extracted, and the sentence-level ironic text representation is formed; finally, the feature representation of the ironic text is sent to the classifier for irony discrimination.

[0060] 1.2.1 Text Representation Layer

[0061] Machines cannot understand real-life speech like humans do. Therefore, if you want computers to be able to process input data, you first need to convert the input data into machine language. Currently, the simplest way to do this is to map words into a vector space and convert them into word vectors containing semantic information.

[0062] However, due to the complexity and diversity of language, the same word may have multiple different meanings. For example, in the ironic sentence "I love to be bothered when working", the word "bother" means "disturb", while in the non-ironic sentence "I don't know why you bother with that crowd", the word "bother" means "waste of words". Therefore, this requires that the word vector model must be able to accurately represent the meaning of words according to different contextual information during training; more importantly, in the irony recognition task, the semantics of words is crucial to the correct recognition of ironic intentions. Taking the above ironic sentence as an example, if the word "bother" in the sentence is not accurately expressed as "disturb" by the word vector, then it will be difficult for the model to determine that it is an ironic sentence. Therefore, in the text representation layer of the model, in order to accurately represent the semantic information of words in different contexts and improve the accuracy of the irony recognition task, this paper uses the pre-trained language model BERT to generate word vectors for words.

[0063] BERT is a new type of deep contextual word vector representation method. By using the language model MLM (masked language model) and multiple deep bidirectional Transformer components for pre-training on massive data, the model can learn the contextual information of words from both the left and right directions, greatly improving the representation ability of word vectors, and ultimately generating text representations that can fully reflect the complex semantics and contextual information of words. The main structure of BERT is as follows Figure 2 As shown:

[0064] Among them, E1, E2, ..., En are the input of the model, which consists of Token Embedding, Position Embedding, and Segment Embedding. Token Embedding is a token embedding, which represents the common subword of the smallest unit. Position Embedding is a position embedding, which indicates the position information of a word in a text sequence. Segment Embedding is a segmentation embedding, which is used to segment two sentences. Its detailed structure is as follows Figure 3 As shown; Trm represents the encoder part of Transformer, which consists of a multi-head attention mechanism and a fully connected layer, which is used to transform the input data into a feature vector; T1, T2, ..., Tn are the outputs of the model, which are the outputs of the last Transformer encoder corresponding to the input.

[0065] The BERT model used in this experiment is the pre-trained language model BERT-BASE based on English corpus open sourced by Google. The number of hidden layers in this model is 12, the size of the hidden vector is 768, and the number of heads of the attention mechanism is 12. The specific steps for using the model training are as follows:

[0066] First, define the input text sequence S, S = {s1, s2, ..., s n}, where si represents the i-th word in the text sequence, and n represents the number of words in the text sequence;

[0067] Secondly, add "[CLS]" and "[SEP]" segmentation markers at the beginning and end of the text sequence respectively to convert the text sequence into a specific format that the BERT model can process;

[0068] Finally, the processed text sequence is sent to the BERT model for training to obtain the word vector representation matrix E of the text sequence. The specific process is shown in formula (3.1):

[0069] E=BERT(“[CLS]”+s1,s2,s3,...s n + "[SEP]") (3.1)

[0070] Where E = {e1, e2, e3..., e n},e i ∈R k Represents the word vector representation of the i-th word in the text sequence, and k represents the dimension of the word vector.

[0071] 1.2.2 Semantic Feature Extraction Layer

[0072] Most of the current advanced irony recognition models identify the ironic intention of text sequences by capturing the semantic conflict information between words within a sentence. However, research has found that when using this method to model the semantic conflict between sentence features, sometimes the semantic conflict information between words and other features cannot be captured because the semantic information contained in the word is too little. Therefore, in order to make up for the problem of too little semantic information contained in word features, this paper proposes a semantic feature representation method based on phrase fragments. By using convolutional neural networks to implicitly divide sentences into phrase fragments to extract higher-level semantic features, the attention mechanism is used to assist the model in capturing features that are more relevant to the irony task. After assigning different weight scores to the features according to their importance, the features and weights are re-weighted and combined.

[0073] 1.2.2.1 CNN Layer

[0074] In order to solve the problem that the semantic information extracted by using words as input cannot fully summarize the text content, this paper proposes a semantic feature representation method based on phrase fragments. Since in the entire text sequence, phrase fragments are equivalent to local information of the entire text, this paper uses a text convolutional neural network to extract such local features.

[0075] Text convolutional neural network is a commonly used local feature extractor in the field of natural language processing. It usually consists of four modules, namely input module, convolution module, pooling module and fully connected module.

[0076] The specific method of feature extraction is:

[0077] (1) Two-dimensional word embedding matrix of input text sequence;

[0078] (2) Use different convolution kernels to continuously perform convolution operations with the word vector matrix to extract the feature graph of the text sequence;

[0079] (3) Use the maximum pooling method to process feature maps of different sizes to obtain a single feature of fixed length;

[0080] (4) All single features are concatenated into a simple feature vector. The detailed process of text convolution is as follows: Figure 4 As shown:

[0081] In the process of extracting the features of phrase fragments, the convolution kernel continuously moves on the entire text sequence to implicitly divide the text sequence into multiple phrase fragments. The size of the convolution kernel window determines the length of the phrase fragment. The convolution operation between the convolution kernel and the text sequence in the convolution window realizes the extraction of phrase features. The specific process is as follows:

[0082] First, input the two-dimensional word vector matrix E of the text sequence, E = {e1, e2, e3..., e n}, where n represents the number of words contained in the text sequence, e i ∈R k Represents the word vector representation of the i-th word in the text sequence, and k is the dimension of the word vector.

[0083] Secondly, the two-dimensional word vector matrix E is input into the convolution module, and the features of the phrase fragments are extracted by convolution operation between the convolution kernel and the text sequence in the convolution window. In the experiment, the size of the convolution kernel W is defined as h*k, where h represents the size of the convolution kernel window, which determines the number of words contained in the phrase fragment. The feature extraction process of the phrase fragment can be expressed as shown in formula (3.2):

[0084] c i =f(W·E i:i+h-1 +b) (3.2)

[0085] Here we define a convolution function operation f, c i represents the phrase features extracted after the convolution kernel W is convolved with the phrase fragment consisting of the i-th word to the i+h-1-th word in the word vector matrix E, and b is the bias.

[0086] Again, after the convolution kernel W completes the convolution operation with the entire word vector matrix E from top to bottom, a single feature map c of all phrase fragments in the text sequence is obtained, c = (c1, c2, c3, ... c n-h+1 ).

[0087] Finally, use k convolution kernels with the same size as W to repeat the above operation, and concatenate the obtained feature maps to obtain the semantic feature matrix M∈R of the phrase fragment (n-h+1)*k ,M=(m1,m2,m3,...,m n-h+1 ), where m i ∈R k Represents the semantic feature representation of the i-th phrase fragment in the text sequence.

[0088] The specific process of feature extraction is as follows Figure 5 shown.

[0089] 1.2.2.2 Attention Layer

[0090] After the convolutional neural network, the model extracted phrase fragment features with richer semantic information. In order to highlight the feature information that is more relevant to the current irony task among all semantic features, this paper added an attention model after the convolutional neural network, and used the attention network to analyze the importance of different semantic features and assign corresponding weights to them, and finally re-weighted the weights and features.

[0091] In this study, inspired by the hierarchical attention mechanism proposed by Yang et al., a method for analyzing the importance of phrase features in text sequences was designed. By assigning weight scores to different semantic features, the purpose of strengthening key semantic features was achieved. The specific design steps are as follows:

[0092] First, the semantic features mi extracted from the feature extraction layer are input into a linear layer, and then the tanh function processes the result to obtain the hidden feature representation m′ of the i-th phrase. i , where b is the bias, the specific process can be expressed as shown in formula (3.3):

[0093] m′ i =tanh(W·m i +b) (3.3)

[0094] Secondly, according to the semantic feature m′ i The similarity with the context vector q is used to calculate the semantic feature m′ i The weight score s i , and then use the softmax function to normalize the weight scores of all features to obtain the final weight matrix a. The specific calculation process is shown in equations (3.4), (3.5), and (3.6):

[0095]

[0096] a=Soft max(s1,s2,s3,...,s n-h+1 ) (3.5)

[0097] a=(a1,a2,a3,...,a n-h+1 ) (3.6)

[0098] Finally, the weight score a i With semantic feature m i The final semantic feature V is obtained by associating them. The specific calculation method is shown in formulas (3.7) and (3.8):

[0099] v i =a i *m i (3.7)

[0100] V=(v1,v2,v3,...,v n-h+1 ), V∈R (n-h+1)*k (3.8)

[0101] The calculation process of the entire attention layer is as follows Figure 6 shown.

[0102] 1.2.3 Irony Semantic Relationship Modeling Layer

[0103] Semantic contradiction or emotional inconsistency between the internal features of a sentence is an important reason for the ironic effect. In this study, according to the language structure characteristics of ironic expression, an ironic semantic modeling method based on the intra-sentence attention mechanism is proposed. This method captures the semantic conflict information within the sentence by modeling the semantic joint information between the internal semantic features of the sentence, thereby achieving the purpose of identifying the ironic intention of the text.

[0104] The main steps of this method are:

[0105] 1. Use the intra-sentence attention mechanism to model the semantic joint information between all phrase fragments in the text sequence, calculate the attention scores between all phrase features to obtain a two-dimensional score matrix, the size of which represents the degree of semantic conflict between phrase features;

[0106] 2. Use the row-wise maximum pooling method to find the largest attention score for the current phrase feature. The larger the score, the greater the possibility that the phrase feature will have a semantic conflict with other phrase features;

[0107] 3. Perform a weighted summation of all phrase features and the maximum conflict score of their corresponding rows to obtain the sentence-level vector representation of the text sequence. The specific design steps are as follows:

[0108] First, for the phrase feature v i and v j , calculate the attention score w between them i,j , the calculation method is shown in formula (3.9):

[0109] w i,j =tanh(v i ·M i,j ·v j T ) (3.9)

[0110] Among them, w i,j The size of represents the semantic feature v i and v j The degree of semantic conflict between M i,j ∈R (n-h+1)*(n-h+1) is a parameter matrix. It should be noted that this calculation method is inspired by the method of Xiong et al. to calculate the semantic conflict information between words.

[0111] Secondly, the semantic conflict scores between all phrase features in the text sequence are calculated to obtain the score matrix W as shown in formula (3.10):

[0112]

[0113] Among them, when i=j, the corresponding score w i,j It is set to 0 because there is no semantic conflict between the phrase features themselves. Setting it to 0 can avoid affecting the overall semantic conflict information.

[0114] Again, perform row-wise maximum pooling on the score matrix W, and use the softmax function to normalize the pooled score matrix to obtain the feature score matrix a. The specific calculation process is shown in equations (3.11) and (3.12):

[0115]

[0116] a=(a1,a2,...a n-h+1 ) (3.12)

[0117] After performing the row max pooling operation on the score matrix W, the model can find the value with the largest semantic conflict for the current phrase. The larger this value is, the greater the possibility that the text sequence contains ironic semantic conflict.

[0118] Finally, the attention score a i The weighted summation of the corresponding phrase features is performed to obtain the ironic semantic representation of the text sequence. a , f a ∈R k , the specific calculation process is shown in formula (3.13):

[0119]

[0120] The calculation process of the semantic conflict score of the entire irony semantic relationship modeling module is as follows: Figure 7 shown.

[0121] 1.2.4 Irony Intention Identification Module

[0122] Where J is the cost function, y i ' is the prediction result of our model for sample i, y i is the true label of sample i. N is the size of the training data. R is the standard L2 regularization, and λ is the weight of R.

[0123] The irony discriminant layer consists of a linear layer and a softmax classification layer. The purpose of the linear layer is to reduce the feature representation f of the irony semantics. a The purpose of the softmax layer is to predict the output of the linear layer and determine whether the text sequence contains ironic rhetoric. The specific process is shown in formula (3.14):

[0124]

[0125] in is the classification result of the model, W∈R k*2 ,b∈R 2 are the parameters of the linear layer, which are learned continuously as the model is trained.

[0126] The model is optimized using the cross entropy loss function during training. The loss function is defined as shown in formula (3.15):

[0127]

[0128] in is the model's predicted label for sample i, y i is the true label of the sample, N is the size of the training data, and R is the standard L2 regularization.

[0129] 1.3 Summary

[0130] This chapter introduces the irony recognition model based on convolutional neural network and attention mechanism proposed in this paper in detail. First, the introduction introduces some shortcomings of the existing irony recognition model and the improvements made in this model; secondly, the overall structure of this model is briefly summarized; finally, each part of the model is introduced in detail, including the text representation layer based on BERT, the semantic feature extraction layer based on CNN and Attention, the irony semantic relationship modeling layer, and the irony intention discrimination layer.

Claims

1. An irony recognition model based on convolutional neural network and attention mechanism, characterized in that: include: S1. Text representation layer: used to generate word vectors through the pre-trained language model BERT; S2. Semantic feature extraction layer: It is used to extract semantic features by implicitly segmenting sentences into phrases using the text convolutional neural network (CNN) layer. It assists the model in capturing features related to the irony task through the Attention layer mechanism, assigns different weight scores according to the importance of the features, and re-weights the features and weights. S3. Irony semantic relationship modeling layer: by modeling the semantic joint information between the semantic features within the sentence, the semantic conflict information within the sentence is captured; S4. Irony intention discrimination layer: The feature dimension of irony semantics is reduced through the linear layer, and the output of the linear layer is predicted through the softmax layer to determine whether the text sequence contains irony rhetoric; The model takes the input text sequence S through the text representation layer, adds segmentation tags, converts, and trains to obtain the word vector representation matrix E of the text sequence; The word vector representation matrix E is used as the input of the semantic feature extraction layer, and the convolution operation is used to extract features, and the obtained single phrase fragment features are spliced ​​into a feature matrix M; the importance of different semantic features of the matrix M is analyzed through the attention network, and corresponding weights are assigned to them. Finally, the weights and features are re-weighted and combined to obtain the final semantic feature V; The semantic feature V is used as the input of the ironic semantic relationship modeling layer. The ironic semantic representation f of the text sequence is obtained by modeling, pooling, and weighted summation of semantic joint information. a ; Ironic semantic representation of text sequences a As the input of the irony discriminant layer, the feature representation f of irony semantics is reduced through a linear layer a The softmax layer predicts the output of the linear layer to determine whether the text sequence contains irony and obtain the classification result of the model. In the text representation layer: the pre-trained language model BERT is used to train ironic texts under different context information to obtain word embedding representations containing context information; The steps to use the pre-trained language model BERT are as follows: First, define the input text sequence S, S = {s1, s2, ...s i ...,s n }, its i represents the i-th word in the text sequence, and n represents the number of words contained in the text sequence; Secondly, add "[CLS]" and "[SEP]" segmentation markers at the beginning and end of the text sequence respectively to convert the text sequence into a specific format that can be processed by the BERT model; Finally, the processed text sequence is sent to the BERT model for training to obtain the word vector representation matrix E of the text sequence. The specific process is as shown in Formula 3.1: E=BERT("[CLS]”+s1,s2,s3,...s i ...s n +"[SEP]”)(3.1) Where E = {e1, e2, e3...e i ...,e n },e i ∈R k Represents the word vector representation of the i-th word in the text sequence, and k represents the dimension of the word vector; The CNN layer feature extraction step includes: (1) Two-dimensional word embedding matrix of input text sequence; (2) Use different convolution kernels to continuously perform convolution operations with the word vector matrix to extract the feature graph of the text sequence; (3) Use the maximum pooling method to process feature maps of different sizes to obtain a single feature of fixed length; (4) Concatenate all single features into a simple feature vector; The process is as follows: First, input the two-dimensional word vector matrix E of the text sequence, E = {e1, e2, e3...e i ...,e n }, where n represents the number of words contained in the text sequence, e i ∈R k Represents the word vector representation of the i-th word in the text sequence, and k is the dimension of the word vector; Secondly, the two-dimensional word vector matrix E is input into the convolution module, and the features of the phrase fragments are extracted by convolution operation between the convolution kernel and the text sequence in the convolution window. The size of the convolution kernel W is defined as h*k, where h represents the size of the convolution kernel window, which determines the number of words contained in the phrase fragment. The feature extraction process of the phrase fragment can be expressed as follows: c i =f(W·E i:i+h-1 +b)(3.2) Here we define a convolution function operation f, c i represents the phrase features extracted after the convolution kernel W is convolved with the phrase fragment consisting of the i-th word to the i+h-1-th word in the word vector matrix E, and b is the bias; Again, after the convolution kernel W completes the convolution operation with the entire word vector matrix E from top to bottom, a single feature map c of all phrase fragments in the text sequence is obtained, c = (c1, c2, c3, ... c i ...,c n-h+1 ); Finally, use k convolution kernels with the same size as W to repeat the above operation, and concatenate the obtained feature maps to obtain the semantic feature matrix M∈R of the phrase fragment (n-h+1)*k ,M=(m1,m2,m3,...m i ...,m n-h+1 ), where m i ∈R k Represents the semantic feature representation of the i-th phrase fragment in the text sequence; The attention layer strengthens the key semantic features by assigning weight scores to different semantic features. The steps are as follows: First, the semantic features m extracted from the feature extraction layer are i Input into a linear layer, and then the tanh function processes its result to obtain the hidden layer feature representation m of the i-th phrase i ', where b is the bias, the specific process can be expressed as shown in formula (3.3): m i '=tanh(W·m i +b)(3.3) Secondly, according to the semantic feature m i 'The similarity with the context vector q is used to calculate the semantic feature m i 'The weight score s i , and then use the softmax function to normalize the weight scores of all features to obtain the final weight matrix a. The specific calculation process is as shown in formulas 3.4, 3.5, and 3.6: <h2 style=";text-align:left;direction:ltr">a=Softmax(s1,s2,s3,...,s<h2 style=";text-align:left;direction:ltr"> n-h+1 <h2 style=";text-align:left;direction:ltr"> (3.5) <h2 style=";text-align:left;direction:ltr">a = (a1,a2,a3,...,a)<h2 style=";text-align:left;direction:ltr"> n-h+1 <h2 style=";text-align:left;direction:ltr"> (3.6) Finally, the weight score a i With semantic feature m i The final semantic feature V is obtained by associating them. The specific calculation method is as shown in formulas 3.7 and 3.8: in i =a i *m i (3.7) V=(v1,v2,v3,...,v n-h+1 ),V∈R (n-h+1)*k (3.8)。 2. The irony recognition model based on convolutional neural network and attention mechanism according to claim 1, characterized in that: The pre-trained language model BERT includes a token embedding model TokenEmbedding, a position embedding model PositionEmbedding, and a segmentation embedding model SegmentEmbedding.

Citation Information

Patent Citations

  • Cross-language plain text inverse recognition method based on internal attention

    CN110134962A

  • Condition fusion-based multi-mode phage detection method

    CN113535894A