A method and system for alleviating large language model hallucination

By calculating the cross-layer prediction distribution entropy of candidate words in large language models and correcting the prediction probability, the hallucination phenomenon when large language models generate text is solved, and more refined and reliable decoding enhancement is achieved, which is suitable for a variety of model bases.

CN119149718BActive Publication Date: 2025-02-25BEIJING WISPIRIT TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411662715.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-11-20
Publication Date
2025-02-25
Estimated Expiration
2044-11-20

AI Technical Summary

Technical Problem

Large language models may produce logically reasonable but untenable answers when generating text, leading to hallucinations, especially in key areas such as law, where existing technologies fail to fundamentally solve this problem.

Method used

By obtaining multiple candidate words at each time step in the large language model, the entropy of the cross-layer prediction distribution of each candidate word is calculated, and based on this, the candidate word with the highest correction probability is output as the final output result.

Benefits of technology

This method can more precisely analyze the predicted probability changes of large language models, enhance factual probability, reduce the occurrence of hallucinations, and has high generalization without additional model training.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119149718B_ABST
    Figure CN119149718B_ABST
Patent Text Reader

Abstract

The present invention discloses a method and system for alleviating the hallucination of a large language model. The method comprises the following steps: obtaining multiple candidate words at the t-th time step in the large language model; obtaining the prediction probability of the high-level neural network in each layer of the large language model for each candidate word; normalizing the prediction probability of the high-level neural network in each layer of the large language model for each candidate word to form a cross-layer prediction distribution, and calculating the entropy of the cross-layer prediction distribution as the cross-layer entropy of each candidate word; based on the cross-layer entropy of each candidate word, correcting the initial prediction probability of each candidate word at the t-th time step to obtain the corrected probability of each candidate word at the t-th time step; outputting the candidate word with the highest value of the corrected probability as the output result corresponding to the t-th time step. By using the present invention, the output hallucination of the large language model can be effectively eliminated.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to a method for alleviating large language model hallucination, and also relates to a system for alleviating large language model hallucination, belonging to the technical field of natural language processing. Background Art

[0002] Large Language Models (LLMs) are a class of natural language processing models with large-scale parameters and computing power. They can understand and generate natural language through deep learning and natural language processing techniques. These models learn a wide range of contexts and language structures during the pre-training phase, allowing them to achieve efficient natural language generation and understanding in downstream tasks. LLMs have a wide range of applications, including but not limited to text summarization, question-answering systems, machine translation, etc. They are profoundly changing the e-commerce industry and providing the possibility of a series of innovative applications from customer service to personalized recommendations.

[0003] However, large language models also face challenges in application, especially the so-called "hallucination" problem. This refers to the fact that when a large language model generates text, it may produce answers that seem logical but are actually untenable. This phenomenon is particularly evident in legal language model applications, where the answers given by the model may be biased or based on incorrect reasoning, resulting in a large amount of false information. Most current solutions rely on the training data of large language models, but fail to fundamentally solve the problem of hallucinations. To address this challenge, researchers are exploring how to detect and reduce hallucinations, such as by providing external knowledge and increasing the number of reasoning steps to enhance the ability of large language models to detect hallucinations. In addition, there are studies focusing on building benchmark datasets for detecting and evaluating large language model hallucinations, such as the HaluEval dataset. These efforts aim to improve the reliability and accuracy of large language models so that they can be more widely used in key fields such as law and medicine. Summary of the invention

[0004] The primary technical problem to be solved by the present invention is to provide a method for alleviating the large language model hallucination.

[0005] Another technical problem to be solved by the present invention is to provide a system for alleviating the large language model hallucination.

[0006] In order to achieve the above technical objectives, the present invention adopts the following technical solutions:

[0007] According to a first aspect of an embodiment of the present invention, a method for alleviating large language model hallucination is provided, comprising the following steps:

[0008] Get multiple candidate words at the t-th time step in the large language model, where t is a positive integer;

