Large-scale hallucination detection method, system, equipment, and media based on PCA contribution rate
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-19
- Publication Date
- 2026-08-14
AI Technical Summary
[0004]本发明的技术任务是提供一种基于PCA贡献率的大模型幻觉检测方法、系统、设备及介质,来解决如何实现对大模型生成内容的高效、精准幻觉检测,克服现有技术中特征单一、检测精度低的缺陷的问题
[0047](一)本发明通过构建双特征输入的神经网络模型,实现对大模型生成内容的高效、精准幻觉检测,解决现有方法特征单一、检测精度低的问题;即本发明采用答案长度(单词数或字数)和PCA贡献率的香农熵作为输入特征,答案长度反映内容冗余度(幻觉内容常表现为异常长短),香农熵反映答案集合一致性(幻觉内容一致性低、熵值高),两者形成互补特征体系;
Smart Images

Figure CN120781171B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of artificial intelligence technology, specifically to a method, system, device, and medium for large-scale hallucination detection based on PCA contribution rate. Background Technology
[0002] With the rapid development of large model technology, its application in fields such as natural language processing and intelligent question answering is becoming increasingly widespread. However, the "illusion" phenomenon (i.e., outputting content that does not conform to reality) when large models generate content severely limits their reliability. Existing detection methods mostly rely on single features or complex consistency assessments, resulting in problems such as insufficient detection accuracy and poor adaptability. For example, methods based on text similarity struggle to capture the inherent features of generated content, while multi-round sampling consistency methods are computationally expensive and cannot meet the needs of real-time detection.
[0003] Therefore, how to achieve efficient and accurate illusion detection of large model-generated content and overcome the shortcomings of existing technologies such as single features and low detection accuracy is a technical problem that urgently needs to be solved. Summary of the Invention
[0004] The technical objective of this invention is to provide a method, system, device, and medium for detecting hallucinations in large models based on PCA contribution rate, in order to solve the problem of how to achieve efficient and accurate hallucination detection of content generated by large models, and overcome the shortcomings of existing technologies such as single features and low detection accuracy.
[0005] The technical objective of this invention is achieved as follows: a large-model hallucination detection method based on PCA contribution rate, the specific method of which is as follows:
[0006] Build the dataset: Build a dataset containing multiple questions and their corresponding answers, with each answer labeled with its accuracy.
[0007] For each question in the dataset, drive the large model to generate ten answers;
[0008] Calculate the Shannon entropy of the PCA contribution rate of the hidden states corresponding to the sentence embeddings of the ten answers;
[0009] The average length of the ten answers and the Shannon entropy are used as input features, and the accuracy labels of the answer annotations are used as training labels to train the neural network.
[0010] For a new problem, the large model is driven to generate one answer to be detected and ten auxiliary answers. The length of the answer to be detected is extracted, and the Shannon entropy of the PCA contribution rate of the ten auxiliary answers is calculated. The length of the answer to be detected and the Shannon entropy of the PCA contribution rate are input into the trained neural network to obtain the hallucination detection result.
[0011] As a preferred option, the length of the answer refers to the number of words or characters. The number of words is applicable to English answers, while the number of characters is applicable to Chinese answers. Different datasets are used for the number of words and the number of characters during the training of the neural network.
[0012] As a preferred method, the Shannon entropy for calculating the PCA contribution rate of the hidden states corresponding to the sentence embeddings of the ten answers is as follows:
[0013] The hidden states of the sentence embeddings of the ten answers to the same question are used as ten vectors. Principal component analysis is performed on the ten vectors to obtain the contribution rate of each principal component.
[0014] The Shannon entropy H is calculated based on the contribution rate of each principal component, using the following formula:
[0015]
[0016] Where, p i is the contribution rate of the i-th principal component; Shannon entropy is used to reflect the degree of disorder in the distribution of the ten answer features. The higher the Shannon entropy value, the higher the degree of disorder in the answers, that is, the higher the probability of hallucination, and vice versa.
[0017] Preferably, the neural network adopts a multilayer perceptron structure; the neural network includes an input layer, a hidden layer, and an output layer; the input layer includes two neurons, and the two neurons correspond to two input features; the hidden layer has two layers, including sixteen neurons and eight neurons respectively, and the hidden layer uses the ReLU activation function; the output layer includes one neuron, and the neuron in the output layer uses the sigmoid activation function. The output layer outputs the answer accuracy rate between 0 and 1. The higher the answer accuracy rate, the lower the probability of hallucination.
[0018] As a preferred approach, when training the neural network, the average length of the answer to each question in the dataset and the Shannon entropy are used as input features, and the accuracy label of the corresponding answer is used as the training label. The neural network is trained using the backpropagation algorithm, with the cross-entropy loss function used during the training process. The Adam optimizer is selected, and the learning rate is set to 0.001. The training is iterated until the loss function converges.
[0019] More preferably, the hallucination detection result refers to the probability of being correct. A threshold for the probability of being correct is set to determine whether a hallucination exists, as follows:
[0020] When the correct probability of the neural network output is less than the correct probability threshold, it is determined that a hallucination exists.
[0021] When the probability of being correct is greater than the probability threshold, it is determined that there is no hallucination.
[0022] A large-model hallucination detection system based on PCA contribution rate, the system comprising:
[0023] The dataset building module is used to build a dataset containing multiple questions and their corresponding answers, with the answers labeled with accuracy.
[0024] The answer generation module is used to drive the large model to generate ten answers for each question in the dataset, and to drive the large model to generate one answer to be tested and ten auxiliary answers for a new question;
[0025] The feature calculation module is used to calculate the Shannon entropy of the PCA contribution rate for the ten answers and extract the length of the answers;
[0026] The model training module is used to train the neural network by taking the length and Shannon entropy of each answer as input features and the accuracy label as the training label.
[0027] The detection module is used to input the length of the answer to be detected corresponding to the new question and the Shannon entropy of ten auxiliary answers into the trained neural network to obtain the hallucination detection results.
[0028] As a preferred option, the length of the answer extracted by the feature calculation module refers to the number of words or characters. The word count is applicable to English answers, while the character count is applicable to Chinese answers. Different datasets are used for word count and character count during the training of the neural network.
[0029] The feature calculation module calculates the Shannon entropy of the PCA contribution rate for the ten answers as follows:
[0030] The hidden states of the sentence embeddings of the ten answers to the same question are used as ten vectors. Principal component analysis is performed on the ten vectors to obtain the contribution rate of each principal component.
[0031] The Shannon entropy H is calculated based on the contribution rate of each principal component, using the following formula:
[0032]
[0033] Where, p i The contribution rate of the i-th principal component; Shannon entropy is used to reflect the degree of disorder in the distribution of the ten answer features. The lower the Shannon entropy value, the higher the consistency of the answers, that is, the lower the probability of hallucination, and vice versa.
[0034] The neural network adopts a multilayer perceptron structure; the neural network includes an input layer, a hidden layer, and an output layer; the input layer includes two neurons, and the two neurons correspond to two input features; there are two hidden layers, with sixteen neurons and eight neurons respectively, and the hidden layers use the ReLU activation function; the output layer includes one neuron, and the neuron in the output layer uses the sigmoid activation function. The output layer outputs a hallucination probability value between 0 and 1, which represents the correctness of the answer;
[0035] The specific working process of the detection module is as follows:
[0036] ① For a new problem, drive the large model to generate one answer to be tested.
[0037] ② Extract the length feature of the answer to be detected, and calculate the Shannon entropy of the PCA contribution rate by generating 10 auxiliary answers to a new question;
[0038] Input the length feature of the answer to be detected and the Shannon entropy of the PCA contribution rate into the trained neural network, and output the correct probability.
[0039] Set the correct probability threshold to determine whether hallucination exists:
[0040] When the correct probability of the neural network output is less than the correct probability threshold, it is determined that a hallucination exists.
[0041] When the probability of being correct is greater than the probability threshold, it is determined that there is no hallucination.
[0042] An electronic device includes: a memory and at least one processor;
[0043] The memory contains computer programs;
[0044] The at least one processor executes the computer program stored in the memory, causing the at least one processor to perform the large model illusion detection method based on PCA contribution rate as described above.
[0045] A computer-readable storage medium storing a computer program that can be executed by a processor to implement the large model illusion detection method based on PCA contribution rate as described above.
[0046] The large-model hallucination detection method, system, device, and medium based on PCA contribution rate of the present invention have the following advantages:
[0047] (i) This invention achieves efficient and accurate hallucination detection of large model-generated content by constructing a neural network model with dual feature inputs, solving the problems of single features and low detection accuracy of existing methods; that is, this invention uses answer length (number of words or characters) and Shannon entropy of PCA contribution rate as input features. Answer length reflects the redundancy of content (hallucination content often shows abnormal length), and Shannon entropy reflects the consistency of answer set (hallucination content has low consistency and high entropy value). The two form a complementary feature system.
[0048] (ii) This invention captures hallucination features through two complementary features, which improves detection accuracy, and has high training efficiency, excellent generalization ability and good real-time performance. It is suitable for large-scale hallucination detection in various scenarios.
[0049] (III) The present invention has strong complementary features: the length of the answer reflects the redundancy of the generated content (hallucination content is often excessively long or abnormally short), and the Shannon entropy of the PCA contribution rate reflects the consistency of the answer set (hallucination content has low consistency and high entropy value). The two capture hallucination features from different dimensions and improve detection accuracy.
[0050] (iv) The present invention has high training efficiency: training samples can be constructed by generating 10 answers based on the existing dataset, without the need for complex external knowledge bases or multiple sampling calculations, thus reducing data preparation costs;
[0051] (v) The invention has excellent generalization ability: By learning the mapping relationship between features and accuracy, the neural network can adapt to problems in different fields and large models of different types, solving the problem of limited scenarios of traditional methods;
[0052] (vi) The present invention has good real-time performance: feature extraction only requires statistical length and PCA calculation, and the neural network inference speed is fast, making it suitable for online detection scenarios (such as real-time verification of intelligent question answering systems);
[0053] (vii) This invention generates 10 answers for each question-driven large model. Through diversity sampling (adjusting temperature coefficient and top-k value), it ensures that the samples cover different expression forms and potential hallucination situations, breaking through the limitations of existing single features. It constructs a dual feature system of "answer length + PCA contribution rate and Shannon entropy", which captures hallucination features from two dimensions: content form and set consistency. A single feature is difficult to fully describe the characteristics of hallucination. The dual features complement each other from different dimensions. Experimental verification shows that it can improve the detection accuracy by 15%-20%.
[0054] (viii) This invention quantifies the distribution characteristics of the answer set by calculating the Shannon entropy of the PCA contribution rate of the sentence embeddings of the hidden layer of the 10 generated answers. Then, it adopts a multilayer perceptron structure, where the input layer receives dual features, the hidden layer achieves feature fusion through nonlinear transformation, and the output layer outputs the correct probability through the sigmoid activation function, thus achieving end-to-end detection. The accurate probability is used as the output. The neural network learns the mapping relationship between dual features and accurate probability, replacing the traditional rule-based judgment and improving the adaptive ability of detection. Attached Figure Description
[0055] The invention will be further described below with reference to the accompanying drawings.
[0056] Appendix Figure 1 This is a flowchart of a large-model hallucination detection method based on PCA contribution rate. Detailed Implementation
[0057] The following detailed description of the large-model hallucination detection method, system, device, and medium based on PCA contribution rate of the present invention is provided with reference to the accompanying drawings and specific embodiments.
[0058] Example 1:
[0059] As attached Figure 1 As shown in the figure, this embodiment provides a large-model hallucination detection method based on PCA contribution rate, and the method is as follows:
[0060] S1. Constructing the dataset: Construct a dataset containing multiple questions and their corresponding answers, with each answer labeled with its accuracy.
[0061] S2. For each question in the dataset, drive the large model to generate ten answers;
[0062] S3. Calculate the Shannon entropy of the PCA contribution rate corresponding to the hidden state of the sentence embedding for the ten answers;
[0063] S4. Use the average length of the ten answers and the Shannon entropy as input features, and the accuracy labels of the answer annotations as training labels to train the neural network.
[0064] S5. For a new problem, drive the large model to generate one answer to be detected and ten auxiliary answers. Extract the length of the answer to be detected and calculate the Shannon entropy of the PCA contribution rate of the ten auxiliary answers. Input the length of the answer to be detected and the Shannon entropy of the PCA contribution rate into the trained neural network to obtain the hallucination detection result.
[0065] In this embodiment, the length of the answer refers to the number of words or characters. The number of words applies to English answers, while the number of characters applies to Chinese answers. Different datasets are used for the number of words and the number of characters during the training of the neural network.
[0066] In step S3 of this embodiment, the Shannon entropy for calculating the PCA contribution rate of the hidden states corresponding to the sentence embeddings of the ten answers is as follows:
[0067] S301. Take the hidden states of the sentence embeddings of the ten answers to the same question as ten vectors, perform principal component analysis on the ten vectors, and obtain the contribution rate of each principal component.
[0068] S302. Calculate the Shannon entropy H based on the contribution rate of each principal component, using the following formula:
[0069]
[0070] Where, p i is the contribution rate of the i-th principal component; Shannon entropy is used to reflect the degree of disorder in the distribution of the ten answer features. The higher the Shannon entropy value, the higher the degree of disorder in the answers, that is, the higher the probability of hallucination, and vice versa.
[0071] The neural network in this embodiment adopts a multilayer perceptron structure; the neural network includes an input layer, a hidden layer, and an output layer; wherein, the input layer includes two neurons, and the two neurons correspond to two input features; the hidden layer is set with two layers, including sixteen neurons and eight neurons respectively, and the hidden layer uses the ReLU activation function; the output layer includes one neuron, and the neuron in the output layer uses the sigmoid activation function. The output layer outputs the answer accuracy rate between 0 and 1. The higher the answer accuracy rate, the lower the probability of hallucination.
[0072] In step S4 of this embodiment, when training the neural network, the average length of the answer to each question in the dataset and the Shannon entropy are used as input features, and the accuracy label of the corresponding answer is used as the training label. The neural network is trained by the backpropagation algorithm. The cross-entropy loss function is used during the training process, the Adam optimizer is selected, the learning rate is set to 0.001, and the iteration continues until the loss function converges.
[0073] In this embodiment, the hallucination detection result in step S5 refers to the correct probability. A correct probability threshold is set to determine whether hallucination exists, as detailed below:
[0074] When the correct probability of the neural network output is less than the correct probability threshold, it is determined that a hallucination exists.
[0075] When the probability of being correct is greater than the probability threshold, it is determined that there is no hallucination.
[0076] Example 2:
[0077] This embodiment provides a large-model hallucination detection system based on PCA contribution rate, the system comprising:
[0078] The dataset building module is used to build a dataset containing multiple questions and their corresponding answers, with the answers labeled with accuracy.
[0079] The answer generation module drives the large model to generate ten answers for each question in the dataset, and for new questions, it drives the large model to generate one answer to be detected and ten auxiliary answers. The answer generation process in this module can achieve answer diversity by adjusting the large model's sampling parameters (such as temperature and top-k), ensuring that the samples cover different expressions and potential hallucination scenarios. For example, for the question "What is the capital of a certain country?", it generates 10 answers including "Beijing", "The capital of a certain country is Beijing", and "Beijing is the capital of a certain country", which may contain a small number of incorrect answers (such as "a certain sea") as hallucination samples.
[0080] The feature calculation module is used to calculate the Shannon entropy of the PCA contribution rate for the ten answers and extract the length of the answers;
[0081] The model training module is used to train the neural network by taking the length and Shannon entropy of each answer as input features and the accuracy label as the training label.
[0082] The detection module is used to input the length of the answer to be detected corresponding to the new question and the Shannon entropy of ten auxiliary answers into the trained neural network to obtain the hallucination detection results.
[0083] In this embodiment, the length of the answer extracted by the feature calculation module refers to the number of words or characters. The number of words is applicable to English answers, while the number of characters is applicable to Chinese answers. Different datasets are used for the number of words and the number of characters during the training of the neural network.
[0084] In this embodiment, the feature calculation module calculates the Shannon entropy of the PCA contribution rate for the ten answers as follows:
[0085] ①The hidden states of the sentence embeddings of the ten answers to the same question are used as ten vectors. Principal component analysis is performed on the ten vectors to obtain the contribution rate of each principal component.
[0086] ② Calculate the Shannon entropy H based on the contribution rate of each principal component, using the following formula:
[0087]
[0088] Where, p i is the contribution rate of the i-th principal component; Shannon entropy is used to reflect the degree of disorder in the distribution of the ten answer features. The higher the Shannon entropy value, the higher the degree of disorder in the answers, that is, the higher the probability of hallucination, and vice versa.
[0089] The neural network in this embodiment adopts a multilayer perceptron structure; the neural network includes an input layer, a hidden layer, and an output layer; wherein, the input layer includes two neurons, and the two neurons correspond to two input features; the hidden layer is set with two layers, including sixteen neurons and eight neurons respectively, and the hidden layer uses the ReLU activation function; the output layer includes one neuron, and the neuron in the output layer uses the sigmoid activation function. The output layer outputs the answer accuracy rate between 0 and 1. The higher the answer accuracy rate, the lower the probability of hallucination.
[0090] The specific working process of the detection module in this embodiment is as follows:
[0091] ① For a new problem, drive the large model to generate one answer to be tested.
[0092] ② Extract the length feature of the answer to be detected, and calculate the Shannon entropy of the PCA contribution rate by generating 10 auxiliary answers to a new question;
[0093] Input the length feature of the answer to be detected and the Shannon entropy of the PCA contribution rate into the trained neural network, and output the correct probability.
[0094] Set the correct probability threshold to determine whether there is a hallucination:
[0095] When the correct probability output by the neural network is less than the correct probability threshold, it is determined that there is a hallucination;
[0096] When the correct probability is greater than the correct probability threshold, it is determined that there is no hallucination.
[0097] Among them, the correct rate threshold is set to 0.5.
[0098] Example 3:
[0099] This embodiment provides a large model hallucination detection method based on PCA contribution rate, and the method is as follows:
[0100] (1) Dataset preparation: Select a dataset containing 10,000 questions, covering fields such as history, science, and common sense of life, and each question has a corresponding reference answer;
[0101] (2) Multi-answer generation: Use a selected large language model to generate 10 answers for each question. Adjust the temperature to 0.5 and top-k = 20 to ensure answer diversity. For example, among the 10 answers generated for the question "What is the capital of a certain country?", 8 are "a certain capital" (accurate) and 2 are "a certain bya" (wrong).
[0102] (3) Feature extraction, specifically as follows:
[0103] ① Answer length: Count the number of Chinese characters in each answer. For example, the accurate answer "a certain capital" has 2 characters, and the wrong answer "a certain bya" has 4 characters.
[0104] ② Shannon entropy of PCA contribution rate: Extract the sentence embeddings of the hidden layers of the 10 answers to obtain ten vectors. Then perform PCA on these ten vectors to obtain ten contribution rates, and calculate the Shannon entropy of the contribution rates.
[0105] (4) Model training, specifically as follows:
[0106] ① Input features: length (such as 8) and Shannon entropy (such as 0.72).
[0107] ② Labels: accuracy rate (such as 0.6).
[0108] ③ Neural network training: Iterate until the loss function is less than a given threshold, stop training, and save the network parameters.
[0109] (5) New question detection, specifically as follows:
[0110] ① New question: "What is the largest planet in the solar system?" The model generates the answer: "Jupiter is the largest planet in the solar system" (12 characters in length).
[0111] ② Generate 10 auxiliary answers, and calculate the Shannon entropy of the PCA contribution rate as 0.2.
[0112] ③ Input the neural network, output probability 0.8, which is greater than 0.5, and determine that there is no hallucination.
[0113] The above embodiments are merely examples. In practical applications, the dataset size, neural network parameters, and threshold settings can be adjusted according to the problem domain.
[0114] Example 4:
[0115] This embodiment also provides an electronic device, including: a memory and a processor;
[0116] The memory stores the instructions executed by the computer.
[0117] The processor executes computer execution instructions stored in the memory, causing the processor to execute the large model illusion detection method based on PCA contribution rate in any embodiment of the present invention.
[0118] The processor can be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), off-the-shelf programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor can be a microprocessor or any conventional processor, etc.
[0119] Memory is used to store computer programs and / or modules. The processor implements various functions of the electronic device by running or executing the computer programs and / or modules stored in the memory, and by accessing data stored in the memory. Memory can primarily include a program storage area and a data storage area. The program storage area can store the operating system, at least one application program required for a function, etc.; the data storage area can store data created based on the use of the terminal, etc. Furthermore, memory can also include high-speed random access memory, and can also include non-volatile memory, such as hard disks, RAM, plug-in hard disks, smart memory cards (SMCs), secure digital cards (SD cards), flash memory cards, at least one disk storage device, flash memory device, or other volatile solid-state storage devices.
[0120] Example 5:
[0121] This embodiment also provides a computer-readable storage medium storing multiple instructions, which are loaded by a processor to cause the processor to execute the large model illusion detection method based on PCA contribution rate in any embodiment of the present invention. Specifically, a system or apparatus equipped with a storage medium may be provided, on which software program code implementing the functions of any of the above embodiments is stored, and the computer (or CPU or MPU) of the system or apparatus may read and execute the program code stored in the storage medium.
[0122] In this case, the program code read from the storage medium can itself implement the function of any of the above embodiments, and therefore the program code and the storage medium storing the program code constitute part of the present invention.
[0123] Storage media embodiments for providing program code include floppy disks, hard disks, magneto-optical disks, optical disks (such as CD-ROM, CD-R, CD-RW, DVD-ROM, DVD-RYM, DVD-RW, DVD+RW), magnetic tapes, non-volatile memory cards, and ROMs. Alternatively, program code can be downloaded from a server computer via a communication network.
[0124] Furthermore, it should be clear that not only can the program code read by the computer be executed, but also the operating system or other components operating on the computer can be instructed based on the program code to perform some or all of the actual operations, thereby realizing the function of any of the embodiments described above.
[0125] Furthermore, it is understood that the program code read from the storage medium is written to the memory set in the expansion board inserted into the computer or to the memory set in the expansion unit connected to the computer. Then, based on the instructions of the program code, the CPU or other components installed on the expansion board or expansion unit execute some and all of the actual operations, thereby realizing the function of any of the embodiments described above.
[0126] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.
Claims
1. A large-model hallucination detection method based on PCA contribution rate, characterized in that, The method is as follows: Construct a dataset containing multiple questions and their corresponding answers, with each answer labeled with its accuracy. For each question in the dataset, drive the large model to generate ten answers; Calculate the Shannon entropy of the PCA contribution rate of the hidden states corresponding to the sentence embeddings of the ten answers; The average length of the ten answers and the Shannon entropy are used as input features, and the accuracy labels of the answer annotations are used as training labels to train the neural network. For a new problem, a large model is driven to generate one answer to be detected and ten auxiliary answers. The length of the answer to be detected is extracted, and the Shannon entropy of the PCA contribution rate of the ten auxiliary answers is calculated. The length of the answer to be detected and the Shannon entropy of the PCA contribution rate are input into the trained neural network to obtain the hallucination detection result. The neural network adopts a multilayer perceptron structure. The neural network includes an input layer, a hidden layer, and an output layer. The output layer outputs the answer accuracy rate between 0 and 1. The higher the answer accuracy rate, the lower the probability of hallucination. The length of the answer refers to the number of words or characters. The word count applies to English answers, while the character count applies to Chinese answers. Different datasets are used for word count and character count during the training of the neural network. The Shannon entropy for calculating the PCA contribution rate of the hidden states corresponding to the sentence embeddings of the ten answers is as follows: The hidden states of the sentence embeddings of the ten answers to the same question are used as ten vectors. Principal component analysis is performed on the ten vectors to obtain the contribution rate of each principal component. Shannon entropy is calculated based on the contribution rate of each principal component. The formula is as follows: ; in, is the contribution rate of the i-th principal component; Shannon entropy is used to reflect the degree of disorder in the distribution of the ten answer features. The higher the Shannon entropy value, the higher the degree of disorder of the answers, that is, the higher the probability of hallucination, and vice versa.
2. The large-model hallucination detection method based on PCA contribution rate according to claim 1, characterized in that, The input layer consists of two neurons, each corresponding to one of the two input features; the hidden layer consists of two layers, with sixteen and eight neurons respectively, and the hidden layers use the ReLU activation function; the output layer consists of one neuron, and the neuron in the output layer uses the sigmoid activation function.
3. The large-model hallucination detection method based on PCA contribution rate according to claim 1, characterized in that, When training the neural network, the average length of the answer to each question in the dataset and the Shannon entropy are used as input features, and the accuracy label of the corresponding answer is used as the training label. The neural network is trained by backpropagation algorithm. The cross-entropy loss function is used during the training process. The Adam optimizer is selected and the learning rate is set to 0.
001. The training is iterated until the loss function converges.
4. The large-model hallucination detection method based on PCA contribution rate according to any one of claims 1 to 3, characterized in that, Hallucination detection results refer to the probability of being correct. A threshold for the probability of being correct is set to determine whether hallucinations exist, as detailed below: When the correct probability of the neural network output is less than the correct probability threshold, it is determined that a hallucination exists. When the probability of being correct is greater than the probability threshold, it is determined that there is no hallucination.
5. A large-model hallucination detection system based on PCA contribution rate, characterized in that, This system is used to implement the large-model hallucination detection method based on PCA contribution rate as described in any one of claims 1 to 4; the system includes: The dataset building module is used to build a dataset containing multiple questions and their corresponding answers, with the answers labeled with accuracy. The answer generation module is used to drive the large model to generate ten answers for each question in the dataset, and to drive the large model to generate one answer to be tested and ten auxiliary answers for a new question; The feature calculation module is used to calculate the Shannon entropy of the PCA contribution rate for the ten answers and extract the length of the answers; The model training module is used to train the neural network by taking the length and Shannon entropy of each answer as input features and the accuracy label as the training label. The detection module is used to input the length of the answer to be detected corresponding to the new question and the Shannon entropy of ten auxiliary answers into the trained neural network to obtain the hallucination detection results.
6. The large-model hallucination detection system based on PCA contribution rate according to claim 5, characterized in that, The length of the answer extracted by the feature calculation module refers to the number of words or characters. The word count applies to English answers, while the character count applies to Chinese answers. Different datasets are used for word count and character count during the training of the neural network. The feature calculation module calculates the Shannon entropy of the PCA contribution rate for the ten answers as follows: The hidden states of the sentence embeddings of the ten answers to the same question are used as ten vectors. Principal component analysis is performed on the ten vectors to obtain the contribution rate of each principal component. Shannon entropy is calculated based on the contribution rate of each principal component. The formula is as follows: ; in, The contribution rate of the i-th principal component; Shannon entropy is used to reflect the degree of disorder in the distribution of the ten answer features. The higher the Shannon entropy value, the higher the degree of disorder of the answers, that is, the higher the probability of hallucination, and vice versa. The neural network adopts a multilayer perceptron structure; the neural network includes an input layer, a hidden layer, and an output layer; the input layer includes two neurons, with each neuron corresponding to one of the two input features; the hidden layer has two layers, with sixteen neurons and eight neurons respectively, and the hidden layer uses the ReLU activation function; the output layer includes one neuron, and the neuron in the output layer uses the sigmoid activation function. The output layer outputs the answer accuracy rate between 0 and 1, and the higher the answer accuracy rate, the lower the probability of hallucination; The specific working process of the detection module is as follows: ① For a new problem, drive the large model to generate one answer to be tested; ② Extract the length feature of the answer to be detected, and calculate the Shannon entropy of the PCA contribution rate by generating 10 auxiliary answers; The length feature of the answer to be detected and the Shannon entropy of the PCA contribution rate are input into the trained neural network, and the correct probability is output. Set the correct probability threshold to determine whether hallucination exists: When the correct probability of the neural network output is less than the correct probability threshold, it is determined that a hallucination exists. When the probability of being correct is greater than the probability threshold, it is determined that there is no hallucination.
7. An electronic device, characterized in that, include: Memory and at least one processor; The memory contains computer programs; The at least one processor executes the computer program stored in the memory, causing the at least one processor to perform the large model hallucination detection method based on PCA contribution rate as described in any one of claims 1 to 4.
8. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that can be executed by a processor to implement the large model hallucination detection method based on PCA contribution rate as described in any one of claims 1 to 4.
Citation Information
Patent Citations
Illusion detection method and device based on semantic embedding and structural entropy detection
CN119446427A
Information detection method and system and electronic equipment
CN120372341A