Image subtitle generation model based on structure and instruction fine tuning large language model

By introducing the CLIP visual encoder, key-value pair module and residual connection module into the image subtitle generation model, and using the few-shot data set for feature optimization, the problem of insufficient generalization ability of image subtitle generation in specific fields in the existing technology is solved. , achieving efficient and accurate subtitle generation effects.

CN118747893APending Publication Date: 2024-10-08HUZHOU UNIVERSITY

Patent Information

Application Number
CN202410856069.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-28
Publication Date
2024-10-08

AI Technical Summary

Technical Problem

Existing image subtitle generation models based on mapping networks do not have strong generalization capabilities in specific fields, and the data collection cost and time are high. They lack efficient image subtitle generation methods for specific fields.

Method used

Propose a large language model ClipCap++ based on structure and instruction fine-tuning. By introducing the CLIP visual encoder, key-value pair module, residual connection module and language model, the few-shot data set is used for feature optimization and weight adjustment to generate more accurate images. subtitle.

Benefits of technology

The ClipCap++ model performs superiorly in image subtitle generation in specific fields, improves the accuracy and generalization ability of generation, reduces training time and parameter scale, and significantly improves the performance of subtitle generation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118747893A_ABST
    Figure CN118747893A_ABST
Patent Text Reader

Abstract

The invention discloses an image caption generation model based on a structure and instruction fine tuning large language model, which is realized through a ClipCapp + + model, and the ClipCapp + + model comprises a CLIP visual encoder, a key value pair module, a residual connection module, a mapping network and a language model. In the image subtitle generation period of the ClipCapp + + model, a contrast language-image pre-training encoder CLIP can be firstly utilized to greatly save training resources and time cost, and after the CLIP is frozen for pre-training, information from a feed-shot data set is introduced and stored in a key value pair model. And carrying out residual connection on the pre-trained visual features and the optimized feature information to prevent the model from over-fitting few-sample data. For a given test image, in the reasoning process of the ClipCap+ + model, image embedding can be obtained through a CLIP visual encoder to serve as a hard prompt, then entity perception soft prompt is constructed through a key value pair module, and finally image description is generated through GPT.
Need to check novelty before this filing date? Find Prior Art

Description

[Technical field]

[0001] The present invention relates to the technical field of graph-generated text, in particular to the technical field of graph-generated text based on mapping networks. [Background technology]

[0002] Images and texts are the main means for people to obtain information through vision. Images are vivid and can leave a deep impression on people. Texts are highly generalizable and can describe and convey information in a concise form. With the continuous development of image classification and target detection and recognition technology, computers' ability to understand images is constantly improving. At the same time, computers' ability to process natural language and processing methods are becoming more and more perfect, making it possible to generate information from images to text descriptions.

[0003] Traditional image-to-text technologies are mainly divided into three categories: retrieval-based methods, template-based methods, and deep learning-based methods. Retrieval-based methods require a fixed title-sentence library and extract image features to find matching sentences in the sentence library. This method is limited by the accuracy of similarity calculation, and the generated descriptions are relatively limited. The work proposed by Farhadi et al. (Farhadi A, Hejrati M, Sadeghi MA, et al. Every picture tells a story: Generating sentences from images [C] / / European conference on computer vision. Springer, Berlin, Heidelberg, 2010: 15-29) to use Curran and Clark parser as templates to generate sentences is a representative work of template-based methods. This method can increase the diversity of sentences, but the generated content is single and relatively fixed. Deep learning-based methods have evolved from two-stage non-end-to-end methods (generating labels by CNN classification or object detection and then inputting them into RNN to generate sentences) to end-to-end methods (directly inputting feature maps generated by CNN into RNN to achieve end-to-end training). The end-to-end image captioning method has been continuously improved from the original basic framework of combining CNN and RNN, such as introducing attention mechanism, replacing RNN with Transformer, and using generative adversarial network (GAN) to generate sentences and distinguish them. In addition, there are also studies on further optimizing image captioning by optimizing evaluation indicators through reinforcement learning or generating multi-emotional captions.

[0004] Mapping network-based methods are a new hot research area in image-to-text technology. They can use transfer learning, use existing pre-trained models for feature encoding, and keep model parameters frozen during visual language pre-training, thereby reducing training costs. The early proposed method of extracting visual features using frozen object detectors (Li J, Li D, Savarese S, et al. Blip-2: Bootstrapping language-image pre-training with frozen image encoders and large language models [J]. arXiv preprint arXiv: 2301.12597, 2023) and the recent work on frozen pre-trained image encoders for CLIP pre-training are both mapping network-based methods.

