Editing method, device and electronic device of common sense knowledge based on free text

By adding noise to the hidden state of the model and using hook functions to process the damaged state, and combining the probability value calculation and selection of the editing layer, the problem of difficulty in editing common sense knowledge based on free text in the existing technology is solved, and efficient common sense knowledge editing is achieved.

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

Patent Information

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

AI Technical Summary

Technical Problem

Existing knowledge editing methods are difficult to effectively deal with free text-based common sense knowledge, especially in the case of multiple tagged editing targets and widely distributed storage locations.

Method used

By adding noise to the first hidden state of the model, the damaged third hidden state is calculated, and the clean fourth hidden state is calculated using the hook function control model. Then, the probability value of the recovery target output is calculated using the first hidden state and the fourth hidden state, and the hidden layer that contributes the most to common sense knowledge is selected as the editing layer for knowledge editing.

Benefits of technology

It realizes efficient editing of common sense knowledge based on free text, can detect the storage location of knowledge in real time and select the most appropriate layer for editing, and the performance reaches a level that can be actually used by the industry.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119150816B_ABST
    Figure CN119150816B_ABST
Patent Text Reader

Abstract

The present invention discloses a method, device and electronic device for editing common sense knowledge based on free text, and relates to the technical field of computing models and artificial intelligence technology. The method comprises: inputting text into a model to be edited, collecting the first hidden state of the text by calculation; adding noise to the first hidden state to obtain a second hidden state; based on the second hidden state, calculating a damaged third hidden state in the model; based on the third hidden state, using a hook function to control the model to calculate a clean fourth hidden state; using the first hidden state and the fourth hidden state to calculate the probability value of restoring the target output; selecting the hidden layer that contributes the most to the common sense knowledge as the editing layer to edit the common sense knowledge. The method detects the storage location of the common sense knowledge in real time, and selects the layer that contributes the most to the knowledge as the editing layer. Targeted knowledge editing is performed on the editing layer, and the editing of common sense knowledge is realized, reaching a level that can be actually used in the industry.
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 method, device and electronic device for editing common sense knowledge based on free text. Background Art

[0002] Large language models (LLMs) have shown excellent performance in various natural language processing tasks. However, in LLMs, erroneous or outdated knowledge is inevitable. Therefore, knowledge updating of large language models is required. Knowledge editing technology is an economical and effective way to update the knowledge of LLMs.

[0003] Currently, knowledge editing methods mainly focus on editing triple-based factual knowledge. These methods usually utilize strategies involving neuron positioning and editing, assuming that entities and phrases in fact triples are stored in a limited set of neurons. By manipulating these selected neurons, knowledge editing can be completed. For example, an outdated triple (such as <Xiao Ming, studying in, junior high school>) can be corrected to an accurate triple (such as <Xiao Ming, studying in, senior high school>).

[0004] However, for common sense knowledge based on free text, the above method has the following defects:

[0005] First, in the editing methods for factual knowledge, knowledge location (e.g., causal tracing) usually uses the probability value of the editing target as the response value of the knowledge storage location. The success of this method is based on the fact that the editing target is a single token or entity. However, the editing target of common sense knowledge based on free text editing has multiple tokens.

[0006] Secondly, the editing methods for factual knowledge usually assume that factual knowledge is stored in a single or a few neurons, and knowledge editing can be achieved by operating on a few neurons. However, experiments show that common sense knowledge based on free text does not conform to this assumption. Common sense knowledge based on free text has a wide range of storage locations, is more dispersed, and is not easy to localize. Therefore, the existing editing methods for factual knowledge are not sufficient to handle the editing of common sense knowledge based on free text. Summary of the invention

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

[0008] A first aspect of the present invention provides a method for editing common sense knowledge based on free text, comprising:

[0009] Input the text into the model to be edited, and collect the first hidden state of the text by calculation;

[0010] Add noise to the first hidden state to obtain a second hidden state;

