Dynamic context weight adaptive comparison decoding method and system

Through the dynamic context weight adaptive contrast decoding method, combined with semantic similarity and entropy value, multi-document fusion and context quality assessment are performed, which solves the problems of ignoring the semantic correlation between context and question and insufficient noise robustness in the existing technology, and achieves It enables more sophisticated and flexible utilization of context information, improving the model's generation performance and robustness in complex scenarios.

CN118779833AActive Publication Date: 2024-10-15SHANDONG INSPUR SCI RES INST CO LTD

Patent Information

Application Number
CN202411266078.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-11
Publication Date
2024-10-15
Estimated Expiration
2044-09-11

Smart Images

  • Figure CN118779833A_ABST
    Figure CN118779833A_ABST
Patent Text Reader

Abstract

The invention provides a dynamic context weight adaptive comparison decoding method and system, and belongs to the technical field of artificial intelligence, and the method comprises the steps of dynamic weight calculation, multi-document fusion, context quality evaluation, token-level dynamic weight and final decoding probability distribution calculation. Finer and more accurate context information utilization is realized by combining the semantic similarity and the dynamic token level weight; the robustness of the model to noise and irrelevant information is improved by a multi-document fusion and context quality evaluation mechanism; dynamic weight calculation enables the model to flexibly cope with contexts of different types and qualities; rich information provided by a retrieval system is fully utilized by a multi-document fusion mechanism; through explicit context quality evaluation and token level weight, the interpretability of model decision making is improved; the method is suitable for various natural language processing tasks needing to be combined with external knowledge.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of artificial intelligence technology, and in particular relates to a dynamic context weight adaptive contrast decoding method and system. Background Art

[0002] Retrieval-Augmented Generation (RAG) technology has made significant progress in recent years and has become an effective method to improve the performance of large language models (LLMs). By combining external knowledge bases, RAG enables the model to access more extensive and updated information, thereby generating more accurate and relevant content.

[0003] In practical applications, the retrieved contextual information often contains noise or irrelevant content, which has a negative impact on the generation quality of the model. To solve this problem, researchers have proposed a variety of contrastive decoding methods, among which Adaptive Contrastive Decoding (ACD) has attracted widespread attention due to its excellent performance in processing noisy context tasks. ACD achieves a balance between model parameter knowledge and external contextual information by dynamically adjusting the weight of contextual influence. This method has achieved remarkable results in improving the robustness of the model to noise.

[0004] However, the current ACD method still has some limitations that affect its application effect in more complex scenarios. For example, ACD only adjusts the context weight based on the entropy value, ignoring the semantic relevance between the context and the question; using the same weight for the entire generation process, not considering the difference in the degree of dependence of different tokens on the context; only using the top-1 document returned by the retrieval system, not making full use of the valuable information in other related documents, etc. These problems limit the effectiveness of the ACD method in dealing with more complex and diverse tasks. Summary of the invention

[0005] In view of the problems in the prior art, the present invention proposes a dynamic context-weighted adaptive contrastive decoding method (DC-ACD). This method aims to achieve more sophisticated and flexible context information utilization by introducing multi-dimensional innovative strategies, thereby further improving the generation performance and robustness of the model in complex scenarios.

[0006] In order to achieve the above purpose, the technical solution adopted in this application is: In a first aspect, the present invention provides a dynamic context weight adaptive contrast decoding method, including: dynamic weight calculation, multi-document fusion, context quality assessment, token level dynamic weight and final decoding probability distribution calculation; Dynamic weight calculation: obtain the weight calculated by the original ACD method at time t, the semantic similarity and balance factor between question q and context c, and dynamically calculate the context weight; Multi-document fusion: Get multiple documents, fuse them using a multi-document fusion strategy based on dynamic weights, and obtain the fused context logit; Context quality assessment: The fused context logit is evaluated using the quality assessment formula; Token-level dynamic weight: Dynamically calculate the weight of each generated token to obtain the token-level dynamic weight; The final decoding probability distribution is calculated: ,in: is the logit output of the original language model; It is the dynamic weight at the token level; is the dynamically calculated context weight; is the fused context logit.

