A knowledge graph completion method, device and medium based on large model enhancement
By combining the fine-tuning technology of graph neural network and large model, the problem of low information utilization efficiency in the knowledge graph completion task is solved, and the efficient completion and accuracy of the knowledge graph are achieved, providing a solid foundation for complex knowledge reasoning tasks.
Patent Information
- Application Number
- CN202411945667.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-27
- Publication Date
- 2025-04-04
AI Technical Summary
It is difficult for the prior art to effectively utilize existing information in the knowledge graph completion task, and the inference method of large models is difficult to apply to specific downstream tasks, which easily leads to inaccurate inference results.
The knowledge graph completion method based on large-model enhancement is adopted, combined with the fine-tuning technology of graph neural networks and large-models, and through entity recognition, relationship extraction, graph neural network embedding and large-model training, the completion efficiency and accuracy of knowledge graphs are improved.
It significantly improves the completion efficiency and accuracy of the knowledge graph, provides a solid foundation for complex knowledge inference tasks, and enhances the ability of large models to distinguish graph structures.
Smart Images

Figure CN119761483A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of knowledge engineering technology, and in particular to a knowledge picture completion method, device and medium based on large model enhancement. Background Art
[0002] Knowledge graph is a structured information representation method used to describe entities and their relationships in the real world. Knowledge graph plays an indispensable role in many vertical fields. For example, in the medical field, knowledge graph is used for disease diagnosis, drug development and health management, and provides support for medical decision-making by integrating multi-source heterogeneous data; in the financial industry, it is widely used in risk control and anti-fraud detection, helping institutions identify potential risks and optimize business processes; in the education field, by building subject knowledge networks, knowledge graph provides a technical basis for personalized learning and intelligent tutoring. However, with the rapid growth of data volume, missing links often appear in knowledge graphs, resulting in incomplete and one-sided knowledge. The knowledge graph completion task aims to predict these missing links, including missing head entities, relationships and tail entities. However, this task faces many challenges, especially in how to effectively use existing information for completion. Although large models have shown powerful capabilities in many aspects, the existing large model reasoning methods are difficult to apply to specific downstream tasks. At the same time, the potential "hallucination" effect of large models increases the complexity of their application, which easily leads to inaccurate reasoning results. Summary of the invention
[0003] The technical problem to be solved by the present invention is to provide a knowledge graph completion method, device and medium based on large model enhancement, which combines the fine-tuning technology of graph neural network and large model, not only improves the completion efficiency of knowledge graph, but also provides a solid foundation for more complex knowledge reasoning tasks in the future.
[0004] In order to solve the technical problem, the technical solution adopted by the present invention is: a knowledge graph completion method based on large model enhancement, comprising the following steps: S01. Build a knowledge graph KG=(E,R,S) by performing entity recognition and relationship extraction on knowledge. Knowledge refers to the related knowledge in question-answering system and semantic search. Entity refers to the text data obtained from natural language text using named entity recognition tools. E is the entity set, R is the relationship set, and S is the triple set in the knowledge graph, which is also the positive sample set. The negative sample set is generated by randomly replacing the head entity or the tail entity. ; S02. Obtain the initial entity embedding representation of the knowledge graph and relation embedding representation ; S03. Embed the initial entity into a representation and relation embedding representation Input the graph neural network. In each layer of the graph neural network, for each entity, feature information is collected from its neighborhood entity set, and the embedding representation of the neighborhood entity is aggregated through the message passing mechanism to obtain the entity embedding representation after the graph neural network is embedded. and relation embedding representation ; S04. Train the big model by judging the truth or falsehood of a given triple. The process is: input the embedding representation output by the graph neural network into the big model, freeze the embedding vector of the knowledge graph during the training process, and combine graph embedding with instruction fine-tuning to improve the model's understanding of different relationships. S05. For a completed triple, first use the trained large model to calculate the output. When the output is false, it is determined that the completed triple is not a correct link. When the output is true, the score of the triple is calculated by the scoring function, and the possibility of the link being a true link is determined based on the score.
[0005] Furthermore, in step S04, the embedded representation output by the graph neural network is mapped to the character encoding space of the large model through an adaptive conversion layer. The conversion process is: in is the activation function, linear is the linear transformation layer that converts the embedded representation output by the graph neural network into a character encoding that is compatible with the large model. is the converted character encoding, They represent the embedding representations of the head entity, relation, and tail entity output by the graph neural network respectively; Through this mapping, the embedded representation of the graph neural network output is integrated into the instruction fine-tuning process, and the output of the large model is: , in It is the string encoding module of the large model itself, and (h, r, t) represents the entity relationship triplet.
[0006] Furthermore, the loss function L2 of the large model is: Where N is the number of samples, is the true label of sample i, which can be 0 or 1. is the predicted probability of the large model for sample i, indicating the probability that the sample belongs to the positive class with label 1; During the training of the large model, the loss function L2 is optimized by comparing the difference between the large model output and the label, so that the large model has a good ability to distinguish positive and negative samples.
[0007] Furthermore, step S03 is specifically as follows: S31. For each node i in the knowledge graph, is the initial vectorized representation of node i, and calculates the attention weight of its neighbor node j : , in represents the attention weight of node i’s neighbor node j, LeakyReLU is the activation function, a is a randomly initialized learnable vector matrix, T represents transposition, Represents the vector To splice; The attention score of each node is normalized by the softmax function to obtain the normalized weight : in Represents the attention weight The normalized value, N(i) is the set of neighbor nodes of node i. The normalized attention coefficient is used to aggregate the node's neighbor information and update the node's embedding representation: , in represents the updated embedding representation of node i, W is the trainable weight matrix, σ is the activation function, repeat the above process to get the node embedding representation after graph neural network embedding and relation embedding representation ; S32. Get the node embedding representation after graph neural network embedding and relation embedding representation After that, the embedding representation of each triple is calculated. , in , , They represent the embedding representations of the head entity, relation, and tail entity in the positive sample triple, respectively. , , , They represent the embedding representations of the head entity, relation, and tail entity in the negative sample triples respectively.
[0008] Furthermore, step S03 also includes: S33, use the loss function L1 to continue to optimize the embedding representation and obtain the optimized entity embedding representation and relation embedding representation ; I Where S is the positive sample set, is a triplet in the positive sample set, is the set of negative samples, is a triplet in the negative sample set, is the score function, is a hyperparameter, is the L1 norm.
[0009] Furthermore, in step S05, the score function is expressed as: , in is the completed triple, is the L1 norm, When the score function ranks in top 3 or top 10, the link is judged to be a real link.
[0010] Furthermore, a negative sample set is generated by randomly replacing the head entity or the tail entity The methods include: A. For each positive sample triple , randomly replace the head entity and select an entity that is not in the positive sample set , generate negative samples ; B. For each positive sample triple , randomly replace the relationship and select a relationship that is not in the positive sample set , generate negative samples ; C. For each positive sample triple , randomly replace the tail entity and select a tail entity that is not in the positive sample set , generate negative samples .
[0011] Furthermore, we use the open source TransE as the initial embedding model of the knowledge graph to obtain its initial entity embedding representation. and relation embedding representation .
[0012] The present invention also discloses a knowledge graph completion device based on large model enhancement, including a processor and a memory storing program instructions, wherein the processor is configured to execute the aforementioned knowledge graph completion method based on large model enhancement when running the program instructions.
[0013] A storage medium stores program instructions, which, when run, execute the aforementioned knowledge graph completion method based on large model enhancement.
[0014] Beneficial effects of the present invention: The present invention integrates a large model to enhance the knowledge graph completion process, making full use of the large model's ability to judge the authenticity of triples, thereby improving the graph completion ability of the graph neural network, and further improving the completion effect and accuracy. This method not only gives full play to the powerful reasoning ability of the large model, but also provides more reliable support for complex knowledge graph completion tasks, and promotes the comprehensive integration and application of knowledge. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] Figure 1 A flowchart of the method is shown in FIG. Figure 2 Schematic diagram of the device described in Example 2. DETAILED DESCRIPTION Example 1 This embodiment discloses a knowledge graph completion method based on large model enhancement, which is mainly aimed at the heating industry question and answer system based on the knowledge graph, and aims to improve the integrity of the graph through the knowledge graph completion technology, thereby enhancing the accuracy and practicality of the question and answer system. The data sources involved in the heating industry are extensive and complex, covering a variety of scenario types, such as heating is not hot, stop, reheating, refund, water leakage, etc. These scenarios construct a complete knowledge graph through several triples (h, r, t) such as (heating is not hot, type, floor heating is not hot), (water leakage, location, living room radiator), etc. Due to the incompleteness of the data and the lag in updating, the knowledge graph may have missing information, which affects the performance of the question and answer system.
[0016] In order to solve this problem, this implementation method proposes a knowledge graph completion technology based on large model enhancement. Specifically, it includes the following steps: first, use existing domain knowledge to build logical rules and generate an initial energy knowledge graph; second, optimize the large model and graph neural network through instruction fine-tuning to mine the potential associations between data; finally, use a deep learning model to analyze the characteristic patterns in massive data to achieve accurate completion of the knowledge graph. The above method can significantly improve the integrity and real-time performance of the knowledge graph, and provide more powerful technical support and reliable guarantee for the question-answering system.
[0017] like Figure 1 As shown, this method is implemented by the following steps: S01. Build a knowledge graph KG=(E,R,S) by performing entity recognition and relationship extraction on knowledge. Knowledge refers to the related knowledge in question-answering system and semantic search. Entity refers to the text data obtained from natural language text using named entity recognition tools. E is the entity set, R is the relationship set, and S is the triple set in the knowledge graph, which is also the positive sample set. The negative sample set is generated by randomly replacing the head entity or the tail entity. .
[0018] For any triple (h, r, t) ∈ S, where h is the head entity, r is the relation, and t is the tail entity, the task of knowledge graph completion is to predict the missing links in the graph, which includes the following three cases: missing head entity (?, r, t); missing relation (h, ?, t); and missing tail entity (h, r, ?).
[0019] In order to improve the accuracy of the large model, it is also necessary to construct a negative sample set. This embodiment generates a negative sample set by randomly replacing the head entity or the tail entity. , specifically including: A. For each positive sample triple , randomly replace the head entity and select an entity that is not in the positive sample set , generate negative samples ; B. For each positive sample triple , randomly replace the relationship and select a relationship that is not in the positive sample set , generate negative samples ; C. For each positive sample triple , randomly replace the tail entity and select a tail entity that is not in the positive sample set , generate negative samples .
[0020] When generating negative samples, ensure that these samples are not included in the positive sample set S, thereby ensuring the effectiveness and accuracy of negative samples.
[0021] S02. Use the open source TransE as the initial embedding model of the knowledge graph to obtain its initial entity embedding representation and relation embedding representation ; , M is the number of entities in the entity set E, and D is the dimension of embedding; , is the number of relations in the relation set R, and D is the dimension of embedding.
[0022] S03. Initial entity embedding representation and relation embedding representation As the input of the graph neural network, it supports subsequent message passing and feature aggregation. In each layer of the graph neural network, for each entity, feature information is collected from its neighborhood entity set, and the embedded representation of the neighborhood entity is aggregated through the message passing mechanism to obtain the entity embedding representation after the graph neural network is embedded. and relation embedding representation .
[0023] Step S03 is specifically as follows: S31. For each node i in the knowledge graph, is the initial vectorized representation of node i, and calculates the attention weight of its neighbor node j : , in represents the attention weight of node i’s neighbor node j, LeakyReLU is the activation function, a is a randomly initialized learnable vector matrix, T represents transposition, Represents the vector To splice; The attention score of each node is normalized by the softmax function to obtain the normalized weight : in Represents the attention weight The normalized value, N(i) is the set of neighbor nodes of node i. The normalized attention coefficient is used to aggregate the node's neighbor information and update the node's embedding representation: , in represents the updated embedding representation of node i, W is the trainable weight matrix, and σ is the activation function. yes Updated node representation. When all nodes are updated, the node representation after graph neural network embedding is obtained. , the relationship is aggregated in the same way, and then the embedded representation of the relationship is obtained .
[0024] S32. Get the node embedding representation after graph neural network embedding and relation embedding representation After that, the embedding representation of each triple is calculated. , in , , They represent the embedding representations of the head entity, relation, and tail entity in the positive sample triple, respectively. , , , They represent the embedding representations of the head entity, relation, and tail entity in the negative sample triples respectively.
[0025] S33, use the loss function L1 to continue to optimize the embedding representation and obtain the optimized entity embedding representation and relation embedding representation ; I Where S is the positive sample set, is a triplet in the positive sample set, is the set of negative samples, is a triplet in the negative sample set, is the score function, is a hyperparameter, is the L1 norm.
[0026] S04. Train the big model by judging the truth or falsehood of a given triple. The process is: input the embedding representation output by the graph neural network into the big model, freeze the embedding vector of the knowledge graph during the training process, and combine graph embedding with instruction fine-tuning to improve the model's understanding of different relationships.
[0027] In this step, the embedded representation output by the graph neural network is mapped to the character encoding space of the large model through the adaptive conversion layer. The conversion process is: in is the activation function, linear is the linear transformation layer that converts the embedded representation output by the graph neural network into a character encoding that is compatible with the large model. is the converted character encoding, They represent the embedding representations of the head entity, relation, and tail entity output by the graph neural network respectively; Through this mapping, the embedded representation of the graph neural network output is integrated into the instruction fine-tuning process, and the output of the large model is: , in It is the string encoding module of the large model itself, and (h, r, t) represents the entity relationship triplet.
[0028] The loss function L2 of the large model is: Where N is the number of samples, is the true label of sample i, which can be 0 or 1. is the predicted probability of the large model for sample i, indicating the probability that the sample belongs to the positive class with label 1; During the training of the large model, the loss function L2 is optimized by comparing the difference between the large model output and the label, so that the large model has a good ability to distinguish positive and negative samples.
[0029] This process not only enhances the model's ability to discriminate graph structures, but also improves the effect of knowledge graph completion. Through instruction fine-tuning, the model can better adapt to complex graph relationships during the learning process, thereby providing more accurate reasoning and judgment capabilities.
[0030] S05. For a given triple, first use the trained large model to calculate the output. When the output is false, it is determined that the given triple is not a correct link. When the output is true, the score of the triple is calculated through the scoring function, and the possibility of the link being a true link is determined based on the score.
[0031] In this step, the expression of the score function is: , in is the completed triple, is the L1 norm, When the score function ranks in top 3 or top 10, the link is judged to be a real link.
[0032] The large-model-based knowledge graph completion method of the present invention effectively solves the challenges faced by traditional methods. Through innovative steps and framework design, it improves the completeness and accuracy of the knowledge graph, and provides new ideas and directions for further research and application.
[0033] Example 2 The present disclosure provides a knowledge graph completion device 300 based on large model enhancement, such as Figure 2 As shown, it includes a processor (processor) 304 and a memory (memory) 301. Optionally, the device may also include a communication interface (Communication Interface) 302 and a bus 303. Among them, the processor 304, the communication interface 302, and the memory 301 can communicate with each other through the bus 303. The communication interface 302 can be used for information transmission. The processor 304 can call the logical instructions in the memory 301 to execute the knowledge spectrum completion method based on large model enhancement of the above embodiment.
[0034] In addition, the logic instructions in the memory 301 described above can be implemented in the form of software functional units and can be stored in a computer-readable storage medium when sold or used as an independent product.
[0035] The memory 301 is a computer-readable storage medium that can be used to store software programs and computer executable programs, such as program instructions / modules corresponding to the method in the embodiment of the present disclosure. The processor 304 executes the function application and data processing by running the program instructions / modules stored in the memory 301, that is, the knowledge spectrum completion method based on large model enhancement in the above embodiment is implemented.
[0036] The memory 301 may include a program storage area and a data storage area, wherein the program storage area may store an operating system and an application required for at least one function; the data storage area may store data created according to the use of the terminal device, etc. In addition, the memory 301 may include a high-speed random access memory and may also include a non-volatile memory.
[0037] Example 3 An embodiment of the present disclosure provides a computer-readable storage medium storing computer-executable instructions, wherein the computer-executable instructions are configured to execute the above-mentioned knowledge spectrum completion method based on large model enhancement.
[0038] The computer-readable storage medium mentioned above may be a transient computer-readable storage medium or a non-transitory computer-readable storage medium.
[0039] The technical solution of the embodiment of the present disclosure can be embodied in the form of a software product, which is stored in a storage medium and includes one or more instructions for enabling a computer device (which may be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the method described in the embodiment of the present disclosure. The aforementioned storage medium may be a non-transient storage medium, including: a USB flash drive, a mobile hard disk, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), a disk or an optical disk, and other media that can store program codes, or a transient storage medium.
[0040] The above description and the accompanying drawings fully illustrate the embodiments of the present disclosure so that those skilled in the art can practice them. Other embodiments may include structural, logical, electrical, process and other changes. The embodiments represent only possible changes. Unless explicitly required, separate components and functions are optional, and the order of operation may vary. The parts and features of some embodiments may be included in or replace the parts and features of other embodiments. Moreover, the words used in this application are only used to describe the embodiments and are not used to limit the scope of protection. As used in the description in the text, unless the context clearly indicates, the singular forms of "a", "an" and "the" are intended to include plural forms as well. Similarly, the term "and / or" as used in this application refers to any and all possible combinations of one or more associated listings. In addition, when used in this application, the term "comprise" and its variants "comprises" and / or comprising refer to the presence of stated features, wholes, steps, operations, elements, and / or components, but do not exclude the presence or addition of one or more other features, wholes, steps, operations, elements, components and / or groups thereof. In the absence of further restrictions, the elements defined by the sentence "including one..." do not exclude the presence of other identical elements in the process, method or device including the elements. In this article, each embodiment may focus on the differences from other embodiments, and the same and similar parts between the embodiments may refer to each other. For the methods, products, etc. disclosed in the embodiments, if they correspond to the method part disclosed in the embodiments, then the relevant parts can refer to the description of the method part.
[0041] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software may depend on the specific application and design constraints of the technical solution. The technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the embodiments of the present disclosure. The technicians may clearly understand that for the convenience and simplicity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments, and will not be repeated here.
Claims
1. A knowledge graph completion method based on large model enhancement, characterized by: The following steps are involved: S01. Build a knowledge graph KG=(E,R,S) by performing entity recognition and relationship extraction on knowledge. Knowledge refers to the related knowledge in question-answering system and semantic search. Entity refers to the text data obtained from natural language text using named entity recognition tools. E is the entity set, R is the relationship set, and S is the triple set in the knowledge graph, which is also the positive sample set. The negative sample set is generated by randomly replacing the head entity or the tail entity. ; S02. Obtain the initial entity embedding representation of the knowledge graph and relation embedding representation ; S03. Embed the initial entity into representation and relation embedding representation Input the graph neural network. In each layer of the graph neural network, for each entity, feature information is collected from its neighborhood entity set, and the embedding representation of the neighborhood entity is aggregated through the message passing mechanism to obtain the entity embedding representation after the graph neural network is embedded. and relation embedding representation ; S04. Train the big model by judging the truth or falsehood of a given triple. The process is: input the embedding representation output by the graph neural network into the big model, freeze the embedding vector of the knowledge graph during the training process, and combine graph embedding with instruction fine-tuning to improve the model's understanding of different relationships. S05. For the determined triples, first use the trained large model to calculate the output. When the output is false, it is determined that the completed triple is not a correct link. When the output is true, the score of the triple is calculated through the scoring function, and the possibility of the link being a true link is determined based on the score.
2. The knowledge graph completion method based on large model enhancement according to claim 1 is characterized in that: In step S04, the embedded representation output by the graph neural network is mapped to the character encoding space of the large model through an adaptive conversion layer. The conversion process is: in is the activation function, linear is the linear transformation layer that converts the embedded representation output by the graph neural network into a character encoding that is compatible with the large model. is the converted character encoding, They represent the embedding representations of the head entity, relation, and tail entity output by the graph neural network respectively; Through this mapping, the embedded representation of the graph neural network output is integrated into the instruction fine-tuning process, and the output of the large model is: , in It is the string encoding module of the large model itself, and (h, r, t) represents the entity relationship triplet.
3. The knowledge graph completion method based on large model enhancement according to claim 2 is characterized in that: The loss function L2 of the large model is: Where N is the number of samples, is the true label of sample i, which can be 0 or 1. is the predicted probability of the large model for sample i, indicating the probability that the sample belongs to the positive class with label 1; During the training of the large model, the loss function L2 is optimized by comparing the difference between the large model output and the label, so that the large model has a good ability to distinguish positive and negative samples.
4. The knowledge graph completion method based on large model enhancement according to claim 1 is characterized in that: Step S03 is specifically as follows: S31. For each node i in the knowledge graph, is the initial vectorized representation of node i, and calculates the attention weight of its neighbor node j : , in represents the attention weight of node i’s neighbor node j, LeakyReLU is the activation function, a is a randomly initialized learnable vector matrix, T represents transposition, Represents the vector To splice; The attention score of each node is normalized by the softmax function to obtain the normalized weight : in Represents the attention weight The normalized value, N(i) is the set of neighbor nodes of node i. The normalized attention coefficient is used to aggregate the node's neighbor information and update the node's embedding representation: , in represents the updated embedding representation of node i, W is the trainable weight matrix, σ is the activation function, repeat the above process to get the node embedding representation after graph neural network embedding and relation embedding representation ; S32. Get the node embedding representation after graph neural network embedding and relation embedding representation After that, the embedding representation of each triple is calculated. , in , , They represent the embedding representations of the head entity, relation, and tail entity in the positive sample triple, respectively. , , , They represent the embedding representations of the head entity, relation, and tail entity in the negative sample triples respectively.
5. The knowledge graph completion method based on large model enhancement according to claim 4 is characterized in that: Step S03 also includes: S33, use the loss function L1 to continue to optimize the embedding representation and obtain the optimized entity embedding representation and relation embedding representation ; I Where S is the positive sample set, is a triplet in the positive sample set, is the set of negative samples, is a triplet in the negative sample set, is the score function, is a hyperparameter, is the L1 norm.
6. The knowledge graph completion method based on large model enhancement according to claim 1 is characterized in that: In step S05, the expression of the score function is: , in is the completed triple, is the L1 norm, When the score function ranks in the top 3 or top 10, the link is judged to be a real link.
7. The knowledge graph completion method based on large model enhancement according to claim 1 is characterized in that: Generate a set of negative samples by randomly replacing the head entity or the tail entity The methods include: A. For each positive sample triple , randomly replace the head entity and select an entity that is not in the positive sample set , generate negative samples ; B. For each positive sample triple , randomly replace the relationship and select a relationship that is not in the positive sample set , generate negative samples ; C. For each positive sample triple , randomly replace the tail entity and select a tail entity that is not in the positive sample set , generate negative samples .
8. The knowledge graph completion method based on large model enhancement according to claim 1 is characterized in that: Use the open source TransE as the initial embedding model of the knowledge graph to obtain its initial entity embedding representation and relation embedding representation .
9. A knowledge graph completion device based on large model enhancement, comprising a processor and a memory storing program instructions, characterized in that: The processor is configured to execute the knowledge graph completion method based on large model enhancement as described in any one of claims 1 to 8 when running the program instructions.
10. A storage medium storing program instructions, characterized in that: When the program instructions are run, they execute the knowledge graph completion method based on large model enhancement as described in any one of claims 1 to 8.
Citation Information
Cited By
Multi-model collaborative knowledge graph construction method, system and equipment and storage medium
CN120316272A
Document question and answer method and device based on topological graph structure
CN120804245A