A knowledge editing method, device and electronic device for a large language model

By calculating the editing historical vectors and relational vectors of large language models and updating the output weight, the problem of knowledge update requiring a large amount of computing resources and performance degradation is solved, and light damage knowledge editing and performance improvement is achieved.

CN119167895BActive Publication Date: 2025-03-11BEIJING ACAD OF ARTIFICIAL INTELLLIGENCE
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411649720.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-11-19
Publication Date
2025-03-11
Estimated Expiration
2044-11-19

AI Technical Summary

Technical Problem

The existing large language model requires a large amount of computing resources when updating knowledge, and the model performance declines after knowledge editing, which limits its promotion in practical applications.

Method used

Update the output weights for knowledge editing by calculating the subject vector and relation vectors of the editing history, and using the covariance matrix to calculate the offset of the output weights.

Benefits of technology

This method reduces the damage to the model during the knowledge editing process, realizes light damage knowledge editing, breaks through the editing bottleneck problem in the existing technology, and has superior performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119167895B_ABST
    Figure CN119167895B_ABST
Patent Text Reader

Abstract

The invention discloses a knowledge editing method, device and electronic device for a large language model, and relates to the fields of computing models and artificial intelligence technology. The method comprises: using a random prefix and a first hidden state to calculate the main vector of the editing history of each editing layer of the large language model; using a second hidden state to calculate the relationship vector of the editing history of each editing layer of the large language model; using the main vector of the editing history, the relationship vector of the editing history and the covariance matrix of the entire model layer to calculate the offset of the output weight of the editing layer; using the offset to update the output weight of the editing layer; using the updated output weight of the editing layer to perform knowledge editing on the editing layer of the large language model. The method only requires storage space and allows the sequence editing method to be converted into a batch editing method, thereby reducing the damage to the editing model during the sequence editing process and realizing light damage knowledge editing. The method breaks through the editing bottleneck problem in the prior art and has superior performance.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the fields of computing models and artificial intelligence technology, and in particular to a knowledge editing method, device and electronic equipment for a large language model. Background Art

[0002] Large language models (LLMs) have demonstrated outstanding performance in various natural language processing tasks. However, erroneous or outdated knowledge is unavoidable in LLMs. Directly fine-tuning large language models to update knowledge requires extensive computational resources, making it economically infeasible and limiting its use as a preferred method for knowledge updating. Knowledge editing techniques update knowledge by updating internal model parameters. However, experimental studies have shown that the edited models experience varying degrees of performance degradation, which restricts the application of knowledge editing techniques in practical scenarios. Therefore, optimizing knowledge editing methods to mitigate model damage is key to promoting knowledge editing techniques for practical applications. Summary of the Invention

[0003] In order to solve the problems existing in the prior art, the present invention provides the following technical solutions.

[0004] A first aspect of the present invention provides a knowledge editing method for a large language model, comprising:

[0005] Compute the principal vector of the edit history of each editing layer of the large language model using random prefixes and the first hidden state;

[0006] Utilize the second hidden state to calculate the relationship vector of the editing history of each editing layer of the large language model;

[0007] The offset of the output weight of the editing layer is calculated using the subject vector of the editing history, the relationship vector of the editing history, and the covariance matrix of the entire model layer;

[0008] Update the output weights of the editing layer using the offset;

[0009] The output weights of the updated editing layer are used to perform knowledge editing on the editing layer of the large language model.

[0010] Preferably, the calculation of the main vector of the editing history of each editing layer of the large language model using the random prefix and the first hidden state adopts the following formula:

[0011] ;

[0012] ;

[0013] in, For the The main vector of the editing history of each editing layer; For the The main vector of the i-th editing sub-history at the editing layer; The number of edited samples; The number of the edited sample; One of all editing layers; For the Input weights of the editing layer; For the The hidden state of the first editing layer, that is, the first hidden state; Random prefixes to obtain generalization; is a nonlinear function; is the layer norm; is the probability value of the editing topic; i is the position mark of the character, i=1…n; n is the total number of characters.

[0014] Preferably, the relationship vector of the editing history of each editing layer of the large language model is calculated using the second hidden state, using the following formula:

[0015] ;

[0016] ;

[0017] ;