[0007] Furthermore, dynamically calculating the context weight includes: the dynamic weight at time t is the weight calculated by the original ACD method at time t plus the A value, the A value is the semantic similarity between the question q and the context c multiplied by the B value, and the B value is 1 minus the value of the balance factor.

[0008] Furthermore, the dynamic weight calculation formula is:

[0009] in: represents the dynamic weight at time t; is the weight calculated by the original ACD method at time t; Represents the semantic similarity between question q and context c; is a balancing factor tuned through the validation set.

[0010] Furthermore, the multi-document fusion strategy includes:

[0011] in: is the fused context logit; Indicates The weight of the document; It is based on The logit of the document.

[0012] Furthermore, the weight of each generated token is calculated dynamically: ,in, yes Token embedding at the moment; yes The hidden state of the moment; It is a contextual representation; It is a small neural network.

[0013] Furthermore, the quality assessment formula is: ; Designed as a small neural network.

[0014] In a second aspect, the present invention provides a dynamic context weight adaptive contrast decoding system, comprising: The dynamic weight calculation module is configured to: obtain the weight calculated by the original ACD method at time t, the semantic similarity and balance factor between the question q and the context c, and dynamically calculate the context weight; The multi-document fusion module is configured to: obtain multiple documents, fuse the multiple documents using a multi-document fusion strategy according to dynamic weights, and obtain fused context logit; The context quality assessment module is configured to: evaluate the fused context logit through a quality assessment formula; The token-level dynamic weight module is configured to: dynamically calculate the weight for each generated token to obtain the token-level dynamic weight; The final decoding probability distribution calculation module is configured as follows: ,in: is the logit output of the original language model; It is the dynamic weight at the token level; is the dynamically calculated context weight; is the fused context logit.

[0015] In a third aspect, the present invention provides a computer-readable storage medium, the computer-readable storage medium comprising a stored program, wherein when the program is running, the device where the computer-readable storage medium is located is controlled to execute a dynamic context weight adaptive contrast decoding method described in the first aspect.

[0016] In a fourth aspect, the present invention provides an electronic device comprising a memory for storing computer program instructions and a processor for executing the program instructions, wherein when the computer program instructions are executed by the processor, the electronic device is triggered to execute a dynamic context weight adaptive contrast decoding method described in the first aspect.

[0017] Compared with the prior art, the advantages and positive effects of the present invention are: 1. The present invention provides a dynamic context-weighted adaptive contrastive decoding method (Dynamic Context-Weighted Adaptive Contrastive Decoding, DC-ACD), including: dynamic weight calculation, multi-document fusion, context quality assessment, token-level dynamic weight and final decoding probability distribution calculation; by combining semantic similarity and dynamic token-level weight, more refined and accurate context information utilization is achieved; multi-document fusion and context quality assessment mechanism improve the robustness of the model to noise and irrelevant information; dynamic weight calculation enables the model to flexibly respond to contexts of different types and qualities; multi-document fusion mechanism makes full use of the rich information provided by the retrieval system; through explicit context quality assessment and token-level weight, the interpretability of model decisions is improved.

[0018] 2. The DC-ACD method provided by the present invention is applicable to various natural language processing tasks that need to combine external knowledge, especially when facing potential noise or incomplete context, such as open domain question answering, knowledge-intensive dialogue systems, fact checking and verification, personalized content generation and other scenarios.

[0019] 3. The DC-ACD method provided by the present invention achieves more sophisticated and flexible use of contextual information by introducing a multi-dimensional innovative strategy, thereby further improving the generation performance and robustness of the model in complex scenarios. BRIEF DESCRIPTION OF THE DRAWINGS

[0020] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in 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 labor.

[0021] Figure 1 A schematic diagram of a flow chart of a dynamic context weight adaptive contrast decoding method of the present invention. DETAILED DESCRIPTION

