Novel irony detection method and system based on comparative learning and modal mutual assistance
Through contrastive learning and modal mutual assistance technology, the problem of difficult integration of visual and language features in multi-modal sarcasm detection is solved, efficient multi-modal feature extraction and sarcastic signal capture are achieved, and detection accuracy and generalization capabilities are significantly improved. .
Patent Information
- Application Number
- CN202410740135.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-07
- Publication Date
- 2024-09-13
AI Technical Summary
There are differences in the integration of visual and language features among existing multi-modal sarcasm detection methods. It is difficult for traditional visual feature extractors to effectively extract emotional information, and the feature correlation between modalities is insufficient, resulting in poor multi-modal information integration capabilities.
Using methods based on contrastive learning and modal mutual assistance, image and text features are extracted through Vision Transformer and Text Transformer respectively, and aligned multi-modal feature representations are generated through multi-modal mutual assistance layer and similarity contrastive learning, combined with data enhancement technology Improve model generalization ability.
Significantly improves the accuracy and generalization ability of sarcasm detection, can capture multi-modal signals more effectively, reduce the impact of modal emotional inconsistency, enhance the clarity of model decision boundaries, and show higher accuracy in practical applications performance and robustness.
Smart Images

Figure CN118643369A
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of multimodal sarcasm detection, and in particular relates to a novel sarcasm detection method and system based on contrastive learning and modal mutual assistance. Background Art
[0002] Multimodal sarcasm detection (MSD) plays a key role in understanding sentiment expressions in social media, especially in areas such as election prediction and product evaluation. However, despite a large amount of work devoted to the development of MSD models, previous research rarely considers the feature correlation between modalities, and few studies consider the inherent differences between vision and language, which leads to poor multimodal information integration capabilities.
[0003] Through the above analysis, the problems and defects of the prior art are as follows:
[0004] (1) Inherent differences between vision and language: Most existing MSDs use unimodal encoders to extract features from images and texts respectively. Separately pre-trained unimodal models to extract visual and text features usually lack the basic alignment capabilities required for effective multimodal data integration, making it challenging to fully integrate multimodal information only through different cross-modal fusion techniques.
[0005] (2) Disadvantages of traditional visual feature extractors: When images contain text information, traditional visual feature extractors may not be able to effectively extract emotional information from visual information. In this case, a visual feature extractor with powerful OCR information extraction capabilities is needed to process images in various fields.
[0006] (3) Feature correlation between modalities: After solving the first two defects, considering that the emotions expressed by the text and images of satirical data are different, the traditional modal fusion strategy cannot be directly applied here. At this time, a targeted cross-modal interaction strategy is needed. Summary of the invention
[0007] In view of the problems existing in the prior art, the present invention provides a novel sarcasm detection method and system based on contrastive learning and modal mutual assistance.
[0008] The present invention is implemented as follows: a novel sarcasm detection method based on contrastive learning and modality mutual assistance, comprising:
[0009] Step 1: Extract text image features by applying the Vision Transformer model and the TextTransformer text encoder to obtain image and text representations respectively;
[0010] Step 2: Cross-modal cooperation: introduce the obtained image and text features for information exchange to obtain multimodal feature representation;
[0011] Step 3: Similarity-based comparative learning allows the model to learn relevant features in multimodal data;
[0012] Step 4: Based on the contrastive learning of enhanced data, a variety of data enhancement techniques are applied to generate enhanced samples. The model learns more essential and generalized animal features by comparing the similarities between the enhanced samples and the original samples.
[0013] Step 5: Model training and classification to obtain sarcasm detection results.
[0014] Furthermore, in step 1, for multimodal satirical data, image embedding is obtained by utilizing the pre-trained VisionTransformer model from CLIP and applying it to the image embedding of the input image. The vit model used is composed of 24 layers of 16-head visual transformers, and its weights are kept frozen after pre-training; for the acquisition of text representation, the Text Transformer text encoder is directly used to derive the corresponding text representation; trainable projection layers are introduced at the output of the CLIP image and text encoders, which map the unimodal image and text features v and t to their corresponding image projections, respectively. and text projection Achieve better alignment between text and image spaces.
[0015] Further, the step 2 includes:
[0016] Step 2.1 introduces the obtained image and text features, which are transmitted through the designed multimodal mutual assistance layer, which contains a modality-specific feature separator to connect the fusion pipeline of the image and text. The module adopts a single-layer design; the discriminator loss is used as a regularization method, and a specially designed similarity contrast loss function is introduced and integrated into the total loss by adding a geometric metric or a distribution similarity metric based on the hidden dimension as a regularization term to the total loss; the modality mutual assistance module is stacked into two pipelines to form a symmetrical structure. The present invention refers to the modality that continues to advance in the same fusion pipeline in the same mutual assistance module as the main modality, which is denoted by X main , and the modality added to the dual-modal fusion in one pipeline but derived from another pipeline as an external modality is called other modality, denoted by X other ;
[0017] Step 2.2 The cross-modal fusion process mainly occurs in the multi-head attention operation. The multi-head attention part in the modal mutual assistance module is composed of two identical Transformer encoders, which respectively form the visual and text encoder modules. At the same time, the visual and text features in the previous layer are utilized. The visual and text streams use their own and from the other side and vector, and vice versa, so if main is other The corresponding Q, K, and V matrices can be obtained as follows:
[0018]
[0019] Step 2.3 uses the calculated feature vector to calculate the attention weight between the two modalities, and uses the corresponding Q, K, and V to calculate an attention weight matrix. This weight matrix can be used to represent the correlation between the two modalities:
[0020]
[0021] The calculation process of the multi-head self-attention mechanism can be expressed as:
[0022] MultiHead(Q,K,V)=Concat(head1,…,head h )W O (5)
[0023]
[0024] in represents the parameter matrix of the i-th head, W O Represents a parameter matrix for output. The present invention uses a residual connection after each multi-head attention layer to add the original feature representation of the modality to the output of the multi-head attention layer, and uses layer normalization after each self-attention layer to normalize the output;
[0025] Step 2.3 uses a feed-forward fully connected layer to further process the representation. This layer contains two linear transformations and a nonlinear activation function. The activation function selects the ReLU function, and the final result is connected with residual connection and layer normalization. Finally, the correlation relationship X between the two modal features is obtained. v2t and X t2v , use a simple FC layer to obtain the multimodal representation R:
[0026] X v2t =MultiHead(Q v ,Kt ,V t ) (7)
[0027] X t2v =MultiHead(Q t ,K v ,V v ) (8)
[0028] R = W2·ReLU(W1·concat(X v2t ,X t2v )+b1)+b2 (9)
[0029] Further, the step three includes:
[0030] Step 3.1 In order to make the model learn the relevant features in multimodal data, this loss function is designed. Since the image feature X obtained by MCM t2v and text feature X v2t Already closely aligned, the present invention uses it as the input of formula (10). In order to maximize the similarity between positive samples and minimize the similarity between negative samples, the present invention uses the Euclidean distance to measure the similarity between the mapped image and text features:
[0031]
[0032] Step 3.2 further enhances the model's ability to learn to distinguish between positive and negative samples by constructing a similarity matrix and comparing the diagonal elements (i.e., the similarity between itself and itself, representing positive sample pairs) with other elements in the matrix (representing negative sample pairs). Here, we calculate v e to e The similarity comparison learning loss is calculated by e to v e Otherwise:
[0033]
[0034] The two losses obtained in step 3.3 will be balanced by a weight value λ as shown in formula (12):
[0035]
[0036] Furthermore, in step four, taking the picture classification model as an example, due to the diverse expressions of the image, it is easy for the model to learn surface features. At this time, if contrastive learning based on data enhancement is adopted, the present invention can apply a variety of data enhancement techniques to the image of each animal, such as rotation, scaling, cropping, color transformation, etc., to generate multiple visually different but semantically identical samples; then, the model learns more essential and generalized animal features by comparing the similarities between these enhanced samples and the original samples, rather than accidental features or noise in the image.
[0037] Furthermore, in step five, the multimodal representation R is fed to the fully connected layer, and the softmax function is used for emotion detection. The present invention uses cross entropy loss as the classification loss, as shown below:
[0038] L SDR =Cross-Entropy(GELU(RW SDR +b SDR )) (13)
[0039] The data augmentation-based contrastive loss and the similarity-based contrastive learning loss can be simply added to the total loss as regularization and can be combined as follows:
[0040] L=L SDR +λ SCL L SCL +λ DACL L DACL (14)
[0041] where λ SCL and λ DACL is a coefficient used to balance different training losses.
[0042] Another object of the present invention is to provide a novel sarcasm detection system based on contrastive learning and modal mutual assistance, the novel sarcasm detection system based on contrastive learning and modal mutual assistance comprising:
[0043] An image encoder, for obtaining an image representation;
[0044] Text encoder, used to obtain text representation;
[0045] The modality mutual assistance module is used to exchange information between the obtained image and text features to obtain multimodal feature representation;
[0046] Similarity comparison learning module, used for comparison learning based on similarity;
[0047] Data enhancement module, used to apply various data enhancement techniques to generate enhanced samples;
[0048] The output module is used to output the sarcasm detection results.
[0049] Another object of the present invention is to provide a computer device, comprising a memory and a processor, wherein the memory stores a computer program, and when the computer program is executed by the processor, the processor executes the steps of the novel sarcasm detection method based on contrastive learning and modal mutual assistance.
[0050] Another object of the present invention is to provide a computer-readable storage medium storing a computer program, which, when executed by a processor, enables the processor to perform the steps of the novel sarcasm detection method based on contrastive learning and modal mutual assistance.
[0051] Another object of the present invention is to provide an information data processing terminal, which is used to implement the novel sarcasm detection system based on contrastive learning and modal mutual assistance.
[0052] In combination with the above technical solutions and the technical problems solved, the advantages and positive effects of the technical solutions to be protected by the present invention are as follows:
[0053] First, in view of the technical problems existing in the above-mentioned prior art, some creative technical effects are brought about after solving the problems. The specific description is as follows:
[0054] (1) The present invention designs a sarcasm detection method in a multimodal scenario. By using the CLIP model, it can efficiently extract OCR information of image features and generate aligned image and text features.
[0055] (2) The present invention adopts a contrastive learning method to reduce the impact caused by modal sentiment inconsistency, and combines a modal mutual assistance module to achieve effective cross-modal interaction, making the decision boundary of the model clearer.
[0056] (3) The effectiveness of the detection method was evaluated on the HFM dataset. The experimental results show that the method not only significantly improves the detection accuracy, but also achieves good results in the interpretability test.
[0057] Second, the novel sarcasm detection method based on contrastive learning and modal mutual assistance provided by the present invention solves the technical problems and achieves technical progress mainly in the following aspects:
[0058] Existing technical problems solved:
[0059] 1) Limitations of a single modality: Traditional sarcasm detection methods usually rely only on text information, ignoring information from other modalities such as images and videos. However, sarcastic expressions often involve interactions in multiple modalities, and single-modality detection methods are difficult to fully capture sarcastic signals.
[0060] 2) Understanding of complex contexts: Sarcastic language usually carries complex contexts and emotions, which requires in-depth understanding of the deeper meaning of text and images. Traditional rule-based or statistical methods often have difficulty accurately understanding these complex contexts.
[0061] 3) Generalization ability: Existing sarcasm detection methods may perform well on specific datasets, but have poor generalization ability in other datasets or real application scenarios, and are difficult to adapt to diverse sarcastic expressions.
[0062] Technological progress achieved:
[0063] 1) Multimodal feature fusion: The Vision Transformer model and the Text Transformer text encoder are used to extract image and text features respectively, and a cross-modal mutual assistance mechanism is introduced to achieve effective fusion of image and text features. This multimodal feature representation can capture sarcasm signals more comprehensively and improve detection accuracy.
[0064] 2) Feature learning based on contrastive learning: A similarity-based contrastive learning method is used to allow the model to learn relevant features in multimodal data. By comparing the similarities between the original samples and the enhanced samples, the model can learn more essential and generalized ironic features and improve generalization ability.
[0065] 3) Data enhancement technology: A variety of data enhancement technologies are applied to generate enhanced samples, which increases the diversity and richness of training data. This helps the model better cope with various complex sarcastic expressions and improves the robustness of detection.
[0066] 4) Model training and classification: After sufficient training and optimization, the model can accurately identify sarcastic text and images and give corresponding classification results. This sarcasm detection method based on contrastive learning and modality mutual assistance performs well in practical applications and has high accuracy and generalization ability.
[0067] In summary, this new sarcasm detection method based on contrastive learning and modal mutual assistance effectively solves the problems existing in traditional sarcasm detection methods by integrating multimodal features, adopting contrastive learning methods and data enhancement technology, improves the detection accuracy and generalization ability, and brings new technological progress to the field of sarcasm detection.
[0068] Third, as auxiliary evidence of the inventiveness of the claims of the present invention, it is also reflected in the following important aspects:
[0069] (1) The present invention can reduce misunderstandings and disputes by timely identifying and processing tweets containing sarcastic content, creating a more harmonious social media environment, and thus improving user satisfaction and platform stickiness. At the same time, accurate detection and analysis of sarcastic tweets can help to better understand user emotions and feedback, optimize advertising strategies, and increase the click-through rate and conversion rate of ads. This not only improves the user experience, but also enhances the advertising effect, and ultimately promotes the overall development of the platform.
[0070] (2) The present invention uses an innovative multimodal sarcasm detection method to achieve efficient extraction and fusion of image and text features, significantly improving the accuracy and generalization ability of detection. The Vision Transformer and TextTransformer models, as well as contrastive learning and modal mutual assistance mechanisms, effectively address the challenges of traditional methods in modal feature correlation and information consistency. Experimental results show that the present invention has excellent accuracy and interpretability on the HFM dataset, overcoming the limitations of single modality detection methods and demonstrating its great potential and broad prospects in practical applications. BRIEF DESCRIPTION OF THE DRAWINGS
[0071] Figure 1 The novel sarcasm detection method based on contrastive learning and modal mutual assistance provided by the embodiment of the present invention is as follows: Figure 1 ;
[0072] Figure 2 The novel sarcasm detection method based on contrastive learning and modal mutual assistance provided by the embodiment of the present invention is as follows: Figure 2 ;
[0073] Figure 3 is a schematic diagram of irony detection provided by an embodiment of the present invention;
[0074] Figure 4 is a schematic diagram of a modal mutual assistance module (MCM) provided in an embodiment of the present invention;
[0075] Figure 5 Schematic diagram of multi-head attention in the modal mutual assistance module provided by an embodiment of the present invention;
[0076] Figure 6 is a flow chart of a DACL algorithm provided by an embodiment of the present invention;
[0077] Figure 7 This is the specific training process of CLMCM provided by the embodiment of the present invention;
[0078] Figure 8 This is a diagram of the architecture of a novel sarcasm detection system based on contrastive learning and modal mutual assistance provided by an embodiment of the present invention;
[0079] Fig. 9 is a model training parameter provided by an embodiment of the present invention;
[0080] Fig.10 This is a performance comparison of different models provided by the embodiments of the present invention in multimodal sarcasm detection. DETAILED DESCRIPTION
[0081] In order to make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention.
[0082] like Figure 1 , Figure 2 As shown, the novel sarcasm detection method based on contrastive learning and modality mutual assistance provided by the embodiment of the present invention includes the following steps:
[0083] S101, text image feature extraction, applying the Vision Transformer model and the TextTransformer text encoder to obtain image and text representations respectively;
[0084] S102, cross-modal mutual assistance (MCM), introduces the obtained image and text features for information exchange and obtains multimodal feature representation;
[0085] S103, similarity-based contrastive learning, allows the model to learn relevant features in multimodal data;
[0086] S104, based on contrastive learning of enhanced data, applies a variety of data enhancement techniques to generate enhanced samples. The model learns more essential and generalized animal features by comparing the similarities between enhanced samples and original samples;
[0087] S105, model training and classification, obtaining sarcasm detection results.
[0088] The novel sarcasm detection method based on contrastive learning and modality mutual assistance provided by the embodiment of the present invention specifically includes the following five steps:
[0089] 1) Text image feature extraction:
[0090] Use the Vision Transformer model to extract image features.
[0091] Use the Text Transformer text encoder to extract text features.
[0092] The representations of images and texts are obtained through these two models respectively.
[0093] 2) Cross-modal Mutual Assistance (MCM):
[0094] The extracted image and text features are introduced for information exchange.
[0095] Obtain multimodal feature representation containing image and text information to enhance the richness and diversity of features.
[0096] 3) Similarity-based contrastive learning:
[0097] Through contrastive learning methods, the model can learn relevant features in multimodal data.
[0098] Similarity-based contrastive learning enables the model to better understand and capture the correlations and differences between data of different modalities.
[0099] 4) Contrastive learning based on enhanced data:
[0100] Apply various data augmentation techniques to generate enhanced samples.
[0101] The model learns more essential and generalized features by comparing the similarities between the enhanced samples and the original samples.
[0102] Data augmentation techniques include rotation, flipping, scaling, etc. to improve the robustness and generalization ability of the model.
[0103] 5) Model training and classification:
[0104] The multimodal features obtained in the above steps are input into the model for training.
[0105] During the training process, the model parameters are continuously optimized using contrastive learning.
[0106] Finally, the sarcasm detection result of the model is obtained, and the sarcasm detection is performed on the input multimodal data through the classifier.
[0107] Detailed working principle:
[0108] 1) Feature extraction:
[0109] Vision Transformer model: It is a model based on the Transformer architecture. It divides the image into fixed-size image blocks and linearly transforms the pixel values of these blocks to generate embedded representations of the image blocks. These embedded representations are then input into the Transformer encoder to extract the global features of the image.
[0110] Text Transformer Text Encoder: By segmenting the text and converting it into an embedded representation, the Transformer encoder is used to extract the contextual features of the text.
[0111] 2) MCM:
[0112] The features of images and texts are exchanged through a cross-modal attention mechanism to achieve complementarity between modalities.
[0113] This information exchange mechanism can capture the correlation features between images and texts and enhance the representation capability of multimodal features.
[0114] 3) Similarity-based contrastive learning:
[0115] Contrastive learning optimizes the model by constructing positive and negative sample pairs and using similarity metrics (such as cosine similarity).
[0116] The model improves the discriminative ability of multimodal features by learning high similarity between similar sample pairs and low similarity between dissimilar sample pairs.
[0117] 4) Contrastive learning based on enhanced data:
[0118] The enhanced samples generated by data augmentation technology allow the model to learn data features from different perspectives.
[0119] By comparing the feature similarities between the original samples and the enhanced samples, the model can capture the essential characteristics of the data, thereby improving the ability to detect sarcasm.
[0120] 5) Model training and classification:
[0121] Combining the above feature extraction and contrastive learning steps, the model continuously optimizes parameters during the training process.
[0122] Finally, the trained model is used to perform sarcasm detection on the input multimodal data and output the detection results.
[0123] This method combines the advantages of contrastive learning and modality mutual assistance, which can better capture the deep features in multimodal data and improve the accuracy and robustness of sarcasm detection.
[0124] Sarcasm detection diagram Figure 3 shown.
[0125] Step 1 provided in an embodiment of the present invention is to obtain image embedding for multimodal satirical data by using a pre-trained Vision Transformer (vit) model from CLIP (a model trained on a large number of image-text pairs using contrastive learning) and applying it to the image embedding of the input image. The vit model used is composed of 24 layers of 16-head visual transformers, and its weights are kept frozen after pre-training. For the acquisition of text representation, the TextTransformer text encoder is directly used to derive the corresponding text representation, and in order to more effectively capture the semantic connection between the image and text feature spaces, the present invention introduces trainable projection layers at the output of the CLIP image and text encoders, which map the unimodal image and text features v and t to their corresponding image projections, respectively. and text projection The goal is to achieve better alignment between text and image spaces, rather than just having text and image embeddings have the same dimensionality.
[0126] like Figure 4 As shown, step 2 provided in the embodiment of the present invention includes:
[0127] Step 2.1 introduces the obtained image and text features, which are transmitted through the designed multimodal mutual assistance layer, which contains modality-specific feature separators to connect the image and text fusion pipeline. This mechanism is intended to "supplement" key clues that may be missed during the transmission process of images and text. Different from the traditional multi-layer stacking method, the module of the present invention adopts a single-layer design to simplify and improve the efficiency of the iterative fusion process.
[0128] In order to ensure the independence between image and text modalities, the present invention uses discriminator loss as a regularization method. This regularization effect helps to distinguish the hidden layer representation from the representation of other modalities in the same mutual assistance module. According to the suggestions of previous studies, the present invention adds geometric metrics or distribution similarity metrics based on hidden dimensions as regularization terms to the total loss. However, here the present invention introduces a specially designed similarity contrast loss function and integrates it into the total loss. In short, the present invention uses a similarity-based contrastive learning task to help the model extract the similarity between modalities and quantify it using Euclidean distance. At the same time, the modality mutual assistance module will fuse text and image data. The loss function of the present invention will be specifically introduced in the optimization process based on contrastive learning. This strategy of combining discriminator loss and carefully designed similarity loss effectively improves the accuracy and robustness of the model when processing image and text modalities, and is also in line with the design concept of the overall model architecture of the present invention. Specifically, the modality mutual assistance module is stacked into two pipelines to form a symmetrical structure. For the convenience of explanation, the present invention refers to the modality that continues to advance in the same fusion pipeline in the same mutual assistance module as the main modality, denoted by X main , and the modality added to the dual-modal fusion in one pipeline but derived from another pipeline as an external modality is called other modality, denoted by X other It should be noted that distinguishing between the main mode and other modes is only meaningful in a specific pipeline.
[0129] Step 2.2 The cross-modal fusion process mainly occurs in the multi-head attention operation. Figure 5 As shown in the figure, the multi-head attention part in the modality mutual assistance module is composed of two identical Transformer encoders, which respectively form the visual and text encoder modules. At the same time, the visual and text features in the previous layer are utilized. The visual and text streams use their own Q main =W q X i main And V from the other side other =W v X i other and K other =W k X i other vector, and vice versa. So if main is X i v ,other is Xi t, we can get the corresponding Q, K, and V matrices as follows, where Q, K, and V represent Query, Key, and Value, respectively. They are the core components used for the self-attention mechanism. Specifically, the relevance is calculated through Query and Key, and the attention score is used to represent the relevance of each position in the input sequence to the current query position. Then, a softmax operation is performed on the attention score to obtain the attention weight, which represents the importance of each position in the input sequence to the current query position. Finally, these attention weights are used to perform a weighted summation on the Value to capture the dependencies and related information between different positions in the input sequence:
[0130]
[0131] Step 2.3 then uses the calculated feature vector to calculate the attention weight between the two modalities. Specifically, the corresponding Q, K, and V are used to calculate an attention weight matrix Attention. This weight matrix can be used to represent the correlation between the two modalities. The role of softmax is to normalize the dot product results of each Q and all K in the Attention mechanism and convert them into probability distribution.
[0132]
[0133] The multi-head self-attention mechanism can be understood as dividing the model into multiple heads to form multiple subspaces. Each subspace focuses on different aspects of information. Each subspace will independently execute the attention function to obtain the output value head. i , use Concat to concatenate these values and perform linear transformation to get the final multi-head attention value MultiHead. Its calculation process can be expressed as:
[0134] MultiHead(Q,K,V)=Concat(head1,…,head h )W O (5)
[0135]
[0136] in represents the parameter matrix of the i-th head, W O Represents the parameter matrix for output.
[0137] In order to improve the stability of the model, the present invention uses residual connection after each multi-head attention layer to add the original feature representation of the modality to the output of the multi-head attention layer, which can ensure that the model does not lose the original information during the information transmission process, and uses layer normalization after each self-attention layer to standardize the output. Layer normalization can make the model easier to learn and avoid the problem of gradient disappearance or explosion.
[0138] Step 2.3 Finally, the present invention uses a feed-forward fully connected layer to further process the representation. This layer contains two linear transformations and a nonlinear activation function. The activation function selects the ReLU function (full name: RectifiedLinearUnit, which is an activation function widely used in artificial neural networks). The feed-forward fully connected layer can increase the nonlinear ability of the model, so that it can model complex sequence data. The final result is treated with residual connection and layer normalization, and finally the correlation relationship X between the two modal features is obtained. v2t and X t2v .
[0139] X v2t =MultiHead(Q v ,K t ,V t ) (7)
[0140] X t2v =MultiHead(Q t ,K v ,V v ) (8)
[0141] R = W2·ReLU(W1·concat(X v2t ,X t2v )+b1)+b2 (9)
[0142] According to the previous step, the present invention obtains the sequence features of text and image fusion, but it is obvious that the two sequence features cannot be used for classification tasks. Therefore, the present invention uses a simple fully connected layer (FC layer) to obtain the multimodal representation R. Specifically, first use concat to convert X v2t and X t2v The two eigenvectors are concatenated to form a new joint eigenvector. W and b represent the weight matrix and bias vector respectively. The linear transformation result is added to the bias vector to obtain the output of the first layer, and the ReLU activation function is applied to the output of the first layer to introduce nonlinearity. Then the linear transformation result is added to the bias vector again to obtain the final output R.
[0143] Step three provided in the embodiment of the present invention includes:
[0144] Step 3.1 In order to make the model learn the relevant features in multimodal data, this loss function is designed. Since the image feature X obtained by the modal mutual assistance module t2v and text feature X v2t Already closely aligned, so here the present invention uses it as the input of formula (10). In order to maximize the similarity between positive samples and minimize the similarity between negative samples, the present invention uses the Euclidean distance to measure the similarity ED_SIM between the mapped image and text features, where exp is used to calculate the exponential with e as the base.
[0145]
[0146] Step 3.2 Next, as shown in formula (11), the present invention uses diag to construct a similarity matrix and compares the diagonal elements (i.e., the similarity between itself and itself, representing the positive sample pairs) with other elements in the matrix (representing the negative sample pairs), thereby further enhancing the model's ability to learn to distinguish between positive and negative samples. Here, we calculate v e to e The similarity comparison learning loss is calculated by e to v e And vice versa.
[0147]
[0148] Step 3.3 Finally, the present invention balances the two losses obtained with a weight value λ to obtain the similarity-based contrastive learning loss L SCL , as shown in formula (12):
[0149]
[0150] Step four provided in an embodiment of the present invention, in order to improve the robustness of the model and better help the model learn the intrinsic structure and characteristics of the data, the present invention adds a comparative learning task based on data enhancement. Here, the present invention takes the image classification model as an example. Due to the diverse expressions of images, it is easy for the model to learn surface features. At this time, if comparative learning based on data enhancement is adopted, the present invention can apply a variety of data enhancement techniques to the image of each animal, such as rotation, scaling, cropping, color transformation, etc., to generate multiple visually different but semantically identical samples. Then, by comparing the similarities between these enhanced samples and the original samples, the model learns more essential and generalized animal features, rather than accidental features or noise in the image. For specific steps, please refer to Figure 6The meanings of the specific functions in the algorithm are as follows: einsum represents the Einstein summation convention, arange is used to generate an integer sequence of batch_size length as the contrastive learning label, and τ represents the temperature of contrastive learning. The algorithm mainly includes three steps: The first step is to input the original data and enhanced data into MCM to obtain the fusion features R and R aug ; The second step is to calculate R and R aug The similarity between them is obtained by the similarity matrix M sim Finally, the similarity matrix M is calculated using sim The cross entropy loss between the label cl_label obtained by arange is used to obtain the data enhancement contrast learning loss L DACL .
[0151] Step 5 provided in the embodiment of the present invention is as follows: Figure 7 As shown, the present invention feeds the above multimodal representation R to the fully connected layer and uses the softmax function for emotion detection. Here, GELU is used as the activation function, and the present invention uses the cross-entropy loss Cross-Entropy to calculate the classification loss L SDR , as shown below:
[0152] L SDR =Cross-Entropy(GELU(RW SDR +b SDR )) (13)
[0153] Data augmentation-based contrastive loss and similarity-based contrastive learning loss can be simply added to the total loss as regularization. They can be combined as follows:
[0154] L=L SDR +λ SCL L SCL +λ DACL L DACL (14)
[0155] where λ SCL and λ DACL is a coefficient used to balance different training losses.
[0156] like Figure 8 As shown, the novel sarcasm detection system based on contrastive learning and modality mutual assistance provided by the embodiment of the present invention includes:
[0157] An image encoder, for obtaining an image representation;
[0158] Text encoder, used to obtain text representation;
[0159] The modality mutual assistance module is used to exchange information between the obtained image and text features to obtain multimodal feature representation;
[0160] Similarity comparison learning module, used for comparison learning based on similarity;
[0161] Data enhancement module, used to apply various data enhancement techniques to generate enhanced samples;
[0162] The output module is used to output the sarcasm detection results.
[0163] 2. Application Examples: In order to prove the creativity and technical value of the technical solution of the present invention, this section provides application examples of the technical solution of the claims on specific products or related technologies.
[0164] The novel sarcasm detection method based on contrastive learning and modal mutual assistance provided by the application embodiment of the present invention is applied to a computer device, wherein the computer device includes a memory and a processor, wherein the memory stores a computer program, and when the computer program is executed by the processor, the processor executes the steps of the novel sarcasm detection method based on contrastive learning and modal mutual assistance.
[0165] The novel sarcasm detection method based on contrastive learning and modal mutual assistance provided by the application embodiment of the present invention is applied to an information data processing terminal, and the information data processing terminal is used to implement the novel sarcasm detection system based on contrastive learning and modal mutual assistance.
[0166] It should be noted that the embodiments of the present invention can be implemented by hardware, software, or a combination of software and hardware. The hardware part can be implemented using dedicated logic; the software part can be stored in a memory and executed by an appropriate instruction execution system, such as a microprocessor or dedicated design hardware. It can be understood by a person of ordinary skill in the art that the above-mentioned devices and methods can be implemented using computer executable instructions and / or contained in a processor control code, such as a carrier medium such as a disk, CD or DVD-ROM, a programmable memory such as a read-only memory (firmware), or a data carrier such as an optical or electronic signal carrier. Such code is provided on the carrier medium. The device and its modules of the present invention can be implemented by hardware circuits such as very large-scale integrated circuits or gate arrays, semiconductors such as logic chips, transistors, etc., or programmable hardware devices such as field programmable gate arrays, programmable logic devices, etc., can also be implemented by software executed by various types of processors, and can also be implemented by a combination of the above-mentioned hardware circuits and software, such as firmware.
[0167] 3. Evidence of the effects of the embodiments. The embodiments of the present invention have achieved some positive effects during the development or use process, and indeed have great advantages over the prior art. The following content is described in conjunction with the data, charts, etc. of the test process.
[0168] (I) Experimental data
[0169] Table 1 Dataset introduction
[0170]
[0171] The Sarcasm Detection Dataset HFM is a publicly available dataset. In order to more accurately identify the sarcasm in the data, I expanded on the previous research and used an improved method to filter the dataset to exclude words with obvious sarcasm features (e.g., sarcastic expressions or jokes). During the experiment, the present invention randomly divided the entire dataset into a training set, a validation set, and a test set with a split ratio of 8:1:1. The statistics of these datasets are shown in Table 1.
[0172] 2. Baseline Method
[0173] To verify the feasibility and effectiveness of the proposed model (CLMCM), we compare them with the following state-of-the-art methods:
[0174] Attention-CNN (AC): This method uses the pre-trained VGG 19 as the base model for fine-tuning. It consists of 16 convolutional layers and adds a custom attention layer, 4 maximum pooling layers and 3 FC layers to the output of the last convolutional layer.
[0175] VIT: This method uses the pre-trained Vision Transformer model as the image encoder to map the image to a 1024-dimensional vector, and finally uses Softmax for classification.
[0176] Word2Vec+BiGRU(WB): Use Word2Vec to extract text features, and use Softmax to classify the high-level text features obtained through BiGRU.
[0177] Glove+BiGRU(GB): Glove is used to extract text features, and Softmax is used to classify the high-level text features obtained through BiGRU.
[0178] BERT+Attention-BiLSTM(BAB): This method uses the pre-trained BERT-base-uncoded to extract dynamic word vectors containing contextual semantics.
[0179] CLIP-Text (CT): This method uses the pre-trained CLIP as the base model for fine-tuning to map the text to a 512-dimensional vector, and finally uses Softmax for classification.
[0180] ResNet+BiLSTM(BB): A pre-trained ResNet-50 model with fine-tuning to extract image features and BiLSTM to extract text features. The two extracted features are concatenated and used as input to the classification layer.
[0181] ViLBERT (VB): A co-attention transformer based on the idea of BERT model is proposed to solve the pre-training problem of vision-language tasks. Here, the present invention uses ResNet-34 pre-trained model to extract image features, and uses Wec2Vec to map text to a 300-dimensional vector space as the input of the model.
[0182] Contrastive Learning and Multi-Layer Fusion (CLMLF): A multi-layer fusion module based on Transformer-Encoder is used with multi-head self-attention to better align and fuse text tags and image patches with explicit and implicit relationships. Label contrast loss and data contrast loss are added during training, which further helps to learn common features related to emotions.
[0183] Attention-based Multimodal Fusion Sarcasm Detection (AF): A multimodal fusion sarcasm detection model based on attention mechanism. The model introduces Vision Transformer to extract image features and designs a double-layer bidirectional gated recurrent unit (D-BiGRU) to extract text features. The features of the two modalities are fused into a feature vector and predicted after attention enhancement.
[0184] CMGCN: Using the description of the object as a bridge, we determine the importance of the association between the image modality object and the text modality context words, thereby building a cross-modal graph for each multimodal instance. In turn, we design a cross-modal graph convolutional network to make sense of the incongruous relationship between the modalities for multimodal sarcasm detection.
[0185] MCEF: A novel bipolar semantic attention mechanism to reveal the inconsistency between different modal features. In addition, from a new perspective, based on the design of decision-level fusion strategy, multi-channel fusion is achieved, and a Multi-Channel Enhanced Fusion (MCEF) model is designed for cross-modal sarcasm detection to maximize the information extraction between different modalities.
[0186] (III) Experimental setup
[0187] Pre-trained model: In the pre-trained model named vit-B / 32, the present invention uses text encoders named visual converter and text converter to extract features of text and images.
[0188] Parameters: For experimental parameters, see Fig. 9 . Among them, the present invention sets the network structure of the FC layer in the modal mutual assistance module to 1024 (tanh)-512 (tanh), and tanh is used as the activation function here. During the training process, the stochastic gradient descent method (adamw) is used to solve the objective function, with a learning rate of 0.0001 and a momentum of 0.9. In order to reduce overfitting during the training process, the present invention uses the Dropout technology with a regularization rate of 0.1 in the attention layer.
[0189] Other experimental details: During the training process, formula (14) converts λ DACL Set to 0.7 and λ SCL Set to 1.0. After 11 epochs, the present invention obtains the checkpoint model with the highest classification accuracy on the test set, which is trained on RTX4060Ti using Keras framework and pytorch as the backend.
[0190] (IV) Experimental results and analysis
[0191] This paper verifies the superiority of the proposed model through a series of experiments. In order to comprehensively evaluate the performance of the model, this paper selects three key indicators: recall (Recall, R), F1 score (F1) and accuracy (Accuracy, Acc). The experimental results are summarized in Table 3, and the performance of the model in various indicators is revealed through detailed analysis.
[0192] In addition, the experiments of the present invention also examined unimodal baseline models (such as AC, IT and WG), which were trained using only visual or textual emotion labels to determine the best parameter settings. These models were then tested using multimodal emotion labels and compared with other multimodal methods for accuracy. This operation shows that jointly analyzing multimodal features in multimedia network environments is crucial to improving the ability of machines to understand and recognize abstract expressions of subjective emotions.
[0193] 1. Analysis of unimodal emotion recognition results
[0194] The first task of this study is to determine effective methods for text and visual feature extraction. Fig.10As shown in the upper part of , when word-level content is embedded in the same way, by comparing the two unimodal results, it is found that the text-based method generally achieves better performance than the image-based method, which indicates that the expression of sarcastic / non-sarcastic information mainly exists in the text modality. And in the above experiment of using text single modality for sarcasm detection, the single text model using CLIP achieves better performance than the single text model using Glove (GB) and Word2Vec (WB). This result shows that the text encoder using CLIP is more effective when resources are limited and can adapt to different context changes more flexibly, thus facilitating further sentiment analysis.
[0195] 2. Analysis of multimodal emotion recognition results
[0196] Experimental results show that the proposed CLMCM outperforms all baselines on the HFM dataset, which verifies the effectiveness of the proposed model in multimodal sarcasm detection. Since the single-vision model and the single-text model only classify sentiment on unimodal data, these two methods show relatively low performance. In contrast, early fusion and mid-term fusion greatly improve the performance, which confirms that the combination of visual and textual content is effective for sentiment classification. Fig.10 It can be found that MCEF is the most advanced method, but the proposed CLMCM still has considerable improvements, especially in terms of F1 and Rec. This verifies the effectiveness of the method in multimodal sentiment analysis.
[0197] The above description is only a specific implementation mode of the present invention, but the protection scope of the present invention is not limited thereto. Any modifications, equivalent substitutions and improvements made by any technician familiar with the technical field within the technical scope disclosed by the present invention and within the spirit and principle of the present invention should be covered by the protection scope of the present invention.
Claims
1. A novel sarcasm detection method based on contrastive learning and modality mutual assistance, characterized in that: include: Step 1: Extract text image features by applying the Vision Transformer model and the Text Transformer text encoder to obtain image and text representations respectively; Step 2: Cross-modal cooperation: introduce the obtained image and text features for information exchange to obtain multimodal feature representation; Step 3: Similarity-based comparative learning allows the model to learn relevant features in multimodal data; Step 4: Based on the contrastive learning of enhanced data, a variety of data enhancement techniques are applied to generate enhanced samples. The model learns more essential and generalized animal features by comparing the similarities between the enhanced samples and the original samples. Step 5: Model training and classification to obtain sarcasm detection results.
2. The novel sarcasm detection method based on contrastive learning and modality mutual assistance according to claim 1 is characterized in that: In the step 1, for multimodal ironic data, the image embedding is obtained by using the pre-trained Vision Transformer model from CLIP and applying it to the image embedding of the input image. The vit model used is composed of 24 layers and 16 heads of visual transformers, and its weights are kept frozen after pre-training; for the acquisition of text representation, the TextTransformer text encoder is directly used to derive the corresponding text representation; trainable projection layers are introduced at the output of the CLIP image and text encoders, which map the unimodal image and text features v and t to their corresponding image projections respectively and text projection Achieve better alignment between text and image spaces.
3. The novel sarcasm detection method based on contrastive learning and modality mutual assistance according to claim 1 is characterized in that: The second step comprises: Step 2.1 introduces the obtained image and text features, which are transmitted through the designed multimodal mutual assistance layer, which contains a modality-specific feature separator to connect the fusion pipeline of the image and text. The module adopts a single-layer design; the discriminator loss is used as a regularization method, and a specially designed similarity contrast loss function is introduced and integrated into the total loss by adding a geometric metric or a distribution similarity metric based on the hidden dimension as a regularization term to the total loss; the modality mutual assistance module is stacked into two pipelines to form a symmetrical structure. The present invention refers to the modality that continues to advance in the same fusion pipeline in the same mutual assistance module as the main modality, which is denoted by X main , and the modality added to the dual-modal fusion in one pipeline but derived from another pipeline as an external modality is called other modality, denoted by X other ; Step 2.2 The cross-modal fusion process mainly occurs in the multi-head attention operation. The multi-head attention part in the modal mutual assistance module is composed of two identical Transformer encoders, which respectively form the visual and text encoder modules. At the same time, the visual and text features in the previous layer are utilized. The visual and text streams use their own and from the other side and vector, and vice versa, so if main is other The corresponding Q, K, and V matrices can be obtained as follows: Step 2.3 uses the calculated feature vector to calculate the attention weight between the two modalities, and uses the corresponding Q, K, and V to calculate an attention weight matrix. This weight matrix can be used to represent the correlation between the two modalities: The calculation process of the multi-head self-attention mechanism can be expressed as: MultiHead(Q,K,V)=Concat(head1,…,head h )W O (5) in represents the parameter matrix of the i-th head, W O Represents a parameter matrix for output. The present invention uses a residual connection after each multi-head attention layer to add the original feature representation of the modality to the output of the multi-head attention layer, and uses layer normalization after each self-attention layer to normalize the output; Step 2.3 uses a feed-forward fully connected layer to further process the representation. This layer contains two linear transformations and a nonlinear activation function. The activation function selects the ReLU function, and the final result is connected with residual connection and layer normalization. Finally, the correlation relationship X between the two modal features is obtained. v2t and X t2v , use a simple FC layer to obtain the multimodal representation R: X v2t =MultiHead(Q v ,K t ,V t ) (7) X t2v =MultiHead(Q t ,K v ,V v ) (8) R=W2·ReLU(W1·concat(X v2t ,X t2v )+b1)+b2 (9)。 4. The novel sarcasm detection method based on contrastive learning and modality mutual assistance according to claim 1 is characterized in that: The step three comprises: Step 3.1 In order to make the model learn the relevant features in multimodal data, this loss function is designed. Since the image feature X obtained by MCM t2v and text feature X v2t Already closely aligned, the present invention uses it as the input of formula (10). In order to maximize the similarity between positive samples and minimize the similarity between negative samples, the present invention uses the Euclidean distance to measure the similarity between the mapped image and text features: Step 3.2 further enhances the model's ability to learn to distinguish between positive and negative samples by constructing a similarity matrix and comparing the diagonal elements (i.e., the similarity between itself and itself, representing positive sample pairs) with other elements in the matrix (representing negative sample pairs). Here, we calculate v e to e The similarity comparison learning loss is calculated by e to v e Otherwise: The two losses obtained in step 3.3 will be balanced by a weight value λ as shown in formula (12):
5. The novel sarcasm detection method based on contrastive learning and modality mutual assistance according to claim 1 is characterized in that: In step 4, taking the picture classification model as an example, due to the diverse expressions of images, it is easy for the model to learn surface features. At this time, if contrastive learning based on data enhancement is adopted, the present invention can apply multiple data enhancement techniques to the image of each animal, such as rotation, scaling, cropping, color transformation, etc., to generate multiple visually different but semantically identical samples; then, the model learns more essential and generalized animal features by comparing the similarities between these enhanced samples and the original samples, rather than accidental features or noise in the image.
6. The novel sarcasm detection method based on contrastive learning and modality mutual assistance according to claim 1 is characterized in that: In step 5, the multimodal representation R is fed to the fully connected layer, and the softmax function is used for emotion detection. The present invention uses cross entropy loss as the classification loss, as shown below: L SDR =Cross-Entropy(GELU(RW SDR +b SDR )) (13) The data augmentation-based contrastive loss and the similarity-based contrastive learning loss can be simply added to the total loss as regularization and can be combined as follows: L=L SDR +λ SCL L SCL +λ DACL L DACL (14) where λ SCL and λ DACL is a coefficient used to balance different training losses.
7. A novel sarcasm detection system based on contrastive learning and modality mutual assistance according to any one of claims 1 to 6, characterized in that: The novel sarcasm detection system based on contrastive learning and modality mutual assistance includes: An image encoder, for obtaining an image representation; Text encoder, used to obtain text representation; The modality mutual assistance module is used to exchange information between the obtained image and text features to obtain multimodal feature representation; Similarity comparison learning module, used for comparison learning based on similarity; Data enhancement module, used to apply various data enhancement techniques to generate enhanced samples; The output module is used to output the sarcasm detection results.
8. A computer device, characterized in that: The computer device includes a memory and a processor, the memory stores a computer program, and when the computer program is executed by the processor, the processor executes the steps of the novel sarcasm detection method based on contrastive learning and modal mutual assistance as described in any one of claims 1-6.
9. A computer-readable storage medium storing a computer program, wherein when the computer program is executed by a processor, the processor executes the steps of the novel sarcasm detection method based on contrastive learning and modal mutual assistance as claimed in any one of claims 1 to 6.
10. An information data processing terminal, characterized in that: The information data processing terminal is used to implement the novel sarcasm detection system based on contrastive learning and modal mutual assistance as described in claim 7.
Citation Information
Cited By
Multi-mode irony detection method based on joint attention and graph learning enhancement
CN118916683A
A multimodal sarcasm detection method based on joint attention and graph learning enhancement
CN118916683B
Error information detection method and system based on cross-modal difference classification
CN120045945A
Multi-mode irony detection method based on large language model
CN120952006A
