A method and apparatus for model editing

CN118916378BActive Publication Date: 2026-08-11ALIBABA (CHINA) CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-08-01
Publication Date
2026-08-11

AI Technical Summary

Technical Problem

[0002]随着科技的发展,智能问答系统的应用越来越广泛,具体的,用户向智能问答系统提出问题后,智能问答系统会针对用户提出的问题给出答案,上述问答过程可以通过大规模语言模型LLMs实现,上述LLMs具备理解、分析和生成文本的能力;上述LLMs存在一个重要的缺点,即由于其庞大的参数数量,预训练的计算成本巨大,当需要将新知识引入到预训练的LLMs时,考虑到计算资源和数据资源的开销,无法从头开始进行训练,因此,需要在引入新知识时,精确地修改LLMs中特定的知识参数

Benefits of technology

[0056] In this embodiment of the invention, three sets of query statements to be edited are determined, each set including at least one query statement to be edited; based on each set of query statements to be edited, at least one piece of knowledge data corresponding to it is retrieved from the knowledge database; enhanced representations of each set of query statements to be edited and its corresponding at least one piece of knowledge data are determined respectively; based on the enhanced representations, a prompt character representation corresponding to each query statement to be edited in each set of query statements to be edited is determined; an input embedding representation corresponding to each query statement to be edited in each set of query statements to be edited is determined; based on the combination of the prompt character representation and the input embedding representation, a large-scale language model is edited to generate an updated large-scale language model and at least one semantic vector is generated; a loss function is determined based on the semantic vectors corresponding to the three sets of query statements to be edited and the enhanced representations; and the updated large-scale language model is edited based on the loss function to generate a target large-scale language model. The above method employs retrieval enhancement to generate at least one piece of knowledge data corresponding to each query to be edited from the knowledge database. After enhanced representation, this data is further compressed to generate a prompt character representation. The semantic vector is determined based on the combination of the prompt character representation and the input embedding representation. Since there are three sets of queries to be edited, three loss functions corresponding to reliability, generality, and generalization, as well as a prompt learning loss function, can be determined. Based on these multiple loss functions, the large-scale language model is edited to generate the target large-scale language model. Because the above model editing method does not change the internal parameters of the large-scale data model and only edits new knowledge, lifetime model editing can be achieved, and the capability degradation problem of LLMs during the editing process can be reduced.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118916378B_ABST
    Figure CN118916378B_ABST
Patent Text Reader

Abstract

This invention discloses a method and apparatus for model editing. In this embodiment, three sets of query statements to be edited are determined, and at least one corresponding knowledge data is retrieved from a knowledge database. Enhanced representations are determined for each set of query statements and at least one knowledge data. Corresponding prompt character representations are determined based on the enhanced representations. Input embedding representations are determined for each query statement to be edited. A large-scale language model is edited based on the combination of prompt character representations and input embedding representations to generate an updated large-scale language model and at least one semantic vector. A loss function is determined based on the semantic vectors corresponding to the three sets of query statements to be edited and the enhanced representations. The updated large-scale language model is then edited based on the loss function to generate a target large-scale language model. This method enables lifetime model editing and reduces the capability degradation problem of LLMs during the editing process.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of computer technology, and more specifically, to a method and apparatus for model editing. Background Technology

[0002] With the development of technology, the application of intelligent question answering systems is becoming increasingly widespread. Specifically, after a user asks a question to an intelligent question answering system, the system will provide an answer. This question answering process can be implemented using large-scale language models (LLMs), which have the ability to understand, analyze, and generate text. However, LLMs have a significant drawback: due to their large number of parameters, the computational cost of pre-training is enormous. When new knowledge needs to be introduced into the pre-trained LLMs, considering the overhead of computational and data resources, it is impossible to train from scratch. Therefore, when introducing new knowledge, it is necessary to precisely modify specific knowledge parameters in the LLMs.

[0003] In existing technologies, the Sequence Model Editing (SME) method is used to edit LLMs. However, the SME method is only suitable for single-time editing and simple knowledge editing. It can only handle small amounts of data and still faces significant challenges for editing long sequences of knowledge. Furthermore, in scenarios involving the sequential editing of multiple pieces of knowledge, multiple editing operations are required. These multiple edits can lead to a degradation of the general capabilities of LLMs during the editing process, resulting in forgetting problems. This can then affect other parameters in the LLMs during the editing process, causing the LLMs to exhibit hallucination phenomena.

[0004] In conclusion, how to reduce the capability degradation of LLMs during the editing process is a problem that needs to be solved. Summary of the Invention

[0005] In view of this, embodiments of the present invention provide a method and apparatus for model editing, which can realize lifetime model editing and reduce the capability degradation problem of LLMs during the editing process.

[0006] In a first aspect, embodiments of the present invention provide a method for model editing, the method comprising:

[0007] Three sets of query statements to be edited are identified, wherein each set of query statements to be edited includes at least one query statement to be edited;

[0008] Based on the query statement to be edited in each group, at least one piece of knowledge data corresponding to it is retrieved from the knowledge database.

[0009] Each group of the query statements to be edited and its corresponding enhanced representation of at least one knowledge data point are determined.

[0010] Based on the enhanced representation, determine the prompt character representation corresponding to each query statement to be edited in each group of query statements to be edited;

[0011] Determine the input embedding representation corresponding to each query statement to be edited in each group of query statements to be edited;

[0012] Based on the combination of the prompt character representation and the input embedding representation corresponding to each of the query statements to be edited in each group of query statements to be edited, the large-scale language model is edited to generate an updated large-scale language model and generate at least one semantic vector.

[0013] The loss function is determined based on the semantic vectors corresponding to the three sets of query statements to be edited and the enhanced representation.

[0014] The updated large-scale language model is edited based on the loss function to generate the target large-scale language model.

