Knowledge conflict-oriented adaptive decoding method and apparatus, and electronic device
By judging the conflict between parameterized knowledge and contextual knowledge in large language models, different decoding methods are used to deal with conflict and non-conflict situations, the performance reduction problem of the inability to take into account non-conflict external knowledge in the existing technology is solved, and more efficient and reliable A good decoding process.
Patent Information
- Application Number
- CN202411554277.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-04
- Publication Date
- 2024-12-03
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
Existing decoding strategies fail to handle non-conflict external knowledge, resulting in reduced performance without knowledge conflicts.
By inputting the problem into a large language model to obtain the output distribution containing only parameterized knowledge and the output distribution containing parameterized and contextual knowledge, and using information entropy to judge knowledge conflicts, different decoding methods are used to deal with conflict and non-conflict situations respectively.
It realizes the high decoding performance in both conflict and non-conflict situations, providing a more universal and robust decoding method.
Smart Images

Figure CN119067213A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a knowledge conflict-oriented adaptive decoding method, device and electronic device. Background Art
[0002] As the size of data and parameters grows, large-scale pre-trained language models (LLMs) such as GPT-4 and LLaMA have emerged. These models store rich world knowledge in billions of model parameters by learning on massive corpora, representing a breakthrough in the field of NLP. These large language models have also shown great potential in complex practical tasks such as code generation and recommendation systems. However, as purely parametric models, LLMs also have many challenges. First, they cannot memorize all the facts and knowledge in the training corpus, especially the low-frequency long-tail knowledge. At the same time, the knowledge stored in the model is easily outdated and difficult to update; and it is easy to generate wrong information (i.e., "hallucination"). These problems highlight the need for external knowledge in the reasoning process of large language models, such as knowledge injection by explicitly integrating external knowledge through retrieval and other methods (such as contextual retrieval enhancement).
[0003] However, this approach brings a problem: knowledge conflict, that is, when external documents accurately contain factual knowledge related to the problem, but are inconsistent (conflicting) with the internal knowledge parameterized by the model, the model's reliance on parameter knowledge may ignore the external knowledge enhanced by retrieval, which in turn causes the model to make incorrect predictions. Studies have found that the larger the model, the more likely it is to ignore contextual knowledge that contradicts parameter knowledge.
[0004] At present, most of the focus on the problem of knowledge conflict is to improve the fidelity and consistency between the model output and external knowledge, and a variety of decoding strategies are adopted. For example, the contrastive decoding (CD) strategy decodes the change of the probability distribution of the output by using contextual knowledge. On this basis, context-aware decoding (CAD) enhances the output distribution dependence on model parameter knowledge.
[0005] However, these methods all rely on a basic assumption: the data in the current experimental settings all have knowledge conflicts. Scenarios without knowledge conflicts are also decoded as if there are conflicts, which results in performance degradation when there are no knowledge conflicts. Therefore, existing decoding strategies cannot handle non-conflicting external knowledge. Summary of the invention
[0006] In order to solve the problems existing in the prior art, the present invention provides the following technical solutions.
[0007] A first aspect of the present invention provides a knowledge conflict-oriented adaptive decoding method, comprising: Inputting a question into a large language model, outputting a first answer and obtaining a first output distribution, wherein the first output distribution is an output distribution that only includes parameterized knowledge; Inputting the question and contextual knowledge related to the question into the large language model, outputting a second answer and obtaining a second output distribution, wherein the second output distribution is an output distribution including parameterized knowledge and contextual knowledge; The comparison distribution g is calculated using the first output distribution and the second output distribution according to the following formula: ; Determine whether there is a conflict between parameterized knowledge and contextual knowledge. If there is no conflict, use the first output distribution and the contrast distribution to calculate the model output distribution and perform decoding; if there is a conflict, use the second output distribution and the contrast distribution to calculate the model output distribution and perform decoding; in, is the first output distribution, is the second output distribution, To compare the distribution, For the first answer, For the second answer.
[0008] Preferably, the determining whether there is a conflict between parameterized knowledge and contextual knowledge includes: Calculating a first information entropy of a first answer using the first output distribution; Calculating a second information entropy of a second answer using the second output distribution; It is determined whether the first information entropy and the second information entropy satisfy the constraint condition. If the constraint condition is satisfied, there is no knowledge conflict between the parameterized knowledge and the contextual knowledge; otherwise, there is a knowledge conflict between the parameterized knowledge and the contextual knowledge.
[0009] Preferably, the constraints are: ; ; ; in, is the second information entropy, For the second answer, is the first information entropy, For the first answer, is a constant, For the problem, is the contextual knowledge related to the question.
[0010] Preferably, the first output distribution and the comparison distribution are used to calculate the model output distribution and perform decoding, using the following formula: ; ; in, For the problem, is the contextual knowledge related to the question, for The answer output by the model before time, for The answer output by the model is is the current time, is the scaling weight used to control the influence of contextual knowledge, Output distribution of the model.
[0011] Preferably, the second output distribution and the comparison distribution are used to calculate the model output distribution and perform decoding, using the following formula: ; ; in, For the problem, is the contextual knowledge related to the question, for The answer output by the model before time, for The answer output by the model is is the current time, is the scaling weight used to control the influence of contextual knowledge, Output distribution of the model.
[0012] A second aspect of the present invention provides a knowledge conflict-oriented adaptive decoding device, comprising: A first reasoning module, configured to input a question into the large language model, output a first answer and obtain a first output distribution, wherein the first output distribution is an output distribution that only includes parameterized knowledge; A second reasoning module is used to input the question and the contextual knowledge related to the question into the large language model, output a second answer and obtain a second output distribution, where the second output distribution is an output distribution including parameterized knowledge and contextual knowledge; A contrast distribution calculation module is used to calculate a contrast distribution g using the first output distribution and the second output distribution according to the following formula: ; A decoding module, used to determine whether there is a conflict between parameterized knowledge and contextual knowledge, and if there is no conflict, use the first output distribution and the contrast distribution calculation model to output the distribution and perform decoding; if there is a conflict, use the second output distribution and the contrast distribution calculation model to output the distribution and perform decoding; in, is the first output distribution, is the second output distribution, To compare the distribution, For the first answer, For the second answer.
[0013] Preferably, the first output distribution and the comparison distribution are used to calculate the model output distribution and perform decoding, using the following formula: ; ; in, For the problem, is the contextual knowledge related to the question, for The answer output by the model before time, for The answer output by the model is is the current time, is the scaling weight used to control the influence of contextual knowledge, Output distribution of the model.
[0014] Preferably, the second output distribution and the comparison distribution are used to calculate the model output distribution and perform decoding, using the following formula: ; ; in, For the problem, is the contextual knowledge related to the question, for The answer output by the model before time, for The answer output by the model is is the current time, is the scaling weight used to control the influence of contextual knowledge, Output distribution of the model.
[0015] A third aspect of the present invention provides a memory storing a plurality of instructions, wherein the instructions are used to implement the adaptive decoding method for knowledge conflict as described in the first aspect.
[0016] The fourth aspect of the present invention provides an electronic device, comprising a processor and a memory connected to the processor, the memory storing a plurality of instructions, the instructions being loaded and executed by the processor so that the processor can execute the adaptive decoding method for knowledge conflicts as described in the first aspect.
[0017] The beneficial effects of the present invention are as follows: the present invention provides an adaptive decoding method, device and electronic device for knowledge conflicts. The technical solution accurately identifies knowledge conflicts and adopts different decoding methods for conflict and non-conflict situations, so that the decoding process of a large language model can not only alleviate conflicts when conflicts occur, but also maintain high decoding performance when conflicts do not occur. Therefore, the decoding method provided by the present invention is universal and has consistent effectiveness and robustness in different scenarios. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] Figure 1 It is a flow chart of the adaptive decoding method for knowledge conflict of the present invention; Figure 2 It is a functional structure diagram of the adaptive decoding device for knowledge conflict according to the present invention. DETAILED DESCRIPTION
[0019] In order to better understand the above technical solution, the above technical solution will be described in detail below in conjunction with the accompanying drawings and specific implementation methods.
[0020] The method provided by the present invention can be implemented in the following terminal environment, and the terminal may include one or more of the following components: a processor, a memory, and a display screen. The memory stores at least one instruction, and the instruction is loaded and executed by the processor to implement the method described in the following embodiment.
[0021] The processor may include one or more processing cores. The processor uses various interfaces and lines to connect various parts of the entire terminal, and executes various functions of the terminal and processes data by running or executing instructions, programs, code sets or instruction sets stored in the memory, and calling data stored in the memory.
[0022] The memory may include random access memory (RAM) or read-only memory (ROM). The memory may be used to store instructions, programs, codes, code sets or instructions.
[0023] The display screen is used to display the user interface of each application.
[0024] In addition, those skilled in the art can understand that the structure of the above terminal does not constitute a limitation on the terminal, and the terminal may include more or fewer components, or combine certain components, or arrange the components differently. For example, the terminal also includes components such as a radio frequency circuit, an input unit, a sensor, an audio circuit, and a power supply, which will not be described in detail here.
[0025] Embodiment 1 like Figure 1 As shown, an embodiment of the present invention provides an adaptive decoding method for knowledge conflict, including: S101, inputting a question into a large language model, outputting a first answer and obtaining a first output distribution, wherein the first output distribution is an output distribution that only contains parameterized knowledge; S102, inputting the question and contextual knowledge related to the question into the large language model, outputting a second answer and obtaining a second output distribution, wherein the second output distribution is an output distribution including parameterized knowledge and contextual knowledge; S103, using the first output distribution and the second output distribution, calculate a comparison distribution g according to the following formula: ; S104, determining whether there is a conflict between the parameterized knowledge and the contextual knowledge, if there is no conflict, using the first output distribution and the contrast distribution calculation model to output the distribution and perform decoding; if there is a conflict, using the second output distribution and the contrast distribution calculation model to output the distribution and perform decoding; in, is the first output distribution, is the second output distribution, To compare the distribution, For the first answer, For the second answer.
[0026] In a preferred embodiment of the present invention, the determining whether there is a conflict between parameterized knowledge and contextual knowledge may include: Calculating a first information entropy of a first answer using the first output distribution; Calculating a second information entropy of a second answer using the second output distribution; It is determined whether the first information entropy and the second information entropy satisfy the constraint condition. If the constraint condition is satisfied, there is no knowledge conflict between the parameterized knowledge and the contextual knowledge; otherwise, there is a knowledge conflict between the parameterized knowledge and the contextual knowledge.
[0027] In the embodiment of the present invention, the constraint condition may be: ; ; ; in, is the second information entropy, For the second answer, is the first information entropy, For the first answer, is a constant, For the problem, is the contextual knowledge related to the question.
[0028] In a preferred embodiment of the present invention, the calculation of the model output distribution using the first output distribution and the comparison distribution and decoding can be performed using the following formula: ; ; in, For the problem, is the contextual knowledge related to the question, for The answer output by the model before time, for The answer output by the model is is the current time, is the scaling weight used to control the influence of contextual knowledge, is the model output distribution. " is a conventional expression in statistics, meaning "subject to" or "sampled from..."
[0029] In another preferred embodiment of the present invention, the calculation of the model output distribution using the second output distribution and the comparison distribution and decoding can be performed using the following formula: ; ; in, For the problem, is the contextual knowledge related to the question, for The answer output by the model before time, for The answer output by the model is is the current time, is the scaling weight used to control the influence of contextual knowledge, Output distribution of the model.
[0030] In the above decoding method provided by the present invention, the contrast distribution aims to optimize the difference brought by contextual knowledge. prefer to produce output that is consistent with the knowledge of the model parameterization, while The role of is to exclude the model's inherent memory and favor contextual knowledge.
[0031] based on , using different decoding methods for conflicting and non-conflicting situations. Specifically, for conflicting situations, the model can give priority to contextual knowledge. To this end, It is used strategically to strengthen contextual knowledge. For non-conflicting situations, the model can be encouraged to rely more on parameterized knowledge rather than relying entirely on contextual knowledge. This strategy stems from the recognition of the potential limitations of contextual knowledge, because contextual knowledge may not be able to fully solve the query problem. Therefore, the present invention emphasizes the importance of parameterized knowledge while emphasizing contextual factors. Specifically, for conflicting situations, the model output distribution is calculated using the second output distribution and the comparison distribution: ; For the non-conflicting case, the model output distribution is calculated using the first output distribution and the contrast distribution: ; The final decoding strategy can be formalized as: ; In the above method, for non-conflicting situations, it is hoped that the model will refer to both parameterized knowledge and contextual knowledge when decoding. Therefore, in the decoding stage, g is combined with the expression of parameterized knowledge In the case of conflict, we hope that the model will give priority to contextual knowledge, so in the distribution A contrast distribution g is added to amplify the probability distribution of contextual knowledge.
[0032] Therefore, the decoding method provided by the present invention can achieve a balance between the two knowledge sources (contextual knowledge and parameterized knowledge), thereby obtaining a more effective and holistic decoding process.
[0033] In a preferred embodiment of the present invention, the following steps are used to determine whether there is a conflict between parameterized knowledge and contextual knowledge: Calculating a first information entropy of a first answer using the first output distribution; Calculating a second information entropy of a second answer using the second output distribution; It is determined whether the first information entropy and the second information entropy satisfy the constraint condition. If the constraint condition is satisfied, there is no knowledge conflict between the parameterized knowledge and the contextual knowledge; otherwise, there is a knowledge conflict between the parameterized knowledge and the contextual knowledge.
[0034] The constraints are: ; ; ; in, is the second information entropy, For the second answer, is the first information entropy, For the first answer, is a constant, For the problem, is the contextual knowledge related to the question.
[0035] In the embodiment of the present invention, the above method is used to realize the identification of knowledge conflicts. In the process of studying the method for identifying knowledge conflicts, the present invention first assumes that the context knowledge is consistent with the parameterized knowledge of the model. Therefore, the context knowledge can be regarded as a text generation of the model under certain conditions. Based on this assumption, the stable entropy hypothesis and local typical theory are used in the study to derive the context information entropy constraint for identifying knowledge conflicts at the token level.
[0036] The stable entropy hypothesis holds that the generation of natural language usually falls within a narrow and flat entropy band, so the generation without conflicting contextual knowledge is regarded as the natural generation of the model. If the generation of the model deviates from the specified entropy band, it indicates that there is a potential conflict in the contextual knowledge. In this case, it is necessary to accurately identify specific tokens (which can be understood as words in the present invention) that reflect the conflict. These tokens may cause the model to exceed the boundaries of the specified entropy band during the generation process. In order to solve this problem, local typical sets can be used to limit the change in the information entropy of tokens, that is, to introduce constraints: ; ; ; In other words, the change in information entropy can be constrained by a constant γ. This means that if the change in information entropy of a token complies with this constraint, the token can be considered as a possible non-conflicting context generation. On the contrary, any token that exceeds this constraint represents a probabilistic conflict.
[0037] Therefore, in the decoding process of the large language model, words whose information entropy changes comply with the constraints (within the constraints) represent that the contextual knowledge and parameterized knowledge are consistent and there is no conflict. On the contrary, words whose information entropy changes do not comply with the constraints (fall into the out-of-bounds area) are associated with the conflict of contextual knowledge, which means that the contextual knowledge and parameterized knowledge are inconsistent and there is a conflict.
[0038] Embodiment 2 like Figure 2As shown, another aspect of the present invention also includes a functional module architecture that is completely consistent with the aforementioned method flow, that is, the embodiment of the present invention also provides an adaptive decoding device for knowledge conflicts, including: A first reasoning module 201 is used to input a question into a large language model, output a first answer and obtain a first output distribution, where the first output distribution is an output distribution that only contains parameterized knowledge; A second reasoning module 202, configured to input the question and contextual knowledge related to the question into the large language model, output a second answer and obtain a second output distribution, wherein the second output distribution is an output distribution including parameterized knowledge and contextual knowledge; The contrast distribution calculation module 203 is used to calculate the contrast distribution g by using the first output distribution and the second output distribution according to the following formula: ; The decoding module 204 is used to determine whether there is a conflict between the parameterized knowledge and the contextual knowledge. If there is no conflict, the first output distribution and the contrast distribution calculation model output distribution are used and decoded; if there is a conflict, the second output distribution and the contrast distribution calculation model output distribution are used and decoded; in, is the first output distribution, is the second output distribution, To compare the distribution, For the first answer, For the second answer.
[0039] Furthermore, in the decoding module, the determination of whether there is a conflict between the parameterized knowledge and the contextual knowledge includes: calculating a first information entropy of a first answer using a first output distribution; calculating a second information entropy of a second answer using a second output distribution; and determining whether the first information entropy and the second information entropy satisfy constraints. If the constraints are satisfied, there is no knowledge conflict between the parameterized knowledge and the contextual knowledge; otherwise, there is a knowledge conflict between the parameterized knowledge and the contextual knowledge.
[0040] The constraints are: ; ; ; in, is the second information entropy, For the second answer, is the first information entropy, For the first answer, is a constant, For the problem, is the contextual knowledge related to the question.
[0041] Furthermore, in the decoding module, the first output distribution and the comparison distribution are used to calculate the model output distribution and perform decoding, using the following formula: ; ; in, For the problem, is the contextual knowledge related to the question, for The answer output by the model before time, for The answer output by the model is is the current time, is the scaling weight used to control the influence of contextual knowledge, Output distribution of the model.
[0042] Furthermore, in the decoding module, the second output distribution and the comparison distribution are used to calculate the model output distribution and perform decoding, using the following formula: l ; ; in, For the problem, is the contextual knowledge related to the question, for The answer output by the model before time, for The answer output by the model is is the current time, is the scaling weight used to control the influence of contextual knowledge, Output distribution of the model.
[0043] The device can be implemented by the adaptive decoding method for knowledge conflict provided in the above-mentioned embodiment 1. The specific implementation method can be found in the description of embodiment 1, which will not be repeated here.
[0044] The present invention also provides a memory storing a plurality of instructions, wherein the instructions are used to implement the adaptive decoding method for knowledge conflict as described in the first embodiment.
[0045] The present invention also provides an electronic device, comprising a processor and a memory connected to the processor, wherein the memory stores a plurality of instructions, and the instructions can be loaded and executed by the processor so that the processor can execute the adaptive decoding method for knowledge conflicts as described in Example 1.
[0046] Although preferred embodiments of the present invention have been described, additional changes and modifications may be made to these embodiments by those skilled in the art once the basic inventive concepts are known. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the present invention. Obviously, those skilled in the art may make various changes and modifications to the present invention without departing from the spirit and scope of the present invention. Thus, if these modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include these modifications and variations.
Claims
1. An adaptive decoding method for knowledge conflict, characterized in that: include: Inputting a question into a large language model, outputting a first answer and obtaining a first output distribution, wherein the first output distribution is an output distribution that only includes parameterized knowledge; Inputting the question and contextual knowledge related to the question into the large language model, outputting a second answer and obtaining a second output distribution, wherein the second output distribution is an output distribution including parameterized knowledge and contextual knowledge; The comparison distribution g is calculated using the first output distribution and the second output distribution according to the following formula: ; Determine whether there is a conflict between the parameterized knowledge and the contextual knowledge, and if there is no conflict, calculate the model output distribution using the first output distribution and the comparison distribution and perform decoding; If there is a conflict, the model output distribution is calculated using the second output distribution and the comparison distribution and decoded; in, is the first output distribution, is the second output distribution, To compare the distribution, For the first answer, For the second answer.
2. The adaptive decoding method for knowledge conflict as claimed in claim 1, characterized in that: The determining whether there is a conflict between parameterized knowledge and contextual knowledge includes: Calculating a first information entropy of a first answer using the first output distribution; Calculating a second information entropy of a second answer using the second output distribution; It is determined whether the first information entropy and the second information entropy satisfy the constraint condition. If the constraint condition is satisfied, there is no knowledge conflict between the parameterized knowledge and the contextual knowledge; otherwise, there is a knowledge conflict between the parameterized knowledge and the contextual knowledge.
3. The adaptive decoding method for knowledge conflict as claimed in claim 2, characterized in that: The constraints are: ; ; ; in, is the second information entropy, For the second answer, is the first information entropy, For the first answer, is a constant, For the problem, is the contextual knowledge related to the question.
4. The adaptive decoding method for knowledge conflict as claimed in claim 1, characterized in that: The first output distribution and the comparison distribution are used to calculate the model output distribution and decode it, using the following formula: ; ; in, For the problem, is the contextual knowledge related to the question, for The answer output by the model before time, for The answer output by the model is is the current time, is the scaling weight used to control the influence of contextual knowledge, Output distribution of the model.
5. The adaptive decoding method for knowledge conflict as claimed in claim 1, characterized in that: The second output distribution and the comparison distribution are used to calculate the model output distribution and decode it, using the following formula: ; ; in, For the problem, is the contextual knowledge related to the question, for The answer output by the model before time, for The answer output by the model is is the current time, is the scaling weight used to control the influence of contextual knowledge, Output distribution of the model.
6. An adaptive decoding device for knowledge conflict, characterized in that: include: A first reasoning module, configured to input a question into the large language model, output a first answer and obtain a first output distribution, wherein the first output distribution is an output distribution that only includes parameterized knowledge; A second reasoning module is used to input the question and the contextual knowledge related to the question into the large language model, output a second answer and obtain a second output distribution, where the second output distribution is an output distribution including parameterized knowledge and contextual knowledge; A contrast distribution calculation module is used to calculate a contrast distribution g using the first output distribution and the second output distribution according to the following formula: ; A decoding module, used to determine whether there is a conflict between the parameterized knowledge and the contextual knowledge, and if there is no conflict, use the first output distribution and the comparison distribution to calculate the model output distribution and perform decoding; If there is a conflict, the model output distribution is calculated using the second output distribution and the comparison distribution and decoded; in, is the first output distribution, is the second output distribution, To compare the distribution, For the first answer, For the second answer.
7. The adaptive decoding device for knowledge conflict according to claim 6, characterized in that: The first output distribution and the comparison distribution are used to calculate the model output distribution and decode it, using the following formula: ; ; in, For the problem, is the contextual knowledge related to the question, for The answer output by the model before time, for The answer output by the model is is the current time, is the scaling weight used to control the influence of contextual knowledge, Output distribution of the model.
8. The knowledge conflict-oriented adaptive decoding device according to claim 6, characterized in that: The second output distribution and the comparison distribution are used to calculate the model output distribution and decode it, using the following formula: ; ; in, For the problem, is the contextual knowledge related to the question, for The answer output by the model before time, for The answer output by the model is is the current time, is the scaling weight used to control the influence of contextual knowledge, Output distribution of the model.
9. A memory, characterized in that: A plurality of instructions are stored, and the instructions are used to implement the adaptive decoding method for knowledge conflict as described in any one of claims 1-5.
10. An electronic device, characterized in that: It comprises a processor and a memory connected to the processor, wherein the memory stores a plurality of instructions, and the instructions can be loaded and executed by the processor, so that the processor can execute the adaptive decoding method for knowledge conflict as described in any one of claims 1-5.
Citation Information
Patent Citations
Knowledge conflict analysis relieving method for retrieval enhancement language model
CN118606444A
Intelligent question answering method, apparatus and device, and computer-readable storage medium
WO2021196920A1
Cited By
Large model context conflict resolution method and device based on dynamic coordination decoding
CN120449863A
Model processing method and related apparatus
WO2026208385A1
