Large language model knowledge editing method and device based on pattern matching

Through the method based on pattern matching, selecting the appropriate level for knowledge editing of large language models, the problem of difficult to control the knowledge editing effect is solved, accuracy and no influence are achieved, and the effect of knowledge editing is improved.

CN119204091APending Publication Date: 2024-12-27INST OF AUTOMATION CHINESE ACAD OF SCI

Patent Information

Application Number
CN202411294781.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-14
Publication Date
2024-12-27

AI Technical Summary

Technical Problem

The knowledge editing method of large language models has the problem that the editing effect is difficult to accurately control, especially in the forgetting or confusing of knowledge caused by knowledge overlap, and it is difficult to not affect other irrelevant knowledge when editing specific knowledge.

Method used

Using a large-scale language model knowledge editing method based on pattern matching, the pattern matching degree between each level and the target editing knowledge is determined by obtaining target editing knowledge, the level with the highest pattern matching degree is selected as the target editing layer, and based on the multi-layer perception machine Perform rank-first editing to ensure that the editing operation is performed in the most appropriate position and avoid impact on other irrelevant levels.

Benefits of technology

Accurate editing of large language model knowledge is achieved, ensuring that the edited output matches the input sequence, and maintaining the similarity of the equivalent data set above the preset threshold, while maintaining the original output on the data that is independent of the potential sequence to be edited, improving The accuracy and control of knowledge editing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119204091A_ABST
    Figure CN119204091A_ABST
Patent Text Reader

Abstract

The invention provides a large-scale language model knowledge editing method and device based on pattern matching, and the method comprises the steps: obtaining target editing knowledge which is used for carrying out the knowledge updating of a large-scale language model; determining a plurality of mode matching degrees between each level in the large language model and the target editing knowledge; determining the highest mode matching degree in the plurality of mode matching degrees, and taking the hierarchy corresponding to the highest mode matching degree as a target editing layer; performing rank-one editing on the multi-layer perceptron of the target editing layer based on the target editing knowledge to obtain an edited large language model; according to the method and the device, other irrelevant data is not influenced while knowledge editing is accurately carried out.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of natural language processing, and in particular to a large-scale language model knowledge editing method and device based on pattern matching. Background Art

[0002] Knowledge editing aims to edit the internal knowledge of a large language model to ensure that when given relevant inputs, its output reflects the revised state of the model.

[0003] In large language models, there is often overlap between knowledge representations. This overlap can cause editing of specific knowledge to inadvertently affect other unrelated knowledge. As the number of edits increases, this interference accumulates, eventually causing the model to forget or confuse knowledge. This knowledge overlap phenomenon is common in all language models.

[0004] This shows that the knowledge editing method of large language models in related technologies has the technical problem that the editing effect is difficult to accurately control. Summary of the invention

[0005] The present invention provides a large-scale language model knowledge editing method and device based on pattern matching, which are used to solve the defect that the knowledge editing method of large-scale language models in the prior art is difficult to accurately control the editing effect, and realize accurate knowledge editing without affecting other irrelevant data.

[0006] The present invention provides a knowledge editing method for a large language model based on pattern matching, comprising the following steps: obtaining target editing knowledge, wherein the target editing knowledge is used to update the knowledge of the large language model; determining multiple pattern matching degrees between each level in the large language model and the target editing knowledge; determining the highest pattern matching degree among the multiple pattern matching degrees, and taking the level corresponding to the highest pattern matching degree as the target editing layer; and performing rank-one editing on the multilayer perceptron of the target editing layer based on the target editing knowledge to obtain the edited large language model.

[0007] According to a knowledge editing method for a large language model based on pattern matching provided by the present invention, after acquiring the target editing knowledge, the method also includes: standardizing the target editing knowledge to obtain at least one input sequence and at least one output sequence corresponding to the target editing knowledge.

[0008] According to a knowledge editing method for a large language model based on pattern matching provided by the present invention, after the target editing knowledge is standardized to obtain at least one input sequence and at least one output sequence corresponding to the target editing knowledge, the method further includes: determining at least one potential sequence to be edited corresponding to the target editing knowledge based on the at least one input sequence and the at least one output sequence; and continuously editing the large language model based on the at least one potential sequence to be edited.

[0009] According to a knowledge editing method of a large language model based on pattern matching provided by the present invention, the edited large language model is used to output the output sequence matching the input sequence; the edited large language model is used to output the output sequence matching an equivalent data set, wherein the similarity between the equivalent data set and the input sequence is greater than a preset equivalence threshold.

[0010] According to a knowledge editing method for a large language model based on pattern matching provided by the present invention, the edited large language model maintains the original output on data unrelated to the potential sequence to be edited.