[0015] Optionally, retrieving at least one piece of knowledge data corresponding to each group of query statements to be edited in the knowledge database specifically includes:

[0016] In the knowledge database, at least one knowledge graph corresponding to each of the query statements to be edited in each group is retrieved through the retrieval enhancement generation method;

[0017] Generate at least one piece of knowledge data based on at least one knowledge graph.

[0018] Optionally, determining the enhanced representation of each group of query statements to be edited and its corresponding at least one knowledge data item specifically includes:

[0019] Determine the semantic representation of each group of query statements to be edited and at least one piece of knowledge data corresponding to it;

[0020] The semantic representation is used to generate the enhanced representation.

[0021] Optionally, generating the enhanced representation from the semantic representation specifically includes:

[0022] The semantic representation of each group of query statements to be edited is input into the first multilayer perceptron layer to generate the enhanced representation corresponding to the query statement to be edited.

[0023] Optionally, generating the enhanced representation from the semantic representation specifically includes:

[0024] The semantic representation of the at least one piece of knowledge data is input into the second multilayer perceptron layer to generate an enhanced representation corresponding to the at least one piece of knowledge data.

[0025] Optionally, determining the prompt character representation corresponding to each query statement to be edited in each group of query statements to be edited based on the enhanced representation specifically includes:

[0026] The enhanced representation corresponding to the at least one piece of knowledge data is input into the third multilayer perceptron layer, and then the prompt character representation corresponding to the at least one piece of knowledge data is generated through the activation function;

[0027] Determine the maximum similarity index corresponding to each query statement to be edited in each group of query statements to be edited, wherein the maximum similarity index represents the index of the knowledge data that has the highest similarity to each query statement to be edited;

[0028] The prompt character representation corresponding to each query statement to be edited is determined based on the maximum similarity index.

[0029] Optionally, the loss function includes an editing loss function and a cue learning loss function, wherein the editing loss function includes a reliability performance loss function, a general performance loss function, and a generalization performance loss function.

[0030] Secondly, embodiments of the present invention provide a model editing apparatus, the apparatus comprising:

[0031] The determining unit is used to determine three groups of query statements to be edited, wherein each group of query statements to be edited includes at least one query statement to be edited;

[0032] The retrieval unit is used to retrieve at least one piece of knowledge data corresponding to each group of query statements to be edited from the knowledge database.

[0033] The determining unit is further configured to determine each group of query statements to be edited and the enhanced representation of at least one knowledge data corresponding to it;

[0034] The determining unit is further configured to determine the prompt character representation corresponding to each query statement to be edited in each group of query statements to be edited based on the enhanced representation;

[0035] The determining unit is further configured to determine the input embedding representation corresponding to each query statement to be edited in each group of query statements to be edited;

[0036] The generation unit is used to edit the large-scale language model based on the combination of the prompt character representation and the input embedding representation corresponding to each of the query statements to be edited in each group of query statements to be edited, to generate an updated large-scale language model, and to generate at least one semantic vector.

[0037] The determining unit is further configured to determine a loss function based on the semantic vectors corresponding to the three sets of query statements to be edited and the enhanced representation;

[0038] The generation unit is further configured to edit the updated large-scale language model according to the loss function to generate a target large-scale language model.

[0039] Optionally, the retrieval unit is specifically used for:

[0040] In the knowledge database, at least one knowledge graph corresponding to each of the query statements to be edited in each group is retrieved through the retrieval enhancement generation method;

[0041] Generate at least one piece of knowledge data based on at least one knowledge graph.

[0042] Optionally, the determining unit is specifically used for:

[0043] Determine the semantic representation of each group of query statements to be edited and at least one piece of knowledge data corresponding to it;

[0044] The semantic representation is used to generate the enhanced representation.

[0045] Optionally, the determining unit is specifically used for:

[0046] The semantic representation of each group of query statements to be edited is input into the first multilayer perceptron layer to generate the enhanced representation corresponding to the query statement to be edited.

[0047] Optionally, the determining unit is specifically used for:

[0048] The semantic representation of the at least one piece of knowledge data is input into the second multilayer perceptron layer to generate an enhanced representation corresponding to the at least one piece of knowledge data.

[0049] Optionally, the determining unit is further configured to:

[0050] The enhanced representation corresponding to the at least one piece of knowledge data is input into the third multilayer perceptron layer, and then the prompt character representation corresponding to the at least one piece of knowledge data is generated through the activation function;

[0051] Determine the maximum similarity index corresponding to each query statement to be edited in each group of query statements to be edited, wherein the maximum similarity index represents the index of the knowledge data that has the highest similarity to each query statement to be edited;

[0052] The prompt character representation corresponding to each query statement to be edited is determined based on the maximum similarity index.

[0053] Optionally, the loss function includes an editing loss function and a cue learning loss function, wherein the editing loss function includes a reliability performance loss function, a general performance loss function, and a generalization performance loss function.

[0054] Thirdly, embodiments of the present invention provide an electronic device, including a memory and a processor, wherein the memory is used to store one or more computer program instructions, wherein the one or more computer program instructions are executed by the processor to implement the method as described in the first aspect or any one of the possible methods of the first aspect.

[0055] Fourthly, embodiments of the present invention provide a computer-readable storage medium having stored thereon computer program instructions that, when executed by a processor, implement the method as described in the first aspect or any one of the possibilities of the first aspect.

