Knowledge graph rule generation method

By using recurrent neural networks to encode relationship paths in the knowledge graph, combining entity vectors and relationship vectors, optimizing the generation rules solves the problem of lack of hierarchical and structural information in rule generation in the existing technology, and achieves high quality and high scalability. Sexual rule generation, suitable for large-scale maps.

CN118536592APending Publication Date: 2024-08-23SOUTH CHINA UNIV OF TECH
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410741969.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-11
Publication Date
2024-08-23

Smart Images

  • Figure CN118536592A
    Figure CN118536592A
Patent Text Reader

Abstract

The invention discloses a method for generating knowledge graph rules. The method comprises the following steps: initializing vector representations of all entities and relationships in a graph; sampling paths in the knowledge graph, and respectively extracting a relation path and an entity path; using a recurrent neural network to encode the first two relationships of the relationship path as a new relationship, subtracting 1 from the length of the relationship path to obtain entities at the two ends of the first two relationships, taking the difference represented by vectors of the entities at the two ends as a real relationship between the entities, and taking the Euclidean distance between the generated new relationship and the real relationship as a relationship loss; and repeating the steps until only one relation is left in the relation path, performing similarity comparison on the relation and all the relations, obtaining cross entropy loss based on the similarity as prediction loss, and optimizing vector representation and parameters in the network by jointly using the relation loss and the prediction loss. According to the generation method, hierarchical information in the rule body and structural information between entities can be captured, so that a better rule is obtained.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of rule learning in knowledge graph reasoning, and specifically to a method for generating knowledge graph rules. Background Art

[0002] Knowledge graphs provide a structured representation of real-world facts and have a wide range of applications. For example, knowledge graphs are used in search engines to enhance the relevance and accuracy of search results. In recommendation systems, knowledge graphs are used to build users' interpersonal networks and user portraits, thereby providing more personalized content recommendations. In addition, knowledge graphs have considerable practical value in enterprise information management, intelligent question-and-answer systems, health care and other fields.

[0003] Knowledge graphs are imperfect. Traditional query methods may not provide the correct answer in the graph due to the lack of relevant facts. Through reasoning, the knowledge graph can be completed or the correct answer can be obtained in the absence of facts. This is knowledge graph reasoning. Graph reasoning requires rules. The relationship path in the graph is called the rule body. At a certain credibility, a head relationship replaces the rule body, which is the rule head. Finding a high-credibility rule in the graph is knowledge graph rule learning.

[0004] Existing methods encode the connection matrix of the relationships in the graph as a whole, learn the connections between relationships, and then decode to generate relationship paths and corresponding relevance. This method lacks the hierarchy in the relationship path and the structural information between entities, is restricted by the huge rule space, and is not scalable.

[0005] In order to generate higher quality rules for downstream reasoning or completion tasks, it is urgent to propose a method for generating knowledge graph rules. This generation method needs to be able to capture the hierarchical information in the path and the structural information between entities to obtain better rules and can be expanded to large-scale graphs. Summary of the invention

[0006] The purpose of the present invention is to solve the above-mentioned defects in the prior art and provide a method for generating knowledge graph rules.

[0007] The purpose of the present invention can be achieved by adopting the following technical solutions:

[0008] A method for generating knowledge graph rules based on path coding, wherein the knowledge graph is used to construct a user's interpersonal network and user portrait and provide content recommendation, and the generation method comprises the following steps:

[0009] S1. Assign an entity vector and a relationship vector to all entities and relationships in the knowledge graph, respectively. i, i∈[1,|E|] represents the i-th entity vector, r j ,j∈[1,|R|] represents the jth relationship vector, where |E| represents the number of entities and |R| represents the number of relationships;

