Joint knowledge editing method, system and equipment based on large language model
By jointly editing the parameters, inputs and outputs of the large language model, the illusions, deviations, knowledge degradation and knowledge outdated problems that arise during the application process are solved, and the effect of correcting error output is achieved and computing resource consumption is reduced.
Patent Information
- Application Number
- CN202411946804.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-27
- Publication Date
- 2025-04-25
AI Technical Summary
During the application process, large language models may experience hallucinations, deviation problems, knowledge degradation and knowledge outdated problems. The existing technology is difficult to effectively solve these problems during the model training stage.
A variety of knowledge editing techniques are adopted, including adjusting model parameters, modifying input prompt words, and editing output. Parameter modification, input update and output editing of the large language model through joint knowledge editing methods, and controlling the model's inference process to correct the error output.
It effectively solves the hallucinations, deviation problems, knowledge degradation and outdated knowledge that may occur during the application of large language models, helping model developers and users to correct the model's error output and reduce computing resource consumption.
Smart Images

Figure CN119886302A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of large language models, and in particular relates to a joint knowledge editing method, system and device based on a large language model. Background Art
[0002] Although large language pre-training models have demonstrated impressive results in many downstream tasks, the largest models currently available still suffer from errors, including hallucinations, biases, knowledge degradation, and knowledge obsolescence. However, attempting to address these issues during model training is unrealistic.
[0003] To address the above issues, the first approach involves editing model parameters. Specifically, model parameter editing utilizes gradient decomposition technology, which allows developers to modify local parts of the model by directly manipulating model weights. Through algorithmic design, this approach preserves the model's original generalization capabilities while improving specific areas, thereby reducing the cost and time of model customization. The second approach involves editing the model's input prompts. This approach integrates a large language model and a knowledge graph to address the multi-hop answering task after knowledge editing. Specifically, this approach converts edited factual sentences into triples. For a given question, the large model automatically extracts its relationship chains and transforms them into queries. It then finds the most relevant edited facts based on the question and generates an answer based on these facts. When the answer generated by the large language model conflicts with the answer from the knowledge graph, the answer from the knowledge graph is used as the final answer. The third approach involves editing the model's output. When generating each reasoning step, the parameters and new knowledge are used to find knowledge items that meet the constraints, referred to as valid candidate steps. Among the valid candidates, the more important ones are prioritized as new reasoning steps for further reasoning. Finally, the importance of the large language model is comprehensively evaluated based on the semantic relationships between different candidates and the amount of information the new knowledge contains compared to the parameter knowledge.
[0004] The shortcomings of the three existing solutions are: 1) Models typically have a large number of parameters, which makes it complex and difficult to precisely locate and edit specific knowledge. Furthermore, modifying the parameters of one part of the model may have unexpected effects on other parts of the model, leading to performance degradation or other consequences. 2) Input prompts can only affect the model's output to a certain extent and cannot precisely control the model's behavior as directly editing parameters. Furthermore, different input prompts may lead to inconsistent outputs, especially when dealing with complex or ambiguous tasks, which may require complex prompt design and extensive experimentation. Summary of the Invention
[0005] The present invention aims to address existing issues in the prior art and provide a method, system, and device for joint knowledge editing based on large language models. This method utilizes multiple knowledge editing techniques, including adjusting model parameters, modifying input prompts, and editing output. It aims to address challenges such as hallucination effects, bias, knowledge degradation, and knowledge obsolescence that may arise during the application of large language models.
[0006] In order to achieve the above-mentioned object of the invention, the present invention specifically adopts the following technical solutions:
[0007] In a first aspect, the present invention provides a joint knowledge editing method based on a large language model, which comprises the following steps:
[0008] S1. Use the model parameter modification method to perform knowledge editing on the large language model to obtain the large language model after parameter modification;
[0009] S2. Update the original question using the model input modification method. After performing knowledge editing on the large language model with modified parameters, a new question is obtained.
[0010] S3. Use the new question as the input of the large language model with modified parameters, control the reasoning process of the large language model with modified parameters, obtain the answer to the new question and use it as the final output result, and complete the joint knowledge editing of the large language model.
[0011] Based on the above solution, each step can be implemented in the following preferred specific manner.
[0012] As a preferred embodiment of the first aspect, in step S1, the specific processing process of knowledge editing of the large language model by the model parameter modification method is as follows: obtain the gradients and inputs of each layer from the parameters of the large language model to be edited, obtain a trained multi-layer editing network, splice the input of the lth layer of the large language model to be edited and the gradient of the l+1th layer as the input of the editing network, and obtain the editing weight after processing by the editing network. And compare it with the weight W of the first layer of the large language model to be edited l Perform the operation and get the edited weight as The edited weight As the new weight of the lth layer of the large language model to be edited, until all layers of the large language model to be edited have been processed by the editing network to obtain new weights, thereby obtaining the large language model with modified parameters; where α is the step size corresponding to the parameters of the lth layer of the large language model to be edited.
[0013] As a preferred embodiment of the first aspect, the editing network adopts a two-layer structure. In the editing network, the specific processing process is as follows:
[0014] The input of the lth layer and the l+1th layer gradient of the large language model to be edited are concatenated as the input of the editing network, and are processed by the first layer of the editing network to obtain a first intermediate result; the first intermediate result is input to the second layer of the editing network, and is processed by the second layer of the editing network to obtain an editing weight.
[0015] Furthermore, the input of the lth layer of the large language model to be edited and the gradient of the l+1th layer are concatenated as the input z of the editing network. l , processed by the first layer of the editing network according to the formula, the first intermediate result h is obtained l :
[0016]
[0017] The first intermediate result is input into the second layer of the editing network, and the editing weight is obtained by the second layer of the editing network according to the following formula:
[0018]
[0019] Where: σ is the nonlinear activation function; and Indicates the scaling of the first and second layers of the editing network; and Represents the offset of the first and second layers of the editing network; ⊙ represents point-by-point multiplication; U1, V1, U2, V2 all represent the weight matrices of the editing network; b represents the bias term.
[0020] As a preferred embodiment of the first aspect, in step S2, the specific process of performing knowledge editing on the large language model after parameter modification by the model input modification method is as follows:
[0021] S21. Obtain the original knowledge graph, convert the facts to be edited into edit knowledge triples using the new large language model, and use the edit knowledge triples to update the original knowledge graph to obtain an updated knowledge graph;
[0022] S22. For a given original question, use the new large language model to extract the relationship chain between the question-related entities and their connections with other unknown entities in the updated knowledge graph;
[0023] S23. Obtain a pre-built original answer template, fill the relationship chain into the original answer template, convert the relationship chain into a query list, and use the query list to search the updated knowledge graph, outputting the n entities in the updated knowledge graph with the highest cosine similarity to the original question;
[0024] S24. Add the n entities with the highest cosine similarity to the original question to obtain a new question.
[0025] As a preferred embodiment of the first aspect, in step S3, the specific process of obtaining the answer to the new question is:
[0026] S31. In each iteration of the reasoning process, the updated knowledge graph is retrieved to obtain the N entities with the highest cosine similarity to the input used in each iteration and used as N reasoning steps. The large language model with modified parameters generates one reasoning step with a temperature of 0, and the generated N+1 reasoning steps are used as reasoning step candidates.
[0027] S32, selecting the reasoning step with the highest cosine similarity and containing new knowledge from the reasoning step candidates as the selected reasoning step;
[0028] S33. Use the new large language model as a verifier to determine whether the selected reasoning step meets the preset constraint verification conditions: If the selected reasoning step does not meet the constraint verification conditions, it will be discarded. In addition to the selected reasoning step, the reasoning step with the highest cosine similarity and containing new knowledge will be reselected as the suboptimal reasoning step and re-judged until the constraint verification conditions are met; If the selected reasoning step meets the constraint verification conditions, determine whether the reasoning reaches the preset termination conditions. If the termination conditions are met, stop the reasoning and get the answer to the new question; If the termination conditions are not met, use the output result of the current iteration as the input of the next iteration, and continue the cycle until the termination conditions are met and the answer to the new question is obtained.
[0029] As a preferred embodiment of the above-mentioned first aspect, the specific process of judging whether the selected reasoning step satisfies the preset constraint verification conditions is: the constraint prompt words provide the task requirements and the answer template to the new large language model, and the constraint prompt words include independence constraint conditions, coherence constraint conditions, rationality constraint conditions and relevance constraint conditions. When the new large language model judges that the selected reasoning step satisfies the four constraint conditions at the same time, it means that the selected reasoning step satisfies the constraint verification conditions; otherwise, it means that the selected reasoning step does not satisfy the constraint verification conditions; among them, the independence constraint condition is that each reasoning step is independent of each other; the coherence constraint condition is that there is coherence between two adjacent reasoning steps; the rationality constraint condition is that there is no conflict between the reasoning step and the new knowledge; the relevance constraint condition is that each reasoning step is related to the original problem.
[0030] In a second aspect, the present invention provides a joint knowledge editing system based on a large language model, which comprises the following steps:
[0031] A parameter editing module is used to perform knowledge editing on the large language model through a model parameter modification method to obtain a large language model with modified parameters;
[0032] The input editing module is used to update the original question through the model input modification method. After the knowledge editing of the large language model with modified parameters, a new question is obtained.
[0033] The result acquisition module is used to take the new question as the input of the large language model with modified parameters, control the reasoning process of the large language model with modified parameters, obtain the answer to the new question and use it as the final output result, thereby completing the joint knowledge editing of the large language model.
[0034] In a third aspect, the present invention provides a computer program product, comprising a computer program / instruction, which, when executed by a processor, can implement the joint knowledge editing method based on a large language model as described in any one of the solutions in the first aspect above.
[0035] In a fourth aspect, the present invention provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the joint knowledge editing method based on a large language model as described in any of the schemes in the first aspect above is implemented.
[0036] In a fifth aspect, the present invention provides a computer electronic device comprising a memory and a processor;
[0037] The memory is used to store computer programs;
[0038] The processor is configured to implement the large language model-based joint knowledge editing method as described in any one of the solutions of the first aspect above when executing the computer program.
[0039] Compared with the prior art, the present invention has the following beneficial effects:
[0040] The present invention proposes a joint knowledge editing method, system and device based on a large language model, which adjusts the parameters, input and output of the large language model to achieve the purpose of solving the problems of hallucination, bias, knowledge decay and knowledge obsolescence of the large language model.
[0041] This invention aims to help model developers and users correct erroneous model outputs. By using knowledge editing to correct model errors, it can achieve the desired results with less computational resources than other methods, such as model fine-tuning. Given the increasing popularity of large-scale language model applications, this method has significant practical significance. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] Figure 1 Schematic diagram of the steps of the method of the present invention;
[0043] Figure 2 Schematic diagram of knowledge editing of a large language model through model input modification method;
[0044] Figure 3 A schematic diagram of obtaining the final output result of the present invention;
[0045] Figure 4 is a system block diagram of the present invention;
[0046] Figure 5 A schematic diagram of the composition of computer electronic equipment. DETAILED DESCRIPTION
[0047] In order to make the above-mentioned objects, features and advantages of the present invention more clearly understood, the specific embodiments of the present invention are described in detail below with reference to the accompanying drawings. In the following description, many specific details are set forth to facilitate a full understanding of the present invention. However, the present invention can be implemented in many other ways than those described herein, and those skilled in the art can make similar improvements without violating the connotation of the present invention. Therefore, the present invention is not limited to the specific embodiments disclosed below. The technical features in the various embodiments of the present invention can be combined accordingly without conflicting with each other.
[0048] In the description of the present invention, it should be understood that the terms "first" and "second" are used solely for descriptive purposes and are not to be construed as indicating or implying relative importance or implicitly specifying the number of technical features being described. Therefore, features defined as "first" or "second" may explicitly or implicitly include at least one of such features.
[0049] In order to solve the problems of the existing technical solutions, the present invention proposes a joint knowledge editing method based on a large language model, which combines a variety of commonly used knowledge editing methods and ensures that the model effect is optimal by editing multiple parts such as parameters, input, and output of the model.
[0050] like Figure 1 As shown, in a preferred implementation of the present invention, the above-mentioned joint knowledge editing method based on a large language model includes the following steps S1 to S3. The specific implementation process is described in detail below.
[0051] S1. Use the model parameter modification method to perform knowledge editing on the large language model to be edited, and obtain the large language model after parameter modification.
[0052] It should be noted that in the present invention, in the above step S1, the specific processing process of the model parameter modification method for knowledge editing of the large language model is as follows: the gradients and inputs of each layer are obtained from the parameters of the large language model to be edited, a trained multi-layer editing network is obtained, the input of the lth layer of the large language model to be edited and the gradient of the l+1th layer are spliced as the input of the editing network, and after processing by the editing network, the editing weights are obtained. And compare it with the weight W of the first layer of the large language model to be edited l Perform the operation and get the edited weight as The edited weight As the new weights for the lth layer of the large language model to be edited, this process continues until all layers of the large language model to be edited have been processed by the editing network to obtain new weights, thereby obtaining the large language model with modified parameters. Here, α is the step size corresponding to the parameters of the lth layer of the large language model to be edited.
[0053] It should be noted that, in the embodiment of the present invention, the editing network adopts a two-layer structure. In the editing network, the specific processing process is as follows:
[0054] The input u of the lth layer of the large language model to be edited l and the l+1th layer gradient δ l+1 After splicing, it is used as the input z of the editing network l =contact(u l ,δ l+1 ), is processed by the first layer of the editing network according to the following formula to obtain the first intermediate result h l :
[0055]
[0056] The first intermediate result is input into the second layer of the editing network, and the editing weight is obtained by the second layer of the editing network according to the following formula:
[0057]
[0058] Where: σ is a nonlinear activation function, such as ReLU; and Indicates the scaling of the first and second layers of the editing network; and Represents the offset of the first and second layers of the editing network; ⊙ represents point-by-point multiplication; U1, V1, U2, V2 all represent the weight matrices of the editing network; b represents the bias term; contact(·) represents the vector concatenation operation.
[0059] It should be noted that in step S1 of the present invention, in order to reduce the number of parameters, the editing weights are calculated by the editing network. In the process of , weights are shared between different layers, and only separate editing weights are learned for weight matrices of different shapes. At the same time, through layer-specific scaling s l and offset o l Make adjustments to the hidden states and outputs of the edit network.
[0060] S2. Use the model input modification method to update the original question, and perform knowledge editing on the large language model after parameter modification to obtain a new question.
[0061] It should be noted that, in the present invention, Figure 2 As shown, the specific processing process of the above step S2 using the model input modification method to perform knowledge editing on the large language model after parameter modification is as follows:
[0062] S21. Obtain the original knowledge graph, convert the facts to be edited into edit knowledge triples with the help of the new large language model, and use the edit knowledge triples to update the original knowledge graph to obtain the updated knowledge graph.
[0063] It should be noted that in step S21 of the present invention, the input of the model is modified to perform knowledge editing on the large language model. In this embodiment, the widely recognized knowledge graph Wikidata is used as the original knowledge graph, and then a new large language model (such as ChatGPT-4) is used to edit the facts to be edited into an edited knowledge triple. This step mainly proposes prompt words to the new large language model, allowing it to generate relevant response results (i.e., edited knowledge triples), and then uses these generated relevant response results to update the original knowledge graph, thereby keeping the knowledge graph in the latest state, and finally obtaining an updated knowledge graph.
[0064] S22. For a given original question, use the new large language model to extract the relationship chain between the question-containing entities and their connections with other unknown entities in the updated knowledge graph.
[0065] It should be noted that in step S22 of the present invention, for a question, the new large language model is used to extract its relationship chain, covering the connection between the main question entity and other unknown entities in the updated knowledge graph. When extracting its relationship chain, the present invention provides multiple relationship chain extraction examples in the prompt word. All relationships are selected from a predefined relationship list to reduce different representations of the same relationship. This enables the new large language model (such as ChatGPT-4) to extract the relationship chain according to the structured template and generate output.
[0066] S23. Obtain a pre-built original answer template, fill the relationship chain into the original answer template, and after filling, convert the relationship chain into a query list, and use the query list to search the updated knowledge graph, and output the n entities in the updated knowledge graph with the highest cosine similarity with the original question.
[0067] It should be noted that in step S23 of the present invention, an original answer template of edited knowledge is manually set, and the new large language model (such as ChatGPT-4) is allowed to fill the above extracted relationship chain into the original answer template. After filling the original answer template, the relationship chain is converted into a formal query list, and the formal query list is used to search the updated knowledge graph to obtain the n entities with the highest cosine similarity with the original question. Therefore, before answering, the large language model with modified parameters must not only browse the knowledge graph according to its own weight before issuing a response to generate an answer.
[0068] S24. Add the n entities with the highest cosine similarity to the original question to obtain a modified question, i.e., a new question.
[0069] S3. Use the new question as the input of the large language model with modified parameters, control the reasoning process of the large language model with modified parameters, obtain the answer to the new question and use it as the final output result, and complete the joint knowledge editing of the large language model.
[0070] It should be noted that in step S3 of the present invention, the new question obtained in S2 (i.e. Figure 3 The modified question in S2) is used as the input of this step, and the large language model (i.e. Figure 3 The reasoning process of the large language model after editing the parameters in the __name__ is used to achieve the purpose of knowledge editing and obtain the answer to the new question (i.e. Figure 3 Output the final result).
[0071] It should be noted that, in step S3 of the present invention, the specific process of obtaining the answer to the new question is:
[0072] S31. In each iteration of the reasoning process, the updated knowledge graph is retrieved to obtain the N entities with the highest cosine similarity with the input used in each iteration and used as N reasoning steps. The large language model with modified parameters generates 1 reasoning step with a temperature of 0, and the generated N+1 reasoning steps are used as reasoning step candidates.
[0073] It should be noted that in step S31 of the present invention, the updated knowledge graph is retrieved, the cosine similarity between the entities in the updated knowledge graph and the input used in each iteration is calculated, and the N entities with the highest cosine similarity are obtained, and these entities correspond to N reasoning steps.
[0074] S32. Select the reasoning step with the highest cosine similarity and containing new knowledge from the reasoning step candidates as the selected reasoning step.
[0075] It should be noted that in step S32 of the present invention, the selection of reasoning step candidates is based on the principle that editing facts are usually more important than generation steps (because they contain new knowledge unknown to the large language model after parameter modification) and editing facts that are semantically closer to the generation step are more important (because they have higher relevance to the context generated by reasoning of the large language model after parameter modification). The candidate that is closest and contains new knowledge is selected as the selected reasoning step, thereby improving the reasoning depth.
[0076] S33. Use the new large language model as a verifier to determine whether the selected reasoning step meets the preset constraint verification conditions: if the selected reasoning step does not meet the constraint verification conditions, it will be discarded. In addition to the selected reasoning step, the reasoning step with the highest cosine similarity and containing new knowledge will be reselected as the suboptimal reasoning step and re-judged until the constraint verification conditions are met; if the selected reasoning step meets the constraint verification conditions, determine whether the reasoning reaches the preset termination conditions (such as reaching the maximum number of times, obtaining an answer that meets the requirements, etc.). If the termination conditions are met, stop the reasoning and obtain the final output result (i.e., the answer to the new question); if the termination conditions are not met, use the output result obtained by the current iteration as the input of the next iteration, and continue the cycle until the termination conditions are met and the final output result (i.e., the answer to the new question) is obtained.
[0077] It should be noted that in step S33 of the present invention, the independence, coherence, rationality, and relevance of the selected reasoning step are subjected to constraint verification. When the selected reasoning step is independent, coherent, rational, and relevant at the same time, it is considered that the reasoning step meets the constraint verification conditions. Specifically, the specific process of determining whether the selected reasoning step meets the preset constraint verification conditions is as follows: the constraint prompt word provides the task requirements and the answer template to the new large language model, wherein the constraint prompt word includes the independence constraint condition, the coherence constraint condition, the rationality constraint condition, and the relevance constraint condition. When the new large language model determines that the selected reasoning step meets the four constraint conditions at the same time, it means that the selected reasoning step meets the constraint verification conditions. Otherwise, it means that the selected reasoning step does not meet the constraint verification conditions. Among them, the independence constraint condition is that each reasoning step is independent of each other; the coherence constraint condition is that there is coherence between two adjacent reasoning steps; the rationality constraint condition is that there is no conflict between the reasoning step and the new knowledge; and the relevance constraint condition is that each reasoning step is related to the original question.
[0078] In order to better demonstrate the specific implementation and technical effects of the present invention, the joint knowledge editing method based on a large language model shown in steps S1 to S3 in the above preferred implementation method is applied to a specific example.
[0079] Example
[0080] The specific implementation process of the joint knowledge editing method based on the large language model adopted in this embodiment is as described above and will not be repeated here.
[0081] This example uses the open-source large-scale model Llama2 and is evaluated on the Popular, MQuAKE-CF, and MQuAKE-T datasets. The accuracy rates achieved are shown in Table 1. In Table 1, the MQuAKE-CF dataset consists of multi-hop questions generated by GPT-3.5-turbo. It is used to test whether the edited language model can correctly answer questions whose answers should change due to edited facts, thereby evaluating the model's ability to reason and update complex knowledge. The MQuAKE-T dataset is similar to the MQuAKE-CF dataset, but it is designed for time-dependent knowledge editing. The data format includes fields such as answer_extended to extend the pre-edited standard answers and mitigate the impact of mismatches between the language model training corpus and the Wikidata dump. MEMIT is a model editing method that edits the knowledge of a pre-trained language model through meta-inductive transfer. SEARC is a search-based model editing method. Fine-tuning is a widely used model editing method that further trains a pre-trained language model on a new specific task or knowledge domain. As shown in Table 1, the method of the present invention can basically reach the current state of the art.
[0082] Table 1. Comparison of the accuracy of the method of the present invention and other methods
[0083] Popular MQuAKE-CF MQuAKE-T This method 12.1 11.9 35.5 MEMIT 4.9 3.8 1,7 Fine Tune 5.2 5.4 17.1 SEARC 3.0 7.9 4.5
[0084] It should also be noted that the joint knowledge editing method based on the large language model in the above embodiment can essentially be executed by a computer program or module. Therefore, similarly, based on the same inventive concept, another preferred embodiment of the present invention also provides a joint knowledge editing system based on a large language model corresponding to the joint knowledge editing method based on the large language model provided in the above embodiment, such as Figure 4 As shown, it includes:
[0085] A parameter editing module is used to perform knowledge editing on the large language model through a model parameter modification method to obtain a large language model with modified parameters;
[0086] The input editing module is used to update the original question through the model input modification method. After the knowledge editing of the large language model with modified parameters, a new question is obtained.
[0087] The result acquisition module is used to take the new question as the input of the large language model with modified parameters, control the reasoning process of the large language model with modified parameters, obtain the answer to the new question and use it as the final output result, thereby completing the joint knowledge editing of the large language model.
[0088] It is understood that the large language model-based joint knowledge editing method described in S1 to S3 above can essentially be implemented via a computer program. Therefore, based on the same inventive concept, another preferred embodiment of the present invention also provides a computer program product corresponding to the large language model-based joint knowledge editing method provided in the above embodiment, which includes a computer program / instructions. When executed by a processor, the computer program / instructions can implement the large language model-based joint knowledge editing method described in the above embodiment.
[0089] Similarly, based on the same inventive concept, another preferred embodiment of the present invention also provides a computer electronic device corresponding to the joint knowledge editing method based on the large language model provided in the above embodiment, such as Figure 5 As shown, it includes a memory and a processor;
[0090] The memory is used to store computer programs;
[0091] The processor is configured to implement the large language model-based joint knowledge editing method in the above embodiment when executing the computer program.
[0092] Furthermore, the logic instructions in the aforementioned memory can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the portion that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions for causing a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the method described in each embodiment of the present invention.
[0093] Therefore, based on the same inventive concept, another preferred embodiment of the present invention also provides a computer-readable storage medium corresponding to the joint knowledge editing method based on the large language model provided in the above embodiment, and the storage medium stores a computer program. When the computer program is executed by the processor, it can implement the joint knowledge editing method based on the large language model in the above embodiment.
[0094] It is understood that the storage medium may include random access memory (RAM) or non-volatile memory (NVM), such as at least one disk storage device. Furthermore, the storage medium may be any medium capable of storing program code, such as a USB flash drive, a mobile hard drive, a magnetic disk, or an optical disk.
[0095] It is understandable that the above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, and discrete hardware components.
[0096] It should also be noted that those skilled in the art can clearly understand that for the convenience and brevity of description, the specific working process of the system described above can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here. In the various embodiments provided in this application, the division of steps or modules in the system and method is only a logical function division. In actual implementation, there may be other division methods, for example, multiple modules or steps can be combined or integrated together, and a module or step can also be split.
[0097] The embodiment described above is merely a preferred embodiment of the present invention and is not intended to limit the present invention. Persons skilled in the art may make various changes and modifications without departing from the spirit and scope of the present invention. Therefore, any technical solution obtained by equivalent substitution or equivalent transformation falls within the scope of protection of the present invention.
Claims
1. A joint knowledge editing method based on a large language model, characterized in that: The following steps are involved: S1. Use the model parameter modification method to perform knowledge editing on the large language model to obtain the large language model after parameter modification; S2. Use the model input modification method to update the original question, and edit the knowledge of the large language model after parameter modification to obtain a new question; S3. Use the new question as the input of the large language model with modified parameters, control the reasoning process of the large language model with modified parameters, obtain the answer to the new question and use it as the final output result, and complete the joint knowledge editing of the large language model.
2. A joint knowledge editing method based on a large language model as claimed in claim 1, characterized in that: In step S1, the specific processing process of knowledge editing of the large language model by the model parameter modification method is as follows: obtain the gradients and inputs of each layer from the parameters of the large language model to be edited, obtain a trained multi-layer editing network, splice the input of the lth layer of the large language model to be edited and the l+1th layer gradient as the input of the editing network, after being processed by the editing network, obtain the editing weight and calculate it with the weight of the lth layer of the large language model to be edited to obtain the edited weight, and use the edited weight as the new weight of the lth layer of the large language model to be edited, until all layers of the large language model to be edited are processed by the editing network to obtain new weights, thereby obtaining the large language model with modified parameters.
3. A joint knowledge editing method based on a large language model as claimed in claim 2, characterized in that: The editing network adopts a two-layer structure. In the editing network, the specific processing process is as follows: The input of the lth layer of the large language model to be edited and the gradient of the l+1th layer are concatenated as the input of the editing network, and the first layer of the editing network processes the input to obtain a first intermediate result; The first intermediate result is input into the second layer of the editing network, and after being processed by the second layer of the editing network, the editing weight is obtained.
4. A joint knowledge editing method based on a large language model as claimed in claim 1, characterized in that: In step S2, the specific processing process of performing knowledge editing on the large language model after parameter modification by the model input modification method is as follows: S21. Obtain the original knowledge graph, convert the facts to be edited into edit knowledge triples with the help of the new large language model, and use the edit knowledge triples to update the original knowledge graph to obtain an updated knowledge graph; S22. For a given original question, use the new large language model to extract the relationship chain between the question-containing entities and their connections with other unknown entities in the updated knowledge graph; S23, obtaining a pre-built original answer template, filling the relationship chain into the original answer template, and after filling, converting the relationship chain into a query list, and using the query list to search the updated knowledge graph, and outputting the n entities in the updated knowledge graph with the highest cosine similarity to the original question; S24. Add the n entities with the highest cosine similarity to the original question to obtain a new question.
5. A joint knowledge editing method based on a large language model as claimed in claim 4, characterized in that: In step S3, the specific process of obtaining the answer to the new question is: S31. In each iteration of the reasoning process, the updated knowledge graph is retrieved, and the N entities with the highest cosine similarity with the input used in each iteration are obtained as N reasoning steps. The large language model with modified parameters generates 1 reasoning step with a temperature of 0, and the generated N+1 reasoning steps are used as reasoning step candidates. S32, selecting the reasoning step with the highest cosine similarity and containing new knowledge from the reasoning step candidates as the selected reasoning step; S33, using the new large language model as a verifier, judging whether the selected reasoning step satisfies the preset constraint verification condition: if the selected reasoning step does not satisfy the constraint verification condition, it is discarded, and in addition to the selected reasoning step, the reasoning step with the highest cosine similarity and containing new knowledge is reselected as the suboptimal reasoning step and re-judged until the constraint verification condition is satisfied; if the selected reasoning step satisfies the constraint verification condition, judging whether the reasoning reaches the preset termination condition, if the termination condition is satisfied, the reasoning is stopped and the answer to the new question is obtained; If the termination condition is not met, the output result of the current iteration will be used as the input of the next iteration, and the cycle will continue until the termination condition is met and the answer to the new question is obtained.
6. A joint knowledge editing method based on a large language model as claimed in claim 5, characterized in that: The specific process of judging whether the selected reasoning step satisfies the preset constraint verification condition is as follows: the constraint prompt words provide the task requirements and the answer template to the new large language model, wherein the constraint prompt words include independence constraint conditions, coherence constraint conditions, rationality constraint conditions and relevance constraint conditions. When the new large language model judges that the selected reasoning step satisfies the four constraint conditions at the same time, it means that the selected reasoning step satisfies the constraint verification condition, otherwise, it means that the selected reasoning step does not satisfy the constraint verification condition; wherein, the independence constraint condition is that each reasoning step is independent of each other; the coherence constraint condition is that there is coherence between two adjacent reasoning steps; the rationality constraint condition is that there is no conflict between the reasoning step and the new knowledge; the relevance constraint condition is that each reasoning step is related to the original question.
7. A joint knowledge editing system based on a large language model, characterized in that: The following steps are involved: A parameter editing module is used to perform knowledge editing on the large language model through a model parameter modification method to obtain a large language model after parameter modification; The input editing module is used to update the original question through the model input modification method, and obtain the new question after the knowledge editing of the large language model with modified parameters; The result acquisition module is used to take the new question as the input of the large language model with modified parameters, control the reasoning process of the large language model with modified parameters, obtain the answer to the new question and use it as the final output result, thereby completing the joint knowledge editing of the large language model.
8. A computer program product comprising a computer program / instructions, characterized in that When the computer program / instruction is executed by a processor, it can implement the joint knowledge editing method based on a large language model as described in any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that: The storage medium stores a computer program, and when the computer program is executed by the processor, the joint knowledge editing method based on the large language model as described in any one of claims 1 to 6 is implemented.
10. A computer electronic device, characterized in that: including memory and processor; The memory is used to store computer programs; The processor is used to implement the joint knowledge editing method based on a large language model as described in any one of claims 1 to 6 when executing the computer program.
Citation Information
Cited By
Inference method, system and equipment of wide constraint large language model and medium
CN121146067A