Method and system for hallucination detection of large language models based on residual flow dynamic tracking

CN122965655APending Publication Date: 2026-10-23PEKING UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510510995.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-23
Publication Date
2026-10-23

AI Technical Summary

Technical Problem

[0010]针对上述现有检测技术的不足,本发明提供一种基于残差流动态追踪的大语言模型幻觉检测方法及系统,对残差流的跨层更新过程进行分析,用以解决当前幻觉检测方法特征提取效率低、检测可靠性低的问题

Benefits of technology

[0031]本发明通过构建残差流动态追踪机制,ICR Score矩阵捕获了残差流的在每一层的更新过程,实现了对残差流动态的追踪和捕获,并将这些特征传递给ICR Probe,实现可靠的幻觉检测。相较于现有主要依赖单层或静态隐藏状态的检测方法,本发明所提出的ICR探针(Probe)通过整合各层残差流中信息演化的动态特征,有效克服了现有技术无法捕捉跨层信息流变化、仅能利用局部特征的局限性。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122965655A_ABST
    Figure CN122965655A_ABST
Patent Text Reader

Abstract

The application discloses a hallucination detection method and system for a large language model based on residual flow dynamic tracking. An information contribution ICR scoring mechanism is designed to measure the contribution degree of each layer hidden state update in the text generation process of the large language model. An ICR score matrix is obtained. A global feature vector is obtained by dynamically aggregating the ICR score matrix. A lightweight probe network is designed and trained based on the obtained global feature vector to capture the cross-layer evolution pattern of the residual flow inside the large language model, thereby realizing accurate identification of hallucination content of the large language model. The application does not need to rely on external reference text or multiple generation processes, has high reference independence, parameter efficiency and cross-model generalization ability, and shows superior detection performance on multiple mainstream data sets and open source large models, and is suitable for large-scale model deployment and online hallucination prevention and control and other practical scenarios.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of artificial intelligence and natural language processing technology, and relates to large language model illusion detection technology. Specifically, it relates to a method and system for large language model illusion detection based on residual flow dynamic tracking, which realizes large language model illusion detection by tracking the cross-layer update process of hidden states. Background Technology

[0002] Large language models often exhibit hallucination phenomena when generating text content, leading to unreliable output. The hallucination of large models refers to the presence of unfounded or erroneous content in the text generation results of large models. Existing hallucination detection methods for large language models are mainly divided into three categories: consistency testing methods based on generated text content analysis [1], uncertainty quantification methods based on probability distribution [2], and hidden state analysis methods that have emerged in recent years [3]. Methods based on generated content and probability distribution rely on external reference texts or multiple rounds of generation results, and face problems such as high data acquisition costs and poor real-time performance in practical applications; while methods based on hidden state directly utilize the internal state signals of the model, which has the advantage of not requiring external reference sources. Current hallucination detection methods based on hidden state can be divided into two technical routes: training-based and training-free. Training-based methods achieve detection by constructing probes, with typical examples including the independent probe architecture developed in reference [4], the combined probe framework proposed in reference [3], and the semantic entropy probe technology designed in reference [5]. Training-free methods directly analyze the hidden state features, such as the covariance matrix analysis method proposed in reference [6]. However, these detection methods still have two shortcomings. First, existing technologies focus on the static high-dimensional hidden state representation, failing to consider the update process of the hidden state. Second, current illusion detection techniques fail to effectively capture the dynamic evolution of cross-layer residual flow. This lack of modeling for the hidden state update path and module interaction mechanism limits the reliability of the detection technology.

[0003] References

[0004] [1]Manakul P, Liusie A, Gales MJ F.Selfcheckgpt: Zero-resource black-box hallucination detection for generative large language models[J].arXivpreprint arXiv:2303.08896,2023.

[0005] [2]Ren J, Luo J, Zhao Y, et al. Out-of-distribution detection and selective generation for conditional language models[J]. arXiv preprint arXiv:2209.15558,2022.