[0009] For each candidate word, obtain the prediction probability of each layer of the high-level neural network of the large language model;

[0010] For the candidate words, normalizing the prediction probabilities of the high-level neural networks in each layer of the large language model so that the sum of the probabilities is 1, thereby forming a cross-layer prediction distribution for the candidate words;

[0011] Based on the cross-layer prediction distribution of the candidate word, calculating the entropy of the cross-layer prediction distribution as the cross-layer entropy of the candidate word;

[0012] Based on the cross-layer entropy of the candidate word, the initial prediction probability of the candidate word at the t-th time step is corrected to obtain a corrected probability of the candidate word at the t-th time step;

[0013] According to the revised probability of each candidate word at the t-th time step in the large language model, the candidate word with the highest revised probability value is output as the output result corresponding to the t-th time step.

[0014] Preferably, the method further comprises:

[0015] Let t = t + 1 to obtain the output result corresponding to the t + 1th time step;

[0016] The above process is repeated, and the output results corresponding to each time step are sorted in chronological order, so as to output the final answer result of the large language model.

[0017] Preferably, for each candidate word, the prediction probability of each middle and high-level neural network layer of the large language model is obtained, specifically including:

[0018] Get the candidate word in the selected level range of the large language model Each layer of the neural network The predicted output ; Wherein, i represents the i-th layer of the neural network of the large language model, and Layer represents the level range corresponding to the middle and high-level neural networks of the large language model;

[0019] Use the softmax function for each layer of the neural network The predicted output Perform probability transformation to obtain each layer of neural network The predicted probability .

[0020] Preferably, the cross-layer prediction distribution of the candidate words is formed by the following steps:

[0021] Based on each layer of neural network The predicted probability Perform normalization processing to obtain the normalized probability of the i-th layer neural network of the large language model ;

[0022] in, ;

[0023] Based on the normalized probability of each layer of the neural network within the selected level range of the large language model, a cross-layer prediction distribution of the candidate words is formed.

[0024] Preferably, the entropy of the cross-layer prediction distribution is calculated using the following formula: :

[0025] .

[0026] Preferably, the revised probability of the candidate word at the tth time step is obtained by the following steps:

[0027] Get the initial prediction probability of the candidate word at the tth time step ;in, = , i is the last layer of neural network in the selected level range of the large language model;

[0028] Introduce a cross-layer entropy correction term in the form of exponential power to correct the initial prediction probability Make corrections to form the correction probability of the candidate word at the tth time step ;

[0029] in, ; e represents the exponential function operation; λ represents the adjustment coefficient, which is used to control the degree of correction of the initial prediction probability.

[0030] Preferably, multiple candidate words at the t-th time step in the large language model are obtained, specifically including:

[0031] Obtain a candidate word list at the t-th time step in the large language model, wherein the candidate word list includes multiple candidate words with different initial prediction probabilities; wherein the initial prediction probability is a probability value output by the candidate word in the last layer of the neural network;

[0032] Select the probability value of the highest probability candidate word from the candidate word list;

[0033] Setting α times the probability value of the highest probability candidate word as a threshold; wherein α is set to 0.001 to 0.1;

[0034] According to the threshold, candidate words with probability values ​​higher than the threshold are screened out from the candidate word list as multiple candidate words at the t-th time step in the large language model.

[0035] According to a second aspect of an embodiment of the present invention, a system for alleviating large language model hallucination is provided, comprising:

[0036] A data acquisition unit, used to acquire multiple candidate words at the t-th time step in the large language model;

[0037] A probability conversion unit connected to the data acquisition unit to obtain, for each candidate word, a prediction probability of a high-level neural network in each layer of the large language model;

[0038] A cross-layer distribution unit, connected to the probability conversion unit, normalizes the prediction probabilities of the high-level neural networks in each layer of the large language model for the candidate word so that the sum of the probabilities is 1, thereby forming a cross-layer prediction distribution for the candidate word w;

