Knowledge graph optimization method and knowledge graph reasoning method based on large language model

Through clustering and large language models, the knowledge graph is optimized, and the problem of difficulty in mining the implicit relationships of entities in the existing technology is solved, and more efficient knowledge graph construction and reasoning capabilities are achieved.

CN119443217APending Publication Date: 2025-02-14POWERCHINA HUADONG ENG CORP LTD +1
View PDF 0 Cites 4 Cited by

Patent Information

Application Number
CN202411350720.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-26
Publication Date
2025-02-14

Smart Images

  • Figure CN119443217A_ABST
    Figure CN119443217A_ABST
Patent Text Reader

Abstract

The invention relates to a knowledge graph optimization method based on a large language model. The method is suitable for the field of knowledge graph technology and natural language processing technology. According to the technical scheme, the knowledge graph optimization method based on the large language model is characterized by comprising the steps that entities in a knowledge graph to be optimized are obtained, clustering is carried out based on semantic feature vectors of the entities, and subdivided entity classifications of all the entities are obtained; any two entities belonging to different subdivided entity classifications are subjected to relation description through a large language model, and relation language description between different classification entities is generated; updating the knowledge graph to be optimized on the basis of the generated relational language description among the different classification entities; performing deep reasoning on the updated knowledge graph to further mine and discover implicit relationships among entities in the knowledge graph; and updating the knowledge graph again based on the implicit relationship among the entities to obtain an optimized knowledge graph.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to a knowledge graph optimization method based on a large language model, which is applicable to the fields of knowledge graph technology and natural language processing technology. Background Art

[0002] The knowledge graph represents the relationship between things through the structured representation of entities, relationships, and attributes, and stores and infers knowledge in the form of a graph. It has powerful knowledge representation and reasoning capabilities, can provide highly interpretable results, and demonstrates extremely high knowledge quality in specific fields. The knowledge graph structures and visualizes knowledge information in the nonlinear world, assisting humans in reasoning, prediction, and classification. However, the construction cost of the knowledge graph is generally high, and it is difficult to fully cover knowledge in all fields.

[0003] The construction of knowledge graphs usually includes processes such as data acquisition, knowledge extraction, knowledge fusion, knowledge processing, and knowledge storage. When acquiring data for the construction of knowledge graphs, data from different sources are generally collected and integrated manually or by machine. These data have certain limitations in knowledge due to the limited scope of collection and data. There is no understanding of general knowledge during construction, which leads to the inability to extract relationships that are not clearly shown in the data and the relationships between deep entities. As a result, some implicit relationships between entities in the knowledge graphs constructed by existing technologies cannot be fully and effectively mined, and the knowledge graphs also have poor performance in question-answering in knowledge gaps. In addition, knowledge graphs also have certain difficulties in processing natural languages, and it is difficult to directly deal with complex language phenomena. Summary of the invention

[0004] The technical problem to be solved by the present invention is: to provide a knowledge graph optimization method based on a large language model in response to the above-mentioned problems.

[0005] The technical solution adopted by the present invention is: a knowledge graph optimization method based on a large language model, characterized in that:

[0006] Obtain entities in the knowledge graph to be optimized, cluster them based on their semantic feature vectors, and obtain the subdivided entity classification of each entity;

[0007] Use a large language model to describe the relationship between any two entities belonging to different entity classifications, and generate a language description of the relationship between entities of different classifications;

[0008] Based on the generated relationship language description between different classification entities, the knowledge graph to be optimized is updated;

[0009] Perform deep reasoning on the updated knowledge graph to further explore and discover the implicit relationships between entities in the knowledge graph;

[0010] Based on the implicit relationship between entities, the knowledge graph is updated again to obtain an optimized knowledge graph.

[0011] In the technical solution provided by the present invention, the entities in the knowledge graph are clustered to obtain the classification categories of the entities, and the powerful semantic understanding and generalization capabilities of the large language model are used to analyze the potential relationships between entities of each category. Then, the relationship description output by the large language model is used as a relationship entity and added to the knowledge graph as a virtual node to further mine and discover the implicit relationships between the entities in the knowledge graph, thereby optimizing the knowledge graph so as to be able to mine and improve the knowledge graph entity relationships and complete the knowledge graph.