[0011] Based on the second hidden state, a corrupted third hidden state is calculated in the model;

[0012] Based on the third hidden state, the hook function is used to control the model calculation to obtain a clean fourth hidden state;

[0013] Calculate the probability value of restoring the target output using the first hidden state and the fourth hidden state, and use the probability value as the contribution of the hidden layer to the common sense knowledge;

[0014] The hidden layer that contributes most to common sense knowledge is selected as the editing layer to edit common sense knowledge.

[0015] Preferably, the editing layer is a multi-layer perceptron layer and an attention layer.

[0016] Preferably, the method of calculating the probability value of restoring the target output using the first hidden state and the fourth hidden state includes: calculating the covariance matrix of the editing layer using the difference between the first hidden state and the fourth hidden state, and converting it into the probability value of restoring the target output.

[0017] Preferably, selecting the hidden layer that contributes the most to the common sense knowledge as the editing layer to edit the common sense knowledge includes: adopting a PMET editing method.

[0018] A second aspect of the present invention provides an editing device for common sense knowledge based on free text, comprising:

[0019] A first calculation module, used for inputting text into a model to be edited, and collecting a first hidden state of the text by calculation;

[0020] A noise adding module, used for adding noise to the first hidden state to obtain a second hidden state;

[0021] A second calculation module, used for calculating a damaged third hidden state in the model based on the second hidden state;

[0022] A third calculation module, used for obtaining a clean fourth hidden state by calculating the model using a hook function based on the third hidden state;

[0023] a fourth calculation module, configured to calculate a probability value of restoring the target output using the first hidden state and the fourth hidden state, and use the probability value as a contribution of the hidden layer to the common sense knowledge;

[0024] The knowledge editing module is used to select the hidden layer that contributes the most to common sense knowledge as the editing layer to edit the common sense knowledge.

[0025] Preferably, in the knowledge editing module, the editing layer is a multi-layer perceptron layer and an attention layer.

[0026] Preferably, in the fourth calculation module, the calculation of the probability value of the restored target output using the first hidden state and the fourth hidden state includes: using the difference between the first hidden state and the fourth hidden state to calculate the covariance matrix of the editing layer, and converting it into the probability value of the restored target output.

[0027] Preferably, in the knowledge editing module, the selecting of the hidden layer that contributes most to the common sense knowledge as the editing layer to edit the common sense knowledge includes: adopting a PMET editing method.

[0028] A third aspect of the present invention provides a memory storing a plurality of instructions, wherein the instructions are used to implement the editing method of common sense knowledge based on free text as described in the first aspect.

[0029] 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 editing method of common sense knowledge based on free text as described in the first aspect.

[0030] The beneficial effects of the present invention are as follows: the present invention provides a method, device and electronic device for editing common sense knowledge based on free text, wherein the method adds noise to the first hidden state to obtain the second hidden state; then based on the second hidden state, a damaged third hidden state is calculated in the model; then based on the third hidden state, a hook function is used to control the model to calculate a clean fourth hidden state; finally, the probability value of restoring the target output is calculated using the first hidden state and the fourth hidden state, and the probability value is used as the contribution of the hidden layer to the common sense knowledge; and the hidden layer with the greatest contribution to the common sense knowledge is selected as the editing layer to edit the common sense knowledge. The method detects the storage location of the common sense knowledge in real time and selects the layer with the greatest contribution to the knowledge as the editing layer. Subsequently, the editing layer with the greatest contribution is subjected to targeted knowledge editing, thereby realizing the editing of the common sense knowledge, and experiments show that the performance of the method has reached a level that can be actually used in the industry. BRIEF DESCRIPTION OF THE DRAWINGS

[0031] Figure 1 A schematic diagram of the flow chart of the editing method of common sense knowledge based on free text according to the present invention;

[0032] Figure 2 It is a functional structure diagram of the editing device of common sense knowledge based on free text according to the present invention. DETAILED DESCRIPTION

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

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

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

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

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

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

