Multimodal large language model hallucination mitigation method and device, and electronic device
By utilizing the attention distribution of the visual encoder to determine the importance of visual lexical units and perform differential enhancement, combined with semantic covariant attention, the problem of generating illusions in multimodal large language models is solved, achieving illusion mitigation without increasing decoding latency.
Patent Information
- Application Number
- CN202611563460.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-10-10
- Publication Date
- 2026-11-06
AI Technical Summary
Multimodal large language models are prone to hallucinations during the generation process. Existing training-free hallucination mitigation schemes require additional forward computation of the model, which increases decoding latency and makes it difficult to meet real-time requirements.
The importance of visual words is determined by obtaining the attention distribution within the visual encoder, forming a priori visual importance. Differential weights are then adjusted in the large language model decoder. Combined with semantic covariant attention, noise information of low-information visual words is reduced, and the utilization of information related to the main body and key objects in the image is improved.
Without adding extra model inference, it effectively alleviates object-level illusions and fine-grained attribute illusions, reduces decoding overhead, and improves the accuracy of generated content.
Smart Images

Figure CN123049039A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of large model technology, and in particular to a method, device and electronic device for hallucination relief based on multimodal large language models. Background Technology
[0002] With the development of multimodal large language models, existing models can simultaneously receive image and text information, and perform various visual language tasks such as image description, visual question answering, object recognition, and attribute judgment on input images based on visual features extracted by the visual encoder and the generation capability of the language model.
[0003] However, multimodal large language models are still prone to generating content inconsistent with the input image during the generation process, i.e., producing multimodal illusions. For example, the model may describe objects that do not exist in the image, omit actual targets in the image, or incorrectly describe the visual attributes of targets such as color, shape, quantity, and location.
[0004] Among existing training-free hallucination mitigation schemes, one type constructs original and interfering inputs and performs model inference separately, comparing the output probability distributions obtained from the two inferences to suppress excessive linguistic priors. While this type of method can alleviate hallucinations to some extent, it typically requires additional model forward computation for the same generation step, leading to a significant increase in decoding latency and limiting its application in scenarios such as real-time visual question answering and interactive image understanding. Summary of the Invention
[0005] This invention provides a method, apparatus, and electronic device for alleviating hallucinations based on a multimodal large language model, which can reduce the decoding overhead caused by additional model inference while taking into account both object-level hallucinations and fine-grained attribute hallucinations.
[0006] The objective of this invention is achieved as follows: A hallucination mitigation method based on a multimodal large language model includes: The first visual word unit obtained by processing the input image through the visual encoder is obtained, and the visual importance of each word unit in the first visual word unit is determined based on the attention distribution inside the visual encoder, so as to form a visual importance prior that represents the difference in information content between different first visual word units. The first visual word is processed by feature projection to obtain the second visual word input to the large language model decoder. The visual importance prior is mapped to the second visual word according to the feature projection processing correspondence. The differential enhancement weight of each word in the second visual word is determined according to the visual importance prior. During the attention calculation process of the large language model decoder, the attention corresponding to different second visual words is selectively adjusted according to the differential enhancement weight. Among them, the second visual word with higher visual importance corresponds to a larger enhancement amplitude. In the autoregressive generation process of the large language model decoder, the key state vector corresponding to the current decoding position is obtained. The key state vector is used as a semantic query signal and at least the correlation is calculated with the key state vector corresponding to the second visual word to obtain semantic covariant attention that changes with the semantic state of the current decoding position. In at least one self-attention layer of the large language model decoder, the selective visual attention result obtained based on the differential enhancement weights is fused with the attention result corresponding to the semantic covariant attention to obtain a fused attention result, and autoregressive generation is performed based on the fused attention result.
[0007] A hallucination relief device based on a multimodal large language model includes: The acquisition unit is used to acquire the first visual word units obtained by processing the input image through the visual encoder, and determine the visual importance of each word unit in the first visual word unit based on the attention distribution inside the visual encoder, so as to form a visual importance prior characterizing the information content difference between different first visual word units. The adjustment unit processes the first visual word into a second visual word input to the large language model decoder after feature projection processing. It then maps the visual importance prior to the second visual word according to the feature projection processing correspondence. Based on the visual importance prior, it determines the differential enhancement weight of each word in the second visual word. During the attention calculation process of the large language model decoder, it selectively adjusts the attention corresponding to different second visual words according to the differential enhancement weight. The second visual word with higher visual importance corresponds to a larger enhancement magnitude. The computing unit is used to obtain the key state vector corresponding to the current decoding position during the autoregressive generation process of the large language model decoder, and to use the key state vector as a semantic query signal to perform correlation calculation with at least the key state vector corresponding to the second visual word, so as to obtain semantic covariant attention that changes with the semantic state of the current decoding position. The fusion unit is configured to, in at least one self-attention layer of the large language model decoder, fuse the selective visual attention result obtained based on the differential enhancement weights with the attention result corresponding to the semantic covariant attention to obtain a fused attention result, and perform autoregressive generation based on the fused attention result.
[0008] An electronic device includes a memory and a processor, the memory storing a computer program, and the processor executing the computer program to implement the steps of the hallucination relief method based on a multimodal large language model as described in any of the preceding embodiments.
[0009] The above describes a method that utilizes the attention distribution formed by the visual encoder itself to determine the visual importance of different first visual terms. This prior visual importance is then mapped to the second visual terms actually processed by the large language model decoder, allowing for differentiated attention adjustments based on the visual importance of each second visual term. Specifically, visual terms with higher visual importance receive greater attention enhancement, while those with lower visual importance receive less enhancement or have their original attention maintained. This reduces the simultaneous amplification of low-information visual terms and their noise information during uniform enhancement, improving the utilization of visual information related to the image subject and key objects, and reducing the probability of generating non-existent objects or omitting actual targets in the image. Simultaneously, during the autoregressive generation process, a semantic query signal is formed using the key state vector corresponding to the current decoding position. Based on this semantic query signal, a semantic covariant attention signal is obtained that changes with the current decoding semantics. This allows for the supplementation of local visual information related to the currently generated semantics when the generated content shifts from object-level semantics to fine-grained attribute semantics such as color, shape, quantity, and position, reducing errors in visual attribute description. Furthermore, the aforementioned visual importance priors and key state vectors are all derived from the internal states generated during the original forward propagation of the model. There is no need to perform additional full model forward inference for the same input, thereby reducing the decoding overhead caused by additional model inference while taking into account both object-level illusions and fine-grained attribute illusions. Attached Figure Description
[0010] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0011] Figure 1 This is a flowchart of a hallucination relief method based on a multimodal large language model provided in an embodiment of the present invention; Figure 2This is a flowchart of determining visual importance provided by an embodiment of the present invention; Figure 3 This is a schematic diagram of the attention distribution and visual region response corresponding to different visual words in a visual encoder provided by an embodiment of the present invention; Figure 4 This is a flowchart of a feature projection processing method provided in an embodiment of the present invention; Figure 5 This is a flowchart of a selective adjustment based on differentiated enhancement weights provided in an embodiment of the present invention; Figure 6 This is a flowchart of a fusion process provided in an embodiment of the present invention; Figure 7 This is a schematic diagram comparing the decoding efficiency and object illusion relief effect of the proposed solution with different multimodal large language model illusion relief methods provided in this embodiment of the invention. Figure 8 This is a schematic diagram of the structure of a hallucination relief device based on a multimodal large language model provided in an embodiment of the present invention; Figure 9 This is a schematic diagram illustrating the overall principle of a multimodal large language model hallucination mitigation method based on selective visual enhancement and semantic covariant attention, as provided in an embodiment of the present invention. Figure 10 This is a schematic diagram comparing the visual attention distribution formed by a traditional attention mechanism and the semantic covariant attention mechanism of the present invention for different visual semantic content, as provided in an embodiment of the present invention. Detailed Implementation
[0012] The following detailed description of preferred embodiments is a preferred mode for carrying out the invention. This description is not intended to be limiting; it is provided to illustrate the general principles of the invention.
[0013] It should be understood that the terms "first," "second," "an," "a," and "one" in the following description refer to "at least one" or "one or more" in the embodiments. In particular, the term "a" may refer to "one" in one embodiment and "more than one" in another embodiment. Therefore, the above terms should not be construed as limiting the actual number of elements of the present invention.
[0014] To facilitate understanding of the present invention, a more complete description will be given below with reference to the accompanying drawings. Preferred embodiments of the invention are shown in the drawings. However, the invention can be implemented in many different forms and is not limited to the embodiments described herein. Rather, these embodiments are provided to provide a thorough and complete understanding of the disclosure of the invention.
[0015] As described in the background section, to address the multimodal illusion during model generation, training-free illusion mitigation schemes have emerged. These training-free methods intervene during the inference phase, requiring no modification to model parameters, and are plug-and-play. This invention belongs to the category of training-free methods.
[0016] Currently, training-free techniques include contrastive decoding-based methods, represented by Visual Contrastive Decoding (VCD). This method applies visual perturbations to the original image and compares the probability distributions of the original and perturbed inputs at each decoding step, amplifying the contribution of the visual signal and suppressing linguistic priors. While this method requires no training, its core drawback is low inference efficiency: each decoding step requires two rounds of complete model forward inference, with an inference latency approximately twice that of the baseline, making it difficult to meet real-time requirements.
[0017] Methods based on uniform attention enhancement, exemplified by Visual Amplification Fusion (VAF), apply a uniform enhancement weight to the attention scores of all visual lexical units during the self-attention process of large language model decoding, while suppressing system cue lexical units. This method boasts extremely low inference latency, but its core flaw lies in the "uniform enhancement" strategy: indiscriminately boosting the attention weights of all visual lexical units. The attention distribution within the visual encoder is highly concentrated: a few high-attention lexical units aggregate global semantic information, which, after enhancement, helps alleviate hallucinations; while the vast majority of low-attention lexical units carry background noise, and enhancement actually exacerbates hallucinations. The uniform enhancement strategy of VAF cannot distinguish this difference.
[0018] Methods based on global-local attention contrast are exemplified by the Assembly of Global and Local Attention (AGLA) approach. This method maintains two attention branches—global and local—during decoding, suppressing language priors by comparing their differences. However, it still employs a multi-round computational contrast framework, resulting in an inference latency approximately twice that of the baseline. Furthermore, this method uses a fixed strategy for global and local partitioning, failing to consider the differences in information content within visual lexical units, and it does not address the semantic invariance problem in self-attention: regardless of the generated semantic units, the attention distribution pattern remains essentially fixed.
[0019] To address the shortcomings of the aforementioned training-free techniques, this invention provides a hallucination mitigation method based on a multimodal large language model. In this scheme, Selective Visual Enhancement (SVE) utilizes the existing attention distribution within the visual encoder as prior knowledge to identify key visual lexical units carrying global semantic information. A defined weight mapping function assigns differentiated enhancement weights to lexical units with different information levels: high-attention lexical units receive greater enhancement, while low-attention lexical units receive smaller enhancement. Simultaneously, attention scores pointing to system cue lexical units are suppressed to prevent low-semantic system cue lexical units from intercepting a large amount of attention and diluting the visual enhancement effect. The attention distribution required by the selective visual enhancement module is naturally generated during the model's forward propagation, without introducing additional inference.
[0020] The Semantic Covariant Attention (SCA) scheme utilizes the existing key-state vectors in the self-attention of a large language model to replace the query vectors in traditional query-key attention for attention calculation; that is, it uses key-key attention instead of query-key attention. The key-state vectors contain the semantic information of the current word, and when used as the query signal, the attention distribution can dynamically change with the semantics of the generated content: when generating "hair," the focus is on the hair region; when generating "shoes," the focus is on the shoe region.
[0021] Selective visual enhancement and semantic covariant attention work together in each self-attention layer of the large language model: the selective visual enhancement module acts as the main attention branch, ensuring complete coverage of global information; the semantic covariant attention module acts as an auxiliary branch, achieving precise alignment of local semantics. They are complementary and both operate based on existing state information, requiring no additional reasoning.
[0022] To enable those skilled in the art to better understand and implement this solution, the following detailed description of the specific solution, principles, advantages, and effects of the present invention is provided with reference to the accompanying drawings and specific embodiments.
[0023] In this invention, a multimodal large language model refers to a model that can receive at least visual information and textual information, and generate text using a large language model decoder.
[0024] A multimodal large language model can include a visual encoder, a feature projection module, and an autoregressive large language model decoder. For example, it can be an LLaVA series model that uses a CLIP-type visual encoder, or a visual language model that uses other visual Transformers and visual lexical merging structures.
[0025] In this invention, visual lexical units refer to image blocks divided from the input image or visual representation units formed by further processing by a visual encoder.
[0026] To avoid ambiguity caused by changes in the number of visual lexical units under different model structures, this invention refers to the visual lexical units output by the visual encoder before participating in feature projection processing as the first visual lexical units, and the visual lexical units actually input into the large language model decoder after feature projection, visual lexical unit merging, or other visual adaptation processing already performed in the original model as the second visual lexical units.
[0027] The visual importance in this invention is not determined by additional training to obtain classification labels or importance prediction network outputs, but by attention information formed during the attention calculation process of the visual encoder itself. It is used to characterize the relative attention level of different visual terms in the process of visual information aggregation.
[0028] In this invention, the key state vector corresponding to the current decoding position refers to the key state vector obtained by projecting the hidden state corresponding to the existing context of the current decoding position through the key of the current self-attention layer of the large language model decoder before generating the target word. It is not the key state corresponding to the target word itself that has not yet been generated, therefore it is not required to know the target word to be generated in advance.
[0029] The semantic covariant attention in this invention refers to auxiliary attention formed by using the internal semantic state corresponding to the current decoding position as the attention retrieval signal. Its visual attention distribution can change with the changes in the internal state corresponding to different decoding positions. In this embodiment, the key state vector of the current decoding position is preferably used as the semantic query signal.
[0030] See Figure 1 , Figure 1 This is a flowchart of a hallucination relief method based on a multimodal large language model provided in an embodiment of the present invention.
[0031] S101, obtain the first visual word unit obtained by processing the input image through the visual encoder, and determine the visual importance of each word unit in the first visual word unit based on the attention distribution inside the visual encoder, forming a visual importance prior that characterizes the difference in information content between different first visual word units.
[0032] In some embodiments, the image to be processed is input into the visual encoder of a multimodal large language model. The visual encoder can divide the input image into multiple image patches, and convert each image patch into an initial visual representation through linear mapping. Then, feature extraction is performed through multiple layers of visual Transformer to finally form the first visual word sequence.
[0033] In a visual encoder that includes categorical terms or other global aggregate terms, it is preferable to obtain the attention of the global aggregate terms to each first visual term from the penultimate self-attention layer of the visual encoder.
[0034] Taking a visual Transformer containing the [CLS] term as an example, in the target self-attention layer, the query vector corresponding to the [CLS] term and the key vector corresponding to the first visual term are obtained, and the attention of the [CLS] term to each first visual term is calculated based on the query vector and the key vector.
[0035] For any attention head, its attention can be represented as: .
[0036] in, This represents the query vector corresponding to the [CLS] term. H represents the key-state matrix corresponding to each first visual word (or the key vector of all visual words, where H is the number of attention heads, N is the number of visual words, and D is the feature dimension per head), where D represents the feature dimension of a single attention head. This indicates the attention distribution of the [CLS] lexicon to the first visual lexicon.
[0037] When the target self-attention layer contains H attention heads, H groups of attention distributions can be obtained respectively, and the attention of different attention heads on the same visual word can be averaged or otherwise aggregated to obtain a one-dimensional visual importance vector corresponding to the first visual word.
[0038] Through analysis, the inventors discovered that the shallow layers of the visual encoder primarily retain a large amount of local low-level visual information such as edges and textures, resulting in insufficient semantic aggregation. The last layer of the visual encoder is strongly influenced by the vision-language pre-training objective, and some local visual details may be further compressed during the final global representation formation process. The penultimate layer, located in the high-level visual semantic formation stage and not yet having completed the final output compression, can thus balance higher-level visual semantics with local visual details.
[0039] Furthermore, the attention of the global aggregation lexical units in the penultimate layer is usually focused on a small number of visual lexical units. These visual lexical units mostly correspond to the main body, key objects, or visual regions with high global semantic contribution in the image. Therefore, using the attention of this layer as a visual importance prior can directly obtain the relative importance of different visual lexical units without additional training of the importance prediction model.
[0040] For visual encoders that do not contain the [CLS] lexicon or other explicit global aggregation lexicon, the visual importance of each first visual lexicon can be determined by the self-attention between visual lexicons.
[0041] For the For each first visual word, the attention paid to that word by other first visual words can be averaged: .in, Indicates the first The first visual word pair Attention is allocated to each first visual word.
[0042] This yields the average level of attention each first visual word receives in the visual sequence, and this average level of attention is used as an alternative measure of visual importance.
[0043] It should be noted that this embodiment utilizes the specific attention distribution already formed within the visual encoder, rather than obtaining importance results by inputting the visual words themselves into an additional multilayer perceptron or other importance prediction network. Therefore, this visual importance prior can be obtained directly while freezing the model parameters.
[0044] Implementation Method 1: Visual encoder and large language model decoder architecture containing [CLS] lexical units: The base model is LLaVA-1.5-7B. The visual encoder is a visual transformer (containing [CLS] lexical units) of a contrastive language-image pre-trained model, and the language decoder is LLaVA-7B, connected via a multilayer perceptron projector. First, the pre-trained LLaVA-1.5-7B model is loaded, and all model parameters are frozen without further training or fine-tuning. During forward propagation, the query vector containing [CLS] lexical units is extracted and saved from the penultimate layer (the 23rd of 24 layers) of the visual encoder. and the key vectors of all visual lexical units And calculate attention score The average value is then taken along the attention head dimension. Subsequently, the differential enhancement weights are calculated. The hyperparameters are set to In each layer of self-attention calculation within the large language model, the attention score matrix is adjusted. The correction operation is performed before SoftMax, and the corrected matrix... After SoftMax normalization, the value vector Multiplication. The key matrix is reused within the same self-attention layer. ,calculate Finally, the attention outputs of the selective visual enhancement module and the semantic covariant attention module are fused, and the final output of this layer is obtained through residual connections and a feedforward neural network. An autoregressive text generation strategy is then employed to complete the process.
[0045] Implementation method two: Visual encoder and decoder architecture without [CLS] lexical units: The model is based on Qwen2.5-VL-7B. The visual encoder of this model is a language-image pre-trained model based on Sigmoid loss, which does not contain [CLS] terms, therefore the calculation method of the differential enhancement weights needs to be adjusted. The main difference from Implementation Method 1 lies in the acquisition of the attention distribution prior. Since this encoder lacks [CLS] terms, it uses... As a priori attention distribution, in the penultimate layer, the average attention received by each visual word from all other visual words in the sequence is calculated. The remaining operations (weight calculation, attention correction, semantic covariant attention calculation, fusion) are the same as in Implementation Method 1.
[0046] S102, the first visual lexical unit is processed by feature projection to obtain the second visual lexical unit input to the large language model decoder, and the visual importance prior is mapped to the second visual lexical unit according to the feature projection processing correspondence. The differential enhancement weight of each lexical unit in the second visual lexical unit is determined according to the visual importance prior. During the attention calculation process of the large language model decoder, the attention corresponding to different second visual lexical units is selectively adjusted according to the differential enhancement weight, wherein the second visual lexical unit with higher visual importance corresponds to a larger enhancement magnitude.
[0047] In some embodiments, the visual encoder and the large language model decoder in a multimodal large language model typically have different feature dimensions. Therefore, the first visual lexical output by the visual encoder needs to be converted into a second visual lexical that can be input into the large language model decoder after feature projection processing.
[0048] In models employing word-by-word linear projection or word-by-word multilayer perceptron projection, each first visual word is independently mapped to a second visual word, and the number of visual words remains constant. Therefore, the first... The visual importance of the first visual word can be directly passed to the second. A second visual word element.
[0049] For models that include visual word merging operations, multiple spatially adjacent first visual words or those combined according to preset rules can form a second visual word. Assume the second visual word... Since the second visual word is formed from a first set of visual words, the visual importance of the second visual word can be aggregated based on the visual importance of each first visual word in the set.
[0050] In one implementation, when the original model uses the average merging of adjacent words, the corresponding visual importance also uses average aggregation: .
[0051] in, Indicates the first The visual importance of each second visual word element This indicates participation in the formation of the first A set of first visual lexical units of second visual lexical units; Indicates the first The visual importance of each first visual word.
[0052] When the original model uses weighted pooling, visual importance can be weighted in the same or corresponding way according to the combined weights in the original projection processing; when the original model performs visual word filtering, the visual importance corresponding to the first selected visual word can be retained; in other structures with known word mapping relationships, the mapping matrix can also be used to complete the correspondence of visual importance.
[0053] The key point of the above processing is that the arrangement and number of visual importance priors are consistent with the second visual lexical units that actually enter the large language model decoder, without changing the number of visual lexical units actually used by the original model.
[0054] After obtaining the visual importance corresponding to each second visual word, the differential enhancement weight is determined based on the relative magnitude between the visual importances.
[0055] In a preferred embodiment, the maximum visual importance value corresponding to the current input image is determined. and minimum value Then, the visual importance of each second visual word is linearly mapped to the value of the enhanced parameter. A limited, restricted interval.
[0056] Among them, the The differential enhancement weight of each second visual word can be expressed as: .
[0057] when When, the corresponding visual lexical unit receives the minimum enhancement; when = When the visual word element is at its maximum enhancement, the remaining visual word elements receive continuous enhancement weights within the finite enhancement interval according to their relative position of visual importance.
[0058] Using continuous monotonic mapping can preserve the visual importance ranking relationship reflected by the visual encoder's attention and avoid the granularity loss caused by simply dividing visual lexical units into enhanced and non-enhanced categories using a single threshold.
[0059] In practical applications, It can be configured according to the model and task type. For example, The maximum enhancement magnitude can be taken from 0 to 0.2. In tasks where image understanding is the primary objective, the maximum enhancement magnitude can be appropriately increased; in tasks involving a significant amount of general language generation, the maximum enhancement magnitude can be appropriately decreased.
[0060] In the self-attention calculation of the large language model decoder, the query state, key state, and value state are obtained in the same way as the original model.
[0061] For the current self-attention layer input This can be represented as: query state projection Key state projection Value state projection .
[0062] The raw attention relevance score can be expressed as: , where Q and K are the query matrix and key matrix of the current layer of the large language model, respectively, and D is the feature dimension of each head.
[0063] Based on this, the attention between the text-side query position and the visual word is selectively adjusted according to the differentiated enhancement weights corresponding to the second visual word.
[0064] It should be noted that the specific numerical adjustment for attention can be based on the relevance score before SoftMax, the equivalent attention bias, or the attention weight after SoftMax, depending on the attention implementation of the model used. As long as the relationship is maintained that high-importance visual words receive larger positive adjustments, low-importance visual words receive smaller positive adjustments, or no adjustments are made, it is acceptable.
[0065] By adopting the above method, we can avoid uniformly amplifying all second visual words as equally important sources of information, thereby reducing the probability that background, redundant textures or other interfering information contained in low visual importance words will be simultaneously amplified.
[0066] In some embodiments, selective visual attention adjustment also includes attention convergence calibration for system cue words.
[0067] The unified input sequence of a large language model typically includes system prompt lexical units, user instruction lexical units, second visual lexical units, and previously generated historical text lexical units. The inventors discovered that in some models, lexical units corresponding to dialogue templates, start markers, or other fixed system prompts receive higher attention, thus forming an attention convergence phenomenon.
[0068] System-suggested terms often serve to control format, role, or dialogue boundaries, but some of these terms have a low degree of relevance to the specific visual semantics of the current image. When these terms consistently occupy a large proportion of attention, the increased attention gained from enhancing visual terms is easily diluted during the normalization process.
[0069] Therefore, while performing differentiated enhancement on the second visual lexical unit, the system prompt lexical unit in the unified input sequence can be identified, and the attention of other lexical units pointing to the system prompt lexical unit can be reduced according to the preset suppression strength.
[0070] In a non-limiting embodiment, the suggestion suppression coefficient can be between 0 and 1, for example, 0.1. The suppression amplitude should not be too large to avoid significantly interfering with the format control and dialogue control functions performed by the system suggestions.
[0071] Visual attention enhancement and system cue attention suppression can be performed within the same self-attention computation process. The former performs differentiated processing based on the visual importance of each visual word, while the latter suppresses attention based on the positional mask of system cue words, thereby completing the attention adjustment of the selective visual enhancement module.
[0072] The visual importance prior can be calculated only once for the same input image. In the pre-filling stage, selective visual enhancement can be applied to the attention between the text-side query position and the second visual word; after entering the autoregressive incremental decoding stage, the visual importance prior and differential enhancement weights corresponding to the same input image are reused at the current decoding position.
[0073] Therefore, it is not necessary to re-execute the importance calculation of the visual encoder in every generation step, but the visual importance prior can be reused in multiple subsequent autoregressive decoding steps.
[0074] S103, during the autoregressive generation process of the large language model decoder, the key state vector corresponding to the current decoding position is obtained, and the key state vector is used as a semantic query signal to perform correlation calculation with at least the key state vector corresponding to the second visual word, so as to obtain semantic covariant attention that changes with the semantic state of the current decoding position.
[0075] In some embodiments, in the autoregressive generation of the first When outputting a word, the large language model calculates the hidden state corresponding to the current decoding position based on the existing context. This hidden state is determined by system prompts, user commands, visual input, and previously generated lexical units, but does not include the target lexical units that have not yet been generated.
[0076] By inputting the hidden state at the current decoding position into the key projection of the current self-attention layer, we can obtain: .in, This indicates the hidden state of the input corresponding to the current decoding position; This represents the key state vector corresponding to the current decoding position.
[0077] Simultaneously, the visual key state matrix corresponding to the second visual lexical unit is obtained from the current self-attention layer. and visual value state matrix .
[0078] This embodiment does not use the original query vector at the current decoding position as the query signal for the auxiliary branch, but instead uses the key state vector corresponding to the current decoding position. Perform visual relevance calculations.
[0079] In one implementation, semantic covariant attention can be represented as: .
[0080] in, Indicates the first Semantic covariant attention distribution corresponding to each decoding position; This represents the key state vector at the current decoding position; This represents the visual key state matrix corresponding to the second visual lexical unit.
[0081] Then, the visual value states are aggregated based on the semantic covariant attention: .
[0082] in, This represents the visual value state matrix corresponding to the second visual word element; This represents the semantic covariant visual information obtained at the current decoding position.
[0083] Since the hidden states correspond to different decoding positions, the hidden states are obtained through key projection. The results also change accordingly. Therefore, the results obtained from different generation steps... This can create different visual attention distributions.
[0084] For example, when the model generates descriptions related to hair, the semantic state at the current decoding position can have a high key-state correlation with the hair-related visual region; similarly, when generating descriptions related to shoes, the current key-state can have a high correlation with the visual lexical units corresponding to the shoe region. Thus, without introducing an additional object detector, auxiliary attention can reallocate visual attention based on changes in the generation context.
[0085] It should be noted that the hair and shoes in the above example are used to illustrate the changes in visual attention corresponding to different semantic states, and do not indicate that the model has obtained the key state of the target word before predicting the word.
[0086] In other implementations, the semantic query signal can also be correlated with a key state set containing the second visual word key state and some text key states, and then visual information can be obtained from the resulting attention result. This embodiment preferably performs correlation calculations directly on the visual key state matrix to more clearly establish the semantic correspondence between the current decoding position and the visual word.
[0087] S104, in at least one self-attention layer of the large language model decoder, the selective visual attention result obtained based on the differential enhancement weights is fused with the attention result corresponding to the semantic covariant attention to obtain a fused attention result, and autoregressive generation is performed based on the fused attention result.
[0088] In some embodiments, the original attention branch after differential visual enhancement and attention convergence calibration is used as the main attention branch, and the semantic covariant attention obtained in step S103 is used as the auxiliary attention branch.
[0089] The main attention branch retains the query-key attention structure of the original large language model and uses visual importance priors to selectively enhance visual lexical units, thus better preserving the global generation capability of the original model.
[0090] The auxiliary attention branch recalculates the relevance between the key state at the current decoding position and the visual lexical, and is mainly used to supplement the current layer with visual information related to the currently generated semantics.
[0091] In one basic implementation, two attention branches can be fused according to a preset contribution ratio. For example, the fusion representation of the current layer can be written as: .
[0092] in, Indicates the input of the current layer. This indicates the result of selective visual attention. This represents the fusion representation of the current layer. Indicates the contribution of the auxiliary attention branch. This indicates the output projection.
[0093] The output of the current self-attention layer can be further input into the feedforward neural network and formed into the final output of the layer through residual connections.
[0094] For example: .
[0095] in, The attention score matrix is corrected by the selective visual enhancement module; the attention weights that provide differentiated enhancement for the main attention branch; This provides attention weights for the semantically covariant attention module and semantically covariant attention weights for the auxiliary attention branch. It is a value vector matrix. The contribution hyperparameter of the semantic covariant attention module controls the weight ratio of semantic covariant attention in the overall attention output. When the semantic covariant attention branch fails, it is equivalent to using only the selective visual enhancement module. To output the projection matrix, It is a feedforward neural network.
[0096] In one implementation, to achieve differentiated enhancement for different visual lexical units, a modified attention score matrix is used. The calculation formula is: .
[0097] in, To differentiate and enhance the weight vector, control the enhancement magnitude of each visual word element; Enhance the mask matrix for visual lexical elements. If and only if the query term Belongs to the instruction token and the queried token If it belongs to a visual lexical, it is 0 otherwise. This mask ensures that the enhancement operation only applies to the attention interaction direction from the instruction lexical to the visual lexical. The system will provide a suppression mask matrix. If and only if the queried term If the value belongs to the system suggestion term, it is 0; otherwise, it is 0. This mask is used for attention convergence calibration. The system prompt attention inhibition coefficient controls the degree of inhibition of attention to system prompt lexical units; ⊙ represents element-wise multiplication.
[0098] First item Differentiated visual enhancement was achieved; for visual words with high attention scores, their attentional interaction with instruction words was significantly enhanced. For visual words with low attention scores, the attentional interaction remained almost unchanged. (Second item) Attention convergence calibration was achieved.
[0099] See Figure 2 , Figure 2 This is a flowchart for determining visual importance provided by an embodiment of the present invention.
[0100] S201, Select the penultimate layer of the visual encoder as the target self-attention layer, and obtain the attention distribution in the target self-attention layer.
[0101] In some embodiments, if the visual encoder includes L sequentially connected visual Transformer layers, then the (L-1)th layer can be selected as the target self-attention layer, and the query state, key state, and corresponding attention distribution formed during the self-attention calculation process can be obtained from the target self-attention layer.
[0102] Different layers of a visual encoder typically perform visual information extraction functions at different levels. Shallow layers near the input mainly extract low-level visual features such as edges, textures, and local shapes; as the number of network layers increases, different visual lexical units gradually complete information interaction and form high-level visual semantics such as object categories and scene structures.
[0103] Analysis revealed that the final output layer of the visual encoder is strongly influenced by the vision-language alignment target. In the process of forming the final global representation, some local visual details may be further compressed. The penultimate layer has already completed a relatively sufficient high-level visual semantic aggregation and has not yet undergone further semantic compression in the last layer. Therefore, it can achieve a better balance between global visual semantic information and local visual information.
[0104] Therefore, in this embodiment, the penultimate layer of the visual encoder is preferably used as the target self-attention layer. It should be noted that in other embodiments, other self-attention layers located near the output and preceding the final output layer can also be selected depending on the specific visual encoder structure.
[0105] S202, when the visual encoder includes a global aggregation lexicon for aggregating global visual information, the attention of the global aggregation lexicon to the first visual lexicon is obtained, and the attention corresponding to different attention heads is aggregated, and the visual importance of each lexicon in the first visual lexicon is determined based on the aggregated attention.
[0106] In some visual encoders, the visual lexical sequence includes not only the first visual lexical corresponding to the image patch, but also a global aggregation lexical for aggregating the visual information of the entire image. For example, in a model employing the CLIP visual Transformer, the global aggregation lexical can be the [CLS] lexical.
[0107] In the target self-attention layer, the query vector corresponding to the global aggregate word and the key vector corresponding to each of the first visual words are obtained, and the attention of the global aggregate word to each of the first visual words is calculated.
[0108] When the target self-attention layer includes multiple attention heads, the attention of the global aggregated lexical in each attention head to each first visual lexical is obtained respectively, and the attention of multiple attention heads is averaged, weighted averaged or otherwise aggregated for the same first visual lexical to obtain the visual importance corresponding to each first visual lexical.
[0109] Since the global aggregation lexical unit performs the function of converging information from the entire image, the attention directed to different visual lexical units can reflect the relative contribution of different visual lexical units in the process of forming the global visual representation. Therefore, this embodiment directly utilizes the attention information already generated within the visual encoder to evaluate the importance of visual lexical units, without the need to set up an additional trained importance prediction network.
[0110] S203, when the visual encoder does not include the global aggregated lexical, obtain the self-attention between the first visual lexical, and for each lexical in the first visual lexical, aggregate the self-attention of other first visual lexical to that lexical, and determine the visual importance of the lexical based on the aggregated self-attention.
[0111] In some embodiments, for a visual encoder that does not contain explicit [CLS] lexical units or other globally aggregated lexical units, the self-attention matrix formed between the first visual lexical units in the target self-attention layer is obtained.
[0112] For the j-th first visual word, aggregate the attention directed to that first visual word by other first visual words. For example, averaging can be used to obtain... . It reflects the average level of attention each visual word receives throughout the entire visual sequence and can be used as a substitute measure of its information content.
[0113] The higher the degree to which a first visual word is jointly noticed by multiple other visual words, the higher the aggregation effect of the first visual word in the process of visual information interaction. Therefore, the average degree of attention can be used as the visual importance of the first visual word.
[0114] In other words, regardless of whether the visual encoder has explicit global aggregation lexical units, the visual importance prior can be constructed using the existing attention calculation results of the visual encoder without requiring additional training of the visual lexical unit importance prediction network.
[0115] See Figure 3 , Figure 3 This is a schematic diagram of the attention distribution and visual region response corresponding to different visual words in a visual encoder provided by an embodiment of the present invention.
[0116] like Figure 3As shown, during the process of encoding the input image by the visual encoder, a non-uniform attention distribution is formed among different visual words.
[0117] By acquiring attention information from the self-attention layer near the output of the visual encoder, it can be observed that only some visual words receive relatively high attention, while the attention corresponding to other visual words is relatively low. Specifically, Figure 3 The attention matrix on the right shows a few distinct vertical high-response stripes, indicating differences in the degree of attention given to different visual terms. After mapping the corresponding attention distribution back to the spatial regions of the input image, as shown... Figure 3 As shown on the left, the regions corresponding to high-attention visual words exhibit locally concentrated and discrete response characteristics, while the responses in other regions are relatively weak.
[0118] The attention distribution described above indicates that the visual encoder has already established relative importance differences among different visual units after completing image encoding. Therefore, applying the same enhancement method to all visual units during the large language model decoding stage may simultaneously amplify information related to the main visual semantics as well as information less relevant to the current image understanding, which is not conducive to fully utilizing the importance priors already formed in the visual encoder.
[0119] Based on the above characteristics, this invention uses the attention distribution generated by the visual encoder as prior information to determine the importance of visual words. It determines the importance of different visual words based on the attention information corresponding to them, and further implements differentiated enhancement according to the importance of visual words, so that visual words with higher importance receive greater attention enhancement, while visual words with lower importance receive less enhancement or maintain the original attention level.
[0120] When the visual encoder includes global visual words, the importance of each visual word can be determined by the attention relationship formed by the global visual words on other visual words; when the visual encoder does not include the global visual words, the importance of each visual word can also be determined by the average degree of attention it receives in the attention matrix among visual words.
[0121] See Figure 4 , Figure 4 This is a flowchart of a feature projection process provided in an embodiment of the present invention.
[0122] S401, determine the word correspondence between the first visual word and the second visual word obtained by the feature projection processing.
[0123] In some embodiments, a first visual word sequence output by the visual encoder is obtained, and a second visual word sequence is obtained after the first visual word sequence is processed by the projection of the original features of the multimodal large language model.
[0124] Let N be the number of the first visual lexical units and M be the number of the second visual lexical units. Based on the specific processing method performed on visual lexical units by the feature projection module in the original multimodal large language model, each second visual lexical unit is determined to be formed by one or more first visual lexical units.
[0125] The feature projection processing may include word-by-word linear projection, word-by-word multilayer perceptron projection, merging of adjacent visual words, pooling, visual word filtering, or other visual adaptation processing that can determine the relationship between input and output words.
[0126] S402, when the feature projection processing keeps the number and correspondence between the first visual word and the second visual word unchanged, the visual importance of each word in the first visual word is transferred to the corresponding second visual word.
[0127] In some embodiments, when the feature projection process only changes the feature dimension of the first visual word without changing the number and order of the visual words, the first visual word and the second visual word maintain a one-to-one correspondence.
[0128] In this case, the i-th first visual word corresponds to the j-th second visual word, so the visual importance corresponding to the i-th first visual word is directly taken as the visual importance corresponding to the j-th second visual word.
[0129] Therefore, without recalculating the importance of visual lexical units on the decoder side of the large language model, the prior visual importance obtained inside the visual encoder can be directly passed to the second visual lexical unit.
[0130] S403, when the feature projection processing merges, pools, filters or compresses multiple first visual words, the visual importance of the corresponding first visual words is aggregated, selected or mapped according to the first visual words that participate in forming each second visual word and the word transformation relationship corresponding to the feature projection processing, so as to obtain the visual importance of each word in the second visual word.
[0131] In some embodiments, when the feature projection process changes the number of visual lexical units, the correspondence is determined based on the first visual lexical unit involved in forming each second visual lexical unit.
[0132] For example, if the j-th second visual word is formed by merging multiple first visual words from the first visual word set, then the visual importance of the second visual word can be determined based on the visual importance of each first visual word in the first visual word set.
[0133] When the original model uses a pooling method with explicit combination coefficients, visual importance can be weighted and aggregated according to the corresponding combination coefficients; when the original model uses a visual word selection method, the visual importance corresponding to the first retained visual word can be selected simultaneously.
[0134] Accordingly, determining the differential enhancement weights of each word in the second visual word based on the prior visual importance includes: obtaining each visual importance corresponding to the second visual word, and normalizing each visual importance according to the maximum and minimum values among the visual importances; mapping the normalized visual importances to a preset finite enhancement interval according to a continuous and monotonic mapping relationship, wherein the mapping relationship maintains the relative size relationship between the visual importances, with the second visual word with higher visual importance corresponding to a larger differential enhancement weight, and the second visual word with lower visual importance corresponding to a smaller differential enhancement weight; restricting the differential enhancement weights to the finite enhancement interval, and adjusting the attention corresponding to the corresponding second visual word according to the differential enhancement weights of each word in the second visual word.
[0135] In this way, different enhancement levels can be assigned to different visual words while maintaining the original visual importance ranking, thereby avoiding the application of equal enhancement to all visual words.
[0136] See Figure 5 , Figure 5 This is a flowchart of a selective adjustment based on differentiated enhancement weights provided in an embodiment of the present invention, including: S501, obtain the unified input sequence input to the large language model decoder, and determine the system prompt word and the text-side query position including the current decoding position from the unified input sequence.
[0137] In some embodiments, when constructing a unified input sequence for a large language model decoder, the index range of different types of lexical units in the unified input sequence is recorded.
[0138] The unified input sequence may include system prompt lexical units, user instruction lexical units, second visual lexical units, and historical output lexical units generated during the autoregressive generation process.
[0139] A system prompt word position set is formed based on the predetermined system prompt range in the input template. A visual word position set is formed based on the position of the second visual word in the unified input sequence. The text-side query position currently participating in attention calculation is determined.
[0140] S502, based on the differential enhancement weights corresponding to each word in the second visual word, differential enhancement is applied to the attention pointing to the corresponding second visual word at the text-side query position, and the attention pointing to the system prompt word is suppressed. The differential enhancement for the second visual word and the attention suppression for the system prompt word are applied to the same self-attention calculation process.
[0141] In some embodiments, attention to the second visual word at the text-side query location is enhanced to different degrees based on the differentiated enhancement weights corresponding to each second visual word.
[0142] At the same time, attention to system prompt words is reduced according to a preset suppression intensity.
[0143] The inventors discovered that in some large language models, fixed system cue words consistently receive a large proportion of attention, forming an attention convergence phenomenon. When this type of attention accounts for a high proportion, even if the attention corresponding to visual words is enhanced, the actual increase in attention after normalization may still be limited.
[0144] Therefore, this embodiment increases the attention corresponding to high visual importance words while reducing the attention corresponding to some low semantic system prompt words, thus achieving attention adjustment from two directions: increasing visual attention and releasing non-visual attention.
[0145] In a non-restrictive example, the suppression strength of the system suggestion lexical can be determined by parameters. control, It can take a value between 0 and 1, such as 0.1.
[0146] S503, the differential enhancement is performed in the pre-filling stage and the autoregressive incremental decoding stage of the large language model decoder, and the differential enhancement is performed on the attention of the current decoding position pointing to the second visual word in the autoregressive incremental decoding stage, wherein the visual importance prior and the differential enhancement weight obtained for the same input image are reused in multiple autoregressive decoding steps.
[0147] In some embodiments, during the pre-filling stage, attention to second visual words at the text-side query location is enhanced differentially based on the positional relationship of different types of words in the unified input sequence, while attention to words pointing to system prompts is suppressed.
[0148] After entering the autoregressive incremental decoding stage, corresponding visual attention adjustments are performed for each current decoding position.
[0149] For the same input image, the obtained visual importance prior and the determined differential enhancement weights can be cached and reused. Therefore, it is not necessary to re-execute the importance calculation of the visual encoder in every autoregressive generation step, thereby controlling the additional computational overhead caused by selective visual enhancement.
[0150] In some embodiments, obtaining the key state vector corresponding to the current decoding position, using the key state vector as a semantic query signal, and performing correlation calculation with at least the key state vector corresponding to the second visual word to obtain semantic covariant attention that changes with the semantic state of the current decoding position includes: obtaining the input hidden state corresponding to the current decoding position in the current self-attention layer of the at least one self-attention layer, and performing key projection on the input hidden state to obtain the key state vector corresponding to the current decoding position; obtaining the visual key state vector and visual value state vector corresponding to the second visual word in the current self-attention layer, using the key state vector corresponding to the current decoding position as the semantic query signal that is distinct from the query state vector, determining the degree of correlation between the semantic query signal and the visual key state vector, and forming a semantic correlation distribution of the visual word corresponding to the current decoding position based on the degree of correlation; aggregating the visual value state vector according to the semantic correlation distribution of the visual word to obtain the attention result corresponding to the semantic covariant attention; wherein, the key state vector corresponding to the current decoding position is obtained from the input hidden state of the current decoding position in the current self-attention layer, and the semantic correlation distribution of the visual word is updated with the change of the key state vector corresponding to different decoding positions.
[0151] Specifically, in the autoregressive generation process, the input hidden state corresponding to the current decoding position is obtained based on the existing context.
[0152] The existing context can include system prompts, user instructions, visual input, and output words that have been generated before the current decoding position, but does not include target output words that have not yet been generated.
[0153] The input hidden state corresponding to the current decoding position is input into the existing key projection module of the current self-attention layer to obtain the key state vector corresponding to the current decoding position.
[0154] Obtain the visual key state vector corresponding to each second visual word in the current self-attention layer, and combine multiple visual key state vectors into a visual key state matrix.
[0155] The key state vector corresponding to the current decoding position is used as the semantic query signal in the auxiliary attention branch, and its correlation with the visual key state matrix is calculated.
[0156] When the current decoding position changes, the corresponding input hidden state changes, and the key state vector obtained from the input hidden state also changes accordingly. Therefore, the visual lexical semantic relevance distribution can be updated with the autoregressive generation process.
[0157] Obtain the visual value state vector corresponding to each second visual word in the current self-attention layer, and form a visual value state matrix.
[0158] Based on the determined visual word semantic relevance distribution, the visual value state matrix is aggregated to generate the attention result corresponding to semantic covariant attention.
[0159] For example, when the current generation context involves hair attributes, there may be a high correlation between the corresponding key state and the visual lexicon corresponding to the hair region; when the generation context shifts to shoe attributes, the high correlation can be transferred to the visual lexicon corresponding to the shoe region.
[0160] It should be noted that the current example is used to illustrate the relationship between the semantic state at different decoding positions and the visual word interest region, and does not mean that the model has obtained the key state of the target word itself before the target word is generated.
[0161] See Figure 6 , Figure 6 This is a flowchart of a fusion process provided in an embodiment of the present invention, including: S601, the selective visual attention result is determined as the output of the main attention branch, and the attention result corresponding to the semantic covariant attention is determined as the output of the auxiliary attention branch.
[0162] In some embodiments, the selective visual attention result obtained based on the differential enhancement weight is used as the output of the main attention branch, and the attention result corresponding to the semantic covariant attention is used as the output of the auxiliary attention branch.
[0163] The attention of the current decoding position for each second visual word is extracted from the main attention branch and normalized within the range of the second visual word to form the first visual attention distribution.
[0164] The attention formed for the same second visual word is extracted from the auxiliary attention branch to form a second visual attention distribution.
[0165] S602, a first visual attention distribution is formed based on the attention of the main attention branch on the second visual word, and a second visual attention distribution is formed based on the attention of the auxiliary attention branch on the second visual word.
[0166] In some embodiments, statistical distance can be used to evaluate the degree of difference between two visual attention distributions.
[0167] In one implementation, KL divergence can be used: .
[0168] in, Indicates the first The attention of each second visual word in the first visual attention distribution; This indicates the attention of the same second visual word in the second visual attention distribution. Indicates the number of second visual morphemes.
[0169] S603, determine the distribution difference between the first visual attention distribution and the second visual attention distribution, and determine the contribution of the auxiliary attention branch based on the distribution difference, wherein the distribution difference is determined by a statistical distance characterizing the degree of difference between the two attention distributions.
[0170] In some embodiments, when the difference between the first visual attention distribution and the second visual attention distribution is small, it indicates that the visual information currently retrieved by the auxiliary attention branch is relatively consistent with the visual information that the main attention branch has already focused on, thus reducing the contribution of the auxiliary attention branch.
[0171] When the distribution difference is large, it indicates that there is a significant difference between the visual attention region obtained by the auxiliary attention branch for the current decoding semantics and the attention region formed by the main attention branch based on the visual importance prior. Therefore, the contribution of the auxiliary attention branch should be increased.
[0172] The contribution can be determined by a continuous function that monotonically increases with the distribution difference, or by using different contribution values for different distribution difference intervals.
[0173] S604, when the distribution difference decreases, reduce the contribution of the auxiliary attention branch; when the distribution difference increases, increase the contribution of the auxiliary attention branch; and fuse the output of the auxiliary attention branch with the output of the main attention branch according to the contribution to obtain the fused attention result.
[0174] In some embodiments, the output of the auxiliary attention branch is weighted according to the contribution determined in step S603, and the weighted output of the auxiliary attention branch is fused with the output of the main attention branch.
[0175] In some embodiments, the contribution of the auxiliary attention branch output can be: dynamic auxiliary branch contribution. Wherein, the dynamic auxiliary branch contribution can be: .
[0176] in, Indicates the first Contribution of auxiliary attention branches to each decoding position; Indicates the basic contribution level; This represents the distribution difference adjustment coefficient.
[0177] Then, the main and auxiliary attention branches are fused. .
[0178] in, This indicates the selective visual attention result corresponding to the current decoding position; This represents the semantic covariant attention result; This indicates the contribution of the auxiliary attention branch.
[0179] Then, after output projection: ; .in, This represents the final output of the current self-attention layer.
[0180] In this way, through the above steps, the auxiliary attention branch does not always participate in the fusion in a fixed proportion, but dynamically adjusts its role proportion according to the actual difference in attention of the two attention branches to visual words, thereby forming a dynamic balance between global visual information coverage and local semantic visual alignment that changes with the decoding state.
[0181] In one embodiment, determining the contribution of the auxiliary attention branch based on the distribution difference and fusing the output of the auxiliary attention branch with the output of the main attention branch based on the contribution further includes: forming a visual importance distribution based on the visual importance corresponding to the second visual word, and determining the dispersion of the visual importance distribution among the second visual word; determining the contribution of the auxiliary attention branch determined based on the distribution difference as a base contribution, and adjusting the base contribution and the maximum enhancement amplitude corresponding to the differential enhancement weight based on the dispersion; increasing the maximum enhancement amplitude and increasing the contribution of the auxiliary attention branch based on the base contribution when the dispersion increases; decreasing the maximum enhancement amplitude and decreasing the contribution of the auxiliary attention branch based on the base contribution when the dispersion decreases; determining the differential enhancement weight according to the adjusted maximum enhancement amplitude, and fusing the output of the auxiliary attention branch with the output of the main attention branch according to the adjusted contribution of the auxiliary attention branch.
[0182] See Figure 7 , Figure 7This is a schematic diagram comparing the decoding efficiency and object illusion relief effect of the proposed solution with different multimodal large language model illusion relief methods provided in this embodiment of the invention.
[0183] like Figure 7 As shown, the horizontal axis represents the decoding speed of the multimodal large language model in the autoregressive decoding process, and the vertical axis represents the polling-based object detection evaluation index, which is used to characterize the consistency between the content generated by the model and the actual objects in the input image.
[0184] from Figure 7 It can be seen that while some contrast-based decoding-based hallucination mitigation methods can improve the problem of object hallucination, their decoding speed is significantly lower than that of the original decoding method because they need to construct additional inference branches or perform additional model forward processes. Some visual attention-based methods can maintain a high decoding speed, but their uniform or non-selective enhancement of visual lexical units limits their hallucination mitigation effect.
[0185] This invention determines the importance of different visual words by utilizing the existing attention information of the visual encoder, and implements differentiated attention control on different visual words during the decoding process of the large language model. At the same time, it constructs semantic covariant attention that changes with the current decoding semantics by utilizing the existing key states during the decoding process. Therefore, there is no need to perform an additional complete model inference process for the same input.
[0186] Depend on Figure 7 It can be seen that the present invention can improve the evaluation index of object illusion while basically maintaining the original decoding efficiency, thereby achieving a better balance between the effect of visual information utilization and autoregressive decoding efficiency.
[0187] It should be noted that, Figure 7 The data shown is used to illustrate the technical effects of one embodiment of the present invention and does not constitute a limitation on the applicable model, evaluation index or performance value of the present invention.
[0188] The above describes in detail the hallucination relief method based on a multimodal large language model through some embodiments. In order to enable those skilled in the art to better understand and implement it, the corresponding device is also described in detail below through some embodiments.
[0189] See Figure 8 , Figure 8 This is a schematic diagram of a hallucination relief device based on a multimodal large language model provided in an embodiment of the present invention. Figure 8 As shown, the hallucination relief device 800 based on a multimodal large language model may include: The acquisition unit 810 is used to acquire the first visual word unit obtained by the visual encoder after the input image is processed, and to determine the visual importance of each word unit in the first visual word unit based on the attention distribution inside the visual encoder, so as to form a visual importance prior characterizing the difference in information content between different first visual word units. The adjustment unit 820 processes the first visual word into a second visual word input to the large language model decoder after feature projection processing, and maps the visual importance prior to the second visual word according to the feature projection processing correspondence. Based on the visual importance prior, it determines the differential enhancement weight of each word in the second visual word. During the attention calculation process of the large language model decoder, it selectively adjusts the attention corresponding to different second visual words according to the differential enhancement weight, wherein the second visual word with higher visual importance corresponds to a larger enhancement amplitude. The computing unit 830 is used to obtain the key state vector corresponding to the current decoding position during the autoregressive generation process of the large language model decoder, and to use the key state vector as a semantic query signal to perform correlation calculation with at least the key state vector corresponding to the second visual word, so as to obtain semantic covariant attention that changes with the semantic state of the current decoding position. The fusion unit 840 is used to fuse the selective visual attention result obtained based on the differential enhancement weights with the attention result corresponding to the semantic covariant attention in at least one self-attention layer of the large language model decoder to obtain a fused attention result, and to perform autoregressive generation based on the fused attention result.
[0190] See Figure 9 , Figure 9 This is a schematic diagram illustrating the overall principle of a multimodal large language model hallucination mitigation method based on selective visual enhancement and semantic covariant attention, as provided in an embodiment of the present invention.
[0191] like Figure 9 As shown, the multimodal large language model hallucination mitigation method of the present invention mainly includes a visual information processing part, a selective visual enhancement part, a semantic covariant attention part, and a large language model decoding part.
[0192] First, the input image is input to a visual encoder for encoding, resulting in multiple visual terms. While generating these visual terms, the visual encoder simultaneously establishes attention relationships between them within its self-attention layer. This invention obtains these attention relationships from a predetermined self-attention layer of the visual encoder and determines the importance of different visual terms based on these relationships.
[0193] Based on the importance of the visual lexical units, the selective visual enhancement component determines the corresponding enhancement level for different visual lexical units. Specifically, visual lexical units with higher importance receive a greater enhancement level, while those with lower importance receive a smaller enhancement level, thus forming differentiated visual enhancement information for different visual lexical units.
[0194] Visual lexical units obtained by the visual encoder, after feature projection, are input into the large language model decoder along with the corresponding text lexical units. In the self-attention layer of the large language model decoder, the original attention branch performs attention calculations based on the query state, key state, and value state. This invention applies the aforementioned differentiated visual enhancement information to the attention calculation process corresponding to the visual lexical units, thereby improving the large language model's utilization of important visual information.
[0195] Furthermore, in the autoregressive decoding process of the large language model, the present invention obtains the key state corresponding to the current decoding position participating in output prediction, and uses the key state as a semantic query signal to perform correlation calculation with the key state corresponding to the visual word, so as to obtain semantic covariant attention corresponding to the current decoding semantics.
[0196] Since the contextual semantics corresponding to different decoding positions are different, the corresponding key states also change. Therefore, the visual lexical relevance determined by the key states can change dynamically with the autoregressive generation process, enabling the large language model to adjust the visual attention area according to the current generated content.
[0197] This invention further combines the selective visual enhancement results based on the global importance of visual lexical units with the semantic covariant attention results based on the current decoded semantics for attention calculation in large language models.
[0198] Selective visual enhancement is used to maintain attention to globally important visual information in the input image, while semantic covariant attention is used to supplement local visual information relevant to the current decoding semantics. Through their synergistic effect, the model can maintain an overall perception of the image subject and important objects, while also adjusting the visual region of interest based on the current semantics when generating content related to color, shape, position, quantity, or other fine-grained visual attributes.
[0199] In one implementation, attention convergence formed by system cue words in the input sequence can also be suppressed to reduce the occupation of attention resources by system cue words, so that important visual words after differential enhancement can obtain more effective attention enhancement after attention normalization.
[0200] See Figure 10 , Figure 10This is a schematic diagram comparing the visual attention distribution formed by a traditional attention mechanism and the semantic covariant attention mechanism of the present invention for different visual semantic content, as provided in an embodiment of the present invention.
[0201] To facilitate the explanation of the mechanism of semantic covariant attention in this invention, text content related to different local visual attributes was set for the same input image, and the attention of the model to the image region under different attention calculation methods was observed.
[0202] exist Figure 10 In the example shown, one text content relates to the visual attribute of a person's hair, and the other text content relates to the visual attribute of a person's shoes.
[0203] When using traditional query state and key state for attention calculation, the visual attention regions formed for content related to different local visual attributes exhibit high consistency. The model may still focus on similar visual terms under different semantic conditions. Therefore, when it is necessary to read local visual details such as color, position, and shape, the visual information aggregated by the current attention may not completely correspond to the visual region required for the content to be generated.
[0204] After adopting the semantic covariant attention of the present invention, the key state corresponding to the current decoding position participating in the output prediction is used as the semantic query signal, and the correlation between the key state corresponding to the visual word is calculated.
[0205] When the current decoded semantics are related to a person's hair, the visual lexical units corresponding to the hair area receive relatively high semantic covariance attention; when the current decoded semantics are related to a person's shoes, the semantic covariance attention shifts accordingly to the area where the shoes are located.
[0206] Therefore, while keeping the input image unchanged, the visual attention distribution formed by this invention can also change accordingly as the semantics of the current decoding context changes, enabling the model to obtain visual information from visual regions that are more relevant to the currently generated content.
[0207] Through the above methods, the present invention can improve the ability of traditional attention mechanisms to distinguish different fine-grained visual semantics, and improve the model's ability to align visual semantics in the process of generating text related to color, shape, position, quantity and other visual attributes.
[0208] It should be noted that, Figure 10 The examples of hair and shoes shown are only for illustrating the principle that semantic covariant attention adjusts the visual attention area as the current decoded semantics change, and do not constitute a limitation on the categories of visual attributes processed by this invention.
[0209] Accordingly, the present invention also provides an electronic device, comprising: a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps of the hallucination relief method based on the multimodal large language model described in any of the foregoing embodiments.
[0210] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0211] The above embodiments merely illustrate several implementation methods of the present invention, and their descriptions are relatively specific and detailed, but they should not be construed as limiting the scope of the invention patent. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of the present invention, and these all fall within the protection scope of the present invention. Therefore, the protection scope of this invention patent should be determined by the appended claims.
Claims
1. A hallucination relief method based on a multimodal large language model, characterized in that, include: The first visual word unit obtained by processing the input image through the visual encoder is obtained, and the visual importance of each word unit in the first visual word unit is determined based on the attention distribution inside the visual encoder, so as to form a visual importance prior that represents the difference in information content between different first visual word units. The first visual word is processed by feature projection to obtain the second visual word input to the large language model decoder. The visual importance prior is mapped to the second visual word according to the feature projection processing correspondence. The differential enhancement weight of each word in the second visual word is determined according to the visual importance prior. During the attention calculation process of the large language model decoder, the attention corresponding to different second visual words is selectively adjusted according to the differential enhancement weight. Among them, the second visual word with higher visual importance corresponds to a larger enhancement amplitude. In the autoregressive generation process of the large language model decoder, the key state vector corresponding to the current decoding position is obtained. The key state vector is used as a semantic query signal and at least the correlation is calculated with the key state vector corresponding to the second visual word to obtain semantic covariant attention that changes with the semantic state of the current decoding position. In at least one self-attention layer of the large language model decoder, the selective visual attention result obtained based on the differential enhancement weights is fused with the attention result corresponding to the semantic covariant attention to obtain a fused attention result, and autoregressive generation is performed based on the fused attention result.
2. The hallucination relief method according to claim 1, characterized in that, Determining the visual importance of each word in the first visual word based on the attention distribution within the visual encoder includes: The penultimate layer of the visual encoder is selected as the target self-attention layer, and the attention distribution in the target self-attention layer is obtained. When the visual encoder includes a global aggregation lexicon for aggregating global visual information, the attention of the global aggregation lexicon pointing to the first visual lexicon is obtained, and the attention corresponding to different attention heads is aggregated. The visual importance of each lexicon in the first visual lexicon is determined based on the aggregated attention. When the visual encoder does not include the global aggregated lexical, the self-attention between the first visual lexical is obtained, and for each lexical in the first visual lexical, the self-attention of other first visual lexical points to that lexical is aggregated, and the visual importance of the lexical is determined based on the aggregated self-attention.
3. The hallucination relief method according to claim 1, characterized in that, The step of mapping the visual importance prior to the second visual lexical unit based on the feature projection processing correspondence includes: Determine the word correspondence between the first visual word and the second visual word obtained through the feature projection processing; When the feature projection processing keeps the number and correspondence between the first visual word and the second visual word unchanged, the visual importance of each word in the first visual word is transferred to the corresponding second visual word. When the feature projection processing merges, pools, filters, or compresses multiple first visual lexical units, the visual importance of the corresponding first visual lexical units is aggregated, selected, or mapped according to the first visual lexical units that participate in forming each second visual lexical unit and the lexical transformation relationship corresponding to the feature projection processing, so as to obtain the visual importance of each lexical unit in the second visual lexical unit.
4. The hallucination relief method according to claim 1, characterized in that, The step of determining the differential enhancement weights of each word in the second visual word based on the visual importance prior includes: Obtain the visual importance of each corresponding to the second visual word, and normalize each visual importance according to the maximum and minimum values among the visual importance; The normalized visual importance is mapped to a preset finite enhancement interval according to a continuous and monotonic mapping relationship. The mapping relationship maintains the relative size relationship between the visual importance. The second visual word with higher visual importance corresponds to a larger differential enhancement weight, and the second visual word with lower visual importance corresponds to a smaller differential enhancement weight. The differential enhancement weights are restricted to the limited enhancement range, and the attention corresponding to each second visual word is adjusted according to the differential enhancement weights corresponding to each word in the second visual word.
5. The hallucination relief method according to claim 1, characterized in that, During the attention calculation process of the large language model decoder, the attention corresponding to different second visual lexical units is selectively adjusted according to the differential enhancement weights, including: Obtain the unified input sequence input to the large language model decoder, and determine the system prompt word and the text-side query position, including the current decoding position, from the unified input sequence; Based on the differential enhancement weights corresponding to each word in the second visual word, differential enhancement is applied to the attention pointing to the corresponding second visual word at the text-side query position, and the attention pointing to the system prompt word is suppressed. The differential enhancement for the second visual word and the attention suppression for the system prompt word are applied to the same self-attention calculation process. The differential enhancement is performed in the pre-filling stage and the autoregressive incremental decoding stage of the large language model decoder, and the differential enhancement is performed on the attention of the current decoding position pointing to the second visual word in the autoregressive incremental decoding stage, wherein the visual importance prior and the differential enhancement weights obtained for the same input image are reused in multiple autoregressive decoding steps.
6. The hallucination relief method according to claim 1, characterized in that, The step of obtaining the key state vector corresponding to the current decoding position, using the key state vector as a semantic query signal, and performing correlation calculation with at least the key state vector corresponding to the second visual word to obtain semantic covariant attention that changes with the semantic state of the current decoding position includes: In the current self-attention layer of the at least one self-attention layer, the input hidden state corresponding to the current decoding position is obtained, and the input hidden state is key-projected to obtain the key state vector corresponding to the current decoding position; Obtain the visual key state vector and visual value state vector corresponding to the second visual word in the current self-attention layer, use the key state vector corresponding to the current decoding position as the semantic query signal that is different from the query state vector, determine the degree of correlation between the semantic query signal and the visual key state vector, and form the semantic correlation distribution of the visual word corresponding to the current decoding position based on the degree of correlation. The visual value state vector is aggregated based on the visual word semantic relevance distribution to obtain the attention result corresponding to the semantic covariant attention; The key state vector corresponding to the current decoding position is obtained from the input hidden state of the current decoding position in the current self-attention layer, and the visual lexical semantic relevance distribution is updated as the key state vector corresponding to different decoding positions changes.
7. The hallucination relief method according to claim 1, characterized in that, The step of fusing the selective visual attention result obtained based on the differential enhancement weights with the attention result corresponding to the semantic covariant attention includes: The selective visual attention result is determined as the output of the main attention branch, and the attention result corresponding to the semantic covariant attention is determined as the output of the auxiliary attention branch. A first visual attention distribution is formed based on the attention of the main attention branch on the second visual word, and a second visual attention distribution is formed based on the attention of the auxiliary attention branch on the second visual word. Determine the distribution difference between the first visual attention distribution and the second visual attention distribution, and determine the contribution of the auxiliary attention branch based on the distribution difference, wherein the distribution difference is determined by the statistical distance characterizing the degree of difference between the two attention distributions; When the distribution difference decreases, the contribution of the auxiliary attention branch is reduced; when the distribution difference increases, the contribution of the auxiliary attention branch is increased; and the output of the auxiliary attention branch is fused with the output of the main attention branch according to the contribution to obtain the fused attention result.
8. The hallucination relief method according to claim 7, characterized in that, The step of determining the contribution of the auxiliary attention branch based on the distribution difference, and fusing the output of the auxiliary attention branch with the output of the main attention branch based on the contribution, further includes: A visual importance distribution is formed based on the visual importance corresponding to the second visual word, and the degree of dispersion of the visual importance distribution among the second visual word is determined. The contribution of the auxiliary attention branch determined based on the distribution difference is determined as the base contribution, and the base contribution and the maximum enhancement magnitude corresponding to the differentiated enhancement weight are adjusted according to the degree of dispersion. When the dispersion increases, the maximum enhancement amplitude is increased, and the contribution of the auxiliary attention branch is increased based on the base contribution; when the dispersion decreases, the maximum enhancement amplitude is decreased, and the contribution of the auxiliary attention branch is decreased based on the base contribution. The differentiated enhancement weight is determined according to the adjusted maximum enhancement magnitude, and the output of the auxiliary attention branch is fused with the output of the main attention branch according to the adjusted contribution of the auxiliary attention branch.
9. A hallucination relief device based on a multimodal large language model, characterized in that, include: The acquisition unit is used to acquire the first visual word units obtained by processing the input image through the visual encoder, and determine the visual importance of each word unit in the first visual word unit based on the attention distribution inside the visual encoder, so as to form a visual importance prior characterizing the information content difference between different first visual word units. The adjustment unit processes the first visual word into a second visual word input to the large language model decoder after feature projection processing. It then maps the visual importance prior to the second visual word according to the feature projection processing correspondence. Based on the visual importance prior, it determines the differential enhancement weight of each word in the second visual word. During the attention calculation process of the large language model decoder, it selectively adjusts the attention corresponding to different second visual words according to the differential enhancement weight. The second visual word with higher visual importance corresponds to a larger enhancement magnitude. The computing unit is used to obtain the key state vector corresponding to the current decoding position during the autoregressive generation process of the large language model decoder, and to use the key state vector as a semantic query signal to perform correlation calculation with at least the key state vector corresponding to the second visual word, so as to obtain semantic covariant attention that changes with the semantic state of the current decoding position. The fusion unit is configured to, in at least one self-attention layer of the large language model decoder, fuse the selective visual attention result obtained based on the differential enhancement weights with the attention result corresponding to the semantic covariant attention to obtain a fused attention result, and perform autoregressive generation based on the fused attention result.
10. An electronic device, comprising: A memory and a processor, the memory storing a computer program, characterized in that the processor, when executing the computer program, implements the steps of the hallucination relief method based on a multimodal large language model as described in any one of claims 1 to 8.