[0012] As a preferred solution, the process of obtaining entities in the knowledge graph to be optimized and clustering the entities based on their semantic feature vectors to obtain detailed entity classifications of each entity includes:

[0013] Obtain entities in the knowledge graph to be optimized;

[0014] Extract the semantic feature vector of each entity in the knowledge graph to be optimized through the text feature extractor;

[0015] The entity semantic feature vectors are clustered using the k-means algorithm to obtain the subdivided entity classification of each entity.

[0016] As a preferred solution, the method of using a large language model to describe the relationship between any two entities belonging to different entity classifications to generate a language description of the relationship between entities of different classifications includes:

[0017] Extract entity 1 and entity 2 from the knowledge graph to be optimized, and take the entity, relationship and attribute value to form a triple, where entity 1 belongs to subdivided entity category 1 and entity 2 belongs to subdivided entity category 2;

[0018] The triples are sent to the large language model, and the large language model is used to obtain the language description of the relationship between entity 1 and entity 2.

[0019] As a preferred solution, the updating of the knowledge graph to be optimized based on the generated relationship language description between entities of different classifications includes:

[0020] Extract the relationship between entities from the generated relationship language description between entities of different classifications as virtual nodes and add them to the knowledge graph;

[0021] All entities of different entity categories are connected through relationship edges, and the weights of the relationship edges are determined based on the semantic feature vector using a hybrid similarity weight calculation method.

[0022] As a preferred solution, all entities of different entity subdivision categories are connected through relationship edges, and the relationship edge weights are determined based on the semantic feature vectors using a hybrid similarity weight calculation method, including:

[0023] The cosine similarity, jaccard similarity, and Euclidean distance of the semantic feature vectors between entities are calculated, and then the weighted average is taken as the weight of the relationship edge between the entities.

[0024] A knowledge graph optimization system based on large language model enhancement, characterized by:

[0025] The entity classification module is used to obtain entities in the knowledge graph to be optimized, cluster them based on the semantic feature vectors of the entities, and obtain the subdivided entity classification of each entity;

[0026] A relationship description module is used to describe the relationship between any two entities belonging to different subdivided entity categories through a large language model, and generate a relationship language description between entities of different categories;

[0027] A graph updating module, used to update the knowledge graph to be optimized based on the generated relationship language description between different classification entities;

[0028] The deep reasoning module is used to perform deep reasoning on the updated knowledge graph to further explore and discover the implicit relationships between entities in the knowledge graph;

[0029] The secondary update module is used to update the knowledge graph again based on the implicit relationship between entities to obtain an optimized knowledge graph.

[0030] A knowledge graph reasoning method, characterized by comprising:

[0031] Get user questions;

[0032] Based on the user question, extracting a reasoning path from the knowledge graph optimized by the optimization method;

[0033] The extracted reasoning path is input into the large language model and the knowledge graph reasoning result is output.

[0034] A knowledge graph reasoning method, characterized by comprising:

[0035] Get user questions;

[0036] Based on the user question, extracting a reasoning path from the knowledge graph optimized by the optimization method;

[0037] Based on user questions, use knowledge retrieval RAG to obtain context-related knowledge of user questions;

[0038] The extracted reasoning path and context-related knowledge of user questions are input into the large language model, and the knowledge graph reasoning results are output.

[0039] The present invention utilizes knowledge retrieval RAG and a large language model to improve and optimize the output results of the knowledge graph during knowledge graph reasoning, thereby allowing the knowledge graph to achieve a better effect.

[0040] A storage medium stores a computer program executable by a processor, wherein the computer program implements the steps of the method when executed.

[0041] An electronic device comprises a memory and a processor, wherein the memory stores a computer program executable by the processor, and is characterized in that the steps of the method are implemented when the computer program is executed.

