Knowledge editing method and device of autoregressive large language model

By identifying key layers in an autoregressive large language model and using low-rank matrix processing, the problems of long training cycles and high editing costs are solved, achieving more efficient knowledge editing.

CN120218023BActive Publication Date: 2025-11-18BEIJING DP TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510337893.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-03-21
Publication Date
2025-11-18
Estimated Expiration
2045-03-21

AI Technical Summary

Technical Problem

The knowledge editing process of existing autoregressive large language models suffers from problems such as long training cycles, low editing efficiency, and high costs.

Method used

By identifying attention/MLP layers that are strongly associated with knowledge information as key layers, and optimizing the parameters of only these key layers during each knowledge editing, a low-rank matrix approach is used to reduce computational complexity and the total number of optimization parameters.

Benefits of technology

It effectively shortens the training cycle, improves editing efficiency, and reduces editing costs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120218023B_ABST
    Figure CN120218023B_ABST
Patent Text Reader

Abstract

The embodiment of the present application relates to a kind of autoregressive large language model's knowledge editing method and device, the method includes: autoregressive large language model is as target model;And each knowledge entry in the pre-training knowledge base of target model is converted into question-answer text pair;Each text pair is processed according to three kinds of model reasoning mode (single normal inference, single perturbation inference, multiple repair inference under perturbation premise) to obtain first, second predicted text and third prediction information set;And based on the first, second predicted text and third prediction information set of each text pair, a key layer estimation is carried out;And according to all estimated key layers, key layer final judgment is carried out, and the parameter reset of target model is carried out by the way of implanting low rank matrix parameter in all key layers;And all low rank matrix parameters implanted form implantation parameter set, and only implantation parameter set is updated in each knowledge editing process.The present application can improve editing efficiency and reduce editing cost.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of data processing technology, and in particular to a knowledge editing method and apparatus for an autoregressive large language model. Background Technology

[0002] Autoregressive Large Language Models (AMLs) can perform various Natural Language Processing (NLP) tasks, such as text generation, machine translation, intelligent question answering, and text classification. Currently, most common AMLs (such as GPT, BERT, LLaMA, and T5) are based on Transformer models. This means that if we break down these common AMLs, we find that they are mainly composed of a series of attention modules and multilayer perceptron (MLP) modules. These attention / MLP modules can be represented hierarchically as a series of attention / MLP layers, each corresponding to a set of independent layer weight parameters.

[0003] During the pre-training phase, autoregressive large language models learn from massive amounts of linguistic knowledge and establish mapping relationships between all learned knowledge features and the layer weights of all attention / MLP layers, thus enabling the model to store knowledge information. If knowledge editing (updating, modifying, or optimizing) of the knowledge information stored by the autoregressive large language model is required, it can be achieved through model fine-tuning. The conventional model fine-tuning method involves collecting the knowledge information to be edited to construct a fine-tuning corpus, and then training and optimizing the overall model parameters of the autoregressive large language model based on this corpus until the model converges. In other words, this conventional knowledge editing method optimizes the overall model parameters of the autoregressive large language model. However, the number of parameters in any common autoregressive large language model is currently enormous, which means that each knowledge editing session will face the following problems: long training cycles, low editing efficiency, and high editing costs.

[0004] To improve this situation, we attempt to identify key attention / MLP layers with strong correlation to knowledge information from the model using this invention. During each knowledge editing process, we only optimize the parameters of these key layers, and employ a low-rank matrix injection method for optimization. This effectively reduces computational complexity and the total number of optimization parameters, thereby shortening the training cycle, improving editing efficiency, and reducing editing costs. Summary of the Invention

[0005] The purpose of this invention is to address the shortcomings of existing technologies by providing a knowledge editing method, apparatus, electronic device, and computer-readable storage medium for autoregressive large language models. This invention takes any autoregressive large language model based on the Transformer model structure that has been pre-trained and fine-tuned for NLP tasks as the target model; it transforms each knowledge item in the pre-trained knowledge base of the target model into a question-answer text pair to obtain a corresponding text pair; it processes each text pair according to three types of model inference methods (single normal inference, single scrambled inference, and multiple repair inference under scrambled premise) to obtain three types of prediction information (first predicted text, second predicted text, and third prediction information set); it performs a key layer prediction based on the three types of prediction information (first predicted text, second predicted text, and third prediction information set) of each text pair to obtain the corresponding first key layer set; it performs a key layer final judgment based on all the obtained first key layer sets to obtain the second key layer set; it resets the model parameters of the target model by implanting low-rank matrix parameters into the layer weight parameters of all second key layers, and the implanted low-rank matrix parameters form the corresponding implanted parameter set; and in each subsequent knowledge editing process, it achieves the knowledge editing effect by only fine-tuning the implanted parameter set. This invention can effectively reduce computational complexity and the total number of optimization parameters, thereby shortening the training cycle, improving editing efficiency, and reducing editing costs.

[0006] To achieve the above objectives, a first aspect of the present invention provides a knowledge editing method for an autoregressive large language model, the method comprising:

[0007] An autoregressive large language model based on the Transformer model structure, which has been pre-trained and fine-tuned for NLP tasks, is used as the target model; and each attention layer or MLP layer in the inference module of the target model is denoted as the corresponding inference layer A. i and for the inference layer A i The total number N is obtained by statistically analyzing the total number of elements. A ; 1 ≤ level index i ≤ N A The target model's internal structure is divided into two main sections: the preprocessing section and the inference section.

[0008] Configure a question-and-answer instruction template for the target model; and convert each knowledge item in the pre-trained knowledge base of the target model into a question-and-answer text pair to obtain the corresponding first text pair.

[0009] Each of the first text pairs is taken as the corresponding current text pair; the question text of the current text pair is input into the question-and-answer instruction template to generate the current instruction text; the current instruction text is used as the model input text and input into the preprocessing module for preprocessing to obtain the corresponding initial vector H0; the initial vector H0 is input into the inference module for one forward inference and the generated text output in this step is used as the first predicted text, and all inference layers A in this inference process are processed. i The output process vector is cached, and a vector matrix M is formed by all cached process vectors; the initial vector H0 is scrambled to obtain a scrambling vector; the scrambling vector is input into the inference module for one forward inference, and the generated text output in this round is used as the second predicted text; then the scrambling vector is input into the inference module again for one round N. A The process involves forward reasoning and, in each round of reasoning, a process vector correction is performed based on the vector matrix M to obtain a vector from N. A A third prediction information set is composed of three third prediction information sets; and based on the current text, a key layer prediction is performed on the corresponding first and second prediction texts and the third prediction information set to obtain the corresponding first key layer set;

[0010] The second key layer set is obtained by performing a final key layer judgment based on all the first key layer sets; and the model parameters of the target model are reset by embedding low-rank matrix parameters into the layer weight parameters of all the second key layers.

[0011] The implanted parameter set is composed of all the low-rank matrix parameters implanted; and only the implanted parameter set is updated during each knowledge editing process.

[0012] Preferably, the NLP task includes at least text generation and intelligent question answering;

[0013] The preprocessing module is used to preprocess the model input text, specifically: performing word segmentation on the model input text to obtain a word segmentation sequence, and performing embedding encoding on each word of the word segmentation sequence according to the set embedding encoding rules to obtain the corresponding initial vector H0, which is then sent to the inference module; the inference module is used to perform forward inference based on the input initial vector H0 to obtain the corresponding generated text and output it; the inference module contains N A The inference layer A i Each of the aforementioned inference layers A i The layer weight parameter is denoted as weight W. i ;