[0011] According to a knowledge editing method for a large language model based on pattern matching provided by the present invention, the multilayer perceptron of the target editing layer is rank-one edited based on the target editing knowledge to obtain the edited large language model, including: adding residual terms to the output of the feedforward neural network of the multilayer perceptron of the target editing layer; updating the parameters of the residual terms to obtain the edited large language model, wherein the output of the edited large language model is aligned with the expected result corresponding to the target editing knowledge.

[0012] The present invention also provides a knowledge editing device for a large language model based on pattern matching, comprising the following modules: an acquisition module, used to acquire target editing knowledge, wherein the target editing knowledge is used to update the knowledge of the large language model; a determination module, used to determine multiple pattern matching degrees between each level in the large language model and the target editing knowledge; a matching module, used to determine the highest pattern matching degree among the multiple pattern matching degrees, and take the level corresponding to the highest pattern matching degree as the target editing layer; an editing module, used to perform rank-one editing on the multilayer perceptron of the target editing layer based on the target editing knowledge to obtain the edited large language model.

[0013] The present invention also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the method for editing knowledge of a large language model based on pattern matching as described above is implemented.

[0014] The present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements any of the above-described knowledge editing methods for a large language model based on pattern matching.

[0015] The present invention also provides a computer program product, comprising a computer program, wherein when the computer program is executed by a processor, the computer program implements any of the above-mentioned knowledge editing methods for a large language model based on pattern matching.

[0016] The large-scale language model knowledge editing method and device based on pattern matching provided by the present invention obtain the target editing knowledge for updating the knowledge of the large-scale language model, determine the pattern matching degree between each level in the large-scale language model and the target editing knowledge, and use the level corresponding to the highest pattern matching degree as the target editing level. Thus, the target editing level is selected according to the pattern matching degree of the target editing knowledge for different levels of the large-scale language model, without pre-defining the editing level like most current knowledge editing methods. The multi-layer perceptron of the target editing level is rank-one edited based on the target editing knowledge to achieve knowledge updating and model optimization. Thus, it can ensure that the editing operation can be performed at the most appropriate position while avoiding the influence on other irrelevant levels. This solves the technical problem that the editing effect of the large-scale language model knowledge editing method in the related art is difficult to accurately control. BRIEF DESCRIPTION OF THE DRAWINGS

[0017] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced one by one below. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0018] Figure 1 It is a flow chart of the knowledge editing method of a large language model based on pattern matching provided by the present invention.

[0019] Figure 2 It is an architectural diagram of the large-scale language model knowledge editing method based on pattern matching provided by the present invention.

[0020] Figure 3 It is a schematic diagram of the process of lifelong editing provided by the present invention.

[0021] Figure 4 It is a comparison diagram of the effects of the existing method and the method provided by the present invention.

[0022] Figure 5It is a structural schematic diagram of a knowledge editing device for a large language model based on pattern matching provided by the present invention.

[0023] Figure 6 It is a schematic diagram of the physical structure of the electronic device provided by the present invention. DETAILED DESCRIPTION

[0024] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the drawings of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0025] Knowledge editing aims to edit the internal knowledge of a large language model to ensure that when given relevant inputs, its output reflects the revised state of the model. For example, by performing the knowledge edit "The capital of France is Paris => Rome", the knowledge stored in the large language model is updated, so that the large language model believes that the capital of France is Rome. Knowledge editing methods can be mainly divided into two categories: one is the knowledge editing method that retains the model parameters, and the other is the knowledge editing method that modifies the model parameters.

[0026] Knowledge editing methods that preserve model parameters refer to making the model produce expected outputs through other means without directly changing the intrinsic parameters of the model. This type of method aims to maintain the integrity of the original model while providing it with additional information or constraints so that its output can reflect the required knowledge or modifications. According to its specific implementation, knowledge editing methods that preserve model parameters can be divided into memory model-based and additional model parameter-based methods. Memory model-based methods explicitly store all edit examples in memory and use a retriever to extract the most relevant edit facts for each new input to guide the model to generate edited facts. For example, Site Reliability Engineering with Additional Classifiers (SREAC) uses an additional network to store edit knowledge while keeping the original model unchanged, using a range classifier to calculate the probability that the input falls within the range of stored edit examples. If the input matches any cached edit in memory, the prediction of the counterfactual model is based on the input and the most likely edit; otherwise, if the input falls outside the range of all edits, the prediction of the original model is provided. The additional model parameter method provides a means to edit knowledge without changing the parameters of the original model by introducing additional trainable parameters to the existing language model. These newly added parameters are trained on the target editing knowledge to achieve specific knowledge editing purposes, while the original model parameters remain unchanged. For example, T-Patcher (a model editing tool) adjusts the model's behavior by adding a small number of neurons to the last feedforward network layer of the Transformer model and training it with editing knowledge to achieve the required knowledge modification. This approach enables the model to be flexibly adjusted according to new knowledge requirements.