[0042] The beneficial effects of the present invention are: the present invention generates a large number of relationship language descriptions between entities of different classifications through a large language model, adds virtual nodes of relationship entities to optimize the knowledge graph, can mine and improve the knowledge graph entity relationships and complete the knowledge graph, achieve better knowledge graph construction, and enhance the reasoning ability of the knowledge graph. BRIEF DESCRIPTION OF THE DRAWINGS

[0043] Figure 1 This is a flow chart of Example 1.

[0044] Figure 2 This is a flow chart of Example 6. DETAILED DESCRIPTION

[0045] The technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all the embodiments. The components of the embodiments of the present invention generally described and shown in the drawings here can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present invention provided in the drawings is not intended to limit the scope of the claimed invention, but merely represents the selected embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without making creative work belong to the scope of protection of the present invention.

[0046] The terms "including" and "having" and any variations thereof in this application are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device comprising a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units not listed, or may optionally include other steps or units inherent to these processes, methods, products or devices.

[0047] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.

[0048] Example 1: Figure 1 As shown, the knowledge graph optimization method based on the large language model in this embodiment specifically includes the following steps:

[0049] S1. Obtain entities in the knowledge graph to be optimized, cluster them based on the semantic feature vectors of the entities, and obtain the subdivided entity classification of each entity.

[0050] S1-1. Obtain structured knowledge in the knowledge graph, then extract entities in the knowledge graph, and use the open source knowledge graph extraction and construction tool DeepKE to extract entities, relationships, and attributes from the knowledge graph.

[0051] S1-2, extract the semantic feature vector of each entity in the knowledge graph to be optimized through the text feature extractor. Since entities are generally text, it is not convenient to perform cluster analysis. In this embodiment, the semantic feature vector of the entity in the knowledge graph is obtained through the clip text encoder. Other text feature extractors can replace the clip text encoder here.

[0052] S1-3. Cluster the entity semantic feature vectors using the k-means algorithm to obtain the subdivided entity classification of each entity.

[0053] In this example, the specific number of categories can be obtained by taking an empirical value through the entity categories in the knowledge graph or by gradually iterating the algorithm to a stable category, but the algorithm iteration will take a long time to stabilize.

[0054] S2. Use a large language model to describe the relationship between any two entities belonging to different entity classifications, and generate a language description of the relationship between entities of different classifications.

[0055] Based on the entities and corresponding classification categories of the knowledge graph obtained in step S1, entity 1 is randomly extracted from subdivided entity classification 1, and entity 2 is randomly extracted from subdivided entity classification 2. Subdivided entity classifications 1 and 2 are both classification categories obtained in step S1, and subdivided entity classification 1 is different from subdivided entity classification 2.

[0056] Based on entity 1 and entity 2, take the entity, relationship and attribute value to form a triple, "entity 1 + attribute, entity 2 + attribute, relationship between entity 1 and entity 2", where the relationship between entity 1 and entity 2 is filled in if there is a relationship in the knowledge graph, otherwise it is left blank.

[0057] In this embodiment, the triple formed by entity 1 and entity 2 is sent to the large language model through the Prompt instruction, so as to use the general knowledge of the large language model to obtain a deep relationship description between the two.

[0058] The construction template of the relational prompt instruction in this example is as follows:

[0059] “

[0060] You are a knowledge graph expert. Please conduct in-depth mining of the relationships between entities in the following knowledge graph to facilitate knowledge graph reasoning. If there is no substantial relationship between the corresponding entities, it can be described as no relationship.

[0061] The entity description is as follows: "Entity 1 + attributes, entity 2 + attributes, entity 1 and entity 2 relationship" (replace with the real entity value when used)

[0062] Could you please answer the relationship between entities?

[0063] ”

[0064] In this embodiment, an exhaustive method is used to obtain at least one relationship description between any two entities belonging to different subdivided entity categories in the knowledge graph.

[0065] S3. Based on the generated relationship language description between entities of different classifications, the knowledge graph to be optimized is updated.

[0066] S3-1. Use the relationship language description between each classification entity as a new virtual node relationship entity, extract the relationship between each entity, and add it to the knowledge graph as a virtual node.

