Knowledge graph completion method and device based on subgraph structure decoupling and common sense transformation
By using subgraph structure decoupling and common sense transformation, a trained network model is used to complete the knowledge graph, solving the OOKB problem and achieving comprehensive and accurate knowledge graph completion, thus improving completion efficiency and accuracy.
Patent Information
- Application Number
- CN202310916467.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-07-25
- Publication Date
- 2025-11-04
- Estimated Expiration
- 2043-07-25
AI Technical Summary
Existing knowledge graphs struggle to achieve comprehensive and accurate completion when faced with the OOKB problem, as unknown entity information is not included, resulting in insufficient completeness and accuracy of the knowledge graph.
A method based on subgraph structure decoupling and common sense transformation is adopted. The first network model is used to extract and decouple the subgraph of the knowledge graph to be completed. The second network model is combined with the training model to make predictions based on common sense knowledge, generating the first and second prediction triples, and then completing the graph through filtering rules.
It improves the comprehensiveness and accuracy of knowledge graph completion by combining internal learning with external common knowledge, thereby enhancing the efficiency and accuracy of completion.
Smart Images

Figure CN117273138B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of artificial intelligence, and in particular to a knowledge graph completion method and device based on subgraph structure decoupling and common sense transformation. BACKGROUND
[0002] A knowledge graph is a knowledge resource and its carrier described by visualization technology, and it mines, analyzes, constructs, draws and displays knowledge and their mutual relationships.
[0003] A knowledge graph is usually represented in the form of a triple (head entity, relationship, tail entity). As new information continues to emerge in the real world, many unknown entities in the knowledge graph will be generated, that is, the information corresponding to these entities has not been included in the existing knowledge base. This situation is referred to as the OOKB (Out Of Knowledge Base) problem. Therefore, how to solve the OOKB problem and more comprehensively and accurately complete the existing knowledge graph has become an urgent problem to be solved. SUMMARY
[0004] The present application aims to at least solve one of the technical problems in the related art. To this end, the present application provides a knowledge graph completion method and device based on subgraph structure decoupling and common sense transformation to more comprehensively and accurately complete the knowledge graph.
[0005] The present application provides a knowledge graph completion method based on subgraph structure decoupling and common sense transformation, comprising:
[0006] predicting a to-be-predicted object in a to-be-completed knowledge graph using a trained first network model to obtain a first predicted triple; wherein the to-be-predicted object includes any one of a head entity, a tail entity and a relationship, and the first network model is used to extract a subgraph from the to-be-completed knowledge graph and decouple the structure of the subgraph;
[0007] predicting the to-be-predicted object in the to-be-completed knowledge graph using a trained second network model to obtain a second predicted triple; the second network model is used to determine a to-be-predicted entity according to common sense knowledge and entities and relationships in the to-be-completed knowledge graph;
[0008] completing the to-be-completed knowledge graph according to the first predicted triple and the second predicted triple.
[0009] In some possible implementation manners, the training step of the first network model comprises: obtaining a first training sample set, the first training sample set comprising a knowledge graph constituted by a plurality of entities and a plurality of relations; inputting the first training sample set into the first network model constructed in advance to obtain a training prediction triple; determining a total score of the training prediction triple, determining a first loss value by using a first preset loss function according to the total score, and updating parameters of the first network model according to the first loss value until the first network model converges, to obtain a trained first network model.
[0010] In some possible implementation manners, the inputting the first training sample set into the first network model constructed in advance to obtain a training prediction triple comprises: performing subgraph extraction on the first training sample set to obtain a training subgraph, the training subgraph comprising at least two entities and at least two relations, the entities comprising a head entity and a tail entity, and the relations comprising a to-be-predicted relation between the head entity and the tail entity; determining initial entity features of each of the entities in the training subgraph and initial relation features of each of the relations; decoupling each of the initial entity features to obtain intermediate entity features of each of the entities under each preset semantic; performing feature updating on each of the intermediate entity features of each of the entities to obtain target entity features of each of the entities under each preset semantic, and performing feature updating on each of the initial relation features to obtain target relation features of each of the relations under each preset semantic; and determining the training prediction triple according to the target entity features of the head entity, the target entity features of the tail entity, and the target relation features of the to-be-predicted relation in all the relations.
[0011] In some possible implementation manners, the determining the initial entity features of each of the entities in the training subgraph comprises: determining, for any entity of the training subgraph, a distance label of the entity, the distance label being used to represent distances between the entity and the head entity and the tail entity; and generating the initial entity features corresponding to each of the entities according to the distance labels of each of the entities; and the determining the initial relation features of each of the relations in the training subgraph comprises: initializing a relation parameter matrix and a preset number of orthogonal bases, the relation parameter matrix comprising each of the relations of the subgraph, and different orthogonal bases being used to represent different preset semantics; and obtaining the initial relation features of each of the relations according to each of the orthogonal bases and the relation parameter matrix.
[0012] In some possible implementation manners, the decoupling of each of the initial entity features to obtain intermediate entity features of each of the entities under each of the preset semantics comprises: projecting, for any entity, the initial entity feature of the entity by using each of the orthogonal bases to obtain a projection length of the entity under each of the preset semantics; and determining, for any entity, the intermediate entity feature of the entity under each of the preset semantics according to each of the projection lengths of the entity and each of the orthogonal bases.
[0013] In some possible implementation manners, the first network model comprises at least two graph neural network layers, and each of the graph neural network layers is sequentially connected. The feature updating of each of the intermediate entity features of each of the entities to obtain a target entity feature of each of the entities under each of the preset semantics comprises: for any intermediate entity feature of any entity, inputting the intermediate entity feature from a first graph neural network layer of all the graph neural network layers, performing feature updating on the intermediate entity feature by using at least two of the graph neural network layers, and outputting, from a last graph neural network layer of all the graph neural network layers, the target entity feature corresponding to the intermediate entity feature under a preset semantic. The feature updating of each of the initial relationship features to obtain a target relationship feature of each of the relationships under each of the preset semantics comprises: inputting each of the initial relationship features from a first graph neural network layer of all the graph neural network layers, performing feature updating on the initial relationship features by using at least two of the graph neural network layers, and outputting, from a last graph neural network layer of all the graph neural network layers, the target relationship feature of each of the relationships under each of the preset semantics.
[0014] In some possible implementation manners, the determining of the total score of the training prediction triple comprises: determining, for any preset semantic, a score of the training prediction triple under the preset semantic according to the target entity feature of the head entity, the target entity feature of the tail entity, and the target relationship feature of the relationship to be predicted; determining a weight of the score of the training prediction triple under each of the preset semantics according to the score of the training prediction triple under each of the preset semantics and the relationship parameter matrix; and determining the total score of the training prediction triple according to the score of the training prediction triple under each of the preset semantics and the corresponding weight.
[0015] In some possible implementation manners, the training step of the second network model comprises: obtaining a second training sample set comprising at least two input words with relationship labels; inputting the input words with relationship labels into the second network model to obtain a target word and a probability of predicting the target word; calculating a second loss value by using a second preset loss function according to the target word and the probability, and updating parameters of the second network model according to the second loss value until the second network model converges, thereby obtaining a trained second network model.
[0016] The application further provides a knowledge graph completion device based on subgraph structure decoupling and common sense transformation, comprising: a first prediction module configured to predict a to-be-predicted object in a to-be-completed knowledge graph by using a trained first network model to obtain a first predicted triple; wherein the to-be-predicted object comprises any one of a head entity, a tail entity and a relationship, and the first network model is configured to extract a subgraph from the to-be-completed knowledge graph and decouple the structure of the subgraph; a second prediction module configured to predict the to-be-predicted object in the to-be-completed knowledge graph by using a trained second network model to obtain a second predicted triple; wherein the second network model is configured to determine a to-be-predicted entity according to common sense knowledge and entities and relationships in the to-be-completed knowledge graph; and a completion module configured to complete the to-be-completed knowledge graph according to the first predicted triple and the second predicted triple.
[0017] The application further provides an electronic device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the processor implements the knowledge graph completion method based on subgraph structure decoupling and common sense transformation according to any one of the above descriptions when executing the program.
[0018] The application further provides a computer readable storage medium having a computer program stored thereon, wherein the computer program is executable on a processor to implement the knowledge graph completion method based on subgraph structure decoupling and common sense transformation according to any one of the above descriptions.
[0019] The application further provides a computer program product comprising a computer program, wherein the computer program is executable on a processor to implement the knowledge graph completion method based on subgraph structure decoupling and common sense transformation according to any one of the above descriptions.
[0020] The application provides a knowledge graph completion method and device based on subgraph structure decoupling and common sense transformation. BRIEF DESCRIPTION OF DRAWINGS
[0021] In order to more clearly illustrate the technical solutions in the application or the prior art, the following will briefly introduce the drawings needed to be used in the embodiments or the prior art description. Obviously, the drawings in the following description are some embodiments of the application, and other drawings can be obtained by those skilled in the art without any creative effort on the basis of these drawings.
[0022] Figure 1 is a flowchart of the knowledge graph completion method of the embodiment of the application;
[0023] Figure 2 is one of the flowcharts of the first network model training method of the embodiment of the application;
[0024] Figure 3 is the second flowchart of the first network model training method of the embodiment of the application;
[0025] Figure 4 is a schematic diagram of the initial subgraph and the subgraph of the embodiment of the application;
[0026] Figure 5 is the third flowchart of the first network model training method of the embodiment of the application;
[0027] Figure 6 is a schematic diagram of the distance label of the embodiment of the application;
[0028] Figure 7 is the fourth flowchart of the first network model training method of the embodiment of the application;
[0029] Figure 8 is the fifth flowchart of the first network model training method of the embodiment of the application;
[0030] Figure 9 is a structural schematic diagram of the fourth network branch of the embodiment of the application;
[0031] Figure 10is the first network model training method flowchart of the embodiment of the present application;
[0032] Figure 11 is the second network model training method flowchart of the embodiment of the present application;
[0033] Figure 12 is the block diagram of the knowledge graph completion device of the embodiment of the present application;
[0034] Figure 13 An entity structure schematic diagram of an electronic device is exemplified. DETAILED DESCRIPTION
[0035] In order to make the objects, technical solutions and advantages of the present application clearer, the technical solutions in the present application will be described clearly and completely below with reference to the drawings in the present application. Obviously, the described embodiments are some embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative labor fall within the protection scope of the present application.
[0036] Figure 1 is the flowchart of the knowledge graph completion method of the embodiment of the present application. As shown in Figure 1 , the knowledge graph completion method based on subgraph structure decoupling and common sense transformation can include the following steps:
[0037] Step 110: predicting the to-be-predicted object in the to-be-completed knowledge graph by using the trained first network model to obtain a first predicted triple.
[0038] It should be noted that the to-be-predicted object includes any one of the head entity, the tail entity and the relationship, and the first network model is used to extract a subgraph from the to-be-completed knowledge graph and decouple the structure of the subgraph. In addition, the to-be-completed knowledge graph can be any type of knowledge graph, such as an educational knowledge graph, a fault diagnosis knowledge graph, a power data knowledge graph, etc. The process of completing the to-be-completed knowledge graph is to predict the third element according to the two known elements of the to-be-completed knowledge graph triple, so as to complete the triple.
[0039] It can be understood that most of the relationships contained in the knowledge graph are the relationships between entities with direct connection. For example, in the fault diagnosis knowledge graph, there is a direct causing relationship between "user operation" and "fault phenomenon", and there is a direct occurrence relationship between "fault site" and "fault phenomenon", and the fault diagnosis knowledge graph usually does not construct the relationship between "user operation" and "fault site".
[0040] Therefore, the embodiment mines the relationship between the entities with loose relationship from the to-be-completed knowledge graph by decoupling the to-be-completed knowledge graph through the trained first network model, so as to obtain a new triple (i.e., a first predicted triple) to complete the to-be-completed knowledge graph.
[0041] Specifically, when completing the to-be-completed knowledge graph by using the trained first network model, the trained first network model will first perform subgraph extraction on the to-be-completed knowledge graph to obtain a subgraph. The subgraph will contain a head entity and a tail entity that need to be predicted. The head entity and the tail entity can be entities with loose relationship in the to-be-completed knowledge graph. In addition, the subgraph will also contain entities having a connection relationship with the head entity and the tail entity and the relationship between the entities.
[0042] Further, the trained first network model realizes decoupling of the subgraph structure by decoupling and aggregating the entity features of the subgraph. By decoupling the subgraph structure, the latent rule information of the subgraph structure is obtained, and general features are set for the entities. Finally, the first predicted triple is obtained according to the entity features obtained after decoupling the subgraph structure.
[0043] Step 120: predicting the to-be-predicted object in the to-be-completed knowledge graph by using the trained second network model to obtain a second predicted triple.
[0044] It should be noted that the second network model is used to determine the to-be-predicted entity according to the common sense knowledge and the entities and relationships in the to-be-completed knowledge graph.
[0045] In the embodiment, the architecture of the CTKG model can be used as the basic architecture of the second network model. It should be noted that the CTKG model is obtained based on the COMET (Commonsense Transformers) model, and the CTKG model is a framework for constructing a common sense knowledge base by using a pre-trained language model. The CTKG model learns common sense knowledge from a large-scale text corpus, and represents each common sense knowledge as a vector. By giving a seed knowledge graph, the CTKG model generates new nodes (i.e., entities) and edges (i.e., relationships) for the seed knowledge graph by using the learned common sense knowledge.
[0046] Based on the above functions of the CTKG model, the CTKG model can be used in the present embodiment, using the CTKG model as the second network model. By a given subject s and a relation r, the CTKG model generates an object o using learned common sense knowledge, and thus a new triple (s, r, o) can be obtained. It should be noted that the subject s can be an existing entity of the knowledge graph to be completed, and the object o can be a to-be-predicted entity. For ease of understanding, in the present embodiment, the entity corresponding to the subject s is referred to as a known entity, and the entity corresponding to the object o is referred to as a to-be-predicted entity.
[0047] Specifically, when completing the knowledge graph to be completed using the trained second network model, the known entity and the relation can be first represented by vectors. The manner of representing the known entity and the relation by vectors can be: using a pre-trained word vector or a character-level embedding to obtain a vector representation of the known entity and the relation. After obtaining the vector of the known entity and the vector of the relation, the vector of the known entity and the vector of the relation are input into the trained second network model, and the trained second network model outputs the to-be-predicted entity according to common sense knowledge, to obtain a second predicted triple.
[0048] Step 130: completing the knowledge graph to be completed according to the first predicted triple and the second predicted triple.
[0049] After obtaining the first predicted triple and the second predicted triple, the first predicted triple and the second predicted triple can be directly updated to the knowledge graph to be completed, to realize comprehensive completion of the knowledge graph to be completed.
[0050] However, there can be some unreasonable relations between entities in the first predicted triple and the second predicted triple obtained by the model, for example, the relations between entities have symmetry, transitivity, inversion, inconsistency, and do not conform to common sense. Therefore, in the present embodiment, a processing rule can be set in advance to filter the predicted triple with unreasonable relations, and then the filtered first predicted triple and second predicted triple are updated to the knowledge graph to be completed.
[0051] Specifically, if the relations of two entities have symmetry, for example, the relations between the two entities of “father” and “son” have symmetry, when there is only a triple of “father-son” in the knowledge graph to be completed, but there is no triple of “son-father”, the latter can be added to the knowledge graph.
[0052] For the transitivity of triples, for example, "grandfather" and "grandson", if there are two triples "A is the grandfather of B" and "B is the father of C" in the knowledge graph to be completed, then it can be inferred that "A is the grandfather of C". Therefore, when updating the knowledge graph to be completed, the transitive relationship should be complete.
[0053] For the reversibility of triples, for example, "employ" and "be employed", the triples corresponding to the two entities should be mutual. Therefore, when updating the knowledge graph to be completed, the triples of these relationships should be complete.
[0054] For the consistency of triples, that is, there are multiple triples describing the relationship between the same pair of entities, then these triples should be consistent. For example, if there are two triples "A is the father of B" and "A is the biological father of B", then the relationship between the two triples should be consistent.
[0055] For the common sense of triples, when adding new triples to the knowledge graph to be completed, it is necessary to consider whether the new triples conform to common sense. For example, the triple "dog is the friend of human" obviously does not conform to common sense, so this triple should be filtered out.
[0056] Therefore, by decoupling the subgraph structure of the trained first network model, the relationship between entities is learned from the inside of the knowledge graph to be completed, and then the knowledge graph to be completed is updated; by the trained second network model according to the common sense knowledge learned from the outside, the knowledge graph to be completed is updated; improve the comprehensiveness and accuracy of the completion of the knowledge graph to be completed, and by the two models of the first network model and the second network model simultaneously updating the knowledge graph to be completed, the efficiency of the completion of the knowledge graph to be completed is also improved.
[0057] The model architecture and training method of the first network model will be described in detail below.
[0058] Figure 2 is one of the first network model training method flowcharts of the embodiments of the present application. As shown in Figure 2 the first network model can be trained by the following steps:
[0059] Step 210: Obtain a first training sample set, and the first training sample set includes a knowledge graph composed of multiple entities and multiple relationships.
[0060] Step 220: Input the first training sample set into the pre-constructed first network model to obtain a training prediction triple.
[0061] Step 230: determining a total score of the training prediction triplets, determining a first loss value according to the total score and the first preset loss function, and updating the parameters of the first network model according to the first loss value until the first network model converges, so as to obtain the trained first network model.
[0062] In this embodiment, the first training sample set can be any knowledge graph containing multiple entities and multiple relationships, which is not specifically limited here. For example, the first training sample set can use the WN18RR dataset, the FB15k-237 dataset, the NELL-995 dataset, and the like. Taking the WN18RR dataset as an example, the WN18RR dataset contains 40943 entities and 11 types of relationships, and the WN18RR dataset is equivalent to a knowledge graph. Therefore, the WN18RR dataset can be used to train the first network model.
[0063] After the first training sample set is determined, the first training sample set can be input into the first network model constructed in advance. The first network model predicts the relationship between the unknown entities in the first training sample set to obtain the training prediction triplets. It should be noted that the input of the first network model can be known entities and relationships, and the output is a to-be-predicted entity. The input of the first network model can also be two known entities, and the output is a to-be-predicted relationship.
[0064] After obtaining the training prediction triplets, the total score of the training prediction triplets is calculated, and the loss value is calculated by using the total score of the prediction triplets and the first preset loss function. Then, the parameters of the first network model are optimized by using the loss value until the loss value tends to be minimum and the first network model converges, so as to obtain the trained first network model.
[0065] Figure 3 is a second flowchart of the first network model training method of the embodiment of the present application. As shown in Figure 3 In some embodiments, the step of inputting the first training sample set into the first network model constructed in advance in step 220 to obtain the training prediction triplets can include the following steps:
[0066] Step 310: performing subgraph extraction on the first training sample set to obtain a training subgraph, the training subgraph including at least two entities and at least two relationships, the entities including a head entity and a tail entity, and the relationships including a to-be-predicted relationship between the head entity and the tail entity.
[0067] Step 320: determining initial entity features of each entity and initial relationship features of each relationship in the training subgraph.
[0068] Step 330: decoupling each initial entity feature to obtain intermediate entity features of each entity under each preset semantic.
[0069] Step 340: performing feature updating on each intermediate entity feature of each entity to obtain a target entity feature of each entity under each preset semantic, and performing feature updating on each initial relationship feature to obtain a target relationship feature of each relationship under each preset semantic.
[0070] Step 350: determining a training prediction triple according to the target entity feature of the head entity, the target entity feature of the tail entity, and the target relationship feature of the to-be-predicted relationship in all entities and all relationships.
[0071] In the embodiment, the first network model can include a first network branch, a second network branch, a third network branch, and a fourth network branch connected in sequence. The first network branch is configured to perform step 310, the second network branch is configured to perform step 320, the third network branch is configured to perform step 330, and the fourth network branch is configured to perform step 340.
[0072] It can be understood that when predicting the relationship between the two known entities in the first training sample set, not all connection relationships between all entities in the first training sample set will help the relationship prediction process. For example, entities far away from the two known entities rarely carry semantic information that helps the relationship prediction process. Therefore, the dataset of the first training sample set can be preprocessed to remove entities and relationships that do not help the relationship prediction process.
[0073] In the embodiment, the first network branch is used to extract a subgraph from the first training sample set to remove entities and relationships that do not help the relationship prediction process. Thus, only the local subgraph between the two known entities is considered to predict the relationship between the two known entities. In the embodiment, the two known entities can be recorded as a head entity and a tail entity, and the relationship to be predicted between the head entity and the tail entity can be recorded as a to-be-predicted relationship.
[0074] Specifically, the first network branch can extract a subgraph from the first training sample set in the following manner: first, determine the K-hop reachable neighborhood of each of the head entity and the tail entity from the first training sample set to obtain an initial subgraph. It should be noted that the K-hop reachable neighborhood includes K entities most similar (i.e., closest in the feature space) to the entity. After determining the K-hop reachable neighborhood of each of the head entity and the tail entity, there are many entities in the K-hop reachable neighborhood of each of the head entity and the tail entity that only have an association relationship with the head entity or the tail entity, and these entities are not helpful for predicting the to-be-predicted relationship. Therefore, in the embodiment, the entities only having an association relationship with the head entity or the tail entity are removed, and the entities having an association relationship with both the head entity and the tail entity and the mutual edges between the entities are retained, thereby obtaining a final training subgraph φZ.
[0075] Figure 4 is a schematic diagram of an initial subgraph and a subgraph of an embodiment of the present application.
[0076] As an example, as shown in Figure 4 , if the sample prediction triple is (A, r, B), where A is the head entity, r is the relationship to be predicted, and B is the tail entity. The process of subgraph extraction for the to-be-completed model is as follows: first, find all entities in the K-hop reachable neighborhood of the head entity A and all entities in the K-hop reachable neighborhood of the tail entity B, to obtain the set k (A) and the set k (B), to obtain the initial subgraph as shown in Figure 4 . Next, take the intersection of the set k (A) and the set k (B), thereby removing entities connected only to the head entity A or the tail entity B, to obtain the set {A, B, φ k (A)∩φ k (B)}, which contains all entities of the subgraph, and retains the mutual edges between the entities in the set, thereby obtaining the final training subgraph φZ.
[0077] After the first network branch outputs the training subgraph φZ by performing subgraph extraction on the first training sample set in step 320, the training subgraph is input to the second network branch. The second network branch can set initial features for the entities and relationships in the training subgraph, and output initial entity features and initial relationship features corresponding to each entity in the training subgraph.
[0078] Figure 5 is a third flowchart of a first network model training method according to an embodiment of the present application. As shown in Figure 5 , in some embodiments, determining the initial entity features of each entity in the training subgraph in step 320 can include the following steps:
[0079] Step 510: For any entity of the training subgraph, determine the distance label of the entity, which is used to represent the distance between the entity and the head entity and the tail entity.
[0080] Step 520: Generate the initial entity features corresponding to each entity according to the distance labels of the entities.
[0081] It can be understood that when setting the initial entity features of each entity in the training subgraph, the particularity of the entity cannot be considered. Therefore, one-hot encoding and similar methods cannot be used to set the initial entity features of each entity, because when determining the initial entity features of each entity using these methods, an independent feature vector needs to be set for each entity, and when the number of entities is very large, using these methods will cause problems such as dimension explosion and high computational complexity.
[0082] In addition, when the knowledge completion model is trained, due to the limitation of the OOKB problem, the first training sample set does not contain the entities of the test set, so that the initial entity feature of the new entity cannot be obtained because the new entity is not trained. Therefore, when the knowledge completion model is trained for the OOKB problem, the setting mode of the initial entity feature should be general.
[0083] Based on this, the embodiment designs an initial entity feature determination mode for the OOKB problem. Since the first training sample set structure implies rule information, the initial entity feature of each entity in the training subgraph can be set from the perspective of the training subgraph structure.
[0084] Specifically, the second network branch can set a distance label for each entity in the training subgraph, and the distance label is used to represent the distance between the entity and the head entity and the tail entity. The distance label can be represented as (x1, x2), wherein x1 is the shortest distance between the entity and the head entity, and x2 is the shortest distance between the entity and the tail entity. More specifically, the distance label of the head entity is represented as (0, 1), and the distance label of the tail entity is represented as (1, 0).
[0085] Figure 6 is a schematic diagram of the distance label of the embodiment of the application. As shown in Figure 6 , as an example, the distance label of the head entity A is (0, 1), the distance label of the tail entity B is (1, 0), and the distance label of the entity C is (1, 1). In this way, the distance label of each entity in the training subgraph can be obtained.
[0086] After obtaining the distance label of each entity in the training subgraph, the distances x1 and x2 in the distance label of each entity can be binary coded to obtain the x1 code and the x2 code corresponding to each entity. For any entity, the x1 code and the x2 code are spliced to obtain the initial entity feature corresponding to the entity.
[0087] Figure 7 is a fourth flowchart of the first network model training method of the embodiment of the application. As shown in Figure 7 , in some embodiments, the step 320 of determining the initial relationship feature of each relationship in the training subgraph can include the following steps:
[0088] Step 710: initializing a relationship parameter matrix and a preset number of orthogonal bases, the relationship parameter matrix including the relationships of the subgraph, and different orthogonal bases being used to represent different preset semantics.
[0089] Step 720: obtaining the initial relationship feature of each relationship according to the relationship parameter matrix and each orthogonal base.
[0090] It should be noted that the preset number can be set artificially by the staff according to actual needs, and the specific limitation is not made here, and in this embodiment, the preset number is represented as m1.
[0091] Specifically, the second network branch can first initialize m1 orthogonal bases (e1, e2, …, e m1 , to obtain an orthogonal basis matrix M base ∈R m1×dim In order to always maintain the orthogonality of the basis, during the training of the first network model, the orthogonal basis matrix can be set not to be updated by training, and the m1 orthogonal bases can be used to represent the features of each relationship in the training subgraph respectively.
[0092] Next, a relationship parameter matrix W rel ∈R m2×m1 , wherein m2 is used to represent the number of relationships in the training subgraph. Finally, the initial relationship feature matrix of the training subgraph is calculated according to the orthogonal basis matrix and the relationship parameter matrix, and the initial relationship feature matrix contains the initial relationship features of each relationship under each semantic, and the initial relationship feature matrix can be determined by the following formula:
[0093]
[0094] , wherein M rel is the initial relationship feature matrix of the training subgraph, e m2 m1 is the relationship parameter of the m2th relationship under the m1th orthogonal basis (i.e. semantic), e m1 dim is the dim dimension under the m1th orthogonal basis, M m2,m1 is the initial relationship feature of the m2th relationship under the m1th orthogonal basis (i.e. semantic). Thus, the initial relationship features of each relationship under different semantics in the training subgraph can be obtained, and each initial relationship feature reflects the characteristics of the relationship in different directions.
[0095] In step 330, after the second network branch obtains the initial entity features of each entity and the initial relationship features of each relationship in the training subgraph, the third network branch decouples the initial entity features of each entity to obtain the intermediate entity features of each entity under each preset semantic.
[0096] It can be understood that in the structure of the training subgraph, there are many entities that are not directly connected except through the head entity and the tail entity, i.e. unconnected structure. These unconnected structures often represent the connection between the head entity and the tail entity in different semantics at the semantic level, but not all semantic connections help the relationship prediction positively.
[0097] In practical applications, these unconnected structures will occupy a certain proportion in the training subgraph. Table 1 shows the proportion of unconnected structures in the training subgraph corresponding to each dataset, if the first training sample set is the WN18RR dataset, the FB15k-237 dataset and the NELL-995 dataset, and the selected head entity and tail entity K-hop reachable domain K = 3, the proportion of unconnected structures in the training subgraph. Among them, proportion 1 is the proportion of unconnected structures in all training subgraphs extracted; proportion 2 is the proportion of unconnected structures in the training subgraph where only the head entity and the tail entity of the relationship to be predicted are located.
[0098] Table 1
[0099] Dataset WN18RR FB15k-237 NELL-995 Scale 1 19.25% 5.39% 2.29% Scale 2 28.61% 5.84% 3.82%
[0100] Therefore, by decoupling the structure of the training subgraph, the training subgraph structure with low semantic correlation is screened out, so as to reduce the influence of the training subgraph structure with low semantic correlation on the relationship prediction effect, and further ensure the accuracy and prediction efficiency of the first network model obtained by training. In this embodiment, it is through decoupling the initial entity features of each entity to realize the decoupling of the training subgraph structure.
[0101] Figure 8 is the fifth network model training method flowchart of the embodiment of the application. As shown in Figure 8 In some embodiments, the decoupling of the initial entity features of each entity in step 330 to obtain the intermediate entity features of each entity under each preset semantics can include the following steps:
[0102] Step 810: For any entity, project the initial entity features of the entity using each orthogonal basis to obtain the projection length of the entity under each preset semantics.
[0103] Step 820: For any entity, determine the intermediate entity features of the entity under each preset semantics according to the projection length of the entity and each orthogonal basis.
[0104] Specifically, the third network branch first maps the initial entity features of each entity to different orthogonal bases by calculating the pseudo-inverse to obtain the projection length of each entity under different preset semantics. After obtaining the projection length of each entity under different preset semantics, the third network branch determines the intermediate entity features of each entity under each preset semantics according to the projection length and each orthogonal basis. Decoupling the initial entity features of each entity can learn the influence of different latent factors on the prediction result and find the key features.
[0105] It should be noted that one orthogonal basis corresponds to representing one semantic space, and therefore, for the same entity, the semantics represented by its features in different orthogonal bases are different.
[0106] As an example, taking entity u as an example, if the initial entity feature of entity u is denoted as x u , the projection length of entity u under different preset semantics and the intermediate entity features under each preset semantics can be calculated by the following formula:
[0107]
[0108] h u,i =a i M base,i
[0109]
[0110] Wherein, A is a set of projection lengths of entity u under different preset semantics, and the A set contains a i , a i is the projection length of entity u under the i-th preset semantics, M base -1 is the pseudo-inverse of the orthogonal basis matrix, M base,i is the i-th orthogonal basis, h u,i is the intermediate entity feature of entity u under the i-th preset semantics, X u is a set of intermediate entity features of entity u under different preset semantics.
[0111] It is worth mentioning that the embodiment realizes decoupling by setting orthogonal bases and mapping the initial entity features of each entity on each orthogonal basis, thereby ensuring the independence of the intermediate entity features after decoupling.
[0112] In step 340, after the third network branch decouples the structure of the training subgraph to obtain the intermediate entity features corresponding to each entity, the intermediate entity features of each entity and the initial relationship features of each relationship can be input into the fourth network branch for feature updating to obtain the target entity features of each entity under each preset semantics and the target relationship features of each relationship under each preset semantics.
[0113] It should be noted that the fourth network branch is composed of multiple layers of graph neural network layers, and each layer of graph neural network layer includes an attention unit and a fully connected unit.
[0114] In the embodiment, the fourth network branch updates the intermediate entity features and the initial relationship features n times, where n = m1, corresponding to the m1 semantic spaces. Meanwhile, considering that different orthogonal bases have different proportions in relationship prediction, i.e., different relationships have different preference degrees in semantic spaces, when updating the features, the attention coefficients in different semantic spaces need to be calculated, and then the target entity features and the target relationship features are determined according to the attention coefficients in different semantic spaces, so as to ensure the accuracy of the first network model obtained by training.
[0115] Figure 9 FIG. 4 is a structural schematic diagram of the fourth network branch of the embodiment of the present application. As shown in FIG. 4, in some embodiments, the first network model includes at least two graph neural network layers, and the graph neural network layers are connected in sequence. Figure 9
[0116] In some embodiments, the step 340 of updating the intermediate entity features of each entity to obtain the target entity features of each entity in each preset semantic space can include the following steps: for any intermediate entity feature of any entity, the intermediate entity feature is input from the first graph neural network layer in all graph neural network layers, the intermediate entity feature is updated by at least two graph neural network layers, and the target entity feature corresponding to the intermediate entity feature in the preset semantic space is output from the last graph neural network layer in all graph neural network layers.
[0117] Taking any intermediate entity feature in any entity as an example, after the intermediate entity feature is input into the fourth network branch, the first graph neural network layer calculates the attention coefficient corresponding to the intermediate entity feature, and then obtains the updated feature according to the attention coefficient; next, the updated feature is taken as the input of the second graph neural network layer, and the specific process of the second graph neural network layer is the same as that of the first graph neural network layer, so that the updated feature output by the second graph neural network layer is also obtained. The intermediate entity feature is updated by each graph neural network layer until the target entity feature corresponding to the intermediate entity feature is output in the last graph neural network layer.
[0118] Taking the entity u and the entity v as an example, the process of the fourth network branch feature update is described in detail below.
[0119] In the embodiment, each graph neural network layer calculates the attention coefficient by running the following formula:
[0120]
[0121]
[0122] wherein k is the kth layer of the graph neural network, k e n, f1 is a full connection unit, h k (u,j) is the feature of the entity u inputted in the kth layer under the jth preset semantics, h k (v,j) is the feature of the entity v inputted in the kth layer under the jth preset semantics, M (rel,uv,j) is the initial relationship feature of the relationship between the entity u and the entity v under the jth preset semantics, M (rel,label,j) is the initial relationship feature s of the relationship to be predicted under the jth preset semantics k (u,v,j) is the output of the full connection unit, a k (u,v,j) is the attention coefficient of the entity u and the entity v under the jth preset semantics, N(u) represents the adjacent entity of the entity u.
[0123] The feature h k (u,j) of the entity u inputted in the kth layer under the jth preset semantics in the above formula is obtained through the attention coefficient outputted by the previous layer of the graph neural network, and can be determined through the following formula h k (u,j) :
[0124]
[0125] wherein a k-1 (u,v,j) is the attention coefficient of the entity u and the entity v outputted in the k-1th layer under the jth preset semantics, h k-1 (u,j) is the feature of the entity u inputted in the k-1th layer under the jth preset semantics, h k-1 (v,j) is the feature of the entity v inputted in the k-1th layer under the jth preset semantics, W r is the parameter matrix of the relationship r between the entity u and the entity v, and it should be noted that a parameter matrix W r .
[0126] It is worth mentioning that the intermediate entity feature is updated through the fourth network branch, and the intermediate entity feature has learned the structure information of the training subgraph. Specifically, when the initial entity features of each entity are initialized, since the initial entity features are arranged according to the distance between the entity and the head entity and the tail entity, the matrix composed of the initial entity features belongs to ordered data. In this embodiment, when the fourth network branch performs the last feature update, GRU (gated recurrent neural network) is used to update h k(u,j) The update is performed, so as to extract the path information on the training subgraph. Specifically, it is expressed as:
[0127]
[0128] wherein, is the target entity feature of the entity u output by the last layer of the graph neural network under the jth preset semantic.
[0129] It should be noted that the path information refers to the adjacency relationship of the entities in the training subgraph, for example, the edge type and distance between adjacent entities; and other association information between entities, for example, the semantic relationship and attribute between entities.
[0130] As an example, if the training subgraph contains three entities A, B and C, and the relationship therebetween is as follows: there is an edge between entity A and entity B, and the edge type is “same type”; there is an edge between entity A and entity C, and the edge type is “attribute”; there is no edge between entity B and entity C, which is the path information.
[0131] In some embodiments, the step 340 of updating the features of each pair of initial relationship features to obtain the target relationship feature of each relationship under each preset semantic can include the following steps: inputting each initial relationship feature from the first graph neural network layer in all graph neural network layers, updating the features of the initial relationship features through at least two graph neural network layers, and outputting the target relationship feature of each relationship under each preset semantic from the last graph neural network layer in all graph neural network layers.
[0132] It should be noted that the process of updating the features of each initial relationship feature by the fourth network branch is the same as the process of updating the features of each intermediate entity feature, which will not be repeated here. Finally, the last layer of the graph neural network of the fourth network branch will output the target relationship feature of each relationship under each preset semantic.
[0133] After the fourth network branch outputs the target entity features of each entity and the target relationship features of each relationship in step 350, the to-be-predicted relationship can be generated according to the target relationship features of the to-be-predicted relationship, and the head entity, the tail entity and the to-be-predicted relationship are combined to form a training prediction triple.
[0134] The following will introduce in detail the way of determining the training prediction triple according to the target entity features and the to-be-predicted relationship features by taking a specific example.
[0135] Take the head entity (Li Si), the tail entity (Wang Wu) and the relationship to be predicted (classmate) as an example, a training prediction triple (Li Si, classmate, Wang Wu) is generated. First, the intermediate entity features of the head entity Li Si and the tail entity Wang Wu are input into the first network model for encoding, and the updated target entity features and
[0136] Specifically, the contribution of each entity to the relationship to be predicted is calculated using the attention unit in the fourth network branch, that is, the contribution of each entity to the relationship to be predicted is calculated Here, j represents the jth basis, because the embodiment uses the guest basis to process the diversity of entities and relationships. Specifically, when calculating , the and the target relationship features corresponding to the classmate relationship are input into the fully connected layer f2 to obtain Then, the softmax function is used to convert into a probability distribution to obtain Finally, the is used to weight and average the features of the adjacent entities to update the features of the current entity. Specifically, for the head entity Li Si, the updated features of the head entity Li Si on the jth basis can be obtained by calculating and the weighted average of the features of the adjacent entities of the head entity and the attention coefficient Similarly, the updated features of the tail entity Wang Wu on the jth basis can also be obtained When the updating of the entity features is completed, the target entity features can be obtained, and further, these target entity features can be input into the classifier to predict whether the classmate relationship exists between the head entity Li Si and the tail entity Wang Wu.
[0137] Figure 10 is the sixth flowchart of the first network model training method of the embodiment of the present application. As Figure 10 shown, in some embodiments, determining the total score of the training prediction triple in step 230 can include the following steps:
[0138] Step 1010: For any preset semantics, the score of the training prediction triple under the preset semantics is determined according to the target entity features of the head entity, the target entity features of the tail entity and the target relationship features of the relationship to be predicted.
[0139] Step 1020: According to the scores of the training prediction triples under each preset semantics and the relationship parameter matrix, the weight of the score of the training prediction triple under each preset semantics is determined.
[0140] Step 1030: determining the total score of the training prediction triple according to the scores and the corresponding weights of the training prediction triple under each preset semantic.
[0141] Specifically, after obtaining the target entity features of the head entity and the tail entity under each preset semantic, and the target relationship features of the relationship to be predicted under each preset semantic, the final features of the head entity and the tail entity under different semantics can be determined, for example:
[0142]
[0143]
[0144] wherein X k head is the final feature of the head entity, X k tail is the final feature of the tail entity.
[0145] The score of the training prediction triple under each preset semantic can be calculated as follows:
[0146]
[0147] wherein score i is the score of the training prediction triple under the i-th preset semantic, f2 is a full connection function, x head i is the final feature of the head entity under the i-th preset semantic, x relation i is the final feature of the relationship to be predicted under the i-th preset semantic, x tail i is the final feature of the tail entity under the i-th preset semantic, x avg i is the average feature of the entities in the training subgraph under the i-th preset semantic.
[0148] After obtaining the scores of the training prediction triple under different preset semantics, the weights of the scores under different preset semantics in relationship prediction can be determined as follows:
[0149] att = abs(W rel (r))
[0150] wherein att is the weight of the relationship to be predicted r under different preset semantics, W relis a parameter matrix of relations, and abs(·) is an absolute value operation. Considering that the sign of the weight under different preset semantics only represents the direction and does not represent the size when determining the target relation feature, the weight is subjected to the absolute value operation here. For the to-be-predicted relation r, the weight under different preset semantics represents the preference degree of the to-be-predicted relation r to different preset semantic spaces. Therefore, when calculating the total score of the training prediction triple, the score result under the preset semantic space with a larger weight is considered more.
[0151] The total score of the training prediction triple can be specifically determined by the following formula:
[0152] score = att [score1, score2,... score m1 ]
[0153] Wherein, score is the total score of the training prediction triple, score m1 is the score of the training prediction triple under the m1th preset semantic.
[0154] In this embodiment, the first network model can be trained by using a marginal loss function, so that the trained first network model has a higher score on the positive sample than on the negative sample, thereby obtaining the trained first network model. The marginal loss function can be expressed as the following formula:
[0155]
[0156] Wherein, is the first loss value, ε is a set of triple samples; p d and n d respectively represent the dth positive sample triple and negative sample triple; γ represents a margin hyperparameter, and when the total score of the positive sample triple is greater than the total score of the negative sample triple by more than γ, the loss is not counted.
[0157] Therefore, before the total score of the training prediction triple is used for loss calculation, it is also necessary to determine whether the training prediction triple is a positive sample or a negative sample; if the training prediction triple is a positive sample, the total score corresponding to the training prediction triple is brought into the positive sample score; if the training prediction triple is a negative sample, the total score corresponding to the training prediction triple is brought into the negative sample score.
[0158] It should be noted that the positive sample triple is a known triple in the first training sample set, and the negative sample triple refers to a false triple that has never appeared or does not exist in the first training sample set. In this embodiment, the head or tail of the triple can be randomly replaced by Bernoulli negative sampling to generate the negative sample triple, so as to increase the diversity and quantity of the training data in the first training sample set.
[0159] The loss value of the first network model is calculated by comparing the score difference between the positive sample and the negative sample with a preset margin, and the first network model is converged by continuously optimizing the model parameters, so as to obtain the trained first network model. Therefore, the first network model can learn a more accurate representation, thereby improving the prediction accuracy of the first network model.
[0160] The trained first network model can be obtained through the above steps, and the model architecture and training method of the second network model will be introduced in detail below.
[0161] Figure 11 is a flow chart of a second network model training method according to an embodiment of the present application. As shown in Figure 11 , in some embodiments, the training steps of the second network model can include:
[0162] Step 1110: Obtain a second training sample set, and the second training sample set includes at least two input words with relationship labels.
[0163] Step 1120: input the input words with relationship labels into the second network model to obtain a target word and a probability of predicting the target word.
[0164] Step 1130: calculate a second loss value according to the target word and the probability using a second preset loss function, and update the parameters of the second network model according to the second loss value until the second network model converges, thereby obtaining a trained second network model.
[0165] First of all, it should be noted that the architecture of the CTKG model can be used as the basic architecture of the second network model. The CTKG model uses a Transformer language model as the basic model, wherein each Transformer block includes a multi-head self-attention mechanism layer and a fully connected feedforward network.
[0166] Specifically, the triples in the natural language knowledge base can be converted into a word sequence and a relationship label, and the word sequence can be encoded to obtain a corresponding word vector. Finally, a training sample can be composed of a word vector and a corresponding relationship label, and multiple training samples can construct a second training sample set. The training sample in the second training sample set can be a "question and answer" sample, i.e., a (C, o) sample composed of a word vector C corresponding to an input word and a target word o.
[0167] After obtaining the second training sample set, it is input into the second network model. The multi-head self-attention layer in the second network model first performs a linear projection on the input word sequence with relation labels, obtaining the query vector Q, key vector K, and value vector V. The multi-head self-attention layer then separates the query vector Q, key vector K, and value vector V into multiple independent heads, each with a different sub-query vector Q, sub-key vector K, and sub-value vector V. Next, the sub-attention value for each independent head is calculated separately. After obtaining the sub-attention values for each independent head, all the sub-attention values are concatenated and linearly projected to obtain the attention value corresponding to the input word sequence with relation labels. Finally, based on the attention value corresponding to the input word, the probability that the target word is 'o' is determined.
[0168] It is worth mentioning that, in order to make the second network model sensitive to the position of the input words, a position vector P can be initialized for the absolute position of each input word. t Where t represents the t-th word, and the position vector P is... t The word vector C of the input word t Add them together to get the encoding h of the input word. 0 t :
[0169]
[0170] It should be noted that the specific working process of the multi-head self-attention machine layer and the fully connected feedforward network in the second network model can be referred to the working process of the multi-head self-attention machine layer and the fully connected feedforward network in the existing Transformer language model, and will not be repeated here.
[0171] After obtaining the probability that the target word is 'o', the cross-entropy loss function can be used as the second preset loss function to optimize the second network model. For each training sample (C,o), the second preset loss function can be defined as:
[0172]
[0173] Where L(C,o) is the second loss value, y s Let p(o) be the one-hot vector representation of the target word in the vocabulary. s |C,r) represents the second network model predicting the target word o at the s-th position given the input word C and relation label r. s The probability is given by U, where U represents the total number of positions.
[0174] Figure 12 This is a block diagram of a knowledge graph completion device according to an embodiment of the present invention. Figure 12As shown, the knowledge graph completion device 1200 based on subgraph structure decoupling and common sense transformation can include:
[0175] The first prediction module 1210 is configured to predict the to-be-predicted object in the to-be-completed knowledge graph by using the trained first network model to obtain first predicted triples; wherein the to-be-predicted object includes any one of the head entity, the tail entity and the relationship, and the first network model is used to extract a subgraph from the to-be-completed knowledge graph and decouple the structure of the subgraph.
[0176] The second prediction module 1220 is configured to predict the to-be-predicted object in the to-be-completed knowledge graph by using the trained second network model to obtain second predicted triples; and the second network model is used to determine the to-be-predicted entity according to the common sense knowledge and the entities and relationships in the to-be-completed knowledge graph.
[0177] The completion module 1230 is configured to complete the to-be-completed knowledge graph according to the first predicted triples and the second predicted triples.
[0178] Therefore, the first prediction module 1210 decouples the to-be-completed knowledge graph by using the trained first network model to predict the to-be-predicted object to obtain the first predicted triples; the second prediction module 1220 predicts the to-be-predicted object in the to-be-completed knowledge graph by using the trained second network model according to the common sense knowledge to obtain the second predicted triples; and finally, the completion module 1230 completes the to-be-completed knowledge graph according to the first predicted triples and the second predicted triples, thereby learning from the to-be-completed knowledge graph internally and completing by using the first network model, learning externally and completing by using the second network model according to the common sense knowledge, and improving the comprehensiveness and accuracy of completing the knowledge graph.
[0179] It should be noted that the details of the knowledge graph completion device based on subgraph structure decoupling and common sense transformation in this embodiment are not disclosed, and please refer to the details disclosed in the embodiments of the knowledge graph completion method based on subgraph structure decoupling and common sense transformation in this specification.
[0180] Figure 13 An entity structure schematic diagram of an electronic device is shown as Figure 13As shown, the electronic device can include a processor 1310, a communications interface 1320, a memory 1330, and a communications bus 1340, wherein the processor 1310, the communications interface 1320, and the memory 1330 complete mutual communication through the communications bus 1340. The processor 1310 can invoke a logic instruction in the memory 1330 to execute a knowledge graph completion method based on subgraph structure decoupling and common sense transformation, the method comprising: predicting a to-be-predicted object in a to-be-completed knowledge graph using a trained first network model to obtain a first predicted triple; wherein the to-be-predicted object includes any one of a head entity, a tail entity, and a relationship, and the first network model is used to extract a subgraph from the to-be-completed knowledge graph and decouple the structure of the subgraph; predicting the to-be-predicted object in the to-be-completed knowledge graph using a trained second network model to obtain a second predicted triple; the second network model is used to determine a to-be-predicted entity according to common sense knowledge and entities and relationships in the to-be-completed knowledge graph; and completing the to-be-completed knowledge graph according to the first predicted triple and the second predicted triple.
[0181] In addition, the logic instruction in the memory 1330 described above can be implemented in the form of a software functional unit and sold or used as an independent product, and can be stored in a computer readable storage medium. Based on this understanding, the technical solutions of the present application essentially or the part that contributes to the prior art or part of the technical solutions can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a plurality of instructions to make a computer device (which can be a personal computer, a server, or a network device, etc.) execute all or part of the steps of the method described in various embodiments of the present application. The foregoing storage medium includes: a U disk, a mobile hard disk, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), a magnetic disk or an optical disk, and various program code storage media.
[0182] In another aspect, the present application also provides a computer program product comprising a computer program, which can be stored on a computer readable storage medium, and the computer program can be executed by a processor to enable the computer to perform the knowledge graph completion method based on subgraph structure decoupling and common sense transformation provided by the above-mentioned methods, which comprises: predicting a to-be-predicted object in the knowledge graph to be completed by using a trained first network model to obtain a first predicted triple; wherein the to-be-predicted object comprises any one of a head entity, a tail entity and a relationship, and the first network model is used to extract a subgraph from the knowledge graph to be completed and decouple the structure of the subgraph; predicting the to-be-predicted object in the knowledge graph to be completed by using a trained second network model to obtain a second predicted triple; the second network model is used to determine a to-be-predicted entity according to common sense knowledge and entities and relationships in the knowledge graph to be completed; and completing the knowledge graph to be completed according to the first predicted triple and the second predicted triple.
[0183] In another aspect, the present application also provides a computer readable storage medium having a computer program stored thereon, and the computer program can be executed by a processor to implement the knowledge graph completion method based on subgraph structure decoupling and common sense transformation provided by the above-mentioned methods, which comprises: predicting a to-be-predicted object in the knowledge graph to be completed by using a trained first network model to obtain a first predicted triple; wherein the to-be-predicted object comprises any one of a head entity, a tail entity and a relationship, and the first network model is used to extract a subgraph from the knowledge graph to be completed and decouple the structure of the subgraph; predicting the to-be-predicted object in the knowledge graph to be completed by using a trained second network model to obtain a second predicted triple; the second network model is used to determine a to-be-predicted entity according to common sense knowledge and entities and relationships in the knowledge graph to be completed; and completing the knowledge graph to be completed according to the first predicted triple and the second predicted triple.
[0184] The device embodiments described above are only schematic, wherein the units shown as separate components can or can not be physically separate, and the components shown as units can or can not be physical units, i.e., can be located in one place, or can be distributed on multiple network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the present embodiment scheme. Those skilled in the art can understand and implement without creative labor.
[0185] Those skilled in the art can clearly understand the technical solutions of the various embodiments from the above description of the embodiments, and the various embodiments can be implemented by means of software with the necessary general hardware platforms, and of course, can also be implemented by hardware. Based on such understanding, the above technical solutions, essentially or in other words, the part of the prior art that makes a contribution, can be embodied in the form of a software product, which can be stored in a computer readable storage medium, such as a ROM / RAM, a magnetic disk, an optical disk, and the like, and includes a number of instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in the various embodiments or some parts of the embodiments.
[0186] Finally, it should be noted that: the above embodiments are only used to illustrate the technical solutions of the present application, and not to limit them; although the present application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that: it can still modify the technical solutions recorded in the foregoing embodiments, or make equivalent replacement for some technical features therein; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present application.
Claims
1. A knowledge graph completion method based on subgraph structure decoupling and common sense transformation, characterized in that, include: The trained first network model is used to predict the objects to be predicted in the knowledge graph to be completed, and a first prediction triple is obtained; wherein, the objects to be predicted include any one of head entity, tail entity and relation; the first network model is used to extract subgraphs from the knowledge graph to be completed, and decouple the structure of the subgraphs. The trained second network model is used to predict the objects to be predicted in the knowledge graph to be completed, and a second prediction triple is obtained; the second network model is used to determine the entities to be predicted based on common sense knowledge and the entities and relations in the knowledge graph to be completed. The knowledge graph to be completed is completed based on the first predicted triplet and the second predicted triplet. The training steps for the first network model include: Obtain a first training sample set, which includes a knowledge graph consisting of multiple entities and multiple relations; The first training sample set is subjected to subgraph extraction to obtain a training subgraph. The training subgraph includes at least two entities and at least two relations. The entities include head entities and tail entities. The relations include the relationship to be predicted between the head entities and the tail entities. For any entity in the training subgraph, a distance label is determined for the entity, which represents the distance between the entity and the head entity and the tail entity; Generate initial entity features corresponding to each entity based on the distance labels of each entity; Initialize a relation parameter matrix and a preset number of orthogonal bases. The relation parameter matrix includes each relation of the subgraph, and different orthogonal bases are used to represent different preset semantics. Based on each of the orthogonal bases and the relation parameter matrix, the initial relation features of each relation are obtained; For any entity, the initial entity features of the entity are projected using each of the orthogonal basis vectors to obtain the projection length of the entity under each of the preset semantics. For any entity, based on the entity's projection lengths and orthogonal basis, the intermediate entity features of the entity under each preset semantic meaning are determined; wherein, the intermediate entity features are calculated using the following formula: ; Where A is the set of projection lengths of entity u under different preset semantics, and set A contains a number of preset semantics. i a i M is the projection length of entity u under the i-th preset semantics. base -1 M is the pseudo-inverse of the orthogonal basis matrix. base,i h is the i-th orthogonal basis. u,i Let X be the intermediate entity feature of entity u under the i-th preset semantic. u This is the set of intermediate entity features for entity u under different preset semantics; The intermediate entity features of each entity are updated to obtain the target entity features of each entity under each preset semantics; the initial relation features are updated to obtain the target relation features of each relation under each preset semantics. Based on the target entity features of the head entity, the target entity features of the tail entity, and the target relation features of the relation to be predicted, a training prediction triplet is determined. Determine the total score of the training prediction triplet, determine the first loss value based on the total score using the first preset loss function, and update the parameters of the first network model based on the first loss value until the first network model converges, thus obtaining the trained first network model. The training steps for the second network model include: Obtain a second training sample set, which includes at least two input words with relation labels; The input words with relational labels are input into the second network model to obtain the target word and the probability of predicting it as the target word; The second loss value is calculated using the second preset loss function based on the target word and probability, and the parameters of the second network model are updated based on the second loss value until the second network model converges, thus obtaining the trained second network model.
2. The knowledge graph completion method based on subgraph structure decoupling and common sense transformation according to claim 1, characterized in that, The first network model includes at least two graph neural network layers, and the graph neural network layers are connected sequentially. The step of updating the features of each intermediate entity of each entity to obtain the target entity features of each entity under each preset semantic is as follows: For any intermediate entity feature of any entity, the intermediate entity feature is input from the first graph neural network layer among all the graph neural network layers, the intermediate entity feature is updated through at least two graph neural network layers, and the target entity feature under the preset semantics corresponding to the intermediate entity feature is output from the last graph neural network layer among all the graph neural network layers. The step of updating the initial relation features to obtain the target relation features of each relation under each preset semantic includes: Each initial relation feature is input from the first graph neural network layer among all the graph neural network layers, the initial relation features are updated through at least two graph neural network layers, and the target relation features of each relation under each preset semantic are output from the last graph neural network layer among all the graph neural network layers.
3. The knowledge graph completion method based on subgraph structure decoupling and common sense transformation according to claim 2, characterized in that, Determining the total score of the training predicted triples includes: For any preset semantics, the score of the training prediction triplet under the preset semantics is determined based on the target entity features of the head entity, the target entity features of the tail entity, and the target relation features of the relation to be predicted. Based on the scores of the training prediction triples under each preset semantic and the relation parameter matrix, determine the weights of the scores of the training prediction triples under each preset semantic; The total score of the training prediction triplet is determined based on the score and corresponding weight of the training prediction triplet under each preset semantic.
4. A knowledge graph completion device based on subgraph structure decoupling and common sense transformation, characterized in that, include: The first prediction module is used to predict the objects to be predicted in the knowledge graph to be completed using a trained first network model, and obtain the first prediction triplet; wherein, the objects to be predicted include any one of head entity, tail entity and relation, and the first network model is used to extract subgraphs from the knowledge graph to be completed, and decouple the structure of the subgraphs; The second prediction module is used to predict the objects to be predicted in the knowledge graph to be completed using a trained second network model, and obtain a second prediction triple; the second network model is used to determine the entities to be predicted according to common sense knowledge and based on the entities and relationships in the knowledge graph to be completed. The completion module is used to complete the knowledge graph to be completed based on the first predicted triplet and the second predicted triplet. The first prediction module is further configured to acquire a first training sample set, the first training sample set including a knowledge graph composed of multiple entities and multiple relations; extract a subgraph from the first training sample set to obtain a training subgraph, the training subgraph including at least two entities and at least two relations, the entities including a head entity and a tail entity, the relations including the relationship to be predicted between the head entity and the tail entity; for any entity in the training subgraph, determine the distance label of the entity, the distance label being used to represent the distance between the entity and the head entity and the tail entity; and generate initial entity features corresponding to each entity based on the distance labels of each entity. Initialize the relation parameter matrix and a preset number of orthogonal bases, wherein the relation parameter matrix includes each relation of the subgraph, and different orthogonal bases are used to represent different preset semantics; obtain the initial relation features of each relation based on each orthogonal base and the relation parameter matrix; for any entity, project the initial entity features of the entity using each orthogonal base to obtain the projection length of the entity under each preset semantic; for any entity, determine the intermediate entity features of the entity under each preset semantic based on each projection length of the entity and each orthogonal base; wherein the intermediate entity features are calculated by the following formula: ; Where A is the set of projection lengths of entity u under different preset semantics, and set A contains a number of preset semantics. i a i M is the projection length of entity u under the i-th preset semantics. base -1 M is the pseudo-inverse of the orthogonal basis matrix. base,i h is the i-th orthogonal basis. u,i Let X be the intermediate entity feature of entity u under the i-th preset semantic. u The system is a set of intermediate entity features for entity u under different preset semantics; the intermediate entity features of each entity are updated to obtain the target entity features of each entity under each preset semantics; the initial relation features are updated to obtain the target relation features of each relation under each preset semantics; and training prediction triples are determined based on the target entity features of the head entity, the target entity features of the tail entity, and the target relation features of the relation to be predicted. The second prediction module is further configured to acquire a second training sample set, which includes at least two input words with relational labels; input the input words with relational labels into the second network model to obtain the target word and the probability of predicting it as the target word; calculate a second loss value using a second preset loss function based on the target word and the probability, and update the parameters of the second network model based on the second loss value until the second network model converges to obtain a trained second network model.
5. An electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the knowledge graph completion method based on subgraph structure decoupling and common sense transformation as described in any one of claims 1 to 3.
Citation Information
Patent Citations
Data processing method and device, computer equipment and storage medium
CN114064912A
Knowledge graph completion method based on common sense perception and question answering system
CN116431821A