[0056] In this embodiment of the invention, three sets of query statements to be edited are determined, each set including at least one query statement to be edited; based on each set of query statements to be edited, at least one piece of knowledge data corresponding to it is retrieved from the knowledge database; enhanced representations of each set of query statements to be edited and its corresponding at least one piece of knowledge data are determined respectively; based on the enhanced representations, a prompt character representation corresponding to each query statement to be edited in each set of query statements to be edited is determined; an input embedding representation corresponding to each query statement to be edited in each set of query statements to be edited is determined; based on the combination of the prompt character representation and the input embedding representation, a large-scale language model is edited to generate an updated large-scale language model and at least one semantic vector is generated; a loss function is determined based on the semantic vectors corresponding to the three sets of query statements to be edited and the enhanced representations; and the updated large-scale language model is edited based on the loss function to generate a target large-scale language model. The above method employs retrieval enhancement to generate at least one piece of knowledge data corresponding to each query to be edited from the knowledge database. After enhanced representation, this data is further compressed to generate a prompt character representation. The semantic vector is determined based on the combination of the prompt character representation and the input embedding representation. Since there are three sets of queries to be edited, three loss functions corresponding to reliability, generality, and generalization, as well as a prompt learning loss function, can be determined. Based on these multiple loss functions, the large-scale language model is edited to generate the target large-scale language model. Because the above model editing method does not change the internal parameters of the large-scale data model and only edits new knowledge, lifetime model editing can be achieved, and the capability degradation problem of LLMs during the editing process can be reduced. Attached Figure Description

[0057] The above and other objects, features and advantages of the present invention will become clearer from the following description of embodiments of the invention with reference to the accompanying drawings, in which:

[0058] Figure 1 This is a flowchart of a model editing method in the prior art;

[0059] Figure 2 This is a flowchart of another model editing method in the existing technology;

[0060] Figure 3 This is a flowchart of a model editing method according to an embodiment of the present invention;

[0061] Figure 4 This is a flowchart of another model editing method in an embodiment of the present invention;

[0062] Figure 5 This is a flowchart of another model editing method in an embodiment of the present invention;

[0063] Figure 6 This is a schematic diagram of a model editing device according to an embodiment of the present invention;

[0064] Figure 7 This is a schematic diagram of an electronic device according to an embodiment of the present invention. Detailed Implementation

[0065] The present application is described below based on embodiments, but it is not limited to these embodiments. In the detailed description of the present application below, certain specific details are described in detail. Those skilled in the art can fully understand the present application without these details. To avoid obscuring the substance of the present application, well-known methods, processes, flows, elements, and circuits are not described in detail.

[0066] Furthermore, those skilled in the art should understand that the accompanying drawings provided herein are for illustrative purposes only and are not necessarily drawn to scale.

[0067] Unless the context explicitly requires it, words such as "including" or "contains" throughout the application should be interpreted as including rather than exclusive or exhaustive; that is, meaning "including but not limited to".

[0068] In the description of this application, it should be understood that the terms "first," "second," etc., are used for descriptive purposes only and should not be construed as indicating or implying relative importance. Furthermore, in the description of this application, unless otherwise stated, "a plurality of" means two or more.

[0069] In existing technologies, simple Sequential Model Editing (SME), MEND, and ROME methods are used to edit large-scale language models (LLMs).

[0070] Specifically, the SME method is only applicable to single-edit and simple knowledge editing scenarios. It can only handle small-scale data volumes and still faces significant challenges in editing long-sequence knowledge. Furthermore, in scenarios involving sequential editing of multiple pieces of knowledge, multiple edits are required. These multiple edits can lead to a degradation of the general capabilities of LLMs during the editing process, resulting in forgetting problems. This, in turn, affects other parameters in the LLMs during the editing process, causing a degradation of the capabilities of the LLMs during the editing process, i.e., forgetting problems, and ultimately leading to hallucination phenomena.

[0071] The MEND method is based on a set of small auxiliary editing networks using gradient decomposition. It rapidly edits a pre-trained model locally using a single desired input-output data set. MEND obtains gradients through standard fine-tuning, decomposes these gradients into two low-rank tensors, and utilizes the network modeling interactions between these tensors to provide superior editing performance. Even for models with over 10 billion parameters, MEND can complete the training of editing parameters within a day on a single Graphics Processing Unit (GPU), quickly applying new editing parameters to pre-trained large-scale language models. However, the MEND method can only model tensor interactions between individual editing samples and cannot effectively capture the correlations between input sample knowledge. In sequence editing scenarios, for multiple input knowledge points, the MEND method can only process each knowledge point sequentially, leading to performance degradation. During the editing process, the MEND method gradually adds internal parameters from the large-scale data model to the feedforward (FFN) layer, specifically as follows... Figure 1 As shown, the For the initial large-scale data model, knowledge data , ... Edit to the above First, knowledge data To edit, that is... After Edit generate The New parameters have been added internally, namely, the large-scale data model is described in the following text. Updated to Then, the knowledge data To edit, that is... After Edit generate The New parameters have been added internally, namely, the large-scale data model is described in the following text. Updated to ; and so on, after multiple edits, the knowledge data To edit, that is... After Edit generate The New parameters have been added internally, namely, the large-scale data model is described in the following text. Updated to The knowledge data The president of a certain country is AA-BB; (The knowledge data mentioned) The CEO of Amazon is CC-DD; [The aforementioned knowledge data] The largest solar power plant is located in California, India; the query to be edited includes... , , and The The content is "The President of a certain country is _ (The President of the country is _)", which states... The content is "Amazon's general manager is _ (The chief executive officer of Amazon is _)". The content is "The Space Needle is located in _". The content states that "the largest solar power plant is located in _ (The location of the largest solar power plant is _)"; according to the above... Generate the , , and The answers are respectively AA; Anssy; Seadia; India; the first three answers to the four questions are incorrect because of the following. Compared with the initial statement The significant variations in internal parameters are a major cause of the forgetting problem. As the number of edits to a large-scale data model increases, more and more parameters are added, leading to parameter degradation. The root cause is that internal parameter training is a holistic alignment training, while adding parameters only abruptly alters a portion of the parameter structure without modifying the knowledge data from a global parameter space perspective. , ... The query statement to be edited can be any knowledge data that needs to be edited. , , and This can be any query statement to be edited; this is just an example.