[0039] a calculation unit connected to the cross-layer distribution unit to calculate the entropy of the cross-layer prediction distribution as the cross-layer entropy of the candidate word based on the cross-layer prediction distribution of the candidate word;

[0040] a correction unit connected to the calculation unit to correct the initial prediction probability of the candidate word at the t-th time step based on the cross-layer entropy of the candidate word to obtain a corrected probability of the candidate word at the t-th time step;

[0041] The output unit is connected to the correction unit to output the candidate word with the highest correction probability value as the output result corresponding to the tth time step according to the correction probability of each candidate word in the large language model at the tth time step.

[0042] According to a third aspect of an embodiment of the present invention, a system for alleviating large language model hallucinations is provided, comprising a processor and a memory, wherein the processor and the memory are coupled; wherein the memory is used to store a computer program; and the processor is used to run the computer program stored in the memory to execute the above-mentioned method for alleviating large language model hallucinations.

[0043] Compared with the prior art, the present invention has the following technical effects:

[0044] (1) Vertically collect the prediction probabilities of each layer of the high-level neural network in the large language model, globally analyze the changes in internal predictions, fully capture the changes in prediction probabilities within the large language model, and avoid accidental occurrences as much as possible.

[0045] (2) The enhancement of entropy starts from the granularity of candidate words, rather than directly comparing an entire layer. Even if the selected layer cannot highlight the factuality of each candidate word in the decoding at this time step, since the changes of each candidate word between layers are inconsistent, therefore, performing cross-layer prediction analysis on each candidate word separately can enhance the probability of factuality in a finer granularity, thereby achieving more refined and reliable decoding enhancement.

[0046] (3) No additional model training is required. It can be directly inserted into the Transformer architecture as an optional decoding algorithm. It is plug-and-play and has high generalization ability, effectively improving the effectiveness on a variety of model bases.

[0047] (4) In the open generation of long texts, a threshold is set to limit the range of candidate words, and only candidate words with probability values ​​higher than this threshold are selected from the vocabulary to form a set of head candidate words. Therefore, by calculating the cross-layer entropy and correcting the generation probability only for the candidate words within the set of head candidate words, the computational cost is greatly reduced and a considerable inference rate is maintained. BRIEF DESCRIPTION OF THE DRAWINGS

[0048] Figure 1 A flowchart of a method for alleviating large language model hallucination provided by the first embodiment of the present invention;

[0049] Figure 2 This is a schematic diagram of the prediction probability of the 32-layer large language model for the candidate words A / B / C / D at a certain time step in the first embodiment of the present invention;

[0050] Figure 3 Schematic diagram of cross-layer entropy of each candidate word in the first embodiment of the present invention;

[0051] Figure 4 It is a schematic diagram of correction by cross-layer entropy of each candidate word in the first embodiment of the present invention;

[0052] Figure 5 A flowchart of a method for alleviating large language model hallucination provided by the second embodiment of the present invention;

[0053] Figure 6 A structural diagram of a system for alleviating large language model hallucination provided by a third embodiment of the present invention;

[0054] Figure 7 A structural diagram of a system for alleviating large language model hallucination provided in a fourth embodiment of the present invention. DETAILED DESCRIPTION

[0055] The technical content of the present invention is described in detail below with reference to the accompanying drawings and specific embodiments.

[0056] After research, we found that when the large language model generates grammatical functional vocabulary and copies question input words, its prediction probability is determined before the middle neural network layer of the large language model, and remains unchanged in the high-level neural network until the output of the last layer. However, for factual knowledge vocabulary such as important noun entities or dates, the prediction probability of the large language model will change greatly in the high-level neural network, indicating that the large language model gradually incorporates more factual information in later reasoning. Therefore, by measuring the degree of change in the prediction probability of candidate words within the high-level of the large language model, the factual information contained in it can be inferred. Using this factual information as an auxiliary gain term can enhance the decoding ability of the large language model and improve the output of factual information by the large language model, thereby reducing the phenomenon of hallucination.