[0006] [3]CH-Wang S, Van Durme B, Eisner J, et al. Do Androids Know They're OnlyDreaming of Electric Sheep? [J].arXiv preprint arXiv:2312.17249,2023.

[0007] [4]Azaria A,Mitchell T.The internal state of an LLM knows when it'slying[J].arXiv preprint arXiv:2304.13734,2023.

[0008] [5]Kossen J, Han J, Razzak M, et al. Semantic entropy probes: Robust and cheap hallucination detection in llms[J]. arXiv preprint arXiv:2406.15927,2024.

[0009] [6]Sriramanan G,Bharti S,Sadasivan VS,et al.LLM-Check: InvestigatingDetection of Hallucinations in Large Language Models[J].Advances in NeuralInformation Processing Systems,2025,37:34188-34216. Summary of the Invention

[0010] To address the shortcomings of existing detection technologies, this invention provides a large language model hallucination detection method and system based on residual flow dynamic tracking. The method analyzes the cross-layer update process of residual flow to solve the problems of low feature extraction efficiency and low detection reliability in current hallucination detection methods.

[0011] This invention uses the following terms to define:

[0012] 1. Residual Stream: The core path for information transmission within a large language model, characterized by the iterative update process of the hidden state through multiple layers of neural network modules. A token is the basic unit of text processing. After the input text is segmented into N discrete tokens by a tokenizer, each unit is converted into an initial hidden state in the form of a d-dimensional vector through an embedding layer. This state evolves layer by layer in the model's L-layer decoding structure: during the processing of each layer l, token t... i Hidden state The system updates the data collaboratively using two modules: Multi-Head Self-Attention Mechanism (MHSA) and Feedforward Network (FFN), and obtains... The MHSA module adjusts the distribution of contextual information by calculating the dynamic association weights between tags, while the FFN module performs knowledge retrieval and fusion operations based on the model's parameterized knowledge base. Together, they drive the cross-layer update of the residual flow.

[0013] 2. MHSA module: Multi-Head Self-Attention (MHSA) mechanism, which dynamically adjusts the distribution of contextual information by calculating the association weights between tokens.

[0014] 3. FFN module: Feed-Forward Network (FFN), which retrieves and injects external knowledge based on a parameterized knowledge base.

[0015] This invention proposes a large language model illusion detection method based on residual stream dynamic tracking. The aim is to systematically model the update process of the residual stream within a large language model in a multi-layered structure, thereby achieving efficient, reference-free illusion detection capabilities. The method mainly consists of an information contribution scoring module, a dynamic aggregation module, and a probe detection network module, exhibiting significant innovation and adaptability.

[0016] In the implementation process, the input text is first divided into discrete tokens. Each token is mapped to a d-dimensional initial hidden state through an embedding layer and then propagates through the multi-layer decoding structure. In each layer, the residual stream is generated by the combined action of two key modules: Multi-Head Self-Attention (MHSA) and Feed-Forward Network (FFN).

[0017] The core technology of this invention lies in proposing an Information Contribution to Residual Stream (ICR Score) mechanism. By introducing Jensen-Shannon divergence (JSD), it measures the contribution of MHSA and FFN modules to hidden state updates in each layer. This score not only characterizes the dominant path of information but also reflects the dynamic changes in the dominance of different modules in different layers.

[0018] Furthermore, to construct global features for cross-layer dynamic patterns, this method performs average pooling on the ICR score matrices of each layer along the token dimension to obtain a unified one-dimensional global feature vector. Based on this feature vector, this invention designs and trains a lightweight probe network (ICR Probe) to capture the cross-layer evolution patterns of residual flow within the model, thereby achieving accurate identification of hallucination content.

[0019] This method does not rely on external reference texts or multiple generation processes, and has high reference independence, parameter efficiency and cross-model generalization ability. It has shown superior detection performance on multiple mainstream datasets and open source large models, and is suitable for practical scenarios such as large-scale model deployment and online hallucination prevention.

[0020] The method of the present invention includes the following steps:

[0021] A. Residual Flow Information Contribution Scoring Module:

[0022] The Residual Stream Information Contribution Score (ICR Score) is calculated for the text generation process of a large language model. This score captures the update process of the hidden states (i.e., the dynamic evolution of the residual stream) and passes the dynamic evolution features (i.e., the residual stream information contribution score) to the ICR Probe for illusion detection. In the specific implementation, firstly, the scores of all attention heads in the large language model are extracted and averaged across heads to generate the comprehensive attention distribution of the large language model. Then, by calculating the difference between the hidden states of adjacent layers in the large language model, the residual stream update amount of each layer is obtained. This update amount reflects the new information introduced by the current layer compared to the previous layer. To further evaluate the actual contribution of this information to the model output, this invention projects the residual stream update amount onto the hidden state space corresponding to the context token, thereby constructing a projection vector representing the direction and intensity of information. This projection vector is used to characterize the degree of correlation between the residual update and the semantic context, and then the difference between the hidden states of two layers is calculated. Finally, the Jensen-Shannon divergence is used to measure the degree of difference between the projection vector in this direction and the corresponding attention distribution, and the ICR score is defined accordingly to measure the information contribution of each module (MHSA and FFN modules) in the residual flow update process of this layer.

[0023] The core function of the ICR Score is to capture the specific contributions of each module to the information flow during the residual stream update process in a large language model. It reveals the relationship between semantic information introduced into different structural units of the model and the attention mechanism, which is key to this invention. The score is mainly calculated based on two types of core information: the model's attention score and the update direction of the hidden states. The specific calculation process for these two parts will be explained in detail below.

[0024] A.1 First, extract the attention scores. For the i-th token in layer l, calculate its attention score with all context tokens. The single-head attention score is obtained through the query vector. and key vector The dot product is calculated and normalized to generate an attention score vector. Average pooling is performed on all attention head scores to obtain a robust overall attention score.

[0025] A.2 Secondly, the hidden state update direction is calculated. To calculate the hidden state update direction, this invention designs a vector projection method to measure the similarity between the hidden state update amount and each context token. Specifically, the difference between the hidden states of two adjacent layers is first calculated to obtain the residual flow update amount, and its calculation formula is as follows: in This represents the hidden state of the i-th token at the l-th layer of the large language model. This represents the residual stream update amount of the i-th token at the l-th layer of the large language model, where the superscript l represents the layer index and the subscript i represents the token position index. Then, Project onto the hidden state space of the context token and compute the projection. Finally, combine the projections on each context token. Obtain the projection vector The distribution of the update direction is represented after softmax normalization. Projection vector. This indicates the direction of the hidden state update and is the core information for calculating the ICR Score.

[0026] A.3 Finally, the ICR Score is calculated. This invention uses the Jensen-Shannon divergence (JSD) to measure the projected vector. With attention score The consistency between these components yields the Residual Flow Information Contribution Score (ICR Score). The ICR Score captures the information contribution of different modules within the large language model during the residual flow update process. Specifically: when the ICR Score is low, the hidden state update direction is highly consistent with the attention distribution, indicating that the update is mainly dominated by MHSA, with FFN only slightly enhancing the existing information; when the ICR Score is high, the update direction differs significantly from the attention distribution, indicating that the FFN module dominates the update process at this layer, injecting more new parameterized knowledge. To obtain the features of the global information flow of the large language model, we combine the ICR Score of each token at each layer using the method described above into an N×L dimensional ICR Score matrix.

[0027] B. Dynamic Feature Aggregation Module: The N×L dimensional ICR Score matrix is ​​averaged along the token dimension to generate a 1×L dimensional global feature vector, preserving the dynamic evolution patterns between layers (such as the peak features dominated by the intermediate layer FFN) while suppressing noise interference. The combined and pooled ICR score retains the information contribution of each module (i.e., MHSA and FFN) during the update of the residual flow at each layer, capturing the cross-layer evolution information of the residual flow.