[0072] The ROME method is a knowledge-edit-based attribution method. During the knowledge editing process, it first locates model parameters based on the input knowledge to be edited, and then edits the model based on the located parameters. However, the ROME method also locates and edits based on single pieces of knowledge, and lacks interaction between the location and editing processes for sequential knowledge data. Therefore, the MEND method also suffers from capability degradation. The ROME method gradually modifies the internal parameters of the large-scale data model at the FFN layer during the editing process, specifically as follows... Figure 2 As shown, the For the initial large-scale data model, knowledge data , ... Edit to the above First, knowledge data To edit, that is... After Edit generate The The internal parameters have been modified, meaning the large-scale data model is now based on the aforementioned... Updated to Then, the knowledge data To edit, that is... After Edit generate The The internal parameters have been modified, meaning the large-scale data model is now based on the aforementioned... Updated to ; and so on, after multiple edits, the knowledge data To edit, that is... After Edit generate The The internal parameters have been modified, meaning the large-scale data model is now based on the aforementioned... Updated to The knowledge data The president of a certain country is AA-BB; (The knowledge data mentioned) The CEO of Amazon is CC-DD; [The knowledge data mentioned] The largest solar power plant is located in California, India; the query to be edited includes... , , and The The content is "The President of a certain country is _". The content is "Amazon's chief executive officer is _". The content is "The Space Needle is located in _". The content states that "the largest solar power plant is located in _ (The location of the largest solar power plant is _)"; according to the above... Generate the , , and The answers are respectively Bimp; Jeff Jassy; Califor; California; the answers to all four questions are incorrect because of the following. Compared with the initial statement The significant variations in internal parameters are a major cause of the forgetting problem. As the number of edits to a large-scale data model increases, more and more parameters are modified, leading to parameter degradation. The root cause lies in the fact that internal parameter training is a holistic alignment training, while parameter modifications only abruptly alter part of the parameter structure, failing to perform knowledge editing from the perspective of the global parameter space. , ... This can be any knowledge data that needs to be edited, which will not be elaborated here.

[0073] Therefore, how to achieve lifetime model editing of large-scale language model LLMs and reduce the capability degradation problem of the LLMs during the editing process is a problem that needs to be solved.

[0074] In this embodiment of the invention, to solve the above problems, a model editing method is proposed, specifically as follows: Figure 3 As shown, the method includes:

[0075] Step S301: Determine three sets of query statements to be edited.

[0076] Specifically, each group of query statements to be edited includes at least one query statement to be edited.

[0077] In this embodiment of the invention, the three sets of query statements to be edited are used to determine the reliability performance loss function, the general performance loss function, and the generalization performance loss function included in the editing loss function, and to determine the prompting learning loss function.

[0078] In one possible implementation, taking a set of query statements as an example, the query statements to be edited include... , and The The content is "Amazon's CEO is _". The content is "The country's executive branch is led by President _". The content is "Xiao Ming's birthplace is _ (The birthplace of Xiao Ming is _)".

[0079] Step S302: Based on each group of query statements to be edited, retrieve at least one piece of knowledge data corresponding to it in the knowledge database.

[0080] Specifically, in the knowledge database, retrieval-augmented generation is performed.

[0081] The method of generation (RAG) retrieves at least one knowledge graph corresponding to each of the query statements to be edited in each group of query statements to be edited; and generates at least one knowledge data based on the at least one knowledge graph (KG).

[0082] In this embodiment of the invention, the knowledge database stores multiple knowledge graphs, each consisting of triples. For example, based on the query to be edited, the knowledge graphs corresponding to each set of the query to be edited are retrieved from the knowledge database using a retrieval enhancement generation method, such as "President BB of a certain country", "General Manager DD of Amazon", ... "The largest solar power plant in India". After obtaining the knowledge graphs, they need to be generated into natural language statements. For example, the knowledge graph "President BB of a certain country" is used to generate knowledge data. The knowledge graph "Amazon General Manager DD" generates knowledge data for the statement "The president of a certain country is BB". For example, "The CEO of Amazon is DD"; ... knowledge data is generated for the knowledge graph "India, the largest solar power plant". The largest solar power plant is located in India.

[0083] In this embodiment of the invention, the knowledge data is obtained from the knowledge database through enhanced retrieval based on the query statement to be edited. The specific content obtained is determined according to the content of the query statement to be edited. This is only an illustrative example, and the specific details are determined according to the actual situation.

[0084] Step S303: Determine the enhanced representation of each group of query statements to be edited and at least one piece of knowledge data corresponding to them.

[0085] Specifically, the semantic representation of each group of query statements to be edited and its corresponding at least one knowledge data is determined; the semantic representation is then used to generate the enhanced representation.

[0086] In this embodiment of the invention, the query statement to be edited is... , , and knowledge data , The RoBERTa model is used to obtain the corresponding semantic representations. Specifically, the RoBERTa model can be represented by a function. This indicates that the semantic representation of the query statement to be edited is... The semantic representation of the knowledge data is as follows: According to the above and stated Further enhanced representations are generated, as follows:

[0087] The semantic representation of each group of query statements to be edited is input into the first multilayer perceptron layer. ), generate the enhanced representation corresponding to the query statement to be edited.

[0088] Specifically, the aforementioned Input to The enhanced representation corresponding to the query statement to be edited is generated as follows:

[0089] ;

[0090] In this embodiment of the invention, the query statement to be edited , , The corresponding enhanced characterization is and .