[0057] Based on the above theoretical basis, an embodiment of the present invention provides a method for alleviating the hallucination of a large language model. This method is based on the hidden state inside the large language model and focuses on the degree of change in the cross-layer prediction probability of candidate words. Specifically, by capturing the change in the prediction probability of candidate words between different neural network layers, cross-layer entropy can be used to measure the factual knowledge contained in each candidate word during the generation process. This method uses the factual knowledge of candidate words as a gain indicator to assist the decoding process of the large language model, thereby improving the prediction probability of knowledge candidate words, enabling the large language model to generate more realistic and accurate content and reduce the occurrence of hallucinations. Another significant advantage of this method is that it does not require additional training of the large language model. It can be directly integrated into the Transformer architecture as a plug-and-play module as an optional decoding algorithm. This modular design makes the method highly generalizable and can effectively improve performance on a variety of different model bases.

[0058] First embodiment

[0059] like Figure 1 As shown, a method for alleviating large language model hallucination provided by the first embodiment of the present invention specifically includes the following steps:

[0060] S1: Get multiple candidate words at the t-th time step in the large language model.

[0061] It should be noted that for a question, the large language model needs to go through at least one time step of logical operations to output the final answer result. Among them, if the answer result is a single word, the answer result can be output after only one time step. If the answer result is a sentence composed of multiple words, the output results of multiple time steps need to be sorted in chronological order before the answer result can be obtained.

[0062] In this embodiment, a time step is used as a benchmark, and the output result of the time step is corrected to improve the accuracy of the output result at the time step. Similarly, when the accuracy of the output result at each time step is improved, the accuracy of the overall answer result of the large language model will be significantly improved.

[0063] Based on this, in step S1, this embodiment needs to first obtain multiple candidate words at the t-th time step in the large language model; wherein t is a positive integer.

[0064] Specifically, in this embodiment, multiple candidate words at the t-th time step in the large language model are obtained through the following steps:

[0065] S11: Obtain the candidate word list X at the t-th time step in the large language model.

[0066] The candidate word list X includes multiple candidate words w with different initial prediction probabilities. The initial prediction probability is the probability value of the candidate word w output by the last layer of the neural network.

[0067] S12: Select the probability value corresponding to the candidate word w with the highest initial prediction probability from the candidate word list .

[0068] S13: The probability value corresponding to the candidate word with the highest initial prediction probability α times of is set as the threshold; wherein α is set to 0.001~0.1.

[0069] S14: According to the threshold, candidate words with probability values ​​higher than the threshold are screened out from the candidate word list as multiple candidate words for the t-th time step in the large language model.

[0070] It can be understood that the method proposed in this embodiment is a low-cost and lightweight decoding enhancement method. Therefore, in order to further improve the ease of use and reasoning efficiency of the method, in the open generation scenario of long text, this embodiment sets a threshold to limit the range of candidate words w, and only selects candidate words with probability values ​​higher than this threshold in the vocabulary, thereby forming a set of head candidate words. .

[0071] in, .

[0072] Therefore, only the cross-layer entropy is calculated for the candidate words within the range and the generation probability is corrected, which greatly reduces the calculation cost and maintains a considerable inference rate. As for other candidate words, since their original generation probability is much lower than that of the head candidate words, there is no need to correct them and they are directly used as the final output probability, which will not affect the final output result.

[0073] S2: For each candidate word w, form a cross-layer prediction distribution for the candidate word w.

[0074] Specifically, the following steps are included:

[0075] S21: Select any candidate word and obtain the prediction probability of the high-level neural network in each layer of the large language model for the candidate word.