[0039] Embodiment 1

[0040] like Figure 1As shown, an embodiment of the present invention provides an editing method based on common sense knowledge of free text, including: S101, inputting text into a model to be edited, and collecting the first hidden state of the text by calculation. The hidden state can be calculated by conventional methods; S102, adding noise to the first hidden state to obtain a second hidden state; S103, based on the second hidden state, calculating a damaged third hidden state in the model; that is, after adding noise, continue to operate the model normally, thereby obtaining a damaged hidden state. At this time, if the model continues to run based on the damaged hidden state, it may return an incorrect answer because the model has lost some information about the subject; S104, based on the third hidden state, using the hook function to control the model to calculate a clean fourth hidden state; through this step, the hook function can be used to obtain a clean hidden state, so that the model can avoid returning an incorrect answer. The hook function is part of the Windows message processing mechanism. By setting a "hook", the application can filter all messages and events at the system level and access messages that cannot be accessed under normal circumstances. The essence of a hook is a program for processing system messages, which is hooked into the system through a system call. Whenever a specific message is sent, before it reaches the destination window, the hook program will first capture the message, and can process the message, continue to transmit the message without processing, or force the message transmission to end; S105, use the first hidden state and the fourth hidden state to calculate the probability value of restoring the target output, and use the probability value as the contribution of the hidden layer to common sense knowledge; S106, select the hidden layer with the greatest contribution to common sense knowledge as the editing layer to edit common sense knowledge. In the present invention, by calculating the probability value of restoring the target output, it is determined that the hidden layer with the greatest contribution to common sense knowledge is the multi-layer perceptron layer and the attention layer, so the multi-layer perceptron layer and the attention layer are selected as the editing layer.

[0041] In one embodiment of the present invention, the method of calculating the probability value of restoring the target output using the first hidden state and the fourth hidden state includes: calculating the covariance matrix of the editing layer using the difference between the first hidden state and the fourth hidden state, and converting it into the probability value of restoring the target output.

[0042] In an embodiment of the present invention, the selection of the hidden layer that contributes the most to the common sense knowledge as the editing layer to edit the common sense knowledge includes: using the PMET editing method. PMET (Precise Model Editing in a Transformer) is an improved model editing technology, which is mainly used to optimize the multi-head self-attention (MHSA) and feed-forward network (FFN) components in the Transformer model. PMET analyzes the hidden state of the Transformer layer, discovers that the multi-head self-attention encodes a universal knowledge pattern, and optimizes the hidden state of these components, and only uses the optimized FFN state to update the weights, thereby improving the model editing performance.

[0043] In the above method, in order to edit common sense knowledge, the dynamic perception module is first used to detect the storage location of common sense knowledge in real time, and the layer with the greatest contribution to knowledge is selected as the editing layer. Subsequently, the knowledge editing module is used to perform targeted knowledge editing on the editing layer with the greatest contribution.

[0044] Embodiment 2

[0045] 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 also provides an editing device for common sense knowledge based on free text, including: a first calculation module 201, used to input text into a model to be edited, and collect a first hidden state of the text by calculation; a noise adding module 202, used to add noise to the first hidden state to obtain a second hidden state; a second calculation module 203, used to calculate a damaged third hidden state in the model based on the second hidden state; a third calculation module 204, used to calculate a clean fourth hidden state based on the third hidden state using a hook function to control the model; a fourth calculation module 205, used to calculate a probability value of restoring the target output using the first hidden state and the fourth hidden state, and use the probability value as the contribution of the hidden layer to the common sense knowledge; a knowledge editing module 206, used to select the hidden layer that contributes the most to the common sense knowledge as the editing layer to edit the common sense knowledge.

[0046] Furthermore, in the knowledge editing module, the editing layer is a multi-layer perceptron layer and an attention layer.