[0005] The goal of automatic image captioning (abbreviated as image-to-captioning) is to describe the salient information conveyed by an image in an accurate and meaningful sentence. The challenge of image captioning lies in understanding the interaction between image and text, which is a dependency deeply rooted in the image-text pair. Figure 1 As shown in the figure, the ClipCap model based on the mapping network (Mokady R, Hertz A, Bermano A H. ClipCap: Clip prefix for image captioning [J]. arXiv preprint arXiv: 2111.09734, 2021) can train a mapping network that bridges the semantic gap between CLIP and the language model GPT-2 when both are frozen, thereby generating meaningful captions. In order to extract a fixed-length prefix, the ClipCap model first trains a mapping network based on a lightweight transformer from the embedding space of CLIP and the learning constants of GPT-2, and then uses GPT-2 to generate meaningful captions (describing that the image is composed of one or several main objects and the spatial relationship between objects). Although the ClipCap model is currently the most widely used and best-performing image-to-text model, it is difficult to achieve satisfactory results on specific tasks, and the model's generalization is not strong.

[0006] In addition, there are two main sources of data for existing image-to-text technologies: one is to use existing image-text data, and the other is to create image-text pairs from independent data sources. The former is based on deep learning technology and requires a large amount of labeled data for training. Due to problems such as long-tail distribution, annotation noise, and increasing labeling costs, it is challenging to collect image-text pair data. The latter is implemented using a mapping network-based method (Fei J, Wang T, Zhang J, et al. Transferable decoding with visual entities for zero-shot image captioning [C] / / Proceedings of the IEEE / CVF International Conference on Computer Vision. 2023: 3136-3146), that is, using off-the-shelf multimodal models and large language models as encoders and decoders, which has problems such as low quality and exposure bias in generating descriptions for specific tasks.

[0007] In summary, compared with manually labeled and web-scraped datasets, synthetic data is more efficient in terms of cost and time, but the generalization ability of cross-domain subtitle generation for specific fields is not strong, and the generated text description accuracy is low. At present, there is no method specifically designed to integrate multimodal pre-training and large language models in specific fields to handle image subtitle generation tasks, which needs to be solved urgently. [Summary of the invention]

[0008] The purpose of the present invention is to solve the problems in the prior art and propose an image subtitle generation model based on a large language model fine-tuned by structure and instructions, which can solve the problem that existing mapping network-based models such as ClipCap cannot adapt to specific fields.

[0009] To achieve the above object, the present invention is implemented through the following technical solutions:

[0010] The image caption generation model based on structure and instruction fine-tuning of a large language model is implemented by the ClipCap++ model, which includes a CLIP visual encoder, a key-value pair module, a residual connection module, a mapping network and a language model, and the training process includes the following steps:

[0011] a) encoding visual information of a test image using the visual encoder from the frozen CLIP model, thereby obtaining pre-trained visual information;

[0012] b) firstly introduce a few-shot dataset of the corresponding field and store the visual information and label information in the key-value pair model, and then optimize the features of the test image using the visual information and label information, so as to obtain optimized feature information;

[0013] c) using the residual connection module to perform residual connection on the pre-trained visual information and the optimized feature information, thereby obtaining a joint embedding;

[0014] d) passing the joint embedding through a mapping network to generate a prompt vector;

[0015] e) enabling the language model to output text description information according to the prompt vector.

[0016] Preferably, for a given set of image-text pairs training data For example, the training objective of the ClipCap++ model is defined as formula (1):

[0017]

[0018] in, is the text description of each training sample and the number of tokens is padded to the maximum length l; θ represents the trainable parameters of the model.

[0019] Furthermore, the condition is regarded as a prefix of the generated text, the language model is used to predict the next tag and the training objective of the ClipCap++ model is further described as formula (2) through formula (1):

[0020]

[0021] Preferably, in the steps a) to d), in order to obtain the image x i To extract visual information, first use the CLIP visual encoder of the frozen CLIP model to obtain the visual encoding f test , the information of the few-shot dataset in the corresponding field is integrated into the key-value pair module and the residual connection module to obtain the image vector, and then the mapping network is used to obtain k visual embedding vectors, and each vector is set It has the same dimension as the word embedding. Finally, the pre-trained visual information and the optimized feature information are connected to obtain the prompt vector, and the processing process is expressed as formula (3) and formula (4):

[0022]

[0023] Furthermore, during the training process, the language model is provided with a prefix vector The training goal is to predict the text token conditioned on the prefix in an autoregressive manner, and at the same time, the mapping network is trained using a cross entropy loss function as shown in formula (5):

[0024]

[0025] Preferably, for the key-value pair module, the visual representation of the image obtained by CLIP encoding is regarded as the key, and the label vector obtained by one-hot encoding is regarded as the value of the key; the model construction of the key-value pair module is implemented by formula (6):

[0026]

[0027] Among them, F train ∈R NK*C represents the visual representation obtained by the pre-trained CLIP model; L train ∈R NK*N Represents the label vector obtained based on one-hot encoding; in the few-shot dataset, it contains N types of training samples for image classification, and each category contains K annotated images I K ; The category label of the image is represented by L N .

[0028] Preferably, for the residual connection module, the residual rate is used to adjust the weight ratio of the CLIP visual coding and the optimized visual coding, and the adaptive adjustment of the CLIP visual coding is achieved by three matrix multiplications as shown in formula (7):

[0029]

[0030] Among them, f test ∈R 1*C W represents the normalized features of the test image generated by the CLIP encoder and performs similarity calculation with the key vector in the key-value pair module; C is the transformation vector generated from the pre-trained text encoder; FL_embed∈R 1*C Represents the generated intermediate vector; the similarity calculation formula is formula (8):