[0022] In order to more clearly understand the above-mentioned purpose, features and advantages of the present invention, the present invention is further described below in conjunction with the accompanying drawings and embodiments. It should be noted that the embodiments of the present application and the features in the embodiments can be combined with each other without conflict.

[0023] In the following description, many specific details are set forth to facilitate a full understanding of the present invention. However, the present invention may also be implemented in other ways different from those described herein. Therefore, the present invention is not limited by the specific embodiments disclosed in the following specification.

[0024] Example 1, as Figure 1 shown, this example proposes a Dynamic Context-Weighted Adaptive Contrastive Decoding (DC-ACD) method, aiming to solve some key problems in the existing Retrieval-Augmented Generation (RAG) technology. The DC-ACD method effectively balances the prior knowledge and context information of the model through multiple carefully designed components, achieving a more accurate and flexible text generation process.

[0025] Step S1, dynamic weight calculation. The core innovation of the DC-ACD method lies in its dynamic weight calculation mechanism. The traditional Adaptive Contrastive Decoding (ACD) method only relies on entropy values to adjust context weights, ignoring the important factor of semantic relevance. To solve this problem, this example introduces a new dynamic weight calculation formula:

[0026] where: represents the dynamic weight at time t; is the weight calculated by the original ACD method at time t; represents the semantic similarity between the question q and the context c; is a balance factor that can be tuned through the validation set; This formula combines entropy values and semantic similarity, making the weight calculation more comprehensive and accurate. In specific implementation, is calculated using the following method, based on entropy values. The entropy value calculation process of the ACD method is as follows: For the given input x and the previously generated y<t, calculate the output probability distributions of the language model at time t in the context of c and the irrelevant context respectively: and , where represents the parameters of the language model, represents the output token at time t, x is the input (usually the question in the Q&A task), y<t represents the sequence generated before time t, and c is the context information.

[0027] Compute the entropy of these two probability distributions: ,and , where the sum is performed on all tokens in the vocabulary.

[0028] Calculate the difference in entropy:

[0029] Use the sigmoid function to map the entropy difference to the (0,1) interval, and we get : in, is the weight calculated at time t, which reflects the contribution of context information to reducing model uncertainty. When ΔH is large, it means that the context significantly reduces the uncertainty of the model. Close to 1; otherwise, close to 0.

[0030] and It can be calculated using a pre-trained semantic matching model (such as BERT, RoBERTa, etc.). The calculation steps are as follows: Step S11, input the question q and context c into the pre-trained model to obtain their vector representations; Step S12, calculate the cosine similarity of the two vectors as The value of; To better understand the function of this formula, this embodiment provides a specific example. Assume that there is a question "Who invented the telephone?" and the search system returns two pieces of context: c1: "Alexander Graham Bell invented the telephone in 1876." c2: "Thomas Edison invented many important electronic devices." Calculated using the semantic matching model: and , assuming , ,but: (for c1) (for c2) The above example shows that even if two contexts The values ​​of c1 and c2 are the same, but c1 will get a larger weight because it has a higher semantic similarity to the question. This approach ensures that more relevant information can play a greater role in the generation process.

[0031] Step S2, multi-document fusion. In practical applications, a single document often cannot provide comprehensive information. To solve this problem, DC-ACD adopts a multi-document fusion strategy, using the top-k documents returned by the retrieval system: in: is the fused context logit; Indicates The weight of the document; It is based on The logit of the document.

[0032] Implementation details: Step a, document weight It can be determined based on the relevance score returned by the retrieval system, for example, by normalizing the relevance score using a softmax function: Where exp represents the softmax function, Representative The relevance score of a document can be calculated based on the calculation logic of a traditional search engine.

[0033] Step b: For each document, calculate the ACD score ; Step c, finally, the logit weighted sum of all documents is obtained .

[0034] This embodiment provides a specific example. Assume that the retrieval system returns 3 documents, whose relevance scores are 10, 8, and 6 respectively. First, the weight is calculated:

[0035] Then, suppose that at a certain time step t, the logits corresponding to these three documents are: , , The fused logit is: This fusion method can comprehensively consider the information of multiple related documents, improve the comprehensiveness and accuracy of information utilization, and enhance the robustness of the system to noise and incomplete information.

[0036] Step S3, context quality assessment, the quality of information is often more important than the quantity. In order to further improve the generation quality, DC-ACD introduces a lightweight but efficient context quality assessment network , the quality assessment formula is: . Implementation details: a) Designed as a small neural network, for example a two-layer feedforward network: ,in , , , are learnable parameters.

[0037] b) The input c of the network can be the average of the word vectors of the context or the vector representation obtained using a pre-trained model.

[0038] c) Output of the network After the sigmoid function Mapped to the (0,1) interval.

[0039] d) During the training phase, manually annotated contextual quality labels can be used to supervise the training network This embodiment is shown through an example, assuming that for the two previous contexts: c1: "Alexander Graham Bell invented the telephone in 1876." c2: "Thomas Edison invented many important electronic devices." The outputs of the quality assessment network are: , , the final weight adjustment is: For c1; For c2.

[0040] This shows that the higher quality context c1 gets a larger weight, while the lower quality context c2 is further reduced in influence. In this way, the system is able to further highlight the impact of high-quality information while reducing the interference of low-quality or irrelevant information.

[0041] Step S4: Token-level dynamic weight. The complexity of language is reflected in the fact that different words often have different degrees of dependence on context. The DC-ACD method dynamically calculates the weight of each generated token: ,in: yes Token embedding at the moment; yes The hidden state of the moment; It is a contextual representation; is a small neural network; Implementation details: Step A, It can be designed as a multi - layer perceptron (MLP), for example: , where means concatenating these three vectors Step B, the output of the network passes through the sigmoid function and is mapped to the interval (0, 1), representing the degree of dependence of the current token on the context; Step C, in the training phase, the network can be trained in an end - to - end manner so that it learns the degree of dependence of different tokens on the context. For example, when generating the sentence "Alexander Graham Bell invented the telephone": For the token "Alexander", it may be close to 1 because it highly depends on context information For the common grammar word "了", it may be close to 0 because it mainly depends on the language knowledge of the model For the word "电话", it may be around 0.5 because it depends on both context and the prior knowledge of the model. This fine - grained weight adjustment enables the model to more precisely utilize context information, thereby generating more accurate and coherent text.

[0042] Step S5, the final decoding probability distribution. The essence of the DC - ACD method lies in its calculation of the final decoding probability distribution. Combining all the above components, the calculation of the final decoding probability distribution is as follows: Calculation of the final decoding probability distribution: , where: is the logit output of the original language model, representing the prediction of the model based on its parametric knowledge; is the token - level dynamic weight, which further refines the degree of dependence of the current token on the context; is the dynamically calculated context weight, which adjusts the importance of the overall context information; is the fused context logit, represents the additional contribution of context information relative to the prior knowledge of the model; In this way, the DC - ACD method can dynamically balance the prior knowledge and context information of the model at the token level, achieving a more precise decoding process.

[0043] Step S6, Summary,The dynamic context weight adaptive contrastive decoding (DC-ACD) method effectively solves the challenges faced by existing ACD methods in dealing with complex and noisy contexts through its unique innovative components such as dynamic weight calculation, multi-document fusion, context quality assessment, and token-level dynamic weights. This method not only significantly improves the performance and robustness of the model, but also enhances its adaptability and interpretability.

[0044] The main advantages of the DC-ACD method include: 1. Refined context utilization: By combining semantic similarity and dynamic token-level weights, more refined and accurate context information utilization is achieved.

[0045] 2. Enhanced robustness: Multi-document fusion and contextual quality assessment mechanisms improve the model’s robustness to noise and irrelevant information.

[0046] 3. Flexible adaptability: Dynamic weight calculation enables the model to flexibly respond to contexts of different types and qualities.

