A sequence model editing method, device, electronic device and storage medium

By obtaining and updating hidden vectors and neuronal parameters in the sequence model, the problem of forgetting and crashing during the model editing process is solved, and the effect of retaining knowledge and reducing editing risks during the continuous editing process is achieved.

CN118585639BActive Publication Date: 2024-11-05UNIV OF SCI & TECH OF CHINA
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411067077.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-08-06
Publication Date
2024-11-05
Estimated Expiration
2044-08-06

AI Technical Summary

Technical Problem

Existing sequence model editing methods are prone to forget and crash during the continuous editing process, unable to effectively retain the knowledge of previous modifications, and excessive editing will damage the model's ability to generate coherent text.

Method used

By obtaining the original hidden vector in the sequence model, positioning the position to be edited, determining the optimal hidden vector, selecting a subset of high-score neurons, updating the weight matrix, and iterating the neuron parameters until a specific threshold is met, to fix the original parameters and Reduce editing times and avoid model forgetting and crashing.

Benefits of technology

It effectively alleviates the problem of model forgetting, reduces the number of model edits, prevents model damage, and ensures that the model retains previous knowledge and generates coherent text during continuous editing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118585639B_ABST
    Figure CN118585639B_ABST
Patent Text Reader

Abstract

The present invention discloses a sequence model editing method, device, electronic device and storage medium, comprising: giving a prompt word to the sequence model, obtaining multiple original hidden vectors of the prompt word; locating the position to be edited of the sequence model according to the multiple original hidden vectors, the position to be edited includes a target layer and a keyword; determining the optimal hidden vector according to the multiple original hidden vectors of the keyword; selecting high-scoring neurons activated in the target layer after the prompt word is given, and determining a neuron subset; modifying the neuron parameters of the neuron subset, and updating the weight matrix of each layer; iteratively selecting neurons of the target layer to obtain an iterated neuron subset, and modifying the neuron parameters of the iterative neuron subset. The present invention can alleviate the model forgetting problem to a great extent; and by selecting the target layer and part of the neurons, the number of model edits is reduced, thereby reducing the risk of preventing model damage.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of video concentration in computer vision, and specifically to a sequence model editing method, device, electronic device and storage medium. Background Art

[0002] Large-scale language models (LLMs) have demonstrated remarkable capabilities to store large amounts of factual knowledge during pre-training and to recall this information during reasoning. However, as real-world knowledge continues to evolve, the information in these models may become outdated or incorrect. Retraining LLMs to incorporate new information is costly. Therefore, a large number of model editing methods have emerged in recent years that focus on modifying specific knowledge without full retraining. These methods first identify key layers by computing the causal influence of the target knowledge on the output, and then modify the final output by updating the weights of these layers and manipulating the hidden states of these layers, thereby enabling LLMs to seamlessly adapt to dynamic real-world information.

[0003] Although current direct model editing approaches work well for a single round of modifications, real-world applications require a process of continuous learning, where the model must retain previous edits in subsequent modifications. This leads to the concept of sequential model editing, which requires multiple consecutive edits to the model. However, current model editing approaches present significant risks in this context. The main risk is model forgetting, where the cumulative changes in parameters during consecutive edits cause the model to forget the knowledge of previous modifications, resulting in a decrease in overall performance. In addition, the second risk is model failure, where too many edits impair the model's ability to generate coherent text and may even cause the model to crash, manifesting as the generation of irrelevant, repetitive, or meaningless text. Summary of the invention

[0004] This embodiment provides a sequence model editing method, device, electronic device and storage medium, and explores how to solve the problem that the sequence model forgets the previously modified knowledge during the continuous editing process, and excessive editing damages the model's generation of coherent text and causes the model to crash.

[0005] In a first aspect, the present invention provides a sequence model editing method, comprising:

[0006] Give the sequence model a prompt word and obtain multiple original hidden vectors of the prompt word ;

[0007] According to multiple original hidden vectors Locating a position to be edited of the sequence model, wherein the position to be edited includes a target layer and a keyword element;