[0031]

[0032] Among them, β is used to control the sharpness of affinity; A∈R 1*NK Represents the obtained similarity value.

[0033] Furthermore, for the residual connection module, the weight ratio of the CLIP visual coding and the optimized visual coding is adaptively adjusted by the residual ratio as shown in formula (9):

[0034] clip_embed=αAL train W C +f test (9);

[0035] Among them, α represents the residual ratio.

[0036] Preferably, the mapping network consists of a fully connected layer, a learnable constant vector sequence and a text encoder, and the language model is an autoregressive language model.

[0037] Furthermore, the CLIP visual encoder is ResNet-50, the text encoder is a Transformer module, and the autoregressive language model is GPT-2 or GPT-4.

[0038] With the continuous development of the field of artificial intelligence, it is very necessary to apply the concept of transfer learning to incorporate pre-trained models (such as CLIP) into the image subtitle generation task. The present invention proposes a novel image-to-text model ClipCap++, which can integrate multimodal pre-training and large language models to simplify the subtitle generation process. The present invention forms a ClipCap++ model by fine-tuning the structure and instructions of the ClipCap model (introducing a key-value pair module and a residual connection module on the basis of the ClipCap model). The added key-value pair module and residual connection module can be used to improve the generalization ability of the model (the key-value pair module adopts a few-sample fine-tuning strategy so that the model can better identify images of a specific category; the residual connection module is used to adjust the weight ratio of the prior knowledge from the pre-trained model and the fine-tuned visual information), so that the model has migration ability, effectively improving the accuracy of the model in generating image subtitles in specific fields.

[0039] During the image caption generation, the ClipCap++ model can first use the contrastive language-image pre-trained encoder CLIP to greatly save training resources and time costs. After freezing CLIP for pre-training, the information from the few-shot dataset is introduced and stored in the key-value pair model, and then the pre-trained visual features are residually connected with the optimized feature information to prevent the model from overfitting to the few-shot data. For a given test image, during the inference process, the ClipCap++ model can first use the CLIP visual encoder to obtain the image embedding as a hard prompt, then use the key-value pair module to build entity-aware soft prompts, and finally generate the image description through GPT. Quantitative analysis shows that the ClipCap++ model not only has a subtitle generation capability that exceeds the current best-performing ClipCap model, but is also basically consistent with the ClipCap model in terms of training time and parameter scale (several orders of magnitude less than the training time of the current deep learning-based image-to-text model).

[0040] In general, the beneficial effects of the present invention are as follows:

[0041] 1) The present invention discloses a fast and efficient lightweight image-to-text technology, which can generate image-text pairs by freezing the multimodal pre-trained model and the large language model and adopting the transfer learning method, thereby effectively reducing the pre-training time of the model;

[0042] 2) The present invention improves the original ClipCap model architecture by adding a key-value pair module and a residual connection module, thereby realizing the image-to-text task in a specific field, and being able to more comprehensively understand the image scene and generate meaningful text descriptions;

[0043] 3) The ClipCap++ model disclosed in the present invention has the best performance in terms of accuracy, training time, parameter scale, and transferability compared with the current advanced image-to-text models (such as the BUTD model, OSCA model, VLP model, and ClipCap model) (it has significant advantages in in-domain, near-domain, and cross-domain image subtitle generation), proving the effectiveness of lightweight image-to-text technology driven by synthetic data.

[0044] The features and advantages of the present invention will be described in detail through embodiments in conjunction with the accompanying drawings.

Brief Description of the Drawings

[0045] Figure 1 It is a process diagram of the existing ClipCap model based on mapping network to generate subtitle description;

[0046] Figure 2 It is a framework diagram of the ClipCap++ model of the present invention;

[0047] Figure 3 is the test image 1 of Table 4 of the embodiment;

[0048] Figure 4 is the test image 2 of Table 4 of the embodiment;

[0049] Figure 5 is the test image 3 of Table 4 of the embodiment;

[0050] Figure 6 is the test image 4 of Table 4 of the embodiment;

[0051] Figure 7 is a test diagram showing the influence of the values ​​of the hyperparameters of the embodiment on the recognition accuracy;

[0052] Figure 8 This is a test chart of the effect of prefix length on subtitle generation performance in an embodiment. [Specific implementation method]

[0053] The present invention is based on the image subtitle generation method of fine-tuning a large language model with structure and instructions, which is implemented through the ClipCap++ model.

[0054] 1) The overall framework of the ClipCap++ model:

[0055] The present invention makes a series of improvements on the ClipCap model (adding a key-value pair module and a residual connection module), and obtains an image caption generation model that integrates few-shot information and is named ClipCap++ model. Figure 2 ,The ClipCap++ model is a model that combines the CLIP visual encoder, key-value pair module, residual connection module, mapping network and language model (GPT-2) for image caption generation.

