Large language model knowledge editing method based on data enhancement
By using causal mediation analysis and data augmentation techniques to locate target neurons, the problem of balancing locality and generalization ability in knowledge editing of large language models is solved, achieving efficient knowledge editing and maintaining model generation capabilities.
Patent Information
- Application Number
- CN202511331185.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-17
- Publication Date
- 2026-02-10
AI Technical Summary
Existing large language models struggle to maintain edit locality during knowledge editing, and existing methods struggle to balance maintaining model generation and generalization capabilities.
The target neuron is located through causal mediation analysis, fine-tuned using data augmentation techniques, and the loss function is constrained to keep the model's performance unchanged on irrelevant knowledge. Only the parameters of the target neuron are modified.
It achieves efficient knowledge editing, maintains a balance between model generation and generalization capabilities, reduces overfitting, and improves the editing locality and specificity of the model.
Smart Images

Figure CN121503602A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to artificial intelligence technology, and more particularly to a method for editing knowledge of a large language model based on data augmentation. Background Technology
[0002] Pre-trained large language models have been widely used as general-purpose knowledge bases in various fields; however, some knowledge within these models may change over time. Currently, there is considerable research on model editing. These works can be divided into two categories: adding additional information to a frozen model at some point and directly modifying the model's parameters. The former focuses on determining when and what information should be input into the model, relying on intuitive strategies, such as determining the specific location of the edit within the model through intuitive performance comparisons. Methods focusing on editing model parameters can be categorized into three types: fine-tuning-based methods, meta-learning-based methods, and optimization-based methods. While the first two methods face the problem of overfitting and struggle to balance generalization and specificity, they are similar to editing a frozen model in terms of "edit location," primarily focusing on obtaining better parameters.
[0003] The optimization-based approach divides the model editing task into two sub-problems: parameter selection and parameter editing. To determine the editing location, a "causal tracing" approach is introduced to analyze the correlation between knowledge and parameters. Considering the crucial role of the position of the last subject character in the model, they transform the editing task into an optimization task. While ROME and MEMIT offer some explanation for where the model stores knowledge, significant ambiguity remains requiring further exploration.
[0004] Existing methods primarily focus on the reliability of editing, often neglecting means to maintain edit locality, i.e., keeping irrelevant knowledge unaffected. A typical strategy is to limit the range of weight variations. This greatly helps maintain the model's generative ability, but it lacks explanation in terms of maintaining edit locality. One important reason is the difficulty in determining whether knowledge is irrelevant, making it hard to design explicit methods to control it. Summary of the Invention
[0005] The technical problem to be solved by the present invention is to provide a knowledge editing method for large language models based on data augmentation, which addresses the shortcomings of the existing technology.
[0006] The technical solution adopted by this invention to solve its technical problem is: a knowledge editing method for large language models based on data augmentation, comprising the following steps: 1) Locating the target neuron in the model; The target neuron is a neuron that makes a high contribution to the specified knowledge; The target neuron was located using causal mediation analysis, as follows: The contribution of each neuron is measured by calculating the indirect influence (IE) of each neuron on knowledge prediction through three inferences. Noiseless reasoning: using knowledge clues (can be described as) Subject-Predicate Form Input Model In this process, the set of internal states in each layer of the MLP is obtained: ; Where L is the total number of layers in the model, and S is the total number of neurons. Indicates the first The internal state of neuron i in layer i; Noisy inference: Adding noise to the entire cue word in the model's embedding layer. And record the probability that the model generates the correct result at this time. ; in, To inject random noise into the embedding layer; This represents the probability that the model generates the correct result under noisy inference. Noisy replacement inference: Based on noisy inference, the activation values of the MLP internal states that have been affected by noise are sequentially replaced with the original noise-free activation values. The positions of the replaced activation values are denoted as... ,in, Indicates the layer number of the MLP. This represents the neuron index in the MLP; after the record is replaced, the probability of the model predicting the correct result is obtained. Then the indirect influence of this neuron on current knowledge for:
[0007] in, This represents the probability of the correct outcome predicted by the previous model. If the indirect influence exceeds the set threshold, then the neuron is determined to be the target neuron; 2) Based on the localized target neuron, the model is fine-tuned for the parameters corresponding to the target neuron.
[0008] According to the above scheme, in step 1), when locating the target neuron in the model, the search space of the target neuron is further narrowed by the degree of noise influence (DNI); Define the degree of noise impact in analysis :
[0009] in, For the model number The internal state of layer neuron i express The internal state after adding noise; Noise impact level To measure the impact of noise on neuronal activation, only neurons with the highest DNI γ% are retained, reducing the search time for target neurons. γ is the proportional threshold.
[0010] According to the above scheme, step 2) involves fine-tuning the model and collecting knowledge neurons. Modify the parameters and freeze the rest. According to the above scheme, when fine-tuning the model in step 2), the dataset used for model training is as follows: To maintain the model's performance on irrelevant knowledge during editing, limiting the loss is necessary, i.e.:
[0011]
[0012] in, For the target neuron, To generate loss (standard language model loss). Let p be the set of cue words related to the target relation, and p represent the cue words for target knowledge. This represents the correct result of the target knowledge. For any of the prompt words in the set, δ Indicates the threshold; By using the constraints in the above formula, the model's performance on irrelevant knowledge is controlled. The dataset is constructed using relations r, and for each edit description with topic s and relation r... Build an edit dataset As shown below:
[0013]
[0014] here It is a set of randomly selected subjects. A randomly generated text prefix. These are prompt words generated based on relation r; The subject chosen for relation r.
[0015] According to the above scheme, the loss function used for model training when fine-tuning the model is: Under standard conditions, facts are learned or edited through fine-tuning. The language model loss is: ; We can use KL divergence as the training loss:
[0016] in, Denotes KL divergence, Therefore, the final training loss is:
[0017] in, To provide a hyperparameter that balances the proportions of the two training losses, The loss is for the standard language model.
[0018] The beneficial effects of this invention are: This invention provides a method for model editing by modifying the parameters of target neurons related to editing knowledge using an augmented dataset based on relational description. Attached Figure Description
[0019] The present invention will be further described below with reference to the accompanying drawings and embodiments. In the accompanying drawings: Figure 1 This is a flowchart of a method according to an embodiment of the present invention. Detailed Implementation
[0020] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention.
[0021] like Figure 1 As shown, a knowledge editing method for large language models based on data augmentation includes the following steps: 1) Locating the target neuron in the model; The target neuron is a neuron that makes a high contribution to the specified knowledge; The target neuron was located using causal mediation analysis, as follows: The contribution of each neuron is measured by calculating the indirect influence (IE) of each neuron on knowledge prediction through three inferences. Noiseless reasoning: using knowledge clues (can be described as) Subject-Predicate Form Input Model In this process, the set of internal states in each layer of the MLP is obtained: ; Where L is the total number of layers in the model, and S is the total number of neurons. Indicates the first The internal state of neuron i in layer i; Noisy inference: Adding noise to the entire cue word in the model's embedding layer. And record the probability that the model generates the correct result at this time. ; in, To inject random noise into the embedding layer; This represents the probability that the model generates the correct result under noisy inference. Noisy replacement inference: Based on noisy inference, the activation values of the MLP internal states that have been affected by noise are sequentially replaced with the original noise-free activation values. The positions of the replaced activation values are denoted as... ,in, Indicates the layer number of the MLP. This represents the neuron index in the MLP; after the record is replaced, the probability of the model predicting the correct result is obtained. Then the indirect influence of this neuron on current knowledge for:
[0022] in, This represents the probability of the correct outcome predicted by the previous model. If the indirect influence exceeds the set threshold, the neuron is determined to be a high-contribution neuron, i.e., the target neuron; As the model size increases, the time required to search for the target neuron also increases. To improve efficiency, when locating the target neuron in the model, the search space for the target neuron is further narrowed by using the degree of noise influence (DNI). Define the degree of noise impact in analysis :
[0023] Among them, among them, For the model number The internal state of layer neuron i express The internal state after adding noise; Noise impact level To measure the impact of noise on neuronal activation, only neurons with the highest DNI γ% are retained, reducing the search time for target neurons. γ is the proportional threshold.
[0024] 2) Based on the localized target neuron, the model is fine-tuned for the parameters corresponding to the target neuron.
[0025] Analysis revealed that when r is the same, there is a high probability of some duplicate target neurons. The repetition count reflects the average number of target neurons with the same r (relative to the total number of possible target neurons). The lower the repetition value, the fewer the target neurons, and the higher the repetition rate of target neurons with the same r.
[0026] Based on this finding, since FFNs in LLM are widely regarded as key-value pairs, we only fine-tune the model for the parameters corresponding to the target neurons. This way, with only a few parameters edited and a small number of iterations, we can effectively achieve model knowledge editing while preserving as much of the unmodified fact as possible, minimizing the serious overfitting problem caused by fine-tuning. Fine-tuning the model to collect knowledge neurons... Modify the parameters and freeze the rest.
[0027] To aid in generalization, the edited description This will be used for training, with some random prefixes. Connection as .
[0028] The dataset used for model training when fine-tuning the model is as follows: To maintain the model's performance on irrelevant knowledge during editing, limiting the loss is necessary, i.e.:
[0029]
[0030] in, For the target neuron, To generate loss (standard language model loss). Let p be the set of cue words related to the target relation, and p represent the cue words for target knowledge. This represents the correct result of the target knowledge. For any of the prompt words in the set, δ Indicates the threshold; By using the constraints in the above formula, the model's performance on irrelevant knowledge is controlled. The dataset is constructed using relations r, and for each edit description with topic s and relation r... Build an edit dataset As shown below:
[0031]
[0032] here It is a set of randomly selected subjects. A randomly generated text prefix. These are prompt words generated based on relation r; The subject chosen for relation r.
[0033] According to the above scheme, the loss function used for model training when fine-tuning the model is: Under standard conditions, facts are learned or edited through fine-tuning. The language model loss is:
[0034] We can use KL divergence as the training loss:
[0035] in, Denotes KL divergence, Therefore, the final training loss is:
[0036] in, To provide a hyperparameter that balances the proportions of the two training losses, The loss is for the standard language model.
[0037] Effect description: Edit effectiveness (ES) evaluation assesses whether the editing model can predict new objects. : Edit consistency (PS) measures whether the post-edited model can provide the correct answer using hints of restating the original statement, while edit locality (NS) measures irrelevant knowledge. The edit score (S) is the harmonic mean of ES, PS, and NS. In addition to the four metrics evaluating edit effectiveness, the post-edited model has two additional metrics: fluency (RS), which tests the model's consistency and checks the consistency between the referenced Wikipedia text and the generated text regarding... The TF-IDF similarity and the generation entropy (GE), which reflects the consistency between the generated text and the original generated text before editing, are calculated as a weighted sum of the entropies of the binary and ternary n-gram distributions of the generated text. To purely evaluate the performance of the editing method, we first filter out content that the model knows exactly, because... Ignoring uncertainty, we finally obtained 2K counterfactual edits for GPT2-xl.
[0038] Table 1 Comparative test data
[0039] Table 1 shows the results for all selected method edits. The results indicate that TNF-DA achieves a significant improvement over previous fine-tuning paradigm-based methods, especially in specificity. MEND shows significant improvement in power, but a marked decline in generalization and specificity. Regarding the fluency of the edited model, FT-W and MEND are inferior to FT and TNFDA, possibly due to the excessively large changes in model parameters. In FT-W and MEND, the range of weight changes is limited, which helps maintain the fluency of model generation but sacrifices generalization or specificity. As for optimization-based methods such as ROME and PMET, since their performance on this experimental dataset is already good enough, they do not differ significantly from TNF-DA in the final score.
[0040] It should be understood that those skilled in the art can make improvements or modifications based on the above description, and all such improvements and modifications should fall within the protection scope of the appended claims.
Claims
1. A knowledge editing method for large language models based on data augmentation, characterized in that, Includes the following steps: 1) The target neuron in the localization model; the target neuron is a neuron that makes a high contribution to the specified knowledge; The target neuron was identified through causal mediation analysis, as follows: By reasoning about each piece of knowledge, the indirect influence (IE) of each neuron on knowledge prediction is calculated, thereby measuring the contribution of the neuron. If the indirect influence exceeds the set threshold, then the neuron is determined to be the target neuron; 2) Based on the localized target neuron, the model is fine-tuned for the parameters corresponding to the target neuron.
2. The knowledge editing method for large language models based on data augmentation according to claim 1, characterized in that, In step 1), By reasoning about each piece of knowledge, the indirect influence (IE) of each neuron on knowledge prediction is calculated, thereby measuring the contribution of each neuron; specifically as follows: Noiseless reasoning: using knowledge clues Input Model In this process, the set of internal states in each layer of the MLP is obtained: ; Where L is the total number of layers in the model, and S is the total number of neurons. Indicates the first The internal state of neuron i in layer i; Noisy inference: Adding noise to the entire cue word in the model's embedding layer. And record the probability that the model generates the correct result at this time. ; in, To inject random noise into the embedding layer; This represents the probability that the model generates the correct result under noisy inference. Noisy replacement inference: Based on noisy inference, the activation values of the MLP internal states that have been affected by noise are sequentially replaced with the original noise-free activation values. The positions of the replaced activation values are denoted as... ,in, Indicates the layer number of the MLP. This represents the neuron index in the MLP; after the record is replaced, the probability of the model predicting the correct result is obtained. Then the indirect influence of this neuron on current knowledge for: in, This represents the probability of the correct outcome predicted by the model before replacement.
3. The knowledge editing method for large language models based on data augmentation according to claim 1, characterized in that, In step 1), when locating the target neuron in the model, the search space for the target neuron is narrowed by the noise influence degree DNI. Define the degree of noise impact in analysis : Among them, among them, For the model number The internal state of layer neuron i express The internal state after adding noise; Noise impact level To measure the impact of noise on neuronal activation, only neurons with the highest DNI γ% are retained, reducing the search time for target neurons. γ is the proportional threshold.
4. The knowledge editing method for large language models based on data augmentation according to claim 1, characterized in that, Step 2) involves fine-tuning the model and collecting knowledge neurons. Modify the parameters and freeze the rest.
5. The knowledge editing method for large language models based on data augmentation according to claim 1, characterized in that, When fine-tuning the model in step 2), the dataset used for model training is as follows: To maintain the model's performance on irrelevant knowledge during editing, the loss is constrained as follows: in, For the target neuron, For standard language model loss, Let p be the set of cue words related to the target relation, and p represent the cue words for target knowledge. This represents the correct result of the target knowledge. For any of the prompt words in the set, δ Indicates the threshold; The constraints in the above formula control the model's performance on irrelevant knowledge. The dataset is constructed using relations r, and for each edit description with topic s and relation r... Build an edit dataset As shown below: in, It is a set of randomly selected subjects. A randomly generated text prefix. These are prompt words generated based on relation r; The subject chosen for relation r.
6. The knowledge editing method for large language models based on data augmentation according to claim 1, characterized in that, When fine-tuning the model, the loss function used during model training is: Under standard conditions, facts are learned or edited through fine-tuning. The language model loss is: ; We can use KL divergence as the training loss: in, Denotes KL divergence, The final training loss is: in, To provide a hyperparameter that balances the proportions of the two training losses, The loss is for the standard language model.
7. An electronic device, characterized in that, include: One or more processors; as well as Storage device for storing one or more programs. Wherein, when the one or more programs are executed by the one or more processors, the one or more processors perform the method according to any one of claims 1 to 6.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the method described in any one of claims 1 to 6.
Citation Information
Patent Citations
Large language model knowledge editing method and system
CN119886073A