[0028] C. Probe Network Detection Module: The ICR Probe employs a lightweight fully connected neural network model architecture. Its input dimension equals the number of model layers, and the output generates non-hallucination probabilities through a sigmoid function mapping. During network training, a binary cross-entropy loss function and the Adam optimizer are used, along with a dynamic learning rate scheduling strategy (decreasing the learning rate when the validation loss stagnates) and regularization mechanisms (including Dropout and weight decay) to prevent overfitting. The training process involves multiple iterations, with an early stopping mechanism monitoring the validation set performance to preserve the optimal model parameters, ultimately achieving efficient and stable detection capabilities.

[0029] In specific implementation, this invention provides a hallucination detection system that implements the above method, including: a residual flow information contribution scoring module: capturing the update amount of MHSA and FFN in each layer in real time and calculating the cross-layer ICR score; a dynamic feature aggregation module: performing average pooling on the ICR score matrix along the token dimension to generate a one-dimensional global feature vector; and a probe network detection module: loading a lightweight probe with an input dimension equal to the number of layers in the target model, supporting real-time hallucination detection.

[0030] Compared with the prior art, the present invention has the following significant advantages:

[0031] This invention constructs a dynamic residual flow tracking mechanism. The ICR Score matrix captures the update process of the residual flow at each layer, achieving dynamic tracking and capture of the residual flow. These features are then passed to the ICR Probe for reliable hallucination detection. Compared to existing detection methods that mainly rely on single-layer or static hidden states, the ICR probe proposed in this invention effectively overcomes the limitations of existing technologies, which cannot capture cross-layer information flow changes and can only utilize local features, by integrating the dynamic features of information evolution in the residual flow of each layer.

[0032] This method not only focuses on the hidden state itself, but also delves into the differentiated contributions of the multi-head self-attention mechanism (MHSA) and the feedforward neural network (FFN) to the residual flow update in each layer, thereby achieving precise analysis of the information flow path within the model. This joint modeling based on module contribution and the dynamic evolution of residual flow provides a more interpretable and structured source of signals for hallucination detection.

[0033] Furthermore, ICR Probe has the advantage of not requiring the selection of specific layers or tokens, directly constructing detection features based on the evolution trajectory of residuals across all layers during model generation, greatly improving its model adaptability and task versatility. In terms of computational efficiency, ICR Probe can achieve real-time hallucination recognition in a single generation, avoiding the need for multiple samplings or reliance on external references, significantly reducing computational resource consumption.

[0034] Meanwhile, the present invention is more lightweight in parameter design. The probe network only needs a small number of parameters to complete cross-layer dynamic tracking and detection tasks, which is suitable for scenarios with limited computing power or edge deployment and has good engineering feasibility. Attached Figure Description

[0035] Figure 1 This is a flowchart of the ICR probe hallucination detection process. Detailed Implementation

[0036] The present invention will be further described below with reference to the accompanying drawings and embodiments, but the scope of the invention is not limited in any way.

[0037] This invention provides a method and system for hallucination detection that tracks the cross-layer update process of hidden states. It models and tracks the residual flow update process of a large language model and trains a probe to achieve reliable hallucination detection. Specifically, it constructs a residual flow information contribution score (ICR Score) using Jensen-Shannon divergence to quantify the differentiated contributions of multi-head self-attention mechanism (MHSA) and feedforward network (FFN) to hidden state updates. Based on the feature vector, a lightweight probe (ICR Probe) is trained to capture the cross-layer evolution pattern of the residual flow. The hallucination detection system includes: a residual flow information contribution score module: which captures the update amounts of MHSA and FFN at each layer in real time and calculates the cross-layer residual flow information contribution score (ICR Score); a dynamic feature aggregation module: which averages the ICR score matrix along the token dimension to generate a one-dimensional global feature vector; and a probe network detection module: which loads a lightweight probe with an input dimension equal to the number of layers in the target model, supporting real-time hallucination detection.

[0038] This invention provides a systematic modeling method for the residual stream update process of large language models, comprising three main modules: a residual stream information contribution scoring module, a dynamic aggregation module, and a probe detection network module. The residual stream information contribution scoring module captures information updates in a single layer of the large language model, quantifying the information contribution of MHSA and FFN to the residual stream; the dynamic aggregation module combines the information contribution scores of all layers and performs pooling; finally, the probe network module detects illusions.