[0047] 4. Improved information utilization efficiency: The multi-document fusion mechanism makes full use of the rich information provided by the retrieval system.

[0048] 5. Enhanced interpretability: The interpretability of model decisions is improved through explicit contextual quality assessment and token-level weights.

[0049] The DC-ACD method is applicable to a variety of natural language processing tasks that need to incorporate external knowledge, especially when faced with potential noise or incomplete context, such as open-domain question answering, knowledge-intensive dialogue systems, fact checking and verification, personalized content generation, and other scenarios.

[0050] Embodiment 2: This embodiment provides an improved context-aware adaptive contrast decoding system, including: The dynamic weight calculation module is configured to: obtain the weight calculated by the original ACD method at time t, the semantic similarity and balance factor between the question q and the context c, and dynamically calculate the context weight; The multi-document fusion module is configured to: obtain multiple documents, fuse the multiple documents using a multi-document fusion strategy according to dynamic weights, and obtain fused context logit; The context quality assessment module is configured to: evaluate the fused context logit through a quality assessment formula; The token-level dynamic weight module is configured to: dynamically calculate the weight for each generated token to obtain the token-level dynamic weight; The final decoding probability distribution calculation module is configured as follows: ,in: is the logit output of the original language model, representing the model's prediction based on its knowledge of its parameters; It is a dynamic weight at the token level, which further refines the degree of dependence of the current token on the context; It is a dynamically calculated context weight that adjusts the importance of the overall context information; is the fused context logit, Represents the additional contribution of contextual information relative to the model’s prior knowledge.

[0051] Embodiment 3, this embodiment provides a computer-readable storage medium, the computer-readable storage medium includes a stored program, wherein when the program is running, the device where the computer-readable storage medium is located is controlled to execute a dynamic context weight adaptive contrast decoding method of embodiment 1.

[0052] Embodiment 4. This embodiment provides an electronic device, including a memory for storing computer program instructions and a processor for executing program instructions, wherein when the computer program instructions are executed by the processor, the electronic device is triggered to execute a dynamic context weight adaptive contrast decoding method of embodiment 1.

[0053] The electronic device may include: a processor, a memory and a communication unit. These components communicate via one or more buses. Those skilled in the art will appreciate that the structure of the electronic device does not limit the embodiments of the present invention, and it may be a bus structure or a star structure, or a combination of certain components, or different component arrangements.

[0054] The communication unit is used to establish a communication channel so that the electronic device can communicate with other devices, receive user data sent by other devices or send user data to other devices.

[0055] The processor is the control center of the electronic device. It uses various interfaces and lines to connect various parts of the entire electronic device. It runs or executes software programs and / or modules stored in the memory, and calls data stored in the memory to perform various functions of the electronic device and / or process data. The processor can be composed of an integrated circuit (IC), for example, it can be composed of a single packaged IC, or it can be composed of multiple packaged ICs with the same or different functions. For example, the processor can only include a central processing unit (CPU). In an embodiment of the present invention, the CPU can be a single computing core or multiple computing cores.

[0056] The memory is used to store the execution instructions of the processor. The memory can be implemented by any type of volatile or non-volatile storage device or a combination of them, 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, magnetic disk or optical disk.

[0057] When the execution instructions in the memory are executed by the processor, the electronic device is enabled to execute part or all of the steps of Embodiment 1.

[0058] The above description is only a preferred embodiment of the present invention and does not limit the present invention in other forms. Any technician familiar with the profession may use the technical content disclosed above to change or modify it into an equivalent embodiment with equivalent changes and apply it to other fields. However, any simple modification, equivalent change and modification made to the above embodiment based on the technical essence of the present invention without departing from the content of the technical solution of the present invention still falls within the protection scope of the technical solution of the present invention.

Claims

