Method and device for determining whether large language model output is hallucination
By performing unit division, named entity recognition and probability calculation on the large language model output, combined with question generation and answer verification, the problem of low efficiency in detecting large language model hallucinations in the existing technology is solved, and more efficient hallucination detection is achieved.
Patent Information
- Application Number
- CN202410743889.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-11
- Publication Date
- 2024-10-15
- Estimated Expiration
- 2044-06-11
Smart Images

Figure CN118333149B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of machine learning technology, and in particular to a method and device for determining whether the output of a large language model is hallucination. Background Art
[0002] Large language models (LLMs) perform well in multiple domains, but they may produce unrealistic or meaningless "hallucination" outputs. The "hallucination" of large language models refers to the unrealistic or inaccurate information produced by the model when generating content. Existing hallucination detection methods mainly rely on external knowledge bases for authenticity verification or require sampling multiple responses of large language models from LLMs to verify information consistency, which are costly and inefficient. Summary of the invention
[0003] In view of this, embodiments of the present application provide a method, device, electronic device, and computer-readable storage medium for determining whether a large language model output is a hallucination, so as to solve the problem of low efficiency in detecting large language model hallucinations in the prior art.
[0004] According to a first aspect of an embodiment of the present application, there is provided a method for determining whether an output of a large language model is an illusion, comprising: obtaining an output of a first language model, dividing the output into a plurality of units in a sequence according to preset units, performing named entity recognition on each unit to obtain a category of each unit, wherein the sequence of each unit is the position of the unit in the output; using a second language model to predict the probability of generating a unit corresponding to the position at each position of the output, wherein the first language model and the second language model adopt different model architectures; calculating a first illusion degree value corresponding to the output based on each unit and its category and its corresponding probability; generating a plurality of questions according to the output and the category of each unit, answering each question using the first language model, and obtaining an answer to each question; calculating a second illusion degree value corresponding to the output based on the output and the answers to each question; and determining whether the output is an illusion generated by the first language model according to the first illusion degree value and the second illusion degree value.
[0005] According to a second aspect of an embodiment of the present application, there is provided an apparatus for determining whether an output of a large language model is an illusion, comprising: a division module configured to obtain an output of a first language model, divide the output into a plurality of units in a sequence according to preset units, perform named entity recognition on each unit, and obtain a category of each unit, wherein the sequence of each unit is the position of the unit in the output; a prediction module configured to predict, using a second language model, a probability of generating a unit corresponding to the position at each position of the output, wherein the first language model and the second language model adopt different model architectures; a first calculation module configured to calculate a first illusion degree value corresponding to the output based on each unit and its category and its corresponding probability; a generation module configured to generate a plurality of questions according to the output and the category of each unit, answer each question using the first language model, and obtain an answer to each question; a second calculation module configured to calculate a second illusion degree value corresponding to the output based on the output and the answers to each question; and a determination module configured to determine, based on the first illusion degree value and the second illusion degree value, whether the output is an illusion generated by the first language model.
[0006] According to a third aspect of an embodiment of the present application, an electronic device is provided, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the above method when executing the computer program.
[0007] According to a fourth aspect of an embodiment of the present application, a computer-readable storage medium is provided, which stores a computer program, and when the computer program is executed by a processor, the steps of the above method are implemented.
[0008] Compared with the prior art, the embodiments of the present application have the following beneficial effects: obtaining the output of the first language model, dividing the output into a plurality of units in a sequence according to preset units, performing named entity recognition on each unit, and obtaining the category of each unit, wherein the sequence of each unit is the position of the unit in the output; using the second language model to predict the probability of generating the unit corresponding to the position at each position of the output, wherein the first language model and the second language model adopt different model architectures; calculating the first hallucination degree value corresponding to the output based on each unit and its category and its corresponding probability; generating a plurality of questions based on the output and the category of each unit, answering each question using the first language model, and obtaining the answer to each question; calculating the second hallucination degree value corresponding to the output based on the output and the answer to each question; judging whether the output is a hallucination generated by the first language model based on the first hallucination degree value and the second hallucination degree value. The above technical means can solve the problem of low efficiency in detecting hallucinations of large language models in the prior art, thereby improving the efficiency of detecting hallucinations of large language models. BRIEF DESCRIPTION OF THE DRAWINGS
[0009] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings in the following description are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0010] Figure 1 It is a flowchart of a method for determining whether the output of a large language model is hallucination, provided in an embodiment of the present application;
[0011] Figure 2 It is a flowchart of a method for calculating a hallucination degree value of an output of a large language model provided in an embodiment of the present application;
[0012] Figure 3 The present invention provides a schematic diagram of a device structure for determining whether a large language model output is a hallucination, provided in an embodiment of the present application;
[0013] Figure 4 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0014] In the following description, specific details such as specific system structures and technologies are provided for the purpose of illustration rather than limitation, so as to provide a thorough understanding of the embodiments of the present application. However, it should be clear to those skilled in the art that the present application can also be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to prevent unnecessary details from obstructing the description of the present application.
[0015] A method and apparatus for determining whether a large language model output is hallucination according to an embodiment of the present application will be described in detail below with reference to the accompanying drawings.
[0016] Figure 1 It is a flowchart of a method for determining whether the output of a large language model is hallucination, provided in an embodiment of the present application. Figure 1 The method for determining whether the output of the large language model is hallucination can be executed by a computer or a server, or by software on the computer or the server. Figure 1 As shown, the method for determining whether the output of the large language model is hallucination includes:
[0017] S101, obtaining the output of the first language model, dividing the output into a plurality of units having a sequence according to preset units, performing named entity recognition on each unit, and obtaining a category of each unit, wherein the sequence of each unit is the position of the unit in the output;
[0018] S102, using the second language model to predict the probability of generating a unit corresponding to each position of the output, wherein the first language model and the second language model use different model architectures;
[0019] S103, calculating and outputting a corresponding first hallucination degree value based on each unit and its category and its corresponding probability;
[0020] S104, generating multiple questions based on the output and the category of each unit, answering each question using the first language model, and obtaining answers to each question;
[0021] S105, calculating a second hallucination degree value corresponding to the output based on the output and the answers to each question;
[0022] S106: Determine whether the output is a hallucination generated by the first language model according to the first hallucination degree value and the second hallucination degree value.
[0023] The preset unit can be a token. In natural language processing, a token is a basic unit in a text, usually a word, a phrase, a punctuation mark, a character, etc. The output is divided into multiple tokens in a sequential order. For example, "OpenAI is a company" can be split into tokens in the form of {Open, AI, is, a, company}. The trained BERT (full name: Bidirectional Encoder Representations from Transformers) model is used to perform named entity recognition on each unit. The categories of each unit include names of people, places, names of institutions, time, date, amount, etc. For example, the categories of each unit {Open, AI, is, a, company} are {"ORG_B", "ORG_E", "other", "other", "other"}, indicating that the first two in the token have category information of ORG (organization) (where _B and _E represent the beginning and end, and other represents unimportant information).
[0024] The first language model and the second language model use different model architectures. The first language model and the second language model can be commonly used large language models, such as Tongyi Qianwen, Wenxin Yiyan, Zhipu Qingyan and ChatGPT (full name: ChatGenerative Pre-trained Transformer). The second language model predicts the probability of generating the corresponding unit at each position of the output, such as the probability of generating Open at the first position of the output, and the probability of generating AI at the second position... The first illusion degree value is calculated based on each unit and its category and its corresponding probability, which is actually to evaluate the first illusion degree value corresponding to the output of the first language model with the help of the second language model. Reconstruct multiple questions based on the output and the category of each unit, and the first language model re-answers each question to obtain the answer to each question. Calculate the second illusion degree value based on the output and the answer to each question, which is actually to repeatedly use the first language model to evaluate the second illusion degree value corresponding to its own output. Finally, the first illusion degree value and the second illusion degree value are combined to determine whether the output is an illusion generated by the first language model.
[0025] According to the technical solution provided by the embodiment of the present application, the output of the first language model is obtained, the output is divided into a plurality of units with a sequence according to the preset units, and each unit is subjected to named entity recognition to obtain the category of each unit, wherein the sequence of each unit is the position of the unit in the output; the probability of generating the unit corresponding to the position at each position of the output is predicted by the second language model, wherein the first language model and the second language model adopt different model architectures; the first hallucination degree value corresponding to the output is calculated based on each unit and its category and its corresponding probability; multiple questions are generated according to the output and the category of each unit, and each question is answered using the first language model to obtain the answer to each question; the second hallucination degree value corresponding to the output is calculated based on the output and the answer to each question; and the output is judged whether it is a hallucination generated by the first language model according to the first hallucination degree value and the second hallucination degree value. The above technical means can solve the problem of low efficiency in detecting hallucinations of large language models in the prior art, thereby improving the efficiency of detecting hallucinations of large language models.
[0026] Figure 2 FIG. 1 is a flow chart of a method for calculating the hallucination degree value of the output of a large language model provided in an embodiment of the present application. Figure 2 As shown, the method includes:
[0027] S201, calculating the correction value corresponding to each unit based on the probability corresponding to each unit;
[0028] S202, determining a first weight corresponding to each unit based on the category of each unit;
[0029] S203, calculating the uncertainty value corresponding to each unit based on the probability, correction value and first weight corresponding to each unit;
[0030] S204, determining a second weight corresponding to each unit based on each unit and its category;
[0031] S205: Calculate and output a corresponding first hallucination degree value based on the uncertainty value corresponding to each unit and the second weight.
[0032] Calculate the correction value corresponding to each unit according to the following formula:
[0033] ;
[0034] in, is the unit at the jth position of the output, is the probability corresponding to the unit at the jth position of the output, The base is 2 The logarithm of is the correction value corresponding to the unit at the ith position of the output.
[0035] You can set a dynamic weight function , according to the category of each unit, different weights between 0 and 1 are returned. For example, if it is part of a name, it is 0.9, if it is a date, it is 0.7, and so on.
[0036] Calculate the uncertainty value corresponding to each unit according to the following formula:
[0037] ;
[0038] in, is the probability corresponding to the unit at the ith position of the output, The base is 2 The logarithm of is the correction value corresponding to the unit at the ith position of the output, is the first weight corresponding to the unit at the ith position of the output, is the uncertainty value corresponding to the unit at the ith position of the output.
[0039] You can set a piecewise function p(x), if a unit is the core information in the output, the second weight corresponding to the unit is 1, otherwise it is 0. The core information in the output can be determined according to the category of each unit. For example, in an output "OpenAI's current CEO is Gates", the organization "OpenAI" and the name "Gates" are the core information.
[0040] Calculate the first illusion degree value corresponding to the output according to the following formula :
[0041] ;
[0042] in, is the second weight corresponding to the unit at the jth position of the output, is the uncertainty value corresponding to the unit at the jth position in the output, and n is the number of all positions or units in the output.
[0043] There is one unit in one position in the output, so the number of all positions in the output is the same as the number of all units. The smaller the first hallucination degree value, the lower the probability that the output is a hallucination.
[0044] Multiple questions are generated based on the output and the categories of each unit. This is to ask questions about the more important categories in the output. For example, if an output is "OpenAI's current CEO is Gates", the following questions can be generated: "Who is OpenAI's current CEO?" and "Which company's current CEO is Gates?" The first language model answers each question and obtains the answer to each question.
[0045] Furthermore, a second illusion degree value corresponding to the output is calculated based on the output and the answers to each question, including: judging whether the answer to each question is consistent with the output to determine the score of the answer to each question; and calculating the second illusion degree value corresponding to the output according to the score of the answer to each question.
[0046] If the answer to "Who is the current CEO of OpenAI" is "Gates", the score of the answer to this question is 1. If the answer to "Which company's current CEO is Gates" is "OpenAI", the score of the answer to this question is 1. If the answers to all questions are correct, the second illusion degree value corresponding to the output is 0. The smaller the first illusion degree value, the lower the probability that the output is an illusion. If the answer to a question is incorrect, the second illusion degree value corresponding to the output is 1.
[0047] Furthermore, judging whether the output is a hallucination produced by the first language model based on the first hallucination degree value and the second hallucination degree value includes: taking a weighted sum of the first hallucination degree value and the second hallucination degree value to obtain the hallucination degree value; and when the hallucination degree value is greater than a preset threshold, determining that the output is a hallucination produced by the first language model.
[0048] Corresponding weights can be assigned to the first hallucination degree value and the second hallucination degree value according to the accuracy of the second language model's historical evaluation that the output of the first language model is a hallucination and the accuracy of the first language model's historical evaluation that its own output is a hallucination. The first hallucination degree value and the second hallucination degree value are weighted and summed to obtain the hallucination degree value. When the hallucination degree value is greater than a preset threshold, it is determined that the output is a hallucination generated by the first language model, otherwise it is determined that the output is not a hallucination generated by the first language model.
[0049] It is also possible to determine that the output is a hallucination produced by the first language model when the first hallucination degree value is greater than the first threshold value; or to determine that the output is a hallucination produced by the first language model when the second hallucination degree value is greater than the second threshold value. That is, the second language model is used alone to evaluate whether the output of the first language model is a hallucination and the first language model evaluates whether its own output is a hallucination.
[0050] All the above-mentioned optional technical solutions can be arbitrarily combined to form optional embodiments of the present application, which will not be described one by one here.
[0051] The following is an embodiment of the device of the present application, which can be used to execute the embodiment of the method of the present application. For details not disclosed in the embodiment of the device of the present application, please refer to the embodiment of the method of the present application.
[0052] Figure 3 Schematic diagram of a device for determining whether the output of a large language model is hallucination, provided in an embodiment of the present application. Figure 3 As shown, the device for determining whether the output of the large language model is hallucination includes:
[0053] The division module 301 is configured to obtain the output of the first language model, divide the output into a plurality of units having a sequence according to preset units, perform named entity recognition on each unit, and obtain a category of each unit, wherein the sequence of each unit is the position of the unit in the output;
[0054] A prediction module 302 is configured to predict the probability of generating a unit corresponding to each position of the output using the second language model, wherein the first language model and the second language model adopt different model architectures;
[0055] A first calculation module 303 is configured to calculate and output a corresponding first hallucination degree value based on each unit and its category and its corresponding probability;
[0056] A generating module 304 is configured to generate a plurality of questions according to the output and the category of each unit, answer each question using the first language model, and obtain an answer to each question;
[0057] A second calculation module 305 is configured to calculate a second hallucination degree value corresponding to the output based on the output and answers to each question;
[0058] The judgment module 306 is configured to judge whether the output is a hallucination generated by the first language model according to the first hallucination degree value and the second hallucination degree value.
[0059] According to the technical solution provided by the embodiment of the present application, the output of the first language model is obtained, the output is divided into a plurality of units with a sequence according to the preset units, and each unit is subjected to named entity recognition to obtain the category of each unit, wherein the sequence of each unit is the position of the unit in the output; the probability of generating the unit corresponding to the position at each position of the output is predicted by the second language model, wherein the first language model and the second language model adopt different model architectures; the first hallucination degree value corresponding to the output is calculated based on each unit and its category and its corresponding probability; multiple questions are generated according to the output and the category of each unit, and each question is answered using the first language model to obtain the answer to each question; the second hallucination degree value corresponding to the output is calculated based on the output and the answer to each question; and the output is judged whether it is a hallucination generated by the first language model according to the first hallucination degree value and the second hallucination degree value. The above technical means can solve the problem of low efficiency in detecting hallucinations of large language models in the prior art, thereby improving the efficiency of detecting hallucinations of large language models.
[0060] In some embodiments, the first calculation module 303 is also configured to calculate the correction value corresponding to each unit based on the probability corresponding to each unit; determine the first weight corresponding to each unit based on the category of each unit; calculate the uncertainty value corresponding to each unit based on the probability, correction value and first weight corresponding to each unit; determine the second weight corresponding to each unit based on each unit and its category; calculate the first hallucination degree value corresponding to the output based on the uncertainty value corresponding to each unit and the second weight.
[0061] In some embodiments, the first calculation module 303 is further configured to calculate the correction value corresponding to each unit according to the following formula:
[0062] ;
[0063] in, is the unit at the jth position of the output, is the probability corresponding to the unit at the jth position of the output, The base is 2 The logarithm of It is the correction value corresponding to the unit at the i-th position of the output.
[0064] You can set a dynamic weight function , according to the category of each unit, different weights between 0 and 1 are returned. For example, if it is part of a name, it is 0.9, if it is a date, it is 0.7, and so on.
[0065] In some embodiments, the first calculation module 303 is further configured to calculate the uncertainty value corresponding to each unit according to the following formula:
[0066] ;
[0067] in, is the probability corresponding to the unit at the ith position of the output, The base is 2 The logarithm of is the correction value corresponding to the unit at the ith position of the output, is the first weight corresponding to the unit at the ith position of the output, is the uncertainty value corresponding to the unit at the ith position of the output.
[0068] You can set a piecewise function p(x), if a unit is the core information in the output, the second weight corresponding to the unit is 1, otherwise it is 0. The core information in the output can be determined according to the category of each unit. For example, in an output "OpenAI's current CEO is Gates", the organization "OpenAI" and the name "Gates" are the core information.
[0069] In some embodiments, the first calculation module 303 is further configured to calculate and output the corresponding first hallucination degree value according to the following formula: :
[0070] ;
[0071] in, is the second weight corresponding to the unit at the jth position of the output, is the uncertainty value corresponding to the unit at the jth position in the output, and n is the number of all positions or units in the output.
[0072] There is one unit in one position in the output, so the number of all positions in the output is the same as the number of all units. The smaller the first hallucination degree value, the lower the probability that the output is a hallucination.
[0073] Multiple questions are generated based on the output and the categories of each unit. This is to ask questions about the more important categories in the output. For example, if an output is "OpenAI's current CEO is Gates", the following questions can be generated: "Who is OpenAI's current CEO?" and "Which company's current CEO is Gates?" The first language model answers each question and obtains the answer to each question.
[0074] In some embodiments, the second calculation module 305 is further configured to determine whether the answer to each question is consistent with the output to determine the score of the answer to each question; and calculate the second hallucination degree value corresponding to the output according to the score of the answer to each question.
[0075] If the answer to "Who is the current CEO of OpenAI" is "Gates", the score of the answer to this question is 1. If the answer to "Which company's current CEO is Gates" is "OpenAI", the score of the answer to this question is 1. If the answers to all questions are correct, the second illusion degree value corresponding to the output is 0. The smaller the first illusion degree value, the lower the probability that the output is an illusion. If the answer to a question is incorrect, the second illusion degree value corresponding to the output is 1.
[0076] In some embodiments, the judgment module 306 is further configured to perform a weighted summation of the first hallucination degree value and the second hallucination degree value to obtain a hallucination degree value; when the hallucination degree value is greater than a preset threshold, determine that the output is a hallucination generated by the first language model.
[0077] Corresponding weights can be assigned to the first hallucination degree value and the second hallucination degree value according to the accuracy of the second language model's historical evaluation that the output of the first language model is a hallucination and the accuracy of the first language model's historical evaluation that its own output is a hallucination. The first hallucination degree value and the second hallucination degree value are weighted and summed to obtain the hallucination degree value. When the hallucination degree value is greater than a preset threshold, it is determined that the output is a hallucination generated by the first language model, otherwise it is determined that the output is not a hallucination generated by the first language model.
[0078] It is also possible to determine that the output is a hallucination produced by the first language model when the first hallucination degree value is greater than the first threshold value; or to determine that the output is a hallucination produced by the first language model when the second hallucination degree value is greater than the second threshold value. That is, the second language model is used alone to evaluate whether the output of the first language model is a hallucination and the first language model evaluates whether its own output is a hallucination.
[0079] It should be understood that the sequence numbers of the steps in the above embodiments do not imply a sequence of execution. The execution sequence of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.
[0080] Figure 4 This is a schematic diagram of an electronic device 4 provided in an embodiment of the present application. Figure 4As shown, the electronic device 4 of this embodiment includes: a processor 401, a memory 402, and a computer program 403 stored in the memory 402 and capable of running on the processor 401. When the processor 401 executes the computer program 403, the steps in the above-mentioned method embodiments are implemented. Alternatively, when the processor 401 executes the computer program 403, the functions of each module / unit in the above-mentioned device embodiments are implemented.
[0081] The electronic device 4 may be a desktop computer, a notebook, a PDA, a cloud server, or other electronic device. The electronic device 4 may include, but is not limited to, a processor 401 and a memory 402. Those skilled in the art will appreciate that Figure 4 The electronic device 4 is merely an example and does not limit the electronic device 4 , which may include more or fewer components than those shown in the figure, or different components.
[0082] The processor 401 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc.
[0083] The memory 402 may be an internal storage unit of the electronic device 4, for example, a hard disk or memory of the electronic device 4. The memory 402 may also be an external storage device of the electronic device 4, for example, the electronic device 4 is equipped with a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc. The memory 402 may also include both an internal storage unit of the electronic device 4 and an external storage device. The memory 402 is used to store computer programs and other programs and data required by the electronic device.
[0084] Those skilled in the art can clearly understand that, for the convenience and simplicity of description, only the above-mentioned functional units and module divisions are used as examples for illustration. In practical applications, the above-mentioned functions can be assigned to different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. In the embodiment, each functional unit and module can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit, and the above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units.
[0085] If the integrated module / unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present application implements all or part of the process in the above-mentioned embodiment method, and can also be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium, and the computer program can implement the above-mentioned various method embodiment steps when executed by the processor. The computer program may include computer program code, and the computer program code may be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may include: any entity or device capable of carrying computer program code, recording medium, U disk, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electric carrier signal, telecommunication signal and software distribution medium. It should be noted that the content contained in the computer-readable medium can be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, the computer-readable medium does not include electric carrier signals and telecommunication signals.
[0086] The above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some of the technical features therein by equivalents. These modifications or replacements do not essentially deviate the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application, and should all be included in the protection scope of the present application.
Claims
1. A method for determining whether the output of a large language model is hallucination, characterized in that: include: Obtaining an output of the first language model, dividing the output into a plurality of units having a sequence according to preset units, performing named entity recognition on each unit to obtain a category of each unit, wherein the sequence of each unit is a position of the unit in the output; Predicting, using a second language model, the probability of generating a unit corresponding to the position at each position of the output, wherein the first language model and the second language model use different model architectures; Calculate a first hallucination degree value corresponding to the output based on each unit, its category and its corresponding probability; Generate multiple questions based on the output and the category of each unit, answer each question using the first language model, and obtain answers to each question; Calculating a second hallucination degree value corresponding to the output based on the output and answers to each question; determining whether the output is a hallucination generated by the first language model according to the first hallucination degree value and the second hallucination degree value; Wherein, calculating the first hallucination degree value corresponding to the output based on each unit, its category and its corresponding probability includes: calculating the correction value corresponding to each unit based on the probability corresponding to each unit; determining the first weight corresponding to each unit based on the category of each unit; calculating the uncertainty value corresponding to each unit based on the probability, correction value and first weight corresponding to each unit; determining the second weight corresponding to each unit based on each unit and its category; calculating the first hallucination degree value corresponding to the output based on the uncertainty value and the second weight corresponding to each unit; Wherein, calculating the second illusion degree value corresponding to the output based on the output and the answers to each question includes: judging whether the answer to each question is consistent with the output to determine the score of the answer to each question; and calculating the second illusion degree value corresponding to the output according to the score of the answer to each question.
2. The method according to claim 1, characterized in that: Calculate the correction value corresponding to each unit according to the following formula: ; in, is the unit at the jth position of the output, is the probability corresponding to the unit at the jth position of the output, The base is 2 The logarithm of is the correction value corresponding to the unit at the ith position of the output.
3. The method according to claim 1, characterized in that: Calculate the uncertainty value corresponding to each unit according to the following formula: ; in, is the probability corresponding to the unit at the ith position of the output, The base is 2 The logarithm of is the correction value corresponding to the unit at the ith position of the output, is the first weight corresponding to the unit at the ith position of the output, is the uncertainty value corresponding to the unit at the ith position of the output.
4. The method according to claim 1, characterized in that: The first hallucination degree value corresponding to the output is calculated according to the following formula : ; in, is the second weight corresponding to the unit at the jth position of the output, is the uncertainty value corresponding to the unit at the j-th position of the output, and n is the number of all positions or units in the output.
5. The method according to claim 1, characterized in that: Judging whether the output is a hallucination generated by the first language model according to the first hallucination degree value and the second hallucination degree value includes: Taking a weighted sum of the first hallucination degree value and the second hallucination degree value to obtain a hallucination degree value; When the hallucination degree value is greater than a preset threshold, it is determined that the output is a hallucination generated by the first language model.
6. A device for determining whether the output of a large language model is hallucination, characterized in that: include: a division module configured to obtain an output of the first language model, divide the output into a plurality of units having a sequence according to preset units, perform named entity recognition on each unit, and obtain a category of each unit, wherein the sequence of each unit is a position of the unit in the output; a prediction module, configured to predict, using a second language model, a probability of generating a unit corresponding to the position at each position of the output, wherein the first language model and the second language model adopt different model architectures; A first calculation module is configured to calculate a first hallucination degree value corresponding to the output based on each unit and its category and its corresponding probability; A generation module is configured to generate a plurality of questions according to the output and the category of each unit, and answer each question using the first language model to obtain an answer to each question; A second calculation module is configured to calculate a second hallucination degree value corresponding to the output based on the output and answers to each question; a judging module configured to judge whether the output is a hallucination generated by the first language model according to the first hallucination degree value and the second hallucination degree value; The first calculation module is further configured to calculate the correction value corresponding to each unit based on the probability corresponding to each unit; determine the first weight corresponding to each unit based on the category of each unit; calculate the uncertainty value corresponding to each unit based on the probability, correction value and first weight corresponding to each unit; determine the second weight corresponding to each unit based on each unit and its category; calculate the first hallucination degree value corresponding to the output based on the uncertainty value and the second weight corresponding to each unit; The second calculation module is further configured to determine whether the answer to each question is consistent with the output to determine the score of the answer to each question; and calculate the second hallucination degree value corresponding to the output according to the score of the answer to each question.
7. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 5 are implemented.
8. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 5 are implemented.
Citation Information
Cited By
System for monitoring and intervening large model to generate illusion content in real time
CN119357759A
A System for Real-time Monitoring and Intervention of Hallucination Content Generated by Large Language Models
CN119357759B