[0076] At present, large language models usually contain different numbers of layers, such as 32 layers, 40 layers, and 72 layers. For these large language models, the definition of medium and high-level neural networks will vary according to the total number of layers: specifically, the medium and high-level neural networks of the 32-layer model refer to the 16th to 32nd layers; the medium and high-level neural networks of the 40-layer model refer to the 20th to 40th layers; and the medium and high-level neural networks of the 72-layer model refer to the 48th to 72nd layers. In addition, according to the specific number of layers of different large language models, the division of medium and high-level neural networks can also be specially set accordingly, for example: more than 1 / 2 of the total number of layers are medium and high-level neural networks.

[0077] Furthermore, it should be noted that the prediction probability of each layer of the high-level neural network here is not the same as the concept of the initial prediction probability in the above step S1. The initial prediction probability in step S1 is only the prediction probability of the last layer of the neural network, while the prediction probability of each layer of the high-level neural network here refers to a series of continuous prediction probabilities starting from the middle layer to the last layer.

[0078] Specifically, first, obtain the candidate words in the selected level range of the large language model Each layer of the neural network The predicted output . Among them, i represents the i-th layer of the neural network of the large language model, and Layer represents the level range corresponding to the middle and high-level neural networks of the large language model.

[0079] Then, the softmax function is used to adjust each layer of the neural network The predicted output Perform probability transformation to obtain each layer of neural network The predicted probability It can be understood that when i is the last layer of the large language model, then This corresponds to the initial prediction probability for the candidate word w in the above step S1.

[0080] S22: Normalize the prediction probabilities of the high-level neural networks in each layer of the large language model so that the sum of the probabilities is 1, thereby forming a cross-layer prediction distribution for the candidate word w.

[0081] Specifically, based on each layer of the neural network The predicted probability Normalization is performed to obtain the normalized probability of the i-th layer neural network of the large language model ;

[0082] in, .

[0083] After obtaining the normalized probability of each layer of the neural network within the selected level of the large language model, the cross-layer prediction distribution of the candidate words can be constructed.

[0084] S23: Repeat the above steps S21 to S23 to obtain the cross-layer prediction distribution corresponding to each candidate word w.

[0085] S3: For each candidate word w, calculate the entropy of the cross-layer prediction distribution as the cross-layer entropy of the candidate word w.

[0086] Specifically, the entropy of the cross-layer prediction distribution is calculated using the following formula: :

[0087] .

[0088] It can be understood that each candidate word w corresponds to a cross-layer prediction distribution, that is, each candidate word w corresponds to a cross-layer entropy.

[0089] S4: For each candidate word w, the initial prediction probability is modified based on the respective cross-layer entropy.

[0090] Specifically, after the cross-layer entropy of each candidate word w is calculated based on the above step S3, a cross-layer entropy correction term is introduced in the form of exponential power to correct the initial prediction probability Make corrections to form the correction probability of the candidate word at the tth time step .

[0091] in, = , where i is the last layer of the neural network in the selected level range of the large language model.

[0092] ; e represents the exponential function operation; λ represents the adjustment coefficient, which is used to control the degree of correction of the initial prediction probability.

[0093] S5: Output the output result corresponding to the tth time step.

[0094] Specifically, after the correction probability of each candidate word is calculated based on step S4, the candidate word with the highest correction probability value is selected as the output result corresponding to the t-th time step.

[0095] It is understandable that, through the correction of cross-layer entropy, the initial prediction probability of each candidate word will be lowered to varying degrees due to the amount of internal knowledge it possesses. Based on the adjusted candidate word generation probability (i.e., the corrected probability), the model decoder will select words with both high prediction output probability and high knowledge information as the final output words, thereby preventing the large language model from inertially outputting non-knowledge content and low-knowledge content, thereby reducing the output of irrelevant sentences and incorrect knowledge-based answers.

[0096] The method provided in the first embodiment of the present invention is described in detail below with reference to examples:

[0097] like Figure 2 As shown in the figure, the predicted probability of candidate words A / B / C / D for a 32-layer large language model at a certain time step. Figure 2 Only the probability values ​​of some layers are shown, but in fact, they are the predicted probabilities of candidate words A / B / C / D for each layer from 16 to 32. And for each candidate word, the predicted probability is extracted layer by layer to form a line distribution.

