Multi-modal transfer learning method for large language model
The frozen image encoder extracts visual features and learnable modal embedding mapping, combines the Adapter module and cross-attention layer, and uses the ∈-greedy algorithm to search for the best placement layer, which solves the problem of low transfer efficiency and multi-modal learning of large language models. For problems with high computational complexity, low-cost and efficient multi-modal transfer learning is achieved.
Patent Information
- Application Number
- CN202410982010.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-22
- Publication Date
- 2024-10-29
- Estimated Expiration
- 2044-07-22
AI Technical Summary
The general knowledge transfer efficiency of large language models in multi-modal learning is low and the computational complexity is high, resulting in limited efficiency and practicality in practical applications.
A frozen image encoder is used to extract multi-scale visual features, and feature splicing is performed through learnable modal embedding mapping and Adapter modules. It combines cross-attention layers and ∈-greedy algorithms to search for the best placement layer, reducing computational overhead and improving transfer. efficiency.
It achieves low-cost, efficient multi-modal transfer learning of large language models, significantly reduces the amount of training parameters and computing overhead, and improves the accuracy and efficiency of generation tasks.
Smart Images

Figure CN118863010A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of machine learning, and in particular to a multimodal transfer learning method for a large language model. Background Art
[0002] The current natural language processing and multimodal fields are facing the challenge of effectively transferring the general knowledge of large language models (LLMs) to vision-language (VL) tasks. Although large language models have made significant progress in processing language tasks, there are still some key issues when applying them to multimodal scenarios.
[0003] The difficulty of large language models in multimodal learning is mainly reflected in the transfer of their general knowledge. First, current multimodal learning methods usually require the use of large-scale pre-training methods to adapt to new multimodal tasks. This process is not only time-consuming, but also consumes a lot of computing resources, which restricts the flexibility and scalability of large language models in practical applications. Secondly, although the method of directly using linear mapping of image features to obtain text information to describe the image is simple, it raises the problem of computational complexity. Due to the high dimensionality of visual features, mapping them to the input sequence of a large language model will lead to a sharp increase in computational complexity, especially when processing large-scale image data. This problem becomes particularly significant. This makes the current multimodal transfer learning of large language models face severe tests in terms of efficiency and practicality in practical applications. Summary of the invention
[0004] The technical problem to be solved by the present invention is to provide a multimodal transfer learning method for large language models, so as to quickly transfer the general knowledge of large language models to specific downstream multimodal tasks in a low-cost and high-efficiency manner.
[0005] The present invention provides a multimodal transfer learning method for a large language model, comprising the following steps:
[0006] Step 1: Extract the multi-scale visual features F of the image Img in the multimodal task through the frozen image encoder CLIP-ViT [CLS] , F [CLS] Do a linear projection W t , encode the input text Txt through the large language model and obtain the corresponding feature F Txt , initialize two learnable modality embedding mappings W m Used to represent the pure text modality and image-text modality, the modality representation F is determined according to the modality contained in the training sample m ;
[0007] Step 2: Concatenate the features contained in different modalities to obtain the actual input features F of the large language model;
[0008] Step 3: Freeze the parameters of the large language model, set a multi-layer perceptron and two randomly initialized Adapter modules after each self-attention sublayer, the Adapter module is used to model the processing path of single-modal tasks and multi-modal tasks, and the multi-layer perceptron represents the modality F m Get the distribution weights of unimodal and multimodal tasks;
[0009] Step 4: Equip each layer with an independent cross-attention layer Generate fused cues using criss-cross attention layers and search for the best placement layer K of fused cues in the large language model;
[0010] Step 5: Extract the image features F from the visual encoder Img The plain text feature F corresponding to the output of the K-1th layer of the large language model txt Through the cross attention layer Get the corresponding fusion hint F P Then, F P The multi-scale visual features and text features corresponding to the output of the K-1th layer are added, and then sent to the optimal placement layer K for further interactive learning, and finally a large language model is obtained to generate text results for the input.
[0011] Furthermore, in step 2, the feature input to the large language model is represented as F, and c is the longest input sequence of the large language model:
[0012] F=[F m ; F [CLS] W t ; F Txt ], Image-Text
[0013] F=[F m ; F Txt ], plain text
[0014] If the length of F is less than c, it is padded with a padding vector; if it exceeds c, it is truncated.
[0015] Furthermore, in step 3, the Adapter module consists of a downsampling layer An upsampling layer And a SiLU activation function δ, the input of the Adapter module is defined as Then the calculation formula of the Adapter output O is:
[0016] O=X+U(δ(D(X)))
[0017] d his the intermediate dimension of the Adapter module, and is scaled to the text dimension d Txt 1 / 64 of
[0018] The multilayer perceptron consists of two linear projection matrices W1, W2 and an activation function σ. The weight [α1, α2] is calculated as:
[0019] [α1,α2]=Softmax(W2(σb1(W1(F m )+b1))+b2)
[0020] Among them, b1 and b2 are bias terms;
[0021] Then the expression of F through two Adapter modules in each layer is:
[0022]
[0023] Among them, F represents the sequence features of the large language model, and F' represents the weighted output features of the input series features of the large language model after passing through the two Adapter modules.
[0024] Furthermore, the step 4 specifically includes:
[0025] Step 41: Use the search method based on the ∈-greedy algorithm to regard each decoder layer of the large language model as a search space, assign a preference H to represent the probability of each decoder layer being selected, and equip each layer with an independent cross attention layer.
[0026] Step 42: During each training step t, randomly sample an insertion layer K from the M decoder layers of the large language model, using the cross attention layer Generate visual features F that can be connected to the final output of the image encoder Img And the K-1th layer outputs text features F Txt Fusion Tips F P , using F Txt The mean pooling feature of is used as the query vector, F Img As the key vector and value vector, F P It is added to the Kth layer of the large language model, concatenated with the output of the previous layer, and then continuously passed to the subsequent layers, and then the Adapter module and the modal representation F are updated. m , Visual to Text Projection W t Corresponding to the current Parameters;
[0027] Step 43: After the training step t is updated, the evaluation phase of sampling n times is entered. Each evaluation sampling has a probability of 1-∈ based on the weight size of preference H and a probability of ∈ random sampling. During the evaluation process, a verification data set D is set v , according to D v The loss function is used to obtain the reward score R of inserting cross prompts at different layers in the above n samplings t , then based on R t Update the preference H;
[0028] After looping through steps 42 and 43 and after the search phase is over, the best placement layer K of the fusion hint in the large language model is obtained according to the weight of the preference H.
[0029] Furthermore, if it is an image-text feature, use the cross attention layer Generate fusion hint F for large language model P The specific calculation formula is:
[0030] F P =Concat(head1,..,head h )W O
[0031]
[0032] Where h is the number of attention heads, represents the intermediate dimension of the cross-attention layer, Represents the mapping of query vector, W K i represents the mapping of key vectors, W V i Represents the mapping of value vectors, W O Represents the final concatenated map.
[0033] Furthermore, in step 42, at each training step t, the objective function of the large language model is:
[0034]
[0035] in, Indicates the parameters of the Adapter module; W t Represents the projection matrix from vision to text; F m is a learnable modality representation; represents the parameters of the cross-attention layer; L(G(F)) represents the loss function of the large language model.
[0036] Furthermore, in step 42, at each training step t, the weight π of the Kth layer in the preference H corresponding to the large language model t(K) is calculated as:
[0037]
[0038] After sampling n times, based on R t The formula for updating preference H is:
[0039] H t+1 (K)=H t (K)+α(R t -R b )π t (K)(1-π t (K))
[0040] Among them, M represents the number of layers of the large model, H t (K) represents the weight of the Kth layer, H t (m) represents the weight of the mth layer, α is the learning rate of preference update, which is set to 1; R t It is 100 times the negative loss function power of the natural logarithm e, that is, 100*e -loss , R b is the mean reward of n samples.
[0041] Furthermore, in step 5, on the image-text features corresponding to the multimodal task, the large language model obtains the best placement layer K based on the ∈-greedy algorithm search strategy, and the image features F extracted by the image encoder Img and the feature F output by the K-1th layer of the large language model K-1 Through the cross attention layer Get the corresponding fusion hint F P , F P Join F K-1 Then it is sent to the Kth layer, and the input feature F of the Kth layer K for:
[0042]
[0043] in, represents the modal representation of the output of the K-1th layer, Represents the text representation corresponding to the output of the K-1th layer.
[0044] The present invention has the following technical effects or advantages:
[0045] (1) Use each multi-scale image [CLS] feature to provide visual information, and add fusion hints at specific layers to better connect the representation of image and text. In terms of cross-hints, use the pooled features of the corresponding text output at a specific layer as the cross-attention layer The query vector interacts with the image features finally output by the image encoder to ensure that only features of length 1 are introduced while obtaining global image information, ensuring that the sequence position of other input information is not occupied.
[0046] (2) Two lightweight Adapter modules are used in each layer to form a switching mechanism between single mode and multi-modality. At the same time, the ∈-greedy algorithm can help the large language model find the best position for fusion prompts, thereby better guiding the large language model to generate more accurate answers.
[0047] (3) Intermediate Dimensions in Cross-Attention Layers and the mapping from vision to text W t Since the feature dimension of the large language model is very large, the idea of Adapter module is used here to convert Set to the intermediate dimension d with the Adapter module h Similar low-dimensionality, W t Decompose into two low-rank matrices. BRIEF DESCRIPTION OF THE DRAWINGS
[0048] The present invention will be further described below in conjunction with embodiments with reference to the accompanying drawings.
[0049] Figure 1 This is an execution flow chart of a multimodal transfer learning method for a large language model according to the present invention.
[0050] Figure 2 The present invention is a schematic block diagram of the principles of a multimodal transfer learning method for a large language model.
[0051] Figure 3 It is a schematic diagram of the process of searching for the best placement layer of fusion prompts based on the ∈-greedy algorithm for the large language model in the present invention.
[0052] Figure 4 A schematic diagram of a human-computer interaction interface of a multimodal transfer learning method for a large language model in a specific application of the present invention. DETAILED DESCRIPTION
[0053] The present invention provides a multimodal transfer learning method suitable for large language models. The overall idea of the technical solution is as follows: In multimodal tasks, we use frozen visual encoders to extract multi-scale [CLS] features of images to provide visual information, and use the mapping from vision to text W t It is converted into a representation consistent with the text feature dimension, and a learnable modal representation F is added to the input m Two Adapter modules are added after the self-attention layer in each decoder layer of the frozen large language model to switch between single mode and multi-mode. m Make weight distribution.Txt The pooled features output at the corresponding layer are used as the cross attention layer The query vector, the final visual feature F output by the image encoder Img As a cross-modal attention layer The key vector and value vector of the fusion prompt are generated, and then the search method based on the ∈-greedy algorithm is used to obtain the best placement layer K of the fusion prompt in the large language model. The large language model is transferred based on the searched best placement layer K. In the multimodal task, the fusion prompt F P The features output by the K-1th layer are added and continued to be sent to the Kth layer. Based on the large language model, the present invention uses a small amount of multi-scale image features, Adapter modules and their switching mechanism, and fusion prompts to complete multimodal transfer learning, which not only significantly reduces the amount of training parameters and computational overhead, but also can simultaneously complete single-modal and multi-modal generation tasks, stimulate the transfer learning ability of the large language model in the multimodal field, and can then be applied to human-computer interaction.
[0054] In order to better understand the technical solution of the present invention, the above technical solution will be described in detail below in conjunction with the accompanying drawings and specific implementation methods.
[0055] See also Figure 1 and Figure 2 The embodiment of the present invention provides a multimodal transfer learning method for a large language model, comprising the following steps:
[0056] Step 1: Extract multi-scale visual features of image Img in multimodal tasks through the frozen image encoder CLIP-ViT Here, we extract the [CLS] image global representation of each layer encoder of CLIP-ViT, where N is the number of layers, d v is the dimension of the image feature; the input text Txt is encoded through the large language model to obtain the corresponding feature L is the length of this text, and two learnable modality embedding mappings are initialized d Txt is the dimension of the text, and the modal representation is determined by the modalities contained in the training samples To align the dimensions, Do a linear projection For example, we can use labels 0 / 1 to distinguish text modality from image-text modality. Based on the 0 / 1 labels, the modality embedding mapping W m Convert to modal representation F m .
[0057] Step 2: Concatenate the features contained in different modalities (i.e., the above three features) to obtain the actual input feature F of the large language model;
[0058] Step 3: Freeze the parameters of the large language model. Set a multi-layer perceptron and two randomly initialized adapter modules after each self-attention sublayer. The latter is used to model the processing path of unimodal tasks and multimodal tasks, and the former is used to represent the modality F. m Get the distribution weights of unimodal and multimodal tasks;
[0059] Step 4: Equip each layer with an independent cross-attention layer Generate fused cues using criss-cross attention layers and search for the best placement layer K of the fused cues in the large language model.
[0060] Step 5: According to the best placement layer K found, the image features F extracted by the visual encoder are Img (The frozen image encoder CLIP-ViT in step 1 not only extracts the multi-scale [CLS] visual features of the image, but also obtains the extracted image features F in the final layer Img ) and the plain text feature F corresponding to the output of the K-1th layer of the large language model Txt Through the cross attention layer Get the corresponding fusion hint F P Then, F P Added to the multi-scale visual features and text features corresponding to the output of the K-1th layer (generally, the output of the K-1th layer is F m , image features F extracted by the visual encoder Img and the concatenation of plain text features, and the output of the previous layer is used as the input of the next layer), and then sent to the Kth layer for continued interactive learning, and finally the text result generated by the large language model for the input is obtained.
[0061] In a specific embodiment, the step 4 specifically includes:
[0062] Step 41: Use a search method based on the ∈-greedy algorithm to treat each decoder layer of the large language model as a search space and assign a preference To indicate the probability of each layer of decoder being selected, and to equip each layer with an independent cross attention layer
[0063] Step 42: During each training step t, randomly sample an insertion layer K from the M decoder layers of the large language model, and use the corresponding cross-attention layer to generate a fusion prompt. In order to better align the features of the image and text, the cross-attention layer is used. Generate visual features that can be connected to the final output of the image encoder And the K-1th layer outputs text features F Txt Fusion Tips F P, s is the visual feature length of the final output of the image encoder, and here we use F Txt The mean pooling feature of is used as the query vector, F Img as key vector and value vector. P It is added to the Kth layer of the large language model, concatenated with the output of the previous layer, and then continuously passed to the subsequent layers, and then the Adapter module and the modal representation F are updated. m , Visual to Text Projection W t Corresponding to the current Parameters;
[0064] Step 43: After the training step t is updated, the evaluation phase of sampling n times is entered. In each evaluation sampling, there is a probability of 1-∈ based on the weight size of preference H, and a probability of ∈ random sampling. In the evaluation process, a verification data set D is set v , according to D v The loss function is used to obtain the reward score R of inserting cross prompts at different layers in the above n samplings t , then based on R t Update the preference H;
[0065] Steps 42 and 43 are looped, and after a short search phase, the best placement layer K of the fusion hint in the large language model is obtained according to the weight of the preference H;
[0066] In a specific embodiment, in step 2, the feature input to the large language model is represented as c is the longest input sequence of the large language model:
[0067] F=[F m ; F [CLS] W t ; F Txt ], Image-Text
[0068] F=[F m ; F Txt ], plain text
[0069] If the length of F is less than c, it is padded with a padding vector, and if it exceeds, it is truncated. t The projected space is decomposed into
[0070] F=[F m ; F [CLS] W t1 W t2 ; F Txt ]
[0071] In a specific embodiment, the Adapter module consists of a downsampling layer An upsampling layer And a SiLU activation function δ, the input of the Adapter module is defined as Then the calculation formula of the Adapter output O is:
[0072] O=X+U(δ(D(X)))
[0073] d h is the intermediate dimension of the Adapter module, and is scaled to the text dimension d Txt 1 / 64 of . The multilayer perceptron consists of two linear projection matrices and an activation function σ, d n Represents the intermediate dimension of the multilayer perceptron. For each decoder layer, two Adapter The weight [α1, α2] is calculated as:
[0074] [α1,α2]=Softmax(W2(σb1(W1(F m )+b1))+b2);
[0075] Among them, b1 and b2 are bias terms;
[0076] Then the expression of F through two Adapter modules in each layer is:
[0077]
[0078] Among them, F represents the sequence features of the large language model, F' represents the weighted output features of the input series features of the large language model after passing through the two adapter modules, and the weight represents the weight assigned to the two adapter modules as routing selection;
[0079] In a specific embodiment, in step 4, if it is an image-text feature, a cross attention layer is used Generate fusion hint F for large language model P The specific calculation formula is:
[0080] F P =Concat(head1,..,head h )W O
[0081]
[0082] Where h is the number of attention heads, represents the intermediate dimension of the cross-attention layer, where These four projection matrices in the multi-head attention layer represent the mapping of the query vector, the mapping of the key vector, the mapping of the value vector, and the final concatenation mapping, which is the calculation formula of the multi-head attention mechanism. Considering that the search based on the ∈-greedy algorithm requires M cross-attention layers, in order to avoid too many training parameters, here we also use the idea of dimensionality reduction to reduce the intermediate dimension d h Set to 64.
[0083] If it is plain text, there is no need to insert fusion features.
[0084] In a specific embodiment, in step 42, at each training step t, the objective function of the large language model is:
[0085]
[0086] in, Indicates the parameters of the Adapter module; W t Represents the projection matrix from vision to text; F m is a learnable modality representation; represents the parameters of the cross attention layer; L(G(F)) represents the loss function of the large language model, which uses the ordinary cross entropy function.
[0087] In a specific embodiment, in step 42, at each training step t, the weight π of the Kth layer in the preference H corresponding to the large language model is t (K) is calculated as:
[0088]
[0089] After sampling n times, based on R t The formula for updating preference H is:
[0090] H t+1 (K)=H t (K)+α(R t -R b )π t (K)(1-π t (K))
[0091] Among them, M represents the number of layers of the large model, H t (K) represents the weight of the Kth layer, H t (m) represents the weight of the mth layer, α is the learning rate of preference update, which is set to 1; R t It is 100 times the negative loss function power of the natural logarithm e, that is, 100*e -loss , Rb is the mean reward of n samples.
[0092] In a specific embodiment, in step 5, on the image-text features corresponding to the multimodal task, the large language model obtains the best placement layer K based on the ∈-greedy algorithm search strategy, and the image features F extracted by the image encoder Img and the feature F output by the K-1th layer of the large language model K-1 Through the cross attention layer Get the corresponding fusion hint F P , F P Join F K-1 Then it is sent to the Kth layer, and the input feature F of the Kth layer K for:
[0093]
[0094] The sequence length is also limited to c. Among them, represents the modal representation of the output of the K-1th layer, Represents the text representation corresponding to the output of the K-1th layer.
[0095] The technical solution provided in the embodiments of the present application has at least the following technical effects or advantages: a multimodal transfer learning method for a large language model of the present application can realize a low-cost and high-efficiency way to quickly transfer the general knowledge of the large language model to the multimodal generation tasks, such as ScienceQA, etc., which can not only keep the original parameters of the large language model unchanged, but also reduce the high computational overhead brought by visual features, and use the search strategy based on the ∈-greedy algorithm to obtain compact features of the connected image text, and guide the large model to generate more accurate answers.
[0096] The specific implementation process of the model under a specific embodiment is given below:
[0097] Step 1: Model implementation process:
[0098] 1.1 Model input:
[0099] The input of the model is the image Img of the multimodal task, whose size is trimmed to 224×224×3 to adapt to the input of the CLIP visual encoder. The multi-scale [CLS] features of the image are extracted and mapped. At the same time, the features of the description text Txt of the corresponding image and the learnable modal features F m The three are concatenated and input into the large language model, with a fixed length of 512. Figure 1 shown.
[0100] 1.2 Large Language Model:
[0101] The present invention is based on the large language model LLaMA-7B, and the relevant parameters are shown in Table 1. In the multimodal task, we regard it as a classification model, and add two Adapter modules after the self-attention layer in each decoding layer of LLaMA-7B.
[0102] Table 1 LLaMA-7B related parameters
[0103]
[0104] 1.3 Generation of fusion prompts:
[0105] For image-text, the corresponding F in F Txt The pooled features of The query vector, the final output of the image encoder is F Img As a cross attention layer The key vector and value vector of To reduce the training parameter size, we will cross the intermediate dimension of the attention layer Set to 64 to generate text-related, compact fusion hints.
[0106] F P =Concat(head1,..,head h )W O
[0107]
[0108] Where h is the number of attention heads, which is set to 8 here.
[0109] Step 2: Fusion Tips Based on the ∈-Greedy Algorithm Search Strategy
[0110] As shown in the pseudo code flow of Algorithm 1 below, we regard the 32 autoencoder layers of the large language model LLaMA-7B as the search space, and the selection of each layer is regarded as a policy action. First, the 32 layers are given preference To indicate the probability of each layer being selected. At the same time, each layer is equipped with an independent cross-modal attention layer
[0111] At each search process iteration time step t, a placement layer K is randomly sampled in H. The corresponding cross-attention layer is used To generate fusion hints, add them to the feature output of the K-1th layer before the Kth layer of the large language model, and then pass them to subsequent layers to update the visual-to-text mapping W t1 W t2 、Adapter module、 Parameters.
[0112] After the update is completed, n samplings are performed, with a probability of 1-∈ based on the weight size of the preference H, and a probability of ∈ for random sampling. In this process, a validation data set D is set v , find the reward score R after each sampling t , then based on R t Update the preference H. After the search phase is completed, the optimal placement layer K of LLaMA-7B on the current multimodal task is obtained according to the weight of the preference H. The entire algorithm flow is as follows: Figure 3 shown.
[0113]
[0114]
[0115] In this search process, we set the sampling times n in the evaluation phase to 10 and the probability of ∈ to 20% to avoid falling into the local optimal solution. At the same time, we control the search process in a more appropriate time range. We control the epoch to 1-2. In this process, we use the Adam optimizer to verify the data set D v The batch size is set to the training As shown in Table 2.
[0116] Table 2 Related parameter settings of the optimal placement K of LLaMA-7B search fusion prompts on SQA
[0117] Model Dataset Epoch batchsize Training learning rate LLaMA-7B ScienceQA 2 32 0.01
[0118] Step 3: Model training process:
[0119] Through step 2, we search for the best placement layer K of the multimodal task fusion prompt in the large language model LLaMA-7B, and place it before the Kth layer of the large language model. The generated fusion hint F P Add to the output of the K-1th layer and send it to the subsequent layers of LLaMA-7B. Update the Adapter through gradient descent. and the visual-to-text mapping W t1 W t2 In the whole training process, only about 10M parameters need to be trained. We use the Adam optimizer and set the epoch and batch size according to different vision-language tasks. As shown in Table 3, the batch size is set to 256.
[0120] Table 3 Training parameter settings for multimodal transfer learning of LLaMA-7B on SQA
[0121] Model Dataset Epoch batchsize Learning Rate LLaMA-7B ScienceQA 20 32 0.01
[0122] Step 4: Model deployment process:
[0123] After multimodal transfer learning of LLaMA-7B in step 3, we input the corresponding image and text instructions to obtain the generation result of the large language model. By switching between the two adapters in each layer, we can realize the flexible switching between language single modality and visual-language multimodality. We use the open source Grdio library in Python for encapsulation. The human-computer interaction interface is as follows: Figure 4 As shown, the corresponding text results are output according to the input text and / or picture.
Claims
1. A multimodal transfer learning method for a large language model, characterized by: The steps include: Step 1: Extract the multi-scale visual features F of the image in the multimodal task through the frozen image encoder CLIP-ViT [CLS] , F [CLS] Do a linear projection W t , encode the input text through the large language model and obtain the corresponding feature F Txt , initialize two learnable modality embedding mappings W m Used to represent the pure text modality and image-text modality, the modality representation F is determined according to the modality contained in the training sample m ; Step 2: Concatenate the features contained in different modalities to obtain the actual input features F of the large language model; Step 3: Freeze the parameters of the large language model, set a multi-layer perceptron and two randomly initialized Adapter modules after each self-attention sublayer, the Adapter module is used to model the processing path of single-modal tasks and multi-modal tasks, and the multi-layer perceptron represents the modality F m Get the distribution weights of unimodal and multimodal tasks; Step 4: Equip each layer with an independent cross-attention layer Generate fused cues using criss-cross attention layers and search for the best placement layer K of fused cues in the large language model; Step 5: Extract the image features F from the visual encoder Img The plain text feature F corresponding to the output of the K-1th layer of the large language model txt Through the cross attention layer Get the corresponding fusion hint F P Then, F P The multi-scale visual features and text features corresponding to the output of the K-1th layer are added, and then sent to the optimal placement layer K for further interactive learning, and finally a large language model is obtained to generate text results for the input.
2. A multimodal transfer learning method for a large language model as claimed in claim 1, characterized in that: In step 2, the feature input to the large language model is represented as F, and c is the longest input sequence of the large language model: F=[F m ; F [CLS] W t ; F Txt ], Image-Text F=[F m ; F Txt ], plain text If the length of F is less than c, it is padded with a padding vector; if it exceeds c, it is truncated.
3. The multimodal transfer learning method for a large language model according to claim 1, characterized in that: In step 3, the Adapter module consists of a downsampling layer An upsampling layer And a SiLU activation function δ, the input of the Adapter module is defined as Then the calculation formula of the Adapter output O is: O=X+U(δ(D(X))) d h is the intermediate dimension of the Adapter module, and is scaled to the text dimension d Txt 1 / 64 of; The multilayer perceptron consists of two linear projection matrices W1, W2 and an activation function σ. The weight [α1, α2] is calculated as: [α1,α2]=Softmax(W2(σb1(W1(F m )+b1))+b2) Among them, b1 and b2 are bias terms; Then the expression of F through two Adapter modules in each layer is: Among them, F represents the input sequence features of the large language model, and F' represents the weighted output features of the input series features of the large language model after passing through the two Adapter modules.
4. The multimodal migration method for a large language model as claimed in claim 1, characterized in that: The step 4 specifically includes: Step 41: Use the search method based on the ∈-greedy algorithm to regard each decoder layer of the large language model as a search space, assign a preference H to represent the probability of each decoder layer being selected, and equip each layer with an independent cross attention layer. Step 42: During each training step t, randomly sample an insertion layer K from the M decoder layers of the large language model, using the cross attention layer Generate visual features F that can be connected to the final output of the image encoder Img And the K-1th layer outputs text features F Txt Fusion Tips F P , using F Txt The mean pooling feature of is used as the query vector, F Img As the key vector and value vector, F P It is added to the Kth layer of the large language model, concatenated with the output of the previous layer, and then continuously passed to the subsequent layers, and then the Adapter module and the modal representation F are updated. m , Visual to Text Projection W t Corresponding to the current Parameters; Step 43: After the training step t is updated, the evaluation phase of sampling n times is entered. Each evaluation sampling has a probability of 1-∈ based on the weight size of preference H and a probability of ∈ random sampling. During the evaluation process, a verification data set D is set v , according to D v The loss function is used to obtain the reward score R of inserting cross prompts at different layers in the above n samplings t , then based on R t Update the preference H; After looping through steps 42 and 43 and after the search phase is over, the best placement layer K of the fusion hint in the large language model is obtained according to the weight of the preference H.
5. A multimodal transfer method for a large language model as claimed in claim 1 or 4, characterized in that: If it is an image-text feature, use the cross attention layer Generate fusion hint F for large language model P The specific calculation formula is: F P =Concat(head1,..,head h )W O Where h is the number of attention heads, represents the intermediate dimension of the cross-attention layer, W Q i Represents the mapping of query vector, W K i represents the mapping of key vectors, W V i Represents the mapping of value vectors, W O Represents the final concatenated map.
6. A multimodal transfer method for a large language model as claimed in claim 4, characterized in that: In step 42, at each training step t, the objective function of the large language model is: in, Indicates the parameters of the Adapter module; W t Represents the projection matrix from vision to text; F m is a learnable modality representation; represents the parameters of the cross-attention layer; L(G(F)) represents the loss function of the large language model.
7. The multimodal migration method for a large language model as claimed in claim 4, characterized in that: In step 42, at each training step t, the weight π of the Kth layer in the preference H corresponding to the large language model t (K) is calculated as: After sampling n times, based on R t The formula for updating preference H is: H t+1 (K)=H t (K)+α(R t -R b )p t (K)(1-π) t (K)) Among them, M represents the number of layers of the large model, H t (K) represents the weight of the Kth layer, H t (m) represents the weight of the mth layer, α is the learning rate of preference update, which is set to 1; R t is 100 times the negative loss function power of the natural logarithm e, R b is the mean reward of n samples.
8. The multimodal migration method for a large language model as claimed in claim 1, characterized in that: In step 5, on the image-text features corresponding to the multimodal task, the large language model obtains the best placement layer K based on the ∈-greedy algorithm search strategy, and the image features F extracted by the image encoder Img and the feature F output by the K-1th layer of the large language model K-1 Through the cross attention layer Get the corresponding fusion hint F P , F P Join F K-1 Then it is sent to the Kth layer, and the input feature F of the Kth layer K for: in, represents the modal representation of the output of the K-1th layer, Represents the text representation corresponding to the output of the K-1th layer.
Citation Information
Patent Citations
Vision-language task-oriented pre-training language model adaptation method
CN117037176A
Cited By
Robot grabbing detection method based on visual language action multi-mode alignment strategy
CN119526405A
Robot grasping detection method based on visual language action multi-modal alignment strategy
CN119526405B
