Knowledge graph induction relation prediction method and device based on relation perception
By extracting and filtering relationship paths from the knowledge graph, generating relationship-aware reasoning neighbors and combining language models for prediction, we solve the problem of inability to accurately predict relationships in the existing technology and achieve more accurate inductive relationship predictions.
Patent Information
- Application Number
- CN202410855446.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-28
- Publication Date
- 2024-10-01
AI Technical Summary
Existing knowledge graph completion methods are difficult to determine effective relationship neighbors in inductive relationship prediction, resulting in inability to obtain accurate inductive relationship prediction results.
By extracting relationship paths from the knowledge graph, calculating path confidence, filtering out high-confidence paths as reasoning paths, generating relationship-aware reasoning neighbors, and combining hard prompts and soft prompts to input language models for prediction.
Being able to identify effective relational neighbors improves the accuracy of inductive relational predictions.
Smart Images

Figure CN118734972A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of machine learning, and specifically relates to a relationship-aware knowledge graph induction relationship prediction method and device. Background Art
[0002] Knowledge graph is a structured semantic network knowledge base consisting of entities, relations and attributes. In the Resource Description Framework (RDF), knowledge can be expressed as fact triples in the form of (head, relation, tail), where head and tail represent the head entity and tail entity respectively, and relation represents the relationship between the head entity and the tail entity.
[0003] The task of knowledge graph completion aims to predict missing relations in knowledge graphs, which is crucial for applications such as information retrieval, recommender systems, and natural language processing. Inductive relation prediction is a more challenging task in knowledge graph completion, which requires the model to be able to predict relations between entity pairs that have not been seen in the training data. The difficulty of this task lies in the fact that the model needs to have good generalization ability so that it can infer new relation instances, rather than simply learning patterns from the training data.
[0004] Existing knowledge graph completion methods mainly include embedding-based methods, path-based methods, graph-based methods and pre-trained language model-based methods.
[0005] Embedding-based models, such as TransE and DistMult, learn representations of entities and relations by mapping them into low-dimensional vector spaces. These models usually assume that the interactions between entities and relations can be captured by vector operations, but this approach cannot fully express complex semantic information. Path ranking algorithms, such as Path Ranking Algorithm (PRA), predict possible relationships between entity pairs by analyzing the paths between them. This approach can capture the relationships between entities, but its performance may be limited when there is a lack of direct paths between entity pairs. Graph-based methods such as graph convolutional networks (GCNs) and graph attention networks (GATs) extract subgraphs containing target triples and use GNN message passing to learn representations of nodes and edges. These methods are able to exploit the structural information of the entire knowledge graph, but they encounter problems with computational efficiency and scalability when processing large-scale graph data. Recently, pre-trained language models such as BERT and GPT have achieved great success in the field of natural language processing, and their powerful semantic understanding capabilities have also been introduced into knowledge graph completion. These models predict relationships by treating the paths between entity pairs as text sequences and extracting features using Pretrain Language Models (PLMs). However, these methods still lack in handling path-less situations and learning comprehensive representations of relations.
[0006] For example, we want to predict the target triplet (A, occupation, director), and assume that the path between A and director is missing. By analyzing A's related neighbor triplets, such as (A, directed, Movie) and (A, won, Oscar), we can infer (A, occupation, director). Therefore, analyzing the neighbor triplets around an entity helps to infer the target triplet. However, the contributions of neighbors associated with the head and tail entities are not equal. Some neighbors can provide strong supporting information, while others may be noisy and unreliable. For example, (A, lives in, the United States) cannot provide strong clues for predicting (A, occupation, director). Therefore, determining effective relational neighbors is an important and challenging task.
[0007] In short, the existing inductive relationship prediction methods are still unable to determine effective relationship neighbors, and thus cannot obtain accurate inductive relationship prediction results. Summary of the invention
[0008] The present invention is made to solve the above-mentioned problems, and its purpose is to provide a relationship-aware knowledge graph induction relationship prediction method and device.
[0009] The present invention provides a relationship-aware knowledge graph inductive relationship prediction method, which is used to obtain corresponding inductive relationship prediction results according to a question containing a target triple (h, r, t) and a knowledge graph, and has the following characteristics, including the following steps: step S1, extracting a relationship path from the knowledge graph according to a head entity h and a tail entity t; step S2, calculating the relationship path confidence corresponding to each relationship path; step S3, screening out the relationship paths corresponding to the relationship path confidences less than a preset relationship path confidence threshold, and taking the remaining relationship paths as reasoning paths; step S4, judging whether the reasoning path is empty, and if so, executing step S5, If not, the reasoning path is used as the reasoning information, and step S6 is executed; step S5, according to the head entity h, the tail entity t and the knowledge graph, the relationship-aware reasoning neighbor RN is obtained as the reasoning information; step S6, a hard prompt q is generated according to the question, adaptive information c is generated according to the reasoning information, and a soft prompt v corresponding to the relationship r is generated according to the relationship matrix; step S7, the soft prompt v, the hard prompt q and the adaptive information c are concatenated, and the concatenation result is input into the language model to obtain the inductive relationship prediction result, wherein the inductive relationship prediction result is that the target triple (h, r, t) is correct or the target triple (h, r, t) is incorrect.
[0010] The relationship-aware knowledge graph induction relationship prediction method provided by the present invention may also have the following feature: wherein, in step S1, the path between the head and tail entities is extracted by a breadth-first search algorithm.
[0011] In the relationship-aware knowledge graph induction relationship prediction method provided by the present invention, there may also be such a feature: wherein the calculation expression of the relationship path confidence is: Where R p is the logical reasoning path of the relation combination, There is a logical reasoning path R from entity h to t p The relationship path confidence, E G -{h} removes the head entity h from the entity set. For a logical reasoning path R p The number of triplets.
[0012] The relationship-aware knowledge graph induction relationship prediction method provided by the present invention may also have the following characteristics: wherein the calculation expression of the relationship-aware reasoning neighbor RN is: Where R h′ is the reliable relation set of the head entity h, For the ownership relationship h The set of triples whose entity is h, R t′ is the reliable relation set of tail entity t, For the ownership relationship tThe set of triples whose entity is t, R h is the neighbor relationship set of the head entity h, To filter the set by the first threshold The set of relations whose contribution scores are lower than the first threshold, is the set of relations associated with the head entity in the set of triples containing relation r, R t is the neighbor relationship set of the tail entity t, To filter the set by the second threshold The relationship set after the contribution score is lower than the second threshold, the set is the set of relations associated with the tail entity in the set of triples containing relation r.
[0013] The relationship-aware knowledge graph induction relationship prediction method provided by the present invention may also have the following characteristics: wherein the relationship r i The contribution score p(r|r i ) is calculated as: Where R is the set of all relations in the knowledge graph, |D r | is the set D of triples containing relation r r The number of the three ancestors in the middle To appear in set D r The collection of head entities in , For the relationship i With entity The relative frequency of the associated relationship, f inv is the inverse frequency, For entity e and relation r∈R e The relative frequency, R e is the set of relations related to entity e, is the number of relations r associated with entity e.
[0014] In the relationship-aware knowledge graph induction relationship prediction method provided by the present invention, it can also have the following characteristics: wherein the expression of the splicing result is: z = [e([CLS])ve(q)e([SEP])e(c)], where z is the splicing result and e(·) is the vector embedding operation.
[0015] In the relationship-aware knowledge graph induction relationship prediction method provided by the present invention, there may also be such a feature: wherein, in step S7, when the reasoning information is a reasoning path, each reasoning path is used as the reasoning information to generate a corresponding splicing result, and the language model is based on the splicing result corresponding to the i-th reasoning path Generate the corresponding predicted probability pro i , predicted probability pro iThe calculation expression is: Where N is the total number of reasoning paths, y∈{0,1} is the class label, and the inductive relationship prediction result is obtained based on the final score score(h,r,t) of the target triple (h,r,t). The calculation expression of the final score score(h,r,t) is:
[0016] The relationship-aware knowledge graph inductive relationship prediction method provided by the present invention may also have the following characteristics: wherein, a training data set is constructed based on existing data to train the initial language model and the initial relationship matrix, and the parameters of the initial relationship matrix and the initial language model are iteratively updated to obtain the trained initial language model as the language model and the trained initial relationship matrix as the relationship matrix.
[0017] The relationship-aware knowledge graph induction relationship prediction method provided by the present invention may also have the following characteristics: wherein, in the training, the calculation expression of the j-th layer of the initial language model is: Where LM θ (·) is the forward function of the initial language model, and j=0 corresponds to the input layer. is the i-th soft hint vector specific to relation r, k is the total number of soft hint vectors specific to relation r, is the representation vector of the j-1th layer model, To represent the vector After the LM function, the i-th dimension vector represents z i is the i-th dimension vector of the concatenated result.
[0018] The present invention provides a relationship-aware knowledge graph inductive relationship prediction device, which is used to obtain corresponding inductive relationship prediction results based on questions and knowledge graphs containing target triples (h, r, t), and has the following characteristics, including: a path extraction module, a path confidence calculation module, a reasoning path generation module, a judgment module, a neighbor generation module, an embedding generation module and a prediction module, wherein the path extraction module is used to extract relationship paths from the knowledge graph according to the head entity h and the tail entity t, the path confidence calculation module is used to calculate the relationship path confidence corresponding to each relationship path, and the reasoning path generation module stores a preset relationship path confidence threshold, which is used to screen out relationship paths corresponding to relationship path confidences less than the relationship path confidence threshold, and use the remaining relationship paths as reasoning paths. The path, judgment module is used to determine whether the reasoning path is empty. If so, the neighbor generation module is executed. If not, the reasoning path is used as reasoning information and the embedding generation module is executed. The neighbor generation module is used to obtain the relationship-aware reasoning neighbor RN as reasoning information based on the head entity h, the tail entity t and the knowledge graph. The embedding generation module is used to generate a hard prompt q according to the question, generate adaptive information c according to the reasoning information, and generate a soft prompt v corresponding to the relationship r according to the relationship matrix. The prediction module includes a language model, which is used to splice the soft prompt v, the hard prompt q and the adaptive information c, and input the splicing result into the language model to obtain the inductive relationship prediction result. The inductive relationship prediction result is that the target triple (h, r, t) is correct or the target triple (h, r, t) is incorrect.
[0019] Functions and Effects of the Invention
[0020] According to the relationship-aware knowledge graph inductive relationship prediction method and device involved in the present invention, since the relationship path is extracted from the knowledge graph, and the reasoning path is obtained according to the relationship path confidence threshold and the relationship path confidence screening, when the reasoning path is empty, the relationship-aware reasoning neighbor RN, that is, the relationship neighbor is generated according to the knowledge graph as the reasoning information, and then the hard prompt generated by the question, the adaptive information generated by the reasoning information, and the soft prompt generated by the relationship matrix are spliced and input into the language model, thereby obtaining the inductive relationship prediction result of the question. Therefore, the relationship-aware knowledge graph inductive relationship prediction method and device of the present invention can determine the effective relationship neighbors and obtain accurate inductive relationship prediction results. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] Figure 1 is a block diagram of a knowledge graph induction relationship prediction device in an embodiment of the present invention;
[0022] Figure 2 is a schematic diagram of the structure of the knowledge graph A in an embodiment of the present invention;
[0023] Figure 3is a schematic diagram of the structure of the knowledge graph B in an embodiment of the present invention;
[0024] Figure 4 Schematic diagram of the working principle of the language model for inductive relationship prediction in an embodiment of the present invention;
[0025] Figure 5 It is a flow chart of a relationship-aware knowledge graph induction relationship prediction method in an embodiment of the present invention. DETAILED DESCRIPTION
[0026] In order to make the technical means, creative features, objectives and effects achieved by the present invention easy to understand, the following embodiments and the accompanying drawings specifically illustrate the relationship-aware knowledge graph induction relationship prediction method and device of the present invention.
[0027] In this embodiment, a relationship-aware knowledge graph inductive relationship prediction device is provided, which is used to obtain the corresponding inductive relationship prediction result according to the question and knowledge graph containing the target triple (h, r, t). In this embodiment, the knowledge graph KG is represented by G = (E, R, D), where G is the knowledge graph KG, E is the entity set, R is the relationship set, and D = {(h, r, t) | h, t∈E, r∈R} represents the triple in G.
[0028] Figure 1 It is a block diagram of a knowledge graph induction relationship prediction device in an embodiment of the present invention.
[0029] like Figure 1 As shown, the knowledge graph inductive relationship prediction device 100 includes a path extraction module 10, a path confidence calculation module 20, an inference path generation module 30, a judgment module 40, a neighbor generation module 50, an embedding generation module 60, a prediction module 70 and a control module 80 for controlling the operation of the above modules.
[0030] The path extraction module 10 is used to extract the relationship path from the knowledge graph according to the head entity h and the tail entity t.
[0031] Among them, in the path extraction module 10, the path between the head and tail entities is extracted by using a breadth-first search algorithm.
[0032] The path confidence calculation module 20 is used to calculate the relationship path confidence corresponding to each relationship path.
[0033] Among them, the calculation expression of the relationship path confidence is:
[0034]
[0035] Where R p The logical reasoning path for the relationship combination, e.g. There is a logical reasoning path R from entity h to t p The relationship path confidence, E G -{h} removes the head entity h from the entity set. For a logical reasoning path R p The number of triplets.
[0036] The reasoning path generation module 30 stores a preset relationship path confidence threshold, which is used to filter out relationship paths corresponding to relationship path confidences less than the relationship path confidence threshold, and use the remaining relationship paths as reasoning paths.
[0037] In this embodiment The higher the confidence value, the more reliable the corresponding relationship path. Therefore, by setting the relationship path confidence threshold, reliable relationship paths are screened out as reasoning paths for subsequent inductive relationship prediction of target triples.
[0038] The judgment module 40 is used to judge whether the reasoning path is empty. If so, the neighbor generation module 50 is executed. If not, the reasoning path is used as reasoning information and the embedding generation module 60 is executed.
[0039] The neighbor generation module 50 is used to obtain the relationship-aware reasoning neighbor RN as reasoning information based on the head entity h, the tail entity t and the knowledge graph.
[0040] Among them, the calculation expression of the relationship-aware reasoning neighbor RN is:
[0041]
[0042] Where R h′ is the reliable relation set of the head entity h, For the ownership relationship h The set of triples whose entity is h, R t′ is the reliable relation set of tail entity t, For the ownership relationship t The set of triples whose entity is t, R h is the neighbor relationship set of the head entity h, To filter the set by the first threshold The set of relations whose contribution scores are lower than the first threshold, is the set of relations associated with the head entity in the set of triples containing relation r, R t is the neighbor relationship set of the tail entity t, To filter the set by the second threshold The relationship set after the contribution score is lower than the second threshold, the set is the set of relations associated with the tail entity in the set of triples containing relation r.
[0043] Among them, the relationship r i The contribution score p(r|r i ) is calculated as:
[0044]
[0045] Where R is the set of all relations in the knowledge graph, |D r | is the set D of triples containing relation r r The number of the three ancestors in the middle To appear in set D r The collection of head entities in , For the relationship i With entity The relative frequency of the associated relationship, f inv is the inverse frequency, i.e. the logarithm of the ratio of the total number of entities to the number of entities with relation r, For entity e and relation r∈R e The relative frequency, R e is the set of relations related to entity e, is the number of relations r associated with entity e, p(r) is the probability of relation r appearing in the knowledge graph, and p(r i |r) is the prior probability. In this embodiment, the contribution score p(r|r i ) represents the relationship r i The probability that the head entity of also has relation r.
[0046] The calculation process of the prior probability is described below with reference to the accompanying drawings.
[0047] Figure 2 It is a schematic diagram of the structure of the knowledge graph A in an embodiment of the present invention.
[0048] like Figure 2 As shown in the figure, the two entities connected by the solid arrows represent the triples in the knowledge graph A, and the two entities connected by the dotted arrows are the target triples (A, profession, Director). Therefore, the knowledge graph A includes 9 entities, namely A, Oscars, Movie1, USA, Director, C, Movie2, China, and B. Because only the triple (C, profession, Director) contains the target relationship profession, Expressed as Where pro is the abbreviation of profession, R e Expressed as That is, there are three relations related to entity C. Then for the target relation profession, the prior probability of relation direct is in f inv =log(9 / 2), f inv Where 2 is the number of entities in the remaining triples containing the relation direct after removing the triples containing entity C and the relation direct.
[0049] The embedding generation module 60 is used to generate a hard prompt q according to the question, generate adaptive information c according to the reasoning information, and generate a soft prompt v corresponding to the relationship r according to the relationship matrix. In this embodiment, v=U r (V φ ), where is the relationship matrix, |R| is the number of different relationships in the knowledge graph, and U r is the matrix that generates the relation r.
[0050] The prediction module 70 includes a language model for concatenating the soft prompt v, the hard prompt q and the adaptive information c, and inputting the concatenated result into the language model to obtain the inductive relationship prediction result, wherein the inductive relationship prediction result is that the target triple (h, r, t) is correct or the target triple (h, r, t) is incorrect.
[0051] Among them, the expression of the splicing result is:
[0052] z=[e([CLS])ve(q)e([SEP])e(c)],
[0053] Where z is the concatenation result and e(·) is the vector embedding operation.
[0054] Among them, in the prediction module 70, when the reasoning information is a reasoning path, each reasoning path is used as reasoning information to generate a corresponding splicing result.
[0055] The language model is concatenated according to the corresponding result of the i-th reasoning path Generate the corresponding predicted probability pro i , predicted probability pro i The calculation expression is:
[0056]
[0057] Where N is the total number of reasoning paths and y∈{0,1} is the class label.
[0058] The inductive relationship prediction result is obtained based on the final score score(h,r,t) of the target triple (h,r,t). The calculation expression of the final score score(h,r,t) is:
[0059]
[0060] The following, in conjunction with the accompanying drawings, illustrates the process of summarizing and predicting relationships on the knowledge graph B containing grassroots social governance events.
[0061] Figure 3 It is a schematic diagram of the structure of the knowledge graph B in an embodiment of the present invention.
[0062] Figure 4 It is a schematic diagram of the working principle of the language model performing inductive relationship prediction in an embodiment of the present invention.
[0063] like Figure 3 and 4 As shown in the figure, for knowledge graph B, the question is "Where was event A sent? Is it Pudong New Area?", then the triple to be predicted, i.e. the target triple, is (event A, location, Pudong New Area). The corresponding Hardprompt, i.e. the hard prompt, generated according to the question is: q = question: Where was event A sent? Is it Pudong New Area? . The adaptive information corresponding to the reasoning path extracted from knowledge graph B is: c p = Event A occurs in Zhangjiang; Event C occurs in Zhangjiang; Event C occurs in Pudong New Area [SEP] Des (A) [SEP] Des (Pudong New Area). The adaptive information corresponding to the relation-aware reasoning neighbor RN extracted from the knowledge graph B is: c n = Event A occurred Zhangjiang Event A Category Consultation [SEP] Des (A) [SEP] Des (Pudong New Area). This process of extracting adaptive information from the knowledge graph is adaptive reasoning information extraction. According to the relationship soft prompt V trained together with the pre-trained language model, that is, the language model φ That is, the relationship matrix generates the corresponding soft prompts. The above soft prompts, hard prompts and adaptive information are sequentially spliced and input into the language model to obtain the inductive relationship prediction result.
[0064] In this embodiment, a training data set is constructed based on existing data to train the initial language model and the initial relationship matrix, and the parameters of the initial relationship matrix and the initial language model are iteratively updated to obtain the trained initial language model as the language model and the trained initial relationship matrix as the relationship matrix. In this embodiment, a negative sampling strategy is used to generate negative samples, that is, entities are randomly sampled from the common 3-hop entities of the head and tail entities to destroy the head or tail entity of each positive triple.
[0065] Among them, during training, the calculation expression of the i-th layer of the initial language model is:
[0066]
[0067] Where LMθ (·) is the forward function of the initial language model, and j=0 corresponds to the input layer. is the i-th soft hint vector specific to relation r, k is the total number of soft hint vectors specific to relation r, is the representation vector of the j-1th layer model, To represent the vector After the LM function, the i-th dimension vector represents z i is the i-th dimension vector of the concatenated result. In this embodiment, the soft prompt v specific to the relation r is v r , which contains k soft hint vectors specific to relation r.
[0068] The control module 80 stores a control program for controlling the operation of each module.
[0069] The following describes the process of the knowledge graph induction relationship prediction method using the knowledge graph induction relationship prediction device 100 to perform relationship perception in conjunction with the accompanying drawings.
[0070] Figure 5 It is a flow chart of a relationship-aware knowledge graph induction relationship prediction method in an embodiment of the present invention.
[0071] like Figure 5 As shown in FIG. 1 , the relationship-aware knowledge graph induction relationship prediction method includes the following steps:
[0072] Step S1, using the path extraction module 10 to extract the relationship path from the knowledge graph according to the head entity h and the tail entity t.
[0073] Step S2: Calculate the relationship path confidence corresponding to each relationship path using the path confidence calculation module 20.
[0074] Step S3: The reasoning path generation module 30 is used to filter out the relationship paths corresponding to the relationship path confidences less than the relationship path confidence threshold, and the remaining relationship paths are used as reasoning paths.
[0075] In step S4, the judging module 40 is used to judge whether the reasoning path is empty. If so, step S5 is executed. If not, the reasoning path is used as reasoning information and step S6 is executed.
[0076] Step S5, using the neighbor generation module 50 to obtain the relationship-aware reasoning neighbor RN as reasoning information according to the head entity h, the tail entity t and the knowledge graph.
[0077] Step S6, using the embedding generation module 60 to generate a hard prompt q according to the question, generate adaptive information c according to the reasoning information, and generate a soft prompt v corresponding to the relationship r according to the relationship matrix.
[0078] Step S7, using the prediction module 70 to concatenate the soft prompt v, the hard prompt q and the adaptive information c, and inputting the concatenation result into the language model to obtain the inductive relationship prediction result.
[0079] In this embodiment, the relationship-aware knowledge graph inductive relationship prediction method, namely the Raker method, is compared with the existing RuleN method, GRAIL method, MINERVA method, TuckER method, KG-BERT method, BERTRL method and KRST method. The Mean Reciprocal Rank (MRR) and Hits@1 of 1 positive triple in 49 negative triples out of 50 samples are calculated on the existing inductive relationship prediction datasets FB15k-237, WN18RR and NELL-995. MRR calculates the average reciprocal ranking of all positive triples, and Hits@1 calculates the percentage of positive triples that appear as the top 1 triple. The status of each indicator of each method under different datasets is shown in the following table:
[0080]
[0081] In the above table, the first column is each indicator, the second column is each method, the third to fifth columns are the results of each indicator of each method on the direct induction subsets of the WN18RR, FB15k-237 and NELL-995 datasets, and the sixth to eighth columns are the results of each indicator of each method on the inductive subsets of the WN18RR, FB15k-237 and NELL-995 datasets. For example, the cell in the third row and the third column indicates that the MRR indicator result of the RuleN method on the direct induction subset of the WN18RR dataset is 0.669. It can be seen that the Raker method has achieved the best performance in various cases compared with various other existing methods, and is much better than the baseline. Especially on the FB15k-237 inductive subset, which has the most different relations between the three datasets and has many unconnected entity pairs, the improvement is more than 10%. This improvement comes from the combined effect of the soft prompts of the relationship and the relationship-aware reasoning neighbors in the Raker method.
[0082] In this example, the Raker method is also used with the KG-BERT method, the BERTRL method, and the KRST method to perform performance tests on the FB15k-237 inductive dataset using triplets of 50 visible relations and 100 visible relations. The results are shown in the following table:
[0083]
[0084] In the above table, the first column is the performance index, the second column is the method, and the third and fourth columns are the performance index results of each method on 50 visible relations and 100 visible relations respectively. For example, the cell in the third row and third column indicates that the MRR performance index result of the BERTRL method on 50 visible relations is 0.580. It can be seen that the Raker method is much better than the baseline model because the Raker method can extract more reasoning information for relationship prediction.
[0085] Functions and Effects of the Embodiments
[0086] According to the relationship-aware knowledge graph inductive relationship prediction method and device involved in this embodiment, the relationship path is extracted from the knowledge graph, and the reasoning path is obtained according to the relationship path confidence threshold and the relationship path confidence screening. If the reasoning path is empty, the relationship-aware reasoning neighbor RN, that is, the relationship neighbor, is generated according to the knowledge graph as the reasoning information, and then the hard prompt generated by the question, the adaptive information generated by the reasoning information, and the soft prompt generated by the relationship matrix are spliced and input into the language model, so as to obtain the inductive relationship prediction result of the question. In short, this method can determine the effective relationship neighbors and obtain accurate inductive relationship prediction results.
[0087] Those skilled in the art should understand that the present invention is not limited to the above embodiments, and the above embodiments and descriptions are only for explaining the principles of the present invention. Without departing from the spirit and scope of the present invention, the present invention may have various changes and improvements, and these changes and improvements fall within the scope of the present invention to be protected. The scope of protection of the present invention is defined by the attached claims and their equivalents.
Claims
1. A relationship-aware knowledge graph inductive relationship prediction method for obtaining corresponding inductive relationship prediction results based on a question containing a target triple (h, r, t) and a knowledge graph, characterized in that: The following steps are involved: Step S1, extracting a relationship path from the knowledge graph based on the head entity h and the tail entity t; Step S2, calculating the relationship path confidence corresponding to each of the relationship paths; Step S3, filtering out the relationship paths corresponding to the relationship path confidences that are less than a preset relationship path confidence threshold, and using the remaining relationship paths as inference paths; Step S4, determining whether the reasoning path is empty, if so, executing step S5, if not, taking the reasoning path as reasoning information and executing step S6; Step S5, obtaining a relation-aware reasoning neighbor RN as the reasoning information according to the head entity h, the tail entity t, and the knowledge graph; Step S6, generating a hard prompt q according to the question, generating adaptive information c according to the reasoning information, and generating a soft prompt v corresponding to the relationship r according to the relationship matrix; Step S7: concatenate the soft prompt v, the hard prompt q, and the adaptive information c, and input the concatenation result into a language model to obtain the inductive relationship prediction result. The inductive relationship prediction result is that the target triple (h, r, t) is correct or the target triple (h, r, t) is incorrect.
2. The relationship-aware knowledge graph induction relationship prediction method according to claim 1 is characterized by: in, In step S1, a path between the head and tail entities is extracted by a breadth-first search algorithm.
3. The relationship-aware knowledge graph induction relationship prediction method according to claim 1, characterized in that: in, The calculation expression of the relationship path confidence is: Where R p is the logical reasoning path of the relation combination, There is a logical reasoning path R from entity h to t p The relationship path confidence, E G -{h} removes the head entity h from the entity set. For a logical reasoning path R p The number of triplets.
4. The relationship-aware knowledge graph induction relationship prediction method according to claim 1, characterized in that: in, The calculation expression of the relationship-aware reasoning neighbor RN is: Where R h′ is the reliable relation set of the head entity h, For the ownership relationship r h And the entity is a triple set h, R t′ is the reliable relation set of the tail entity t, For the ownership relationship r t And the entity is a triple set of t, R h is the neighbor relationship set of the head entity h, To filter the set by the first threshold The relationship set after the contribution score is lower than the first threshold, the set is the set of relations associated with the head entity in the set of triples containing relation r, R t is the neighbor relationship set of the tail entity t, To filter the set by the second threshold The relationship set after the contribution score is lower than the second threshold, the set is the set of relations associated with the tail entity in the set of triples containing relation r.
5. The relationship-aware knowledge graph induction relationship prediction method according to claim 4 is characterized by: in, Relationship i The contribution score p(r|r i ) is calculated as: Where R is the set of all relations in the knowledge graph, |D r | is the set D of triples containing relation r r The number of the three ancestors in the middle To appear in set D r The collection of head entities in , For the relationship r i With entity The relative frequency of the associated relationship, f inv is the inverse frequency, For entity e and relation r∈R e The relative frequency, R e is the set of relations related to entity e, is the number of relations r associated with entity e.
6. The relationship-aware knowledge graph induction relationship prediction method according to claim 1, characterized in that: in, The expression of the splicing result is: z=[e([CLS])ve(q) e([SEP]) e(c)], Where z is the concatenation result and e(·) is the vector embedding operation.
7. The relationship-aware knowledge graph induction relationship prediction method according to claim 1, characterized in that: in, In step S7, when the reasoning information is the reasoning path, each of the reasoning paths is used as the reasoning information to generate a corresponding splicing result. The language model is based on the splicing result corresponding to the i-th reasoning path Generate the corresponding predicted probability pro i , Prediction Probability i The calculation expression is: Where N is the total number of reasoning paths, y∈{0,1} is the class label, The inductive relationship prediction result is obtained according to the final score score(h,r,t) of the target triple (h,r,t). The calculation expression of the final score score(h,r,t) is:
8. The relationship-aware knowledge graph induction relationship prediction method according to claim 1, characterized in that: in, A training data set is constructed based on existing data to train the initial language model and the initial relationship matrix, and the parameters of the initial relationship matrix and the initial language model are iteratively updated to obtain the trained initial language model as the language model and the trained initial relationship matrix as the relationship matrix.
9. The relationship-aware knowledge graph induction relationship prediction method according to claim 8, characterized in that: in, During the training, the calculation expression of the j-th layer of the initial language model is: Where LM θ (·) is the forward function of the initial language model, j = 0 corresponds to the input layer, is the i-th soft hint vector specific to relation r, k is the total number of soft hint vectors specific to relation r, is the representation vector of the j-1th layer model, To represent the vector After the LM function, the i-th dimension vector represents z i is the i-th dimension vector of the splicing result.
10. A relationship-aware knowledge graph inductive relationship prediction device for obtaining corresponding inductive relationship prediction results based on a question containing a target triple (h, r, t) and a knowledge graph, characterized in that: include: Path extraction module, path confidence calculation module, reasoning path generation module, judgment module, neighbor generation module, embedding generation module and prediction module, The path extraction module is used to extract the relationship path from the knowledge graph based on the head entity h and the tail entity t. The path confidence calculation module is used to calculate the relationship path confidence corresponding to each of the relationship paths. The reasoning path generation module stores a preset relationship path confidence threshold, and is used to filter out the relationship paths corresponding to the relationship paths with confidence values less than the relationship path confidence threshold, and use the remaining relationship paths as reasoning paths. The judgment module is used to judge whether the reasoning path is empty. If so, the neighbor generation module is executed. If not, the reasoning path is used as reasoning information and the embedding generation module is executed. The neighbor generation module is used to obtain the relationship-aware reasoning neighbor RN as the reasoning information based on the head entity h, the tail entity t and the knowledge graph, The embedding generation module is used to generate a hard prompt q according to the question, generate adaptive information c according to the reasoning information, and generate a soft prompt v corresponding to the relationship r according to the relationship matrix. The prediction module includes a language model, which is used to splice the soft prompt v, the hard prompt q and the adaptive information c, and input the splicing result into the language model to obtain the inductive relationship prediction result. The inductive relationship prediction result is that the target triple (h, r, t) is correct or the target triple (h, r, t) is incorrect.
Citation Information
Patent Citations
Induction relation prediction method fusing subgraph enhancement and relation semantics and application
CN116415661A
System and Method for Knowledge-Based Entity Prediction
US20230127121A1