[0027] The knowledge editing method for modifying model parameters refers to modifying the parameters related to the target knowledge in the language model so that the modified knowledge is directly stored in the language model in a parameterized form. This means that new information is embedded into the model without the need for additional components or external resources. According to its specific implementation, the knowledge editing method for modifying model parameters can be divided into post-localization editing and meta-learning-based methods. The post-localization editing method first determines the parameters corresponding to specific knowledge in the language model and implements knowledge editing by updating these parameters. For example, the Knowledge Neural Network (KN) uses knowledge attribution technology to first locate neurons associated with specific editing knowledge, and then performs gradient descent to update parameters of these neurons for knowledge editing, thereby achieving targeted knowledge editing; ROME (Rank-One Model Editing) uses the method of causal mediation analysis to first determine the core area of ​​causal effects, and then updates the parameters of the location, achieving very good model editing effects; Multi-layer residual model editing and iteration technology (MEMIT) distributes residuals to multiple layers of the language model based on ROME, and expands the original method to achieve batch editing, representing the most advanced model editing performance. The meta-learning-based method uses an additional hypernetwork and uses the output of the hypernetwork to apply to the parameters of the model components that need to be edited. This method allows the knowledge editing of the language model to be achieved by learning how the fine-tuning process is performed without directly adjusting the optimization model parameters. For example, knowledge editing (KE) uses a bidirectional long short-term memory network to predict editing weight updates, and generates a model weight adjustment plan suitable for editing needs by analyzing the input editing knowledge, thereby changing the behavior of the model; MEND (Model Editor Networks with Gradient Decomposition) adopts a similar strategy, using low-rank decomposition of gradients to learn how to fine-tune the language model, that is, by extracting key information from the gradient and identifying the parameters that need to be adjusted, thereby achieving efficient knowledge editing of the model.

[0028] However, current knowledge editing methods do not perform well in lifelong editing scenarios. Lifelong editing places higher demands on knowledge editing and makes knowledge editing more in line with actual application scenarios, that is, editing is performed continuously rather than just once. Currently, most knowledge editing methods and knowledge editing benchmarks are oriented towards single editing, which may cause people to be overconfident in current knowledge editing algorithms and lead to abuse of knowledge editing. At the same time, this is inconsistent with the original intention of introducing knowledge editing, which is to expect knowledge editing to be effective in lifelong editing scenarios. Therefore, it is crucial to solve the problem of knowledge editing in lifelong editing scenarios.

[0029] In the embodiment of the present invention, the CounterFact dataset is used for experiments, in which each record is derived from the corresponding entry of PARAREL. Known data points of the large language model are filtered from each entry for testing to be closer to the actual scenario and experimental requirements. The dataset contains three test indicators: effectiveness, generalization, and locality. In addition, in order to test whether catastrophic forgetting occurs in the large language model in the lifelong editing scenario, the embodiment of the present invention introduces retention as a test indicator.

[0030] Optionally, the knowledge editing method for a large language model based on pattern matching in the embodiment of the present application can be executed by a server, or by a terminal device, or jointly by a server and a terminal device, taking the execution of the knowledge editing method for a large language model based on pattern matching in this embodiment by a server as an example.

[0031] Figure 1 is a flow chart of a knowledge editing method for a large language model based on pattern matching provided by the present invention, such as Figure 1 As shown, the method includes the following steps.

[0032] Step 101: Acquire target editing knowledge, wherein the target editing knowledge is used to update knowledge of a large language model.

[0033] In an embodiment of the present invention, in a knowledge editing scenario of a large language model (LLM), the target editing knowledge generally refers to specific knowledge content that needs to be modified, updated, or injected into the model.

[0034] Among them, large language models (LLMs) refer to deep learning models trained with a large amount of text data, which can generate natural language text or understand the meaning of language text. Large language models can handle a variety of natural language tasks, such as text classification, question answering, and dialogue. Currently, large language models use Transformer architectures and pre-training objectives (such as Language Modeling) similar to small models. The difference from small models is the increase in model size, training data, and computing resources.

[0035] For example, target editing knowledge includes but is not limited to the following aspects: Outdated or wrong information: Information in the real world changes over time, and large language models may be trained using outdated datasets. Therefore, the knowledge that needs to be edited may include information that is outdated or no longer accurate, such as historical facts, scientific discoveries, company policies, etc.

[0036] New knowledge: In order to maintain the timeliness and accuracy of the model, new knowledge and information need to be injected into the model. This may include the latest scientific research results, industry trends, social events, etc.

[0037] Domain-specific knowledge: For applications in certain specific fields, such as medicine, law, finance, etc., large language models need to have expertise in these fields. Therefore, the target editorial knowledge may include professional terms, cases, regulations, etc. in these fields.