[0014] The initial vector H0 is composed of multiple sub-vectors h 0,j Composition, 1 ≤ subvector index j ≤ NJ N J The total number of words in the word segmentation sequence corresponding to the initial vector H0;

[0015] The inference layers A corresponding to the initial vector H0 i The output vector is denoted as the process vector H. i The process vector H i Composed of multiple subvectors h i,j Composition, the subvector h i,j With the subvector h 0,j One-to-one correspondence;

[0016] The shape of the vector matrix M corresponding to the initial vector H0 is N. A ×N J , by N A N matrix rows, N J The vector matrix M consists of N matrix columns; the vector matrix M includes N... A ×N J m matrix units i,j ; matrix rows and the process vector H i One-to-one correspondence, and also with the inference layer A. i One-to-one correspondence, the matrix columns correspond one-to-one with the word segments of the word segmentation sequence; the matrix unit m i,j With the subvector h i,j One-to-one correspondence;

[0017] The question-and-answer instruction template is a formatted instruction text template; the configurable parameters of the question-and-answer instruction template include question configuration parameters, which are text parameters; the question-and-answer instruction template is used to prompt the target model to perform text generation processing on the corresponding answer to the question configuration parameters;

[0018] The pre-trained knowledge base includes multiple knowledge entries; the text format of the knowledge entries is a knowledge triplet text format [subject text, subject-object relation text, object text];

[0019] The first text pair corresponds one-to-one with the knowledge item; the first text pair includes the question text and the answer text; the question text is converted from the subject text and the subject-object relation text of the corresponding knowledge item; the answer text is converted from the object text of the corresponding knowledge item.

[0020] The third prediction information set consists of N A The third prediction information comprises a third prediction text and a first correction layer index; the first correction layer index is related to the inference layer A. i One-to-one correspondence;

[0021] The first key layer set consists of multiple first key layers; each first key layer corresponds to one inference layer A. i ;

[0022] The second key layer set consists of multiple second key layers; each second key layer corresponds to one inference layer A. i .

[0023] Preferably, the step of inputting the question text of the current text pair into the question-and-answer instruction template to generate the current instruction text specifically includes:

[0024] The question configuration parameter of the question-and-answer instruction template is set to the question text of the current text pair to obtain a corresponding template setting text, and the template setting text is used as the corresponding current instruction text.

[0025] Preferably, the step of scrambling the initial vector H0 to obtain the scrambling vector specifically includes:

[0026] The word segmentation sequence corresponding to the initial vector H0 is taken as the current word segmentation sequence; the subject word segmentation in the current word segmentation sequence is identified; and the sub-vector h corresponding to the subject word segmentation in the initial vector H0 is... 0,j As the subject vector h subject And generate a vector whose length and feature dimension are both the same as the subject vector h. subject Maintain a consistent random Gaussian noise vector ε; and apply the subject vector h based on the random Gaussian noise vector ε. subject The scrambling is performed to obtain the corresponding scrambling vector, where the scrambling vector = h. subject +ε.

[0027] Preferably, the scrambling vector is then input into the inference module for another round of N... A The process involves forward reasoning and, in each round of reasoning, a process vector correction is performed based on the vector matrix M to obtain a vector from N. A The third prediction information set, composed of three sets of third prediction information, specifically includes:

[0028] Step 51: Set a first counter initialized to 1;

[0029] Step 52: Input the scrambling vector into the inference module to perform one forward inference; and during this forward inference process, each time the inference layer A is passed... i Pause once; and during each pause, the currently passed inference layer A will be... i As the corresponding current inference layer; and the process vector H output by the current inference layer. iAs the corresponding current process vector; and identify whether the layer index i of the current inference layer matches the first counter; if they do not match, release the pause and continue to transmit the current process vector to the next internal component in the inference module; if they match, take the matrix row in the vector matrix M corresponding to the current inference layer as the current matrix row, and based on the total number of word segments N corresponding to the vector matrix M. J Generate a value in N J / 2 to N J A random integer R between the given and given values, and randomly selects R matrix elements m from the current matrix row. i,j For the R corresponding sub-vectors h in the current process vector i,j The replacement is performed to obtain a new current process vector. Then, the pause is lifted and the new current process vector is sent to the next internal component in the inference module. At the end of this forward inference, the generated text output by this inference is used as a corresponding third predicted text. A corresponding first correction layer index is configured for the current third predicted text, and the current first correction layer index is set as the first counter. The current third predicted text and the corresponding first correction layer index are combined to form a corresponding third predicted information.

[0030] Step 53: Increment the first counter by 1; and check whether the incremented first counter exceeds the total number N. A Perform identification; if yes, proceed to step 54; if no, return to step 52.

[0031] Step 54, from the obtained N A The third prediction information constitutes the corresponding third prediction information set.

[0032] Preferably, the step of performing a key layer prediction based on the current text on the corresponding first, second, and third predicted texts to obtain the corresponding first key layer set specifically includes:

[0033] Step 61: Use the answer text of the current text pair as the first tag text;

[0034] Step 62: Input the first label text and the first predicted text as the corresponding current label text and current predicted text into the preset first model loss function for calculation, and use the loss value output by the function at this time as the corresponding loss value a1;

[0035] The first model loss function is used to calculate the loss based on the input current label text and the current predicted text and output the corresponding loss value; the first model loss function is implemented based on the cross-entropy loss function or the negative log-likelihood loss function; the loss value a1 ranges from 0 to 1;

[0036] Step 63: Input the first label text and the second predicted text as the corresponding current label text and the current predicted text into the first model loss function for calculation, and use the loss value output by the function at this time as the corresponding loss value a2;

[0037] The loss value a2 ranges from 0 to 1.

[0038] Step 64: Input the first label text and each of the third prediction texts in the third prediction information set as the corresponding current label text and the current prediction text into the first model loss function for calculation, and use the loss value output by the function at this time as the corresponding loss value a3;

[0039] The value of each loss value a3 is between 0 and 1;

[0040] Step 65: If the loss value a1 satisfies a preset model convergence loss value range and the loss value a1 is less than the loss value a2, calculate the corresponding loss repair rate r based on the loss value a2 and each of the loss values ​​a3; and record each loss repair rate r that is not lower than a preset repair rate threshold as the corresponding preferred repair rate; and assign the inference layer A corresponding to the first correction layer index of each preferred repair rate to... i As a corresponding first key layer; and the first key layer set is composed of all the obtained first key layers;

[0041] The loss repair rate r is calculated as follows:

[0042] The repair rate threshold is a ratio value greater than 0.

[0043] Preferably, the step of obtaining the second key layer set by performing a final key layer determination based on all the obtained first key layer sets specifically includes:

[0044] All sets of the first key layers are merged to obtain the corresponding first set; the same first key layers in the first set are grouped together as the corresponding first group; the total number of the first key layers in each first group is counted and the counted result is used as the corresponding key layer score; the first key layer corresponding to each key layer score greater than the preset score threshold is used as a corresponding second key layer; and all the obtained second key layers form the corresponding second key layer set.

[0045] Preferably, resetting the model parameters of the target model by embedding low-rank matrix parameters into the layer weight parameters of all second key layers specifically includes:

[0046] The weights W corresponding to each of the second key layers i Let W be the corresponding old weight. old ; and for the old weight W old Set up two corresponding low-rank matrices A and B; initialize low-rank matrix A based on a random Gaussian distribution, and initialize low-rank matrix B as a matrix of all zeros; then construct the corresponding incremental weight ΔW = AB from the initialized low-rank matrices A and B; and use the old weight W... old The incremental weight ΔW constitutes the corresponding new weight W. new =W old +△W; and based on the currently stated new weight W new The weight W corresponding to the current second key layer i Perform a reset; and form the corresponding low-rank matrix parameters by the matrix parameters of the low-rank matrices A and B corresponding to the current second key layer.