[0067] S3-2. All entities in the classification are connected through relationship edges, and non-1 weights are used to identify the relationships between nodes. The weights are calculated using a mixed similarity weight method.

[0068] In this embodiment, the relationship description between each entity of each category is added to the knowledge graph as a new relationship entity. The two entities generating the relationship description are connected on the left and right sides of the relationship entity respectively, and are connected by relationship edges. The weight of the edge is calculated by the similarity of the semantic feature vectors of the entity text to identify the strength of the relationship between the relationship entity and the connected entity.

[0069] The mixed similarity weight calculation method in this embodiment includes the following steps:

[0070] ①. Extract feature vectors from the text description of entities obtained from the knowledge graph through the clip model to extract semantic feature vector information;

[0071] ②, through the semantic feature vector information of the text of the two entity nodes, calculate the cosine similarity, jaccard similarity, and Euclidean distance of the node text, and then calculate the weighted average as the relationship edge weight;

[0072] The cosine similarity of feature vectors is to evaluate their similarity by calculating the cosine value of the angle between two vectors. The calculation is as follows: Assuming two feature vectors A = (A1, A2, ..., An), B = (B1, B2, ..., Bn), according to the dot product formula:

[0073]

[0074] The Jaccard similarity coefficient is used to compare the similarities and differences between finite sample sets. Its similarity formula is defined as

[0075]

[0076] The similarity formula of Euclidean distance is defined as

[0077]

[0078] Mixed similarity weight calculation:

[0079]

[0080] S4. Perform deep reasoning on the updated knowledge graph to further explore and discover the implicit relationships between entities in the knowledge graph.

[0081] After completing the update of all nodes in the knowledge graph in step S3, logical reasoning is performed based on graph neural networks and the existing knowledge in the knowledge graph to further explore and discover the implicit relationships between entities in the knowledge graph. For example, if the knowledge graph indicates "A is the father of B" and "B is the father of C", through reasoning, it can be concluded that "A is the grandfather of C".

[0082] S5. Based on the implicit relationship between entities, the knowledge graph is updated again to obtain an optimized knowledge graph.

[0083] This embodiment clusters the entities in the knowledge graph to obtain the categories of the entities, uses the powerful semantic understanding and generalization capabilities of the large language model to analyze the potential relationships between entities of each category, and then adds the relationship description output by the large language model as a relationship entity to the knowledge graph. However, during reasoning, it is added to the graph neural network as a virtual node, and the similarity of the semantic feature vectors between entities is used as the weight between the entity relationships to improve the existing knowledge graph. Through knowledge reasoning, more knowledge is mined to update the knowledge graph, thereby obtaining a better knowledge graph.

[0084] Embodiment 2: This embodiment is a knowledge graph optimization system based on large language model enhancement, including an entity classification module, a relationship description module, a graph update module, a deep reasoning module and a secondary update module, etc.

[0085] In this example, the entity classification module is used to obtain entities in the knowledge graph to be optimized, cluster them based on the semantic feature vectors of the entities, and obtain the detailed entity classification of each entity.

[0086] In this embodiment, the relationship description module is used to describe the relationship between any two entities belonging to different subdivided entity categories through a large language model, and generate a relationship language description between entities of different categories.

[0087] The graph updating module is used to update the knowledge graph to be optimized based on the generated relationship language description between different classification entities.

[0088] The deep reasoning module is used to perform deep reasoning on the updated knowledge graph to further explore and discover the implicit relationships between entities in the knowledge graph.

[0089] In this embodiment, the secondary update module is used to update the knowledge graph again based on the implicit relationship between entities to obtain an optimized knowledge graph.

[0090] Embodiment 3: This embodiment is a storage medium on which a computer program that can be executed by a processor is stored. When the computer program is executed, the steps of the knowledge graph optimization method based on a large language model in Embodiment 1 are implemented.

[0091] Embodiment 4: This embodiment is an electronic device having a memory and a processor. The memory stores a computer program that can be executed by the processor. When the computer program is executed, the steps of the knowledge graph optimization method based on a large language model in Embodiment 1 are implemented.