[0008] Multiple original hidden vectors based on keyword meta- , determine the optimal hidden vector ;

[0009] After a given prompt word is given, the high-scoring neurons activated in the target layer are selected to determine the neuron subset ;

[0010] Modifying the neuron subset The neuron parameters of each layer are updated ;

[0011] Iteratively select neurons in the target layer to obtain the iterated neuron subset , modify the neuron subset after iteration The neuron parameters are adjusted until the optimal hidden vector and the original hidden vector Satisfy the formula: ,in for target threshold.

[0012] In some embodiments, a prompt word is given to the sequence model, and a plurality of original hidden vectors of the prompt word are obtained. ,include:

[0013] Giving a prompt word to the sequence model, the prompt word is decomposed into a plurality of word-units corresponding to each layer;

[0014] The multiple word units are sent to the decoder block to obtain the original hidden vector corresponding to each word unit .

[0015] In some of the embodiments, according to a plurality of original hidden vectors Locating a position to be edited of the sequence model, wherein the position to be edited includes a target layer and a keyword element, including:

[0016] The original hidden vector corresponding to each layer of the sequence model Add Gaussian noise to determine the disturbed model;

[0017] Calculate the first probability of the interfered model outputting the target word;

[0018] The Gaussian noise is removed progressively at each layer so that the original hidden vector are restored to their original values;

[0019] Calculate the original hidden vector The model output restored to its original value has a second probability of the target word;

[0020] Obtaining a difference between the first probability and each second probability to obtain a plurality of differences;

[0021] quantifying the plurality of differences to obtain a plurality of restoration scores;

[0022] Based on the plurality of restoration scores, a plurality of target layers exceeding preset restoration scores are identified.

[0023] In some of the embodiments, the original hidden vectors of the key words are , determine the optimal hidden vector ,include:

[0024] Get multiple original hidden vectors The loss value of

[0025] Optimize the loss value to obtain the optimal hidden vector .

[0026] In some embodiments, after a given prompt word is given, a high-scoring neuron in the target layer that is activated is selected to determine a neuron subset. ,include:

[0027] Based on the given cue word, determine the activated neurons in each layer;

[0028] Calculating an activation value score according to the activated neurons;

[0029] sorting the activation value scores;

[0030] Selecting the subset of neurons from the ranked activation scores .

[0031] In some of these embodiments, modifying the subset of neurons The neuron parameters of each layer are updated ,include:

[0032] Get the weight matrix in the last round of editing Weight The residual ;

[0033] Optimizing the weights The residual ;

[0034] According to the optimized weights The residual , determine the optimal model parameter change;

[0035] Update the weight matrix according to the optimal model parameter change .

[0036] Compared with the prior art, a sequence model editing method of the present invention can alleviate the model forgetting problem to a great extent by fixing the original parameters during the optimization of the original hidden vector change amount; and by selecting the target layer and some neurons, the number of model editing times is reduced, thereby reducing the risk of preventing model damage.

[0037] In a second aspect, the present invention provides a sequence model editing device, comprising:

[0038] The original hidden vector acquisition module is used to give a prompt word to the sequence model and obtain multiple original hidden vectors of the prompt word. ;

[0039] The positioning module is used to locate the Locating a position to be edited of the sequence model, wherein the position to be edited includes a target layer and a keyword element;

[0040] The optimal hidden vector optimization module is used to optimize the original hidden vectors of the keyword element. , determine the optimal hidden vector ;

[0041] The neuron selection module is used to select the high-scoring neurons activated in the target layer after a given prompt word, and determine the neuron subset ;

[0042] A neuron parameter modification module, used to modify the neuron subset The neuron parameters of each layer are updated ;

[0043] Multi-layer iteration module, used to iteratively select neurons in the target layer and obtain the neuron subset after iteration , modify the neuron subset after iteration The neuron parameters are adjusted until the optimal hidden vector and the original hidden vector Satisfy the formula: ,in for target threshold.