[0047] Preferably, updating only the implanted parameter set during each knowledge editing process specifically includes:

[0048] Step 91: Each time knowledge editing is required, first receive the updated knowledge item set for that time;

[0049] The updated knowledge entry set includes multiple updated knowledge entries; the text format of the updated knowledge entries is the knowledge triplet text format.

[0050] Step 92: Generate a corresponding first training question based on the subject text and subject-object relationship text of each updated knowledge entry; generate a corresponding first label answer based on the object text of each updated knowledge entry; and form a corresponding first data record by combining each first training question and the corresponding first label answer.

[0051] Step 93: Perform another round of traversal on all the first data records; during this round of traversal, take the currently traversed first data record as the corresponding current data record; input the first training question of the current data record into the question-answering instruction template to generate the corresponding first instruction text; input the first instruction text as the model input text into the target model for processing, and take the generated text output by this processing as the corresponding first predicted answer; and form a corresponding first prediction-label pair by the first predicted answer and the first label answer of the current data record.

[0052] Step 94: Substitute all the obtained first prediction-label pairs into the preset second model loss function; and based on the preset first model optimizer, modulate the implanted parameter set of the target model in the direction that minimizes the second model loss function until the model loss converges.

[0053] The second model loss function is implemented based on the cross-entropy loss function or the negative log-likelihood loss function; the first model optimizer includes at least the Adam optimizer and the SGD optimizer.

[0054] A second aspect of the present invention provides an apparatus for implementing the knowledge editing method of the autoregressive large language model described in the first aspect above. The apparatus includes: a first preprocessing module, a second preprocessing module, a key layer prediction module, a key layer localization and low-rank matrix parameter implantation module, and a knowledge editing module.

[0055] The first preprocessing module is used to take an autoregressive large language model based on the Transformer model structure, which has been pre-trained and fine-tuned for NLP tasks, as the target model; and to denote each attention layer or MLP layer in the inference module of the target model as the corresponding inference layer A. i and for the inference layer A i The total number N is obtained by statistically analyzing the total number of elements. A ; 1 ≤ level index i ≤ N A The target model's internal structure is divided into two main sections: the preprocessing section and the inference section.

[0056] The second preprocessing module is used to configure a question-and-answer instruction template for the target model; and to convert each knowledge item in the pre-trained knowledge base of the target model into a question-and-answer text pair to obtain the corresponding first text pair.

[0057] The key layer prediction module is used to take each of the first text pairs as the corresponding current text pair; input the question text of the current text pair into the question-and-answer instruction template to generate the current instruction text; input the current instruction text as the model input text into the preprocessing module for preprocessing to obtain the corresponding initial vector H0; input the initial vector H0 into the inference module for one forward inference and use the generated text output in this step as the first predicted text, and perform inference on all inference layers A in this inference process. i The output process vector is cached, and a vector matrix M is formed by all cached process vectors; the initial vector H0 is scrambled to obtain a scrambling vector; the scrambling vector is input into the inference module for one forward inference, and the generated text output in this round is used as the second predicted text; then the scrambling vector is input into the inference module again for one round N. A The process involves forward reasoning and, in each round of reasoning, a process vector correction is performed based on the vector matrix M to obtain a vector from N. A A third prediction information set is composed of three third prediction information sets; and based on the current text, a key layer prediction is performed on the corresponding first and second prediction texts and the third prediction information set to obtain the corresponding first key layer set;

[0058] The key layer localization and low-rank matrix parameter implantation module is used to perform key layer final judgment based on all the obtained first key layer sets to obtain the second key layer set; and to reset the model parameters of the target model by implanting low-rank matrix parameters into the layer weight parameters of all the second key layers.

[0059] The knowledge editing module is used to form a corresponding implanted parameter set composed of all the implanted low-rank matrix parameters; and only the implanted parameter set is updated during each knowledge editing process.

[0060] A third aspect of the present invention provides an electronic device, including: a memory, a processor, and a transceiver;

[0061] The processor is used to couple with the memory, read and execute instructions in the memory to implement the steps of the method described in the first aspect above;

[0062] The transceiver is coupled to the processor, and the processor controls the transceiver to send and receive messages.

[0063] A fourth aspect of the present invention provides a computer-readable storage medium storing computer instructions that, when executed by a computer, cause the computer to perform the instructions described in the first aspect.

[0064] This invention provides a knowledge editing method, apparatus, electronic device, and computer-readable storage medium for an autoregressive large language model. As described above, this embodiment of the invention considers any autoregressive large language model based on the Transformer model structure that has been pre-trained and fine-tuned for NLP tasks as the target model; it transforms each knowledge item in the pre-trained knowledge base of the target model into a question-answer text pair to obtain a corresponding text pair; it processes each text pair according to three types of model inference methods (single normal inference, single scrambling inference, and multiple repair inference under scrambling premise) to obtain three types of prediction information (first predicted text, second predicted text, and third prediction information set); it performs a key layer prediction based on the three types of prediction information (first predicted text, second predicted text, and third prediction information set) of each text pair to obtain the corresponding first key layer set; it performs a key layer final judgment based on all the obtained first key layer sets to obtain the second key layer set; it resets the model parameters of the target model by implanting low-rank matrix parameters into the layer weight parameters of all second key layers, and the implanted low-rank matrix parameters form the corresponding implanted parameter set; and in each subsequent knowledge editing process, it achieves the knowledge editing effect by only fine-tuning the implanted parameter set. The embodiments of the present invention effectively reduce computational complexity and the total number of optimization parameters, thereby shortening the training cycle, improving editing efficiency, and reducing editing costs. Attached Figure Description

[0065] Figure 1 This is a schematic diagram of a knowledge editing method for an autoregressive large language model provided in Embodiment 1 of the present invention;

[0066] Figure 2 This is a module structure diagram of a knowledge editing device for an autoregressive large language model provided in Embodiment 2 of the present invention;

[0067] Figure 3 This is a schematic diagram of the structure of an electronic device provided in Embodiment 3 of the present invention. Detailed Implementation

[0068] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings. Obviously, the described embodiments are merely some embodiments of this invention, and not all embodiments. Based on the embodiments of this invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this invention.

[0069] Embodiment 1 of the present invention provides a knowledge editing method for an autoregressive large language model, such as... Figure 1As shown in the schematic diagram of a knowledge editing method for an autoregressive large language model provided in Embodiment 1 of the present invention, the method mainly includes the following steps:

[0070] Step 1: Select an autoregressive large language model based on the Transformer model architecture that has been pre-trained and fine-tuned for NLP tasks as the target model; and denote each attention layer or MLP layer in the inference module of the target model as the corresponding inference layer A. i And for reasoning layer A i The total number N is obtained by statistically analyzing the total number of elements. A .

[0071] Where 1 ≤ level index i ≤ N A NLP tasks include at least text generation tasks and intelligent question answering tasks.

[0072] Here, in this embodiment of the invention, the internal structure of the target model is divided into two main sections: the preprocessing section and the inference section.

