Method and device for editing knowledge of generative language model based on time sequence knowledge graph and medium
Patent Information
- Application Number
- CN202410656184.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-24
- Publication Date
- 2026-10-09
- Estimated Expiration
- 2044-05-24
AI Technical Summary
但是上述方案均是使用新的知识来直接替换语言模型内部过时的知识,缺乏将过时的知识保存为历史事实的能力,导致在连续多次编辑的场景下仍然会产生知识遗忘问题
与现有技术相比,本发明的优点在于:本发明通过为历史时期的事实知识构建对应的静态知识图谱,将各时期的静态知识图谱关联形成时序知识图谱,以将历次编辑的事实知识以时序知识图谱的形式存储在外部知识库中,然后通过分析用户查询中的时间节点检索大模型内部对应时期的事实知识,依据用户查询中的时间节点与大模型内部的时间节点之间的关系控制生成查询的回复,在查询中的时间节点晚于大模型内部的时间节点时,先从时序知识图谱中检索对应时间节点的知识图谱信息,利用检索到的知识图谱信息调用大模型生成查询的回复,能够基于建立的外部知识库利用上下文学习的短期记忆技术对大型语言模型进行知识编辑,使得能够适用于知识不断更新的场景下,高效、准确地实现对大型语言模型中知识的批量编辑,同时还能够避免传统方法在连续多次编辑的情况下知识灾难性遗忘的问题。
Smart Images