[0039] The overall process is as follows: The input text is divided into N tokens, and each token is mapped to a d-dimensional initial hidden state through an embedding layer. This hidden state evolves layer by layer in the model's L decoding layers: during the processing of the l-th layer, token t... i Hidden state Iterative updates are performed using two core modules: Multi-Head Self-Attention Mechanism (MHSA) and Feedforward Network (FFN). Among them, t i This refers to the i-th token in the input text. This represents the hidden state of the i-th token at layer l of the large language model. Taking the residual flow update process of the i-th token at layer l of the large language model as an example, the MHSA module dynamically adjusts the information interaction weights between lexical units based on contextual association, generating attention-driven update quantities. The FFN module generates feedforward network updates through parameterized knowledge retrieval and fusion. The synergy between the two forms the residual flow update path; specifically, for the hidden state... The update process is as follows: The update process of the hidden state is the dynamic evolution process of the residual flow, in which... This reflects the dynamic reallocation of the i-th token's contextual information at the l-th layer of the large language model. Targeted injection of knowledge from within the representation model.

[0040] The system framework and method flow of this invention are as follows: Figure 1 As shown, it mainly includes two steps: calculating and combining ICR scores, and training and detecting ICRProbes. The specific steps are as follows:

[0041] A. In order to effectively capture the update features of residual streams, this invention designs the ICR Score, which calculates the contribution score of residual stream information based on the attention score and hidden state of each layer of the large language model.

[0042] A1. First, extract the attention score. In layer l, the attention score between the i-th token and the j-th context token is calculated using the given attention head h. This calculation process can be represented as:

[0043]

[0044] in, and Let d represent the query vector and key vector of the i-th and j-th tokens, respectively, where d is the dimension of the vector.

[0045] For the i-th token, its attention score vector with respect to all N tokens can be represented as:

[0046]

[0047] To obtain more robust attention scores, we perform average pooling on the scores of all H attention heads:

[0048]

[0049] In this way, we can extract the comprehensive attention score of each token in each layer, providing a more stable input for subsequent analysis and detection. This is an intermediate step in calculating the ICR Score.

[0050] A2. For the hidden states of each layer of the large language model, calculate the hidden state update direction. When analyzing the hidden state update direction, we first consider the set of hidden states for all N input tokens. To quantify the update volume We calculate the update amount based on how much information is integrated from the context. The hidden state of the token in all input contexts Projection length between Specifically, the projection length is calculated using the following formula:

[0051]

[0052] in, This represents the modulus (norm) of the hidden state of the j-th token. Projected length. Measuring the update In hidden state The magnitude in the direction; T represents transpose.

[0053] Next, we construct the projection vector. The hidden state is then normalized using the softmax function. This process helps to more clearly analyze the directionality of the hidden state updates and their relationship with contextual information.

[0054] A3. Based on the attention score and hidden state update direction obtained in steps A.1 and A.2, calculate the consistency between the hidden state update direction and the attention score. This invention quantifies the consistency between the hidden state update direction and the attention score using Jensen-Shannon divergence (JSD) and constructs the Residual Flow Information Contribution Score (ICR Score), defined as:

[0055]

[0056] Where JSD represents the Jensen-Shannon divergence calculation; Let the attention score of the i-th token be the value at the l-th layer of the large language model.

[0057] This score is used to characterize the differences in the contribution of different modules to the residual flow information, and can serve as an analytical signal for the evolution pattern of the residual flow in large language models. The specific analysis is as follows:

[0058] 1. Low ICR Score: A low ICR score indicates a hidden state update. This is highly consistent with the attention distribution. In this state, the self-attention mechanism (MHSA) dominates information updates, and the feedforward network (FFN) only reinforces existing information without introducing significant new content.