[0073] The preprocessing module is used to preprocess the model input text. Specifically, it performs word segmentation on the input text to obtain a word segmentation sequence, and then performs embedding encoding on each word segment according to the set embedding encoding rules to obtain the corresponding initial vector H0, which is sent to the inference module. This initial vector H0 consists of multiple sub-vectors h. 0,j Composition, 1 ≤ subvector index j ≤ N J N J The total number of words in the word segmentation sequence corresponding to the initial vector H0.

[0074] The reasoning section is used to perform forward reasoning based on the input initial vector H0 to obtain the corresponding generated text and output it; the reasoning section contains N A One inference layer A i Each inference layer A i The layer weight parameter is denoted as weight W. i After an initial vector H0 is input into the inference module, the various inference layers A within it... i This will generate a corresponding output vector, which is denoted as the process vector H. i The process vector H i Specifically, it consists of multiple sub-vectors h i,j Composed of, and subvector h i,j with subvector h 0,j One-to-one correspondence.

[0075] Step 2: Configure question-answering instruction templates for the target model; and convert each knowledge item in the pre-trained knowledge base of the target model into a question-answer text pair to obtain the corresponding first text pair.

[0076] Specifically, this includes: Step 21, configuring a question-and-answer instruction template for the target model;

[0077] Here, the question-and-answer instruction template in this embodiment of the invention is a formatted instruction text template; the configurable parameters of the question-and-answer instruction template include a question configuration parameter, which is a text parameter; the question-and-answer instruction template is used to prompt the target model to perform text generation processing on the corresponding answer to the question configuration parameter;

[0078] Step 22, and convert each knowledge item in the pre-trained knowledge base of the target model into a question-answer text pair to obtain the corresponding first text pair;

[0079] Here, the pre-trained knowledge base of this embodiment of the invention includes multiple knowledge entries; the text format of the knowledge entries is a knowledge triplet text format [subject text, subject-object relation text, object text];

[0080] In this embodiment of the invention, the first text pair corresponds one-to-one with the knowledge item; the first text pair includes a question text and an answer text; the question text is converted from the subject text and subject-object relation text of the corresponding knowledge item; the answer text is converted from the object text of the corresponding knowledge item; for example, if a knowledge item is known as [subject text = "snow", subject-object relation text = "color", object text = "white"], then the question text converted from the subject text = "snow" and the subject-object relation text = "color" is "What is the color of snow?", and the answer text converted from the object text = "white" is "white".

[0081] Step 3: Each first text pair is used as the corresponding current text pair; the question text of the current text pair is input into the question-answering instruction template to generate the current instruction text; the current instruction text is used as the model input text and input into the preprocessing module for preprocessing to obtain the corresponding initial vector H0; the initial vector H0 is input into the inference module for one forward inference, and the generated text output in this step is used as the first predicted text, and all inference layers A in this inference process are processed. i The output process vectors are cached and a vector matrix M is formed from all cached process vectors; the initial vector H0 is scrambled to obtain a scrambled vector; the scrambled vector is then input into the inference module for one forward inference, and the generated text output in this iteration is used as the second predicted text; then the scrambled vector is input into the inference module again for one round N. A The process involves forward reasoning and, in each round of reasoning, a process vector correction is performed based on the vector matrix M to obtain a result from N. A The third prediction information set consists of three third prediction information sets; and based on the current text, the corresponding first and second prediction texts and the third prediction information set are used to perform a key layer prediction to obtain the corresponding first key layer set;

[0082] Specifically, this includes: step 31, treating each first text pair as the corresponding current text pair;

[0083] Step 32, and input the question text of the current text pair into the question-and-answer instruction template to generate the current instruction text;

[0084] Specifically, this includes: setting the question configuration parameters of the question-and-answer instruction template to the question text of the current text pair to obtain a corresponding template setting text, and using the template setting text as the corresponding current instruction text;

[0085] Step 33, and input the current instruction text as the model input text into the preprocessing module for preprocessing to obtain the corresponding initial vector H0;

[0086] Step 34: Input the initial vector H0 into the inference module to perform a forward inference and use the generated text of this step as the first predicted text. Then, process all inference layers A during this inference process. i The output process vectors are cached and a vector matrix M is formed by all cached process vectors.

[0087] Here, after an initial vector H0 is input into the inference module, the various inference layers A within it... i It will output a corresponding process vector H i Each process vector H i Both consist of multiple sub-vectors h i,j Composition; consisting of all process vectors H in the cache i This can form a vector matrix M; the shape of the vector matrix M is N. A ×N J , by N A N matrix rows, N J It consists of matrix columns, and the matrix rows are connected to the process vector H. i One-to-one correspondence, also with reasoning layer A i One-to-one correspondence, the matrix columns correspond one-to-one with the word segments in the word segmentation sequence corresponding to the initial vector H0; the vector matrix M includes N A ×N J m matrix units i,j Matrix unit m i,j With all process vectors H in the cache i subvector h i,j One-to-one correspondence;

[0088] It should be noted that the matrix elements m of this vector matrix M i,j The specific data content is based on all process vectors H cached during the forward inference process of the current step 34. i Data content settings;

[0089] Step 35, and scramble the initial vector H0 to obtain the scrambled vector;

[0090] Specifically, this includes: using the word segmentation sequence corresponding to the initial vector H0 as the current word segmentation sequence; identifying the subject word segmentation in the current word segmentation sequence; and retrieving the sub-vector h from the initial vector H0 that corresponds to the subject word segmentation. 0,j As the subject vector h subject And generate a vector whose length and feature dimension are the same as the subject vector h. subject Maintain a consistent random Gaussian noise vector ε; and adjust the subject vector h based on the random Gaussian noise vector ε. subject The scrambling is performed to obtain the corresponding scrambling vector, scrambling vector = h subject +ε;

[0091] It should be noted that the scrambling method in step 35 is to add noise to the subject segmentation sub-vector in the initial vector H0 to achieve the scrambling purpose. In addition, other scrambling methods can also be used in this embodiment of the invention. For example, all segments in the current segmentation sequence corresponding to the initial vector H0 that are nouns and / or pronouns and / or adjectives are recorded as scrambled segments, and the sub-vector h corresponding to each scrambled segment is recorded. 0,j Let the initial screening vector be denoted as the initial screening vector. A preset extraction mode (including random mode and full mode) is identified. If the extraction mode is random mode, a portion of the initial screening vectors are randomly selected as the scrambling vectors. If the extraction mode is full mode, all initial screening vectors are used as scrambling vectors. A random Gaussian noise vector u is generated for each scrambling vector, with the same vector length and vector feature dimension as the current scrambling vector. A corresponding scrambling vector = scrambling vector + u is generated based on each scrambling vector and its corresponding random Gaussian noise vector u.

[0092] Step 36: Input the scrambling vector into the inference module to perform a forward inference and use the generated text output in this step as the second predicted text;

[0093] Step 37, and then input the scrambling vector into the inference module for another round of N. A The process involves forward reasoning and, in each round of reasoning, a process vector correction is performed based on the vector matrix M to obtain a result from N. A A set of third-prediction information consisting of three third-prediction information items;

[0094] Specifically, this includes: Step 371, setting a first counter initialized to 1;