[0092] Example 5: Figure 2 As shown, this embodiment is a knowledge graph reasoning method, which specifically includes the following steps:

[0093] A. Get user questions.

[0094] B. Based on the user question, the corresponding knowledge graph is retrieved through the graph neural network to extract the reasoning path. The knowledge graph is optimized by the knowledge graph optimization method based on the large language model in Example 1.

[0095] The shortest path connecting question knowledge entities and answer candidates in the knowledge graph is extracted through graph neural network.

[0096] C. Input the reasoning path extracted in step B into the large language model and output the knowledge graph reasoning result.

[0097] Example 6: Figure 2 As shown, this embodiment is a knowledge graph reasoning method, which specifically includes the following steps:

[0098] a. Obtain user questions;

[0099] b. Based on the user question, the corresponding knowledge graph is retrieved through the graph neural network to extract the reasoning path. The knowledge graph is optimized by the knowledge graph optimization method based on the large language model in Example 1.

[0100] c. Based on user questions, use knowledge retrieval RAG to obtain context-related knowledge of user questions.

[0101] d. Input the reasoning path extracted in step b and the user question context-related knowledge obtained in step c into the large language model and output the knowledge graph reasoning result.

[0102] During knowledge graph reasoning, the reasoning path extracted by the graph neural network retrieval knowledge graph is converted into a natural language description and sent to the large language model for reasoning output together with the contextual knowledge obtained by the large model knowledge retrieval, thereby optimizing the output of the knowledge graph.

[0103] RAG is a framework that combines the two stages of retrieval and generation to enhance the capabilities of large language models (LMMs). In the retrieval stage, RAG retrieves highly relevant text snippets from knowledge bases based on the user's input query. These knowledge bases ensure retrieval quality by containing the latest, authoritative, and professional information sources.

[0104] This embodiment optimizes the output results of the knowledge graph by constructing a large model instruction project, and optimizes the reasoning results of the knowledge graph by combining RAG with the general understanding ability of the large language model. The contextual knowledge related to the question is extracted from the vector knowledge base through the text features input by the user, and the relevant knowledge of the knowledge graph reasoning is sent to the large language model.

[0105] The large model instruction project construction template used in this embodiment is as follows:

[0106] “

[0107] Assuming that you are an expert in knowledge graph reasoning, please optimize the reasoning results of the following knowledge graph, and combine the retrieved context information to improve the answers of the knowledge graph reasoning results and give better, more reasonable and natural answers:

[0108] User question: "Excuse me, ******?" (real question)

[0109] Reasoning path of knowledge graph:

[0110] "Entity 1 -> Entity 2 -> Entity 3 -> Relationship 4..." (replace with the actual reasoning path when used)

[0111] RAG retrieved context: "*****" (retrieved context knowledge)

[0112] Please combine the above information and the reasoning basis of the knowledge graph to give a more comprehensive and reasonable answer?

[0113] ”

[0114] Embodiment 7: This embodiment is a storage medium on which a computer program that can be executed by a processor is stored. When the computer program is executed, the steps of the knowledge graph reasoning method in Embodiment 5 or 6 are implemented.

[0115] Embodiment 8: This embodiment is an electronic device having a memory and a processor. The memory stores a computer program that can be executed by the processor. When the computer program is executed, the steps of the knowledge graph reasoning method in Embodiment 5 or 6 are implemented.

[0116] The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any person skilled in the art can easily think of changes or substitutions within the technical scope disclosed by the present invention, which should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention should be based on the protection scope of the claims.

Claims

1. A knowledge graph optimization method based on a large language model, characterized by: Obtain entities in the knowledge graph to be optimized, cluster them based on the semantic feature vectors of the entities, and obtain the subdivided entity classification of each entity; Use a large language model to describe the relationship between any two entities belonging to different entity classifications, and generate a language description of the relationship between entities of different classifications; Based on the generated relationship language description between different classification entities, the knowledge graph to be optimized is updated; Perform deep reasoning on the updated knowledge graph to further explore and discover the implicit relationships between entities in the knowledge graph; Based on the implicit relationship between entities, the knowledge graph is updated again to obtain an optimized knowledge graph.