[0056] For the ClipCap++ model, during the training process, the visual encoder of the frozen CLIP (Contrastive Language-Image Pretraining) model is first used to encode the visual information of the test image, thereby obtaining the pre-trained visual information. Since the visual embedding and text embedding in the CLIP model are interrelated, this correlation can greatly save training resources and time costs. Then, the information from the few-shot dataset is introduced (the few-shot dataset belongs to the field corresponding to the test image), the visual information and label information are stored in the key-value pair model, and the visual information and label information are used to optimize the features of the test image, thereby obtaining the optimized feature information. Next, the residual connection module is used to connect the pre-trained visual information with the optimized feature information, thereby obtaining the joint embedding (used to prevent the model from overfitting to the few-sample data). Then, the joint embedding is passed through the mapping network to generate a sequence of prompt vectors. The prefix of the prompt vector is a fixed-size embedding sequence that can be input into the language model after being connected with the title text embedding, and the language model is finally responsible for outputting the text description information. In the inference stage, the language model starts from the CLIP prefix and generates the title word by word. This solution narrows the gap between the visual and textual worlds by fine-tuning a simple mapping network. In addition, the mapping network consists of a fully connected layer, a learnable constant vector sequence, and a Transformer module, which can act as a bridge between the image space and the text space, responsible for mapping the image vector into the text space to obtain a prompt vector sequence. In order to ensure feasibility, the present invention also chooses to use GPT-2 (Radford A, Wu J, Child R, et al. Language models are unsupervised multitask learners [J]. OpenAI blog, 2019, 1 (8): 9.) proposed by Radford et al. as the language model. GPT-2 can generate corresponding text descriptions based on the prompt vector sequence.

[0057] 2) Training objectives of ClipCap++ model:

[0058] The main architecture of the ClipCap++ model is an encoder-decoder structure based on the mapping network. For a series of given image-text pair training data Generally speaking, the goal of ClipCap++ model training is to generate a meaningful text description for a new input image.

[0059] First, for each text description in the training sample, we pad its token number to the maximum length l, that is, The training objective is defined as formula (1):

[0060]

[0061] Among them, θ represents the trainable parameters of the model.

[0062] Both CLIP's adversarial training and GPT-2's autoregressive pre-training adopt similar ideas (i.e., learning representations by maximizing similarity metrics). CLIP's rich semantic embedding contains the most basic visual data that can be used as a condition for the model. The present invention regards the condition as a prefix for generating text. In addition, since the required semantic information is encapsulated in the prefix, the present invention uses the autoregressive language model GPT-2 to predict the next tag, and further describes the training objective from formula (1) to formula (2):

[0063]

[0064] In order to get the image x i To extract visual information, first use the pre-trained CLIP model’s visual encoder to get the visual encoding f test , the information of the few-shot data in the corresponding field is integrated into the image vector through the key-value pair module and the residual connection module, and then the mapping network (FC) is used to obtain k visual embedding vectors, and each vector is Has the same dimension as word embedding. The above process is expressed as formula (3):

[0065]

[0066] Next, the obtained visual embedding is concatenated with the caption embedding to obtain the prefix vector (hint vector) as shown in formula (4):

[0067]

[0068] During the training process, the present invention provides the language model with a prefix vector The training goal is to predict the text token conditioned on the prefix in an autoregressive manner. Here, the present invention chooses to use a simple and effective cross entropy loss function as shown in formula (5) to train the mapping network:

[0069]

[0070] 3) Key-value pair module of ClipCap++ model:

[0071] Based on the ClipCap model, the present invention adds a key-value pair module, so as to use the key-value pair module to extract the required new knowledge from the few-shot dataset and update the prior knowledge stored in CLIP. In the key-value pair module, the visual representation of the image obtained by CLIP encoding is regarded as the key, and the label vector obtained by one-hot encoding is regarded as the value of the key. The construction process of the key-value pair model is shown in formula (6):

[0072]

[0073] Among them, F train ∈R NK*C represents the visual representation obtained by the pre-trained CLIP model; L train ∈R NK*N Represents the label vector obtained based on one-hot encoding; in a given few-shot dataset, it contains N types of training samples for image classification, and each category contains K annotated images I K ; The category label of the image is represented by L N .

[0074] The traditional way of generating image captions based on pre-trained visual language models (VLM) and large language models (LLM) has the problem of low quality of generated captions in specific fields. In this model, the CLIP module can use visual perception language to guide GPT-2 to generate captions related to images, while the key-value pair module can enhance the model's ability to generate captions for specific fields by storing information of a few-sample datasets. During the reasoning process, the features generated from the test examples will be regarded as queries, and the information in the key-value pair module will be retrieved and aggregated to optimize the embedded representation. This is similar to the attention mechanism in Transformer, which can effectively improve the ability of image-to-text tasks to recognize specific information in specific fields.

[0075] 4) Residual connection module of ClipCap++ model:

[0076] In order to adjust the influence ratio of the key-value pair module on the visual perception language guidance of the overall model, the present invention introduces a residual connection module in the ClipCap++ model. Specifically, after the key-value pair module, the residual rate can be used to adjust the weight ratio of the CLIP visual encoding and the optimized visual encoding. In addition, the adaptive adjustment of the CLIP visual encoding can be achieved by three matrix multiplications as shown in formula (7):

