Multimodal sentiment analysis method based on contrastive learning and multi-head self-attention mechanism
The Transformer-Encoder structure of contrastive learning and multi-head self-attention mechanism is used to fuse text and image features, solving the problem of feature fusion in multi-modal image and text sentiment analysis, and improving the accuracy and discrimination ability of sentiment analysis.
Patent Information
- Application Number
- CN202210084807.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-01-25
- Publication Date
- 2024-10-01
- Estimated Expiration
- 2042-01-25
AI Technical Summary
In existing multi-modal image and text sentiment analysis tasks, text and image features are difficult to fuse, and the fused features contain information that is irrelevant to sentiment analysis, making sentiment analysis difficult.
The Transformer-Encoder structure based on contrastive learning and multi-head self-attention mechanism is used to align and fuse text and image features, and contrastive learning tasks of label type and image-text fusion features are added to improve the model's data emotion discrimination ability.
By aligning and merging text and image features, the model can better focus on emotional features and related features in the image-text fusion process, improving the accuracy and differentiation capabilities of sentiment analysis.
Smart Images

Figure CN114529758B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of natural language processing, and in particular to a multimodal sentiment analysis method based on contrastive learning and multi-head self-attention mechanism. Background Art
[0002] With the development of the Internet, the number of Internet users in my country is increasing day by day, and the scale of Internet users is becoming larger and larger. More and more people use terminal devices to express their opinions on some hot topics on platforms such as Weibo, forums, and social software. Taking Weibo as an example, people can express their opinions in the form of text and pictures, and the content posted by people on these social media often has a strong subjective consciousness and contains rich emotions. Sentiment analysis is also called opinion mining, which refers to the process of identifying and analyzing emotional tendencies of subjective texts with emotional colors. The theoretical significance of sentiment analysis is that when people make decisions, they rely to a large extent on the views and evaluations of others, and opinions are the main factors affecting people's behavior. Sentiment analysis includes multiple subtasks, such as sentiment classification, sentiment information extraction, topic identification, subjective and objective analysis, etc. In terms of social value, with the popularity of social media such as forums and Weibo, people are more and more inclined to express their views on issues, events, topics, and news on the Internet. Therefore, sentiment analysis of unstructured texts on social media can understand the comments of the masses and extract the masses' views on a certain event, thereby helping the government or relevant social departments to better grasp public opinion and make corresponding decisions. In other aspects, sentiment analysis technology has also been applied in the field of psychology, providing a feasible path for improving the proof of psychological theories. Sentiment analysis can also realize automatic review of papers, predict the trend of stocks and movie box office, etc.
[0003] In the past, the analysis of user sentiment on social networks mainly focused on the text information in the user's status update. The task of text sentiment analysis is to judge the user's emotional polarity based on the text content. As uploading images or videos with short texts has become the main way for users to share their moods and express their opinions on social networks, images and texts together constitute the main part of the content in social media. Multimodal data usually has the characteristics of complementarity, mutual verification, fusion and convertibility. Complementarity is an important attribute of multimodal data. Various data types can provide partial explanations and descriptions of a certain thing or phenomenon. The structures of different types of raw data vary greatly, but after proper processing, these diverse data can be fused together or even converted to each other to verify the consistency of the results of the same event. Recently, in the field of data fusion, researchers have applied deep learning technology to multimodal data analysis tasks and made some important progress. Multimodal data analysis methods based on deep learning have achieved some results in the fields of sentiment analysis, language translation, cross-modal retrieval and medical auxiliary diagnosis. Deep learning has brought new opportunities to the field of multimodal data fusion. Summary of the invention
[0004] The present invention takes into account that text and image features are difficult to fuse and align, and that there is some information irrelevant to sentiment analysis in the fused text and image features, which makes multimodal text and image sentiment analysis always a relatively difficult task; a multimodal sentiment analysis method based on contrastive learning and multi-head self-attention mechanism is proposed; the method aims to use the Transformer-Encoder structure based on the multi-head self-attention mechanism to help align and fuse text and image features, and at the same time add two auxiliary contrastive learning tasks to help the model better extract and learn the features after the fusion of text and image, and help the model improve the ability to distinguish data sentiment.
[0005] The present invention is achieved through the following scheme:
[0006] A multimodal sentiment analysis method based on contrastive learning and multi-head self-attention mechanism:
[0007] The method specifically comprises the following steps:
[0008] Step 1: Obtain training samples for multimodal sentiment analysis; perform data division and preprocessing on the training samples; obtain text and image data of the training samples;
[0009] Step 2: Divide the sentences in each sample in the training sample into subwords, add markers at the beginning and end of the sentence, and then map the words to word vector indexes to complete the preliminary representation of the text;
[0010] Step 3: Read the images in the training sample into the memory and map the image format into RGB format vector data to complete the preliminary representation of the image;
[0011] Step 4: Input the preliminary representation of the text obtained in step 2 and the preliminary representation of the image obtained in step 3 into the text pre-training model BERT and the image feature extraction model ResNet-50 respectively, to obtain the sequence feature representation of the text and the feature representation of the image respectively;
[0012] Step 5: Input the image feature representation obtained in step 4 into the multi-layer Transformer-Encoder network to obtain the secondary extracted image features;
[0013] Step 6: Concatenate the text feature representation obtained in step 4 and the secondary extracted image features obtained in step 5 to obtain a text-image feature sequence representation, input the text-image feature sequence representation into a multi-layer Transformer-Encoder network, align and fuse the text-image features through the calculation of the multi-head self-attention mechanism, and obtain a text-image sequence fusion feature vector;
[0014] Step 7: The text-image sequence fusion feature vector in step 6 is passed through the attention layer to obtain the final text-image fusion feature vector;
[0015] Step 8: Input the text-image fusion feature vector obtained in step 7 into the sentiment classifier to obtain the sentiment classification result and loss function;
[0016] Step 9: The text-image fusion feature vector obtained in step 7 is used as an auxiliary task to calculate the loss function through Info-NCE comparative learning between the same label data in the same batch set;
[0017] Step 10: Perform data enhancement on the text-image data obtained in step 1, and obtain a data-enhanced text-image fusion feature vector through steps 2 to 7. Then, perform Info-NCE comparative learning on the final text-image fusion feature vector obtained in step 7 and the data-enhanced text-image fusion feature vector as an auxiliary task, and calculate the loss function.
[0018] Step 11: Add the three loss functions from step 8 to step 10 according to the weights to optimize the entire multimodal sentiment analysis model.
[0019] Furthermore, in step one, the specific method of data division is: dividing the data set into a training set, a validation set and a test set in a ratio of 8:1:1; and ensuring that the amount of text and image data in each set is balanced.
[0020] Furthermore, in step 2, the text sequence S of the training sample is converted into {w1w2...w N} to split the word and add start and end symbols at the beginning and end;
[0021] The text sequence after word segmentation is S sub ={[start],w1,w2,...,w N , [end]}, and then convert the text sequence after word segmentation into a word vector index:
[0022]
[0023] Furthermore, in step three: the image is read into the memory to obtain the vector data of the image in RGB format, and after scaling, the image vector data Img is obtained:
[0024] Img=convert_to_RGB(Image_Read(image_file_path)).
[0025] Further, step 4: index the text word vector S index and image vector data Img are input into the model respectively, and the sequence feature representation of the text is obtained respectively. index ) and the sequence feature representation of the image Image_Model (Img);
[0026] [T r[cls] , T r1 , T r2 , ..., T rN , T r[end] ]=Text_Model(S index ) [I r1 , I r2 , ..., I r49 ]=Image_Model(Img).
[0027] Furthermore, in step 5, the image sequence features are input into a multi-layer Transformer-Encoder network to obtain image features that are closer to the text, and obtain the secondary image feature Transformer img ([I r1 , I r2 , ..., I r49 ]);
[0028]
[0029] Further, in step six, the text-image feature sequence represents:
[0030]
[0031] The text-image feature sequence representation is input into the multi-layer Transformer-Encoder to obtain the text-image sequence fusion feature vector [M1, M2, ..., M N+51 ];
[0032] [M1, M2, ..., M N+51 ]=Transformer text-img (T_Img);
[0033] In step 7, the final text-image fusion feature vector is:
[0034] [q1, q2, ..., q N+51 ]=Softmax(Linear([M1, M2,...,M N+51 ]))
[0035]
[0036] Furthermore, in step eight, the result and loss function of the sentiment classification are:
[0037] f=GELU(R text-image W f +b f )
[0038] o=softmax(fW o +b o )
[0039] y′=argmax(o)∈[1,c]
[0040] Loss c =ylog(o(y′)) / len(labels)
[0041] Among them, f is the emotion category feature vector, o is the emotion category probability value, m and n are the hidden dimensions of the linear layer, c represents the number of emotion categories, y′ represents the final emotion category, y represents the true emotion label, labels represents all labels in the same batch, and the loss function Loss c The cross entropy loss function is used for calculation;
[0042] In step nine, the specific calculation formula is as follows:
[0043]
[0044] cl_self_labels=get_target_labels(labels)
[0045] cl_self_encoder=cl_self_encoder / temperature
[0046] cl_self_loss=gather(cl_self_encoder, dim=1, index=cl_self_labels)
[0047] Loss cl_self =cl_self_loss / len(labels)
[0048] The get_target_labels() function generates the index data of the same labels that need to maximize the probability in the same batch set required for Info-NCE contrastive learning based on the original labels. The gather() function extracts the maximized selected features from the contrastive learning encoding features based on the index data of the given labels and calculates the loss.
[0049] Step 10: Perform Info-NCE comparative learning between the text-image features obtained by data enhancement and the text-image features of the original data. The calculation formula is as follows:
[0050] T a , I a =Data_augmentation(S,Img)
[0051] R text-image,a =Multimodal_model(T a , I a )
[0052]
[0053] cl_labels=range(len(labels))
[0054] Loss cl =CrossEntropyLoss(cl_encoder,cl_labels) / len(labels)
[0055] Data_augmentation() in the formula is used to perform data augmentation on text-image data, where reverse translation is performed on text, i.e., in the form of source language-translation language-source language; for image data, brightness and darkness transformation, cropping, and contrast transformation are used for data augmentation; Multimodal_model in the formula is the operation in steps 4 to 7, where the model parameters and the model used for the original data are parameter-shared;
[0056] Step 11: Finally, add the Loss obtained from Steps 8 to 10 c 、Loss cl self and Loss cl Add them in proportion and jointly optimize the multimodal sentiment analysis model. The formula is as follows:
[0057] Loss=Loss c +αLoss cl_self +βLoss cl
[0058] Where α and β are equal to 1.
[0059] An electronic device comprises a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of the above method when executing the computer program.
[0060] A computer-readable storage medium is used to store computer instructions, and when the computer instructions are executed by a processor, the steps of the above method are implemented.
[0061] Beneficial effects of the present invention
[0062] The present invention uses a Transformer-Encoder structure based on a multi-head self-attention mechanism to help align and fuse text and image features, and adds two auxiliary contrastive learning tasks, namely contrastive learning for label types and contrastive learning for image-text fusion features, to help the model pay more attention to the emotional features in the image-text fusion features and the related features in the image-text fusion process, and help the model improve its ability to distinguish data emotions. BRIEF DESCRIPTION OF THE DRAWINGS
[0063] Figure 1 It is the overall model structure diagram of the present invention;
[0064] Figure 2 It is a structural diagram of the data feature extraction component in the model structure of the present invention;
[0065] Figure 3 It is a structural diagram of the multimodal fusion component based on the multi-head self-attention mechanism in the model structure of the present invention;
[0066] Figure 4 This is a flow chart of model training of the present invention. DETAILED DESCRIPTION
[0067] The technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all the embodiments; based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.
[0068] Combination Figures 1 to 4 ,
[0069] A multimodal sentiment analysis method based on contrastive learning and multi-head self-attention mechanism:
[0070] The method specifically comprises the following steps:
[0071] Step 1: Obtain training samples for multimodal sentiment analysis; perform data division and preprocessing on the training samples; obtain text and image data of the training samples;
[0072] Step 2: Divide the sentences in each sample in the training sample into subwords, add markers at the beginning and end of the sentence, and then map the words to word vector indexes to complete the preliminary representation of the text;
[0073] Step 3: Read the images in the training sample into the memory and map the image format into RGB format vector data to complete the preliminary representation of the image;
[0074] Step 4: Input the preliminary representation of the text obtained in step 2 and the preliminary representation of the image obtained in step 3 into the text pre-training model BERT and the image feature extraction model ResNet-50 respectively, to obtain the sequence feature representation of the text and the feature representation of the image respectively;
[0075] Step 5: Input the image feature representation obtained in step 4 into the multi-layer Transformer-Encoder network. This step is to convert the image features into image features that are closer to the text and obtain secondary extracted image features;
[0076] Step 6: Concatenate the text feature representation obtained in step 4 and the secondary extracted image features obtained in step 5 to obtain a text-image feature sequence representation, input the text-image feature sequence representation into a multi-layer Transformer-Encoder network, align and fuse the text-image features through the calculation of the multi-head self-attention mechanism, and obtain a text-image sequence fusion feature vector;
[0077] Step 7: The text-image sequence fusion feature vector in step 6 is passed through the attention layer to obtain the final text-image fusion feature vector;
[0078] Step 8: Input the text-image fusion feature vector obtained in step 7 into the sentiment classifier (fully connected layer and softmax layer) to obtain the sentiment classification result and loss function;
[0079] Step 9: The text-image fusion feature vector obtained in step 7 is used as an auxiliary task to calculate the loss function through Info-NCE comparative learning between the same label data in the same batch set;
[0080] Step 10: Perform data enhancement on the text-image data obtained in step 1, and obtain a data-enhanced text-image fusion feature vector through steps 2 to 7. Then, perform Info-NCE comparative learning on the final text-image fusion feature vector obtained in step 7 and the data-enhanced text-image fusion feature vector as an auxiliary task, and calculate the loss function.
[0081] Step 11: Add the three loss functions from step 8 to step 10 according to the weights to optimize the entire multimodal sentiment analysis model.
[0082] In step 1, the specific method of data division is: dividing the data set into a training set, a validation set and a test set in a ratio of 8:1:1; and ensuring that the amount of text and image data in each set is balanced.
[0083] In step 2, the text sequence of the training sample S = {w1w2...w N} to split the word and add start and end symbols at the beginning and end;
[0084] The text sequence after word segmentation is S sub ={[start],w1,w2,...,w N , [end]}, and then convert the text sequence after word segmentation into a word vector index:
[0085]
[0086] In step three: read the image into memory, obtain the vector data of the image in RGB format, and after scaling, obtain the 3*224*224 image vector data Img:
[0087] Img=convert_to_RGB(Image_Read(image_file_path)).
[0088] Step 4: Index the text word vector Sindex and image vector data Img are input into the model respectively, and the sequence feature representation of the text is obtained respectively. index ) and the sequence feature representation of the image Image_Model (Img); (such as Figure 2 The structure diagram of the data feature extraction component is shown below):
[0089] [T r[cls] , T r1 , T r2 , ..., T rN , T r[end] ]=Text_Model(S index ) [I r1 , I r2 , ..., I r49 ]=Image_Model(Img).
[0090] For text sequence features, a 768-dimensional feature vector is extracted for each subword, and for images, a 49*768-dimensional feature vector is obtained.
[0091] In step 5, the image sequence features are input into the multi-layer Transformer-Encoder network to obtain image features that are closer to the text, and obtain the secondary image feature Transformer img ([I r1 , I r2 , ..., I r49 ]);(like Figure 3 Structural diagram of multimodal fusion components based on multi-head self-attention mechanism);
[0092]
[0093] This is to make the image features and text features more compatible, so as to help the model better perform subsequent text-image feature fusion;
[0094] In step six, the text-image feature sequence is represented as:
[0095]
[0096] The text-image feature sequence representation is input into the multi-layer Transformer-Encoder to obtain the text-image sequence fusion feature vector [M1, M2, ..., M N+51 ];(like Figure 3 Structure diagram of multimodal fusion components based on multi-head self-attention mechanism):
[0097] [M1, M2, ..., M N+51]=Transformer text-img (T_Img);
[0098] In step 7, the final text-image fusion feature vector is:
[0099] [q1, q2, ..., q N+51 ]=Softmax(Linear([M1, M2,...,M N+51 ]))
[0100]
[0101] In step eight, the result and loss function of the sentiment classification are: Figure 1 The first task on the upper left):
[0102] f=GELU(R text-image W f +b f )
[0103] o=softmax(fW o +b o )
[0104] y′=argmax(o)∈[1,c]
[0105] Loss c =ylog(o(y′)) / len(labels)
[0106] Among them, f is the emotion category feature vector, o is the emotion category probability value, m and n are the hidden dimensions of the linear layer, c represents the number of emotion categories, y′ represents the final emotion category, y represents the true emotion label, labels represents all labels in the same batch, and the loss function Loss c The cross entropy loss function is used for calculation;
[0107] In step nine, Info-NCE comparative learning is performed between the same label data in the same batch set. This is to allow the model to learn the emotional information features after text-image fusion, rather than just focusing on how to fuse text and image features. The specific calculation formula is as follows:
[0108]
[0109] cl_self_labels=get_target_labels(labels)
[0110] cl_self_encoder=cl_self_encoder / temperature
[0111] cl_self_loss=gath er(cl_self_encoder, dim=1, index=cl_self_labels)
[0112] Loss cl_self =cl_self_loss / len(labels)
[0113] The get_target_labels() function generates the index data of the same labels that need to maximize the probability in the same batch set required for Info-NCE contrastive learning based on the original labels. Figure 1 In the shaded part of the middle matrix, the gather() function extracts the maximized selected features (required features) from the contrastive learning encoding features according to the given label index data and calculates the loss;
[0114] Step 10: Perform Info-NCE comparative learning between the text-image features obtained by data enhancement and the text-image features of the original data (such as Figure 1 The shaded part of the upper left matrix), the calculation formula is as follows:
[0115] T a , I a =Data_augmentation(S, Img)
[0116] R text-image,a =Multimodal_model(T a , I a )
[0117]
[0118] cl_labels=range(len(labels))
[0119] Loss cl =CrossEntropyLoss(cl_encoder,cl_labels) / len(labels)
[0120] Data_augmentation() in the formula is used to perform data augmentation on text-image data, where reverse translation is performed on text, i.e., in the form of source language-translation language-source language; for image data, data augmentation is performed using strategies such as shading transformation, cropping, and contrast transformation; Multimodal_model in the formula is the operation in steps 4 to 7, where the model parameters are shared with the model used for the original data;
[0121] Step 11: Finally, add the Loss obtained from Steps 8 to 10 c 、Loss cl self and Loss cl Add them in proportion and jointly optimize the multimodal sentiment analysis model. The formula is as follows:
[0122] Loss=Loss c +αLoss cl_self +βLoss cl
[0123] Where α and β are equal to 1.
[0124] An electronic device comprises a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of the above method when executing the computer program.
[0125] A computer-readable storage medium is used to store computer instructions, and when the computer instructions are executed by a processor, the steps of the above method are implemented.
[0126] The training rules for model optimization are as follows Figure 4 As shown in the flowchart, a total training round number epoch and two layered training round numbers epoch1 and epoch2 are defined, and epoch = epoch1 + epoch2. The text is trained and layered optimization is used during the training process. First, optimize Figure 3 After epoch 1, all model parameters are optimized. Define a batch size, which is the number of training samples used by the model in a batch.
[0127] Optionally, in this embodiment, the learning rate is 2e-5 and the Adamw optimizer is used.
[0128] Introduction to implementation data and evaluation indicators
[0129] In this embodiment, the MVSA-Single dataset for multimodal text and image sentiment analysis provided by the MCR Laboratory of the University of Ottawa is used. The MVSA-Single dataset needs to be manually divided into a training set, a validation set, and a test set. The distribution of the data after division is shown in Table 1:
[0130]
[0131] Table 1: Distribution of sentiment labels in the MVSA-Single dataset
[0132] In this embodiment, the multimodal emotion dataset HFM for sarcasm recognition based on Twitter provided by Tsinghua University is also used. The dataset itself has been divided into training set, validation set and test set, and its data distribution is shown in Table 2:
[0133]
[0134] Table 2: Distribution of sentiment labels in the HFM dataset
[0135] The present invention adopts F1 value and accuracy as evaluation indicators.
[0136] Experimental Results
[0137] The experimental results on the MVSA-Single dataset are shown in Table 3:
[0138]
[0139] Table 3: Experimental results of sentiment classification on MVSA-Single dataset
[0140] The experimental results on the HFM dataset are shown in Table 4:
[0141]
[0142] Table 4: Experimental results of sentiment classification on MVSA-Single dataset
[0143] Experimental results for the MVSA-Single dataset. BERT and ResNet-50 are text and image pre-training models. MultiSentiNet is a multimodal emotion recognition method based on multi-scene semantics, CoMN(6) is a multimodal emotion recognition method based on mutual attention mechanism, and MGNNS is a multimodal emotion recognition method based on multi-channel graph neural network.
[0144] Experimental results on the HFM dataset. BERT and ResNet-50 are pre-trained models for text and images. Random represents the prediction result obtained by randomly generating answers. Concat is a method of concatenating the features of text and images for classification. Hierarchical FM is a multimodal emotion recognition method based on hierarchical local and global features.
[0145] The above is a detailed introduction to the multimodal sentiment analysis method based on contrastive learning and multi-head self-attention mechanism proposed in the present invention, and the principles and implementation methods of the present invention are explained. The description of the above embodiments is only used to help understand the method of the present invention and its core idea; at the same time, for those skilled in the art, according to the idea of the present invention, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present invention.
Claims
1. A multimodal sentiment analysis method based on contrastive learning and multi-head self-attention mechanism, characterized by: The method specifically comprises the following steps: Step 1: Obtain training samples for multimodal sentiment analysis; perform data division and preprocessing on the training samples; obtain text and image data of the training samples; Step 2: Divide the sentences in each sample in the training sample into subwords, add markers at the beginning and end of the sentence, and then map the words to word vector indexes to complete the preliminary representation of the text; Step 3: Read the images in the training sample into the memory and map the image format into RGB format vector data to complete the preliminary representation of the image; Step 4: Input the preliminary representation of the text obtained in step 2 and the preliminary representation of the image obtained in step 3 into the text pre-training model BERT and the image feature extraction model ResNet-50 respectively, to obtain the sequence feature representation of the text and the feature representation of the image respectively; Step 5: Input the image feature representation obtained in step 4 into the multi-layer Transformer-Encoder network to obtain the secondary extracted image features; Step 6: Concatenate the text feature representation obtained in step 4 and the secondary extracted image features obtained in step 5 to obtain a text-image feature sequence representation, input the text-image feature sequence representation into a multi-layer Transformer-Encoder network, align and fuse the text-image features through the calculation of the multi-head self-attention mechanism, and obtain a text-image sequence fusion feature vector; Step 7: The text-image sequence fusion feature vector in step 6 is passed through the attention layer to obtain the final text-image fusion feature vector; Step 8: Input the text-image fusion feature vector obtained in step 7 into the sentiment classifier to obtain the sentiment classification result and loss function; Step 9: The text-image fusion feature vector obtained in step 7 is used as an auxiliary task to calculate the loss function through Info-NCE comparative learning between the same label data in the same batch set; Step 10: Perform data enhancement on the text-image data obtained in step 1, and obtain a data-enhanced text-image fusion feature vector through steps 2 to 7. Then, perform Info-NCE comparative learning on the final text-image fusion feature vector obtained in step 7 and the data-enhanced text-image fusion feature vector as an auxiliary task, and calculate the loss function. Step 11: Add the three loss functions from step 8 to step 10 according to the weights to optimize the entire multimodal sentiment analysis model.
2. The method according to claim 1, characterized in that: In step 1, the specific method of data division is: dividing the data set into a training set, a validation set and a test set in a ratio of 8:1:1; and ensuring that the amount of text and image data in each set is balanced.
3. The method according to claim 2, characterized in that: In step 2, the text sequence of the training sample S = {w1 w2 ... w N } to split the word and add start and end symbols at the beginning and end; The text sequence after word segmentation is S sub ={[start],w1,w2,...,w N , [end]}, and then convert the text sequence after word segmentation into a word vector index:
4. The method according to claim 3, characterized in that: In step three: read the image into memory, obtain the vector data of the image in RGB format, and after scaling, obtain the image vector data Img: Img=convert_to_RGB(Image_Read(image_file_path)).
5. The method according to claim 4, characterized in that: Step 4: Index the text word vector S index and image vector data Img are input into the model respectively, and the sequence feature representation of the text is obtained respectively. index ) and the sequence feature representation of the image Image_Model (Img); [T r[cls] ,T r1 ,T r2 ,...,T rN ,T r[end] ]=Text_Model(S index ) [I r1 ,I r2 ,...,I r49 ]=Image_Model(Img)。 6. The method according to claim 5, characterized in that: In step 5, the image sequence features are input into the multi-layer Transformer-Encoder network to obtain image features that are closer to the text, and obtain the secondary image feature Transformer img ([I r1 , I r2 , ..., I r49 ]); 7. The method according to claim 6, characterized in that: In step six, the text-image feature sequence is represented as: The text-image feature sequence representation is input into the multi-layer Transformer-Encoder to obtain the text-image sequence fusion feature vector [M1, M2, ..., M N+51 ]; [M1,M2,...,M N+51 ]=Transformer text-img (T_Img); In step 7, the final text-image fusion feature vector is: [q1,q2,...,q N+51 ]=Softmax(Linear([M1,M2,...,M N+51 ]) 8. The method according to claim 7, characterized in that: In step eight, the result and loss function of the sentiment classification are: f=GEL(R text-image W f +b f ) o=softmax(fW o +b o ) y′=argmax(o)∈[1,c] Loss c =ylog(o(y′)) / len(labels) Among them, f is the emotion category feature vector, o is the emotion category probability value, m and n are the hidden dimensions of the linear layer, c represents the number of emotion categories, y′ represents the final emotion category, y represents the true emotion label, labels represents all labels in the same batch, and the loss function Loss c The cross entropy loss function is used for calculation; In step nine, the specific calculation formula is as follows: cl_self_labels=get_target_labels(labels) cl_self_encoder=cl_self_encoder / temperature cl_self_loss=gath er(cl_self_encoder, dim=1, index=cl_self_labels) Loss cl_self =cl_self_loss / len(labels) The get_target_labels() function generates the index data of the same labels that need to maximize the probability in the same batch set required for Info-NCE contrastive learning based on the original labels. The gather() function extracts the maximized selected features from the contrastive learning encoding features based on the index data of the given labels and calculates the loss. Step 10: Perform Info-NCE comparative learning between the text-image features obtained by data enhancement and the text-image features of the original data. The calculation formula is as follows: T a ,I a =Data_augmentation(S,Img) R text-image,a =Multimodal_model(T a ,I a ) cl_labels=range(len(labels)) Loss cl =CrossEntropyLoss(cl_encoder,cl_labels) / len(labels) Data_augmentation() in the formula is used to perform data augmentation on text-image data, where reverse translation is performed on text, i.e., in the form of source language-translation language-source language; for image data, brightness and darkness transformation, cropping, and contrast transformation are used for data augmentation; Multimodal_model in the formula is the operation in steps 4 to 7, where the model parameters are shared with the model used for the original data; Step 11: Finally, add the Loss obtained from Steps 8 to 10 c 、Loss cl_self and Loss cl Add them in proportion and jointly optimize the multimodal sentiment analysis model. The formula is as follows: Loss=Loss c +αLoss cl_self +βLoss cl Where α and β are equal to 1.
9. An electronic device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to claims 1 to 8 are implemented.
10. A computer-readable storage medium for storing computer instructions, characterized in that: When the computer instructions are executed by a processor, the steps of the method according to claims 1-8 are implemented.