[0095] Step 372: Input the scrambling vector into the inference module for one forward inference; and during this forward inference process, each time it passes through an inference layer A... iPause once; and during each pause, change the currently passed inference layer A. i As the corresponding current inference layer; and the process vector H output by the current inference layer. i This serves as the corresponding current process vector; it also identifies whether the layer index i of the current inference layer matches the first counter; if they do not match, the pause is lifted and the current process vector is passed to the next internal component in the inference module; if they match, the matrix row in the vector matrix M corresponding to the current inference layer is taken as the current matrix row, and the total number of word segments N corresponding to the vector matrix M is used as the current matrix row. J Generate a value in N J / 2 to N J A random integer R between the given and current matrix rows is selected, and R matrix elements m are randomly selected from the current matrix row. i,j For the R corresponding sub-vectors h in the current process vector i,j The replacement is performed to obtain a new current process vector. Then, the pause is lifted and the new current process vector is sent to the next internal component in the inference module. At the end of this forward inference, the generated text output by this inference is used as a corresponding third predicted text. A corresponding first correction layer index is configured for the current third predicted text, and the current first correction layer index is set as the first counter. The current third predicted text and the corresponding first correction layer index are combined to form a corresponding third predicted information.

[0096] Step 373: Increment the first counter by 1; and check whether the incremented first counter exceeds the total number N. A Perform identification; if yes, proceed to step 374; if no, return to step 372.

[0097] Step 374, from the obtained N A Each third prediction information item forms a corresponding third prediction information set;

[0098] Here, the third prediction information set in this embodiment of the invention is composed of N A The third prediction information consists of a third prediction text and a first correction layer index; the first correction layer index is related to the inference layer A. i One-to-one correspondence;

[0099] Step 38, and based on the current text, perform a key layer prediction on the corresponding first, second, and third prediction information sets to obtain the corresponding first key layer set;

[0100] The first key layer set consists of multiple first key layers; each first key layer corresponds to a reasoning layer A. i ;

[0101] Specifically, this includes: Step 381, using the answer text of the current text pair as the first label text;

[0102] Step 382: Input the first label text and the first predicted text as the corresponding current label text and current predicted text into the preset first model loss function for calculation, and use the loss value output by the function at this time as the corresponding loss value a1;

[0103] Here, the first model loss function in this embodiment of the invention is used to calculate the loss based on the input current label text and the current predicted text and output the corresponding loss value; the first model loss function is implemented based on the cross-entropy loss function or the negative log-likelihood loss function; the loss value a1 ranges from 0 to 1;

[0104] Step 383: Input the first label text and the second predicted text as the corresponding current label text and current predicted text into the first model loss function for calculation, and use the loss value output by the function at this time as the corresponding loss value a2;

[0105] Here, the loss value a2 in this embodiment of the invention ranges from 0 to 1;

[0106] Step 384: Input the first label text and each third prediction text in the third prediction information set as the corresponding current label text and current prediction text into the first model loss function for calculation, and use the loss value output by the function at this time as the corresponding loss value a3;

[0107] Here, the value of each loss value a3 in this embodiment of the invention ranges from 0 to 1;

[0108] Step 385: When the loss value a1 meets the preset model convergence loss value range and the loss value a1 is less than the loss value a2, calculate the corresponding loss repair rate r based on the loss value a2 and each loss value a3; and record each loss repair rate r that is not lower than the preset repair rate threshold as the corresponding preferred repair rate; and set the inference layer A corresponding to the first correction layer index of each preferred repair rate as the inference layer A. i As a corresponding first key layer; and the first key layer set is composed of all the obtained first key layers;

[0109] Here, the loss repair rate r in this embodiment of the invention is calculated as follows:

[0110]

[0111] In this embodiment of the invention, the model convergence loss value range is a preset numerical range, and the repair rate threshold is a preset ratio value that is greater than 0.

[0112] Step 4: Based on the obtained first key layer set, perform key layer final judgment to obtain the second key layer set; and reset the model parameters of the target model by implanting low-rank matrix parameters into the layer weight parameters of all second key layers.

[0113] Specifically, this includes: Step 41, performing a final judgment on the key layers based on all the obtained first key layer sets to obtain the second key layer set;

[0114] The set of second key layers consists of multiple second key layers; each second key layer corresponds to a reasoning layer A. i ;

[0115] Specifically, this includes: merging all sets of first key layers to obtain a corresponding first set; grouping the same first key layers in the first set into a group and calling it a corresponding first group; counting the total number of first key layers in each first group and using the statistical result as the corresponding key layer score; and using the first key layer corresponding to each key layer score greater than a preset scoring threshold as a corresponding second key layer; and forming a corresponding second key layer set from all the obtained second key layers.

[0116] Here, the scoring threshold in this embodiment of the invention is a pre-set positive integer score;

[0117] Step 42, and reset the model parameters of the target model by implanting low-rank matrix parameters into the layer weight parameters of all second key layers;

[0118] Specifically, this includes: assigning weights W to each of the second key layers. i Let W be the corresponding old weight. old ; and for the old weight W old Set up two corresponding low-rank matrices A and B; initialize low-rank matrix A based on a random Gaussian distribution, and initialize low-rank matrix B as a matrix of all zeros; then construct the corresponding incremental weights ΔW = AB from the initialized low-rank matrices A and B; and use the old weights W... old The incremental weight △W constitutes the corresponding new weight W. new =W old +△W; and based on the current new weight W new The weight W corresponding to the current second key layer i Perform a reset; and form the corresponding low-rank matrix parameters from the matrix parameters of the low-rank matrix A and low-rank matrix B corresponding to the current second key layer.

[0119] Step 5: The implanted parameter set is composed of all the low-rank matrix parameters implanted; and only the implanted parameter set is updated during each knowledge editing process.

[0120] Specifically, this includes: Step 51, which consists of the corresponding implantation parameter set composed of all implanted low-rank matrix parameters;

[0121] Step 52, and only update the implanted parameter set during each knowledge editing process;

[0122] Specifically, this includes step 521, where each time knowledge editing is required, the updated set of knowledge entries for that session is received first;

[0123] Here, the updated knowledge item set in this embodiment of the invention includes multiple updated knowledge items; the text format of the updated knowledge items is a knowledge triplet text format;

[0124] Step 522: Generate a corresponding first training question based on the main text and subject-object relationship text of each updated knowledge entry; generate a corresponding first label answer based on the object text of each updated knowledge entry; and form a corresponding first data record by combining each first training question and the corresponding first label answer.

[0125] Step 523: Perform another round of traversal on all first data records; during this round of traversal, take the first data record currently being traversed as the corresponding current data record; input the first training question of the current data record into the question-answering instruction template to generate the corresponding first instruction text; input the first instruction text as the model input text into the target model for processing, and take the generated text output from this processing as the corresponding first predicted answer; and form a corresponding first prediction-label pair by the first predicted answer and the first label answer of the current data record.

[0126] Step 524: Substitute all the obtained first prediction-label pairs into the preset second model loss function; and based on the preset first model optimizer, modulate the parameters of the target model's implanted parameter set in the direction that minimizes the second model loss function until the model loss converges.

[0127] Here, the second model loss function in this embodiment of the invention is implemented based on the cross-entropy loss function or the negative log-likelihood loss function; the first model optimizer in this embodiment of the invention includes at least the Adam optimizer and the SGD optimizer. It should be noted that when modulating the parameters of the implanted parameter set of the target model, it is not necessary to modulate the original model parameters of the target model (i.e., the parameters in the current model parameters other than the implanted parameter set).

[0128] Figure 2This is a module structure diagram of a knowledge editing device for an autoregressive large language model provided in Embodiment 2 of the present invention. This device can be a terminal device or server implementing the aforementioned method embodiments, or it can be a device that enables the aforementioned terminal device or server to implement the aforementioned method embodiments. For example, the device can be a device or chip system of the aforementioned terminal device or server. Figure 2 As shown, the device includes: a first preprocessing module 201, a second preprocessing module 202, a key layer prediction module 203, a key layer localization and low-rank matrix parameter implantation module 204, and a knowledge editing module 205.