[0098] like Figure 3 As shown in the figure, according to the line division of each candidate word, the cross-layer prediction distribution of each candidate word is formed through the normalized standard processing. Among them, the low-knowledge candidate word A with a stable prediction probability change has a large uncertainty in its cross-layer prediction distribution, and thus has a large cross-layer entropy. The high-knowledge candidate word D with a steeper prediction probability change has a small uncertainty in its cross-layer prediction distribution and a small cross-layer entropy. Therefore, the cross-layer entropy is used as an indicator to enhance the decoding part of the large language model.

[0099] like Figure 4 As shown in the figure, based on the cross-layer entropy corresponding to the four candidate words A / B / C / D, the prediction distribution of the last layer of the neural network is corrected respectively to form the final prediction distribution. From the final prediction distribution, it can be seen that although the probability value of candidate word A is the highest in the initial prediction result, after correction, the corrected probability of candidate word A is lower than that of candidate word D. Therefore, candidate word D is used as the final output result.

[0100] Second embodiment

[0101] like Figure 5 As shown, based on the above first embodiment, the second embodiment of the present invention further provides a method for alleviating the large language model hallucination. In addition to steps S1 to S5 in the first embodiment, the method further includes the following steps:

[0102] S6: Time step judgment.

[0103] If the current time step is the last step, execute step S8; if the current time step is not the last step, execute step S7.

[0104] S7: Let t=t+1 to obtain the output result corresponding to the t+1th time step.

[0105] Specifically, after the correction of the output result of the t-th time step is completed, the above process S1 to S5 is repeated to correct the output result of the next time step again, so as to obtain the output result corresponding to the t+1-th time step.

[0106] S8: Output the final answer of the large language model.

[0107] Specifically, the output results corresponding to each time step are sorted in chronological order to output the final answer result of the large language model.

[0108] Third embodiment

[0109] like Figure 6 As shown, a system for alleviating large language model hallucination provided by the third embodiment of the present invention includes a data acquisition unit 1, a probability conversion unit 2, a cross-layer distribution unit 3, a calculation unit 4, a correction unit 5 and an output unit 6. Among them,

[0110] The data acquisition unit 1 is used to obtain multiple candidate words at the t-th time step in the large language model.

[0111] The probability conversion unit 2 is connected to the data acquisition unit 1 to obtain the prediction probability of the high-level neural network in each layer of the large language model for each candidate word.

[0112] The cross-layer distribution unit 3 is connected to the probability conversion unit 2 to normalize the prediction probability of the high-level neural network in each layer of the large language model for the candidate word so that the sum of the probabilities is 1, thereby forming a cross-layer prediction distribution for the candidate word w.

[0113] The calculation unit 4 is connected to the cross-layer distribution unit 3 to calculate the entropy of the cross-layer prediction distribution as the cross-layer entropy of the candidate word based on the cross-layer prediction distribution of the candidate word.

[0114] The correction unit 5 is connected to the calculation unit 4 to correct the initial prediction probability of the candidate word at the tth time step based on the cross-layer entropy of the candidate word to obtain the corrected probability of the candidate word at the tth time step.

[0115] The output unit 6 is connected to the correction unit 5 to output the candidate word with the highest correction probability value as the output result corresponding to the tth time step according to the correction probability of each candidate word at the tth time step in the large language model.

[0116] It can be understood that the above-mentioned data acquisition unit 1, probability conversion unit 2, cross-layer distribution unit 3, calculation unit 4, correction unit 5 and output unit 6 are module structures corresponding to the above-mentioned steps S1~S5, so as to implement the above-mentioned S1~S5 operations, wherein the specific composition of the module is not elaborated here, it is only necessary to satisfy the above-mentioned functions.

[0117] Fourth embodiment

