Method for realizing multi-model parameterized knowledge editing through ensemble learning
Through the integrated learning method, the dynamic weighting mechanism of the plug-in model and large language model is adopted, combined with the search space zero initialization and target enhancement strategy, the inconsistency problem of multi-model knowledge editing is solved, and stable and efficient knowledge update is achieved.
Patent Information
- Application Number
- CN202510514901.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-23
- Publication Date
- 2025-07-25
AI Technical Summary
The existing knowledge editing method can only modify a single large language model, and is not suitable for complex scenarios where multiple large language models need to be updated at the same time. It is highly sensitive to hyperparameter settings, resulting in inconsistent editing effects.
Through integrated learning, multi-model parameterized knowledge editing is realized, and the dynamic weighting mechanism of plug-in models and large language models is adopted, combining search space zero initialization and target enhancement strategies to integrate and decode knowledge.
Seamless and stable knowledge editing across multiple large language models is achieved, improving editing accuracy and generalization capabilities, avoiding the dominance of the central model, and reducing the sensitivity of hyperparameter settings.
Smart Images

Figure CN120373437A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of large model knowledge editing in the field of natural language processing, and specifically relates to a method for realizing multi-model parameterized knowledge editing through ensemble learning. Background Art
[0002] Large Language Models (LLMs) have demonstrated excellent performance in various downstream tasks by expanding the scale of parameters and training data, thereby capturing a wide range of world knowledge during pre-training. However, due to the dynamic changes in real-world information, the internal parameterized knowledge of large language models gradually becomes outdated, leading to errors and hallucinations, which hinders the practical applications of large language models. For example, outdated drug dosage information in a medical diagnosis scenario may cause serious consequences. Therefore, Knowledge Editing emerges as a promising alternative to retraining, providing an efficient way to update model knowledge. These techniques enable the integration of growing knowledge into the model by allowing modifications to specific parameters. Traditional full-parameter fine-tuning schemes can update knowledge, but they are difficult to be practical due to the huge consumption of computing resources, the risk of catastrophic forgetting, and the risk of overfitting, and they cannot achieve precise local knowledge updates. This contradiction has spawned the exploration of knowledge editing techniques, whose core goal is to insert, modify, or erase specific knowledge through lightweight and high-precision parameter intervention without destroying the overall capabilities of large language models, such as the literature (Huang Y, Feng X, Li B, et al. Ensemble learning for heterogeneous large language models with deep parallel collaboration[J]. Advances in Neural Information Processing Systems, 2024, 37: 119838-119860.).
[0003] In recent years, researchers have proposed various knowledge editing methods for large language models, using techniques such as meta-learning, post-localization editing strategies, and memory-based methods to update model knowledge while preserving irrelevant facts. However, existing knowledge editing methods mainly focus on modifying a single large language model, which makes them unsuitable for complex scenarios that require simultaneous updating of multiple large language models. In addition, these methods are highly sensitive to hyperparameter settings, resulting in significant inconsistencies in editing effects, which limits their scalability and adaptability to new large language models. Summary of the Invention
[0004] The objective of the present invention is to solve the problem that existing knowledge editing methods can only modify a single large language model and are not applicable to complex scenarios that require simultaneous updating of multiple large language models, and thus a method for multi-model parametric knowledge editing through ensemble learning is proposed.
[0005] The technical solution adopted by the present invention to solve the above technical problems is: a method for multi-model parametric knowledge editing through ensemble learning, the method specifically includes the following steps:
[0006] Step 1: Use the input text as the input of the plug-in model to obtain the output of the plug-in model;
[0007] The output of the plug-in model includes the output probability distribution corresponding to the input text and the editing weight corresponding to the input text;
[0008] Step 2: Use the input text as the input of the large language model to obtain the probability distribution output by the large language model;
[0009] Step 3: According to the editing weight output by the plug-in model, integrate the probability distribution output by the plug-in model and the probability distribution output by the large language model;
[0010] Then obtain the output text corresponding to the input text according to the integrated probability distribution.
[0011] Further, the plug-in model is an SLM.
[0012] Further, the training process of the plug-in model is as follows:
[0013] Step 1: Obtain the knowledge set S to be updated E , the knowledge set S E includes various text pairs, and each text pair includes an input text x and an expected output text y;
[0014] Step 2: Add a marker [WEIGHT] to the vocabulary of the plug-in model, use the input text x as the input of the plug-in model, and calculate the loss function according to the output of the plug-in model
[0015] Step 3: According to the loss function and the full fine-tuning strategy, update the parameters of the plug-in model in reverse until the loss function converges and stops training to obtain the trained plug-in model.
[0016] Further, the loss function is:
[0017]
[0018] Wherein, The loss function representing the output learning task of the plug-in model;
[0019] The loss function representing the editing weight learning task of the plug-in model;
[0020] λ represents a hyperparameter;
[0021]
[0022] where θ represents the parameters of the plug-in model;
[0023] f θ f(y|x) represents the probability that the plug-in model outputs the expected text y when the text x is used as the input of the plug-in model;
[0024] E(·) represents taking the expected value;
[0025] z represents the editing label of the text x;
[0026] log it ω logit(x) represents the logits value of the plug-in model at the [WEIGHT] position when the text x is used as the input of the plug-in model;
[0027] φ(·) represents the sigmoid function, and the output of the sigmoid function is used as the editing weight of the text x;
[0028] BCE(·) represents the binary cross-entropy loss function.
[0029] Furthermore, integrating the probability distribution output by the plug-in model and the probability distribution output by the large language model according to the editing weight output by the plug-in model; the specific process is as follows:
[0030] Step Three - One: Use the common words in the vocabulary of the plug-in model and the vocabulary of the large language model as anchor words, and denote the number of anchor words as |A|;
[0031] Step Three - Two: Calculate the relative transition matrix R of the plug-in model S and the relative transition matrix R of the large language model l , |V S | represents the number of words in the vocabulary of the plug-in model, |V l | represents the number of words in the vocabulary of the large language model;
[0032] Step Three - Three: Weightedly fuse the probability distributions output by the plug-in model and the large language model according to the relative transition matrix R S and the relative transition matrix R l to obtain the integrated output probability distribution
[0033] Steps three and four: Convert into a one-hot vector
[0034] Steps three and five: According to the one-hot vector and R l search for the optimal output probability distribution p d ;
[0035] Steps three and six: Obtain the output text according to the optimal output probability distribution p d and the vocabulary of the large language model.
[0036] Furthermore, the specific process of step three and three is:
[0037]
[0038] where α represents the editing weight output by the plug-in model;
[0039] p s represents the probability distribution output by the plug-in model;
[0040] p l represents the probability distribution output by the large language model;
[0041] represents the integrated output probability distribution.
[0042] Furthermore, the specific process of step three and four is
[0043]
[0044] where represents the j-th element in represents the one-hot vector the i-th element in
[0045] Furthermore, the gradient descent method is adopted in step three and five, and the specific process of step three and five is:
[0046] Step three and five one: Initialize the integrated output probability distribution representation as a zero vector, and set the maximum number of iterations to T;
[0047] Step three and five two: Let the iteration number t = 0;
[0048] Step three and five three: Calculate the updated representation of the output probability distribution
[0049]
[0050] Among them, represents the KL divergence;
[0051] η represents a hyperparameter;
[0052] Step three five four: Determine whether t = T is satisfied:
[0053] If not satisfied, let t = t + 1, and return to execute step three five three;
[0054] If satisfied, then use the obtained in the last iteration as the optimal output probability distribution p d .
[0055] The beneficial effects of the present invention are:
[0056] By introducing a dynamic weight mechanism and using [WEIGHT] tags to predict the weight assignment of each instance, the present invention can ensure the effective utilization of knowledge in the ensemble model while the update of new knowledge will not affect irrelevant information. The present invention also proposes an ensemble enhancement mechanism by combining the strategies of zero initialization of the search space and target enhancement. By starting the decoding search with a zero vector instead of the distribution of the central model and preferentially selecting tags with higher probability values in the fusion distribution for decoding, it ensures that the decoding process is driven by the fusion knowledge, avoids the central large model dominating the integration result, and improves the accuracy and generalization ability of knowledge editing.
[0057] Moreover, the method of the present invention can perform knowledge transfer across multiple large language models, thereby achieving seamless and stable knowledge editing. BRIEF DESCRIPTION OF THE DRAWINGS
[0058] Figure 1 is a flowchart of a method for realizing multi-model parametric knowledge editing through ensemble learning according to the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0059] Detailed Description One: Combine Figure 1 to illustrate this embodiment. A method for realizing multi-model parametric knowledge editing through ensemble learning described in this embodiment specifically includes the following steps:
[0060] Step One: Use the input text as the input of the plug-in model to obtain the output of the plug-in model;
[0061] The output of the plug-in model includes the output probability distribution corresponding to the input text and the editing weight corresponding to the input text;
[0062] Step Two: Use the input text as the input of the large language model to obtain the probability distribution output by the large language model;
[0063] Step 3: Integrate the probability distribution output by the plug-in model and the probability distribution output by the large language model according to the editing weights output by the plug-in model;
[0064] Then, obtain the output text corresponding to the input text according to the integrated probability distribution.
[0065] In the editing stage, in order to effectively promote the update of multi-model knowledge, the small model as an editing plug-in plays a crucial role. The present invention first adopts a simple and effective full-fine-tuning strategy to update the knowledge in the plug-in model. Since the plug-in model is relatively small, the related computational cost is kept within a controllable range. However, full fine-tuning usually leads to a significant degradation of the original knowledge of the model. Therefore, the present invention introduces a dynamic weighting mechanism that adaptively adjusts the contribution of each model in the integration stage according to the given input. Specifically, the present invention introduces a special token [WEIGHT] in the vocabulary of the plug-in model, which helps to distinguish the knowledge that needs to be modified from the knowledge that should remain unchanged. Therefore, for editing-related inputs, the plug-in model is given a higher weight, while for non-editing-related inputs, the large language model dominates. To effectively train [WEIGHT], not only the fine-tuning model needs to be modified on the target knowledge, but also a set of irrelevant knowledge needs to be introduced as a reference group to guide the model to distinguish between editing-related and non-editing-related knowledge. Finally, the present invention adopts a multi-task learning method to jointly train the plug-in model.
[0066] In the integration stage, the present invention selects the words common between the plug-in model and the large language model as the anchor words and calculates the corresponding relative transition matrix. At each decoding step, the integrated model maps the output distribution to the relative space using the corresponding relative transition matrix and then fuses it with the weighted contribution to obtain the aggregated distribution. Once the aggregated distribution is obtained, the present invention uses the large language model as the decoding model. Following the DEEPEN framework, the present invention uses the gradient descent method to search for the optimal output distribution in the vocabulary space of the large language model to ensure that the aggregated distribution is accurately represented. However, if the output distribution of the LLM is directly used for initialization search, treating the aggregated distribution as a perturbation to the original output of the LLM may cause bias in the large central model, resulting in the integrated output being overly dependent on the knowledge of the LLM. In the context of knowledge editing, the plug-in model and the LLM usually exhibit significant distribution differences, and using the original distribution of the LLM for initialization may not effectively capture the newly injected knowledge. Therefore, the present invention proposes an integration enhancement mechanism including two strategies: zero initialization of the search space and target enhancement, to better align the decoding distribution with the aggregated distribution. These two strategies together help the final decoding distribution better capture the partial order relationship in the aggregated distribution, thus more effectively representing the new knowledge.
[0067] The method of the present invention simultaneously solves the problem that the traditional method is highly sensitive to the setting of hyperparameters, resulting in significant inconsistencies in the editing effect.
[0068] Specific Embodiment 2: The difference between this embodiment and Specific Embodiment 1 is that the plug-in model is SLM.
[0069] Other steps and parameters are the same as those in Specific Embodiment 1.
[0070] The plug-in model SLM (Small Language Model, SLM) is a small language model. For example, the number of parameters of TinyLlama is about 1.1B.
[0071] Specific Embodiment 3: The difference between this embodiment and Specific Embodiment 1 or 2 is that the training process of the plug-in model is as follows:
[0072] Step 1: Obtain the knowledge set S to be updated E , the knowledge set S E includes various text pairs, and each text pair includes an input text x and an expected output text y;
[0073] Step 2: Add a marker [WEIGHT] to the vocabulary of the plug-in model, use the input text x as the input of the plug-in model, and calculate the loss function according to the output of the plug-in model
[0074] Step 3: According to the loss function and the full fine-tuning strategy, update the parameters of the plug-in model in reverse until the loss function converges and stops training to obtain the trained plug-in model.
[0075] Other steps and parameters are the same as those in Specific Embodiment 1 or 2.
[0076] Specific Embodiment 4: The difference between this embodiment and one of Specific Embodiments 1 to 3 is that the loss function is:
[0077]
[0078] Among them, represents the loss function of the output learning task of the plug-in model;
[0079] represents the loss function of the editing weight learning task of the plug-in model;
[0080] λ represents a hyperparameter (used to balance the contributions of the two learning tasks);
[0081]
[0082] Among them, θ represents the parameters of the plug-in model;
[0083] f θ f(y|x) represents the probability that the plug-in model outputs the expected text y when the text x is used as the input of the plug-in model;
[0084] E(·) represents taking the expected value;
[0085] z represents the edit label of the text x (instances related to editing are assigned a value of 1, and instances not related to editing are assigned a value of 0);
[0086] log it ω logit(x) represents the logits value of the plug-in model at the [WEIGHT] position when the text x is used as the input of the plug-in model;
[0087] φ(·) represents the sigmoid function, and the output of the sigmoid function is used as the edit weight of the text x;
[0088] BCE(·) represents the binary cross-entropy loss function.
[0089] Other steps and parameters are the same as those in any one of the first to third specific embodiments.
[0090] Specific embodiment five: The difference between this embodiment and any one of the first to fourth specific embodiments is that the probability distribution output by the plug-in model and the probability distribution output by the large language model are integrated according to the edit weight output by the plug-in model; the specific process is as follows:
[0091] Step three one: Use the common words in the vocabulary of the plug-in model and the vocabulary of the large language model as anchor words, and record the number of anchor words as |A|;
[0092] Step three two: Calculate the relative transition matrix R of the plug-in model S and the relative transition matrix R of the large language model l , |V S | represents the number of words in the vocabulary of the plug-in model, and |V l | represents the number of words in the vocabulary of the large language model;
[0093] In the relative transition matrix R S , calculate the distance between each word in the vocabulary of the plug-in model and the first anchor word respectively, and use the distance between each word and the first anchor word as the first row of the relative transition matrix R S , and similarly, the relative transition matrix R S and the relative transition matrix R l can be obtained;
[0094] Step 33: Map the output distribution to the relative space using the relative transfer matrix, and then perform weighted contribution fusion to obtain the integrated aggregated distribution, that is, according to the relative transfer matrix R S and the relative transfer matrix R l perform weighted fusion on the probability distributions output by the plug-in model and the large language model to obtain the integrated output probability distribution
[0095] Step 34: Convert into a one-hot vector
[0096] Step 35: According to the one-hot vector and R l search for the optimal output probability distribution p d in the vocabulary space;
[0097] Step 36: Obtain the output text according to the optimal output probability distribution p d and the vocabulary of the large language model, that is, search for the output text from the vocabulary of the large language model according to the obtained optimal output probability distribution p d Other steps and parameters are the same as those in one of the specific embodiments 1 to 4.
[0098] Other steps and parameters are the same as those in one of the specific embodiments 1 to 4.
[0099] Specific embodiment 6: The difference between this embodiment and one of the specific embodiments 1 to 5 is that the specific process of the said step 33 is as follows:
[0100]
[0101]
[0102] p s represents the probability distribution output by the plug-in model;
[0103] p l represents the probability distribution output by the large language model;
[0104] represents the integrated output probability distribution.
[0105] Other steps and parameters are the same as those in one of the specific embodiments 1 to 5.
[0106] To avoid the problem of significant degradation of the original knowledge of the large language model, the present invention adopts a dynamic weighting mechanism to adaptively adjust the contribution of each model during the integration stage. For editing-related inputs, the plug-in model is given a higher weight; while for non-editing-related inputs, the large language model dominates.
[0107] Specific Embodiment VII: The difference between this embodiment and any one of Embodiments I to VI is that the specific process of Step 34 is as follows
[0108]
[0109] wherein, represents the j-th element in (only the element corresponding to the largest element in in is 1, otherwise it is 0), represents the i-th element of the one-hot vector , and the one-hot vector is a vector with the same length as .
[0110] Other steps and parameters are the same as those in any one of Embodiments I to VI.
[0111] Specific Embodiment VIII: The difference between this embodiment and any one of Embodiments I to VII is that Step 35 adopts the gradient descent method, and the specific process of Step 35 is as follows:
[0112] Step 351: Initialize the output probability distribution representation of the ensemble as a zero vector, and set the maximum number of iterations to T;
[0113] Step 352: Let the iteration number t = 0;
[0114] Step 353: Calculate the updated representation of the output probability distribution
[0115]
[0116] wherein, represents the KL divergence;
[0117] η represents a hyperparameter (referred to as the relative learning rate);
[0118] Step 354: Determine whether t = T is satisfied:
[0119] If not, let t = t + 1, and return to execute Step 353;
[0120] If satisfied, take the obtained in the last iteration as the optimal output probability distribution p d .
[0121] Other steps and parameters are the same as those in any one of Embodiments I to VII.
[0122] The present invention initializes the search space to zero and converts the aggregated distribution into a one-hot vector (i.e., the target enhancement strategy). These two strategies can jointly help the final decoded distribution better capture the partial order relationship in the aggregated distribution, so as to better align the decoded distribution with the aggregated distribution, thereby more effectively representing new knowledge. At the same time, the present invention can avoid the integrated output being overly dependent on the knowledge of the LLM, enabling the LLM to effectively capture the newly injected knowledge.
[0123] The above examples of the present invention are only for illustrating in detail the calculation model and calculation process of the present invention, rather than limiting the implementation manner of the present invention. For those of ordinary skill in the art, other different forms of changes or modifications can be made based on the above description. It is impossible to enumerate all the implementation manners here. Any obvious changes or modifications derived from the technical solution of the present invention still fall within the protection scope of the present invention.
Claims
1. A method for realizing multi-model parametric knowledge editing through ensemble learning, characterized in that, The method specifically includes the following steps: Step 1: Use the input text as the input of the plug-in model to obtain the output of the plug-in model; The output of the plug-in model includes the output probability distribution corresponding to the input text and the editing weight corresponding to the input text; Step 2: Use the input text as the input of the large language model to obtain the probability distribution output by the large language model; Step 3: Integrate the probability distribution output by the plug-in model and the probability distribution output by the large language model according to the editing weight output by the plug-in model; Then obtain the output text corresponding to the input text according to the integrated probability distribution.
2. The method for realizing multi-model parameterized knowledge editing through ensemble learning according to claim 1, characterized in that The plug-in model is SLM.
3. The method for realizing multi-model parametric knowledge editing through ensemble learning according to claim 2, wherein The training process of the plug-in model is as follows: Step 1, obtain the knowledge set S to be updated E , the knowledge set S E includes various text pairs, and each text pair includes an input text x and an expected output text y; Step 2: Add a tag [WEIGHT] to the vocabulary of the plug-in model, take the input text x as the input of the plug-in model, and calculate the loss function according to the output of the plug-in model Step 3. According to the loss function and the full fine-tuning strategy, update the parameters of the plug-in model in reverse until the loss function converges, then stop training to obtain the trained plug-in model.
4. A method for realizing multi-model parameterized knowledge editing through ensemble learning according to claim 3, characterized in that The loss function is as follows: Among them, represents the loss function of the output learning task of the plug-in model; Represents the loss function for the editing weight learning task of the plug-in model; λ represents a hyperparameter; Among them, θ represents the parameters of the plug-in model; f θ (y|x) represents the probability that when the text x is input to the plug-in model, the plug-in model outputs the expected text y; E(·) represents taking the expected value; z represents the editing label of text x; logit ω (x) represents the logits value of the plug-in model at the position of [WEIGHT] when the text x is used as the input of the plug-in model; φ(·) represents the sigmoid function, and the output of the sigmoid function is used as the editing weight of text x; BCE(·) represents the binary cross-entropy loss function.
5. A method for realizing multi-model parameterized knowledge editing through ensemble learning according to claim 4, characterized in that, The integrating of the probability distribution output by the plug-in model and the probability distribution output by the large language model according to the editing weight output by the plug-in model; the specific process is as follows: Step 3-1: Use the common words in the vocabulary of the plug-in model and the vocabulary of the large language model as the anchor words, and record the number of anchor words as |A|; Step 32: Calculate the relative transition matrix R of the plug-in model S and the relative transition matrix R of the large language model l , |V S | represents the number of words in the vocabulary of the plug-in model, |V l | represents the number of words in the vocabulary of the large language model; Step 3: Based on the relative transition matrix R S and the relative transition matrix R l perform weighted fusion on the probability distributions output by the plug-in model and the large language model to obtain the integrated output probability distribution Step 3 and 4: Convert into a one-hot vector Step 35: According to the one-hot vector and R l search for the optimal output probability distribution p d ; Step 36. Obtain the output text according to the optimal output probability distribution p d and the vocabulary of the large language model.
6. A method for realizing multi-model parameterized knowledge editing through ensemble learning according to claim 5, characterized in that The specific process of Step 3-3 is as follows: Among them, α represents the editing weight output by the plug-in model; p s represents the probability distribution output by the plug-in model; p l represents the probability distribution output by the large language model; Represents the output probability distribution after integration.
7. A method for realizing multi-model parametric knowledge editing through ensemble learning according to claim 6, characterized in that The specific process of Step 3-4 is Among them, represents the j-th element in represents the one-hot vector the i-th element in 8. A method for realizing multi-model parametric knowledge editing through ensemble learning according to claim 7, characterized in that, Step 3-5 uses the gradient descent method, and the specific process of Step 3-5 is as follows: Step 351. Initialize the output probability distribution representation of the integration as a zero vector, and set the maximum number of iterations to T; Step 3-5-2: Let the iteration number t = 0; Step 353: Calculate the updated representation of the output probability distribution Among them, represents the KL divergence; η represents a hyperparameter; Step 3-5-4: Judge whether t = T is satisfied: If not, let t = t + 1, and return to execute Step 3-5-3; If satisfied, then use the obtained in the last iteration as the optimal output probability distribution p d .