A hallucination detection and dynamic correction method and system for a large language model based on multi-scale time-frequency spectrum feature coupling
Patent Information
- Application Number
- CN202611169137.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-04
- Publication Date
- 2026-10-30
AI Technical Summary
仅依据单一频谱特征或者单一几何特征进行判断,难以区分正常的层间语义加工变化与可能引发幻觉的异常变化
[0031]本发明的有益效果:本发明在大语言模型推理过程中采集多个Transformer层的隐层状态向量,并按网络层序构建隐层时序信号,将原本分散的高维隐层状态转换为能够进行时频分析的信号序列,从而能够表征同一语义内容随推理深度逐层演变的过程。通过采集层最终输出向量、注意力子层输出向量、注意力残差向量及前馈神经网络输出向量中的至少两种,还可将异常检测范围由网络层级进一步细化至子层级。
Smart Images

Figure CN123013946A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of artificial intelligence natural language processing technology, specifically relating to a method and system for hallucination detection and dynamic correction of a large language model based on multi-scale temporal spectral feature coupling. Background Technology
[0002] Large language models typically employ a multi-layered Transformer structure to process the semantics of the input text layer by layer and generate text through an autoregressive approach. Since the generated content is primarily based on the parameter distribution formed by the training data and the probabilistic relationships within the current context, the text generation process may produce illusory content that is inconsistent with objective facts, lacks basis, or deviates from the input semantics. This can affect the reliability of the output results in applications such as intelligent question answering, text generation, knowledge services, and professional decision support.
[0003] Most existing hallucination detection methods perform fact-checking, semantic consistency analysis, confidence assessment, or external knowledge retrieval on the output text after the model has generated the text. These methods primarily focus on the final generated result and struggle to observe the formation, propagation, and evolution of anomalous semantics within the various network layers of a large language model, nor can they accurately determine the network layer at which the hallucination anomaly initially occurred. Therefore, even if anomalies are detected in the output text, it is usually difficult to correct the corresponding internal state before the model's inference is complete.
[0004] Some methods for hallucination detection that utilize internal activation representations of the model typically select a single network layer or a single type of hidden state as the detection criterion, failing to fully leverage the temporal features formed by the changes in hidden state with network depth. In reality, hallucination anomalies may manifest as localized high-frequency abrupt changes in hidden states at specific layers, or as directional deviations in the evolutionary trajectory in the semantic space between adjacent layers. Judging solely based on a single spectral feature or a single geometric feature is insufficient to distinguish between normal inter-layer semantic processing changes and anomalous changes that may trigger hallucinations.
[0005] Furthermore, different large language models exhibit variations in the number of network layers, hidden layer dimensions, and internal activation distributions. The intensity of anomalous signals also differs across task scenarios, making it difficult to apply a fixed threshold for detection due to insufficient adaptability. Existing detection and correction techniques are also often separate; after an anomaly is detected, it is typically necessary to regenerate the text, call an external correction model, or adjust model parameters, making it difficult to directly intervene in the hidden layer state at the anomaly origin level in real time. Summary of the Invention
[0006] To address the shortcomings of existing technologies, the present invention aims to provide a method and system for hallucination detection and dynamic correction of large language models based on multi-scale time-spectral feature coupling, thereby overcoming the aforementioned deficiencies in existing technologies.
[0007] To achieve the above objectives, the present invention provides the following technical solution:
[0008] A method for hallucination detection and dynamic correction based on multi-scale temporal-spectral feature coupling in a large language model includes:
[0009] Cross-layer signal construction steps: During the inference process of generating text in the large language model, the hidden layer state vectors across Transformer layers are collected and arranged in layer order to construct the hidden layer temporal signal;
[0010] Multi-scale time-frequency localization steps: Perform multi-scale wavelet decomposition on the hidden layer time series signal to obtain decomposition coefficients that characterize high-frequency details, and locate the target layer in the hidden layer time series signal where abnormal fluctuations occur based on the energy distribution of the decomposition coefficients;
[0011] Spectral-geometric coupling verification steps: Obtain the geometric trajectory change features of the hidden layer state vectors corresponding to the target level and adjacent levels in the semantic space, and perform coupling operation on the geometric trajectory change features with the high-frequency energy features of the target level to obtain the spectral-geometric consistency coefficient characterizing the degree of hallucination risk;
[0012] Adaptive correction step: When the spectral-geometric consistency coefficient exceeds a preset threshold, based on the predetermined truth direction, projection correction or spectral domain filtering correction is performed on the hidden state vector of the target level, and the corrected hidden state vector is input into the subsequent levels for further inference.
[0013] Preferably, in the cross-layer signal construction step, for the same Transformer layer, at least two intermediate activation vectors from different sources are collected. The intermediate activation vectors include at least two of the following: the final output vector of the layer, the output vector of the attention sublayer, the attention residual vector, and the output vector of the feedforward neural network. This is to improve the feature richness of the hidden layer temporal signal and provide a signal basis for the multi-scale time-frequency localization step to achieve anomaly localization at the sublayer granularity.
[0014] Preferably, the intermediate activation vectors collected from each layer are concatenated in layer order and expanded along the feature dimension to construct a signal matrix. The row direction of the signal matrix corresponds to the combination of layer order and activation vector type, and the column direction corresponds to the hidden layer dimension. Each column in the signal matrix constitutes a one-dimensional hidden layer time-series signal that evolves along the inference depth, which serves as the direct processing object of multi-scale wavelet decomposition in the multi-scale time-frequency localization step.
[0015] Preferably, in the multi-scale time-frequency localization step, an orthogonal wavelet basis with compact support characteristics is used to decompose the hidden layer time series signal into multiple scales. The number of decomposition levels is adaptively determined according to the length of the hidden layer time series signal, and high-frequency detail coefficients and low-frequency approximation coefficients at multiple scales are obtained. The high-frequency detail coefficients are used to characterize the local abrupt change features of the signal along the inference depth direction at the corresponding scale.
[0016] Preferably, the method for locating the target level includes: calculating the sum of the energy of multiple scale high-frequency detail coefficients at corresponding positions of the hidden layer time series signal at each level, as the local high-frequency energy of that level; calculating the mean and standard deviation of the global high-frequency energy of the hidden layer time series signal; and marking the level where the local high-frequency energy exceeds the sum of the mean and the standard deviation by a preset multiple as a candidate target level, thereby realizing the layer-by-layer determination of the hallucination origin level.
[0017] Preferably, the method for obtaining the geometric trajectory change features includes: calculating the difference between the hidden state vector corresponding to the target level and the hidden state vector corresponding to its adjacent level to obtain a semantic velocity vector that characterizes the semantic change trend of the level; calculating the degree of directional deviation between the semantic velocity vector of the target level and the semantic velocity vector of the adjacent level as the geometric trajectory change feature, which is then used for subsequent coupling operations with the high-frequency energy features of the target level.
[0018] Preferably, the spectral-geometric consistency coefficient is calculated as follows:
[0019] ;
[0020] in, The high-frequency energy after normalization at the target level. The angle between the semantic velocity vector of the target level and the semantic velocity vector of the adjacent level.
[0021] Preferably, the authenticity direction is pre-obtained as follows: Based on a comparative corpus containing real and fake statements, the activation representations of the corresponding final layer of the large language model are extracted; a linear classifier is trained to distinguish between real and fake statements; the weight direction of the linear classifier is normalized and used as the authenticity direction; when the spectral-geometric consistency coefficient exceeds a preset threshold and triggers the adaptive correction step, the hidden state vector of the target layer is orthogonally projected onto the authenticity direction to obtain the corrected hidden state vector.
[0022] ;
[0023] in, Let be the hidden state vector of the target level. This refers to the direction of authenticity after normalization.
[0024] Preferably, the preset threshold is determined based on the statistical distribution of the historical spectral-geometric consistency coefficient on the validation dataset. The value located at the preset quantile in the statistical distribution is used as the preset threshold, so that the triggering condition of the adaptive correction step is adaptively calibrated as the large language model and application scenario change, without the need to manually set a fixed threshold.
[0025] A large language model hallucination detection and dynamic correction system based on multi-scale temporal-spectral feature coupling includes:
[0026] The signal construction module is used to collect cross-layer hidden layer state vectors during the reasoning process of a large language model and construct the hidden layer temporal signal.
[0027] A time-frequency positioning module, connected to the signal construction module, is used to perform multi-scale wavelet decomposition on the hidden layer time series signal and locate the target level.
[0028] The feature coupling module, connected to the time-frequency positioning module, is used to acquire the geometric trajectory change features of the target level and calculate the spectrum-geometric consistency coefficient.
[0029] An adaptive correction module, connected to the feature coupling module, is used to perform the projection correction or spectral domain filtering correction on the hidden state vector of the target level when the spectral-geometric consistency coefficient exceeds the preset threshold.
[0030] The control module is connected to the signal construction module, the time-frequency positioning module, the feature coupling module, and the adaptive correction module, respectively, and is used to coordinate the sequential execution of signal acquisition, time-frequency positioning, feature coupling, and adaptive correction operations by each module.
[0031] The beneficial effects of this invention are as follows: During the reasoning process of a large language model, this invention collects hidden state vectors from multiple Transformer layers and constructs hidden layer temporal signals according to the network layer order. This transforms the originally dispersed high-dimensional hidden state into a signal sequence capable of time-frequency analysis, thereby representing the evolution of the same semantic content layer by layer with the depth of reasoning. By collecting at least two of the following: the final output vector of the layer, the output vector of the attention sublayer, the attention residual vector, and the output vector of the feedforward neural network, the anomaly detection range can be further refined from the network layer level to the sublayer level.
[0032] Multi-scale wavelet decomposition is used to extract high-frequency detail coefficients of hidden layer time-series signals at different scales, and the anomalous target level is located based on the relationship between the local high-frequency energy and the global high-frequency energy statistical distribution at each level. Wavelet decomposition simultaneously preserves frequency domain variation information and sequence position information, enabling the system to identify the Transformer layer or sub-layer corresponding to the anomaly while recognizing local abrupt changes in the hidden layer state, thus achieving layer-by-layer localization of the origin of hallucinations.
[0033] The semantic velocity vector between the hidden state vectors of the target layer and adjacent layers is calculated, and the degree of deviation of the semantic velocity direction is used to characterize the semantic geometric trajectory change. This geometric feature is then coupled with the high-frequency energy feature of the target layer. Through dual verification of high-frequency anomalies in the frequency domain and semantic trajectory anomalies, the possibility of misjudging normal inter-layer semantic changes as hallucination anomalies by relying on only a single feature can be reduced.
[0034] The preset threshold is determined based on the statistical distribution of the historical spectrum-geometric consistency coefficient on the validation dataset, and the value corresponding to the preset quantile is used as the correction trigger condition. This allows the detection standard to be adjusted according to the changes in the type of large language model and application scenario, avoiding insufficient adaptability of the fixed threshold under different models, different tasks and different hidden layer signal distributions.
[0035] When the spectral-geometric consistency coefficient exceeds a preset threshold, the hidden state vector of the target level is directly corrected. Specifically, projection correction preserves vector components related to reality based on a predetermined reality direction; spectral filtering correction suppresses or removes high-frequency detail coefficients corresponding to anomalous frequency bands and reconstructs the hidden state through inverse wavelet transform. Neither correction method requires retraining the model or changing the main model parameters, allowing intervention in anomalous semantic states during the current inference process.
[0036] The corrected hidden state vector is re-inputted into subsequent Transformer layers for further inference, allowing anomaly detection results to directly impact the subsequent text generation process. This forms a closed-loop processing flow from cross-layer signal acquisition, anomaly level localization, spectral-geometric coupling verification to hidden state correction. Spectral domain filtering correction can also selectively weaken high-frequency fluctuation components of anomalies while preserving the overall semantic components of the hidden state.
[0037] This invention comprises a signal construction module, a time-frequency localization module, a feature coupling module, an adaptive correction module, and a control module. Each module operates collaboratively in the order of signal acquisition, time-frequency localization, feature coupling, and dynamic correction. It can be used as software middleware to connect to a large language model inference platform, or it can be combined with a hardware acceleration unit to perform time-frequency analysis and feature coupling operations, making it easy to deploy in different computing environments. Attached Figure Description
[0038] Figure 1This is a flowchart of the overall method of the present invention;
[0039] Figure 2 This is a flowchart of the cross-layer signal construction process of the present invention;
[0040] Figure 3 This is a flowchart of the multi-scale time-frequency positioning process of the present invention;
[0041] Figure 4 This is a flowchart of the spectral-geometric coupling verification process of the present invention;
[0042] Figure 5 This is a system structure block diagram of the present invention. Detailed Implementation
[0043] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0044] It should be noted that when a component is described as "fixed to" another component, it can be directly on the other component or may have a component in between. When a component is considered "connected to" another component, it can be directly connected to the other component or may have a component in between. When a component is considered "set on" another component, it can be directly set on the other component or may have a component in between. The terms "vertical," "horizontal," "left," "right," and similar expressions used in this document are for illustrative purposes only.
[0045] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention pertains. The terminology used herein in the description of the invention is for the purpose of describing particular embodiments only and is not intended to be limiting of the invention. The term "and / or" as used herein includes any and all combinations of one or more of the associated listed items.
[0046] The embodiments of the present invention will be further described in detail below with reference to the accompanying drawings:
[0047] like Figures 1 to 5 As shown in the accompanying drawings, the specific implementation of a method and device for hallucination detection and dynamic correction of a large language model based on time-frequency coupling analysis of hidden layer time-series signals, as described in the claims, will be described in detail below. The following embodiments are elaborations and expansions of the technical solutions defined in the claims, intended to help those skilled in the art fully understand and implement the invention, and are not intended to limit the scope of protection of the invention.
[0048] This embodiment provides a method for large language model illusion detection and dynamic correction based on hidden layer time-series signal time-frequency coupling analysis, including a cross-layer signal construction step, a multi-scale time-frequency localization step, a spectrum-geometric coupling verification step, and an adaptive correction step.
[0049] In the cross-layer signal construction step, during the inference process of generating text by the large language model, hidden layer state vectors across Transformer layers are collected and arranged in layer order to construct hidden layer temporal signals. Among them, the large language model refers to a deep neural network model with a multi-layered stacked Transformer structure as its backbone network, which is pre-trained on massive corpora to obtain the ability to understand and generate natural language. In the process of generating each word, the input information needs to be processed and semantically refined layer by layer through several sequentially connected Transformer layers within the network. Finally, the output of the last layer is used to predict the probability distribution of the next word. The hidden layer state vector refers to the multi-dimensional numerical vector output by each Transformer layer within the large language model when it completes a forward inference of a certain word. This vector carries the degree of semantic understanding of the current layer. This vector is continuously updated and corrected as the inference deepens layer by layer. The hidden layer temporal signal refers to the signal sequence formed by arranging the hidden layer state vectors corresponding to each Transformer layer in the order of their positions in the network structure, with the layer order as the time dimension. This signal sequence describes the dynamic evolution trajectory of the large language model's understanding of the same semantic content in the cross-layer inference process, providing the original signal basis for subsequent time-frequency localization and anomaly detection. Specifically, sampling can be performed when the large language model infers the last word of the answer. At this point, the inference state has integrated all the contextual information from the input question to the currently generated answer, making it an ideal node for observing hallucination phenomena. By traversing each layer of the model, the original material used to construct the hidden layer temporal signal can be obtained.
[0050] Furthermore, in the cross-layer signal construction step, for the same Transformer layer, at least two intermediate activation vectors from different sources are collected. These intermediate activation vectors include at least two of the following: the final output vector of the layer, the output vector of the attention sublayer, the attention residual vector, and the output vector of the feedforward neural network. This improves the feature richness of the hidden layer temporal signal and provides a signal basis for the multi-scale time-frequency localization step to achieve anomaly localization at the sublayer granularity. Specifically, the attention sublayer output vector refers to the intermediate result obtained after the self-attention mechanism module within the Transformer layer performs a weighted aggregation operation on the input vector; the attention residual vector refers to the intermediate vector obtained by adding the attention sublayer output vector to the layer's input vector, reflecting the residual connection mechanism; and the feedforward neural network output vector refers to the intermediate result obtained after the feedforward neural network submodule in the layer further performs a nonlinear transformation on the attention residual vector. The final output vector of the layer is the vector obtained after normalizing and processing the feedforward neural network output vector, which serves as the final output vector of the Transformer layer. By simultaneously collecting intermediate activation vectors from multiple sources within the same layer, the information processing within a single layer can be refined into multiple observable nodes without increasing additional model call overhead. This allows subsequent steps to determine the location of hallucination anomalies at a finer granularity at the sub-layer level, rather than only being able to locate them at a coarser granularity at the layer level.
[0051] Based on this, the intermediate activation vectors collected from each layer are concatenated in layer order and expanded along the feature dimension to construct a signal matrix. The rows of the signal matrix correspond to the combination of layer order and activation vector types, and the columns correspond to the hidden layer dimension. Each column of the signal matrix constitutes a one-dimensional hidden layer temporal signal that evolves along the inference depth, serving as the direct processing object for multi-scale wavelet decomposition in the multi-scale time-frequency localization step. That is, if the large language model has several Transformer layers, and each layer collects several intermediate activation vectors, then the number of rows in the concatenated signal matrix is equal to the product of the number of layers and the number of activation vector types in each layer, and the number of columns is equal to the hidden layer dimension. Each column in the matrix corresponds to a fixed feature component in the hidden space, recording the numerical trajectory of this feature component as it evolves with the network layer order, i.e., the inference depth. This transforms the original high-dimensional, discrete set of hidden layer states into several one-dimensional temporal sequences that are easy to process.
[0052] In the multi-scale time-frequency localization step, the hidden layer time series signal is subjected to multi-scale wavelet decomposition to obtain decomposition coefficients characterizing high-frequency details. Based on the energy distribution of the decomposition coefficients, the target level in the hidden layer time series signal where abnormal fluctuations occur is located. Multi-scale wavelet decomposition refers to a signal processing method that uses wavelet transform to decompose a one-dimensional time series signal into multiple sub-bands with different time-frequency resolutions. Compared to Fourier transform, which only reflects the global frequency components of the signal, wavelet transform preserves the signal's time-domain localization capability during the decomposition process, thus enabling the determination of the original level position corresponding to the frequency domain component while obtaining frequency domain information. Among the decomposition coefficients, the parts characterizing local details and abrupt changes in the signal are called high-frequency detail coefficients, and the parts characterizing the overall trend of the signal are called low-frequency approximation coefficients. Specifically, in the multi-scale time-frequency localization step, an orthogonal wavelet basis with compact support characteristics is used to decompose the hidden layer time series signal at multiple scales. The number of decomposition levels is adaptively determined according to the length of the hidden layer time series signal, resulting in high-frequency detail coefficients and low-frequency approximation coefficients at multiple scales. The high-frequency detail coefficients are used to characterize the local abrupt changes of the signal along the inference depth direction at the corresponding scale. The compact support characteristic means that the wavelet basis function takes a non-zero value only within a finite length interval. Wavelet bases with this characteristic can better preserve the local localization accuracy of the signal in the sequence direction during decomposition. As an optional implementation, the orthogonal wavelet basis can be the Db4 wavelet basis, which has a moderate compact support length and vanishing moment order, balancing decomposition accuracy and computational efficiency. The number of decomposition levels J can be adaptively determined according to the length N of the hidden layer time series signal, and its determination method can be expressed as follows: ,in This indicates a floor function, where the number of decomposition levels is the integer obtained by rounding down the logarithm of the hidden layer timing signal length to base 2. This method allows the number of decomposition levels to automatically match the signal length without requiring manual setting for large language models with different numbers of levels.
[0053] The method for locating the target level includes: calculating the sum of the energy of multiple scale high-frequency detail coefficients at corresponding positions of the hidden layer time series signal at each level, as the local high-frequency energy of that level; calculating the mean and standard deviation of the global high-frequency energy of the hidden layer time series signal; and marking the levels where the local high-frequency energy exceeds the sum of the mean and the standard deviation by a preset multiple as candidate target levels, thereby achieving layer-by-layer determination of the hallucination origin level. Specifically, for the local high-frequency energy at level l... , can be represented as ,in Indicates the first High-frequency detail coefficients at scale in the hierarchy The corresponding value at that location, This represents the summation after taking the modulus, squared, and accumulated. This refers to the aforementioned number of decomposition levels; after obtaining the local high-frequency energy corresponding to each level of the hidden layer time-series signal, the mean of the global high-frequency energy of the signal is further calculated. with standard deviation And set dynamic thresholds ,in For the sensitivity coefficient, iterate through all levels, if the local high-frequency energy of a certain level is... Greater than this dynamic threshold If so, that level is marked as a candidate target level. Sensitivity coefficient The value can be selected between 2.0 and 3.0 depending on the number of layers in the large language model, the task scenario, and the detection sensitivity requirements. The larger the value, the stricter the judgment criteria, the fewer candidate target levels are marked, and the higher the accuracy of the detection results, but the risk of missed detection increases accordingly; the smaller the value, the better.
[0054] In the spectral-geometric coupling verification step, the geometric trajectory change features of the hidden state vectors corresponding to the target level and adjacent levels in the semantic space are obtained. These geometric trajectory change features are then coupled with the high-frequency energy features of the target level to obtain the spectral-geometric consistency coefficient characterizing the degree of hallucination risk. Here, the semantic space refers to the high-dimensional vector space within the large language model used to carry semantic information. The hidden state vectors are distributed within this space, and the evolution of the hidden state vectors with the reasoning level can be considered as a trajectory in this semantic space. The geometric trajectory change features are used to characterize the degree to which this trajectory undergoes a turning point or abrupt change near the target level. Specifically, obtaining the geometric trajectory change features includes: calculating the difference between the hidden state vector corresponding to the target level and the hidden state vectors corresponding to its adjacent levels to obtain a semantic velocity vector characterizing the semantic change trend of that level; calculating the directional deviation between the semantic velocity vector of the target level and the semantic velocity vectors of its adjacent levels, using this as the geometric trajectory change feature for subsequent coupling with the high-frequency energy features of the target level. The target level... For example, its semantic velocity vector It can be represented as ,in For target level The corresponding hidden state vector, The difference between the hidden state vector of the adjacent preceding level and the hidden state vector of the preceding level reflects the semantic content as it changes through the hierarchy. Advance to level The changing trends and magnitudes during the process; further, by calculating the semantic velocity vector at the target level. semantic velocity vectors of adjacent levels The degree of directional deviation between the two measures whether the direction of semantic evolution has undergone a significant change before and after the target level. This degree of directional deviation can be represented by the cosine of the angle between them. ,in This represents the vector dot product operation. This represents the operation of taking the modulus of a vector. That is, semantic velocity vector and The angle between them. The larger, that is The smaller the value, the more drastic the shift in the semantic trajectory near that level, and the more likely it is to correspond to the generation of hallucinatory content.
[0055] After obtaining the local high-frequency energy and geometric trajectory change characteristics at the target level, coupling these two parameters yields the spectral-geometric consistency coefficient, which characterizes the degree of hallucination risk. Specifically, the spectral-geometric consistency coefficient is calculated as follows: ,in, The high-frequency energy after normalization at the target level. The angle between the semantic velocity vector of the target level and the semantic velocity vectors of adjacent levels. Mean. with standard deviation The calculations show that the value is used to eliminate the differences in energy levels between different signals, making the value comparable across levels and signals. These are used to characterize the degree of change in the semantic trajectory. The larger the values of both, the more likely the level has experienced an abrupt change in the frequency domain and a significant shift in the geometric trajectory, respectively. The larger the spectral-geometric consistency coefficient obtained by multiplying the two, the more likely the target level simultaneously satisfies both the high-frequency energy anomaly and the semantic trajectory shift. This effectively reduces the probability of misjudgment caused by judging based on a single modality feature alone, achieving dual cross-validation of frequency domain features and geometric features. The preset threshold is determined based on the statistical distribution of historical spectral-geometric consistency coefficients on the validation dataset. The value located at a preset quantile in the statistical distribution is used as the preset threshold, allowing the triggering condition of the adaptive correction step to adaptively calibrate with changes in the large language model and application scenario, without the need for manually setting a fixed threshold. That is, a series of spectral-geometric consistency coefficient values generated by the large language model on the validation dataset can be collected in advance, their overall distribution can be statistically analyzed, and the value at a higher quantile position in the distribution can be selected as the preset threshold. As an optional implementation, the preset quantile can be selected as the 95th percentile. Since the overall numerical distribution of the spectral-geometric consistency coefficient may differ under different large language models and application scenarios, adopting a threshold determination method based on statistical distribution can enable the preset threshold to be automatically adjusted according to the actual deployed model and scenario, avoiding the problem of insufficient adaptability of fixed thresholds under different conditions.
[0056] In the adaptive correction step, when the spectral-geometric consistency coefficient exceeds a preset threshold, based on a pre-determined truthfulness direction, projection correction or spectral filtering correction is performed on the hidden state vector of the target level, and the corrected hidden state vector is input into subsequent levels for further inference. Here, the truthfulness direction refers to a specific directional vector in the semantic space. The component of the hidden state vector in this direction is considered to be related to the truthfulness of the sentence content. By processing the hidden state vector in this direction, the semantic content in the current inference process can be guided towards a more truthful direction without changing the model parameters. Specifically, the truthfulness direction is pre-obtained as follows: based on a comparative corpus containing real and fake sentences, the activation representation of the corresponding final layer of the large language model is extracted, a linear classifier is trained to distinguish between real and fake sentences, and the weight direction of the linear classifier is normalized to serve as the truthfulness direction; when the spectral-geometric consistency coefficient exceeds the preset threshold and triggers the adaptive correction step, the hidden state vector of the target level is orthogonally projected onto the truthfulness direction to obtain the corrected hidden state vector. ,in, Let be the hidden state vector of the target level. The authenticity direction is obtained after normalization. That is, a set of contrastive corpora containing both real and fake statements is constructed, input into a large language model, and the activation representations of the final layer are extracted as training samples. A linear classifier is trained using real and fake statements as category labels. The weight direction learned by this classifier represents the direction that distinguishes real and fake content in the semantic space. The authenticity direction is obtained by normalizing this weight vector by dividing it by its own magnitude. After confirming the target level's trigger correction conditions, the hidden state vector of that level is... and the direction of authenticity Perform the inner product operation, then AND with Multiply, and you get The projection component in the direction of reality is used as the corrected hidden layer state vector. Replace the original vector. More generally, if the true orientation is denoted as before normalization... Then the projection formula can be expressed as ,in This represents the hidden state vector of the target level. This is the true orientation weight vector before normalization. This indicates that the weight vector is squared after taking its magnitude; due to the realism direction in this embodiment... It has been unitized, that is Equal to 1, therefore the above formula simplifies to the aforementioned formula. The projection operation preserves the components in the hidden state vector that are consistent with the direction of reality and suppresses the components that deviate from the direction of reality. Therefore, it can correct semantic biases that may lead to hallucinations before the reasoning process is over. The corrected vector will continue to be fed into subsequent layers as input to participate in reasoning, so that the intervention effect can be continuously transmitted along the subsequent layers of the network.
[0057] As another alternative implementation of projection correction, spectral domain filtering correction can be used to process the hidden state vector of the target level. This involves performing a wavelet transform on the hidden state vector to obtain its decomposition coefficients in the time-frequency domain. High-frequency detail coefficients corresponding to anomalous fluctuations are then suppressed or zeroed out using a preset attenuation coefficient. Finally, an inverse wavelet transform is used to reconstruct the corrected hidden state vector from the processed decomposition coefficients. Since the high-frequency detail coefficients of the target level have already been used to determine the generation of anomalous levels in the multi-scale time-frequency localization step, targeted suppression of these coefficients can effectively weaken anomalous fluctuation components that lead to increased spectral-geometric consistency coefficients while preserving the overall semantic core of the hidden state vector. Compared to projection correction, spectral domain filtering correction, which processes in the time-frequency domain, is more suitable for scenarios where anomalous fluctuations are concentrated in specific frequency bands. Projection correction and spectral domain filtering correction can be chosen individually or used in combination depending on specific deployment requirements.
[0058] This embodiment also provides a large language model illusion detection and dynamic correction system, including a signal construction module, a time-frequency localization module, a feature coupling module, an adaptive correction module, and a control module. The signal construction module is used to acquire cross-layer hidden layer state vectors during the large language model inference process and construct the hidden layer time-series signal. The time-frequency localization module, connected to the signal construction module, is used to perform multi-scale wavelet decomposition on the hidden layer time-series signal and locate the target layer. The feature coupling module, connected to the time-frequency localization module, is used to obtain the geometric trajectory change features of the target layer and calculate the spectral-geometric consistency coefficient. The adaptive correction module, connected to the feature coupling module, is used to perform projection correction or spectral domain filtering correction on the hidden layer state vector of the target layer when the spectral-geometric consistency coefficient exceeds a preset threshold. The control module is connected to the signal construction module, the time-frequency localization module, the feature coupling module, and the adaptive correction module respectively, and is used to coordinate the sequential execution of signal acquisition, time-frequency localization, feature coupling, and adaptive correction operations by each module.
[0059] Specifically, the signal construction module, serving as the interface between the entire system and the large language model inference engine, collects the hidden state vectors corresponding to each Transformer layer in real time during the forward inference process of the large language model and constructs them into hidden time-series signals according to the layer order, which are then output to the time-frequency localization module. Upon receiving the hidden time-series signals, the time-frequency localization module performs multi-scale wavelet decomposition operations on them to obtain high-frequency detail coefficients and low-frequency approximation coefficients at each scale, and determines and outputs the location information of the target layer based on this. The feature coupling module, based on the target layer information output by the time-frequency localization module, further obtains the geometric trajectory change features of the hidden state vectors corresponding to that layer and its adjacent layers, and correlates them with the target layer information. The high-frequency energy features at the target level are coupled and calculated to obtain the spectral-geometric consistency coefficient, which is then output to the adaptive correction module. When the received spectral-geometric consistency coefficient exceeds a preset threshold, the adaptive correction module performs projection correction or spectral domain filtering correction on the hidden state vector of the target level and re-integrates the corrected hidden state vector into the subsequent inference process of the large language model. The control module coordinates the execution timing and data flow of the above modules to ensure that the signal acquisition, time-frequency localization, feature coupling and adaptive correction are connected in sequence and run in coordination. This allows for real-time detection and dynamic correction of hallucination phenomena without changing the parameters of the large language model itself or the main inference framework.
[0060] The modules in the above system can be deployed as software modules on the computing platform on which the large language model inference relies, intervening in the inference process of the large language model as middleware; or they can be combined with dedicated hardware acceleration units to realize parallel computing in the time-frequency analysis and feature coupling process, so as to reduce the impact of system operation on the native inference latency of the large language model.
[0061] The above are merely preferred embodiments of the present invention. The scope of protection of the present invention is not limited to the above embodiments. All technical solutions falling within the scope of the present invention's concept are within the scope of protection of the present invention. It should be noted that for those skilled in the art, any improvements and modifications made without departing from the principle of the present invention should also be considered within the scope of protection of the present invention.
Claims
1. A method for hallucination detection and dynamic correction based on multi-scale temporal-spectral feature coupling in a large language model, characterized in that, include: Cross-layer signal construction steps: During the inference process of generating text in the large language model, the hidden layer state vectors across Transformer layers are collected and arranged in layer order to construct the hidden layer temporal signal; Multi-scale time-frequency localization steps: Perform multi-scale wavelet decomposition on the hidden layer time series signal to obtain decomposition coefficients that characterize high-frequency details, and locate the target layer in the hidden layer time series signal where abnormal fluctuations occur based on the energy distribution of the decomposition coefficients; Spectral-geometric coupling verification steps: Obtain the geometric trajectory change features of the hidden layer state vectors corresponding to the target level and adjacent levels in the semantic space, and perform coupling operation on the geometric trajectory change features with the high-frequency energy features of the target level to obtain the spectral-geometric consistency coefficient characterizing the degree of hallucination risk; Adaptive correction step: When the spectral-geometric consistency coefficient exceeds a preset threshold, based on the predetermined truth direction, projection correction or spectral domain filtering correction is performed on the hidden state vector of the target level, and the corrected hidden state vector is input into the subsequent levels for further inference.
2. The method for hallucination detection and dynamic correction based on multi-scale temporal-spectral feature coupling of a large language model according to claim 1, characterized in that, In the cross-layer signal construction step, for the same Transformer layer, at least two intermediate activation vectors from different sources are collected. The intermediate activation vectors include at least two of the following: the final output vector of the layer, the output vector of the attention sublayer, the attention residual vector, and the output vector of the feedforward neural network. This is to improve the feature richness of the hidden layer temporal signal and provide a signal basis for the multi-scale time-frequency localization step to achieve anomaly localization at the sublayer granularity.
3. The method for hallucination detection and dynamic correction based on multi-scale temporal-spectral feature coupling of a large language model according to claim 2, characterized in that, The intermediate activation vectors collected from each layer are concatenated in layer order and expanded along the feature dimension to construct a signal matrix. The row direction of the signal matrix corresponds to the combination of layer order and activation vector type, and the column direction corresponds to the hidden layer dimension. Each column in the signal matrix constitutes a one-dimensional hidden layer time-series signal that evolves along the inference depth, which serves as the direct processing object of multi-scale wavelet decomposition in the multi-scale time-frequency localization step.
4. The method for hallucination detection and dynamic correction based on multi-scale temporal-spectral feature coupling of a large language model according to claim 1, characterized in that, In the multi-scale time-frequency localization step, an orthogonal wavelet basis with compact support characteristics is used to decompose the hidden layer time series signal into multiple scales. The number of decomposition levels is adaptively determined according to the length of the hidden layer time series signal, resulting in high-frequency detail coefficients and low-frequency approximation coefficients at multiple scales. The high-frequency detail coefficients are used to characterize the local abrupt change features of the signal along the inference depth direction at the corresponding scale.
5. The method for hallucination detection and dynamic correction of a large language model based on multi-scale temporal-spectral feature coupling according to claim 4, characterized in that, The method for locating the target level includes: calculating the sum of the energy of multiple scale high-frequency detail coefficients at corresponding positions of the hidden layer time series signal at each level, as the local high-frequency energy of that level; calculating the mean and standard deviation of the global high-frequency energy of the hidden layer time series signal; and marking the level where the local high-frequency energy exceeds the sum of the mean and the standard deviation by a preset multiple as the candidate target level, thereby realizing the layer-by-layer determination of the hallucination origin level.
6. The method for hallucination detection and dynamic correction of a large language model based on multi-scale temporal-spectral feature coupling according to claim 1, characterized in that, The method for obtaining the geometric trajectory change features includes: calculating the difference between the hidden state vector corresponding to the target level and the hidden state vector corresponding to its adjacent level to obtain a semantic velocity vector that characterizes the semantic change trend of the level; calculating the degree of directional deviation between the semantic velocity vector of the target level and the semantic velocity vector of the adjacent level as the geometric trajectory change feature, which is then used for subsequent coupling operations with the high-frequency energy features of the target level.
7. The method for hallucination detection and dynamic correction of a large language model based on multi-scale temporal-spectral feature coupling according to claim 6, characterized in that, The spectral-geometric consistency coefficient is calculated as follows: ; in, The high-frequency energy after normalization at the target level. The angle between the semantic velocity vector of the target level and the semantic velocity vector of the adjacent level.
8. The method for hallucination detection and dynamic correction of a large language model based on multi-scale temporal-spectral feature coupling according to claim 1, characterized in that, The authenticity direction is obtained in advance in the following way: based on the comparative corpus containing real sentences and fake sentences, the activation representation of the corresponding last layer of the large language model is extracted, a linear classifier is trained to distinguish between real sentences and fake sentences, and the weight direction of the linear classifier is normalized as the authenticity direction. When the spectral-geometric consistency coefficient exceeds a preset threshold and triggers the adaptive correction step, the hidden state vector of the target level is orthogonally projected onto the truth direction to obtain the corrected hidden state vector: ; in, Let be the hidden state vector of the target level. This refers to the direction of authenticity after normalization.
9. The method for hallucination detection and dynamic correction of a large language model based on multi-scale temporal-spectral feature coupling according to claim 1, characterized in that, The preset threshold is determined based on the statistical distribution of the historical spectral-geometric consistency coefficient on the validation dataset. The value located at the preset quantile in the statistical distribution is used as the preset threshold, so that the triggering condition of the adaptive correction step is adaptively calibrated as the large language model and application scenario change, without the need to manually set a fixed threshold.
10. A large language model hallucination detection and dynamic correction system based on multi-scale temporal-spectral feature coupling, characterized in that, For implementing the method according to any one of claims 1 to 9, comprising: The signal construction module is used to collect cross-layer hidden layer state vectors during the reasoning process of a large language model and construct the hidden layer temporal signal. A time-frequency positioning module, connected to the signal construction module, is used to perform multi-scale wavelet decomposition on the hidden layer time series signal and locate the target level. The feature coupling module, connected to the time-frequency positioning module, is used to acquire the geometric trajectory change features of the target level and calculate the spectrum-geometric consistency coefficient. An adaptive correction module, connected to the feature coupling module, is used to perform the projection correction or spectral domain filtering correction on the hidden state vector of the target level when the spectral-geometric consistency coefficient exceeds the preset threshold. The control module is connected to the signal construction module, the time-frequency positioning module, the feature coupling module, and the adaptive correction module, respectively, and is used to coordinate the sequential execution of signal acquisition, time-frequency positioning, feature coupling, and adaptive correction operations by each module.