[0010] S2, acyclic paths in the sampled knowledge graph that pass through the number of relations l∈[2,L] It is required that there is a direct relationship link between the start entity and the end entity of the acyclic path. This relationship link is called the head relationship. h , sequentially extract acyclic paths The relationship in forms a relationship path with a length of l Relationship Path The length of is the same as the number of relations in the acyclic path, and the acyclic path is extracted The entity in the form a solid path with a length of l+1 Represent the 1st, 2nd, ..., lth relations respectively, Represent the 1st, 2nd,…,l+1th entities respectively;

[0011] S3, set the current cycle round k = 1, use the recurrent neural network to the first pair of adjacent relationships in the relationship path Encoding, the obtained fusion representation r mix ;

[0012] S4. Get Entities at both ends and For relationship The starting entity, For relationship The end entity of Get vector r t , calculate r t With r mix The Euclidean distance between them, let the Euclidean distance be the loss loss_rel_k, and use fusion to represent r mix replace delete

[0013] S5, repeat steps S3 and S4 l-1 times, each cycle process, the initial value of the relationship path length is l The length is reduced by 1 until only one encoded relation remains in the relation path. The similarity is compared with all relations in the knowledge graph. The cross entropy loss loss_pre is obtained based on the similarity. At the same time, the loss loss_rel_k, k∈[1,l-1], obtained by looping through step S4 is calculated. loss_rel is the mean of loss_rel_k;

[0014] S6. Calculate the weighted optimization loss loss through loss_rel and loss_pre, and optimize the representation vectors of entities and relationships and the parameters of the recurrent neural network.

[0015] S7. Traverse all possible relationship paths within the length M in the knowledge graph, execute steps S1 to S5 for each relationship path to obtain the similarity between the fusion representation corresponding to the relationship path encoding and all the relationships in the knowledge graph, select the k relationships with the highest similarity as the head relationships, and the similarity corresponding to the head relationships as the credibility, and the head relationship, credibility and relationship path together constitute a learned rule.

[0016] Furthermore, the knowledge graph and knowledge graph rule generation are defined as follows:

[0017] The knowledge graph is defined as g = {E, R, O}, which contains entity set E, relationship set R and fact set O. Facts in the fact set are represented by r(h, t), h, t∈E, r()∈R, where h represents the head entity, h represents the tail entity, and r() represents the relationship from the head entity to the tail entity.

[0018] The rules in the knowledge graph consist of head relations and relation paths. Rule learning is used to learn chain combination rules in the following form: s(r h ,r s )∈[0,1] is the confidence corresponding to the rule, r h (x,y) is called the head relation, It is called a relationship path. Combining the head relationship and the relationship path, a rule is defined as

[0019] Knowledge graph rule generation aims to generate a rule for each rule (r h ,r b ) Learn the confidence score s(r h ,r b ).

[0020] Furthermore, the process of step S3 is as follows:

[0021] S31, the current cycle is the kth round, and the relationship path is Construct, and take out the first pair of adjacent relationship pairs

[0022] S32, As input, the operation function RNN() of the recurrent neural network is used as output: in It's a relationship The hidden state of the last hidden state is often used to represent the hidden state of the entire sequence. As The fusion representation of recurrent neural network was proposed by Mike Schuster and Kuldip K Paliwal in the 1997 paper Bidirectional recurrent neural networks, which can be used to encode sequence information.

[0023] Furthermore, the process of step S4 is as follows:

[0024] S41, the current cycle is the kth cycle, and the adjacent relationship pairs encoded in this cycle are The entity path corresponding to the relationship path Select the corresponding two end entities

[0025] S42, by subtracting the entity vectors at both ends Get vector r t , calculate r t The encoding r of the relation pair to be recursively fused mix The Euclidean distance between them is used as the loss loss_rel_k, and a loss_rel_k is obtained for each cycle;

[0026] S43, use r mix replace Delete at the same time

[0027] Furthermore, the process of step S5 is as follows:

[0028] Loop through steps S3 and S4, and reduce the length of the relationship path by 1 each time until there is only one encoded relationship left in the relationship path. It is natural to conclude that the loop is performed l-1 times in total, and loss_rel_k can be obtained in each loop, k∈[1,l-1], and calculated That is, the average value of loss_rel_k;

[0029] Calculate the last remaining relationship in the relationship path and compare it with all relationships to get the similarity measure [φ1,φ2,...,φ r ,...,φ |R| ], |R| represents the number of relations in the knowledge graph relation set, and the predicted cross entropy loss is obtained based on the similarity metric: in is the rth one-hot encoding.

[0030] Furthermore, the calculation formula of the weighted optimization loss in step S6 is as follows:

[0031] loss=loss_pre+β*loss_rel

[0032] Among them, β is a hyperparameter used to optimize the weighted control.

[0033] Compared with the prior art, the present invention has the following advantages and effects:

[0034] 1. The present invention designs a method for generating knowledge graph rules, which uses a recurrent neural network to cyclically encode the first two relationships in the encoded relationship path into one relationship. Each cycle reduces one relationship in the relationship path, and finally encodes the relationship path into one relationship. This method uses the encoding ability of the recurrent neural network for sequences and balances the number of parameters of the network so as not to overfit, thereby generating higher quality rules;

[0035] 2. Based on the cyclic coding relationship path, the present invention adds entities to constrain the relationship path encoding and integrates the structural information between entities, thereby generating higher quality rules. BRIEF DESCRIPTION OF THE DRAWINGS

[0036] The drawings described herein are used to provide a further understanding of the present invention and constitute a part of this application. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the drawings:

[0037] Figure 1 It is a flowchart of a method for generating knowledge graph rules disclosed in the present invention;

[0038] Figure 2 It is an overall schematic diagram of the model of the present invention during training;

[0039] Figure 3 is a schematic diagram of steps S3 and S4 of the present invention during training;

[0040] Figure 4 It is an overall schematic diagram of the model of the present invention when generating rules;

[0041] Figure 5 It is a schematic diagram of step S3 of the present invention when generating rules. DETAILED DESCRIPTION

[0042] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0043] Example 1

[0044] This embodiment discloses a method for generating knowledge graph rules based on path coding. The knowledge graph is used to construct a user's interpersonal network and user portrait, and provide content recommendations, such as Figure 1 As shown in the flowchart of a method for generating knowledge graph rules, the generation method includes the following steps:

[0045] S1. Assign an entity vector and a relationship vector to all entities and relationships in the knowledge graph, respectively. i , i∈[1,|E|] represents the i-th entity vector, r j ,j∈[1,|R|] represents the jth relationship vector, where |E| represents the number of entities and |R| represents the number of relationships; the knowledge graph and knowledge graph rule generation are defined as follows:

[0046] The knowledge graph is defined as g = {E, R, O}, which contains entity set E, relationship set R and fact set O. Facts in the fact set are represented by r(h, t), h, t∈E, r()∈R, where h represents the head entity, h represents the tail entity, and r() represents the relationship from the head entity to the tail entity.

[0047] The rules in the knowledge graph consist of head relations and relation paths. Rule learning is used to learn chain combination rules in the following form: Among them, s(r h ,r s )∈[0,1] is the confidence corresponding to the rule, r h (x,y) is called the head relation, It is called a relationship path. Combining the head relationship and the relationship path, a rule is defined as

[0048] Knowledge graph rule generation aims to generate a rule for each rule (r h ,r b ) Learn the confidence score s(r h ,r b ).

[0049] S2, acyclic paths in the sampled knowledge graph that pass through the number of relations l∈[2,L] It is required that there is a direct relationship link between the start entity and the end entity of the acyclic path. This relationship link is called the head relationship. h , sequentially extract acyclic paths The relationship in forms a relationship path with a length of l Relationship Path The length of is the same as the number of relations in the acyclic path, and the acyclic path is extracted The entity in the form a solid path with a length of l+1 Represent the 1st, 2nd, ..., lth relations respectively, Represent the 1st, 2nd,…,l+1th entities respectively.