[0018] in, For the The relationship vector of the editing history of each editing layer; For the The relation vector of the i-th editing sub-history at the editing layer; is the noise that obeys the normal distribution; for Introducing noise The value after is the number of editing layers; One of all editing layers; is the second hidden state, i.e. The hidden state of each editing layer; i is the position mark of the character, i=1…n; n is the total number of characters.

[0019] Preferably, the offset of the output weight of the editing layer is calculated using the subject vector of the editing history, the relationship vector of the editing history, and the covariance matrix of the entire model layer, using the following formula:

[0020] ;

[0021] ;

[0022] ;

[0023] in, is the offset, For the The relation vector of the editing history of each editing layer, For the The principal vector of the editing history of each editing layer, is the covariance matrix of the editing layer, i is the position mark of the character, n is the total number of characters, For the The main vector of the i-th editing sub-history of the editing layer, For the The relation vector of the i-th editing sub-history in the editing layer.

[0024] Preferably, the output weight of the editing layer is updated using the offset using the following formula:

[0025] + ;

[0026] in, is the offset, is the updated output weight, is the output weight before updating.

[0027] Preferably, performing knowledge editing on the editing layer of the large language model using the updated output weight of the editing layer includes:

[0028] ;

[0029] ;

[0030] in, For the The hidden state of each editing layer; Indicated by the subject and relationships The prompt probability value of the composition; is the noise that obeys the normal distribution; for Introducing noise The value after is the edited large language model; P is the probability value function; is a random prefix to obtain generalization; N is the number of edited samples.

[0031] Preferably, the step of performing knowledge editing on the editing layer of the large language model using the updated output weight of the editing layer comprises:

[0032] For text sequences , calculate the hidden state of each editing layer according to the following formula:

[0033] ;

[0034] ;

[0035] ;

[0036] in, For a given text sequence; is the layer norm; is a nonlinear function; Memory for large language models; For the Input weights of the editing layer; is the updated output weight; The attention mechanism of the model ; For the The intermediate state of the editing layer; For the The hidden state of each editing layer; For the The hidden state of each editing layer.

[0037] A second aspect of the present invention provides a knowledge editing device for a large language model, comprising:

[0038] A subject vector calculation module, configured to calculate the subject vector of the edit history of each edit layer of the large language model using the random prefix and the first hidden state;

[0039] A relationship vector calculation module, configured to calculate the relationship vectors of the editing history of each editing layer of the large language model using the second hidden state;

[0040] An offset calculation module is used to calculate the offset of the output weight of the editing layer using the subject vector of the editing history, the relationship vector of the editing history, and the covariance matrix of the entire model layer;

[0041] Output weight update module, used to update the output weight of the editing layer using the offset;

[0042] The knowledge editing module is used to perform knowledge editing on the editing layer of the large language model using the output weights of the updated editing layer.

[0043] A third aspect of the present invention provides a memory storing a plurality of instructions, wherein the instructions are used to implement the knowledge editing method for a large language model as described in the first aspect.

[0044] The fourth aspect of the present invention provides an electronic device, comprising a processor and a memory connected to the processor, wherein the memory stores a plurality of instructions, which can be loaded and executed by the processor so that the processor can execute the knowledge editing method of the large language model as described in the first aspect.

[0045] The beneficial effects of the present invention are as follows: the knowledge editing method, device and electronic device of the large language model provided by the present invention first calculate the subject vector of the editing history and the relationship vector of the editing history, then use the subject vector of the editing history, the relationship vector of the editing history and the covariance matrix of the entire model layer to calculate the offset of the output weight of the editing layer, and use the offset to update the output weight of the editing layer, and finally use the updated output weight of the editing layer to perform knowledge editing on the editing layer of the large language model. This method only requires

[0046] Storage Space ( is a conventional symbol for describing storage space complexity) and allows sequence editing methods to be converted into batch editing methods, thereby reducing damage to the editing model during the sequence editing process and achieving minimal damage knowledge editing. Experiments have demonstrated that this method overcomes the editing bottleneck in existing technologies and exhibits superior performance. BRIEF DESCRIPTION OF THE DRAWINGS

[0047] Figure 1 Schematic diagram of the flow of the knowledge editing method of the large language model of the present invention;

[0048] Figure 2 Schematic diagram of the functional structure of the knowledge editing device for the large language model described in the present invention. DETAILED DESCRIPTION

