A Large Language Model Illusion Reduction Method Based on Entropy-Triggered Visual Attention Backtracking
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2026-01-26
- Publication Date
- 2026-08-11
AI Technical Summary
[0017]本发明的目的在于解决多模态大语言模型中因模态融合层视觉注意力不足及后验层特征分布不匹配引起的对象幻觉与近模态坍塌问题
[0066]1.本发明通过步骤S3中引入的“熵触发机制”,有效地解决了现有视觉增强方法中因“盲目干预”导致的噪声引入与计算资源浪费问题,实现了对视觉注意力准确、有效地增强,对模型幻觉的精准、低耗抑制。现有技术(如VAF等)通常采用静态或全局的方式在特定层级无差别地放大视觉注意力权重。这种“地毯式”的增强策略忽略了模型在不同样本或不同生成步数下的置信度差异。
Smart Images

Figure CN121982494B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology and provides a method for reducing illusions in large language models by triggering visual attention backtracking. Background Technology
[0002] In recent years, with the continuous evolution of deep learning architectures, multimodal large language models (MLLMs) have achieved significant breakthroughs in the field of artificial intelligence. By integrating and collaboratively processing data from multiple modalities such as vision, audio, and text, MLLMs have demonstrated outstanding cross-modal understanding and reasoning capabilities, exhibiting remarkable performance in various application scenarios such as image captioning, complex visual question answering (VQA), and multimodal dialogue systems. These models are typically based on large-scale pre-trained data and leverage the powerful sequence modeling capabilities of the Transformer architecture to achieve a leap from perception to cognition.
[0003] However, despite the excellent performance of existing multimodal large language models in various benchmark tests, they still face significant technical challenges in practical application deployment. Among these, the most prominent and urgent problem to be solved is "object hallucination." Specifically, object hallucination refers to the phenomenon where the text response generated by the model contains objects that do not actually exist in the input image or data, or provides descriptions that contradict the content of the input data and cannot be verified by the input data. This phenomenon essentially reflects a discrepancy between the model's visual perception features and the language decoding process.
[0004] In critical application areas with extremely high requirements for safety and accuracy, such as autonomous driving, medical imaging diagnosis, clinical decision support, and security monitoring, the object illusion problem can seriously undermine users' trust in the system and even lead to unforeseen safety risks and ethical issues.
[0005] To alleviate the aforementioned object illusion problem, existing research has proposed various solutions. Generally speaking, existing technologies can be summarized into the following main technical schools:
[0006] The first category is based on Retrieval-Augmented Generation (RAG) methods. These methods introduce external knowledge bases to retrieve relevant information during the generation process to assist model decision-making, thereby mitigating illusions. However, this approach is highly dependent on the quality and coverage of the external retrieval system, and introducing external knowledge bases significantly increases system complexity and maintenance costs.
[0007] The second category is based on supplementary fine-tuning. This strategy aims to enhance the consistency of the model's generated text by further training on a specific dataset. However, both RAG and fine-tuning strategies share a common drawback: they require additional high-quality labeled data for post-hoc debiasing. This not only increases the human cost of data collection and cleaning but also introduces significant computational overhead and a lengthy training cycle, making it difficult to adapt to the needs of rapidly iterating applications.
[0008] The third category consists of training-free inference-stage strategies, primarily including attention intervention and contrastive decoding (CD). Attention intervention typically involves retrospectively redistributing the attention map during inference; contrastive decoding requires adjusting the generation probabilities by constructing a contrastive model or contrastive path.
[0009] While these two approaches avoid additional model training, they typically require complex computational operations during the decoding process, such as backtracking or multi-model parallel inference, which leads to extremely high inference latency, making it difficult to meet the response speed requirements of real-time interactive systems.
[0010] Among the various methods mentioned above, visual attention enhancement-based approaches have become a highly popular technological direction due to their relative simplicity and efficiency. Visual amplification fusion (VAF), the closest existing technology in this direction, has been proposed to address the problem of illusions.
[0011] Specifically, the VAF (Visual Aspect-Oriented Function) strategy advocates amplifying the model's attentional weights to visual information through human intervention in the model's Modality Fusion Layer (e.g., layers 9 to 14). Its core logic is to force the model to rely more on visual input when generating text by increasing the weight of visual features in the fusion stage, thereby reducing the generation of illusions detached from image content.
[0012] Existing methods based on visual attention enhancement still have some drawbacks:
[0013] 1. Disproportionate enhancement of attention: Although the visual attention head in the modality fusion layer is enhanced, the enhancement of text attention far outweighs the enhancement of visual attention.
[0014] 2. Disruption of the original feature balance: The visual signals introduced by directly amplifying the weights may not be effectively semantically understood by the model.
[0015] 3. Near-modal collapse problem: The enhanced model begins to ignore visual input and relies excessively on the prior probabilities of the language model for generation.
[0016] Therefore, all these phenomena indicate that the simple and crude attention amplification methods in the existing technology have not fundamentally solved the problem of weak visual attention. On the contrary, they have introduced new noise and feature degradation to a certain extent, limiting the further improvement of model performance. Summary of the Invention
[0017] The purpose of this invention is to solve the problems of object illusion and near-modal collapse caused by insufficient visual attention in the modality fusion layer and mismatch in feature distribution of the posterior layer in multimodal large language models.
[0018] The core of this invention is the introduction of two key mechanisms during the inference phase: entropy-triggered visual attention backtracking and moment-matching-based modality protection. The method of this invention mainly includes the following steps:
[0019] S1: Input data reception and preprocessing
[0020] The system receives multimodal input data, including image data. and text prompts ,in The system template is Prompt. The prompt provided by the user.
[0021] 1. Process image data using a visual encoder, extract visual feature blocks, and map them to the embedding space of a language model through a linear projection layer to obtain a visual token sequence. .
[0022] 2. Use a tokenizer to process the text prompts and convert them into a text token sequence. .
[0023] 3. Concatenate the visual token sequence with the text token sequence to form the model's input sequence. ;
[0024] S2: Forward propagation of a multi-layer Transformer network
[0025] The input sequence is fed into the backbone network of a large language model. This backbone network consists of L layers of stacked Transformer decoders (e.g., 32 layers). In each layer l, the model computes self-attention and updates the hidden states. The hierarchical logic of the model in this invention is divided into three stages:
[0026] Shallow Layers: Primarily responsible for feature extraction and physical alignment of the lower layers;
[0027] Modality Fusion Layers: This is the key area for deep semantic fusion of visual and textual information, and also the main area for implementing "visual attention backtracking" in this invention;
[0028] The posterior layer is responsible for converting the fused features into the final text output and is also the main area where the "modal protection" of this invention is implemented.
[0029] S3 Core Module 1: Entropy-Triggered Visual Attention Regression
[0030] S3.1: Obtain the baseline attention score matrix
[0031] In the initial stage of model inference, the attention score matrix of the attention heads in this layer is recorded. Specifically, let... For the initial layer The attention score matrix for each attention head. This is because the initial attention distribution shows higher attention to visual features, i.e., it is more faithful to the visual input. This matrix... This will serve as the "anchor head h" for subsequent backtracking.
[0032] S3.2: Calculating Hierarchical Uncertainty (Entropy Calculation)
[0033] When the model inference reaches the modality fusion layer (let the current layer be l, and...), When performing a calculation, the system first evaluates the "perplexity" of the model at the current layer. The specific calculation process is as follows:
[0034] 1. Get the current layer Hidden state of input ;
[0035] 2. Calculate the vocabulary probability distribution for the current step using LayerNorm and the classification head. .
[0036]
[0037]
[0038] in, This represents a linear transformation that maps to the vocabulary size.
[0039] 3. Calculate the entropy value of the input hidden state of this layer. To quantify uncertainty:
[0040]
[0041] Where N is the vocabulary size, It represents the probability of the i-th word. The higher the entropy value, the flatter the probability distribution, and the more "confused" or "uncertain" the model is about what content should be generated.
[0042] S3.3: Conditional Triggers and Attention Redistribution
[0043] Set a preset entropy threshold. :
[0044] Judgment: If the entropy of the current layer is... If the model is confident and requires no intervention, continue with normal reasoning; otherwise, backtracking should be performed.
[0045] Execution backtracking: If This indicates that the model is confused and is very likely experiencing hallucinations. At this point, the visual attention backtracking mechanism is activated.
[0046] The specific operation of visual attention backtracking is to use the attention matrix of the initial layer... Attention matrix injected into the current layer Corrected attention score The calculation formula is as follows:
[0047]
[0048] in, It is the retrospective coefficient, used to control the intensity of introducing shallow visual information. Subsequently, the corrected scores are normalized to obtain the final attention weights:
[0049]
[0050] S4: Modal protection based on moment matching
[0051] Because the posterior layer of a multimodal large model inherently favors the distribution of text features, when visual features are enhanced in the fusion layer, their statistical distribution parameters may differ significantly from those of the text features, leading to a substantial decrease in the attention the posterior layer pays to visual information compared to the original. To address this issue, this module of the present invention adjusts the distribution of visual features to make them statistically converge with those of text features.
[0052] S4.1: Feature Separation and Statistical Calculation
[0053] Hidden state in the target layer Separate into visual parts and Calculate text features First moment ) and second moment :
[0054]
[0055]
[0056] Similarly, computational visual features of and .
[0057] S4.2: Distribution Alignment Variation
[0058] We utilize the concept of Adaptive Instance Normalization (AdalN) to transform visual features. Specifically, we first "de-normalize" the visual features to a standard normal distribution, and then "re-normalize" them using the mean and standard deviation of the text features. The transformation formula is as follows:
[0059]
[0060] Through this step, the transformed visual features Its distribution is more similar to text features.
[0061] S4.3: Dynamic Fusion
[0062] To preserve the original semantic content of visual features, this invention employs residual fusion. Simultaneously, as the number of layers increases, a dynamic attenuation coefficient is introduced to prevent over-intervention. Final revised visual features for:
[0063]
[0064] Here, β is a dynamically adjusted parameter. It varies with the number of layers. The distribution gradually decreases as the layer increases. This design ensures strong distribution correction immediately after leaving the fusion layer, while reducing intervention as the layer approaches the output layer, maintaining the consistency and naturalness of the generated output.
[0065] Because the present invention employs the above-mentioned technical means, it has the following beneficial effects:
[0066] 1. This invention, through the "entropy triggering mechanism" introduced in step S3, effectively solves the problems of noise introduction and computational resource waste caused by "blind intervention" in existing visual enhancement methods, achieving accurate and effective enhancement of visual attention and precise, low-cost suppression of model illusions. Existing technologies (such as VAF) typically amplify visual attention weights indiscriminately at specific levels using a static or global approach. This "carpet-bombing" enhancement strategy ignores the differences in confidence levels of the model across different samples or different generation steps.
[0067] When the model itself has high confidence in the current input, forcibly enhancing it and introducing additional visual signals can disrupt the model's original smooth output chain, introduce unnecessary feature noise, and reduce the coherence of the generated results. To address this issue, in steps S3.2 and S3.3, this invention innovatively uses Shannon entropy as a quantitative indicator of the model's "perplexity".
[0068] By calculating the entropy value of the vocabulary probability distribution, the system can perceive the current internal state of the model in real time: when the entropy value is lower than a preset threshold, it indicates that the model is in a "confident" state, and this invention intelligently chooses to "remain silent" without additional intervention, thereby preserving the original language generation coherence of the model to the greatest extent; only when the entropy value exceeds the threshold (i.e., the model is "confused" or "hesitant") is visual attention backtracking triggered. This "on-demand allocation" computation strategy not only avoids interference with the correct reasoning process and greatly reduces the risk of misguidance, but also effectively saves computational overhead in the reasoning process, achieving a dual optimization of computational accuracy and efficiency.
[0069] 2. This invention, through the "visual attention backtracking" implemented in steps S3.1 and S3.3, utilizes the high-fidelity visual features of shallow networks as anchor points, solving the "object illusion" problem caused by insufficient visual attention in the modality fusion layer, and significantly improving the true alignment between the generated text and visual content. In deep networks of Multimodal Large Language Models (MLLM) (especially modality fusion layers of layers 9-14), as the number of layers increases, the model's attention to visual features is significantly lower than that to text features.
[0070] This invention deeply understands this mechanism, explicitly stating in step S3.1 that the initial layer's attention matrix is most faithful to the visual input. Based on this, in step S3.3, this invention employs a "backtracking" strategy, injecting this highly visually focused initial attention matrix into the deep modal fusion layer triggered by entropy. This technique is equivalent to forcing the model to "look back" at the most original and clearest visual evidence when it is "confused." By introducing a backtracking coefficient α, this invention calibrates deep attention using underlying perceptual information without completely covering deep semantics. This "source-guided" mechanism fundamentally corrects the model's attention bias in the fusion stage, significantly reducing the incidence of object illusion in quantitative metrics (such as POPE and CHAIR).
[0071] 3. This invention, through the "moment-matching-based modal protection" proposed in step S4, solves the "near-modal collapse" problem caused by feature distribution mismatch in existing technologies, ensuring the effective retention and utilization of visual information in the deep generation stage. Although step S3 enhances visual attention, the posterior layers of multimodal large models (layers 15 and beyond as defined in step S2) are usually fine-tuned from pure text large models, and their weight matrices have an inherent bias towards the statistical distribution of text features. When visual features are significantly enhanced in the fusion layer, their statistical features (such as mean and variance) often exhibit a significant distributional shift from text features. Faced with such "heterogeneous" strong signals, the adaptive mechanism of the posterior layer treats them as noise and suppresses them, causing the model to ignore visual information in the final generation stage, which is "near-modal collapse".
[0072] To overcome this deep-seated hidden danger, this invention introduces moment matching technology in steps S4.1 and S4.2. By calculating the first moment (mean) and second moment (standard deviation) of the text features, and using the adaptive instance normalization formula in S4.2, the distribution of visual features is forcibly adjusted to resemble the shape of text features. This process essentially "mimics" the visual features, making them statistically more like text features, thereby minimizing the "rejection reaction" of the posterior layer. Through this distribution alignment, visual semantics can pass smoothly through the posterior layer without suppression, fundamentally avoiding modality collapse and ensuring that the visual enhancement effect can truly extend to the final text output.
[0073] 4. This invention, through the "dynamic residual fusion strategy" in step S4.3, utilizes coefficients that decay with layer depth to solve the balance problem between feature intervention and language model fluency, achieving the effect of preserving visual semantics without compromising text generation quality. If only a rigid distribution replacement is performed, although modality collapse is solved, it may result in the loss of fine-grained semantic information originally contained in the visual features, or lead to abrupt changes in the language style of the generated text.
[0074] In step S4.3, this invention employs a sophisticated dynamic fusion formula. First, residual connections are used to ensure that the original visual feature information is not completely covered. Second, a dynamic attenuation coefficient that gradually decreases with increasing layer number is introduced. It is larger immediately after leaving the modality fusion layer (i.e., the region with the highest risk of "collapse"), applying strong distribution correction to prevent feature loss. As the network progresses to the output layer, the model's prediction of the next word becomes clearer, at which point the coefficient is reduced to decrease the intervention intensity, allowing the model to return to its natural generation logic. This dynamic balancing mechanism ensures that the text generated by the model is faithful to the image content (avoiding illusions) while maintaining the high fluency and grammatical correctness of natural language.
[0075] 5. This invention comprehensively utilizes the full-process techniques from S1 to S4 to achieve a "training-free" plug-and-play illusion elimination scheme, solving the engineering challenges of existing methods that rely on expensive heavy training or high-latency external retrieval. Existing RAG methods require maintaining a large external database, increasing system complexity and retrieval latency; while fine-tuning methods require thousands of GPU hours and a large amount of labeled data. In contrast, the technical solution of this invention is entirely based on internal activation intervention during the inference stage. From the data input in step S1 to the feature output in S4, the entire process involves only matrix addition and subtraction operations (S3.3), basic statistical calculations (S4.1), and simple linear transformations (S4.2), without any backpropagation or parameter updates. This means that this method can be seamlessly integrated into any existing multimodal large-scale model based on the Transformer structure with almost no additional inference latency.
[0076] 6. This invention combines the "entropy-triggered visual attention backtracking" in step S3 with the "moment-matching-based modality protection" in step S4. This combination ensures that the corrected visual information possesses both semantic accuracy and feature distribution compatibility, allowing it to successfully pass through the model's posterior layer and participate in the final generation. This enables the invention to stably and efficiently solve the object illusion problem in multimodal large language models without retraining, while maintaining the coherence of text generation. Attached Figure Description
[0077] Figure 1 A flowchart of the large language model workflow;
[0078] Figure 2 This is a schematic diagram illustrating the principle of illusion reduction in large-scale models. Detailed Implementation
[0079] The embodiments of the present invention will be described in detail below. Although the present invention will be described and illustrated in conjunction with some specific embodiments, it should be noted that the present invention is not limited to these embodiments. On the contrary, any modifications or equivalent substitutions made to the present invention should be covered within the scope of the claims of the present invention.
[0080] Furthermore, to better illustrate the present invention, numerous specific details are set forth in the following detailed embodiments. Those skilled in the art will understand that the present invention can be practiced without these specific details.
[0081] The purpose of this patent is to provide an innovative method to alleviate the illusion problem of large multimodal models. This method can perform visual attention backtracking by judging the perplexity of each modal fusion layer's output during the decoding stage of the large model, while maintaining modal balance in subsequent layers. This reduces the illusion of large multimodal models and generates more reliable text. This invention aims to solve the following problems of existing technologies:
[0082] 1. Achieve precise enhancement of visual attention: By detecting the perplexity of the modal fusion layer, the stage of enhancing visual attention can be accurately determined. By backtracking visual attention, the model's attention to visual features in the modal fusion layer can be significantly enhanced.
[0083] 2. Maintain the original feature balance of the model: Since visual attention backtracking does not destroy the original attention weights, additional visual features are added in addition to maintaining the original feature distribution.
[0084] 3. Preserve enhanced modal behavior: The moment matching method can make the enhanced visual information and text information more homogeneous, that is, maintain the deep text preferences of the model to preserve the enhanced modal behavior.
[0085] This patent proposes an entropy-triggered visual-attention backtracking method. It uses the principle of entropy to accurately describe the perplexity of the model's inter-layer output in the modality fusion layer, thereby accurately identifying and applying visual attention backtracking. Furthermore, through visual attention backtracking, the model corrects the attention of some modality fusion layers, enabling the model to focus more on visual features. This adds additional visual features to the modality fusion layer, improving the deep fusion of visual and textual elements in the multimodal large model within the modality fusion layer.
[0086] In addition, this patent also solves the near-modal collapse problem after enhancement by using the moment matching method. By adjusting the visual features to "text-like", the rejection response of deep networks to heterogeneous visual signals is eliminated, so that the model can naturally accept and integrate visual features without destroying the original language generation ability. This fundamentally avoids modal collapse caused by feature distribution mismatch and significantly improves the utilization rate and fidelity of visual information in the generation process.
[0087] This invention provides a method for eliminating object illusions in multimodal large language models based on entropy-triggered visual attention backtracking, applicable to various multimodal large language model frameworks. To clearly illustrate the implementation details, this embodiment selects the widely used open-source multimodal model LLaVA-v1.5-7B from academia and industry as the basic backbone network. The specific parameter configuration of this model is as follows, which constitute the physical basis for the algorithm's operation:
[0088] Visual encoder: The CLIP-ViT-L-336px model is used. This encoder processes the input image into visual feature vectors. The input image resolution is adjusted to 336×336 pixels, and the Patch Size is set to 14, therefore the number of generated visual tokens is (336 / 14). 2 =576.
[0089] Modal projection layer (Projector): Employs a two-layer multilayer perceptron (MLP) to map the dimensions of visual features from the 1024 dimensions of CLIP to the 4096 dimensions of the language model.
[0090] Large Language Model Backbone (LLM Backbone): Employs Vicuna-7B-v1.5 (based on the LLaMA-2 architecture). This backbone network contains L layers of Transformer decoders (L=32), hidden layer dimension D=4096, attention heads H=32, and vocabulary size N=32000.
[0091] Based on the above model configuration, the reasoning process of this invention includes the following four core steps:
[0092] S1: Input data reception and vectorization processing
[0093] At the start of inference, the system receives an image input by the user. and a text prompt , Right now For example, "Please describe the content in the picture in detail".
[0094] 1. Visual Feature Extraction: The processor calls the visual encoder to extract visual features from the image. Feature extraction is performed to obtain the original visual feature sequence. Then, spatial mapping is performed through a modal projection layer to obtain the visual Toke sequence. , each of Represents the first in the visual token sequence One visual feature vector;
[0095] 2. Text Encoding: The processor calls the tokenizer to encode the text prompt. Convert to a text token sequence ,in, Indicates the first in the sequence A text token for each location.
[0096] 3. Sequence concatenation: The visual sequence V and the text sequence T are concatenated along the sequence length dimension to form the model's input embedding. The input sequence is fed into the Vicuna-7B backbone network.
[0097] S2: Forward Propagation Based on Hierarchical Functional Division
[0098] Based on the hierarchical characteristics of the LLaVA-v1.5-7B model, this invention divides the 32-layer Transformer network logic into three functional regions:
[0099] Shallow layers (layers 0-8): responsible for feature extraction and physical modality alignment of the lower layers.
[0100] Modal fusion layer (layers 9-14): This is the key area for deep interaction between visual information and textual semantics, and it is also the target area for implementing "visual attention backtracking" in this invention.
[0101] Posterior layer (layers 15-31): responsible for converting the fused features into the final text output, and is also the target area for implementing "modal protection" in this invention.
[0102] S3: Entropy-triggered visual attention regression
[0103] This step aims to address the "object illusion" problem, which prevents the model from generating objects that do not exist in the image.
[0104] S3.1 Anchor Point Acquisition: When the inference process reaches Layer 0, the system intercepts and temporarily stores the attention score matrix for that layer. Specifically, for each attention head in Layer 0... Record its attention score matrix .
[0105] Implementation details: Since Layer 0 is closest to the input, experimental observations show that this layer shows the highest attention to the visual token. Therefore, It is selected as the "anchor point" for subsequent calibration, where Z represents the attention score matrix, subscript 0 represents the initial layer, and subscript h represents the h-th attention head.
[0106] S3.2 Entropy Calculation and Trigger Judgment: When inference progresses to the modality fusion layer (Layer 9 in LLaVA-v1.5-7B), the system pauses regular calculations and first assesses the "uncertainty" of the model.
[0107] 1. Get the hidden state of the current layer's output. The vocabulary probability distribution of the current step is calculated using LayerNorm and a linear mapping layer. The subscript 9 indicates that this is the 9th layer in the Transformer network.
[0108] 2. Calculate Shannon entropy ,in The model predicts the first The probability value of each word. ;
[0109] 3. Judgment logic: Set the entropy threshold γ=0.75.
[0110] like This indicates that the model is very confident in the currently generated content (e.g., generating function words "is" or "the"), and in this case, no intervention is made, and the output is directly provided.
[0111] like When the model is in a state of "confusion," it is prone to hallucinations (such as hesitating between "Apple" and "Ball"). At this time, set the global trigger flag to TRUE and activate the backtracking mechanism.
[0112] S3.3 Attention Reassignment: In the triggered state, the system will reassign the previously stored Layer 0 attention matrix. The weighted injection is applied to the layer that triggers the backtracking mechanism, for example, the original attention matrix of the current 12th layer. In the middle. The backtracking coefficient α is set to 0.3. The corrected formula is: Subsequently, on Softmax normalization is then performed. This step forces the model to "look back" at the visual region that Layer 0 focuses on, thereby correcting the attention bias caused by deep semantic drift.
[0113] S4: Modal protection based on moment matching
[0114] If backtracking is triggered in step S3 (i.e., a TRUE state), modal protection must be performed in subsequent layers to prevent "near-modal collapse." This is because the enhanced visual feature distribution may be incompatible with the text feature distribution preferred by the Vicuna-7B deep network.
[0115] S4.1 Feature Statistics Calculation: Taking the 20th layer as an example, the input is the hidden state. The system divides it into visual components. and text section The system calculates text features separately. and visual features The first moment μ (mean) and the second moment (Standard deviation)
[0116]
[0117]
[0118] in This represents a statistical function used to calculate the first moment (mean) and second moment (standard deviation) of the input feature matrix:
[0119] Calculate text features mean ) and standard deviation The calculation formula is as follows:
[0120]
[0121]
[0122] in Indicates the number of text tokens. Indicates the first Layer The hidden state of each token, where ϵ is a small constant to prevent division by zero;
[0123] Computational visual features mean and standard deviation The calculation formula is as follows:
[0124]
[0125]
[0126] in Indicates the number of visual tokens. Indicates the range of summation over the visual token index;
[0127] S4.2 Distribution Alignment Transformation: Utilizing the principle of adaptive instance normalization, the distribution of visual features is forcibly adjusted to resemble the distribution of text features. Transformed visual features. The calculation is as follows:
[0128]
[0129] After this transformation, visual features statistically achieve "mimicry" of text features, reducing the "rejection response" of deep networks.
[0130] S4.3 Dynamic Residual Fusion
[0131] To balance the original semantics of the features with distribution compatibility and achieve a smooth transition, this embodiment introduces a dynamic attenuation coefficient. .set up The initial value (at layer 15) is 0.5, and it decays linearly with the number of layers to 0 (at layer 32). For layer 20, the calculation... :
[0132] The final corrected visual features are:
[0133]
[0134] This step ensures that the visual information retains the accurate content corrected in step S3, and also has the compatible distribution obtained in step S4, thus enabling it to successfully pass through the posterior layer and participate in the final generation.
Claims
1. A method for reducing hallucinations in a large language model using entropy-triggered visual attention backtracking, characterized in that, Includes the following steps: Step S1: Input data reception and preprocessing: Receive multimodal input data containing image data and text prompts, extract image features through a visual encoder and map them to the language model embedding space to obtain a visual token sequence, convert the text prompts into a text token sequence through a word segmenter, and concatenate the visual token sequence and the text token sequence to form the input sequence. Step S2: Forward propagation of multi-layer Transformer network: The input sequence is fed into the backbone network containing multi-layer Transformer decoders for forward propagation. The backbone network is logically divided into shallow layer, modality fusion layer and posterior layer. The shallow layer is used for low-level feature extraction, the modality fusion layer is used for deep semantic fusion of visual and text information, and the posterior layer is used to generate the final text output. Step S3: Entropy-triggered visual attention backtracking: When inference reaches the modality fusion layer, the hidden state of the current layer's input is obtained. A vocabulary probability distribution is obtained through mapping, and Shannon entropy is calculated based on this distribution to represent the current layer's perplexity with the input. When the model's perplexity with the input exceeds a preset threshold... At that time, the attention score matrix of the initial layer of the model is injected into the attention matrix of the current layer in a weighted manner, through the backtracking coefficients. Control the injection intensity; Step S4: Modality protection based on moment matching: In the posterior layer, the hidden state is separated into visual and text parts. The mean and standard deviation of the text features are calculated. The visual features are normalized and then renormalized using the mean and standard deviation of the text features to make the distribution of visual features approximate the distribution of text features. Then, the transformed visual features are fused with the original visual features proportionally through dynamic residual fusion. The fusion ratio coefficient β decreases linearly from the posterior layer to 0 in the output layer to prevent near-modal collapse, that is, to prevent the visually enhanced features from being suppressed in the deep network.
2. The method according to claim 1, characterized in that: Step S1.1: The system receives multimodal input data, which includes image data. and text prompts ,in The system template is Prompt. The prompt provided by the user; Step S1.2: Process the image data using a visual encoder, extract visual feature blocks, and map them to the embedding space of the language model through a linear projection layer to obtain a visual token sequence. ,in Indicates the first A visual token Indicates the total number of visual tokens; Step S1.3: Process the text prompt using a tokenizer and convert it into a text token sequence. ,in Indicates the first There are n text tokens, where n represents the total number of text tokens; Step S1.4: Concatenate the visual token sequence and the text token sequence to form the input sequence for the model. .
3. The method according to claim 1, characterized in that: The forward propagation of the multi-layer Transformer network in step S2 specifically includes: The input sequence is fed into the backbone network of the large language model, which is composed of L layers of Transformer decoders stacked together, where L represents the total number of layers in the backbone network. In each layer In the process, the model computes self-attention and updates the hidden state, where Indicates the index of the network layer currently being processed; The backbone network is logically divided into three functional regions: The shallow layer is mainly responsible for feature extraction and physical alignment of the lower layer. The modality fusion layer is a key area for deep semantic fusion of visual and textual information, and also the main area for implementing "visual attention backtracking". The posterior layer is responsible for converting the fused features into the final text output and is also the main area for implementing "modal protection".
4. The method according to claim 1, characterized in that: The entropy-triggered visual attention backtracking step S3 specifically includes: Step S3.1: In the initial stage of model inference, record the attention score matrix of the initial layer. ,in Indicates the initial layer number Attention score matrix of each attention head. The index representing the attention head; Step S3.2: When inference reaches the modality fusion layer, let the current layer be... and Get the current layer Hidden state of input The vocabulary probability distribution of the current step is calculated through layer normalization and classification head. And calculate Shannon entropy : Where N represents the vocabulary size, Indicates the first The word in the first The probability of the layer; Set a preset entropy threshold If the Shannon entropy of the current layer Activate the visual attention backtracking mechanism and apply the attention matrix of the initial layer. The attention matrix is injected into the current layer in a weighted manner. The corrected attention score is obtained. The calculation formula is as follows: in Represents the backtracking coefficient and , used to control the intensity of introducing shallow visual information; Step S3.3: Normalize the corrected attention scores to obtain the final attention weights. The calculation formula is as follows: 。 5. The method according to claim 1, characterized in that: Step S4, mode protection based on moment matching, specifically includes: Step S4.1: In the posterior layer, the hidden state... Separate into visual parts and ,in This represents the index of the currently processed network layer, used to calculate text features. mean ) and standard deviation The calculation formula is as follows: in Indicates the number of text tokens. Indicates the first Layer The hidden state of each token, where ϵ is a small constant to prevent division by zero; Computational visual features mean and standard deviation The calculation formula is as follows: in Indicates the number of visual tokens. Indicates the range of summation over the visual token index; Step S4.2: Transform the visual features using adaptive instance normalization to "de-normalize" them to a standard normal distribution, and then "re-normalize" them using the mean and standard deviation of the text features to obtain the transformed visual features. The calculation formula is as follows: Step S4.3: The original visual features and the transformed visual features are fused using a residual fusion method, and a dynamic attenuation coefficient β is introduced to obtain the corrected visual features. The calculation formula is as follows: Where β is a dynamically adjusted parameter that gradually decreases as the number of layers increases, and is used to control the intensity of the distribution correction.
Citation Information
Patent Citations
Illusion relieving method and device for multi-modal large model, electronic equipment and medium
CN119128061A
Attention migration method, data processing method and large language model
CN120146154A