2. The knowledge graph optimization method based on a large language model according to claim 1, characterized in that: The obtaining of entities in the knowledge graph to be optimized, clustering based on the semantic feature vectors of the entities, and obtaining subdivided entity classifications of each entity include: Obtain entities in the knowledge graph to be optimized; Extract the semantic feature vector of each entity in the knowledge graph to be optimized through the text feature extractor; The entity semantic feature vectors are clustered using the k-means algorithm to obtain the subdivided entity classification of each entity.

3. The knowledge graph optimization method based on a large language model according to claim 1, characterized in that: The method of using a large language model to describe the relationship between any two entities belonging to different entity classifications and generating a language description of the relationship between entities of different classifications includes: Extract entity 1 and entity 2 from the knowledge graph to be optimized, and take the entity, relationship and attribute value to form a triple, where entity 1 belongs to subdivided entity category 1 and entity 2 belongs to subdivided entity category 2; The triples are sent to the large language model, and the large language model is used to obtain the language description of the relationship between entity 1 and entity 2.

4. The knowledge graph optimization method based on a large language model according to claim 1, characterized in that: The updating of the knowledge graph to be optimized based on the generated relationship language description between entities of different classifications includes: Extract the relationship between entities from the generated relationship language description between entities of different classifications as virtual nodes and add them to the knowledge graph; All entities of different entity categories are connected through relationship edges, and the weights of the relationship edges are determined based on the semantic feature vector using a hybrid similarity weight calculation method.

5. The knowledge graph optimization method based on a large language model according to claim 4 is characterized in that: The method of connecting all entities of different entity subdivision categories through relationship edges, wherein the relationship edge weights are determined based on the semantic feature vectors by using a hybrid similarity weight calculation method, includes: The cosine similarity, jaccard similarity, and Euclidean distance of the semantic feature vectors between entities are calculated, and then the weighted average is taken as the weight of the relationship edge between the entities.

6. A knowledge graph optimization system based on large language model enhancement, characterized by: The entity classification module is used to obtain entities in the knowledge graph to be optimized, cluster them based on the semantic feature vectors of the entities, and obtain the subdivided entity classification of each entity; A relationship description module is used to describe the relationship between any two entities belonging to different subdivided entity categories through a large language model, and generate a relationship language description between entities of different categories; A graph updating module, used to update the knowledge graph to be optimized based on the generated relationship language description between different classification entities; The deep reasoning module is used to perform deep reasoning on the updated knowledge graph to further explore and discover the implicit relationships between entities in the knowledge graph; The secondary update module is used to update the knowledge graph again based on the implicit relationship between entities to obtain an optimized knowledge graph.

7. A knowledge graph reasoning method, characterized in that: include: Get user questions; Based on the user question, extracting a reasoning path from the knowledge graph optimized by the optimization method described in any one of claims 1 to 5; The extracted reasoning path is input into the large language model and the knowledge graph reasoning result is output.

8. A knowledge graph reasoning method, characterized in that: include: Get user questions; Based on the user question, extracting a reasoning path from the knowledge graph optimized by the optimization method described in any one of claims 1 to 5; Based on user questions, use knowledge retrieval RAG to obtain context-related knowledge of user questions; The extracted reasoning path and context-related knowledge of user questions are input into the large language model, and the knowledge graph reasoning results are output.

9. A storage medium having stored thereon a computer program executable by a processor, characterized in that: When the computer program is executed, the steps of the method described in any one of claims 1 to 5, 7 and 8 are implemented.

10. An electronic device comprising a memory and a processor, wherein the memory stores a computer program executable by the processor, wherein: When the computer program is executed, the steps of the method described in any one of claims 1 to 5, 7 and 8 are implemented.

Citation Information

Cited By

  • Intelligent knowledge architecture graph construction method and system based on large model

    CN120144790A

  • Inference method, system and equipment of wide constraint large language model and medium

    CN121146067A

  • Knowledge graph automatic construction system assisted by large language model

    CN121562762A

  • An automated knowledge graph construction system assisted by a large language model

    CN121562762B