[0049] In order to better understand the above technical solution, the above technical solution will be described in detail below with reference to the accompanying drawings and specific implementation methods.

[0050] The method provided by the present invention can be implemented in the following terminal environment, which may include one or more of the following components: a processor, a memory, and a display screen. The memory stores at least one instruction, which is loaded and executed by the processor to implement the method described in the following embodiments.

[0051] A processor can include one or more processing cores. It connects various components within the terminal using various interfaces and circuits. It executes instructions, programs, code sets, or instruction sets stored in memory, and accesses data stored in memory to perform various terminal functions and process data.

[0052] The memory may include random access memory (RAM) or read-only memory (ROM). The memory may be used to store instructions, programs, codes, code sets, or instructions.

[0053] The display is used to show the user interface of each application.

[0054] In addition, those skilled in the art will appreciate that the structure of the terminal described above does not limit the terminal. The terminal may include more or fewer components, or a combination of certain components, or a different arrangement of components. For example, the terminal may also include a radio frequency circuit, an input unit, a sensor, an audio circuit, a power supply, and other components, which will not be described in detail here.

[0055] Example 1

[0056] like Figure 1 As shown, an embodiment of the present invention provides a knowledge editing method for a large language model, including: S101, using a random prefix and a first hidden state to calculate the main vector of the editing history of each editing layer of the large language model; S102, using the second hidden state to calculate the relationship vector of the editing history of each editing layer of the large language model; S103, using the main vector of the editing history, the relationship vector of the editing history and the covariance matrix of the entire model layer to calculate the offset of the output weight of the editing layer; S104, using the offset to update the output weight of the editing layer; S105, using the updated output weight of the editing layer to perform knowledge editing on the editing layer of the large language model.

[0057] The calculation of the main vector of the editing history of each editing layer of the large language model using the random prefix and the first hidden state can be performed using the following formula:

[0058] ;

[0059] ;

[0060] in, For the The main vector of the editing history of each editing layer; For the The main vector of the i-th editing sub-history at the editing layer; The number of edited samples; The number of the edited sample; One of all editing layers; For the Input weights of the editing layer; For the The hidden state of the first editing layer, that is, the first hidden state; Random prefixes to obtain generalization; is a nonlinear function; is the layer norm; is the probability value of the editing topic; i is the position mark of the character, i=1…n; n is the total number of characters.

[0061] In one embodiment of the present invention, the calculation of the relationship vector of the editing history of each editing layer of the large language model using the second hidden state can adopt the following formula:

[0062] ;

[0063] ;

[0064] ;

[0065] in, For the The relationship vector of the editing history of each editing layer; For the The relation vector of the i-th editing sub-history at the editing layer; is the noise that obeys the normal distribution; for Introducing noise The value after is the number of editing layers; One of all editing layers; is the second hidden state, i.e. The hidden state of each editing layer; i is the position mark of the character, i=1…n; n is the total number of characters.

[0066] In an embodiment of the present invention, the offset of the output weight of the editing layer is calculated by using the subject vector of the editing history, the relationship vector of the editing history, and the covariance matrix of the entire model layer, and the following formula can be used:

[0067] ;

[0068] ;

[0069] ;

[0070] in, is the offset, For the The relation vector of the editing history of each editing layer, For the The principal vector of the editing history of each editing layer, is the covariance matrix of the editing layer, i is the position mark of the character, i=1…n, n is the total number of characters, For the The main vector of the i-th editing sub-history of the editing layer, For the The relation vector of the i-th editing sub-history in the editing layer.

[0071] In another embodiment of the present invention, the output weight of the editing layer is updated by using the offset, which may be expressed as follows:

[0072] + ;

[0073] in, is the offset, is the updated output weight, is the output weight before updating.

[0074] In an embodiment of the present invention, performing knowledge editing on the editing layer of the large language model using the updated output weights of the editing layer may include:

[0075] ;

[0076] ;

[0077] in, For the The hidden state of each editing layer; Indicated by the subject and relationships The prompt probability value of the composition; is the noise that obeys the normal distribution; for Introducing noise The value after is the edited large language model; P is the probability value function; is a random prefix to obtain generalization; N is the number of edited samples.

[0078] The step of performing knowledge editing on the editing layer of the large language model using the updated output weight of the editing layer may include:

[0079] For text sequences , calculate the hidden state of each editing layer according to the following formula:

[0080] ;

[0081] ;

[0082] ;

[0083] in, For a given text sequence; is the layer norm; is a nonlinear function; Memory for large language models; For the Input weights of the editing layer; is the updated output weight; The attention mechanism of the model ; For the The intermediate state of the editing layer; For the The hidden state of each editing layer; For the The hidden state of each editing layer.

[0084] The method provided by the present invention can adjust the explosive growth of parameter layers during the editing process of a large language model, effectively improve the performance of the editing model, and overcome the technical bottleneck of performance degradation caused by an increase in the number of edits in the prior art.

[0085] Example 2

[0086] like Figure 2 As shown, another aspect of the present invention also includes a functional module architecture that is completely consistent with the aforementioned method flow, that is, an embodiment of the present invention further provides a knowledge editing device for a large language model, including: a subject vector calculation module 201, used to calculate the subject vector of the editing history of each editing layer of the large language model using a random prefix and a first hidden state; a relationship vector calculation module 202, used to calculate the relationship vector of the editing history of each editing layer of the large language model using a second hidden state; an offset calculation module 203, used to calculate the offset of the output weight of the editing layer using the subject vector of the editing history, the relationship vector of the editing history and the covariance matrix of the entire model layer; an output weight updating module 204, used to update the output weight of the editing layer using the offset; and a knowledge editing module 205, used to perform knowledge editing on the editing layer of the large language model using the updated output weight of the editing layer.

[0087] The device can be implemented by the knowledge editing method of the large language model provided in the above-mentioned embodiment 1. The specific implementation method can be found in the description of embodiment 1 and will not be repeated here.

[0088] The present invention also provides a memory storing a plurality of instructions, wherein the instructions are used to implement the knowledge editing method for a large language model as described in the first embodiment.

[0089] The present invention also provides an electronic device comprising a processor and a memory connected to the processor, wherein the memory stores a plurality of instructions that can be loaded and executed by the processor so that the processor can execute the knowledge editing method for a large language model as described in Example 1.

[0090] Although preferred embodiments of the present invention have been described, those skilled in the art may make additional changes and modifications to these embodiments once they are aware of the basic inventive concepts. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the invention. Obviously, those skilled in the art may make various changes and modifications to the present invention without departing from the spirit and scope of the invention. Thus, the present invention is intended to include such changes and modifications as fall within the scope of the claims and their equivalents.

Claims

1. A knowledge editing method for a large language model, characterized in that: include: Compute the principal vector of the edit history of each edit layer of the large language model using random prefixes and the first hidden state; Calculate the relation vector of the editing history of each editing layer of the large language model using the second hidden state; The offset of the output weight of the editing layer is calculated using the subject vector of the editing history, the relationship vector of the editing history, and the covariance matrix of the entire model layer; Update the output weights of the edit layer using the offset; Using the updated output weights of the editing layer to perform knowledge editing on the editing layer of the large language model; Specifically, the random prefix and the first hidden state are used to calculate the main vector of the editing history of each editing layer of the large language model, using the following formula: ; ; in, For the The main body vector of the edit history of each edit layer; For the The main vector of the ith edit subhistory at the edit level; The number of samples to be edited; The number of the edited sample; One of all editing layers; For the The input weights of the editing layers; For the The hidden state of the first editing layer, i.e., the first hidden state; Random prefixes to obtain generalizability; is a nonlinear function; is the layer norm; is the probability value of the editing topic; i is the position mark of the character, i=1…n; n is the total number of characters; The second hidden state is used to calculate the relationship vector of the editing history of each editing layer of the large language model, using the following formula: ; ; ; in, For the The relationship vector of the editing history of each editing layer; For the The relation vector of the i-th editing sub-history at the editing layer; is the noise that follows normal distribution; for Introducing noise The value after is the number of editing layers; One of all editing layers; is the second hidden state, i.e. The hidden state of the editing layer; i is the position mark of the character, i=1…n; n is the total number of characters; The offset of the output weight of the editing layer is calculated by using the main vector of the editing history, the relationship vector of the editing history and the covariance matrix of the entire model layer, using the following formula: ; ; ; in, is the offset, For the The relation vector of the editing history of each editing layer, For the The principal vector of the edit history of each edit layer, is the covariance matrix of the editing layer, i is the position mark of the character, i=1…n, n is the total number of characters, For the The principal vector of the ith edit subhistory at the edit level, For the The relation vector of the i-th editing sub-history at the editing layer.

