A dynamic context weight adaptive contrast decoding method and system
Through the dynamic context weight adaptive contrast decoding method, combined with semantic similarity and multi-document fusion, the problems of insufficient context information utilization and insufficient noise robustness in the prior art are solved, and more efficient and interpretable text generation is achieved.
Patent Information
- Application Number
- CN202411266078.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-11
- Publication Date
- 2025-02-21
- Estimated Expiration
- 2044-09-11
AI Technical Summary
Existing adaptive contrast decoding methods ignore the semantic correlation between context and problem when dealing with complex and diverse tasks, fail to fully utilize information in multiple related documents, and are robust to noise and irrelevant information. Insufficient sex.
A dynamic context weight adaptive contrast decoding method (DC-ACD) is proposed, which achieves more refined and accurate context information utilization through dynamic weight calculation, multi-document fusion, context quality evaluation and token-level dynamic weights.
It improves the generation performance and robustness of the model in complex scenarios, enhances its resistance to noise and irrelevant information, and improves the interpretability of model decisions.
Smart Images

Figure CN118779833B_ABST
Abstract
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:
[0007] 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;
[0008] 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;
[0009] Multi-document fusion: Get multiple documents, fuse them using a multi-document fusion strategy based on dynamic weights, and obtain the fused context logit;
[0010] Context quality assessment: The fused context logit is evaluated using the quality assessment formula;
[0011] Token-level dynamic weight: Dynamically calculate the weight of each generated token to obtain the token-level dynamic weight;
[0012] The final decoding probability distribution is calculated:
[0013] ,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.
[0014] 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.
[0015] Furthermore, the dynamic weight calculation formula is:
[0016]
[0017] 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.
[0018] Furthermore, the multi-document fusion strategy includes:
[0019]
[0020] in: is the fused contextual logit; Indicates The weight of a document; It is based on The logit of the document.
[0021] 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.
[0022] Furthermore, the quality assessment formula is: ; Designed as a small neural network.
[0023] In a second aspect, the present invention provides a dynamic context weight adaptive contrast decoding system, comprising:
[0024] 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;
[0025] 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;
[0026] The context quality assessment module is configured to: evaluate the fused context logit through a quality assessment formula;
[0027] The token-level dynamic weight module is configured to: dynamically calculate the weight for each generated token to obtain the token-level dynamic weight;
[0028] The final decoding probability distribution calculation module is configured as follows:
[0029] ,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.
[0030] 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.
[0031] 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.
[0032] Compared with the prior art, the advantages and positive effects of the present invention are:
[0033] 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.
[0034] 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.
[0035] 3. The DC-ACD method provided by the present invention achieves more sophisticated and flexible use of contextual information by introducing multi-dimensional innovative strategies, thereby further improving the generation performance and robustness of the model in complex scenarios. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] 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.
[0037] Figure 1 A schematic diagram of a flow chart of a dynamic context weight adaptive contrast decoding method of the present invention. DETAILED DESCRIPTION
[0038] 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.
[0039] 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 than those described herein. Therefore, the present invention is not limited to the specific embodiments of the following disclosure.
[0040] Embodiment 1, as Figure 1 As shown, this embodiment proposes a dynamic context-weighted adaptive contrastive decoding method (Dynamic Context-Weighted Adaptive Contrastive Decoding, DC-ACD), which aims to solve some key problems in the existing retrieval-augmented generation (RAG) technology. The DC-ACD method effectively balances the model's prior knowledge and contextual information through multiple carefully designed components, achieving a more accurate and flexible text generation process.
[0041] Step S1, dynamic weight calculation. The core innovation of the DC-ACD method lies in its dynamic weight calculation mechanism. The traditional adaptive contrast decoding (ACD) method only relies on entropy value to adjust the context weight, but ignores the important factor of semantic relevance. To solve this problem, this embodiment introduces a new dynamic weight calculation formula:
[0042]
[0043] in: represents the dynamic weight at time t;
[0044] is the weight calculated by the original ACD method at time t;
[0045] Represents the semantic similarity between question q and context c;
[0046] is a balancing factor that can be tuned through the validation set;
[0047] This formula combines entropy and semantic similarity to make weight calculation more comprehensive and accurate. The calculation of
[0048] is carried out using the following method, which is based on entropy value calculation. The entropy value calculation process of the ACD method is as follows:
[0049] 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 question - answering task), y<t represents the sequence generated before time t, and c is the context information.
[0050] Calculate the entropy of these two probability distributions:
[0051] , and
[0052] , where the summation is carried out over all tokens in the vocabulary.
[0053] Calculate the difference in entropy:
[0054] Use the sigmoid function to map the entropy difference to the interval (0, 1) to obtain :
[0055] where, is the weight calculated at time t, which reflects the degree of contribution of context information to reducing the uncertainty of the model. When ΔH is large, it means that the context significantly reduces the uncertainty of the model, and at this time is close to 1; otherwise, it is close to 0.
[0056] while can be calculated using a pre - trained semantic matching model (such as BERT, RoBERTa, etc.). The calculation steps are as follows:
[0057] Step S11, input the question q and the context c into the pre - trained model respectively to obtain their vector representations;
[0058] Step S12, calculate the cosine similarity of these two vectors as the value of ;
[0059] To better understand the role of this formula, this embodiment provides a specific example. Suppose there is a question "Who invented the telephone?", and the retrieval system returns two paragraphs of context:
[0060] c1: "Alexander Graham Bell invented the telephone in 1876."
[0061] c2: "Thomas Edison invented many important electronic devices."
[0062] Calculated using the semantic matching model: and , assuming , ,but:
[0063] (for c1)
[0064] (for c2)
[0065] 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.
[0066] 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:
[0067] in: is the fused contextual logit; Indicates The weight of a document; It is based on The logit of the document.
[0068] 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:
[0069] 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.
[0070] Step b: For each document, calculate the ACD score ;
[0071] Step c, finally, the logit weighted sum of all documents is obtained .
[0072] 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:
[0073]
[0074] Then, suppose that at a certain time step t, the logits corresponding to these three documents are:
[0075] , , The fused logit is:
[0076] 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.
[0077] 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:
[0078] a) Designed as a small neural network, for example a two-layer feedforward network:
[0079] ,in , , , are learnable parameters.
[0080] 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.
[0081] c) Output of the network After the sigmoid function Mapped to the (0,1) interval.
[0082] d) During the training phase, manually annotated contextual quality labels can be used to supervise the training network
[0083] This embodiment is shown through an example, assuming that for the two previous contexts:
[0084] c1: "Alexander Graham Bell invented the telephone in 1876."
[0085] c2: "Thomas Edison invented many important electronic devices."
[0086] The outputs of the quality assessment network are: , , the final weight adjustment is:
[0087] For c1; For c2.
[0088] 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.
[0089] 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:
[0090] yes Token embedding at the moment;
[0091] yes The hidden state of the moment;
[0092] It is a contextual representation;
[0093] is a small neural network;
[0094] Implementation details: Step A, It can be designed as a multi-layer perceptron (MLP), for example:
[0095] ,in It means concatenating these three vectors.
[0096] Step B, the output of the network is passed through the sigmoid function Mapped to the (0,1) interval, it indicates the degree of dependence of the current token on the context;
[0097] Step C: In the training phase, training can be done in an end-to-end manner. The network learns how much different tokens depend on the context. For example, suppose when generating the sentence "Alexander Graham Bell invented the telephone":
[0098] For the token "Alexander", It may be close to 1 because it highly depends on context information
[0099] For the common grammatical word "了" it may be close to 0 because it mainly depends on the language knowledge of the model
[0100] 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 utilize context information more precisely, thus generating more accurate and coherent text.
[0101] Step S5, the final decoding probability distribution. The essence of the DC-ACD method lies in the calculation of its final decoding probability distribution. Combining all the above components, the calculation of the final decoding probability distribution is as follows:
[0102] Calculation of the final decoding probability distribution:
[0103] , 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 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;
[0104] In this way, the DC-ACD method can dynamically balance the prior knowledge of the model and context information at the token level, achieving a more precise decoding process.
[0105] Step S6, summary. The Dynamic Context Weight Adaptive Contrastive Decoding (DC-ACD) method effectively addresses 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.
[0106] The main advantages of the DC-ACD method include: First, refined context utilization: By combining semantic similarity and dynamic token-level weights, it realizes a more refined and accurate utilization of context information.
[0107] Second, enhanced robustness: The multi-document fusion and context quality assessment mechanisms improve the robustness of the model against noise and irrelevant information.
[0108] 3. Flexible adaptability: Dynamic weight calculation enables the model to flexibly respond to contexts of different types and qualities.
[0109] 4. Improved information utilization efficiency: The multi-document fusion mechanism makes full use of the rich information provided by the retrieval system.
[0110] 5. Enhanced interpretability: The interpretability of model decisions is improved through explicit contextual quality assessment and token-level weights.
[0111] 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.
[0112] Embodiment 2: This embodiment provides an improved context-aware adaptive contrast decoding system, including:
[0113] 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;
[0114] 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;
[0115] The context quality assessment module is configured to: evaluate the fused context logit through a quality assessment formula;
[0116] The token-level dynamic weight module is configured to: dynamically calculate the weight for each generated token to obtain the token-level dynamic weight;
[0117] The final decoding probability distribution calculation module is configured as follows:
[0118] ,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.
[0119] 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.
[0120] 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.
[0121] 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.
[0122] 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.
[0123] 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.
[0124] 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.
[0125] 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.
[0126] 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, 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, 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. A dynamic context weight adaptive contrast decoding method according to claim 1, 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. A dynamic context weight adaptive contrast decoding method according to claim 1, 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. A dynamic context weight adaptive contrast decoding method according to claim 1, 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, characterized in that: The quality assessment formula is: ; Designed as a small neural network.
7. A dynamic context weighted adaptive contrast decoding system, 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, 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, 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