[0129] The first preprocessing module 201 is used to take an autoregressive large language model based on the Transformer model structure, which has been pre-trained and fine-tuned for NLP tasks, as the target model; and to denote each attention layer or MLP layer in the inference module of the target model as the corresponding inference layer A. i And for reasoning layer A i The total number N is obtained by statistically analyzing the total number of elements. A ; 1 ≤ level index i ≤ N A The target model's internal structure is divided into two main sections: the preprocessing section and the inference section.

[0130] The second preprocessing module 202 is used to configure question-answer instruction templates for the target model; and to convert each knowledge item in the pre-trained knowledge base of the target model into a question-answer text pair to obtain the corresponding first text pair.

[0131] The key layer prediction module 203 is used to take each first text pair as the corresponding current text pair; input the question text of the current text pair into the question-answering instruction template to generate the current instruction text; input the current instruction text as the model input text into the preprocessing module for preprocessing to obtain the corresponding initial vector H0; input the initial vector H0 into the inference module for one forward inference and use the generated text of this inference as the first predicted text, and apply this to all inference layers A during this inference process. i The output process vectors are cached and a vector matrix M is formed from all cached process vectors; the initial vector H0 is scrambled to obtain a scrambled vector; the scrambled vector is then input into the inference module for one forward inference, and the generated text output in this iteration is used as the second predicted text; then the scrambled vector is input into the inference module again for one round N. A The process involves forward reasoning and, in each round of reasoning, a process vector correction is performed based on the vector matrix M to obtain a result from N. A The third prediction information set consists of three third prediction information sets; and based on the current text, the corresponding first and second prediction texts and the third prediction information set are used to perform a key layer prediction to obtain the corresponding first key layer set.

[0132] The key layer localization and low-rank matrix parameter implantation module 204 is used to perform key layer final judgment based on all the obtained first key layer sets to obtain the second key layer set; and to reset the model parameters of the target model by implanting low-rank matrix parameters into the layer weight parameters of all the second key layers.

[0133] The knowledge editing module 205 is used to form the corresponding implanted parameter set from all the implanted low-rank matrix parameters; and only the implanted parameter set is updated in each knowledge editing process.

[0134] The knowledge editing device for an autoregressive large language model provided in this embodiment of the invention can execute the method steps in the above method embodiment. Its implementation principle and technical effect are similar, and will not be described again here.

[0135] It should be noted that the division of the various modules in the above device is merely a logical functional division. In actual implementation, they can be fully or partially integrated into a single physical entity, or they can be physically separated. Furthermore, these modules can be implemented entirely in software via processing element calls; they can be fully implemented in hardware; or some modules can be implemented by processing element calls to software, while others are implemented in hardware. For example, the first preprocessing module can be a separate processing element, or it can be integrated into a chip in the above device. Alternatively, it can be stored as program code in the memory of the above device, and called and executed by a processing element of the device. The implementation of other modules is similar. Moreover, these modules can be fully or partially integrated together, or they can be implemented independently. The processing element described here can be an integrated circuit with signal processing capabilities. In the implementation process, each step of the above method or each of the above modules can be completed through integrated logic circuits in the hardware of the processor element or through software instructions.

[0136] For example, these modules can be one or more integrated circuits configured to implement the above methods, such as one or more Application-Specific Integrated Circuits (ASICs), one or more Digital Signal Processors (DSPs), or one or more Field Programmable Gate Arrays (FPGAs). As another example, when a module is implemented using processing element scheduler code, the processing element can be a general-purpose processor, such as a Central Processing Unit (CPU) or other processor capable of calling program code. Furthermore, these modules can be integrated together as a System-on-a-Chip (SOC).

[0137] In the above embodiments, implementation can be achieved, in whole or in part, through software, hardware, firmware, or any combination thereof. When implemented in software, it can be implemented, in whole or in part, as a computer program product. This computer program product includes one or more computer instructions. When these computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the foregoing method embodiments are generated. The computer described above can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The aforementioned computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the aforementioned computer instructions can be transmitted from one website, computer, server, or data center to another via wired (e.g., coaxial cable, fiber optic, Digital Subscriber Line (DSL)) or wireless (e.g., infrared, wireless, Bluetooth, microwave, etc.) means. The aforementioned computer-readable storage medium can be any available medium that a computer can access, or a data storage device such as a server or data center that integrates one or more available media. The aforementioned available media can be magnetic media (e.g., floppy disks, hard disks, magnetic tapes), optical media (e.g., DVDs), or semiconductor media (e.g., solid-state disks (SSDs)).

[0138] Figure 3 This is a schematic diagram of an electronic device provided in Embodiment 3 of the present invention. This electronic device can be a terminal device or server implementing the methods of the aforementioned embodiments, or it can be a terminal device or server connected to the aforementioned terminal device or server implementing the methods of the aforementioned embodiments. Figure 3As shown, the electronic device may include: a processor 301 (e.g., CPU), a memory 302, and a transceiver 303; the transceiver 303 is coupled to the processor 301, and the processor 301 controls the transmission and reception operations of the transceiver 303. The memory 302 may store various instructions for performing various processing functions and implementing the processing steps described in the foregoing embodiments. Preferably, the electronic device involved in the embodiments of the present invention further includes: a power supply 304, a system bus 305, and a communication port 306. The system bus 305 is used to realize communication connections between components. The communication port 306 is used for communication between the electronic device and other peripherals.

[0139] exist Figure 3 The system bus 305 mentioned can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. This system bus can be divided into address bus, data bus, control bus, etc. For ease of representation, it is represented by only one thick line in the figure, but this does not indicate that there is only one bus or one type of bus. The communication interface is used to enable communication between the database access device and other devices (e.g., clients, read-write libraries, and read-only libraries). Memory may include Random Access Memory (RAM) and may also include non-volatile memory, such as at least one disk storage device.

[0140] The processors mentioned above can be general-purpose processors, including central processing units (CPUs), network processors (NPs), graphics processing units (GPUs), etc.; they can also be digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.

[0141] It should be noted that the embodiments of the present invention also provide a computer-readable storage medium storing instructions that, when run on a computer, cause the computer to perform the methods and processes provided in the above embodiments.

[0142] This invention provides a knowledge editing method, apparatus, electronic device, and computer-readable storage medium for an autoregressive large language model. As described above, this embodiment of the invention considers any autoregressive large language model based on the Transformer model structure that has been pre-trained and fine-tuned for NLP tasks as the target model; it transforms each knowledge item in the pre-trained knowledge base of the target model into a question-answer text pair to obtain a corresponding text pair; it processes each text pair according to three types of model inference methods (single normal inference, single scrambling inference, and multiple repair inference under scrambling premise) to obtain three types of prediction information (first predicted text, second predicted text, and third prediction information set); it performs a key layer prediction based on the three types of prediction information (first predicted text, second predicted text, and third prediction information set) of each text pair to obtain the corresponding first key layer set; it performs a key layer final judgment based on all the obtained first key layer sets to obtain the second key layer set; it resets the model parameters of the target model by implanting low-rank matrix parameters into the layer weight parameters of all second key layers, and the implanted low-rank matrix parameters form the corresponding implanted parameter set; and in each subsequent knowledge editing process, it achieves the knowledge editing effect by only fine-tuning the implanted parameter set. The embodiments of the present invention reduce computational complexity and the total number of optimization parameters, thereby shortening the training cycle, improving editing efficiency, and reducing editing costs.