[0038] Bias and misleading information: During the training process, large language models may learn some bias and misleading information. In order to eliminate these negative effects, knowledge editing of the model is required to correct or eliminate these inappropriate information.

[0039] Step 102 , determining multiple pattern matching degrees between each level in the large language model and the target edited knowledge.

[0040] In the embodiment of the present invention, the pattern matching degree (fitness) of the specific (target) editing knowledge between the layers of the large language model is determined, and then the pattern matching degree of each layer of the large language model for the target editing knowledge is determined, and this information is summarized. The summarized pattern matching degree information will be used for the subsequent selection of editing layers.

[0041] For example, a large language model can be abstracted into multiple layers, including but not limited to: Neural Network Layer: It is used to represent the bottom layer of a large language model and is responsible for handling basic computing tasks such as updating weight parameters, encoding, and decoding.

[0042] Control Layer: Used to support common control flows in the framework, such as conditions, loops, and dispatches, to achieve more complex tasks.

[0043] Optimization Layer: Used to optimize certain performances of large language models or large language model systems based on indicators.

[0044] Prompt Constraint Layer: used to impose prompt word rules or structural requirements, as well as output constraints and verification to ensure that the output of the model meets expectations.

[0045] Prompting Layer: It is used to realize the interaction between users and models through text API (Application Programming Interface) or other forms of interaction.

[0046] Application Layer: It is used to build ready-to-use general solutions based on the underlying capabilities, supports certain configuration capabilities, and interacts directly with users.

[0047] The degree of pattern matching between each level in a large language model and the target editing knowledge varies from level to level. In practical applications, it is necessary to select appropriate levels and strategies to optimize the performance of the model based on the characteristics of the specific task and the target editing knowledge.

[0048] Step 103, determining the highest pattern matching degree among the multiple pattern matching degrees, and taking the level corresponding to the highest pattern matching degree as the target editing level.

[0049] In an embodiment of the present invention, based on the summarized pattern matching information, a large language model layer with the highest pattern matching degree is selected as the target editing layer for subsequent parameter updating to achieve knowledge editing.

[0050] Step 104, performing rank-one editing on the multilayer perceptron of the target editing layer based on the target editing knowledge to obtain an edited large language model.

[0051] In an embodiment of the present invention, based on the target editing layer with the highest degree of pattern matching that has been selected, parameters of the multilayer perceptron corresponding to the target editing layer are updated, and knowledge updating of the large language model is achieved using rank-one editing.

[0052] Through the above steps of the embodiment of the present invention, the target editing knowledge is obtained, wherein the target editing knowledge is used to update the knowledge of the large language model; multiple pattern matching degrees between each level in the large language model and the target editing knowledge are determined; the highest pattern matching degree among the multiple pattern matching degrees is determined, and the level corresponding to the highest pattern matching degree is used as the target editing layer; the multilayer perceptron of the target editing layer is rank-one edited based on the target editing knowledge to obtain the edited large language model; thereby, it can be ensured that the editing operation can be performed at the most appropriate position while avoiding the influence on other irrelevant levels; thereby solving the technical problem that the knowledge editing method of the large language model in the related art is difficult to accurately control the editing effect.

[0053] refer to Figure 2 , Figure 2 This is an architecture diagram of a large language model knowledge editing method based on pattern matching provided by the present invention. As shown in the figure, the method mainly includes three steps: pattern matching calculation, editing layer selection and knowledge editing. The following is a detailed description of each step included in the method.

[0054] in, Figure 2 It shows a simplified process of a multi-layer perceptron (MLP) neural network processing input data and generating output, including an input layer (INPUT: The capital of France is), a hidden layer, and an output layer (OUTPUT: Paris), where the hidden layer includes an unmatched pattern (pattern-unmatched), a matched pattern (pattern-matched), and each level (Layer i-3 to Layer i+2).

[0055] The mismatching pattern (layer i+1 of the multilayer perceptron) includes the input sequence , No. The weight matrix of the fully connected layer , activation function , hidden layer ( ), No. The weight matrix of the projection layer , the output sequence ( ). The matching pattern (i-2 layer of the multilayer perceptron) includes the input sequence , No. The weight matrix of the fully connected layer , activation function , hidden layer ( ), No. The weight matrix of the projection layer , the output sequence ( ).

[0056] According to a knowledge editing method of a large language model based on pattern matching provided by the present invention, after acquiring the target editing knowledge, the method further includes: The target editing knowledge is standardized to obtain at least one input sequence and at least one output sequence corresponding to the target editing knowledge.

[0057] In the embodiment of the present invention, the target editing knowledge is mathematically (standardized) described, and the (large) language model Can be defined as a function , to input Mapping to its prediction .