[0050] S3, set the current cycle round k = 1, use the recurrent neural network to the first pair of adjacent relationships in the relationship path Encoding, the obtained fusion representation r mix ;

[0051] In this embodiment, the process of step S3 is as follows:

[0052] S31, the current cycle is the kth round, and the relationship path is Construct, and take out the first pair of adjacent relationship pairs

[0053] S32, As input, the operation function RNN() of the recurrent neural network is used as output: in It's a relationship The hidden state of the last hidden state is often used to represent the hidden state of the entire sequence. As The fusion representation of recurrent neural network was proposed by Mike Schusterand Kuldip K Paliwal in the 1997 paper Bidirectional recurrent neural networks, which can be used to encode sequence information.

[0054] S4. Get Entities at both ends and For relationship The starting entity, For relationship The end entity of Get vector r t , calculate r t With r mix The Euclidean distance between them, let the Euclidean distance be the loss loss_rel_k, and use fusion to represent r mix replace delete

[0055] In this embodiment, the specific implementation process of step S4 is as follows:

[0056] S41, the current cycle is the kth cycle, and the adjacent relationship pairs encoded in this cycle are The entity path corresponding to the relationship path Select the corresponding two end entities

[0057] S42, by subtracting the entity vectors at both ends Get vector r t , calculate r t The encoding r of the relation pair to be recursively fused mix The Euclidean distance between them is used as the loss loss_rel_k, and a loss_rel_k is obtained for each cycle;

[0058] S43, use r mix replace Delete at the same time

[0059] S5, repeat steps S3 and S4 l-1 times, each cycle process, the initial value of the relationship path length is l The length is reduced by 1 until only one encoded relation remains in the relation path. The similarity is compared with all relations in the knowledge graph. The cross entropy loss loss_pre is obtained based on the similarity. At the same time, the loss loss_rel_k, k∈[1,l-1], obtained by looping through step S4 is calculated. loss_rel is the mean of loss_rel_k;

[0060] In this embodiment, the specific implementation process of step S5 is as follows:

[0061] Loop through steps S3 and S4, and reduce the length of the relationship path by 1 each time until there is only one encoded relationship left in the relationship path. It is natural to conclude that the loop is performed l-1 times in total, and loss_rel_k can be obtained in each loop, k∈[1,l-1], and calculated That is, the average value of loss_rel_k;

[0062] Calculate the last remaining relationship in the relationship path and compare it with all relationships to get the similarity measure [φ1,φ2,...,φ r ,...,φ |R| ], |R| represents the number of relations in the knowledge graph relation set, and the predicted cross entropy loss is obtained based on the similarity metric: in is the rth one-hot encoding.

[0063] S6. Calculate the weighted optimization loss loss through loss_rel and loss_pre, and optimize the representation vectors of entities and relationships and the parameters of the recurrent neural network.

[0064] The calculation formula of the weighted optimization loss in step S6 is as follows:

[0065] loss=loss_pre+β*loss_rel

[0066] Among them, β is a hyperparameter used to optimize the weighted control.

[0067] S7. Traverse all possible relationship paths within the length M in the knowledge graph, execute steps S1 to S5 for each relationship path to obtain the similarity between the fusion representation corresponding to the relationship path encoding and all the relationships in the knowledge graph, select the k relationships with the highest similarity as the head relationships, and the similarity corresponding to the head relationships as the credibility, and the head relationship, credibility and relationship path together constitute a learned rule.