[0143] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein can be implemented in hardware, a software module executed by a processor, or a combination of both. The software module can be located in random access memory (RAM), main memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, CD-ROM, or any other form of storage medium known in the art.

[0144] The specific embodiments described above further illustrate the purpose, technical solution, and beneficial effects of the present invention. It should be understood that the above description is only a specific embodiment of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.

Claims

1. A knowledge editing method for an autoregressive large language model, characterized in that, The method includes: An autoregressive large language model based on the Transformer model structure, which has been pre-trained and fine-tuned for NLP tasks, is used as the target model; and each attention layer or MLP layer in the inference module of the target model is denoted as the corresponding inference layer A. i and for the inference layer A i The total number N is obtained by statistically analyzing the total number of elements. A ; 1 ≤ level index i ≤ N A The target model's internal structure is divided into two main sections: the preprocessing section and the inference section. Configure a question-and-answer instruction template for the target model; and convert each knowledge item in the pre-trained knowledge base of the target model into a question-and-answer text pair to obtain the corresponding first text pair. Each of the first text pairs is taken as the corresponding current text pair; the question text of the current text pair is input into the question-and-answer instruction template to generate the current instruction text; the current instruction text is used as the model input text and input into the preprocessing module for preprocessing to obtain the corresponding initial vector H0; the initial vector H0 is input into the inference module for one forward inference and the generated text output in this step is used as the first predicted text, and all inference layers A in this inference process are processed. i The output process vector is cached, and a vector matrix M is formed by all cached process vectors; the initial vector H0 is scrambled to obtain a scrambling vector; the scrambling vector is input into the inference module for one forward inference, and the generated text output in this round is used as the second predicted text; then the scrambling vector is input into the inference module again for one round N. A The process involves forward reasoning and, in each round of reasoning, a process vector correction is performed based on the vector matrix M to obtain a vector from N. A A third prediction information set is composed of three third prediction information sets; and based on the current text, a key layer prediction is performed on the corresponding first and second prediction texts and the third prediction information set to obtain the corresponding first key layer set; The second key layer set is obtained by performing a final key layer judgment based on all the first key layer sets; and the model parameters of the target model are reset by embedding low-rank matrix parameters into the layer weight parameters of all the second key layers. The implanted parameter set is composed of all the low-rank matrix parameters implanted; and only the implanted parameter set is updated during each knowledge editing process.

2. The knowledge editing method for an autoregressive large language model according to claim 1, characterized in that, The NLP tasks include at least text generation and intelligent question answering; The preprocessing module is used to preprocess the model input text, specifically: performing word segmentation on the model input text to obtain a word segmentation sequence, and performing embedding encoding on each word of the word segmentation sequence according to the set embedding encoding rules to obtain the corresponding initial vector H0, which is then sent to the inference module; the inference module is used to perform forward inference based on the input initial vector H0 to obtain the corresponding generated text and output it; the inference module contains N A The inference layer A i Each of the aforementioned inference layers A i The layer weight parameter is denoted as weight W. i ; The initial vector H0 is composed of multiple sub-vectors h 0,j Composition, 1 ≤ subvector index j ≤ N J N J The total number of words in the word segmentation sequence corresponding to the initial vector H0; The inference layers A corresponding to the initial vector H0 i The output vector is denoted as the process vector H. i The process vector H i Composed of multiple subvectors h i,j Composition, the subvector h i,j With the subvector h 0,j One-to-one correspondence; The shape of the vector matrix M corresponding to the initial vector H0 is N. A ×N J , by N A N matrix rows, N J The vector matrix M consists of N matrix columns; the vector matrix M includes N... A ×N J m matrix units i,j ; matrix rows and the process vector H i One-to-one correspondence, and also with the inference layer A. i One-to-one correspondence, the matrix columns correspond one-to-one with the word segments of the word segmentation sequence; the matrix unit m i,j With the subvector h i,j One-to-one correspondence; The question-and-answer instruction template is a formatted instruction text template; the configurable parameters of the question-and-answer instruction template include question configuration parameters, which are text parameters; the question-and-answer instruction template is used to prompt the target model to perform text generation processing on the corresponding answer to the question configuration parameters; The pre-trained knowledge base includes multiple knowledge entries; the text format of the knowledge entries is a knowledge triplet text format [subject text, subject-object relation text, object text]; The first text pair corresponds one-to-one with the knowledge item; the first text pair includes the question text and the answer text; the question text is converted from the subject text and the subject-object relation text of the corresponding knowledge item; the answer text is converted from the object text of the corresponding knowledge item. The third prediction information set consists of N A The third prediction information comprises a third prediction text and a first correction layer index; the first correction layer index is related to the inference layer A. i One-to-one correspondence; The first key layer set consists of multiple first key layers; each first key layer corresponds to one inference layer A. i ; The second key layer set consists of multiple second key layers; each second key layer corresponds to one inference layer A. i .

3. The knowledge editing method for an autoregressive large language model according to claim 2, characterized in that, The step of inputting the question text of the current text pair into the question-and-answer instruction template to generate the current instruction text specifically includes: The question configuration parameter of the question-and-answer instruction template is set to the question text of the current text pair to obtain a corresponding template setting text, and the template setting text is used as the corresponding current instruction text.

4. The knowledge editing method for an autoregressive large language model according to claim 2, characterized in that, The process of scrambling the initial vector H0 to obtain the scrambling vector specifically includes: The word segmentation sequence corresponding to the initial vector H0 is taken as the current word segmentation sequence; the subject word segmentation in the current word segmentation sequence is identified; and the sub-vector h corresponding to the subject word segmentation in the initial vector H0 is... 0,j As the subject vector h subject And generate a vector whose length and feature dimension are both the same as the subject vector h. subject Maintain a consistent random Gaussian noise vector ε; and apply the subject vector h based on the random Gaussian noise vector ε. subject The scrambling is performed to obtain the corresponding scrambling vector, where the scrambling vector = h. subject +ε.

5. The knowledge editing method for an autoregressive large language model according to claim 2, characterized in that, The scrambling vector is then input into the inference module for another round of N. A The process involves forward reasoning and, in each round of reasoning, a process vector correction is performed based on the vector matrix M to obtain a vector from N. A The third prediction information set, composed of three sets of third prediction information, specifically includes: Step 51: Set a first counter initialized to 1; Step 52: Input the scrambling vector into the inference module to perform one forward inference; and during this forward inference process, each time the inference layer A is passed... i Pause once; and during each pause, the currently passed inference layer A will be... i As the corresponding current inference layer; and the process vector H output by the current inference layer. i As the corresponding current process vector; and identify whether the layer index i of the current inference layer matches the first counter; if they do not match, release the pause and continue to transmit the current process vector to the next internal component in the inference module; if they match, take the matrix row in the vector matrix M corresponding to the current inference layer as the current matrix row, and based on the total number of word segments N corresponding to the vector matrix M. J Generate a value in N J / 2 to N J A random integer R between the given and given values, and randomly selects R matrix elements m from the current matrix row. i,j For the R corresponding sub-vectors h in the current process vector i,j The replacement is performed to obtain a new current process vector. Then, the pause is lifted and the new current process vector is sent to the next internal component in the inference module. At the end of this forward inference, the generated text output by this inference is used as a corresponding third predicted text. A corresponding first correction layer index is configured for the current third predicted text, and the current first correction layer index is set as the first counter. The current third predicted text and the corresponding first correction layer index are combined to form a corresponding third predicted information. Step 53: Increment the first counter by 1; and check whether the incremented first counter exceeds the total number N. A Perform identification; if yes, proceed to step 54; if no, return to step 52. Step 54, from the obtained N A The third prediction information constitutes the corresponding third prediction information set.