[0059] 2. High ICR Score: A high ICR score indicates a significant deviation between the hidden state update direction and the attention distribution. In this case, the feedforward network (FFN) becomes the dominant module for residual flow updates, and its parameterized knowledge retrieval behavior has a greater shaping effect on the information flow than the self-attention mechanism.

[0060] The ICR Score captures the distribution patterns across L network layers and N tokens, revealing the dynamic laws governing the evolution of information within the model. This residual flow dynamic tracking mechanism captures cross-layer evolutionary characteristics, a feature previously lacking attention in this field, and is the core innovation of this invention.

[0061] In the specific implementation, the top k tokens with the highest attention scores (default k=15) are selected for calculation first to reduce noise interference.

[0062] B. For the ICR Score obtained in step A, the ICR Score is combined and pooled. The processing method is as follows: To solve the problem that a single-layer ICR Score can only reflect local features, this invention proposes a cross-layer global feature integration strategy. For a model containing N tokens and an L-layer Transformer structure, the original ICR Score constitutes an N×L dimensional matrix. By performing an average pooling operation along the token dimension, the ICR Scores of the N tokens at each layer are aggregated into a single scalar value, ultimately generating a 1×L dimensional feature vector. This process effectively suppresses random noise of individual tokens (such as spelling errors or low-frequency word interference) while preserving the continuous evolution of inter-layer update intensity (such as the peak features dominated by FFN in the intermediate layer).

[0063] C. Using the aggregated low-dimensional features obtained in step B, train the ICR Probe to detect hallucinations. The specific structural design of the ICR Probe is as follows: This classifier adopts a four-layer fully connected neural network architecture, with the input dimension being the same as the number of model layers L (e.g., a 42-layer Gemma-2 corresponds to a 42-dimensional input). The input is compressed through 128, 64, and 32-dimensional hidden layers, and finally outputs the detection probability in the 0-1 range through the Sigmoid function. By controlling the network width and depth, the total number of parameters is compressed to less than 16K.

[0064] During implementation, the training settings for ICR Probe are as follows:

[0065] The ICR Probe of this invention uses a binary cross-entropy loss function for supervised training, combined with the Adam optimizer (initial learning rate 5×10). -4 The momentum parameters β1 = 0.9 and β2 = 0.999 are used for parameter updates. To balance convergence speed and stability, a dynamic learning rate scheduling mechanism is introduced: if the validation set loss does not decrease for five consecutive training epochs, the learning rate decays by a factor of 0.5. During network initialization, the linear layer weights are initialized using the Kaiming normal distribution strategy to alleviate the gradient vanishing problem. The scaling factor and bias term of the batch normalization layer are fixed at 1 and 0, respectively, to ensure the stability of the feature distribution in the initial stage. To prevent overfitting, a Dropout layer with a dropout probability of 0.3 is introduced after each hidden layer, and an L2 weight decay (coefficient 1 × 10⁻⁶) is added before the output layer. -4 The training process lasts for 50 cycles, with a fixed batch size of 32. The training data is divided into training and validation sets in an 8:2 ratio.

[0066] This method demonstrates outstanding performance. Its hallucination detection capabilities were evaluated on four datasets: HaluEval, SQuAD, TriviaQA, and HotpotQA, using three mainstream open-source models: Llama-3-8B-Instruct, Qwen2.5-7B-Instruct, and Gemma-2-9B-it. Experimental results show that this method outperforms the benchmark methods proposed in references [4,5,6], achieving an AUROC score as high as 0.8436.

[0067] It should be noted that the purpose of disclosing the embodiments is to help further understand the present invention. However, those skilled in the art will understand that various substitutions and modifications are possible without departing from the scope of the present invention and the appended claims. Therefore, the present invention should not be limited to the content disclosed in the embodiments, and the scope of protection of the present invention is defined by the scope of the claims.

Claims

1. A method for hallucination detection in large language models based on residual flow dynamic tracking, characterized in that, By designing an Information Contribution Ratio (ICR) scoring mechanism, the contribution of each layer of hidden state updates in the text generation process of a large language model is measured, and the ICR scoring matrix is ​​obtained. The global feature vector is obtained by dynamically aggregating the ICR scoring matrix; Based on the acquired global feature vectors, a lightweight probe network is designed and trained to capture the cross-layer evolution patterns of residual flows within a large language model, thereby achieving accurate identification of illusory content in the large language model.

