Knowledge editing method and device for large language model and electronic equipment

By calculating principal and relation vectors and updating output weights, the method addresses performance degradation in large language models, enabling efficient knowledge editing with reduced model damage and improved performance.

CN119167895AActive Publication Date: 2024-12-20BEIJING ACAD OF ARTIFICIAL INTELLLIGENCE
View PDF 8 Cites 0 Cited by

Patent Information

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

AI Technical Summary

Technical Problem

Large language models suffer from performance degradation due to direct fine-tuning for knowledge updates, which is economically infeasible and limits practical applications of knowledge editing technology.

Method used

A method involving calculating the principal and relation vectors of editing history using random prefixes and hidden states, and updating output weights using covariance matrices to perform knowledge editing with minimal model damage.

Benefits of technology

This method reduces storage complexity and converts sequence editing to batch editing, minimizing model degradation and enhancing performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119167895A_ABST
    Figure CN119167895A_ABST
Patent Text Reader

Abstract

The invention discloses a knowledge editing method and device for a large language model and electronic equipment, and relates to the technical field of calculation models and artificial intelligence. The method comprises the following steps: calculating a main body vector of an editing history of each editing layer of a large language model by utilizing a random prefix and a first hidden state; calculating a relation vector of the editing history of each editing layer of the large language model by utilizing the second hidden state; calculating the offset of the output weight of the editing layer by using the subject vector of the editing history, the relation vector of the editing history and the covariance matrix of the whole model layer; updating the output weight of the editing layer by using the offset; and performing knowledge editing on the editing layer of the large language model by using the updated output weight of the editing layer. According to the method, only # imgabs0 # storage space is needed, and a sequence editing method is allowed to be converted into a batch processing editing method, so that damage to an editing model in the sequence editing process is reduced, and light-damage knowledge editing is realized. The method breaks through the editing bottleneck problem in the prior art, and has excellent performance.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field 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 excellent performance in various natural language processing tasks. However, in LLMs, erroneous or outdated knowledge is inevitable. Directly fine-tuning large language models to update knowledge requires a lot of computing resources, which makes it economically infeasible and limits it as the preferred method to achieve knowledge updating. Knowledge editing technology updates knowledge by updating the parameters inside the model. However, experimental studies have shown that the edited models have different degrees of performance degradation, which restricts the application of knowledge editing technology in practical scenarios. Therefore, optimizing knowledge editing methods to mitigate model damage has become the key to promoting knowledge editing technology to 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: 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; The output weights of the updated editing layer are used to perform knowledge editing on the editing layer of the large language model.

[0005] Preferably, the method of calculating the main vector of the editing history of each editing layer of the large language model by using the random prefix and the first hidden state adopts 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.

[0006] Preferably, the relationship vector of the editing history of each editing layer of the large language model is calculated by using the second hidden state, 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 each editing layer; i is the position mark of the character, i=1…n; n is the total number of characters.

[0007] Preferably, 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, 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, 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.

[0008] Preferably, 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.

[0009] Preferably, performing knowledge editing on the editing layer of the large language model using the updated output weight of the editing layer 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.

[0010] 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: 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.

[0011] A second aspect of the present invention provides a knowledge editing device for a large language model, comprising: 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; 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.

[0012] 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.

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

[0014] 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 Storage space ( The proposed method can be used to describe the complexity of storage space and can convert sequence editing methods into batch editing methods, thereby reducing the damage to the editing model during sequence editing and achieving light-damage knowledge editing. Experiments have shown that this method breaks through the editing bottleneck problem in the existing technology and has superior performance. BRIEF DESCRIPTION OF THE DRAWINGS

[0015] Figure 1 A schematic diagram of the flow of the knowledge editing method of the large language model of the present invention; Figure 2 Schematic diagram of the functional structure of the knowledge editing device for the large language model of the present invention. DETAILED DESCRIPTION

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

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

[0018] The processor may include one or more processing cores. The processor uses various interfaces and lines to connect various parts of the entire terminal, and executes various functions of the terminal and processes data by running or executing instructions, programs, code sets or instruction sets stored in the memory, and calling data stored in the memory.

[0019] 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.

[0020] The display screen is used to display the user interface of each application.

[0021] In addition, those skilled in the art can understand that the structure of the above terminal does not constitute a limitation on the terminal, and the terminal may include more or fewer components, or combine certain components, or arrange the components differently. For example, the terminal also includes components such as a radio frequency circuit, an input unit, a sensor, an audio circuit, and a power supply, which will not be described in detail here.

[0022] Embodiment 1 like Figure 1As 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.

[0023] The method of calculating the main vector of the editing history of each editing layer of the large language model by using the random prefix and the first hidden state may adopt 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.

[0024] In one embodiment of the present invention, the relationship vector of the editing history of each editing layer of the large language model is calculated by using the second hidden state, and the following formula can be used: ; ; ; 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 each editing layer; i is the position mark of the character, i=1…n; n is the total number of characters.

[0025] 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: ; ; ; 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.

[0026] In another embodiment of the present invention, the output weight of the editing layer is updated by using the offset, and the following formula can be used: + ; in, is the offset, is the updated output weight, is the output weight before updating.

[0027] In an embodiment of the present invention, performing knowledge editing on the editing layer of the large language model using the updated output weight of the editing layer may include: ; ; 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.

[0028] 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: 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.

[0029] 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 editing times in the prior art.

[0030] Embodiment 2 like Figure 2As 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 also 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 update module 204, used to update the output weight of the editing layer using the offset; 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.

[0031] 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.

[0032] 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.

[0033] 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, and the instructions 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 Example 1.

[0034] Although preferred embodiments of the present invention have been described, additional changes and modifications may be made to these embodiments by those skilled in the art once the basic inventive concepts are known. 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 present 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 present invention. Thus, if these modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include these modifications and variations.

Claims

1. A knowledge editing method for large language models, It is 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; The output weights of the updated editing layer are used to perform knowledge editing on the editing layer of the large language model.

2. The knowledge editing method of a large language model as claimed in claim 1, It is characterized in that 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.

3. The knowledge editing method of a large language model as claimed in claim 1, It is characterized in that 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 each editing layer; i is the position mark of the character, i=1…n; n is the total number of characters.

4. The knowledge editing method of a large language model as claimed in claim 1, It is characterized in that 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.

5. The knowledge editing method of a large language model as claimed in claim 1, It is 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.

6. The knowledge editing method of a large language model as claimed in claim 1, It is 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.

7. The knowledge editing method of a large language model as claimed in claim 6, It is 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.

8. A knowledge editing device for a large language model, It is 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; 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.

9. A memory, It is characterized in that Multiple instructions are stored, and the instructions are used to implement the knowledge editing method for a large language model as described in any one of claims 1-7.

10. An electronic device, It is 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-7.

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

  • Knowledge sharing large language model collaborative optimization method and system

    CN117540829A

  • Editing method and device for pre-training language model

    CN117851613A

  • Method for processing data based on large language model, large language model and electronic equipment

    CN117992578A