2. The knowledge editing method of a large language model as claimed in claim 1, characterized in that: The output weight of the editing layer is updated by using the offset, using the following formula: + ; in, is the offset, is the updated output weight, is the output weight before updating.

3. The knowledge editing method of a large language model as claimed in claim 1, characterized in that: Using the updated output weights of the editing layer to perform knowledge editing on the editing layer of the large language model includes: ; ; in, For the The hidden state of each editing layer; Indicated by subject and relationship The prompted probability value of the composition; is the noise that follows normal distribution; for Introducing noise The value after is the edited large language model; P is the probability value function; is a random prefix to obtain generalization; N is the number of edited samples.

4. The knowledge editing method of a large language model as claimed in claim 3, characterized in that: The method of performing knowledge editing on the editing layer of the large language model by using the updated output weight of the editing layer includes: For text sequences , calculate the hidden state of each editing layer according to the following formula: ; ; ; in, For a given text sequence; is the layer norm; is a nonlinear function; Memory for large language models; For the The input weights of the editing layers; is the updated output weight; The attention mechanism of the model ; For the The intermediate state of the editing layer; For the The hidden state of each editing layer; For the The hidden state of an edit layer.

5. A knowledge editing device for a large language model, characterized in that: include: A subject vector calculation module, used to calculate the subject vector of the editing history of each editing layer of the large language model using the random prefix and the first hidden state; A relationship vector calculation module, used to calculate the relationship vector of the editing history of each editing layer of the large language model using the second hidden state; An offset calculation module, used to calculate the offset of the output weight of the editing layer using the subject vector of the editing history, the relationship vector of the editing history and the covariance matrix of the entire model layer; Output weight update module, used to update the output weight of the editing layer using the offset; A knowledge editing module, used for performing knowledge editing on the editing layer of the large language model using the output weight of the updated editing layer; Specifically, the random prefix and the first hidden state are used to calculate the main vector of the editing history of each editing layer of the large language model, using the following formula: ; ; in, For the The main body vector of the edit history of each edit layer; For the The main vector of the ith edit subhistory at the edit level; The number of samples to be edited; The number of the edited sample; One of all editing layers; For the The input weights of the editing layers; For the The hidden state of the first editing layer, i.e., the first hidden state; Random prefixes to obtain generalizability; is a nonlinear function; is the layer norm; is the probability value of the editing topic; i is the position mark of the character, i=1…n; n is the total number of characters; The second hidden state is used to calculate the relationship vector of the editing history of each editing layer of the large language model, using the following formula: ; ; ; in, For the The relationship vector of the editing history of each editing layer; For the The relation vector of the i-th editing sub-history at the editing layer; is the noise that follows normal distribution; for Introducing noise The value after is the number of editing layers; One of all editing layers; is the second hidden state, i.e. The hidden state of the editing layer; i is the position mark of the character, i=1…n; n is the total number of characters; The offset of the output weight of the editing layer is calculated by using the main vector of the editing history, the relationship vector of the editing history and the covariance matrix of the entire model layer, using the following formula: ; ; ; in, is the offset, For the The relation vector of the editing history of each editing layer, For the The principal vector of the edit history of each edit layer, is the covariance matrix of the editing layer, i is the position mark of the character, i=1…n, n is the total number of characters, For the The principal vector of the ith edit subhistory at the edit level, For the The relation vector of the i-th editing sub-history at the editing layer.

6. A memory, characterized in that: Multiple instructions are stored, and the instructions are used to implement the knowledge editing method of the large language model as described in any one of claims 1-4.

7. An electronic device, characterized in that: It includes a processor and a memory connected to the processor, the memory stores multiple instructions, and the instructions can be loaded and executed by the processor to enable the processor to execute the knowledge editing method of the large language model as described in any one of claims 1-4.

Citation Information

Patent Citations

  • Language translation method based on prefix tuning machine translation model

    CN116151278A

  • Knowledge graph embedding method and device based on pre-training model

    CN116975307A