[0044] In a third aspect, the present invention provides an electronic device, comprising a memory and a processor, wherein the memory stores at least one computer executable instruction, and the processor is configured to run the computer executable instruction, and when the computer executable instruction is executed by the processor, a sequence model editing method described in the first aspect is implemented.

[0045] In a fourth aspect, the present invention provides a computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the mold flow analysis method described in the first aspect is implemented.

[0046] Compared with the prior art, the beneficial effects of the sequence model editing device, electronic device and storage medium of the present invention are the same as the beneficial effects of the above-mentioned sequence model editing method, so they are not repeated here. BRIEF DESCRIPTION OF THE DRAWINGS

[0047] Figure 1 A schematic diagram of a flow chart of a sequence model editing method in an embodiment provided by the present invention;

[0048] Figure 2 A working process diagram of a sequence model editing method in an embodiment provided by the present invention;

[0049] Figure 3 A structural block diagram of a sequence model editing device in an embodiment provided by the present invention;

[0050] Figure 4 A diagram of an electronic device in an embodiment of the present invention; DETAILED DESCRIPTION

[0051] In order to more clearly understand the purpose, technical solutions and advantages of the present application, the present application is described and illustrated below in conjunction with the accompanying drawings and embodiments.

[0052] Unless otherwise defined, the technical terms or scientific terms involved in this application shall have the general meaning understood by people with general skills in the technical field to which this application belongs. The words "one", "a", "the", "these" and the like in this application do not indicate a quantitative limitation, and they may be singular or plural. The terms "include", "comprise", "have" and any variants thereof involved in this application are intended to cover non-exclusive inclusions; for example, a process, method and system, product or device comprising a series of steps or modules (units) is not limited to the listed steps or modules (units), but may include unlisted steps or modules (units), or may include other steps or modules (units) inherent to these processes, methods, products or devices. The words "connect", "connected", "coupled" and the like involved in this application are not limited to physical or mechanical connections, but may include electrical connections, whether direct or indirect. The "multiple" involved in this application refers to two or more. "And / or" describes the association relationship of associated objects, indicating that there may be three relationships, for example, "A and / or B" may mean: A exists alone, A and B exist at the same time, and B exists alone. Generally, the character " / " indicates that the objects associated with each other are in an "or" relationship. The terms "first", "second", "third", etc. in this application are only used to distinguish similar objects and do not represent a specific ordering of the objects.

[0053] First, the prior art and related concepts involved in the embodiments of the present invention are described:

[0054] Token: A token is a basic unit of preprocessed text data. The original text string is cut into a series of tokens by a tokenizer. These tokens can be words, subwords, characters, or other meaningful language units, depending on the word segmentation strategy used. For example, the sentence "The cat sat on the mat." may be divided into the following token sequence: ['The', 'cat', 'sat', 'on', 'the', 'mat','.']. In this embodiment, it will be called: word unit.

[0055] Original hidden vector: It is the intermediate representation of the model’s understanding of text features. Each token will generate a new original hidden vector after passing through each layer of the model.

[0056] Gaussian noise: A common type of random noise in statistics, whose distribution follows a normal distribution (also called a Gaussian distribution). In machine learning and deep learning, adding Gaussian noise to model input or intermediate representation is a regularization method that aims to improve the robustness and generalization of the model. In this way, the model is forced to learn more stable and robust feature representations during training, because they must make accurate predictions on data containing slight random variations, so that they can better cope with the uncertainty in unseen data.

[0057] Neuron: In the context of neural networks, "neuron" and "node" are synonymous, referring to the basic unit that performs calculations in the network. Neurons receive input signals, perform a weighted sum on them, and then produce outputs through an activation function. This process occurs in neurons in the input layer, hidden layer, and output layer;

[0058] In an embodiment of the present invention, a sequence model editing method is provided. Figures 1 to 4 , the editing method regards the weights of the feedforward neural network (FFN) layer of the Transformer model as a linear associative memory, that is, the linear operations within the FFN layer can be regarded as key-value storage for information retrieval.