[0077]

[0078] Among them, f test ∈R 1*Crepresents the normalized features of the test image generated by the CLIP encoder, and performs similarity calculation with the key vector in the key-value pair module; W C is the transformation vector generated from the pre-trained text encoder; FL_embed∈R 1*C represents the generated intermediate vector; the calculation formula of the correlation measure is formula (8):

[0079]

[0080] Among them, β is used to control the sharpness of affinity (when β is large, the training sample that is most similar to the test image in the embedding space has a greater impact on the prediction, and the role of the exponential function is to convert the similarity into a non-negative value); A∈R 1*NK Represents the obtained similarity value.

[0081] Next, as shown in formula (9), the residual ratio is introduced to adaptively adjust the weight ratio of CLIP visual encoding and optimized visual encoding:

[0082] clip_embed=αAL train W C +f test (9);

[0083] Among them, α represents the residual ratio (the larger α is, the larger the proportion of the few-shot dataset is). As a rule of thumb, if the domain gap between the pre-trained and downstream few-shot tasks is large, α is set to a larger value. In this case, more knowledge from the few-shot dataset is needed, otherwise α is set to a smaller value. In other words, it is very important to experimentally verify the values ​​of α and β for different few-shot datasets.

[0084] During the reasoning process, given a test image, the present invention uses the image embedding obtained by the visual encoder of CLIP as a hard prompt, and constructs entity-aware soft prompts through the key-value pair module. Due to the strong transferability from training-agnostic hard prompts, the framework of the present invention is robust to changes in the image domain and the model's image recognition ability for specific fields can be further improved through soft prompts from entity perception. An excellent image-to-text model should strike a balance between soft prompts and hard prompts. Specifically, weak visual guidance often leads to modal bias problems, that is, the language prior in LLM dominates the decoding process, resulting in descriptions that are unrelated to the corresponding image; and when the key-value pair cache module accounts for a large proportion, the learnable (soft) visual prompts are prone to overfitting, resulting in poor performance of the model in describing various objects (visual entities), which in turn may cause object hallucination problems in the generated subtitles. The residual connection module proposed in this paper can significantly reduce the problems of modal bias and object hallucination when describing images containing new objects by adjusting the residual ratio α and sharpness β.

[0085] 5) Experimental test of ClipCap++ model:

[0086] 5.1) Dataset:

[0087] This paper evaluates the subtitle generation capability of the proposed model ClipCap++ on different types of datasets through a large number of experiments. This experiment selected three classic datasets - NoCaps (Agrawal H, Desai K, Wang Y, et al. Nocaps: Novel object captioning at scale [C] / / Proceedings of the IEEE / CVF international conference on computer vision. 2019: 8948-8957), COCO (Lin TY, Maire M, Belongie S, et al. Microsoft coco: Common objects in context [C] / / Computer Vision–ECCV 2014: 13th European Conference, Zurich, Switzerland, September 6-12, 2014, Proceedings, Part V 13. Springer International Publishing, 2014: 740-755) and Conceptual Captions (Sharma P, Ding N, Goodman S, et al. Conceptual captions: A cleaned, hypernymed, image alt-text dataset for automatic image captioning[C] / / Proceedings of the 56th Annual Meeting of the Association for ComputationalLinguistics(Volume 1:Long Papers).2018:2556-2565). The model is trained on the COCO dataset; the NoCaps dataset contains only the validation set and the test set, which aims to evaluate the generalization ability of the model to new classes and concepts that have not been seen before. It is divided into three categories: in-domain, near-domain, and out-of-domain. The images in the in-domain dataset belong to known classes (classes in the training set), the images in the near-domain dataset belong to known classes or new classes similar to known classes, and the out-of-domain dataset only contains images of new classes that have not been seen before; the image styles of the Conceptual Captions dataset are more diverse, not limited to specific categories.

[0088] 5.2) Evaluation indicators:

[0089] In order to make a fair comparison with the best ClipCap model, the present invention continues to use BLEU (Kishore Papineni, Salim Roukos, Todd Ward, and Wei-Jing Zhu. Bleu: amethod for automatic evaluation of machine translation. In Proceedings of the 40th annual meeting of the Association for Computational Linguistics, pages 311–318, 2002), METEOR (Michael Denkowski and Alon Lavie. Meteoruniversal: Language specific translation evaluation for any target language. In Proceedings of the ninth workshop on statistical machine translation, pages 376–380, 2014), and CIDEr (Ramakrishna Vedantam, C Lawrence Zitnick, and Devi Parikh. Cider: Consensus-based image description evaluation. In Proceedings of the IEEE conference on computer vision and pattern recognition, pages 376–380, 2014). 4566–4575, 2015), SPICE (Peter Anderson, Basura Fernando, Mark Johnson, and Stephen Gould. Spice: Semanticpropositional image caption evaluation. In European conference on computer vision, pages 382–398. Springer, 2016) and ROUGE-L (Chin-Yew Lin and Franz Josef Och.Automatic evaluation of machine translation quality using longest common subsequence and skip-bigram statistics. In Proceedings of the 42nd Annual Meeting of the Association for Computational Linguistics (ACL-04), pages 605–612, 2004) as evaluation indicators for image caption generation. Specifically, three indicators, ROUGE-L, CIDEr, and SPICE, were used on the COCO dataset; two indicators, CIDEr and SPICE, were used on the nocaps dataset; and five indicators, BLEU, METEOR, ROUGE-L, CIDEr, and SPICE, were used on the ConceptualCaptions dataset. .