[0118] like Figure 7 As shown, based on the above-mentioned first embodiment, the fourth embodiment of the present invention further provides a system for alleviating the large language model hallucination. The system includes one or more processors and a memory. Among them, the memory is coupled to the processor and is used to store one or more programs. When the one or more programs are executed by the one or more processors, the one or more processors implement the method for alleviating the large language model hallucination as in the above-mentioned embodiment.

[0119] Among them, the processor is used to control the overall operation of the system to complete all or part of the steps of the above-mentioned method for alleviating the hallucination of a large language model. The processor can be a central processing unit (CPU), a graphics processing unit (GPU), a field programmable gate array (FPGA), an application-specific integrated circuit (ASIC), a digital signal processing (DSP) chip, etc. The memory is used to store various types of data to support operations in the system, which may include, for example, instructions for any application or method operating on the system, and application-related data. The memory can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, etc.

[0120] In an exemplary embodiment, the system can be implemented by a computer chip or entity, or by a product with a certain function, for executing the above-mentioned method for alleviating the large language model hallucination, and achieving the technical effect consistent with the above-mentioned method. A typical embodiment is a computer. Specifically, the computer can be, for example, a personal computer, a laptop computer, a vehicle-mounted human-computer interaction device, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or a combination of any of these devices.

[0121] In another exemplary embodiment, the present invention further provides a computer-readable storage medium including program instructions, which, when executed by a processor, implements the steps of the method for alleviating the large language model hallucination in any of the above embodiments. For example, the computer-readable storage medium may be the above-mentioned memory including program instructions, and the above-mentioned program instructions may be executed by a processor of the system to complete the above-mentioned method for alleviating the large language model hallucination, and achieve the technical effect consistent with the above-mentioned method.

[0122] In summary, the method and system for alleviating the large language model hallucination provided by the embodiments of the present invention have the following beneficial effects:

[0123] (1) Vertically collect the prediction probabilities of each layer of the high-level neural network in the large language model, globally analyze the changes in internal predictions, fully capture the changes in prediction probabilities within the large language model, and avoid accidental occurrences as much as possible.

[0124] (2) The enhancement of entropy starts from the granularity of candidate words, rather than directly comparing an entire layer. Even if the selected layer cannot highlight the factuality of each candidate word in the decoding at this time step, since the changes of each candidate word between layers are inconsistent, therefore, performing cross-layer prediction analysis on each candidate word separately can enhance the probability of factuality in a finer granularity, thereby achieving more refined and reliable decoding enhancement.

[0125] (3) No additional model training is required. It can be directly inserted into the Transformer architecture as an optional decoding algorithm. It is plug-and-play and has high generalization ability, effectively improving the effectiveness on a variety of model bases.

[0126] (4) In the open generation of long texts, a threshold is set to limit the range of candidate words, and only candidate words with probability values ​​higher than this threshold are selected from the vocabulary to form a set of head candidate words. Therefore, by calculating the cross-layer entropy and correcting the generation probability only for the candidate words within the set of head candidate words, the computational cost is greatly reduced and a considerable inference rate is maintained.

[0127] It should be noted that the above embodiments are only examples, and the technical solutions of the various embodiments can be combined, all within the protection scope of the present invention.

[0128] In addition, the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Therefore, the features defined as "first" and "second" may explicitly or implicitly include one or more of the features. In the description of the present invention, the meaning of "plurality" is two or more, unless otherwise clearly and specifically defined.

[0129] The above is a detailed description of the method and system for alleviating the large language model hallucination provided by the present invention. For those skilled in the art, any obvious changes made to it without departing from the essence of the present invention will constitute an infringement of the patent right of the present invention and will bear corresponding legal responsibilities.

Claims