[0059] Its definition can be expressed as, given the The input weight matrix of the FFN layer ( ), based on knowledge facts When it is a prompt word, the head entity The activation output of the last word is identified as Layer Key ; After that, the key Through the weight matrix Processing, generating values .

[0060] Figure 1 is a flow chart of a sequence model editing method of the present invention, the process comprising the steps of:

[0061] S1. Give a prompt word to the sequence model and obtain multiple original hidden vectors of the prompt word ;

[0062] The step S1 specifically includes: giving a prompt word to the sequence model, the prompt word is decomposed into a plurality of word units corresponding to each layer; the plurality of word units are sent to the decoder block to obtain the original hidden vector corresponding to each word unit .

[0063] For example, reference Figure 2 In this embodiment, given a knowledge fact , i.e. the prompt word ; The prompt word The token sequence is decomposed into multiple words, and then the words are calculated by the original weights of the decoder block of each layer to obtain the original hidden vector corresponding to each word. ; In this embodiment, it is simplified to a unified original hidden vector .

[0064] The process includes the following steps:

[0065] S2, based on multiple original hidden vectors Locating a position to be edited of the sequence model, wherein the position to be edited includes a target layer and a keyword element;

[0066] The step S2 specifically comprises:

[0067] The original hidden vector corresponding to each layer of the sequence model Add Gaussian noise to determine the disturbed model;

[0068] Calculate the first probability of the interfered model outputting the target word;

[0069] The Gaussian noise is removed progressively at each layer so that the original hidden vector are restored to their original values;

[0070] Calculate the original hidden vector The model output restored to its original value has a second probability of the target word;

[0071] Obtaining a difference between the first probability and each second probability to obtain a plurality of differences;

[0072] quantifying the plurality of differences to obtain a plurality of restoration scores;

[0073] Based on the plurality of restoration scores, a plurality of target layers exceeding preset restoration scores are identified.

[0074] After determining the key words and target layers that can be used for editing, the intermediate layer editing operation of the sequence model is performed. In this embodiment, the target layer range of the editing is represented as , so the editing process can be defined as: given a knowledge fact tuple ,in, Represents the head entity, Indicates relationship, Represents the tail entity; the head entity Plays the main role of the text, and the tail entity plays the generated target content , is the relationship between the head entity and the tail entity. The goal is to edit the output of the LLM model so that When it is a prompt word, the target content will be generated .

[0075] In this embodiment, according to the recovery score, a large number of samples (prompt word samples) are required to analyze the target layer of the sequence model (such as layers 3-8 in the GPT-J model) and the position of the keyword word (the last word of the head entity).

[0076] For example, in the sentence "The cat chased the mouse.", "The cat" is the subject, "chased" is the predicate, and "the mouse" is the object. If the sentence is converted into a token sequence, "The", "cat", "chased", "the", and "mouse" each become a token, then "cat", which is the last token of the subject, is the keyword token.

[0077] The process also includes the steps of:

[0078] S3. Multiple original hidden vectors based on keyword meta-words , determine the optimal hidden vector ;

[0079] The step S3 specifically comprises: obtaining a plurality of the original hidden vectors The loss value is optimized to obtain the optimal hidden vector .

[0080] Exemplarily, in this implementation, the change in the original hidden vector is optimized by gradient descent optimization. , and based on the original hidden vector change Maximize the model output target content The probability of , thereby calculating the optimal hidden vector ; Optimal hidden vector The expression is: (Formula 1)

[0081] Furthermore, during the sequence model editing process, it was observed that the updated model parameters were used after each edit. Calculate the optimal hidden vector This causes the model to degrade significantly over multiple editing rounds. Instead, using the original model parameters Calculate the optimal hidden vector This effectively prevents this problem. Thus, the original model parameters are preserved before any editing is done. , making sure to use Calculate the optimal hidden vector , thereby alleviating the adverse effects of cumulative changes in model parameters due to continuous editing; note that this approach only involves changes in the original hidden vector Use original model parameters during optimization , and subsequent editing is based on the changed model parameters, so the optimization objective formula of the method is as follows:

[0082] ; (Formula 2)

[0083] in, Represents finding the optimal original hidden vector change value, represents a negative value of the log-likelihood, Represents model parameters The optimization goal is to maximize the probability distribution of a given input prompt word Output target output under condition , thereby ensuring that new associations are correctly encoded while preserving existing ones.

[0084] also, Represents the original model, and the original hidden vector of the original model Updated to It is expressed as ; Then, Can be updated to , indicating that the model is The output vector of the FFN layer Can be updated to , which will be used for weight updates after support.

[0085] As further explanation, the FFN layer output vector of the original model is , and the original hidden vector has been optimized and calculated before The optimal hidden vector But the model parameters have not changed. So by modifying the weight matrix in the FFN layer To make the original hidden vector becomes the optimal hidden vector , passing it to the FFN layer is equivalent to the output of FFN becoming the output vector Add the original hidden vector The difference between the optimal hidden vector and the optimal hidden vector (refer to the Transformer architecture).

[0086] The process also includes the steps of:

[0087] S4. Select the high-scoring neurons activated in the target layer after the given prompt word, and determine the neuron subset ;

[0088] The step S4 specifically comprises:

[0089] Based on the given cue word, determine the activated neurons in each layer;

[0090] Calculating an activation value score according to the activated neurons;

[0091] sorting the activation value scores;

[0092] Selecting the subset of neurons from the ranked activation scores .

[0093] Specifically, for a given knowledge fact , using the activation value of the neuron Calculate its activation score , that is, the absolute value of the activation value represents the activation value score. Among them, the neuron activation value obtained by the activation layer after the output of the first MLP change in the FFN layer is , which is equivalent to the input of the second MLP. According to the activation value score , the activation value score of the neuron Sort and select neurons according to the sorting so that the cumulative score of the selected neurons exceeds a predetermined percentage of the total score to obtain a neuron subset , the formula is:

[0094] , (Formula 3)

[0095] in, is the set of indices of the selected neurons, Indicates The activation score of each neuron is It is the abbreviation of "subject to", which means "subject to" or "satisfy conditions", indicating that the objective function of a variable is solved under certain conditions; therefore, what Equation 3 means is to select a subset of neurons is an optimization problem, the goal is to minimize the number of selected neurons (expressed in ), but the cumulative score of these neurons must be greater than or equal to the specified ratio Multiply by the total score of all neurons. That is, the set of neurons to be found, whose index set , which will make the cumulative score on this group of neurons At least the total score times. And under this condition, we should try to minimize The size of the neural network is to minimize the number of neurons selected so that a small number of key neurons can be selected for editing instead of modifying the weight matrix of the entire model at once. .

[0096] For example, the activation score is a vector where each value corresponds to the activation score of a neuron, so the activation score Sum all values ​​and select the activation value score The sum of the scores corresponding to the neurons in the middle part makes it greater than The sum of all neurons, It is generally 0.8, which means that the sum of the element values ​​of the subsets in the set can reach 0.8 times the total amount.

[0097] In order to meet the needs of batch editing, that is, to edit multiple knowledge facts at the same time, each knowledge fact may correspond to different sets of neurons. To this end, it is necessary to extract a unified neuron selection from all knowledge facts in the current batch; by dividing the scores of all knowledge facts in the current batch by The aggregated scores are summed up for unified neuron selection, which enables neuron editing to be extended to batch editing.

[0098] However, some knowledge facts may have significantly different neuron sets, which may conflict with the score aggregation. Therefore, a further clustering strategy of neuron sets can be adopted, see Figure 2 As shown in the figure, all knowledge facts are clustered according to the Jaccard similarity to select the corresponding neuron set, so that each cluster is regarded as a mini-batch for unified neuron operation. That is, the neuron set is decomposed into small batches according to the Jaccard similarity in the batch, and batch editing is performed in each small batch of knowledge.

[0099] The process also includes the steps of:

[0100] S5. Modify the neuron subset The neuron parameters of each layer are updated ;

[0101] The step S5 specifically comprises:

[0102] Get the weight matrix in the last round of editing Weight The residual ;

[0103] Optimizing the weights The residual ;

[0104] According to the optimized weights The residual , determine the optimal model parameter change;

[0105] Update the weight matrix according to the optimal model parameter change .

[0106] For example, by selecting a subset of neurons To update the weight matrix First, we need to define knowledge facts After using the last round of editing The weight matrix of the layer Weight The residual ,Right now Then let , represents the amount of change in the model parameters. The goal of this step is to modify only the weights To achieve the optimization goal, we can assume that the weights of the previous round of editing are It is enough to adapt to the internal knowledge and the previously edited knowledge. Here, the optimal expression of the optimal model parameter change is defined as:

[0107] ;(Formula 4)

[0108] in, is the desired target output, which is equivalent to the vector output by the second MLP in the FFN layer. Use the current weight The corresponding output when represents the change in model parameters, represents the optimal model parameter change, is the neuron activation value of the i-th neuron, corresponding to the following three parts: Represents the inherent knowledge of the model, The model is edited in the past, so the above knowledge needs to be retained. The new knowledge that is about to be edited for the model.

[0109] The optimization goal is to find a set of optimal model parameter changes , so that the sum of the changes in the weights of all neurons, the sum of the changes in the weights of the new knowledge, and the sum of the squares of the residuals are minimized; this optimization can be seen as minimizing the weight changes of new knowledge while keeping the existing knowledge unchanged, and making the output of the new knowledge as close to the expected output as possible .

[0110] Formula 4 shows that in the editing process, we hope to find a set of appropriate weight changes so that the new knowledge can be correctly reflected in the model output while avoiding excessive changes to the existing knowledge. The advantage of doing so is that it can ensure the stability and accuracy of the model and prevent excessive editing from causing the loss or destruction of other knowledge. By solving this problem using the least squares method, we can get a set of optimal weights: Change, update the weight matrix of each layer Then complete the knowledge editing.

[0111] The process also includes the steps of:

[0112] S6. Iteratively select neurons in the target layer to obtain the iterated neuron subset , modify the neuron subset after iteration The neuron parameters are adjusted until the optimal hidden vector and the original hidden vector Satisfy the formula: , (Formula 5) where for target threshold.

[0113] Exemplarily, the above model editing process is extended to multiple layers; by updating the output vector Propagate the edits to each layer with the formula ( ).

[0114] Specifically, each layer of editing will still gradually transform the original hidden vector Approximating the optimal hidden vector , but a single execution of the above multi-layer model editing usually cannot fully utilize the original hidden vector Approximating to the optimal hidden vector Therefore, by iteratively selecting neurons to edit multiple layers, refer to Figure 2 , reselect neurons in each iteration to update the weight matrix of each layer ,until Below target threshold , indicating that the editing is successful.

[0115] Compared with the existing model editing methods that need to change model parameters, the model editing method proposed in this embodiment has the following advantages: 1) In the sequence model editing task, the editing method of this embodiment changes the original hidden vector Fixing the original parameters during optimization can alleviate the model forgetting problem to a great extent. 2) And by selecting the target layer and some neurons, the number of model edits is reduced, thereby reducing the risk of model damage.

[0116] The embodiment of the present invention also provides a sequence model editing device, which is used to implement the above method embodiment, and will not be repeated hereafter. The terms "module", "unit", "subunit", etc. used below can implement a combination of software and / or hardware for a predetermined function. Although the device described in the following embodiments is preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceivable.

[0117] like Figure 3 As shown, Figure 3 1 is a structural block diagram of a sequence model editing device of the present invention, the device comprising:

[0118] The original hidden vector acquisition module 110 is used to give a prompt word to the sequence model and obtain multiple original hidden vectors of the prompt word. ;

[0119] The positioning module 120 is used to locate the hidden vectors according to the plurality of original hidden vectors. Locating a position to be edited of the sequence model, wherein the position to be edited includes a target layer and a keyword element;