[0091] The semantic representation of the at least one piece of knowledge data is input into the second multilayer perceptron layer. ), generate the at least one corresponding enhanced representation.

[0092] Specifically, the aforementioned Input knowledge data to The enhanced representation corresponding to the knowledge data is generated as follows:

[0093] ;

[0094] In this embodiment of the invention, the knowledge data , The corresponding enhanced characterization is , ... In this embodiment of the invention, the multilayer perceptron (MLP) layers of the first and second multilayer perceptron layers are independently coded.

[0095] Step S304: Determine the prompt character representation corresponding to each query statement to be edited in each group of query statements to be edited based on the enhanced representation.

[0096] Specifically, the enhanced representation corresponding to the at least one piece of knowledge data is input into the third multilayer perceptron layer, and then the prompt character representation corresponding to the at least one piece of knowledge data is generated through an activation function; the maximum similarity index corresponding to each query statement to be edited in each group of query statements to be edited is determined, wherein the maximum similarity index represents the index of the knowledge data with the highest similarity to each query statement to be edited; and the prompt character representation corresponding to each query statement to be edited is determined according to the maximum similarity index.

[0097] In this embodiment of the invention, the third multilayer sensor layer is The activation function is The prompt character representation corresponding to the knowledge data, also known as the prompt token representation, is represented as follows:

[0098] ;

[0099] The length of the prompt character representation can be controlled, thereby controlling the length of reasoning in a large-scale data model. In this embodiment of the invention, a knowledge prompt is matched to each piece of knowledge data. For example, the include , , , , , ... The knowledge prompt information is not continuous natural language text, but a corresponding model embedding representation. If the knowledge prompt information is relatively long, the prompt characters (tokens) generated by the knowledge prompt information can be compressed. Assuming that each knowledge graph is composed of triples, the prompt character representation is determined to be a triple representation, that is, the compression of three tokens can achieve better large-scale semantic model editing effect.

[0100] In this embodiment of the invention, the The corresponding prompt character is represented as , ... The The corresponding prompt character is represented as , ... ;...the aforementioned The corresponding prompt character is represented as , ... , wherein That is, the number of tokens.

[0101] In one possible implementation, when determining the representation of the prompt character, it is necessary to... After function and the second multilayer perceptron layer ( )generate The above and stated , ... After the third multi-layer sensor layer, The activation function is Together, they generate the prompt character representation.

[0102] In this embodiment of the invention, it is necessary to determine the maximum similarity index corresponding to each query statement to be edited in each group of query statements to be edited. Then, based on the maximum similarity index, the corresponding prompt character representation is determined for each query statement to be edited, wherein the maximum similarity index... pass The scoring is as follows:

[0103] ;

[0104] Among them, the For the The transpose, the This indicates that the knowledge data does not exist, the KS score is Null, and the retrieval process is terminated; specifically, the knowledge data does not exist in the current query database, and a None placeholder is set for retrieval enhancement generation.

[0105] In this embodiment of the invention, the query statement to be edited is determined. and , ... Correspondingly, the query statement to be edited and , ... correspond.

[0106] Step S305: Determine the input embedding representation corresponding to each query statement to be edited in each group of query statements to be edited.

[0107] Specifically, the query statement to be edited Through function Sure The details are as follows:

[0108] ;

[0109] In this embodiment of the invention, the The corresponding input embedding representation is , ..., the stated The corresponding input embedding representation is , ..., the stated The corresponding input embedding representation is , ...

[0110] Step S306: Based on the combination of the prompt character representation and the input embedding representation corresponding to each of the query statements to be edited in each group of query statements to be edited, edit the large-scale language model to generate an updated large-scale language model and generate at least one semantic vector.

[0111] Specifically, the prompt character representation corresponding to each query statement to be edited is combined with the input embedding representation. This combination is not a concatenation at the natural language level, but a concatenation in the embedded semantic space, specifically represented as follows:

[0112] ;

[0113] The combination is then input into the updated large-scale language model. Generate semantic vectors ,Right now:

[0114] ;

[0115] In this embodiment of the invention, the query statement to be edited semantic vectors :DD(DD); The query statement to be edited semantic vectors :BB; The query statement to be edited semantic vectors Hawaii.

[0116] Step S307: Determine the loss function based on the semantic vectors corresponding to the three sets of query statements to be edited and the enhanced representation.

[0117] In this embodiment of the invention, the loss function includes an editing loss function and a cue learning loss function, wherein the editing loss function includes a reliability performance loss function, a general performance loss function, and a generalization performance loss function.

[0118] Specifically, the reliability performance loss function is as follows:

[0119] = ;

[0120] Among them, the The semantic vector corresponding to the query statement to be edited, which corresponds to the reliability performance, is... The query statement to be edited corresponds to the reliability performance. This is for the updated large-scale language model.

[0121] The general performance loss function is as follows:

[0122] = ;

[0123] Among them, the The semantic vector corresponding to the query statement to be edited, which corresponds to general performance. This is the query statement to be edited corresponding to general performance.

[0124] The generalization performance loss function is as follows:

