A visual question answering approach based on hint guidance and self-supervised contrastive learning
Through the visual question and answer method based on prompt guidance and self-supervised contrastive learning, the problem in the existing technology that the attribute information of the image-question pair is not fully exploited is solved, and high-accuracy visual question and answer task prediction is achieved, and the multi-modality of the model is improved. State embedding and fusion capabilities.
Patent Information
- Application Number
- CN202410425002.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-04-10
- Publication Date
- 2024-08-23
- Estimated Expiration
- 2044-04-10
AI Technical Summary
Existing visual question answering technology has problems such as low accuracy, insufficient reasoning ability, model complexity and large amount of calculation in mining and feature extraction of thought chains related to image-question pairs, and ignores the various attributes of image-question pairs. information, leading to inaccurate prediction results.
Using a method based on prompt guidance and self-supervised contrastive learning, by obtaining the target question and inputting the preset visual question and answer model, prompt samples are generated, and the information of the image-question pair is combined to mine text and visual embeddings, and the attention mechanism is used to enhance and Fusing embeddings ultimately predicts answers to visual question answering tasks.
Through multi-category prompt templates and self-supervised contrastive learning, accurate prompt samples and embeddings are generated, which improves the prediction accuracy of visual question and answer tasks, enhances the model's multi-modal embedding fusion capabilities, and improves the accuracy of answer predictions.
Smart Images