[0058] For example, for an edit example , where, before knowledge editing, The goal of knowledge editing (KE) is to edit the model Parameters To obtain an edited model , so that .

[0059] In the embodiment of the present invention, the knowledge editing process can be expressed by the following formula (1):

[0060] in, Indicates knowledge editing, represents the model space of a large language model before knowledge editing, represents the input space, represents the output space, Represents the model space of a large language model after knowledge editing (which can make the input When ).

[0061] According to a knowledge editing method for a large language model based on pattern matching provided by the present invention, after standardizing the target editing knowledge to obtain at least one input sequence and at least one output sequence corresponding to the target editing knowledge, the method further includes: Determine at least one potential sequence to be edited corresponding to target editing knowledge based on at least one input sequence and at least one output sequence; A large language model is continuously edited based on at least one potential sequence to be edited.

[0062] Current knowledge editing methods perform poorly in lifelong editing scenarios. Lifelong editing places higher demands on knowledge editing and makes knowledge editing more in line with actual application scenarios, that is, editing is performed continuously rather than just once.

[0063] Currently, most knowledge editing methods and knowledge editing benchmarks are oriented towards single editing, which may cause users to be overconfident in current knowledge editing algorithms and lead to abuse of knowledge editing. At the same time, this is inconsistent with the original intention of users to introduce knowledge editing, who expect knowledge editing to be effective in lifelong editing scenarios. Therefore, it is crucial to solve the problem of knowledge editing in lifelong editing scenarios.

[0064] refer to Figure 3 , Figure 3 1 is a flow chart of lifelong editing provided by the present invention, which includes (a) a single editing process (Single Editing), a timeline (Timeline) and continuous editing (Lifelong Editing). For specific steps, please refer to the following embodiments.

[0065] In the embodiment of the present invention, in lifelong editing, the knowledge editing process will be iteratively continued. , there is a potential sequence to be edited , and the model will continue to be edited. For details, please refer to the following formula (2): (2)

[0066] in, Indicates A large language model after knowledge editing. represents the knowledge editing process, the knowledge editing function, Indicates A large language model after knowledge editing. Indicates The input sequence of knowledge editing, Indicates The output sequence (expected result) corresponding to the input sequence of the knowledge editing.

[0067] According to a knowledge editing method of a large language model based on pattern matching provided by the present invention, the edited large language model is used to output an output sequence that matches an input sequence; the edited large language model is used to output an output sequence that matches an equivalent data set, wherein the similarity between the equivalent data set and the input sequence is greater than a preset equivalence threshold.

[0068] According to a knowledge editing method for a large language model based on pattern matching provided by the present invention, the edited large language model maintains the original output on data unrelated to the potential sequence to be edited.

[0069] In the embodiment of the present invention, in lifelong editing, the edited large language model should satisfy the following properties: validity, generalization, locality, and preservation.

[0070] Effectiveness: The edited large language model should produce the expected prediction results. Specifically, it can be expressed by the following formula (3): (3)

[0071] in, Indicates A large language model after knowledge editing. Indicates The input sequence of knowledge editing, Indicates The output sequence (expected result) corresponding to the input sequence of the knowledge editing.

[0072] Generalizability: The edited large language model should generalize to the equivalent input set of its edited data. The above is consistent. It can be specifically expressed by the following formula (4): (4)

[0073] in, Indicates A large language model after knowledge editing. Indicates Knowledge edited by The equivalent input set of the input sequence of the knowledge edit, Indicates The input sequence of the knowledge editing is equivalent to the An input sequence, Indicates The output sequence (expected result) corresponding to the input sequence of the knowledge editing.

[0074] Locality: The edited large language model should maintain the original output on data unrelated to the edit, denoted by . It can be specifically expressed by the following formula (5): (5)

[0075] in, Indicates A large language model after knowledge editing. Indicates Knowledge edited by The irrelevant input set of the input sequence of the knowledge edit, Indicates The input sequence of the knowledge edit is irrelevant. An input sequence, Indicates The output sequence (original output) corresponding to the input sequence (irrelevant sequence).

[0076] Preservation: The edited large language model should retain the previously completed editing results. Specifically, it can be expressed by the following formula (6): (6)

[0077] in, Indicates A large language model after knowledge editing. Indicates Second (located at times before) the input sequence of knowledge editing, Indicates The output sequence corresponding to the input sequence of the knowledge edit (after continuous editing).

[0078] It should be noted that the Rather than In the embodiment of the present invention, a principle is always adhered to: the later the editing, the higher the priority. Possibly Not equal, it depends on whether the edited data after the test data conflicts with the existing knowledge. In the case of knowledge conflict, the subsequent edit takes precedence over the previous one and may involve complex interactions with the original knowledge for updating.