[0068] like Figure 2 , Figure 2 is a general schematic diagram of the model during training in this embodiment; wherein the relation path and entity path sampled in step S2 are input, a single relation after encoding the first two relations in step S3 is obtained, and the relation loss in step S4 is obtained. The implementation of encoding can be referred to Figure 3 ; Loop through the first two relations in the relation path, and reduce one relation in each loop until the relation path is encoded as a single relation. The single relation is compared with all relations in the graph for similarity, and then the cross entropy loss is calculated together with the head relation of the fact as the prediction loss; each loop will get a relation loss, calculate the mean of the relation loss, and optimize the vector representation of entities and relations and the recurrent neural network in step S3 together with the prediction loss.

[0069] In this embodiment, steps S3 and S4 are in the process of model training as follows: Figure 3 As shown in the figure, different from when the model is used for rule generation, the sampled path in the input graph during model training includes specific entities, and the relationship path is encoded by the recurrent neural network RNN ​​in step S3, encoding the first two relationships as a single relationship and replacing the first two relationships; the difference between the vector representations of the entities at both ends of the first two relationships is regarded as the vector representation of the factual relationship between the two entities, and the Euclidean distance is calculated with the single relationship after encoding the first two relationships as the relationship loss.

[0070] like Figure 4 , Figure 4This is the overall schematic diagram of the model in this embodiment when generating rules; unlike during training, the input when the model generates rules does not contain entity paths, but only all possible relationship paths within a specific length. In step S3, a relationship path is input, and the first two relationships are encoded as a single relationship; the first two relationships are encoded cyclically until the relationship path is encoded as a single relationship, and the single relationship is matched with all relationships in the graph for similarity, and the k with the highest similarity are selected as the head relationship corresponding to the relationship path. The relationship path and the corresponding head relationship are then combined into a learned rule, and the similarity is regarded as the credibility of the rule;

[0071] In this embodiment, the process of step S3 when generating rules is as follows Figure 5 As shown, unlike during training, the input does not contain an entity path; the relationship path is input into the step S3 block, and the recurrent neural network RNN ​​described in step S3 is used to encode the first two as a single relationship. Unlike during training, there is no entity path, and naturally there will be no loss based on the entity.

[0072] Example 2

[0073] Based on Example 1, this example uses a training sample and a corresponding label and a rule learning task to specifically demonstrate how to train a model and complete the generation of rules through the trained model.

[0074] First, the training samples.

[0075] The training sample is the acyclic path sampled in step S2, in the form of Ann->hasMother->Bella->hasMother->Caral->hasSon->Dylen. For the sake of understanding, a fictitious sample is used here. At the same time, the corresponding label is the head relationship hasUncle in step S2, which is the real connection relationship between the start entity and the end entity of the acyclic path. The intuitive understanding is that there is such a path in the graph, where Ann's mother is Bella, and Bella's mother is Caral, Caral has a son Dylen, and Ann's uncle is Dylen. This is a very common family relationship.

[0076] Then, extract the relationship path, and extract the relationship path [hasMother, hasMother, hasSon] in the acyclic path.

[0077] Execute steps S3 and S4.

[0078] Current cycle round k = 1:

[0079] The first two relations are encoded through a recurrent neural network, that is, the relation [hasMother, hasMother] is encoded as r_mix.

[0080] Get the entities at both ends of the first two relations, namely Ann and Caral, get the vector representations of the two entities e_Ann and e_Caral, calculate r_t = e_Ann-e_Caral, and then calculate the Euclidean distance between r_t and r_mix, and let the Euclidean distance be loss_rel_1. At the same time, replace the first relation hasMother with r_mix and delete the second relation hasMother.

[0081] Current cycle k = 2:

[0082] The relationship path is [r_mix, hasSon].

[0083] The first two relations are encoded through a recurrent neural network, that is, the relation [r_mix, hasSon] is encoded as r_mix'.

[0084] Get the entities at both ends of the first two relations, namely Ann and Dylen, get the vector representations e_Ann and e_Dylen, calculate r_t = e_Ann-e_Dylen, and then calculate the Euclidean distance between r_t and r_mix', and let the Euclidean distance be loss_rel_2. At the same time, replace the first relation r_mix with r_mix' and delete the second relation hasSon.