[0120] The optimal hidden vector optimization module 130 is used to optimize the hidden vectors according to the multiple original hidden vectors of the keyword element. , determine the optimal hidden vector ;

[0121] The neuron selection module 140 is used to select the high-scoring neurons in the target layer that are activated after a given prompt word, and determine the neuron subset. ;

[0122] Neuron parameter modification module 150, used to modify the neuron subset The neuron parameters of each layer are updated ;

[0123] The multi-layer iteration module 160 is used to iteratively select neurons in the target layer to obtain the iterated neuron subset. , modify the neuron subset after iteration The neuron parameters are adjusted until the optimal hidden vector and the original hidden vector Satisfy the formula: ,in for target threshold.

[0124] In the above device, the original hidden vector acquisition module 110 acquires multiple original hidden vectors of the prompt word. ; Through the positioning module 120, the position to be edited of the sequence model is located; through the optimal hidden vector optimization module 130, the optimal hidden vector is determined ; Determine the neuron subset through the neuron selection module 140 ; Update the weight matrix of each layer through the neuron parameter modification module 150 ; Modify the iterated neuron subset through the multi-layer iteration module 160 The neuron parameters are adjusted until the optimal hidden vector and the original hidden vector Satisfy the formula: ,in for The target threshold can prevent model damage to a large extent, improve the success rate of model editing, and alleviate the problem of model forgetting.

[0125] like Figure 4 As shown, an embodiment of the present invention further provides an electronic device, which includes a memory 230 and a processor 210, wherein the memory 230 stores at least one computer executable instruction, and the processor 210 is configured to run the computer executable instruction, and when the computer executable instruction is run by the processor 210, the above-mentioned sequence model editing method is implemented.

[0126] The electronic device may include a processor 210, a communication interface 220, a memory 230, and a communication bus 240, wherein the processor 210, the communication interface 220, and the memory 230 communicate with each other through the communication bus 240. The processor 210 may call the logic instructions in the memory 230 to execute a sequence model editing method disclosed in this embodiment.

[0127] In addition, the logic instructions in the above-mentioned memory 230 can be implemented in the form of software functional units and can be stored in a computer-readable storage medium when 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, which is stored in a storage medium and includes several 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 methods of each embodiment of the present invention. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.

[0128] 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 shown as units may or may not be physical units, i.e., 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. Those of ordinary skill in the art may understand and implement it without creative effort.

[0129] 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, it 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.

[0130] 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 sequence model editing method, characterized in that: include: Give the sequence model a prompt word and obtain multiple original hidden vectors of the prompt word ; Give the sequence model a prompt word and obtain multiple original hidden vectors of the prompt word ,include: Giving a prompt word to the sequence model, the prompt word is decomposed into a plurality of word-units corresponding to each layer; The multiple word units are sent to the decoder block to obtain the original hidden vector corresponding to each word unit ; According to multiple original hidden vectors Locating a position to be edited of the sequence model, wherein the position to be edited includes a target layer and a keyword element; According to multiple original hidden vectors Locating a position to be edited of the sequence model, wherein the position to be edited includes a target layer and a keyword element, including: The original hidden vector corresponding to each layer of the sequence model Add Gaussian noise to determine the disturbed model; Calculate the first probability of the target word output by the disturbed model; The Gaussian noise is removed progressively at each layer so that the original hidden vector are restored to their original values; Calculate the original hidden vector The model output restored to its original value has a second probability of the target word; Obtaining a difference between the first probability and each second probability to obtain a plurality of differences; quantifying the plurality of differences to obtain a plurality of restoration scores; identifying a plurality of target layers exceeding preset recovery scores based on the plurality of recovery scores; Multiple original hidden vectors based on keyword meta- , determine the optimal hidden vector ; Multiple original hidden vectors based on keyword meta- , determine the optimal hidden vector ,include: Get multiple original hidden vectors The loss value of Optimize the loss value to obtain the optimal hidden vector ; After a given prompt word is given, the high-scoring neurons activated in the target layer are selected to determine the neuron subset ; After a given prompt word is given, the high-scoring neurons activated in the target layer are selected to determine the neuron subset ,include: Based on the given cue word, determine the activated neurons in each layer; Calculating an activation value score according to the activated neurons; sorting the activation value scores; Selecting the subset of neurons from the ranked activation scores ; Modifying the neuron subset The neuron parameters of each layer are updated ; Modifying the neuron subset The neuron parameters of each layer are updated ,include: Get the weight matrix in the last round of editing Weight The residual ; Optimizing the weights The residual ; According to the optimized weight The residual , determine the optimal model parameter change; Update the weight matrix according to the optimal model parameter change ; Iteratively select neurons in the target layer to obtain the iterated neuron subset , modify the neuron subset after iteration The neuron parameters are adjusted until the optimal hidden vector and the original hidden vector Satisfy the formula: ,in for target threshold.