2. The hallucination detection method for large language models based on residual flow dynamic tracking as described in claim 1, characterized in that, The Information Contribution (ICR) scoring mechanism is designed for the process of generating text using a large language model. It calculates the Information Residual Flow Contribution (ICR) score by extracting the scores of all attention heads in the large language model and averaging them across the heads to generate the comprehensive attention distribution of the large language model. The residual flow update of the large language model is then projected onto the hidden state space of the context label to construct the directional projection vector. The ICR score is defined by calculating the difference between the directional projection vector and the attention score.

3. The large language model hallucination detection method based on residual flow dynamic tracking as described in claim 2, characterized in that, The specific steps include the following: Extracting attention scores: Calculate the attention head scores of each layer of the large language model; perform average pooling on all attention head scores to obtain the comprehensive attention distribution of the large language model; Calculate the hidden state update direction: Obtain the residual stream update amount of each layer by calculating the difference between the hidden states of two adjacent layers of the large language model; project the residual stream update amount onto the hidden state space corresponding to the context token to construct a projection vector representing the information direction and intensity; this projection vector is used to represent the degree of association between the residual update and the semantic context; then calculate the difference between the hidden states of two layers. The consistency between the hidden state update direction and the attention score is calculated to obtain the ICR score of each token at each layer of the large language model, and an ICR score matrix is ​​generated. The ICR score is used to measure the information contribution of each module in the residual flow update process of that layer.

4. The hallucination detection method for large language models based on residual flow dynamic tracking as described in claim 3, characterized in that, Specifically, the difference between the directional projection vector and the attention score is calculated using Jensen-Shannon divergence, and the ICR score is defined.

5. The large language model hallucination detection method based on residual flow dynamic tracking as described in claim 4, characterized in that, Includes the following steps: Calculate residual flow update amount The hidden state of the token in all input contexts Projection length between The projected length is calculated using the following formula: in, This indicates the hidden state of the j-th token. Modulus length; projected length Indicates update In hidden state The magnitude in direction; Constructing projection vectors Then, normalization is performed using the softmax function; Construct the residual flow information contribution score (ICR Score), defined as: Where JSD represents the Jensen-Shannon divergence calculation; For the i-th token in the large language model Attention score of the layer.

6. The hallucination detection method for large language models based on residual flow dynamic tracking as described in claim 1, characterized in that, The global feature vector is obtained by dynamically aggregating the ICR scoring matrix. The specific process is as follows: For a model containing N text terms and an L-layer Transformer structure, the ICR score matrix is ​​N×L dimensional. By performing average pooling along the lexical dimension, the N lexical scores of each level are aggregated into a single scalar value, generating a 1×L-dimensional feature vector. This preserves the information contribution of each module when the residual flow is updated at each layer, and captures the cross-layer evolution information of the residual flow.

7. The large language model hallucination detection method based on residual flow dynamic tracking as described in claim 1, characterized in that, The designed lightweight probe network adopts a four-layer fully connected neural network architecture, with the same number of layers as the large language model; the hidden layers are 128, 64, and 32-dimensional fully connected layers respectively; the output layer is mapped to the non-hallucination probability in the 0-1 interval by the Sigmoid function; by controlling the network width and depth, the total number of parameters is compressed to less than 16K.

8. A large language model hallucination detection system based on residual flow dynamic tracking, used to implement the method of claim 1, characterized in that, include: Information Contribution Scoring Module: Used to capture the update volume of MHSA and FFN at each layer in real time and calculate the cross-layer ICR score; Dynamic feature aggregation module: used to perform average pooling of the ICR scoring matrix along the token dimension to generate a one-dimensional global feature vector; Cross-layer detection probe: Used to load lightweight probe networks, with the input dimension equal to the number of layers in the target model, supporting real-time illusion detection.