[0090] In addition, the present invention also records the training time and the number of hyperparameters for each method. Because these two factors are very important for image caption generation. Optimizing training time can quickly obtain new models for new data, create model collections, and reduce energy consumption. The number of trainable parameters is a common metric to indicate the feasibility of a model. Similar to other works, this invention discloses the training time in GPU hours and the type of GPU used.

[0091] 5.3) Experimental setup:

[0092] The CLIP backbone of the ClipCap++ model uses ResNet-50 (Koonce B, Koonce B. ResNet 50 [J]. Convolutional neural networks with swift for tensorflow: image recognition and dataset categorization, 2021: 63-72) as the visual encoder and Transformer (Han K, Xiao A, Wu E, et al. Transformer in transformer [J]. Advances in neural information processing systems, 2021, 34: 15908-15919) as the text encoder; the key-value pair module uses the ImageNet dataset as the source of few-sample information; in terms of prompt design, it draws on Tip-adapter (Zhang R, Fang R, Zhang W, et al. Tip-adapter: Training-free clip-adapter for better vision-language modeling [J]. arXiv preprint arXiv:2111.03930,2021), 7 templates are input into the CLIP text encoder, and the average is taken as the final prompt. The 7 prompt templates are "itap ofa[CLASS].", "abadphoto ofthe[CLASS].", "a origami[CLASS].", "aphotoofthe large[CLASS].", "a[CLASS]in a video game.", "art ofthe[CLASS]." and "aphotoofthe small[CLASS].". The present invention uses CLIP-style preprocessing to adjust the short side of the cropped image to 224 while keeping its original aspect ratio unchanged. In addition, the model hyperparameters are set to lr=0.001, augment_epoch=10 and train_epoch=20. After ablation experiments, we obtained the optimal values ​​of α and β to be 1.55 and 0.65, respectively. Considering the feasibility of the experiment, the language model adopts GPT-2 (including an 8-layer Transformer network with 8 attention heads and 768-dimensional hidden vectors, and the length of the learnable soft prompt is set to 10). During the training process, we freeze the text encoder of CLIP. For the caption generation task, we use beam search with a beam size of 5.

[0093] As described above, the present invention conducts experiments on three widely used image caption datasets, NoCaps, COCO, and ConceptualCaptions. For the COCO dataset, we follow the commonly used Karpathy split method (Karpathy A, Fei-Fei L. Deep visual-semantic alignments for generating image descriptions [C] / / Proceedings of the IEEE conference on computer vision and pattern recognition. 2015: 3128-3137) to divide the dataset into a training set and a test set for performance evaluation; for NoCaps, in order to verify the transfer ability of the model, we train the model on the COCO training set and test the results on the NoCaps validation set; for the Conceptual Captions dataset, we use all the data in it as a test set for performance evaluation.For caption generation methods, we compared the following methods: 1) Classic supervised methods, including BUTD (Anderson P, He X, Buehler C, et al. Bottom-up and top-down attention for image captioning and visual question answering [C] / / Proceedings of the IEEE conference on computer vision and pattern recognition. 2018: 6077-6086), OSCAR (Li X, Yin X, Li C, et al. Oscar: Object-semantics aligned pre-training for vision-language tasks [C] / / Computer Vision–ECCV 2020: 16th European Conference, Glasgow, UK, August 23–28, 2020, Proceedings, Part XXX 16. Springer International Publishing, 2020: 121-137) and VLP (Luowei Zhou, Hamid Palangi, Lei Zhang, Houdong Hu, Jason Corso, and Jianfeng Gao.Unified vision-language pretraining for imagecaptioning and vqa.In Proceedings of the AAAI Conference on ArtificialIntelligence,volume 34,pages13041–13049,2020), and BUTD uses LSTM to generate subtitles, while VLP and Oscar use BERT to generate subtitles; 2) Lightweight paired subtitle methods, including ClipCap model and ClipCap++ model, and use GPT-2 for subtitle generation based on CLIP encoding.

[0094] 5.4) Experimental results and analysis:

[0095] 5.4.1) Comparative experiment:

[0096] Tables 1 to 3 below give the quantitative evaluation results of the ClipCap++ model and the comparison model on three data sets. Among them, Table 1 shows the performance of different models in generating subtitles for in-domain images, Table 2 shows the performance of different models in generating subtitles for near-domain images, and Table 3 shows the performance of different models in generating subtitles for out-of-domain images, and the best performance is marked in bold font. It can be seen from Tables 1 to 3 that in terms of accuracy, the performance of the ClipCap++ model on all data sets exceeds that of traditional graph-generated text models (BUTD, OSCA and VLP) and the current best model ClipCap. This shows that the two major improvement measures (key-value pair module and residual connection module) proposed in the present invention have a positive effect on graph-generated text. In terms of training time and parameter scale, the ClipCap++ model achieves an effect comparable to the current best graph-generated text model ClipCap, and the training time is reduced by several orders of magnitude compared to the traditional graph-generated text model. It should be emphasized that this is still under the condition of using a lower-level GPU. This shows that the ClipCap++ model is a lightweight graph-generated text model. In terms of transferability, the ClipCap++ model not only has an absolute advantage in generating in-domain image captions, but also shows superior performance in near-domain and out-of-domain tests, which shows that the ClipCap++ model has good transferability.

[0097] Table 1 Experimental results of different models on COCO dataset

[0098]

[0099]

[0100] Table 2 Experimental results of different models on the NoCaps dataset

[0101]

[0102] Table 3 Experimental results of different models on the Conceptual Captions dataset

[0103]

[0104] 5.4.2) Visual analysis:

[0105] Table 4 below shows the image caption generation effects of the ClipCap++ model, the comparison model ClipCap, and the multimodal large language model Gpt-4 on a specific category (tissues) of the ImageNet dataset (taking the production of English text as an example). Among them, the wrong objects generated by the model are marked in bold font, and the correct objects generated are marked in underline font. It can be seen from Table 4 below that the ClipCap model is prone to generating wrong information. This may be because the training process of the ClipCap model does not involve images of the tissue category. Although Gpt-4 can generate richer text description information, it also ignores the entity information in this specific field (failed to identify the tissue class). This is because it is a pre-trained model and has not been fine-tuned for this field. The accuracy of the model ClipCap++ in generating captions in this field is very high. This is due to the key-value pair module introduced in the model of this paper (this module can use few-shot information to fine-tune the model, so that the model is familiar with the new domain knowledge, thereby generating more accurate text descriptions for new domain images). In addition, test images 1 to 4 in Table 4 below can be referred to respectively. Figures 3 to 6 .

[0106] Table 4 Example comparison of different models in image caption generation

[0107]

[0108] 5.4.2) Parameter sensitivity experiment:

[0109] In order to verify the influence of model parameters on the image caption generation performance, the present invention conducted a series of experiments. Figure 7 The effects of changes in the residual ratio (α) and affinity sharpness (β) in the key-value pair module on the accuracy of image caption generation are shown. Figure 7 It can be seen that when β is less than 0.31, while keeping β unchanged, if α is increased, the accuracy of the model will gradually increase, and when α = 1.55, the accuracy will no longer increase; next, keeping α unchanged, if β is increased, the accuracy of the model will be improved, and when β = 0.31, the accuracy will no longer increase; at this time, if α is increased again, the accuracy of the model will no longer change (this indicates that the model has reached the optimal stable state). Therefore, this experiment fixes the values ​​of α and β to 1.6 and 0.31 respectively.

[0110] Table 5 below shows the effect of the number of image categories used in few-shot fine-tuning on the accuracy of image caption generation. As can be seen from Table 5 below, at the beginning, as the number of image categories used for fine-tuning increases, the model performance gradually increases; when the number of categories increases to 16, the model performance no longer improves if the number of fine-tuning image categories continues to increase (this indicates that the model training has reached saturation at this time). Therefore, in this experiment, the number of image categories used in the model fine-tuning phase is set to 16.

[0111] Table 5. The impact of the number of small sample classes on recognition accuracy

[0112]

[0113] Table 6 below shows the effect of the learning rate (lr) of model training on the accuracy of image caption generation. As can be seen from Table 6 below, when the value of lr is 0.1, the parameter update step of the model is too large, causing the model to skip the local minimum of the loss function during training, thus causing abnormal values ​​in the recognition accuracy; when the value of lr is 0.0001, the model converges too slowly and cannot achieve the best model performance within a limited time; when the value of lr is 0.001, the model has the best performance. Therefore, in this experiment, the learning rate of model fine-tuning training is uniformly set to 0.001.

[0114] Table 6 Effect of learning rate on recognition accuracy

[0115]

[0116] Figure 8 The effect of the prefix length generated by the mapping network on the subtitle generation performance is demonstrated, and the experiment shows the two performance indicators BLEU@4 and CIDEr on the model's early training set (solid line) and test set (dashed line). Among them, BLEU represents a bilingual evaluation auxiliary tool, which is used to compare the degree of overlap between candidate translations and reference translations. In this experiment, it is used to evaluate the consistency of images and generated texts; CIDEr represents a consensus-based image description evaluation, which is used to calculate the cosine of the angle between the image vector and the generated text vector, and thus obtain the similarity between the image and the generated text. From Figure 8 It can be seen that a small prefix length will produce poor results (because the model's expressive power is insufficient, while a long prefix length will lead to overfitting of the model); when the model prefix length is 10, the model works best. Therefore, in this experiment, the prefix length is set to 10.

[0117] The above embodiments are intended to illustrate the present invention, not to limit the present invention. Any solution that is a simple transformation of the present invention belongs to the protection scope of the present invention.

