Method and device for alleviating hallucinations based on false premises
By identifying and weakening the influential attention heads in large language models, the problem of the model generating hallucinatory text when facing error conditions is solved, and the accuracy and reliability of model output is improved.
Patent Information
- Application Number
- CN202510008081.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-03
- Publication Date
- 2025-04-29
- Estimated Expiration
- 2045-01-03
AI Technical Summary
When facing problems based on error premises, large language models tend to generate hallucinatory text consistent with error premises, resulting in a decrease in user interaction quality and misleading information.
By obtaining the input text containing the error premise and its masked version, the activation value of each attention header during processing of the large language model is recorded separately. Then, the target attention head with greater influence is determined and weakened by constraint functions to reduce the tendency of the generation of hallucinations text.
Without sacrificing the overall performance of the model, it effectively reduces the tendency of the model to generate hallucinatory text when facing error prerequisites, thereby improving the accuracy and reliability of model output.
Smart Images

Figure CN119398181B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of natural language processing, and in particular to a method and device for alleviating hallucinations caused by false premises. Background Art
[0002] Although large language models have demonstrated extremely outstanding and impressive performance in many task areas, in the process of performing text generation tasks, there are inevitably situations where they deviate from the source of factual knowledge, which is the widely recognized "hallucination problem". Specifically, the hallucination problem refers to the fact that the text produced by large language models appears to be reasonable and logical on the surface, but in-depth exploration will reveal that it is significantly different from or even completely contrary to the known factual information.
[0003] It is particularly noteworthy that when a large language model faces a problem situation built on a false premise, even if the model parameter system has already fully stored the factual knowledge elements related to the problem, it still tends to generate hallucinatory text that is highly consistent with the false premise. This special phenomenon is also accurately defined as the "false assumption hallucination" in the professional field.
[0004] For example, take the question “For what specific reason did Albert Einstein win the 1920 Nobel Prize in Physics?”, when in fact Einstein won the prize in 1921. Large language models can accurately respond to direct inquiries about the year of the prize, but when faced with questions containing false premises, they will generate hallucinated text: “Albert Einstein won the 1920 Nobel Prize in Physics for his explanation of the photoelectric effect…”.
[0005] This phenomenon directly affects the quality of user interaction with large language models. If the model cannot identify and correct these false premises, it will generate misleading information in various application scenarios, which in turn affects user decisions and behaviors. Summary of the invention
[0006] The present invention provides a method and device for alleviating hallucinations of false premises, so as to solve the problem that a large language model tends to generate hallucinatory texts that are highly consistent with the false premises when facing a problem situation constructed based on the false premises.
[0007] The present invention provides a method for alleviating hallucinations of false premises, comprising: obtaining a first input text and a second input text, wherein the second input text is a text in which the false premise in the first input text is replaced with a placeholder; respectively determining a first activation value of each attention head when a large language model processes the first input text, and a second activation value of each attention head when processing the second input text; determining the influence of each attention head on a hallucination text output by the large language model according to a target processing method; determining a target attention head based on the influence, and weakening the target attention head; wherein the target processing method is: replacing the activation value of the first attention head of the large language model from the first activation value to the second activation value, freezing the activation values of other attention heads, and performing forward propagation based on the first input text to determine the influence of the first attention head on the hallucination text output by the large language model.
[0008] According to a method for alleviating hallucinations of false premises provided by the present invention, the first activation value of each attention head when the large language model processes the first input text, and the second activation value of each attention head when processing the second input text, respectively, include: performing forward propagation of the large language model based on the first input text, and recording the activation status of all attention heads to obtain the first activation value; performing forward propagation of the large language model based on the second input text, and recording the activation status of all attention heads to obtain the second activation value.
[0009] According to a method for alleviating hallucinations of false premises provided by the present invention, before determining the target attention head based on the influence and weakening the target attention head, the method also includes: determining the influence of each attention head in different samples, and determining the significance threshold using a statistical analysis method; determining the target attention head based on the influence and weakening the target attention head includes: when the influence of an attention head is greater than the significance threshold, determining the one attention head as the target attention head and weakening the target attention head.
[0010] According to a method for alleviating hallucinations of false premises provided by the present invention, determining the influence of each attention head in different samples includes: comparing the influence frequency and influence intensity of each attention head in multiple tests to determine the influence of the attention head in different samples.
[0011] According to a method for alleviating hallucinations of false premises provided by the present invention, the target attention head is determined based on the influence, and the target attention head is weakened, including: when the large language model processes the first input text, freezing the ability of the target attention head to process false premises through a constraint function.
[0012] The present invention also provides a device for alleviating hallucinations for erroneous premises, comprising the following modules: an acquisition module and a processing module; the acquisition module is used to acquire a first input text and a second input text, wherein the second input text is a text in which the erroneous premise in the first input text is replaced with a placeholder; the processing module is used to respectively determine the first activation value of each attention head when the large language model processes the first input text, and the second activation value of each attention head when processing the second input text; determine the influence of each attention head on the hallucination text output by the large language model according to a target processing method; determine a target attention head based on the influence, and weaken the target attention head; wherein the target processing method is: replace the activation value of the first attention head of the large language model from the first activation value to the second activation value, freeze the activation values of other attention heads, and perform forward propagation based on the first input text to determine the influence of the first attention head on the hallucination text output by the large language model.
[0013] According to a hallucination mitigation device for false premises provided by the present invention, the processing module is used to perform forward propagation of the large language model based on the first input text, and record the activation status of all attention heads to obtain the first activation value; perform forward propagation of the large language model based on the second input text, and record the activation status of all attention heads to obtain the second activation value.
[0014] According to a device for alleviating hallucinations of false premises provided by the present invention, the processing module is used to determine the influence of each attention head in different samples, and determine the significance threshold by using a statistical analysis method; when the influence of an attention head is greater than the significance threshold, the attention head is determined as a target attention head, and the target attention head is weakened.
[0015] According to a device for alleviating hallucinations of false premises provided by the present invention, the processing module is used to compare the influence frequency and influence strength of each attention head in multiple tests to determine the influence of the attention head in different samples.
[0016] According to a device for alleviating hallucinations of wrong premises provided by the present invention, the processing module is used to freeze the ability of the target attention head to process wrong premises through a constraint function when the large language model processes the first input text.
[0017] The present invention also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the method for alleviating hallucinations for false premises as described above is implemented.
[0018] The present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the method for alleviating hallucinations for false premises as described above is implemented.
[0019] The present invention also provides a computer program product, comprising a computer program, wherein when the computer program is executed by a processor, the computer program implements any of the above-mentioned methods for alleviating hallucinations against false premises.
[0020] The method and device for alleviating hallucinations based on false premises provided by the present invention can determine the target attention head that has a greater influence on the hallucination text output based on the false premise by the large language model, and weaken the target attention head. Through this targeted constraint strategy, the tendency of the model to generate hallucination text when facing false premises can be effectively reduced without sacrificing the overall performance of the model, thereby improving the accuracy and reliability of the model output. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0022] Figure 1 It is a flow chart of the method for alleviating hallucinations for false premises provided by the present invention;
[0023] Figure 2 It is a schematic diagram of the structure of the device for alleviating hallucinations for false premises provided by the present invention;
[0024] Figure 3 It is a structural schematic diagram of the electronic device provided by the present invention. DETAILED DESCRIPTION
[0025] In order to make the purpose, technical solutions and advantages of this application clearer, the technical solutions in this application will be clearly and completely described below in conjunction with the drawings in this application. Obviously, the described embodiments are part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0026] It should be noted that, in the embodiments of the present application, words such as "exemplary" or "for example" are used to indicate examples, illustrations or descriptions. Any embodiment or design described as "exemplary" or "for example" in the embodiments of the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplary" or "for example" is intended to present related concepts in a specific way.
[0027] It should be noted that, in this article, the terms "comprise", "include" or any other variant thereof are intended to cover non-exclusive inclusion, so that the process, method, article or device including a series of elements includes not only those elements, but also includes other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise one..." do not exclude the presence of other identical elements in the process, method, article or device including the element. In addition, it should be pointed out that the scope of the methods and devices in the embodiments of the present application is not limited to performing functions in the order shown or discussed, and may also include performing functions in a substantially simultaneous manner or in reverse order according to the functions involved, for example, the described method may be performed in an order different from that described, and various steps may also be added, omitted, or combined. In addition, the features described with reference to certain examples may be combined in other examples.
[0028] In order to facilitate a clear description of the technical solutions of the embodiments of the present application, in the embodiments of the present application, words such as "first" and "second" are used to distinguish between identical or similar items with substantially the same functions and effects. Those skilled in the art can understand that words such as "first" and "second" do not limit the quantity and order of execution.
[0029] The embodiments of the present application describe some exemplary embodiments for the purpose of explanation. It should be understood that the present application can be implemented in other ways that are not specifically shown in the drawings.
[0030] like Figure 1 As shown, the embodiment of the present application provides a method for alleviating hallucinations for a wrong premise, and the method for alleviating hallucinations for a wrong premise can be applied to a device for alleviating hallucinations for a wrong premise. The method for alleviating hallucinations for a wrong premise can include S101-S104:
[0031] S101. The device for alleviating hallucinations of false premises obtains a first input text and a second input text.
[0032] The second input text is a text obtained by replacing the wrong premise in the first input text with a placeholder.
[0033] Specifically, the first input text may be a question-answer text containing an erroneous premise, and the illusion mitigation device for the erroneous premise may replace the erroneous premise part in the question with a meaningless placeholder, thereby creating a masked version of the question and obtaining the second input text.
[0034] For example, taking the placeholder "XX" as an example, the first input text may be "For what specific reason did Albert Einstein win the Nobel Prize in Physics in 1920?" The second input text may be "For what specific reason did Albert Einstein win the Nobel Prize in Physics in XX?".
[0035] S102. The device for alleviating hallucinations of wrong premises determines respectively a first activation value of each attention head when the large language model processes the first input text, and a second activation value of each attention head when the large language model processes the second input text.
[0036] Optionally, the device for alleviating hallucinations of false premises can perform forward propagation of the large language model based on the first input text, and record the activation status of all attention heads to obtain the first activation value; and perform forward propagation of the large language model based on the second input text, and record the activation status of all attention heads to obtain the second activation value.
[0037] Specifically, the illusion mitigation device for wrong premises can input the first input text into the large language model, and the large language model can gradually pass through each hidden layer from the input layer according to its established network structure, and finally output the answer. In this process, the attention head is a component in the large language model that can focus on key information. Its activation status reflects how each attention head allocates "attention" and which parts of the input information it focuses on when processing the original problem. Recording these activations to obtain the first activation value is equivalent to recording the "thinking steps" inside the model when generating the answer. Similarly, the illusion mitigation device for wrong premises can also use the masked second input text as a new input, and perform the forward propagation operation of the model again to obtain the second activation value. At this time, the focus is on how the activation state of each attention head inside the large language model changes when the wrong premise is missing.
[0038] S103. The device for alleviating hallucinations of wrong premises determines the influence of each attention head on the hallucination text output by the large language model according to the target processing method.
[0039] Among them, the target processing method is: replacing the activation value of the first attention head of the large language model from the first activation value to the second activation value, and freezing the activation values of other attention heads, and performing forward propagation based on the first input text to determine the influence of the first attention head on the hallucination text output by the large language model.
[0040] Optionally, the false premise hallucination mitigation device can determine the specific impact of each attention head on the output of the large language model by performing targeted processing on the activation values of the attention heads during the normal operation of forward propagation of the model using the first input text, that is, replacing some and freezing other parts, and then observing the corresponding changes in the model output.
[0041] Specifically, just like the forward propagation based on the first input text in S102, the illusion mitigation device for the wrong premise can use the unmodified first input text as input to perform the forward propagation operation of the model. This means that the model follows the normal process, starting from the input layer, passing through each layer containing attention heads in turn, and gradually passing information to the output layer and performing calculations, just like starting the entire process normally to generate an answer. During this forward propagation process, certain specific attention heads (i.e., the first attention heads) will be selected, and then their activation values will be replaced with the second activation values previously stored in the forward reasoning stage of the second input text. At the same time, for those other attention heads that have not been selected, let them keep using the first activation values stored in the forward reasoning stage of the first input text, and do not let their activation values change with this forward propagation process, which is equivalent to "freezing" their state.
[0042] In this way, a mixed state is artificially constructed, in which one part of the attention heads adopts activation performance similar to that of the masked problem, while the other part maintains the activation performance under the normal original problem. If the activation value of a specific attention head is replaced according to the previous rules, it is found that the model output has changed significantly compared to the clean run (that is, when reasoning with the original problem normally), this indicates that the attention head has a significant impact on maintaining the wrong premise. For example, the original model can accurately output the answer based on the correct question, but after replacing the activation value of a certain attention head, the output answer has obviously changed in the direction that conforms to the wrong premise, which means that this attention head plays a key role in the model's response to wrong information. Its existence or change in its activation state will greatly affect the final output of the model.
[0043] Through such a carefully constructed "replace and freeze" operation, it is possible to evaluate the influence of each attention head on the hallucination text output by the large language model separately. Because by changing the activation value of a specific attention head and fixing the state of other attention heads, by observing the difference between the final output of the model and the output during normal reasoning, it is possible to infer what role the operated attention head plays in the process of generating answers for the entire model, whether it plays a key positive role or may have a negative interference effect, etc., thereby helping to gain a deeper understanding of the functional characteristics of different attention heads within the model and their importance.
[0044] The influence value directly reflects the importance and actual role of the first self-attention head in dealing with the illusion of false assumptions. The higher the value, the more sensitive the first attention head is to false assumptions and the higher the response when the model generates responses. This means that in the process of information flow, it has a strong processing ability for information related to false premises, and will capture and focus more on such false information.
[0045] S104. The device for alleviating hallucinations of wrong premises determines a target attention head based on the influence, and weakens the target attention head.
[0046] Optionally, the illusion mitigation device for false premises can determine the influence of each attention head in different samples, and use statistical analysis methods to determine the significance threshold; then, when the influence of an attention head is greater than the significance threshold, the attention head is determined as a target attention head, and the target attention head is weakened.
[0047] Specifically, the degree of influence of attention heads in different samples is different. In order to more objectively and accurately judge whether their influence has reached a critical level sufficient to cause the illusion of false assumptions, their performance in many different samples can be comprehensively considered. This application uses statistical analysis methods to collect data on the impact of each attention head on the model output in multiple samples, and then determines a reasonable threshold based on these data. This threshold is like a measurement standard. When the influence of a certain attention head exceeds this standard, it means that its impact on the model output is significant enough, and it may be the main "culprit" that causes the illusion of false assumptions. Weakening them can cut off the path that misleads the model output.
[0048] Optionally, the illusion mitigation device for false premises can compare the influence frequency and influence strength of each attention head in multiple tests to determine the influence of the attention head in different samples.
[0049] Specifically, an attention head that shows a large influence in a single sample is not necessarily the core factor that actually causes the model to have an illusion of false assumptions, because it may be an accidental situation in a specific sample. Therefore, by comparing the influence frequency (that is, the proportion of times that frequently show a large influence in multiple samples) and intensity (the size of the influence value) of each attention head in multiple tests, we can screen out those attention heads that not only have a prominent influence in a single sample, but also often have a large influence between different samples. These screened attention heads are considered to be the key to causing the illusion of false assumptions in the entire model.
[0050] Optionally, the device for alleviating hallucinations of wrong premises may freeze the ability of the target attention head to process wrong premises through a constraint function when the large language model processes the first input text.
[0051] Specifically, the illusion mitigation device for false premises can directly intervene in the model's reasoning process through a constraint function. When the model deals with a problem containing a false premise, this constraint function comes into play, and it takes restrictive measures on the identified target attention heads. Specifically, it temporarily "freezes" or weakens the processing ability of these attention heads for information related to the wrong entity, and the means of implementation is to directly set the output of the attention heads related to the wrong entity to zero. In this way, these attention heads that might have originally led the model to generate answers in the wrong direction will not be able to affect the model's final prediction.
[0052] This targeted constraint strategy can effectively suppress the model's tendency to generate hallucinated text when faced with false premises. Because the adverse effects of attention heads that tend to focus on wrong information and lead to wrong outputs are eliminated or reduced, the accuracy and reliability of the model output will be improved. And because the key attention heads are precisely adjusted rather than making drastic changes to the entire model, the probability of false assumption hallucinations can be significantly reduced without sacrificing the overall performance of the model.
[0053] Optionally, the constraint function is: ;
[0054] in, is the output of the self-attention layer after intervention, represents the number of self-attention heads, is the attention weight matrix, Indicates the first ) layer residual layer information, is the parameter matrix of the large language model, is the number of word prompts, is the total hidden dimension of the self-attention head, yes The set of false assumptions on the layer, Some start and end word positions are incorrectly assumed. Defined as hour, Will The corresponding part Set to zero, otherwise remain unchanged.
[0055] In the embodiment of the present application, the target attention head that has a greater influence on the hallucination text output based on the wrong premise of the large language model can be determined, and the target attention head can be weakened. Through this targeted constraint strategy, the tendency of the model to generate hallucination text when facing wrong premises can be effectively reduced without sacrificing the overall performance of the model, thereby improving the accuracy and reliability of the model output.
[0056] The above mainly introduces the solution provided by the embodiment of the present application from the perspective of the method. In order to realize the above functions, it includes hardware structures and / or software modules corresponding to the execution of each function. Those skilled in the art should easily realize that, in combination with the units and algorithm steps of each example described in the embodiment disclosed herein, the embodiment of the present application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is executed in the form of hardware or computer software driving hardware depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of the present application.
[0057] It should be noted that the device in the embodiment of the present application includes a virtual device and a physical device. The virtual device can be a device for alleviating illusions for false premises, and the physical device can include an electronic device, a computer storage medium, and a computer program product.
[0058] The method for alleviating hallucinations for false premises provided in the embodiment of the present application may be executed by a device for alleviating hallucinations for false premises, or a control module for alleviating hallucinations for false premises in the device for alleviating hallucinations for false premises. In the embodiment of the present application, the device for alleviating hallucinations for false premises performing the method for alleviating hallucinations for false premises is taken as an example to illustrate the device for alleviating hallucinations for false premises provided in the embodiment of the present application.
[0059] It should be noted that the embodiment of the present application can divide the functional modules of the illusion mitigation device for the false premise according to the above method example. For example, each functional module can be divided according to each function, or two or more functions can be integrated into one processing module. The above integrated module can be implemented in the form of hardware or in the form of software functional modules. Optionally, the division of modules in the embodiment of the present application is schematic and is only a logical functional division. There may be other division methods in actual implementation.
[0060] like Figure 2 As shown, the embodiment of the present application provides a device 200 for alleviating hallucinations for wrong premises. The device 200 for alleviating hallucinations for wrong premises includes: an acquisition module 201 and a processing module 202. The acquisition module 201 can be used to acquire a first input text and a second input text, wherein the second input text is a text in which the wrong premise in the first input text is replaced with a placeholder; the processing module 202 is used to respectively determine the first activation value of each attention head when the large language model processes the first input text, and the second activation value of each attention head when processing the second input text; determine the influence of each attention head on the hallucination text output by the large language model according to the target processing method; determine the target attention head based on the influence, and weaken the target attention head; wherein the target processing method is: replace the activation value of the first attention head of the large language model from the first activation value to the second activation value, freeze the activation values of other attention heads, and perform forward propagation based on the first input text to determine the influence of the first attention head on the hallucination text output by the large language model.
[0061] Optionally, the above-mentioned processing module 202 can be used to perform forward propagation of the large language model based on the first input text, and record the activation status of all attention heads to obtain the first activation value; perform forward propagation of the large language model based on the second input text, and record the activation status of all attention heads to obtain the second activation value.
[0062] Optionally, the above-mentioned processing module 202 is used to determine the influence of each attention head in different samples, and use a statistical analysis method to determine a significance threshold; when the influence of an attention head is greater than the significance threshold, the attention head is determined as a target attention head, and the target attention head is weakened.
[0063] Optionally, the processing module 202 is used to compare the influence frequency and influence strength of each attention head in multiple tests to determine the influence of the attention head in different samples.
[0064] Optionally, the processing module 202 is configured to freeze the ability of the target attention head to process erroneous premises through a constraint function when the large language model processes the first input text.
[0065] In the embodiment of the present application, the target attention head that has a greater influence on the hallucination text output based on the wrong premise of the large language model can be determined, and the target attention head can be weakened. Through this targeted constraint strategy, the tendency of the model to generate hallucination text when facing wrong premises can be effectively reduced without sacrificing the overall performance of the model, thereby improving the accuracy and reliability of the model output.
[0066] Figure 3 An example of a physical structure diagram of an electronic device is shown in FIG. Figure 3 As shown, the electronic device may include: a processor 310 , a communications interface 320 , a memory 330 and a communication bus 340 , wherein the processor 310 , the communications interface 320 , and the memory 330 communicate with each other via the communication bus 340 . The processor 310 can call the logic instructions in the memory 330 to execute the hallucination mitigation method for the false premise, which includes: obtaining a first input text and a second input text, wherein the second input text is a text in which the false premise in the first input text is replaced with a placeholder; determining the first activation value of each attention head when the large language model processes the first input text, and the second activation value of each attention head when processing the second input text; determining the influence of each attention head on the hallucination text output by the large language model according to the target processing method; determining the target attention head based on the influence, and weakening the target attention head; wherein the target processing method is: replacing the activation value of the first attention head of the large language model from the first activation value to the second activation value, freezing the activation values of other attention heads, and performing forward propagation based on the first input text to determine the influence of the first attention head on the hallucination text output by the large language model.
[0067] In addition, the logic instructions in the above-mentioned memory 330 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, etc. Various media that can store program codes.
[0068] On the other hand, the present invention also provides a computer program product, which includes a computer program, which can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the hallucination mitigation method for the wrong premise provided by the above methods, and the method includes: obtaining a first input text and a second input text, wherein the second input text is a text in which the wrong premise in the first input text is replaced with a placeholder; respectively determining a first activation value of each attention head when the large language model processes the first input text, and a second activation value of each attention head when processing the second input text; determining the influence of each attention head on the hallucination text output by the large language model according to a target processing method; determining a target attention head based on the influence, and weakening the target attention head; wherein the target processing method is: replacing the activation value of the first attention head of the large language model from the first activation value to the second activation value, and freezing the activation values of other attention heads, and performing forward propagation based on the first input text to determine the influence of the first attention head on the hallucination text output by the large language model.
[0069] On the other hand, the present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which is implemented when the processor executes the method for alleviating hallucinations for erroneous premises provided by the above methods, the method comprising: obtaining a first input text and a second input text, the second input text being a text in which the erroneous premise in the first input text is replaced with a placeholder; respectively determining a first activation value of each attention head when the large language model processes the first input text, and a second activation value of each attention head when processing the second input text; determining the influence of each attention head on the hallucination text output by the large language model according to a target processing method; determining a target attention head based on the influence, and weakening the target attention head; wherein the target processing method is: replacing the activation value of the first attention head of the large language model from the first activation value to the second activation value, freezing the activation values of other attention heads, and performing forward propagation based on the first input text to determine the influence of the first attention head on the hallucination text output by the large language model.
[0070] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.
[0071] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0072] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention 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 make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for alleviating hallucinations based on false premises, characterized in that: include: Obtaining a first input text and a second input text, wherein the second input text is a text obtained by replacing an incorrect premise in the first input text with a placeholder; respectively determining a first activation value of each attention head when the large language model processes the first input text, and a second activation value of each attention head when the large language model processes the second input text; Determine the influence of each attention head on the hallucinated text output by the large language model according to the target processing method; Determine a target attention head based on the influence, and weaken the target attention head; The target processing method is: replacing the activation value of the first attention head of the large language model from the first activation value to the second activation value, freezing the activation values of other attention heads, and performing forward propagation based on the first input text to determine the influence of the first attention head on the hallucination text output by the large language model; The determining a target attention head based on the influence, and weakening the target attention head, includes: When the large language model processes the first input text, the ability of the target attention head to handle wrong premises is frozen by a constraint function.
2. The method for alleviating hallucinations against false premises according to claim 1, characterized in that: The determining, respectively, a first activation value of each attention head when the large language model processes the first input text, and a second activation value of each attention head when the large language model processes the second input text, comprises: Performing forward propagation of the large language model based on the first input text, and recording activation conditions of all attention heads to obtain the first activation value; Perform forward propagation of the large language model based on the second input text, and record activation conditions of all attention heads to obtain the second activation value.
3. The method for alleviating hallucinations against false premises according to claim 1, characterized in that: Before determining the target attention head based on the influence and weakening the target attention head, the method further includes: Determine the influence of each attention head in different samples and use statistical analysis methods to determine the significance threshold; The determining a target attention head based on the influence, and weakening the target attention head, includes: When the influence of an attention head is greater than the significance threshold, the attention head is determined as a target attention head, and the target attention head is weakened; The significance threshold is a preset value for measuring the influence of the attention head.
4. The method for alleviating hallucinations against false premises according to claim 3, characterized in that: Determining the influence of each attention head in different samples includes: Compare the influence frequency and influence strength of each attention head in multiple tests to determine the influence of the attention head in different samples.
5. A device for alleviating hallucinations based on false premises, characterized in that: include: Acquisition module and processing module; The acquisition module is used to acquire a first input text and a second input text, wherein the second input text is a text obtained by replacing an incorrect premise in the first input text with a placeholder; The processing module is used to respectively determine a first activation value of each attention head when the large language model processes the first input text, and a second activation value of each attention head when the large language model processes the second input text; Determine the influence of each attention head on the hallucinated text output by the large language model according to the target processing method; Determine a target attention head based on the influence, and weaken the target attention head; The target processing method is: replacing the activation value of the first attention head of the large language model from the first activation value to the second activation value, freezing the activation values of other attention heads, and performing forward propagation based on the first input text to determine the influence of the first attention head on the hallucination text output by the large language model; The processing module is used to freeze the ability of the target attention head to handle incorrect premises through a constraint function when the large language model processes the first input text.
6. The device for alleviating hallucinations against false premises according to claim 5, characterized in that: The processing module is used to perform forward propagation of the large language model based on the first input text, and record activation conditions of all attention heads to obtain the first activation value; Perform forward propagation of the large language model based on the second input text, and record activation conditions of all attention heads to obtain the second activation value.
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 method for alleviating hallucinations against false premises according to any one of claims 1 to 4 is implemented.
8. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method for alleviating hallucinations against false premises according to any one of claims 1 to 4 is implemented.
9. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the method for alleviating hallucinations against false premises according to any one of claims 1 to 4 is implemented.
Citation Information
Patent Citations
Large model reasoning method and device based on knowledge graph
CN117436527A
Large language model training method and device
CN118445379A