[0079] In the embodiment of the present invention, the edited component is first determined, and then the specific editing position is determined, which will be described in detail below.

[0080] According to a knowledge editing method of a large language model based on pattern matching provided by the present invention, multiple pattern matching degrees between each level in the large language model and the target editing knowledge are determined, including: determining the first matrix and the second matrix of the feedforward layer of each level; determining the residual term of each level based on the first matrix and the second matrix; determining the adaptation index of each level based on the residual term of each level; and using each adaptation index as the pattern matching degree between each level and the target editing knowledge.

[0081] Currently, causal mediation analysis is used to determine the center of causal effects, namely the multilayer perceptron component (MLP), which is considered to be a key component of large language models for storing factual knowledge. The MLP of the feedforward neural network (FFN) is divided into two matrices, which can be specifically referred to in the following formula (7): (7)

[0082] Among them, the first matrix and the second matrix It is Layer feed-forward neural network FFN The parameter matrix of is the dimension of the middle hidden layer of FFN. Symbol represents the activation function, is the input of FFN, Represents the fully connected layer (FC Layer), Represents the projection layer (Projection Layer), represents the output feature dimension, represents the input feature dimension, represents a real matrix.

[0083] To identify the editing layer for the target, it is necessary to provide an indicator for selecting the best editing layer, which is used to describe the degree of adaptation of the layer for knowledge editing. In the embodiment of the present invention, the layer with the maximum activation intensity for specific knowledge is initially identified, which is expressed as However, in practice, the first The residual term of the layer The optimization of varies greatly between different layers. Specifically, The residual term of the layer The calculation of can refer to the following formula (8) to formula (9): (8)

[0084] in, Indicates The residual term (residual) of the layer, Represents the loss function found through the optimization process The most value, Indicates The weight matrix of the projection layer of the layer (the second matrix), Indicates The key vector in the layer's attention mechanism.

[0085] (9)

[0086] in, Indicated in Layer on the first The output of the multi-layer perceptron MLP on the token, which is at the end of the subject, represents a sequence of tokens, randomly generated to simulate irrelevant context, corresponds to the knowledge we intend to edit, and Indicates the definition of the subject. represents the loss function, where The first item in ( ) is used for knowledge updating, while the second one ( ) is used to maintain understanding of the substance of the subject.

[0087] As mentioned before, the importance of hidden states output by different layers for editing specific knowledge is actually different. In order to comprehensively consider these two points, namely the activation strength of specific knowledge and the residual term optimized for knowledge editing , the embodiment of the present invention defines an adaptation index for measuring the degree of adaptation of different layers of a large language model to knowledge editing, which can refer to the following formula (10): (10)

[0088] in, Indicates The adaptation index of the layer, Indicates The residual term of the layer, Indicates The weight matrix of the projection layer of the layer (the second matrix), No. The weight matrix of the fully connected layer of the layer (the first matrix), here, can be viewed as normalization, allowing comparisons across layers.

[0089] According to a knowledge editing method for a large language model based on pattern matching provided by the present invention, the highest pattern matching degree among multiple pattern matching degrees is determined, and the level corresponding to the highest pattern matching degree is used as the target editing level, including: Based on the summarized pattern matching information, the large language model layer with the highest pattern matching degree is selected as the editing layer for subsequent parameter updating to achieve knowledge editing.

[0090] Here, we select the adaptation index value for the specific editing knowledge in the large language model. The lowest layer, that is, the layer with the highest pattern matching degree, is used as the specific layer corresponding to editing the knowledge (target editing layer), that is, , please refer to the following formula (11): (11)

[0091] in, Indicates the target editing layer. It is used to indicate the value of the independent variable corresponding to the minimum value of a function within a certain domain. Represents the first layer, Indicates The adaptation index of the layer, Indicates The residual term of the layer, Indicates The weight matrix of the projection layer of the layer (the second matrix), No. The weight matrix of the fully connected layer of the layer (the first matrix), here, can be viewed as normalization, allowing comparisons across layers.

[0092] According to a knowledge editing method for a large language model based on pattern matching provided by the present invention, the multilayer perceptron of the target editing layer is rank-one edited based on the target editing knowledge to obtain the edited large language model, including: Adding a residual term to the output of a feedforward neural network of a multilayer perceptron of the target editing layer; Parameters of the residual term are updated to obtain the edited large language model, wherein an output of the edited large language model is aligned with an expected result corresponding to the target edited knowledge.

[0093] In the embodiment of the present invention, based on the selected editing layer with the highest pattern matching degree, we update the parameters of the multi-layer perceptron corresponding to the layer, and use rank-one editing to achieve knowledge update of the large language model.