Figure CN118013070B
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of visual question answering of artificial intelligence, and in particular to a visual question answering method based on prompt guidance and self-supervised contrastive learning. Background Art
[0002] The visual question answering task is a typical visual-language task that learns, mines, and interacts with image input, question input, and external supplementary knowledge to answer. The information required by most existing visual question answering tasks comes from image and text input. In addition, some visual question answering models need to learn external knowledge before they can answer. In addition, the above existing visual question answering technologies ignore the thinking chain related to the image-question pair, and most of them have technical defects such as low prediction accuracy, weak reasoning ability, single feature extraction, as well as complex models and large computational complexity.
[0003] For the visual question answering task of scientific questions, all image-question pairs involve multiple attributes such as subject, topic, category, skill, grade, difficulty, etc. The subject attributes include natural science, social science and language science. Similarly, there are other rich attributes: 26 topics, 127 categories, 379 skills and 12 grades. If the attribute information of two image-question pairs is different, the text information, visual information and logical reasoning ability they require are also different. Therefore, in order to better mine the attribute information of image-question pairs and use it to enhance the learning process of text and vision, a visual question answering method based on prompt guidance and self-supervised contrastive learning is proposed. Summary of the invention
[0004] The purpose of the present invention is to provide a visual question answering method based on prompt guidance and self-supervised contrastive learning, which generates prompt samples according to attribute information, interference information and prompt templates, and then obtains predicted answers based on prompt guidance strategies and supervised contrastive learning.
[0005] To achieve the above object, the present invention provides the following solutions:
[0006] A visual question answering method based on prompt-guided and self-supervised contrastive learning, including:
[0007] Obtaining a target question, inputting the target question into a preset visual question answering model, and outputting a predicted answer, wherein the visual question answering model includes: a prompt sample generation module, an embedding extraction module, an embedding fusion module, and an answer prediction module;
[0008] The prompt sample generation module is used to construct a prompt template, and generate a prompt sample based on the prompt template combined with information of the image-question pair;
[0009] The embedding extraction module is used to guide the mining of text information and image information in the image-question pair based on the prompt sample to obtain text embedding and visual embedding;
[0010] The embedding fusion module is used to perform attention mechanism enhancement on the text embedding and the visual embedding, and fuse the enhanced text embedding and the visual embedding to obtain a fused embedding;
[0011] The answer prediction module is used to predict the answer to the visual question answering task based on the fused embedding.
[0012] Optionally, the prompt sample generating module generates a prompt sample based on the prompt template and information of the image-question pair, including:
[0013] The prompt template is combined with the attribute information and interference information of the image-question pair and input into a classifier to generate the prompt samples, which include prompt positive samples and prompt negative samples.
[0014] Optionally, the embedding extraction module obtains the text embedding including:
[0015] The positive example sample and the negative example sample are respectively connected with the text input thinking chain and Integrate and obtain Input and enter;
[0016] Regarding the Input and The input is marked separately and then input into the pre-trained BERT model to obtain Text embedding and Text embedding.
[0017] Optionally, the embedding extraction module acquiring the visual embedding comprises:
[0018] Inputting the image and the prompt positive sample into the pre-trained VILT model in pairs to obtain a first visual input, and concatenating and integrating the first visual input to obtain a first visual embedding;
[0019] After visual enhancement, the image is paired with the prompt positive sample and input into a pre-trained VILT model to obtain a second visual input, and the second visual input is spliced and integrated to obtain a second visual embedding.
[0020] Optionally, the embedding fusion module performs attention mechanism enhancement on the text embedding and the visual embedding, including:
[0021] The text embedding is regarded as a query set and the visual embedding is regarded as a key-value set to perform cross-attention mechanism enhancement to obtain an enhanced visual embedding;
[0022] The visual embedding is regarded as a query set and the text embedding is regarded as a key-value set to perform cross-attention mechanism enhancement to obtain the enhanced text embedding.
[0023] Optionally, fusing the enhanced text embedding with the visual embedding includes:
[0024] The enhanced text embedding and visual embedding are concatenated and input into the fully connected neural network to obtain the fused embedding, which is:
[0025] ,
[0026]
[0027] in, is the first fusion embedding, is the second fusion embedding, FCN is a fully connected neural network, For front and back connection, It is the text embedding enhanced by the cross attention mechanism. is the first visual embedding enhanced by the cross-attention mechanism, It is the second visual embedding enhanced by the cross-attention mechanism.
[0028] Optionally, the method by which the answer prediction module predicts the answer to the visual question answering task based on the fused embedding is:
[0029]
[0030] in, To predict the results, is the activation function.
[0031] Optionally, the visual question answering model further includes a model optimization module, and the model optimization module is used to optimize the model by calculating the loss, and the method for calculating the loss is:
[0032] ,
[0033] ,
[0034] ,
[0035] ,
[0036]
[0037] in, Contrastive loss for visual question answering; , , and is the loss parameter; is the contrast loss for QCM input; is the contrast loss for CoT input; is the contrast loss for fusion embedding; is the loss between the prediction result and the label; exp is an exponential function with the natural constant e as the base; is the i-th prompt positive sample learned by the fully connected neural network Text embedding; is the rth positive example learned by the fully connected neural network Text embedding; and , , is the total number of positive examples; is the jth tip counterexample sample learned by the fully connected neural network Text embedding, is the total number of counterexample samples; is the temperature parameter, is the i-th prompt positive sample learned by the fully connected neural network Text embedding; is the rth positive example learned by the fully connected neural network Text embedding; is the jth tip counterexample sample learned by the fully connected neural network Text embedding; is the first fused embedding of the ith image, is the second fused embedding of the i-th image; is the first fused embedding of the jth image; and , , is the total number of images; , For the The image-question pair belongs to The prediction results of each category; , For the The image-question pair belongs to The label of the category, if The image-question pair belongs to Category, then ,otherwise ; is the total number of categories, is the total number of image-question pairs.
[0038] The beneficial effects of the present invention are:
[0039] The present invention constructs multiple categories of prompt templates, which are combined with attribute information of image-question pairs, interference information and a classifier to generate corresponding prompt positive examples and prompt negative examples, and then guide the mining of text information and image information through the prompt positive examples and prompt negative examples, thereby learning prompt-guided text representation and visual representation, and can perform multimodal embedding fusion and answer prediction through self-supervised comparative learning, and the prediction results are highly accurate. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0041] Figure 1 The visual question answering model structure framework and workflow diagram of an embodiment of the present invention;
[0042] Figure 2 A flow chart of a prompt sample construction according to an embodiment of the present invention. DETAILED DESCRIPTION
[0043] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0044] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and understandable, the present invention is further described in detail below in conjunction with the accompanying drawings and specific implementation methods.
[0045] This embodiment provides a visual question answering method based on prompt guidance and self-supervised contrastive learning, including:
[0046] Get the target question, input the target question into the preset visual question answering model, and output the predicted answer. The structure of the visual question answering model is as follows Figure 1 As shown, it includes: prompt sample generation module, embedding extraction module, embedding fusion module, answer prediction module;
[0047] A prompt sample generation module is used to construct a prompt template and generate a prompt sample based on the prompt template and information of the image-question pair;
[0048] Embedding extraction module, which is used to guide the mining of text and image information in image-question pairs based on prompt samples, and obtain text embedding and visual embedding;
[0049] The embedding fusion module is used to enhance the attention mechanism of text embedding and visual embedding, and fuse the enhanced text embedding and visual embedding to obtain the fused embedding;
[0050] The answer prediction module is used to predict the answer of the visual question answering task based on the fused embeddings.
[0051] Furthermore, the construction and workflow of the visual question answering model of this embodiment specifically includes the following steps:
[0052] Step 1. Construct multi-category prompt templates and then generate prompt samples;
[0053] A multi-category prompt template is designed, and then the prompt template is combined with the attribute information of the image-question pair, the interference information and a classifier to generate corresponding prompt samples; the prompt samples include prompt positive examples and prompt negative examples, among which the prompt positive examples involve attribute information and the prompt negative examples cover some interference information.
[0054] Specifically, we first give the attribute information as the input of the classifier to judge the difficulty of the image-question pair, which is divided into easy and challenging. Figure 2 As shown in the figure, two prompt templates are designed. Take the first template as an example, template t: "This question is for [Mask] grade students. It is about topic [Mask] in subject [Mask]. This is a [Mask] question". They are grade attribute, topic attribute, subject attribute and difficulty attribute. By filling in all [Mask] in the template, a positive example is generated. ,in is the total number of positive examples. "This question is for 8 gradestudents. It is about topic earth-science in subject natural science. This is a challenging question." is an example of a positive example. Similarly, by interfering with information to generate Prompt counterexamples , used for subsequent comparative learning.
[0055] Step 2. Guide the mining of text information and image information;
[0056] Image-question pairs involving different attribute information will focus on different textual information, visual information and multimodal logical reasoning capabilities. Based on this premise, we use prompt positive examples and prompt negative examples to guide the mining of textual information and image information, and then learn prompt-guided text and visual representations.
[0057] Specifically, text input includes thought chain and (Question + context + multiple choices). The constructed prompt samples include prompt positive samples and prompt negative samples. Prompt positive examples Respectively and Integrate into input and :
[0058] ,
[0059]
[0060] in, Indicates the connection between front and back. Similarly, Prompt counterexamples Respectively and Integrate into input and :
[0061] ,
[0062]
[0063] right , , , Add separately The text is then labeled and fed into the pre-trained BERT model (Bidirectional Encoder Representations from Transformers). The BERT model converts each word in the text into its corresponding embedding, represented as , , ,and .
[0064] The text embeddings finally output by the BERT model include the position embedding, segment embedding, and token embedding of each word. , , ,and Respectively , , and middle They are learned by a fully connected neural network (FCN) for subsequent contrastive learning.
[0065] ,
[0066] ,
[0067] ,
[0068]
[0069] Image-question pairs with different attributes focus on different visual areas and visual information. Therefore, the prompt samples not only help the learning of text, but also guide the VILT model (Vision-and-Language Transformer) to mine all visual inputs. and prompt positive examples Enter VILT in pairs. is the number of images. images and Prompt positive examples For example, the detailed process can be described as follows:
[0070]
[0071] Obtain VILT-based Output Similarly, The output with all the hint positive samples is recorded as:
[0072]
[0073] For image input Perform visual data enhancement to obtain enhanced images .in, yes The enhanced result. The same prompt-based guidance strategy is also performed and the result is recorded as :
[0074]
[0075] Finally, concatenate all the results to get and Embedding after prompt guidance and :
[0076] ,
[0077]
[0078] Step 3. Fusion of multimodal embeddings and prediction of answers;
[0079] Combining fusion embedding learning with self-supervised contrastive learning, the integration of multimodal information is enhanced. For self-supervised contrastive learning, the original image-question pair and the enhanced image-question pair are considered as positive samples, while the original image-question pair and other image-question pairs are considered as negative samples. By minimizing the difference between the original data and the positive samples and maximizing the loss between them and the negative samples, a more representative embedding in the same low-dimensional space is obtained to predict the answer.
[0080] Specifically, in the self-attention mechanism, the input is first converted into a query vector , key vector Sum value vector , and then pack these vectors into a matrix ,matrix and matrix .Will , and The input after learning attention weighting is fed into the following function:
[0081]
[0082] In this embodiment, in order to fuse multimodal embedding , , ,and , using the cross-attention mechanism, which is different from the self-attention mechanism in that the input of the cross-attention mechanism is bimodal information.
[0083] On the one hand, we consider text embedding as a set of queries and visual embedding as a set of key-values. Specifically, , , ,in, , or The cross-attention mechanism is as follows:
[0084]
[0085] when When , the result of the cross attention mechanism is . The corresponding result is .
[0086] On the other hand, visual information is used as a query set, text information is regarded as a key-value set, and attention weighting is performed on text embedding:
[0087] ,
[0088] ,
[0089] ,
[0090]
[0091] Text embedding enhanced by attention mechanism and visual embedding , Concatenate them separately and then feed them into the fully connected neural network (FCN):
[0092] ,
[0093]
[0094] use and Perform subsequent supervision comparison loss calculation based on Predicting answers for visual question answering tasks:
[0095]
[0096] in, It is an activation function.
[0097] Step 4. Definition of model loss and optimization of the model;
[0098] Optimize the model based on the loss function, learning rate and optimizer. For QCM, Guided QCM text embeddings are mutually positive examples, based on The guided QCM embedding is The contrast loss for QCM embedding is calculated as follows:
[0099]
[0100] in, Make sure that the hint positive example is not used as its own positive example. Similarly, the contrast loss for CoT embedding is calculated as follows:
[0101]
[0102] Contrastive learning for fusion embedding is based on self-supervised contrastive learning calculation. , the enhanced image Considered as Positive samples, other images (such as )yes For the counter-example sample, the contrast loss for fusion embedding is calculated as follows:
[0103]
[0104] in, It's an anchor. and They are Positive and negative examples.
[0105] Using cross entropy loss function to quantify prediction results in visual question answering tasks and tags The loss between , calculated as follows:
[0106]
[0107] in, and Indicates The image-question pair belongs to The prediction results and labels of the categories. The image-question pair belongs to Category, then ,otherwise . and Represents the number of categories and image-question pairs.
[0108] Combine the contrastive loss of fused embedding and the visual question answering classification loss into the visual question answering contrastive loss , calculated as follows:
[0109]
[0110] By adjusting , , and , balancing all losses. and learning rate , optimize the model through the Adam algorithm.
[0111] Furthermore, the performance of the method of this embodiment is verified by comparing with several state-of-the-art comparison methods, as shown in Table 1:
[0112] Table 1
[0113]
[0114] As can be seen from Table 1, the accuracy of the method of this embodiment, namely PGCL, is considerable. From the average accuracy of all image-question pairs, PGCL achieved the highest value of 61.84%. Patch-TRM and ViLT achieved the second and third best performance respectively. The accuracy of Patch-TRM and ViLT was 0.42% and 0.70% worse than that of PGCL, respectively. For the SOC class (social science class) and IMG class (image context class), PGCL achieved the best performance of 69.40% and 62.72%, respectively. For the image-question pairs of G1-6 classes (belonging to grades 1 to 6), PGCL had an accuracy of 61.44%, which was 0.72% and 3.40% better than the second best model ViLT and the third best model Patch-TRM. The highest performance (67.53%) facing the NO class was obtained by PGCL. In addition, for NAT (Natural Science), LAN (Language Science), TXT (Text Context) and G7-12 (Classes from Grade 7 to Grade 12), the predicted results of PGCL are acceptable.
[0115] In addition to achieving good performance in each class, PGCL also outperforms all the comparison methods. The accuracy of PGCL in all classes is much higher than Random chance, Top-Down based Q, Top-Down based , Top-Down based Q+M, Top-Down based Q+ +M and MCAN. From Top-Down based Q and Top-Down based The comparison results show that, (Image context) is more important in most categories, including SOC, TXT, IMG, G7-12, and Avg. Similarly, Top-Down based Q+ +M is much better than Top-Down based Q+M, indicating It is conducive to model learning.
[0116] The embodiments described above are only descriptions of the preferred embodiments of the present invention and are not intended to limit the scope of the present invention. Without departing from the design spirit of the present invention, various modifications and improvements made to the technical solutions of the present invention by ordinary technicians in this field should all fall within the protection scope determined by the claims of the present invention.
Claims
1. A visual question answering method based on prompt guidance and self-supervised contrastive learning, characterized in that: include: Get the target question; Input the target question into a preset visual question answering model and output a predicted answer, wherein the visual question answering model includes: a prompt sample generation module, an embedding extraction module, an embedding fusion module, and an answer prediction module; The prompt sample generation module is used to construct a prompt template, and generate a prompt sample based on the prompt template combined with information of the image-question pair, wherein generating a prompt sample based on the prompt template combined with information of the image-question pair includes: Combining the prompt template with the attribute information and interference information of the image-question pair and inputting the result into a classifier to generate the prompt samples, wherein the prompt samples include prompt positive sample and prompt negative sample; The embedding extraction module is used to guide the mining of text information and image information in the image-question pair based on the prompt sample to obtain text embedding and visual embedding; The embedding extraction module obtains the text embedding including: The positive example sample and the negative example sample are respectively compared with the text input and Integrate and obtain Input and Input, where the It consists of questions, context, and multiple options. For the chain of thought; Regarding the Input and The input is marked separately and then input into the pre-trained BERT model to obtain Text embedding and Text embedding; The embedding extraction module obtains the visual embedding including: Inputting the image and the prompt positive sample into the pre-trained VILT model in pairs to obtain a first visual input, and concatenating and integrating the first visual input to obtain a first visual embedding; After visual enhancement, the image is paired with the prompt positive sample and input into a pre-trained VILT model to obtain a second visual input, and the second visual input is spliced and integrated to obtain a second visual embedding; The embedding fusion module is used to perform attention mechanism enhancement on the text embedding and the visual embedding, and fuse the enhanced text embedding and the visual embedding to obtain a fused embedding; The answer prediction module is used to predict the answer of the visual question answering task based on the fused embedding; The visual question answering model also includes a model optimization module, which is used to optimize the model by calculating the loss. The method for calculating the loss is: , , , , in, Contrastive loss for visual question answering; , , and is the loss parameter; is the contrast loss for QCM input; is the contrast loss for CoT input; is the contrast loss for fusion embedding; is the loss between the prediction result and the label; exp is an exponential function with the natural constant e as the base; is the i-th prompt positive sample learned by the fully connected neural network Text embedding; is the rth positive example learned by the fully connected neural network Text embedding; and ∈ , ∈ , is the total number of positive examples; is the jth tip counterexample sample learned by the fully connected neural network Text embedding, is the total number of counterexample samples; is the temperature parameter, is the i-th prompt positive sample learned by the fully connected neural network Text embedding; is the rth positive example learned by the fully connected neural network Text embedding; is the jth tip counterexample sample learned by the fully connected neural network Text embedding; is the first fused embedding of the ith image, is the second fused embedding of the i-th image; is the first fused embedding of the jth image; and ∈ , ∈ , is the total number of images; , For the The image-question pair belongs to The prediction results of each category; , For the The image-question pair belongs to The label of the category, if The image-question pair belongs to Category, then ,otherwise ; is the total number of categories, is the total number of image-question pairs.
2. The visual question answering method based on prompt guidance and self-supervised contrastive learning according to claim 1, characterized in that: The embedding fusion module performs attention mechanism enhancement on the text embedding and the visual embedding, including: The text embedding is regarded as a query set and the visual embedding is regarded as a key-value set to perform cross-attention mechanism enhancement to obtain an enhanced visual embedding; The visual embedding is regarded as a query set and the text embedding is regarded as a key-value set to perform cross-attention mechanism enhancement to obtain the enhanced text embedding.
3. The visual question answering method based on prompt guidance and self-supervised contrastive learning according to claim 2, characterized in that: The fusion of enhanced text embedding and visual embedding includes: The enhanced text embedding and visual embedding are concatenated and input into the fully connected neural network to obtain the fused embedding, which is: , in, is the first fusion embedding, is the second fusion embedding, FCN is a fully connected neural network, For front and back connection, It is the text embedding enhanced by the cross attention mechanism. is the first visual embedding enhanced by the cross-attention mechanism, It is the second visual embedding enhanced by the cross-attention mechanism.
4. The visual question answering method based on prompt guidance and self-supervised contrastive learning according to claim 3, characterized in that: The method in which the answer prediction module predicts the answer to the visual question answering task based on the fused embedding is: in, To predict the results, is the activation function.