[0125] =KL( ;

[0126] Among them, the The semantic vector corresponding to the query statement to be edited, which corresponds to the generalization performance. For the query statement to be edited corresponding to generalization performance, the For the initial large-scale language model, KL refers to KL divergence (Kullback–Leibler divergence).

[0127] In this embodiment of the invention, the cue learning process for determining the cue learning loss function is a cue token training process performed through a contrastive learning process. The currently recalled knowledge is used as a positive sample, and other samples are used as negative samples. Contrastive learning training is performed using the infoNCE loss. Specifically, the formula for generating positive samples during training is as follows:

[0128] = ;

[0129] Wherein, R is the sample set.

[0130] The formula for generating negative samples during training is as follows:

[0131] = ;

[0132] Among them, the The set after removing positive samples.

[0133] The formula for the cue learning loss function is as follows:

[0134] = ;

[0135] In one possible implementation, the It is expressed as follows:

[0136] ;

[0137] Among them, the This is a positive sample.

[0138] Step S308: Edit the updated large-scale language model according to the loss function to generate the target large-scale language model.

[0139] Specifically, through the aforementioned , , and Regarding the Edit and generate target .

[0140] In this embodiment of the invention, the data flow diagram of the model editing process is as follows: Figure 4 As shown.

[0141] Through the above embodiments, the For the initial large-scale data model, knowledge data , ... Edit to the above First, knowledge data To edit, that is... After Edit exist Generate Edit1 from outside Edit1 is for knowledge retrieval; then, the knowledge data... To edit, that is... After Edit exist Generate Edit1 and Edit2 externally. ; and so on, after multiple edits, the knowledge data To edit, that is... After Edit exist Generate Edit1, Edit2...Editt externally. The The internal parameters remained unchanged; only the external parameters were modified. A detailed diagram is shown below. Figure 5 As shown, it is assumed that the knowledge data The president of a certain country is AA-BB; (The knowledge data mentioned) The CEO of Amazon is CC-DD; [The aforementioned knowledge data] The location of the largest solar power plant is California — India; the query to be edited includes , , and The The content is "The President of a certain country is _ (The President of the country is _)", which states... The content is "Amazon's general manager is _ (The chief executive officer of Amazon is _)". The content is "The Space Needle is located in _". The content states that "the largest solar power plant is located in _ (The location of the largest solar power plant is _)"; according to the above... Generate the , , and The answers are respectively :BB; :DD; Seattle; India; The answers to all four questions are correct, indicating that the large-scale data model obtained through the method described in the embodiments of the present invention has good general performance after multiple comparisons and edits, and will not produce forgetting problems.

[0142] In this embodiment of the invention, the knowledge to be edited is continuously stored in a knowledge database for recall learning. That is, the knowledge data is retrieved using retrieval capabilities for training. This maintains the reusability of knowledge and preserves the lifetime editing performance of the large-scale language model. Furthermore, during the editing process of the large-scale language model, the length of the large model's input is compressed by reducing the number of tokens through the MLP layer. This improves the utilization rate of the large model's input data and allows the large-scale language model to perform knowledge editing without changing its internal parameters, thus reducing the degradation of the large-scale language model's general performance.

[0143] In this embodiment of the invention, the model editing method can be called RECIPE. The effects of different model editing methods on different number of edits and different datasets are shown in Table 1 below, as detailed below:

[0144] Table 1

[0145]

[0146]

[0147] The average values ​​in Table 1 have positive and negative deviations, which will not be elaborated here;

[0148] As shown in Table 1, RECIPE performs very well in terms of reliability, versatility and generalization when edited on different datasets and with different number of edits, and its general performance is not affected by the different datasets.

[0149] In this embodiment of the invention, the model editing method can be called RECIPE. The changes in general capabilities as the number of edits increases are shown in Table 2 below, as detailed below:

[0150] Table 2

[0151]

[0152] In Table 2 above, N / A represents the general performance of the unedited model. As can be seen from Table 2, the general performance of the model is good in CSQA, MMLU, ANLI, and SQUAD-2, and the performance of the large-scale language model in general performance is not reduced by the increase of the number of edits.

[0153] In this embodiment of the invention, a model editing device is provided, such as... Figure 6As shown, it specifically includes: a determining unit 601, a retrieval unit 602, and a generating unit 603; wherein, the determining unit 601 is used to determine three groups of query statements to be edited, wherein each group of query statements to be edited includes at least one query statement to be edited; the retrieval unit 602 is used to retrieve at least one piece of knowledge data corresponding to each group of query statements to be edited from the knowledge database; the determining unit 601 is also used to determine the enhanced representation of each group of query statements to be edited and its corresponding at least one piece of knowledge data; the determining unit 601 is also used to determine the prompt character representation corresponding to each query statement to be edited in each group of query statements to be edited based on the enhanced representation; the determining unit 603... The determining unit 601 is further configured to determine the input embedding representation corresponding to each query statement to be edited in each group of query statements to be edited; the generating unit 603 is configured to edit the large-scale language model according to the combination of the prompt character representation corresponding to each query statement to be edited in each group of query statements to be edited and the input embedding representation, generate an updated large-scale language model, and generate at least one semantic vector; the determining unit 601 is further configured to determine the loss function according to the semantic vectors corresponding to the three groups of query statements to be edited and the augmented representation; the generating unit 603 is further configured to edit the updated large-scale language model according to the loss function to generate a target large-scale language model.

[0154] Furthermore, the retrieval unit is specifically used for:

[0155] In the knowledge database, at least one knowledge graph corresponding to each of the query statements to be edited in each group is retrieved through the retrieval enhancement generation method;

[0156] Generate at least one piece of knowledge data based on at least one knowledge graph.

[0157] Furthermore, the determining unit is specifically used for:

[0158] Determine the semantic representation of each group of query statements to be edited and at least one piece of knowledge data corresponding to it;

[0159] The semantic representation is used to generate the enhanced representation.

[0160] Furthermore, the determining unit is specifically used for:

[0161] The semantic representation of each group of query statements to be edited is input into the first multilayer perceptron layer to generate the enhanced representation corresponding to the query statement to be edited.

[0162] Furthermore, the determining unit is specifically used for:

[0163] The semantic representation of the at least one piece of knowledge data is input into the second multilayer perceptron layer to generate an enhanced representation corresponding to the at least one piece of knowledge data.

[0164] Furthermore, the determining unit is specifically used for:

[0165] The enhanced representation corresponding to the at least one piece of knowledge data is input into the third multilayer perceptron layer, and then the prompt character representation corresponding to the at least one piece of knowledge data is generated through the activation function;

[0166] Determine the maximum similarity index corresponding to each query statement to be edited in each group of query statements to be edited, wherein the maximum similarity index represents the index of the knowledge data that has the highest similarity to each query statement to be edited;

[0167] The prompt character representation corresponding to each query statement to be edited is determined based on the maximum similarity index.

[0168] Optionally, the loss function includes an editing loss function and a cue learning loss function, wherein the editing loss function includes a reliability performance loss function, a general performance loss function, and a generalization performance loss function.

[0169] Figure 7 This is a schematic diagram of the structure of the electronic device described in an embodiment of the present invention. Figure 7 As shown, it includes a general computer hardware architecture, which includes at least a processor 701 and a memory 702. The processor 701 and the memory 702 are connected via a bus 703. The memory 702 is adapted to store instructions or programs executable by the processor 701. The processor 701 can be a standalone microprocessor or a collection of one or more microprocessors. Thus, the processor 701 executes the instructions stored in the memory 702 to perform the method flow of the embodiments of the present invention as described above, thereby realizing data processing and control of other devices. The bus 703 connects the above-mentioned components together, and also connects the above-mentioned components to a display controller 704, a display device, and an input / output (I / O) device 705. The input / output (I / O) device 705 can be a mouse, keyboard, modem, network interface, touch input device, motion-sensing input device, printer, and other devices known in the art. Typically, the input / output device 705 is connected to the system via an input / output (I / O) controller 706.

[0170] The instructions stored in memory 702 are executed by at least one processor 701 to: determine three sets of query statements to be edited, wherein each set of query statements to be edited includes at least one query statement to be edited; retrieve at least one piece of knowledge data corresponding to each set of query statements to be edited from the knowledge database; determine the enhanced representation of each set of query statements to be edited and the at least one piece of knowledge data corresponding to it; determine the prompt character representation corresponding to each query statement to be edited in each set of query statements to be edited based on the enhanced representation; determine the input embedding representation corresponding to each query statement to be edited in each set of query statements to be edited; edit the large-scale language model based on the combination of the prompt character representation and the input embedding representation, generate an updated large-scale language model, and generate at least one semantic vector; determine a loss function based on the semantic vectors corresponding to the three sets of query statements to be edited and the enhanced representation; and edit the updated large-scale language model based on the loss function to generate a target large-scale language model.

[0171] Specifically, the electronic device includes: one or more processors 701 and a memory 702. Figure 7 Take a processor 701 as an example. The processor 701 and the memory 702 can be connected via a bus or other means. Figure 7 Taking a bus connection as an example, memory 702, as a non-volatile computer-readable storage medium, can be used to store non-volatile software programs, non-volatile computer-executable programs, and modules. Processor 701 executes various functional applications and data processing of the device by running the non-volatile software programs, instructions, and modules stored in memory 702, thereby implementing the aforementioned method for determining the model editing.

[0172] Memory 702 may include a program storage area and a data storage area, wherein the program storage area may store the operating system and applications required for at least one function; the data storage area may store an option list, etc. Furthermore, memory 702 may include high-speed random access memory, and may also include non-volatile memory, such as at least one disk storage device, flash memory device, or other non-volatile solid-state storage device. In some embodiments, memory 702 may optionally include memory remotely located relative to processor 701, and these remote memories may be connected to external devices via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.

[0173] One or more modules are stored in memory 702, and when executed by one or more processors 701, they perform the model editing method in any of the above method embodiments.

[0174] As those skilled in the art will recognize, various aspects of the embodiments of the present invention can be implemented as a system, method, or computer program product. Therefore, various aspects of the embodiments of the present invention can take the form of a completely hardware implementation, a completely software implementation (including firmware, resident software, microcode, etc.), or an implementation combining software and hardware aspects, which may generally be referred to herein as a "circuit," "module," or "system." Furthermore, various aspects of the embodiments of the present invention can take the form of a computer program product implemented in one or more computer-readable media having computer-readable program code implemented thereon.

[0175] Any combination of one or more computer-readable media can be used. A computer-readable medium can be a computer-readable signal medium or a computer-readable storage medium. A computer-readable storage medium can be, for example, (but not limited to) an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or apparatus, or any suitable combination thereof. More specific examples (not an exhaustive list) of computer-readable storage media will include: an electrical connection having one or more wires, a portable computer floppy disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable optical disc read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In the context of embodiments of the present invention, a computer-readable storage medium can be any tangible medium capable of containing or storing a program used by or in conjunction with an instruction execution system, device, or apparatus.

[0176] Computer-readable signal media may include propagated digital signals having computer-readable program code implemented therein, such as in baseband or as part of a carrier wave. Such propagated signals may take any of a variety of forms, including, but not limited to, electromagnetic, optical, or any suitable combination thereof. A computer-readable signal medium may be any computer-readable medium that is not a computer-readable storage medium and can communicate, propagate, or transmit a program used by or in conjunction with an instruction execution system, device, or apparatus.

[0177] Program code implemented on a computer-readable medium may be transmitted using any suitable medium, including but not limited to wireless, wired, fiber optic cable, RF, or any suitable combination thereof.

[0178] Computer program code for performing operations relating to various aspects of embodiments of the present invention can be written in any combination of one or more programming languages, including: object-oriented programming languages ​​such as Java, Smalltalk, C++, etc.; and conventional procedural programming languages ​​such as the "C" programming language or similar programming languages. The program code can be executed as a standalone software package entirely on the user's computer, partially on the user's computer, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the latter case, the remote computer can be connected to the user's computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or it can be connected to an external computer (e.g., via the Internet provided by an Internet service provider).

[0179] The flowchart illustrations and / or block diagrams of the methods, apparatus (systems), and computer program products according to embodiments of the present invention describe various aspects of the embodiments of the present invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, or other programmable data processing apparatus to produce a machine such that the instructions (executed via the processor of the computer or other programmable data processing apparatus) create means for implementing the functions / actions specified in the flowchart and / or block diagram blocks or blocks.

[0180] These computer program instructions may also be stored in a computer-readable medium that can direct a computer, other programmable data processing apparatus or other means to operate in a particular manner, such that the instructions stored in the computer-readable medium produce an article of writing that includes instructions that implement the functions / actions specified in flowchart and / or block diagram blocks or blocks.

[0181] Computer program instructions may also be loaded onto a computer, other programmable data processing apparatus or other device to cause a series of operable steps to be performed on the computer, other programmable apparatus or other device to produce a computer-implemented process, such that the instructions, which execute on the computer or other programmable apparatus, provide for implementing the functions / actions specified in flowchart and / or block diagram blocks or blocks.

[0182] The above description is merely a preferred embodiment of this application and is not intended to limit this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.

Claims

1. A method for model editing, characterized in that, The method includes: Three groups of query statements to be edited are identified, wherein each group of query statements to be edited includes at least one query statement to be edited, and the query statements to be edited are natural language statements; Based on the query statement to be edited in each group, at least one piece of knowledge data corresponding to it is retrieved from the knowledge database. Each group of the query statements to be edited and its corresponding enhanced representation of at least one knowledge data point are determined. Based on the enhanced representation, determine the prompt character representation corresponding to each query statement to be edited in each group of query statements to be edited; Determine the input embedding representation corresponding to each query statement to be edited in each group of query statements to be edited; Based on the combination of the prompt character representation and the input embedding representation corresponding to each of the query statements to be edited in each group of query statements to be edited, the large-scale language model is edited to generate an updated large-scale language model and generate at least one semantic vector. The loss function is determined based on the semantic vectors corresponding to the three sets of query statements to be edited and the enhanced representation; The updated large-scale language model is edited based on the loss function to generate the target large-scale language model.

2. The method according to claim 1, characterized in that, The step of retrieving at least one piece of knowledge data corresponding to each group of query statements to be edited in the knowledge database specifically includes: In the knowledge database, at least one knowledge graph corresponding to each of the query statements to be edited in each group is retrieved through the retrieval enhancement generation method; Generate at least one piece of knowledge data based on at least one knowledge graph.

3. The method according to claim 1, characterized in that, The step of determining the enhanced representation of each group of query statements to be edited and its corresponding at least one knowledge data item specifically includes: Determine the semantic representation of each group of query statements to be edited and at least one piece of knowledge data corresponding to it; The semantic representation is used to generate the enhanced representation.

4. The method according to claim 3, characterized in that, The step of generating the enhanced representation from the semantic representation specifically includes: The semantic representation of each group of query statements to be edited is input into the first multilayer perceptron layer to generate the enhanced representation corresponding to the query statement to be edited.

5. The method according to claim 3, characterized in that, The step of generating the enhanced representation from the semantic representation specifically includes: The semantic representation of the at least one piece of knowledge data is input into the second multilayer perceptron layer to generate an enhanced representation corresponding to the at least one piece of knowledge data.

6. The method according to claim 1, characterized in that, The step of determining the prompt character representation corresponding to each query statement to be edited in each group of query statements to be edited based on the enhanced representation specifically includes: The enhanced representation corresponding to the at least one piece of knowledge data is input into the third multilayer perceptron layer, and then the prompt character representation corresponding to the at least one piece of knowledge data is generated through the activation function; Determine the maximum similarity index corresponding to each query statement to be edited in each group of query statements to be edited, wherein the maximum similarity index represents the index of the knowledge data that has the highest similarity to each query statement to be edited; The prompt character representation corresponding to each query statement to be edited is determined based on the maximum similarity index.

7. The method according to claim 1, characterized in that, The loss function includes an editing loss function and a cue learning loss function. The editing loss function includes a reliability performance loss function, a general performance loss function, and a generalization performance loss function.

8. A model editing apparatus, characterized in that, The device includes: The determining unit is used to determine three groups of query statements to be edited, wherein each group of query statements to be edited includes at least one query statement to be edited, and the query statements to be edited are natural language statements; The retrieval unit is used to retrieve at least one piece of knowledge data corresponding to each group of query statements to be edited from the knowledge database. The determining unit is further configured to determine each group of query statements to be edited and the enhanced representation of at least one knowledge data corresponding to it; The determining unit is further configured to determine the prompt character representation corresponding to each query statement to be edited in each group of query statements to be edited based on the enhanced representation; The determining unit is further configured to determine the input embedding representation corresponding to each query statement to be edited in each group of query statements to be edited; The generation unit is used to edit the large-scale language model based on the combination of the prompt character representation and the input embedding representation corresponding to each of the query statements to be edited in each group of query statements to be edited, to generate an updated large-scale language model, and to generate at least one semantic vector. The determining unit is further configured to determine a loss function based on the semantic vectors corresponding to the three sets of query statements to be edited and the enhanced representation; The generation unit is further configured to edit the updated large-scale language model according to the loss function to generate a target large-scale language model.

9. An electronic device comprising a memory and a processor, characterized in that, The memory is used to store one or more computer program instructions, wherein the one or more computer program instructions are executed by the processor to implement the method as described in any one of claims 1-7.

10. A computer-readable storage medium, characterized in that, The computer-readable storage The medium stores a computer program that, when executed by a processor, implements the method as described in any one of claims 1-7.

Citation Information

Patent Citations

  • Data retrieval method, device and system, electronic equipment and readable storage medium

    CN118093962A

  • Dataset generation using large language models

    US20240185001A1