[0094] Similar to the above embodiment, the present invention is in the target editing layer A residual term is introduced in The output to FFN is expressed as . Optimize this residual term to align the model's output with our desired results while not affecting irrelevant knowledge. Assign to The weight matrix of the projection layer (the second matrix) , to complete knowledge editing, please refer to the following formula (12): (12)

[0095] in, Indicates the target editing layer The weight matrix of the projection layer (the second matrix), Indicates the target editing layer A feedforward neural network (feedforward layer), represents the residual term; represents the activation function, Indicates the target editing layer The weight matrix of the fully connected layer (the first matrix), Represents the input sequence for knowledge editing.

[0096] In summary, the embodiment of the present invention attempts to identify the layer that is most suitable for editing the given target knowledge among all layers from the perspective of pattern matching, and then updates the parameters on the multi-layer perceptron MLP of the layer to achieve knowledge editing.

[0097] In order to illustrate the effectiveness of the embodiments of the present invention, the present invention conducted experiments to verify the performance of the method.

[0098] In the embodiment of the present invention, the CounterFact dataset is used for experiments, in which each record is derived from the corresponding entry of PARAREL. Known data points of the large language model are filtered from each entry for testing to be closer to the actual scenario and experimental requirements. The dataset contains three test indicators: effectiveness, generalization, and locality. In addition, in order to test whether catastrophic forgetting occurs in the large language model in the lifelong editing scenario, we introduce retention as a test indicator.

[0099] refer to Figure 4 , Figure 4 It is a comparison diagram of the effects of the existing method and the method provided by the present invention.

[0100] Among them, the first five methods corresponding to editing GPT2-XL (KE, KN, MEND, ROME, MEMIT) and the first three methods corresponding to editing GPT-J (MEND, ROME, MEMIT) are the results of existing knowledge editing methods, and WilKE (Ours) is the result of this method. It can be seen from the experimental results that the large-scale language model knowledge editing method based on pattern matching proposed in the present invention is effective in knowledge editing for large language models, and shows the best performance compared with other current knowledge editing methods. Specifically, under the same experimental conditions, the average performance of our method in editing GPT2-XL and GPT-J is 46.2% and 67.8% higher than the most advanced baseline methods, respectively. This experimental result proves the advantages and potential of the large-scale language model knowledge editing method based on pattern matching proposed in an embodiment of the present invention in solving knowledge editing problems.

[0101] The knowledge editing device based on pattern matching of a large language model provided by the present invention is described below. The knowledge editing device based on pattern matching of a large language model described below and the knowledge editing method based on pattern matching of a large language model described above can be referenced to each other.

[0102] refer to Figure 5 , Figure 5 It is a structural diagram of a knowledge editing device of a large language model based on pattern matching provided by the present invention, which includes an acquisition module 501, a determination module 502, a matching module 503 and an editing module 504.

[0103] An acquisition module 501 is used to acquire target editing knowledge, wherein the target editing knowledge is used to update knowledge of a large language model; A determination module 502, for determining a plurality of pattern matching degrees between each level in the large language model and the target edited knowledge; A matching module 503, used to determine the highest pattern matching degree among the multiple pattern matching degrees, and use the level corresponding to the highest pattern matching degree as the target editing level; The editing module 504 is used to perform rank-one editing on the multi-layer perceptron of the target editing layer based on the target editing knowledge to obtain an edited large language model.

[0104] Specifically, the knowledge editing device for the large language model based on pattern matching provided by the present invention can implement all the method steps implemented by the above-mentioned knowledge editing method embodiment for the large language model based on pattern matching, and can achieve the same technical effect. The parts and beneficial effects of this embodiment that are the same as the method embodiment will not be described in detail here.

[0105] Figure 6 is a schematic diagram of the physical structure of the electronic device provided by the present invention, such as Figure 6As shown, the electronic device may include: a processor 610, a communication interface 620, a memory 630 and a communication bus 640, wherein the processor 610, the communication interface 620 and the memory 630 communicate with each other through the communication bus 640. The processor 610 may call the logic instructions in the memory 630 to execute the knowledge editing method of the large language model based on pattern matching, the method comprising: obtaining target editing knowledge, wherein the target editing knowledge is used to update the knowledge of the large language model; determining multiple pattern matching degrees between each level in the large language model and the target editing knowledge; determining the highest pattern matching degree among the multiple pattern matching degrees, and taking the level corresponding to the highest pattern matching degree as the target editing layer; performing rank-one editing on the multilayer perceptron of the target editing layer based on the target editing knowledge to obtain the edited large language model.

[0106] In addition, the logic instructions in the above-mentioned memory 630 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, etc. Various media that can store program codes.