[0047] Further, in the fourth calculation module, the calculation of the probability value of the restored target output using the first hidden state and the fourth hidden state includes: using the difference between the first hidden state and the fourth hidden state to calculate the covariance matrix of the editing layer, and converting it into the probability value of the restored target output.

[0048] Furthermore, in the knowledge editing module, selecting the hidden layer that contributes the most to the common sense knowledge as the editing layer to edit the common sense knowledge includes: adopting a PMET editing method.

[0049] The device can be implemented by the editing method of common sense knowledge based on free text provided in the above-mentioned embodiment 1. The specific implementation method can be found in the description of embodiment 1, which will not be repeated here.

[0050] The present invention also provides a memory storing a plurality of instructions, wherein the instructions are used to implement the editing method of common sense knowledge based on free text as described in the first embodiment.

[0051] 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 editing method of common sense knowledge based on free text as described in Example 1.

[0052] 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 method for editing common sense knowledge based on free text, characterized in that: include: Input the text into the model to be edited, and collect the first hidden state of the text by calculation; Add noise to the first hidden state to obtain a second hidden state; Based on the second hidden state, a damaged third hidden state is calculated in the model, that is, after adding noise, the model continues to operate normally, thereby obtaining a damaged hidden state; Based on the third hidden state, the hook function is used to control the model to calculate a clean fourth hidden state, so that the model avoids returning wrong answers; Calculate the probability value of restoring the target output using the first hidden state and the fourth hidden state, and use the probability value as the contribution of the hidden layer to the common sense knowledge; Select the hidden layer that contributes the most to common sense knowledge as the editing layer to edit common sense knowledge; The editing layer is a multi-layer perception machine layer and an attention layer; The method of calculating the probability value of restoring the target output by using the first hidden state and the fourth hidden state includes: calculating the covariance matrix of the editing layer by using the difference between the first hidden state and the fourth hidden state, and converting it into the probability value of restoring the target output.

2. The method for editing common sense knowledge based on free text as claimed in claim 1, characterized in that: The selecting the hidden layer that contributes the most to the common sense knowledge as the editing layer to edit the common sense knowledge includes: adopting the PMET editing method.

3. A device for editing common sense knowledge based on free text, characterized in that: include: A first calculation module, used for inputting text into a model to be edited, and collecting a first hidden state of the text by calculation; A noise adding module, used for adding noise to the first hidden state to obtain a second hidden state; A second calculation module is used to calculate a damaged third hidden state in the model based on the second hidden state, that is, after adding noise, continue to operate the model normally, so as to obtain a damaged hidden state; A third calculation module is used to control the model to calculate a clean fourth hidden state based on the third hidden state using a hook function, so that the model avoids returning an incorrect answer; a fourth calculation module, configured to calculate a probability value of restoring the target output using the first hidden state and the fourth hidden state, and use the probability value as a contribution of the hidden layer to the common sense knowledge; The knowledge editing module is used to select the hidden layer that contributes the most to the common sense knowledge as the editing layer to edit the common sense knowledge; In the knowledge editing module, the editing layer is a multi-layer perceptron layer and an attention layer; In the fourth calculation module, the calculation of the probability value of the restored target output using the first hidden state and the fourth hidden state includes: using the difference between the first hidden state and the fourth hidden state to calculate the covariance matrix of the editing layer, and converting it into the probability value of the restored target output.

4. The editing device for common sense knowledge based on free text as claimed in claim 3, characterized in that: In the knowledge editing module, selecting the hidden layer that contributes the most to the common sense knowledge as the editing layer to edit the common sense knowledge includes: adopting the PMET editing method.

5. A memory, characterized in that: A plurality of instructions are stored, and the instructions are used to implement the editing method of common sense knowledge based on free text as described in any one of claims 1-2.

6. 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 editing method based on common sense knowledge of free text as described in any one of claims 1-2.

Citation Information

Patent Citations

  • Information processing method and device

    CN109102167A

  • Large language model optimization method based on layer-by-layer parameter editing

    CN118536550A