[0085] At this point, there is only one encoded relation r_mix' left in the relation path, and the losses loss_rel_1 and loss_rel_2 in the two cycles are obtained. Loss_rel = mean(loss_rel_k), that is, the average value, is calculated. At the same time, r_mix' is measured for similarity with all relations in the knowledge graph, and the cross entropy is calculated based on the similarity with all relations as the prediction loss loss_pre.

[0086] The weighted optimization loss loss is calculated according to the following formula: loss = loss_pre + β * loss_rel, where β is a hyperparameter used to optimize weighted control.

[0087] The representation vectors of entities and relationships and the parameters of the recurrent neural network are optimized through back-propagation, thus completing the training of a training sample.

[0088] Next, we generate rules and demonstrate the rule generation process through a relationship path example. The relationship path is [hasMother, hasMother, hasSon].

[0089] Step S4 is not required during rule generation:

[0090] By looping step S3, the first two relations are encoded into a single relation each time.

[0091] The first loop round changes the relationship path [hasMother, hasMother, hasSon] to [r_mix, hasSon].

[0092] The second loop round changes [r_mix,hasSon] to [r_mix'].

[0093] At this point, only one encoded relation r_mix' remains, and the loop ends.

[0094] Calculate the similarity between r_mix' and all the relations in the graph. If good training results are obtained during training, the model makes r_mix' very close to hasUncle. Assuming that the previous relation with the highest similarity is taken as the head relation, then for the relation path [hasMother, hasMother, hasSon], a rule hasUncle←hasMother∧hasMother∧hasSon will be obtained, and the similarity between the head relation and r_mix' is regarded as the confidence of the rule.

[0095] The above embodiments are preferred implementation modes of the present invention, but the implementation modes of the present invention are not limited to the above embodiments. Any other changes, modifications, substitutions, combinations, and simplifications that do not deviate from the spirit and principles of the present invention should be equivalent replacement methods and are included in the protection scope of the present invention.

Claims

1. A method for generating knowledge graph rules based on path coding, the knowledge graph is used to construct a user's interpersonal network and user portrait, and provide content recommendation, characterized in that: The generation method comprises the following steps: S1. Assign an entity vector and a relationship vector to all entities and relationships in the knowledge graph, respectively. i , i∈[1,|E|] represents the i-th entity vector, r j ,j∈[1,|R|] represents the jth relationship vector, where |E| represents the number of entities and |R| represents the number of relationships; S2, the acyclic path [e b1 ,r b1 ,e b2 ,r b2 ,e b3 ,...,e bl ,r bl ,e bl+1 ], requiring that there is a direct relationship link between the start entity and the end entity of the acyclic path, and this relationship link is called the head relationship r h , sequentially extract acyclic paths [e b1 ,r b1 ,e b2 ,r b2 ,e b3 ,...,e bl ,r bl ,e bl+1 ], forming a relationship path with a length of l [r b1 ,r b2 ,...,r bl ], relation path [r b1 ,r b2 ,...,r bl ] has the same length as the number of relations in the acyclic path, and the acyclic path [e b1 ,r b1 ,e b2 ,r b2 ,e b3 ,...,e bl ,r bl ,e bl+1 ], forming a physical path with a length of l+1 [e b1 ,e b2 ,...,e bl+1 ],r b1 ,r b2 ,...,r bl Respectively represent the 1st, 2nd, ..., lth relationship, e b1 ,e b2 ,...,e bl+1 Represent the 1st, 2nd,…,l+1th entities respectively; S3, set the current cycle round k = 1, use the recurrent neural network to the first pair of adjacent relations in the relationship path [r b1 ,r bk+1 ] is encoded, and the obtained fusion representation r mix ; S4, get [r b1 ,r bk+1 ]Entities at both ends b1 and e bk+2 , e b1 For the relationship [r b1 ,r bk+1 ]'s start entity, e bk+2 For the relationship [r b1 ,r bk+1 ], by calculating r t =e bk+2 -e b1 Get vector r t , calculate r t With r mix The Euclidean distance between them, let the Euclidean distance be loss_rel_k, and use fusion to represent r mix Replace r b1 , delete r bk+1 ; S5, repeat steps S3 and S4 l-1 times, each cycle process, the initial value of the relationship path length is l The length is reduced by 1 until only one encoded relation remains in the relation path. The similarity is compared with all relations in the knowledge graph. The cross entropy loss loss_pre is obtained based on the similarity. At the same time, the loss loss_rel_k, k∈[1,l-1], obtained by looping through step S4 is calculated. loss_rel is the mean of loss_rel_k; S6. Calculate the weighted optimization loss loss through loss_rel and loss_pre, and optimize the representation vectors of entities and relationships and the parameters of the recurrent neural network. S7. Traverse all possible relationship paths within the length M in the knowledge graph, execute steps S1 to S5 for each relationship path to obtain the similarity between the fusion representation corresponding to the relationship path encoding and all the relationships in the knowledge graph, select the k relationships with the highest similarity as the head relationships, and the similarity corresponding to the head relationships as the credibility, and the head relationship, credibility and relationship path together constitute a learned rule.

2. According to claim 1, a method for generating knowledge graph rules based on path coding is characterized in that: The knowledge graph and knowledge graph rule generation are defined as follows: The knowledge graph is defined as g = {E, R, O}, which contains entity set E, relationship set R and fact set O. Facts in the fact set are represented by r(h, t), h, t∈E, r()∈R, where h represents the head entity, h represents the tail entity, and r() represents the relationship from the head entity to the tail entity. The rules in the knowledge graph are composed of head relations and relation paths, and rule learning is used to learn chain combination rules; Knowledge graph rule generation aims to learn a confidence score for each rule in the knowledge graph.

3. According to the method for generating knowledge graph rules based on path coding according to claim 1, it is characterized in that: The process of step S3 is as follows: S31, the current cycle is the kth round, and the relationship path is Construct, and take out the first pair of adjacent relationship pairs S32, As input, the operation function RNN() of the recurrent neural network is used as output: in It's a relationship The hidden state of the last hidden state is often used to represent the hidden state of the entire sequence. As The fusion representation of mix .

4. According to claim 3, a method for generating knowledge graph rules based on path coding is characterized in that: The process of step S4 is as follows: S41, the current cycle is the kth cycle, and the adjacent relationship pairs encoded in this cycle are The entity path corresponding to the relationship path Select the corresponding two end entities S42, by subtracting the entity vectors at both ends Get vector r t , calculate r t The encoding r of the relation pair to be recursively fused mix The Euclidean distance between them is used as the loss loss_rel_k, and a loss_rel_k is obtained for each cycle; S43, use r mix replace Delete at the same time 5. According to claim 1, a method for generating knowledge graph rules based on path coding is characterized in that: The process of step S5 is as follows: Loop through steps S3 and S4, and reduce the length of the relationship path by 1 each time until there is only one encoded relationship left in the relationship path. Loop through l-1 times in total, and get loss_rel_k each time, k∈[1,l-1], and calculate That is, the average value of loss_rel_k; Calculate the last remaining relationship in the relationship path and compare it with all relationships to get the similarity measure [φ1,φ2,...,φ r ,...,φ |R| ], |R| represents the number of relations in the knowledge graph relation set, and the predicted cross entropy loss is obtained based on the similarity metric: in is the rth one-hot encoding.

6. According to claim 1, a method for generating knowledge graph rules based on path coding is characterized in that: The calculation formula of the weighted optimization loss in step S6 is as follows: loss=loss_pre+β*loss_rel Among them, β is a hyperparameter used to optimize the weighted control.