6. The knowledge editing method for an autoregressive large language model according to claim 2, characterized in that, The step of performing a key layer prediction based on the current text on the corresponding first, second, and third predicted texts to obtain the corresponding first key layer set specifically includes: Step 61: Use the answer text of the current text pair as the first tag text; Step 62: Input the first label text and the first predicted text as the corresponding current label text and current predicted text into the preset first model loss function for calculation, and use the loss value output by the function at this time as the corresponding loss value a1; The first model loss function is used to calculate the loss based on the input current label text and the current predicted text and output the corresponding loss value; the first model loss function is implemented based on the cross-entropy loss function or the negative log-likelihood loss function; the loss value a1 ranges from 0 to 1; Step 63: Input the first label text and the second predicted text as the corresponding current label text and the current predicted text into the first model loss function for calculation, and use the loss value output by the function at this time as the corresponding loss value a2; The loss value a2 ranges from 0 to 1. Step 64: Input the first label text and each of the third prediction texts in the third prediction information set as the corresponding current label text and the current prediction text into the first model loss function for calculation, and use the loss value output by the function at this time as the corresponding loss value a3; The value of each loss value a3 is between 0 and 1; Step 65: If the loss value a1 satisfies a preset model convergence loss value range and the loss value a1 is less than the loss value a2, calculate the corresponding loss repair rate r based on the loss value a2 and each of the loss values ​​a3; and record each loss repair rate r that is not lower than a preset repair rate threshold as the corresponding preferred repair rate; and assign the inference layer A corresponding to the first correction layer index of each preferred repair rate to... i As a corresponding first key layer; and the first key layer set is composed of all the obtained first key layers; The loss repair rate r is calculated as follows: The repair rate threshold is a ratio value greater than 0.

7. The knowledge editing method for an autoregressive large language model according to claim 2, characterized in that, The step of obtaining the second key layer set by performing a final key layer determination based on all the obtained first key layer sets specifically includes: All sets of the first key layers are merged to obtain the corresponding first set; the same first key layers in the first set are grouped together as the corresponding first group; the total number of the first key layers in each first group is counted and the counted result is used as the corresponding key layer score; the first key layer corresponding to each key layer score greater than the preset score threshold is used as a corresponding second key layer; and all the obtained second key layers form the corresponding second key layer set.

8. The knowledge editing method for an autoregressive large language model according to claim 2, characterized in that, The method of resetting the model parameters of the target model by embedding low-rank matrix parameters into the layer weight parameters of all second key layers specifically includes: The weights W corresponding to each of the second key layers i Let W be the corresponding old weight. old ; and for the old weight W old Set up two corresponding low-rank matrices A and B; initialize low-rank matrix A based on a random Gaussian distribution, and initialize low-rank matrix B as a matrix of all zeros; then construct the corresponding incremental weight ΔW = AB from the initialized low-rank matrices A and B; and use the old weight W... old The incremental weight ΔW constitutes the corresponding new weight W. new =W old +△W; and based on the currently stated new weight W new The weight W corresponding to the current second key layer i Perform a reset; and form the corresponding low-rank matrix parameters by the matrix parameters of the low-rank matrices A and B corresponding to the current second key layer.

9. The knowledge editing method for an autoregressive large language model according to claim 2, characterized in that, The statement that only the implanted parameter set is updated during each knowledge editing process specifically includes: Step 91: Each time knowledge editing is required, first receive the updated knowledge item set for that time; The updated knowledge entry set includes multiple updated knowledge entries; the text format of the updated knowledge entries is the knowledge triplet text format. Step 92: Generate a corresponding first training question based on the subject text and subject-object relationship text of each updated knowledge entry; generate a corresponding first label answer based on the object text of each updated knowledge entry; and form a corresponding first data record by combining each first training question and the corresponding first label answer. Step 93: Perform another round of traversal on all the first data records; during this round of traversal, take the currently traversed first data record as the corresponding current data record; input the first training question of the current data record into the question-answering instruction template to generate the corresponding first instruction text; input the first instruction text as the model input text into the target model for processing, and take the generated text output by this processing as the corresponding first predicted answer; and form a corresponding first prediction-label pair by the first predicted answer and the first label answer of the current data record. Step 94: Substitute all the obtained first prediction-label pairs into the preset second model loss function; and based on the preset first model optimizer, modulate the implanted parameter set of the target model in the direction that minimizes the second model loss function until the model loss converges. The second model loss function is implemented based on the cross-entropy loss function or the negative log-likelihood loss function; the first model optimizer includes at least the Adam optimizer and the SGD optimizer.

10. An apparatus for performing the knowledge editing method for an autoregressive large language model according to any one of claims 1-9, characterized in that, The device includes: a first preprocessing module, a second preprocessing module, a key layer prediction module, a key layer localization and low-rank matrix parameter implantation module, and a knowledge editing module; The first preprocessing module is used to take an autoregressive large language model based on the Transformer model structure, which has been pre-trained and fine-tuned for NLP tasks, as the target model; and to denote each attention layer or MLP layer in the inference module of the target model as the corresponding inference layer A. i and for the inference layer A i The total number N is obtained by statistically analyzing the total number of elements. A ; 1 ≤ level index i ≤ N A The target model's internal structure is divided into two main sections: the preprocessing section and the inference section. The second preprocessing module is used to configure a question-and-answer instruction template for the target model; and to convert each knowledge item in the pre-trained knowledge base of the target model into a question-and-answer text pair to obtain the corresponding first text pair. The key layer prediction module is used to take each of the first text pairs as the corresponding current text pair; input the question text of the current text pair into the question-and-answer instruction template to generate the current instruction text; input the current instruction text as the model input text into the preprocessing module for preprocessing to obtain the corresponding initial vector H0; input the initial vector H0 into the inference module for one forward inference and use the generated text output in this step as the first predicted text, and perform inference on all inference layers A in this inference process. i The output process vector is cached, and a vector matrix M is formed by all cached process vectors; the initial vector H0 is scrambled to obtain a scrambling vector; the scrambling vector is input into the inference module for one forward inference, and the generated text output in this round is used as the second predicted text; then the scrambling vector is input into the inference module again for one round N. A The process involves forward reasoning and, in each round of reasoning, a process vector correction is performed based on the vector matrix M to obtain a vector from N. A A third prediction information set is composed of three third prediction information sets; and based on the current text, a key layer prediction is performed on the corresponding first and second prediction texts and the third prediction information set to obtain the corresponding first key layer set; The key layer localization and low-rank matrix parameter implantation module is used to perform key layer final judgment based on all the obtained first key layer sets to obtain the second key layer set; and to reset the model parameters of the target model by implanting low-rank matrix parameters into the layer weight parameters of all the second key layers. The knowledge editing module is used to form a corresponding implanted parameter set composed of all the implanted low-rank matrix parameters; and only the implanted parameter set is updated during each knowledge editing process.

11. An electronic device, characterized in that, include: Memory, processor, and transceiver; The processor is configured to be coupled to the memory, read and execute instructions in the memory to implement the method according to any one of claims 1-9; The transceiver is coupled to the processor, and the processor controls the transceiver to send and receive messages.

12. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions that, when executed by a computer, cause the computer to perform the method described in any one of claims 1-9.

Citation Information

Patent Citations

  • Editing method and device for pre-training language model

    CN117851613A

  • Knowledge distillation fine tuning method, device and equipment of large language model and storage medium

    CN118839749A