Claims

1. Image caption generation method based on structure and instruction fine-tuning of large language model, Features: It is implemented by the ClipCap++ model, which includes a CLIP visual encoder, a key-value pair module, a residual connection module, a mapping network and a language model, and the training process includes the following steps: a) encoding visual information of a test image using the visual encoder from the frozen CLIP model, thereby obtaining pre-trained visual information; b) firstly introduce a few-shot dataset of the corresponding field and store the visual information and label information in the key-value pair model, and then optimize the features of the test image using the visual information and label information, so as to obtain optimized feature information; c) using the residual connection module to perform residual connection on the pre-trained visual information and the optimized feature information, thereby obtaining a joint embedding; d) passing the joint embedding through a mapping network to generate a prompt vector; e) enabling the language model to output text description information according to the prompt vector.

2. The method for generating image captions based on a large language model fine-tuned by structure and instruction as claimed in claim 1, Features: For a given set of image-text pair training data For example, the training objective of the ClipCap++ model is defined as formula (1): in, is the text description of each training sample and the number of tokens is padded to the maximum length l; θ represents the trainable parameters of the model.

3. The image caption generation method based on structure and instruction fine-tuning of a large language model as claimed in claim 2, Features: Considering the condition as the prefix of the generated text, the language model is used to predict the next token and the training objective of the ClipCap++ model is further described as formula (2) through formula (1):

4. The method for generating image captions based on a large language model fine-tuned by structure and instruction as claimed in claim 1, Features: In the steps a) to d), in order to obtain the image x i To extract visual information, first use the CLIP visual encoder of the frozen CLIP model to obtain the visual encoding f test , the information of the few-shot dataset in the corresponding field is integrated into the key-value pair module and the residual connection module to obtain the image vector, and then the mapping network is used to obtain k visual embedding vectors, and each vector is set It has the same dimension as the word embedding. Finally, the pre-trained visual information and the optimized feature information are connected to obtain the prompt vector, and the processing process is expressed as formula (3) and formula (4):

5. The method for generating image captions based on a large language model fine-tuned by structure and instruction as claimed in claim 4, Features: During training, the language model is provided with prefix vectors The training goal is to predict the text token conditioned on the prefix in an autoregressive manner, and at the same time, the mapping network is trained using a cross entropy loss function as shown in formula (5):

6. The method for generating image captions based on a large language model fine-tuned by structure and instruction as claimed in claim 1, Features: For the key-value pair module, the visual representation of the image obtained by CLIP encoding is regarded as the key, and the label vector obtained by one-hot encoding is regarded as the value of the key; the model construction of the key-value pair module is implemented by formula (6): Among them, F train ∈R NK*C represents the visual representation obtained by the pre-trained CLIP model; L train ∈R NK*N Represents the label vector obtained based on one-hot encoding; in the few-shot dataset, it contains N types of training samples for image classification, and each category contains K annotated images I K ; The category label of the image is represented by L N .

7. The method for generating image captions based on a large language model fine-tuned by structure and instruction as claimed in claim 1, Features: For the residual connection module, the residual rate is used to adjust the weight ratio of CLIP visual coding and optimized visual coding. At the same time, the adaptive adjustment of CLIP visual coding is achieved by three matrix multiplications as shown in formula (7): Among them, f test ∈R 1*C W represents the normalized features of the test image generated by the CLIP encoder and performs similarity calculation with the key vector in the key-value pair module; C is the transformation vector generated from the pre-trained text encoder; FL_embed∈R 1*C Represents the generated intermediate vector; the similarity calculation formula is formula (8): Among them, β is used to control the sharpness of affinity; A∈R 1*NK Represents the obtained similarity value.

8. The method for generating image captions based on a large language model fine-tuned by structure and instruction as claimed in claim 7, Features: For the residual connection module, the weight ratio of the CLIP visual coding and the optimized visual coding is adaptively adjusted by the residual ratio as shown in formula (9): clip_embed=αAL train W C +f test (9); Among them, α represents the residual ratio.

9. The method for generating image captions based on a large language model fine-tuned by structure and instruction as claimed in claim 1, Features: The mapping network consists of a fully connected layer, a learnable constant vector sequence and a text encoder, and the language model is an autoregressive language model.

10. The method for generating image captions based on a large language model fine-tuned by structure and instruction as claimed in claim 9, Features: The CLIP visual encoder is ResNet-50, the text encoder is a Transformer module, and the autoregressive language model is GPT-2 or GPT-4.

Citation Information

Patent Citations

  • Visual knowledge question-answering method and system based on triple asymmetry and principle generation

    CN116881422A

  • Method for improving efficiency of adapting large language model to multi-modal task

    CN117194989A

  • Large model image-text generation method based on multi-modal information fusion

    CN117271816A

  • Lightweight multi-modal image description generation method based on CLIP encoder

    CN118069877A

  • Mobile television using lidar sensor and artificial intelligence

    KR1020250133067A

Cited By

  • Icon generation method, system and equipment and storage medium

    CN119201114A