Figure CN118484513B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of natural language processing technology, and in particular to a generative language model knowledge editing method, device, and medium based on temporal knowledge graphs. Background Technology
[0002] Language models can be pre-trained on large-scale unlabeled data, thus large language models exhibit significant performance in text understanding and text generation. Language models can not only model lexical, grammatical, and semantic knowledge in human language, but also learn various facts and common sense. However, as time progresses, the continuous development of the real world constantly generates new facts and updates outdated knowledge. Therefore, pre-trained language models may suffer from knowledge gaps or obsolescence. How to accurately and effectively inject specific new factual and common sense knowledge into language models during their use is a pressing problem that needs to be solved.
[0003] Modifying or adding internal knowledge within a language model is typically achieved through fine-tuning, such as injecting new knowledge and correcting old knowledge by constraining the fine-tuning objective. However, due to the massive number of parameters in large language models, fine-tuning them not only relies on high-performance hardware but also incurs significant time overhead. Furthermore, fine-tuning for specific knowledge can easily lead to overfitting of the language model, making it difficult to guarantee both reliability and generalization / locality.
[0004] Parameter update schemes using pre-trained language models can address the inherent shortcomings of the fine-tuning paradigm. These schemes can be divided into two categories: parameter prediction and local parameter update. Parameter prediction methods involve designing a small-scale hypernetwork to predict the update amount of pre-trained language model parameters when editing specific knowledge within the model, thereby obtaining the updated model parameters. Local parameter update methods, on the other hand, locate parameters in the model related to specific knowledge and then modify those parameters to achieve the purpose of knowledge editing. However, the above-mentioned parameter update schemes using pre-trained language models are limited to editing one factual knowledge at a time, making it difficult to handle scenarios involving batch knowledge editing. Furthermore, continuous editing of the model can lead to catastrophic forgetting of general knowledge, thus failing to cope with real-world scenarios where knowledge is constantly updated. In addition, they require training with a specific pre-trained language model, lacking generality, and there is still significant room for improvement in the reliability, generalization, and locality of knowledge editing.
[0005] Some practitioners have proposed using additional storage modules to store new knowledge while keeping the parameters of the original pre-trained language model unchanged, in order to guide the model in generating answers containing new knowledge. This approach can be divided into two categories: implicit knowledge storage based on neural networks and explicit knowledge storage based on knowledge bases. The implicit knowledge storage method treats the feedforward neural network layer in the transformer network as a key-value pair memory capable of storing external knowledge, implicitly storing external knowledge by adding extra neurons to the feedforward neural network layer of the pre-trained language model. The explicit knowledge storage method based on knowledge bases stores the knowledge that needs to be updated in memory and uses a domain detector to determine whether the input involves new knowledge. If new knowledge is involved, the input and the factual knowledge in memory are fed into a counterfactual model to output an answer containing the new knowledge; if the input does not involve new knowledge, the original pre-trained language model is used to generate the answer normally. However, both of these approaches directly replace outdated knowledge within the language model with new knowledge, lacking the ability to preserve outdated knowledge as historical facts. This leads to knowledge forgetting problems even in scenarios with multiple consecutive edits. Summary of the Invention
[0006] The technical problem to be solved by this invention is as follows: In view of the technical problems existing in the prior art, this invention provides a generative language model knowledge editing method, device and medium based on temporal knowledge graph, which can efficiently and accurately inject new knowledge into large models in scenarios where knowledge is constantly updated, realize batch and accurate editing of knowledge in large language models, and solve the problems of traditional methods being difficult to batch edit knowledge and catastrophic forgetting of knowledge in scenarios of continuous editing.
[0007] A knowledge editing method for generative language models based on temporal knowledge graphs, comprising the following steps: Step 1: Construct a static knowledge graph for the factual knowledge of each period, and link the static knowledge graphs of each period according to the relationship to form a time-series knowledge graph to store the factual knowledge of each period; Step 2: When a user query is received, the first time node is obtained by retrieving the time nodes contained in the user query, and the second time node is obtained by locating the corresponding time node in the large model based on the knowledge in the user query. Step 3: Based on the relationship between the first time node and the second time node, control the generation of the query response. If the first time node is not later than the second time node, control the direct invocation of the large model to generate the query response; otherwise, first retrieve the knowledge graph information of the corresponding time node from the time-series knowledge graph, and use the retrieved knowledge graph information to invoke the large model to generate the query response.
[0008] Furthermore, in step 2, the step of obtaining the first time node from the time nodes contained in the user query includes: Determine whether the user's query includes the display time; If the user query includes a display time, then the included display time is used as the first time node; if the user query does not include a display time, then the time node corresponding to the latest static knowledge graph in the time-series knowledge graph is used as the first time node.
[0009] Furthermore, in step 2, the step of obtaining the second time node based on the corresponding time node in the large model according to the knowledge location in the user query includes: The knowledge K in the user query and each time node in the time-series knowledge graph are combined to form multiple queries about knowledge K, and the generated queries about knowledge K are sent to the large model. The system determines the response of the large model to each query. If the large model cannot answer any query correctly, it is determined that the large model does not have knowledge related to knowledge K, and the second time node in the large model is located as a time before the time sequence knowledge graph. If the large model can answer one of the queries correctly, the time corresponding to the query is determined as the second time node. If the large model can answer multiple queries correctly, the latest time in the queries is taken as the second time node.
[0010] Furthermore, in step 3, the step of retrieving knowledge graph information for the corresponding time node from the temporal knowledge graph and using the retrieved knowledge graph information to call the large model to generate a response to the query includes: Step 3.1. Retrieve the first static knowledge graph corresponding to the first time node from the time-series knowledge graph; Step 3.2. Compare the first static knowledge graph with the second static knowledge graph at the second time node to obtain the updated knowledge at the first time node compared to the second time node and the old knowledge that needs to be removed. Based on the obtained updated knowledge and old knowledge that needs to be removed, construct a knowledge hypergraph. Set the updated knowledge, unupdated knowledge, and old knowledge that needs to be removed on different layers of the knowledge hypergraph and set the corresponding identifier types. Step 3.3. Generate corresponding knowledge descriptions based on the knowledge sets in each layer using the large model. The knowledge descriptions include factual knowledge and identifier types. Identifier types include new identifiers for updated knowledge and removal identifiers for old knowledge that needs to be removed. Generate instructions to call the large model based on the knowledge descriptions with identifier types to obtain a query response containing the currently added factual knowledge and the old knowledge that needs to be removed.
[0011] Furthermore, in step 3.2, the knowledge graph is stored in the form of triples. The intersection S of the triples of the first static knowledge graph and the second static knowledge graph is taken as the unupdated knowledge set KS. The difference of the triples of the intersection S of the first static knowledge graph and the triples is taken as the new knowledge KS'. The difference of the intersection S of the second static knowledge graph and the triples is taken as the old knowledge KS'' to be removed. Each triple in the new knowledge KS' and the old knowledge KS'' to be removed is traversed to obtain the entities contained therein, forming an entity set E containing updated knowledge. All entities in the entity set E are arranged in the first layer. The remaining entities in the first static knowledge graph and the second static knowledge graph are placed in the second layer to construct the knowledge hypergraph.
[0012] Furthermore, the construction of the knowledge hypergraph also includes: using the unupdated knowledge set KS as an edge of the knowledge hypergraph and setting a corresponding layer, updating the corresponding identifier type to remain unchanged, filling the newly added knowledge KS' in the first layer and updating the corresponding identifier type to newly added, filling the old knowledge KS'' that needs to be removed in the first layer and updating the corresponding identifier type to removed.
[0013] Furthermore, step 3.3 includes: using instruction learning to generate a knowledge description based on the knowledge set in the first layer through the large model, and prompting the large model to describe knowledge with the identifier type of "new" as current factual knowledge, and knowledge with the identifier type of "removed" as facts that need to be ignored.
[0014] Furthermore, in step 3, the large model is invoked based on the thought chain prompt method to generate the corresponding response to the user query. If the first time node is not later than the second time node, the large model is directly invoked to generate the query response according to the preset basic prompt template. Otherwise, the knowledge description of the newly added knowledge is combined with the preset basic prompt template to form a new instruction to invoke the large model. The basic prompt template is a template that prompts the large model to generate the required query response. The newly added knowledge is the updated knowledge determined from the time-series knowledge graph based on the first time node T and the second time node T'.
[0015] An electronic device includes a processor and a memory, the memory being used to store a computer program, and the processor being used to execute the computer program to perform the method described above.
[0016] A computer-readable storage medium storing a computer program that, when executed by a processor, implements the method described above.
[0017] To solve the above-mentioned technical problems, the technical solution proposed by this invention is as follows: Compared with existing technologies, the advantages of this invention are as follows: This invention constructs corresponding static knowledge graphs for historical factual knowledge, and associates the static knowledge graphs of each period to form a temporal knowledge graph. This allows the factual knowledge from each editing session to be stored in an external knowledge base in the form of a temporal knowledge graph. Then, by analyzing the time nodes in the user query, the corresponding factual knowledge within the large model is retrieved. The generation of the query response is controlled based on the relationship between the time nodes in the user query and the time nodes within the large model. When the time node in the query is later than the time node within the large model, the knowledge graph information for the corresponding time node is retrieved from the temporal knowledge graph. The retrieved knowledge graph information is then used to call the large model to generate the query response. This allows for knowledge editing of large language models based on the established external knowledge base using short-term memory techniques based on contextual learning. This makes it suitable for scenarios where knowledge is constantly updated, efficiently and accurately achieving batch editing of knowledge in large language models. It also avoids the problem of catastrophic forgetting of knowledge in traditional methods when edited multiple times consecutively. Attached Figure Description
[0018] Figure 1 This is a schematic diagram illustrating the implementation process of the large-scale language model knowledge editing method based on time-series knowledge graphs in this embodiment. Detailed Implementation
[0019] The present invention will be further described below with reference to the accompanying drawings and specific preferred embodiments, but this does not limit the scope of protection of the present invention.
[0020] Knowledge editing, as an emerging natural language processing task, aims to precisely inject specific knowledge into a model. Unlike traditional fine-tuning, knowledge editing typically needs to satisfy the following three properties: 1. Reliability: After knowledge editing, the pre-trained language model should be able to output an answer with the new knowledge for a given query. 2. Generalization: After knowledge editing, the pre-trained language model should be able to output an answer with the new knowledge for different types of queries. 3. Locality: After knowledge editing, the answer output by the pre-trained language model should remain consistent with the answer before editing for queries unrelated to the new knowledge.
[0021] This invention constructs static knowledge graphs corresponding to historical factual knowledge, and then links these static knowledge graphs to form a temporal knowledge graph. This allows the factual knowledge from each editing session to be stored in an external knowledge base in the form of a temporal knowledge graph, creating an explicit external knowledge base. Then, by analyzing the time nodes in the user query, the corresponding factual knowledge within the large model is retrieved. The generation of the query response is controlled based on the relationship between the time nodes in the user query and the time nodes within the large model. When the time node in the query is later than the time node within the large model, the corresponding time node's knowledge graph information is retrieved from the temporal knowledge graph. The retrieved knowledge graph information is then used to call the large model to generate the query response. This fully utilizes the established external knowledge base and short-term memory technology based on contextual learning to edit knowledge in large language models. This makes it suitable for scenarios where knowledge is constantly updated, efficiently and accurately achieving batch editing of knowledge in large language models, while also avoiding the problem of catastrophic forgetting of knowledge in traditional methods with multiple consecutive edits.
[0022] like Figure 1 As shown, the detailed steps of the generative language model knowledge editing method based on temporal knowledge graphs in this embodiment include: Step 1: Construct a static knowledge graph for the factual knowledge of each historical period, and link the static knowledge graphs of each period according to their relationships to form a temporal knowledge graph to store the factual knowledge of each period.
[0023] In the context of multi-hop knowledge question answering, the knowledge to be updated usually has close relationships. This embodiment uses a static knowledge graph to characterize the relationships between factual knowledge. A static knowledge graph is constructed for the factual knowledge of each historical period. The static knowledge graphs of each period are then combined to form a temporal knowledge graph, establishing an explicit external knowledge base. This explicit external knowledge base stores the factual knowledge to be updated for each period, enabling timely updates of knowledge and preservation of historical knowledge during knowledge editing tasks.
[0024] Step 2: When a user query is received, obtain the first time node T by retrieving the time nodes contained in the user query, and locate the corresponding time node in the large model based on the knowledge in the user query to obtain the second time node T'.
[0025] This embodiment first analyzes the user query to determine the time node T contained in the query, and then, based on the knowledge K in the user query, determines the facts related to the knowledge that the large model has already mastered, thereby locating the time node T' within the large model.
[0026] In this embodiment, the step of obtaining the first time node T from the time node contained in the user query includes: Step 2.11. Determine whether the user's query includes the display time; Step 2.12. If the user query includes a display time, then the included display time is taken as the first time node T. If the user query does not include a display time, then the time node corresponding to the latest static knowledge graph in the time-series knowledge graph is taken as the first time node T.
[0027] In a specific application embodiment, the time nodes in the query can be analyzed through instruction learning. Specifically, the explicit time in the query is analyzed first. If the above analysis reveals that there is no explicit time representation in the query, it is assumed that the user is querying the latest state of specific knowledge, and the query time (first time node T) is set to the time node corresponding to the last static knowledge graph in the time-series knowledge graph.
[0028] For a given knowledge K, in order to preserve historical facts in a large language model during multiple consecutive edits, it is first necessary to determine which factual knowledge is already present and which is not within the large model; that is, it is necessary to first determine the time nodes within the large model. For a specific knowledge K, the purpose of knowledge editing in this embodiment is to inject factual knowledge about knowledge K that the large model does not possess. Therefore, it is necessary to first determine the time nodes related to knowledge K within the large model to obtain the second time node T'.
[0029] In this embodiment, the step of obtaining the second time node T' by locating the corresponding time node in the large model based on the knowledge K in the user query includes: Step 2.21. Combine the knowledge K in the user query and each time node in the time-series knowledge graph to form multiple queries about knowledge K, and send each of the formed queries about knowledge K to the large model; Step 2.22. Determine the response of the large model to each query. If the large model cannot answer any query correctly, it is determined that the large model does not have knowledge related to knowledge K, and the second time node in the large model is located as a time before the time sequence knowledge graph. If the large model can answer one of the queries correctly, the time corresponding to the query is determined as the second time node T'. If the large model can answer multiple queries correctly, the latest time in the queries is taken as the second time node T'.
[0030] Specifically, for a specific knowledge K, this embodiment combines each time node T in the temporal knowledge graph and initiates multiple queries about knowledge K to the large model. The second time node T' within the large model is determined based on whether the large model can correctly answer each query. If the large model can correctly answer one of the queries, the time node corresponding to that query is the time node T' within the large model. If the large model can correctly answer multiple queries, the latest time among the queries is taken as the time node T' within the large model.
[0031] In a specific application example, a mind chain-based prompting method can be used to guide the large model to respond to query Q. It is understandable that, in addition to the above-mentioned methods of obtaining time nodes, other methods can also be used to obtain the time nodes contained in the user query and the time nodes within the large model, depending on actual needs.
[0032] Step 3: Based on the relationship between the first time node T and the second time node T', control the generation of the query response. If the first time node T is not later than the second time node T', control the direct invocation of the large model to generate the query response; otherwise, first retrieve the knowledge graph information of the corresponding time node from the time-series knowledge graph, and use the retrieved knowledge graph information to invoke the large model to generate the query response.
[0033] The system determines whether the first time node T' in the query is later than the second time node T within the model. If the first time node T is not later than the second time node T' (i.e., the first time node T is earlier than or equal to the second time node T'), it means that the large model already possesses sufficient internal knowledge to respond to the query. In this case, the large model is directly invoked to generate the corresponding response. Conversely, if the first time node T is later than the second time node T', it means that the large model lacks facts about this knowledge, and the existing knowledge in the large model cannot respond to the user's query. Therefore, before invoking the large model, the corresponding knowledge is retrieved from an external knowledge base composed of a time-series knowledge graph, and the retrieved knowledge graph information is used to invoke the large model to generate the response to the query.
[0034] In this embodiment, when it is determined that the first time node T is later than the second time node T', the corresponding knowledge is retrieved from the external knowledge base composed of the time-series knowledge graph before calling the large model. Then, the retrieved knowledge graph information is used to call the large model to generate a response to the query. The steps include: Step 3.1. Retrieve the first static knowledge graph G corresponding to the first time node T from the temporal knowledge graph.
[0035] The first time node T in the query obtained from step 2 is compared with the time label in the time series knowledge graph, and the corresponding static knowledge graph is obtained as the first static knowledge graph G.
[0036] Step 3.2. Compare the first static knowledge graph G with the second static knowledge graph G' at the second time node T' to obtain the updated knowledge KS' at the first time node T compared to the second time node T' and the old knowledge KS'' that needs to be removed. Construct a knowledge hypergraph based on the obtained updated knowledge KS' and old knowledge KS'' that needs to be removed. Set the updated knowledge KS', the unupdated knowledge KS, and the old knowledge KS'' that needs to be removed on different layers of the knowledge hypergraph and set the corresponding label types.
[0037] This embodiment analyzes the knowledge changes at query time T compared to the model's internal time T' by comparing the first static knowledge graph G with the second static knowledge graph G' corresponding to the model's internal time node by node. Specifically, the knowledge graph is stored in the form of triples. First, the intersection S of the triples of the first static knowledge graph G and the second static knowledge graph G' is taken as the unupdated knowledge set KS. Then, the difference of the triples of the intersection S of the first static knowledge graph G and the second static knowledge graph G' is taken as the newly added knowledge KS', and the difference of the intersection S of the second static knowledge graph G' and the third triples is taken as the old knowledge KS'' to be removed. Then, each triple in the newly added knowledge KS' and the old knowledge KS'' to be removed is traversed, and the entities involved are recorded. Finally, an entity set E involving knowledge updates is formed. Then, a knowledge hypergraph is constructed based on the entity set E. This knowledge hypergraph has update awareness capabilities.
[0038] When constructing the knowledge hypergraph for update awareness, all entities in entity set E are placed in the first layer 1, and the remaining entities in the first static knowledge graph G and the second static knowledge graph G' are placed in the second layer 2. After completing the above-mentioned filtering of update nodes, this embodiment first adds edges to the knowledge hypergraph based on knowledge set KS, with these edges representing unupdated knowledge, and sets the corresponding layers, updating the corresponding identifier type to "unchanged". Specifically, this can be adding layer field "2" and update identifier field "unchanged" to knowledge set KS, which may exist in layer 2 or span both layer 1 and layer 2; for newly added knowledge in set KS', it is completed in the first layer 1, and the corresponding identifier type is updated to "new", that is, layer field "1" and update identifier field "new" are added to the triple; for old knowledge removed in set KS'', it is also completed in the first layer 1, and the corresponding identifier type is updated to "removed", that is, layer field "1" and update identifier field "removed" are added to the triple.
[0039] Step 3.3. Generate corresponding knowledge descriptions based on the knowledge sets in each layer using the large model. The knowledge descriptions include factual knowledge and identifier types. Identifier types include new identifiers for updated knowledge and removal identifiers for old knowledge that needs to be removed. Generate instructions to call the large model based on the knowledge descriptions with identifier types to obtain a query response containing the currently added factual knowledge and the old knowledge that needs to be removed.
[0040] This embodiment utilizes instruction learning to generate a text description based on the knowledge set in the first layer using a large model. The large model is prompted to describe newly added knowledge as current factual knowledge and removed knowledge as facts that need to be ignored. Using the information in the first layer 1 of the updated perceived knowledge hypergraph obtained from the text summary, the difference description text D between the first static knowledge graph G and the second static knowledge graph G' is obtained. Specifically, instruction learning is used to generate a coherent text description based on the knowledge set in the first layer 1 using a large language model; during this process, the large model is prompted to describe knowledge marked "new" as current factual knowledge and removed knowledge as facts that need to be ignored.
[0041] By adopting the method described in this embodiment, not only can new knowledge be injected into the large model and current factual knowledge be obtained through querying, but historical knowledge can also be retained at the same time, without causing the problem of knowledge forgetting.
[0042] For user queries, this embodiment specifically uses a thought chain prompting method to call the large model to generate the corresponding response. If the first time node is not later than the second time node, the control directly calls the large model to generate the query response according to the preset basic prompt template. Otherwise, the knowledge description of the newly added knowledge is combined with the preset basic prompt template to form a new instruction to call the large model. The basic prompt template is a template that prompts the large model to generate the required query response. The newly added knowledge is the updated knowledge KS' determined from the time-series knowledge graph based on the first time node T and the second time node T'.
[0043] This embodiment first analyzes the user query to determine the first time node T contained in the query. Based on the knowledge K in the user query, it determines the facts related to that knowledge that the large model already possesses, thereby locating the second time node T' within the large model. Next, it determines whether the first time node T in the query is later than the second time node T' within the model. If the first time node T is not later than the second time node T', that is, the first time node T is earlier than or equal to the second time node T', it means that the large model's internal knowledge is sufficient to respond to the query. In this case, the large model is directly invoked to generate the corresponding response. Conversely, if the first time node T is later than the second time node T', it means that the existing knowledge in the large model cannot respond to the user query. Before invoking the large model, the corresponding knowledge is retrieved from the external knowledge base composed of the temporal knowledge graph, and a thought chain prompt instruction containing new knowledge is formed. First, the static knowledge graph corresponding to time node T' is retrieved from the temporal knowledge graph. Then, this static knowledge graph is compared with the static knowledge graph at time T, and a knowledge hypergraph with update awareness is constructed. Based on the knowledge hypergraph, an instruction containing new knowledge is formed to invoke the large model.
[0044] This embodiment establishes an explicit external knowledge base by storing the factual knowledge from each editing session in the form of a temporal knowledge graph in an external knowledge base. It retrieves factual knowledge from the corresponding period by analyzing the time nodes in user queries and uses short-term memory technology based on contextual learning to edit knowledge in a large language model. This avoids the problems of traditional methods, such as the difficulty in batch editing knowledge and the catastrophic forgetting of knowledge after multiple editing sessions, thus solving the problem of forgetting historical knowledge in traditional knowledge editing techniques. Furthermore, by inputting new factual knowledge into the model based on instruction learning and using thought chain technology to guide the model in answering multi-hop questions, it can also support the large language model after knowledge editing in answering multi-hop questions.
[0045] This embodiment further provides an electronic device, including a processor and a memory, the memory for storing a computer program, and the processor for executing the computer program to perform the method as described above.
[0046] It is understood that the method described in this embodiment can be executed by a single device, such as a computer or server, or it can be applied to a distributed scenario where multiple devices cooperate to complete the task. In a distributed scenario, one of the multiple devices may execute only one or more steps of the method described in this embodiment, and the multiple devices interact to complete the method. The processor can be implemented using a general-purpose CPU, microprocessor, application-specific integrated circuit, or one or more integrated circuits, and is used to execute relevant programs to implement the method described in this embodiment. The memory can be implemented using read-only memory (ROM), random access memory (RAM), static storage devices, and dynamic storage devices. The memory can store the operating system and other applications. When the method described in this embodiment is implemented through software or firmware, the relevant program code is stored in the memory and called and executed by the processor.
[0047] This embodiment further provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the method described above.
[0048] Those skilled in the art will understand that the above embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-readable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code. This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It should 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, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create a machine for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to operate in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1The functions specified in one or more boxes. These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable apparatus for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0049] The above description is merely a preferred embodiment of the present invention and is not intended to limit the invention in any way. Although the present invention has been disclosed above with reference to preferred embodiments, it is not intended to limit the invention. Therefore, any simple modifications, equivalent changes, and alterations made to the above embodiments based on the technical essence of the present invention without departing from the scope of the present invention should fall within the protection scope of the present invention.
Claims
1. A knowledge editing method for generative language models based on temporal knowledge graphs, characterized by the following steps: include: Step 1: Construct a static knowledge graph for the factual knowledge of each period, and link the static knowledge graphs of each period according to the relationship to form a time-series knowledge graph to store the factual knowledge of each period; Step 2: When a user query is received, the first time node is obtained by retrieving the time nodes contained in the user query, and the second time node is obtained by locating the corresponding time node in the large model based on the knowledge in the user query. Step 3: Based on the relationship between the first time node and the second time node, control the generation of the query response. If the first time node is not later than the second time node, control the direct invocation of the large model to generate the query response; otherwise, first retrieve the knowledge graph information of the corresponding time node from the time-series knowledge graph, and use the retrieved knowledge graph information to invoke the large model to generate the query response. Step 3, which involves retrieving knowledge graph information for the corresponding time node from the temporal knowledge graph and using the retrieved knowledge graph information to call the large model to generate a response to the query, includes the following steps: Step 3.
1. Retrieve the first static knowledge graph corresponding to the first time node from the time-series knowledge graph; Step 3.
2. Compare the first static knowledge graph with the second static knowledge graph at the second time node to obtain the updated knowledge at the first time node compared to the second time node and the old knowledge that needs to be removed. Based on the obtained updated knowledge and old knowledge that needs to be removed, construct a knowledge hypergraph. Set the updated knowledge, unupdated knowledge, and old knowledge that needs to be removed on different layers of the knowledge hypergraph and set the corresponding identifier types. Step 3.
3. Generate corresponding knowledge descriptions based on the knowledge sets in each layer using the large model. The knowledge descriptions include factual knowledge and identifier types. Identifier types include new identifiers for updated knowledge and removal identifiers for old knowledge that needs to be removed. Generate instructions to call the large model based on the knowledge descriptions with identifier types to obtain a query response containing the currently added factual knowledge and the old knowledge that needs to be removed.
2. The knowledge editing method for generative language models based on temporal knowledge graphs according to claim 1, characterized in that, Step 2, the step of obtaining the first time node from the time nodes contained in the user query, includes: Determine whether the user's query includes the display time; If the user query includes a display time, then the included display time is used as the first time node; if the user query does not include a display time, then the time node corresponding to the latest static knowledge graph in the time-series knowledge graph is used as the first time node.
3. The knowledge editing method for generative language models based on temporal knowledge graphs according to claim 1, characterized in that, Step 2, which involves obtaining the second time node based on the corresponding time node in the knowledge location model in the user query, includes the following steps: The knowledge K in the user query and each time node in the time-series knowledge graph are combined to form multiple queries about knowledge K, and the generated queries about knowledge K are sent to the large model. The system determines the response of the large model to each query. If the large model cannot answer any query correctly, it is determined that the large model does not have knowledge related to knowledge K, and the second time node in the large model is located as a time before the time sequence knowledge graph. If the large model can answer one of the queries correctly, the time corresponding to the query is determined as the second time node. If the large model can answer multiple queries correctly, the latest time in the queries is taken as the second time node.
4. The knowledge editing method for generative language models based on temporal knowledge graphs according to claim 1, characterized in that, In step 3.2, the knowledge graph is stored in the form of triples. The intersection S of the triples of the first static knowledge graph and the second static knowledge graph is taken as the unupdated knowledge set KS. The difference of the triples of the intersection S of the first static knowledge graph and the third triple is taken as the new knowledge KS'. The difference of the intersection S of the second static knowledge graph and the third triple is taken as the old knowledge KS'' to be removed. Each triple in the new knowledge KS' and the old knowledge KS'' to be removed is traversed to obtain the entities contained therein, forming an entity set E containing updated knowledge. All entities in the entity set E are arranged in the first layer. The remaining entities in the first static knowledge graph and the second static knowledge graph are placed in the second layer to construct the knowledge hypergraph.
5. The knowledge editing method for generative language models based on temporal knowledge graphs according to claim 4, characterized in that, The process of constructing the knowledge hypergraph also includes: using the unupdated knowledge set KS as an edge of the knowledge hypergraph and setting a corresponding layer, updating the corresponding identifier type to remain unchanged, filling the newly added knowledge KS' in the first layer and updating the corresponding identifier type to newly added, and filling the old knowledge KS'' that needs to be removed in the first layer and updating the corresponding identifier type to removed.
6. The knowledge editing method for generative language models based on temporal knowledge graphs according to claim 5, characterized in that, Step 3.3 includes: using instruction learning to generate a knowledge description based on the knowledge set in the first layer through the large model, and prompting the large model to describe knowledge with the label type of "new" as current factual knowledge, and knowledge with the label type of "removed" as facts that need to be ignored.
7. The generative language model knowledge editing method based on temporal knowledge graphs according to any one of claims 1 to 6, characterized in that, In step 3, the large model is invoked based on the thought chain prompt method to generate the corresponding response to the user query. If the first time node is not later than the second time node, the large model is directly invoked to generate the query response according to the preset basic prompt template. Otherwise, the knowledge description of the newly added knowledge is combined with the preset basic prompt template to form a new instruction to invoke the large model. The basic prompt template is a template that prompts the large model to generate the required query response. The newly added knowledge is the updated knowledge determined from the time-series knowledge graph based on the first time node T and the second time node T'.
8. An electronic device comprising a processor and a memory, the memory being used to store a computer program, characterized in that, The processor is used to execute the computer program to perform the method as described in any one of claims 1 to 7.
9. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by the processor, it implements the method as described in any one of claims 1 to 7.
Citation Information
Patent Citations
Large language model time sequence knowledge question answering method based on sentence granularity prompt
CN117271740A
Intelligent query reasoning method and device based on knowledge graph and large language model collaboration
CN117743531A