1. A method for alleviating large language model hallucination, characterized in that The steps include: Obtain a candidate word list at the t-th time step in the large language model, wherein the candidate word list includes multiple candidate words with different initial prediction probabilities, and the initial prediction probability is a probability value of the candidate word output by the last layer of the neural network; Select the probability value of the highest probability candidate word from the candidate word list; Setting α times the probability value of the highest probability candidate word as a threshold; According to the threshold, candidate words with probability values ​​higher than the threshold are screened out from the candidate word list as multiple candidate words at the t-th time step in the large language model, where t is a positive integer; For each candidate word, obtain the candidate word in the selected level range of the large language model Each layer of the neural network The predicted output ; Wherein, i represents the i-th layer of the neural network of the large language model, and Layer represents the level range corresponding to the middle and high-level neural networks of the large language model; Use the softmax function for each layer of the neural network The predicted output Perform probability conversion to obtain the prediction probability of the high-level neural network in each layer of the large language model ; For the candidate words, the prediction probability of the high-level neural network in each layer of the large language model is Performing normalization processing; forming a cross-layer prediction distribution of the candidate words based on the normalized probability of each layer of the neural network within the selected level range of the large language model; Based on the cross-layer prediction distribution of the candidate word, the entropy of the cross-layer prediction distribution is calculated As the cross-layer entropy of the candidate word; Based on the cross-layer entropy of the candidate word, obtain the initial prediction probability of the candidate word at the tth time step ; Introduce a cross-layer entropy correction term in the form of exponential power to correct the initial prediction probability Correction is performed to obtain the corrected probability of the candidate word at the tth time step ;in, = ; ; e represents exponential function operation; λ represents the adjustment coefficient, which is used to control the degree of correction of the initial prediction probability; According to the revised probability of each candidate word at the t-th time step in the large language model, the candidate word with the highest revised probability value is output as the output result corresponding to the t-th time step.

2. The method according to claim 1, characterized in that Also includes: Let t = t + 1 to obtain the output result corresponding to the t + 1th time step; The above process is repeated, and the output results corresponding to each time step are sorted in chronological order, so as to output the final answer result of the large language model.

3. The method according to claim 1, characterized in that: The α is 0.001 to 0.

1.

4. The method according to claim 1, characterized in that The following formula is used to obtain the normalized probability of the i-th layer neural network of the large language model: : 。 5. The method according to claim 1, characterized in that The entropy of the cross-layer prediction distribution is calculated using the following formula: As the cross-layer entropy of the candidate word: 。 6. A system for alleviating large language model hallucination, used to implement the method for alleviating large language model hallucination as described in any one of claims 1 to 5, characterized in that include: A data acquisition unit, used to acquire multiple candidate words at the t-th time step in the large language model, where t is a positive integer; A probability conversion unit connected to the data acquisition unit to obtain, for each candidate word, a prediction probability of a high-level neural network in each layer of the large language model; A cross-layer distribution unit connected to the probability conversion unit is used to normalize the prediction probabilities of the high-level neural networks in each layer of the large language model for the candidate words so that the sum of the probabilities is 1, thereby forming a cross-layer prediction distribution for the candidate words; a calculation unit connected to the cross-layer distribution unit to calculate the entropy of the cross-layer prediction distribution as the cross-layer entropy of the candidate word based on the cross-layer prediction distribution of the candidate word; a correction unit connected to the calculation unit to correct the initial prediction probability of the candidate word at the t-th time step based on the cross-layer entropy of the candidate word to obtain a corrected probability of the candidate word at the t-th time step; The output unit is connected to the correction unit to output the candidate word with the highest correction probability value as the output result corresponding to the tth time step according to the correction probability of each candidate word in the large language model at the tth time step.

7. A system for alleviating large language model hallucinations, characterized in that The invention comprises a processor and a memory, wherein the processor and the memory are coupled; wherein the memory is used to store a computer program; and the processor is used to run the computer program stored in the memory to execute the method for alleviating the large language model hallucination as described in any one of claims 1 to 5.

Citation Information

Patent Citations

  • Text information extraction method based on large language model and efficient parameter fine tuning

    CN118132674A

  • Optimization method and device of large language model, electronic equipment and storage medium

    CN118364870A