2. A sequence model editing device, characterized in that: include: The original hidden vector acquisition module is used to give a prompt word to the sequence model and obtain multiple original hidden vectors of the prompt word. ; Give the sequence model a prompt word and obtain multiple original hidden vectors of the prompt word ,include: Giving a prompt word to the sequence model, the prompt word is decomposed into a plurality of word-units corresponding to each layer; The multiple word units are sent to the decoder block to obtain the original hidden vector corresponding to each word unit ; The positioning module is used to locate the Locate the position to be edited of the sequence model, wherein the position to be edited includes a target layer and a keyword element; according to a plurality of original hidden vectors Locating a position to be edited of the sequence model, wherein the position to be edited includes a target layer and a keyword element, including: The original hidden vector corresponding to each layer of the sequence model Add Gaussian noise to determine the disturbed model; Calculate the first probability of the interfered model outputting the target word; The Gaussian noise is removed progressively at each layer so that the original hidden vector are restored to their original values; Calculate the original hidden vector The model output restored to its original value has a second probability of the target word; Obtaining a difference between the first probability and each second probability to obtain a plurality of differences; quantifying the plurality of differences to obtain a plurality of restoration scores; identifying a plurality of target layers exceeding preset recovery scores based on the plurality of recovery scores; The optimal hidden vector optimization module is used to optimize the original hidden vectors of the keyword element. , determine the optimal hidden vector ; Multiple original hidden vectors based on keyword meta- , determine the optimal hidden vector ,include: Get multiple original hidden vectors The loss value of Optimize the loss value to obtain the optimal hidden vector ; The neuron selection module is used to select the high-scoring neurons activated in the target layer after a given prompt word, and determine the neuron subset ; Select the high-scoring neurons activated in the target layer after the given prompt word, and determine the neuron subset ,include: Based on the given cue word, determine the activated neurons in each layer; Calculating an activation value score according to the activated neurons; sorting the activation value scores; Selecting the subset of neurons from the ranked activation scores ; A neuron parameter modification module, used to modify the neuron subset The neuron parameters of each layer are updated ; Modify the neuron subset The neuron parameters of each layer are updated ,include: Get the weight matrix in the last round of editing Weight The residual ; Optimizing the weights The residual ; According to the optimized weight The residual , determine the optimal model parameter change; Update the weight matrix according to the optimal model parameter change ; Multi-layer iteration module, used to iteratively select neurons in the target layer and obtain the neuron subset after iteration , modify the neuron subset after iteration The neuron parameters are adjusted until the optimal hidden vector and the original hidden vector Satisfy the formula: ,in for target threshold.

3. An electronic device, characterized in that: The electronic device includes a memory and a processor, the memory stores at least one computer executable instruction, and the processor is configured to execute the computer executable instruction. When the computer executable instruction is executed by the processor, the sequence model editing method according to claim 1 is implemented.

4. A computer-readable storage medium, characterized in that: A computer program is stored on a computer-readable storage medium, and when the computer program is executed by a processor, the method for editing a sequence model according to claim 1 is implemented.