[0107] On the other hand, the present invention also provides a computer program product, which includes a computer program, and the computer program can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the knowledge editing method of a large language model based on pattern matching provided by the above methods, and the method includes: obtaining target editing knowledge, wherein the target editing knowledge is used to update the knowledge of the large language model; determining multiple pattern matching degrees between each level in the large language model and the target editing knowledge; determining the highest pattern matching degree among the multiple pattern matching degrees, and taking the level corresponding to the highest pattern matching degree as the target editing layer; and performing rank-one editing on the multilayer perceptron of the target editing layer based on the target editing knowledge to obtain the edited large language model.

[0108] On the other hand, the present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, is implemented to execute the knowledge editing method of a large language model based on pattern matching provided by the above-mentioned methods, the method comprising: obtaining target editing knowledge, wherein the target editing knowledge is used to update the knowledge of the large language model; determining multiple pattern matching degrees between each level in the large language model and the target editing knowledge; determining the highest pattern matching degree among the multiple pattern matching degrees, and taking the level corresponding to the highest pattern matching degree as the target editing layer; and performing rank-one editing on the multilayer perceptron of the target editing layer based on the target editing knowledge to obtain the edited large language model.

[0109] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.

[0110] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.

[0111] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A knowledge editing method for a large language model based on pattern matching, characterized in that: include: Acquire target editing knowledge, wherein the target editing knowledge is used to update knowledge of a large language model; Determining a plurality of pattern matching levels between each level in the large language model and the target edited knowledge; Determine the highest pattern matching degree among the multiple pattern matching degrees, and use the level corresponding to the highest pattern matching degree as the target editing level; The multilayer perceptron of the target editing layer is rank-one edited based on the target editing knowledge to obtain an edited large language model.

2. The knowledge editing method of a large language model based on pattern matching according to claim 1, characterized in that: After acquiring the target editing knowledge, the method further includes: The target editing knowledge is standardized to obtain at least one input sequence and at least one output sequence corresponding to the target editing knowledge.

3. The knowledge editing method of a large language model based on pattern matching according to claim 2, characterized in that: After the target editing knowledge is standardized to obtain at least one input sequence and at least one output sequence corresponding to the target editing knowledge, the method further includes: Determining at least one potential sequence to be edited corresponding to the target editing knowledge based on the at least one input sequence and the at least one output sequence; The large language model is continuously edited based on the at least one potential sequence to be edited.

4. The knowledge editing method of a large language model based on pattern matching according to claim 3 is characterized in that: The edited large language model is used to output the output sequence that matches the input sequence; the edited large language model is used to output the output sequence that matches an equivalent data set, wherein the similarity between the equivalent data set and the input sequence is greater than a preset equivalence threshold.

5. The knowledge editing method of a large language model based on pattern matching according to claim 3, characterized in that: The edited large language model maintains the original output on data unrelated to the potential sequence to be edited.

6. The knowledge editing method of a large language model based on pattern matching according to claim 1, characterized in that: The step of performing rank-one editing on the multilayer perceptron of the target editing layer based on the target editing knowledge to obtain an edited large language model includes: Adding a residual term to the output of a feedforward neural network of a multilayer perceptron of the target editing layer; Parameters of the residual term are updated to obtain the edited large language model, wherein an output of the edited large language model is aligned with an expected result corresponding to the target edited knowledge.

7. A knowledge editing device for a large language model based on pattern matching, characterized in that: include: An acquisition module, used for acquiring target editing knowledge, wherein the target editing knowledge is used for updating knowledge of a large language model; A determination module, used to determine a plurality of pattern matching degrees between each level in the large language model and the target editing knowledge; A matching module, used to determine the highest pattern matching degree among the multiple pattern matching degrees, and use the level corresponding to the highest pattern matching degree as the target editing level; The editing module is used to perform rank-one editing on the multilayer perceptron of the target editing layer based on the target editing knowledge to obtain an edited large language model.

8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the knowledge editing method of a large language model based on pattern matching as described in any one of claims 1 to 6 is implemented.

9. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method for editing knowledge of a large language model based on pattern matching as claimed in any one of claims 1 to 6 is implemented.

10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the method for editing knowledge of a large language model based on pattern matching as claimed in any one of claims 1 to 6 is implemented.

Citation Information

Patent Citations

  • Model training method and device, operator compiling method and device, equipment and storage medium

    CN117055900A

  • Editing method and device for pre-training language model

    CN117851613A

  • Real-time pruning method and system for neural network, and neural network accelerator

    WO2023019899A1

Cited By

  • Large language model knowledge editing method and interaction method based on knowledge representation decoupling

    CN120181205A

  • Large language model knowledge editing method and interactive method based on knowledge representation decoupling

    CN120181205B

  • Knowledge updating method, device and equipment of model based on industrial internet, medium and program product

    CN120973892A

  • Electric power regulation and control model editing method and system and storage medium

    CN121072752A

  • Knowledge graph-based knowledge question-answering method, medium and equipment

    CN121524297A