1. A dynamic context weight adaptive contrast decoding method, It is characterized in that include: Dynamic weight calculation, multi-document fusion, context quality assessment, token-level dynamic weight and final decoding probability distribution calculation; Dynamic weight calculation: obtain the weight calculated by the original ACD method at time t, the semantic similarity and balance factor between question q and context c, and dynamically calculate the context weight; Multi-document fusion: Get multiple documents, fuse them using a multi-document fusion strategy based on dynamic weights, and obtain the fused context logit; Context quality assessment: The fused context logit is evaluated using the quality assessment formula; Token-level dynamic weight: Dynamically calculate the weight of each generated token to obtain the token-level dynamic weight; The final decoding probability distribution is calculated: ,in: is the logit output of the original language model; It is the dynamic weight at the token level; is the dynamically calculated context weight; is the fused context logit.

2. A dynamic context weight adaptive contrast decoding method according to claim 1, It is characterized in that The dynamic calculation of context weights includes: the dynamic weight at time t is the weight calculated by the original ACD method at time t plus the A value, the A value is the semantic similarity between the question q and the context c multiplied by the B value, and the B value is 1 minus the value of the balance factor.

3. The dynamic context weight adaptive contrast decoding method according to claim 1, It is characterized in that The dynamic weight calculation formula is: in: represents the dynamic weight at time t; is the weight calculated by the original ACD method at time t; Represents the semantic similarity between question q and context c; is a balancing factor tuned through the validation set.

4. The dynamic context weight adaptive contrast decoding method according to claim 1, It is characterized in that The multi-document fusion strategy includes: in: is the fused contextual logit; Indicates The weight of a document; It is based on The logit of the document.

5. The dynamic context weight adaptive contrast decoding method according to claim 1, It is characterized in that The weight of each generated token is dynamically calculated: ,in, yes Token embedding at the moment; yes The hidden state of the moment; It is a contextual representation; It is a small neural network.

6. A dynamic context weight adaptive contrast decoding method according to claim 1, It is characterized in that The quality assessment formula is: ; Designed as a small neural network.

7. A dynamic context weighted adaptive contrast decoding system, It is characterized in that include: The dynamic weight calculation module is configured to: obtain the weight calculated by the original ACD method at time t, the semantic similarity and balance factor between the question q and the context c, and dynamically calculate the context weight; The multi-document fusion module is configured to: obtain multiple documents, fuse the multiple documents using a multi-document fusion strategy according to dynamic weights, and obtain fused context logit; The context quality assessment module is configured to: evaluate the fused context logit through a quality assessment formula; The token-level dynamic weight module is configured to: dynamically calculate the weight for each generated token to obtain the token-level dynamic weight; The final decoding probability distribution calculation module is configured as follows: ,in: is the logit output of the original language model; It is the dynamic weight at the token level; is the dynamically calculated context weight; is the fused context logit.

8. A computer-readable storage medium, It is characterized in that The computer-readable storage medium includes a stored program, wherein when the program is running, the device where the computer-readable storage medium is located is controlled to execute a dynamic context weight adaptive contrast decoding method as described in any one of claims 1-6.

9. An electronic device, It is characterized in that It comprises a memory for storing computer program instructions and a processor for executing the program instructions, wherein when the computer program instructions are executed by the processor, an electronic device is triggered to execute a dynamic context weight adaptive contrast decoding method as described in any one of claims 1-6.

Citation Information

Patent Citations

  • Accurate text representation method based on neural network self-attention mechanism

    CN113961706A

  • Image description generation method and system based on multi-layer decoder dynamic fusion network

    CN117392674A

  • Large-model low-illusion text generation method and system based on notional word uncertainty

    CN118395977A

  • Text processing method and device for improving information retrieval and generation quality and computer system

    CN118535710A

  • Dynamic coattention network for question answering

    US20180129938A1

Cited By

  • Large-model psychological diagnosis and treatment information analysis enhancement method based on lexical diversity

    CN119739846A

  • Method for enhancing mental health diagnosis and treatment information analysis based on lexical diversity of large model

    CN119739846B

  • Large model prediction method and device and electronic equipment

    CN120849628A