Target sub-graph sampling method of knowledge graph

Generating the target subgraph through two-way search, the problem of low sampling efficiency of one-way 2k-step search is solved, and the efficiency and accuracy of knowledge graph link prediction is improved.

CN119248936APending Publication Date: 2025-01-03MEGAROBO TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411232646.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-04
Publication Date
2025-01-03

AI Technical Summary

Technical Problem

When the prior art uses a one-way 2k-step search and intersection method to sample sub-graphs in the knowledge graph, the calculation amount is large, resulting in low sampling efficiency, which seriously affects the efficiency and accuracy of link prediction.

Method used

The target subgraph sampling method of two-way search is adopted to search separately from the starting node and the target node to generate the target subgraph, retain the intersecting nodes and their direct or indirect connections, and delete the nodes that are not directly or indirectly connected through a specific node. Other nodes generate reasonable target subgraphs.

Benefits of technology

It effectively reduces the calculation amount during sub-graph sampling, improves the generation efficiency of target sub-graphs, and improves the efficiency and accuracy of link prediction.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119248936A_ABST
    Figure CN119248936A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a target sub-graph sampling method of a knowledge graph and a link prediction method based on the knowledge graph. The target sub-graph sampling method comprises the following steps: searching on a knowledge graph from a starting node according to a first step number to obtain a first sub-graph; searching on the knowledge graph according to a second step number from the target node to obtain a second sub-graph; according to the first sub-graph and the second sub-graph, generating a target sub-graph, reserving intersecting nodes in the last-step nodes of the first sub-graph and the second sub-graph, and reserving non-intersecting nodes directly connected with the intersecting nodes; other nodes directly connected with all intersecting nodes or indirectly connected with all intersecting nodes through specific nodes in other search steps are reserved, and the connection relation between any two nodes in all reserved nodes is reserved. According to the target sub-graph sampling method, the target sub-graph can be quickly and accurately generated, and the rationality of the target sub-graph can be improved, so that the link prediction efficiency and accuracy can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of knowledge graph technology, and more specifically to a target subgraph sampling method for a knowledge graph and a link prediction method based on a knowledge graph. Background Art

[0002] A knowledge graph is a collection of a large number of triples in the form of (head, relation, tail), expressed as (h, r, t). The connections between triples also reveal the relationships between entities and play an important role in various artificial intelligence application scenarios. A common application of knowledge graphs is link prediction, which is to predict whether there is a certain relationship between the head and the tail in a triple. Currently, when performing link prediction, a subgraph is usually sampled from the knowledge graph, and then a further prediction is made based on the subgraph whether there is a certain relationship between the head and the tail in the triple.

[0003] At present, in the related technology, a one-way 2k-step search to obtain intersection is usually used to sample subgraphs from knowledge graphs. However, since knowledge graphs are usually large, when a one-way 2k-step search to obtain intersection is used, the number of nodes that need to be calculated may increase exponentially with each additional level of search, which results in the subgraph sampling process consuming a lot of time and computing resources, seriously affecting the sampling efficiency of subgraphs. Summary of the invention

[0004] The present invention is proposed in view of the above problems. The present invention provides a target subgraph sampling method of a knowledge graph and a link prediction method based on a knowledge graph, which can quickly and accurately generate a reasonable target subgraph, thereby improving the efficiency and accuracy of link prediction.

[0005] According to one aspect of the present invention, a method for sampling a target subgraph of a knowledge graph is provided, wherein the target subgraph is used to be input into a graph neural network model for link prediction, and the graph neural network model has a longest path hyperparameter, and the longest path hyperparameter represents the maximum number of steps between a starting node for generating a target subgraph and a target node for generating the target subgraph; the method comprises: searching on the knowledge graph from the starting node according to the first number of steps to obtain a first subgraph; searching on the knowledge graph from the target node according to the second number of steps to obtain a second subgraph; wherein the sum of the first number of steps and the second number of steps is the longest path hyperparameter; generating a target subgraph according to the first subgraph and the second subgraph, wherein in the target subgraph, intersecting nodes in the nodes of the last step of the first subgraph and the second subgraph are retained, non-intersecting nodes directly connected to the intersecting nodes are retained, other nodes directly or indirectly connected to all intersecting nodes through specific nodes in other search steps are retained, and the connection relationship between any two nodes in all retained nodes is retained, and the specific nodes are nodes other than the starting node and the target node.

[0006] Optionally, a target subgraph is generated based on the first subgraph and the second subgraph, including: merging the first subgraph and the second subgraph to generate a third subgraph; in the third subgraph, determining the intersecting nodes and non-intersecting nodes between the nodes searched in the last step in the first subgraph and the nodes searched in the last step in the second subgraph; performing the following operations on the third subgraph to obtain the target subgraph: retaining the non-intersecting nodes directly connected to the intersecting nodes and the connection relationship between the two; and deleting the non-intersecting nodes indirectly connected to the intersecting nodes to obtain an updated third subgraph; in the updated third subgraph, deleting other nodes that are not directly or indirectly connected to the intersecting nodes through specific nodes and the connection relationship between the deleted nodes and other nodes to obtain the target subgraph.

[0007] Optionally, when the longest path hyperparameter is even, the first number of steps is equal to the second number of steps.

[0008] Optionally, when the longest path hyperparameter is an odd number, the first step number k1 = (L+1) / 2, the second step number k2 = (L-1) / 2; or, the first step number k1 = (L-1) / 2, the second step number k2 = (L+1) / 2; where L is the longest path hyperparameter.

[0009] Optionally, a target subgraph is generated based on the first subgraph and the second subgraph, including: merging the first subgraph and the second subgraph to generate a third subgraph; in the third subgraph, determining the intersection node between the node searched in the last step in the first subgraph and the node searched in the last step in the second subgraph; performing the following operations on the third subgraph to obtain the target subgraph: for the third subgraph, starting from the node searched in the last step in the first subgraph, step by step performing a fallback filtering operation until falling back to the starting node, and starting from the node searched in the last step in the second subgraph, step by step performing a fallback filtering operation until falling back to the target node, to obtain the target subgraph, wherein the fallback filtering operation includes: for each node, when the node is not directly connected to the intersection node and is not indirectly connected to the intersection node through a preceding node, deleting the node and the connection relationship between the node and other nodes, wherein the preceding node is a node on the fallback path where the node is located and before the node.

[0010] According to another aspect of the present invention, a link prediction method based on a knowledge graph is also provided, comprising the following steps: obtaining target triple information to be tested, the target triple information to be tested at least including a starting node to be tested and a target node to be tested; sampling in the knowledge graph using the above-mentioned target subgraph sampling method according to the nodes included in the target triple information to be tested, so as to obtain a target subgraph to be tested corresponding to the starting node to be tested and the target node to be tested; inputting the target subgraph to be tested and the target triple information to be tested into a trained graph neural network model for reasoning, so as to obtain an reasoning result.

[0011] Optionally, the trained graph neural network model is trained through the following training steps: obtaining multiple sample triple information, each sample triple information including a sample starting node, a sample target node and a link path between the two; according to each sample triple information, using the above-mentioned target subgraph sampling method to sample in the knowledge graph to obtain a sample target subgraph; based on multiple sample triple information and the corresponding multiple sample target subgraphs, training the graph neural network model to obtain a trained graph neural network model.

[0012] Optionally, the graph neural network model includes an aggregation module and a prediction module. When the target subgraph to be tested and the link path to be tested are input into the trained graph neural network model for reasoning, an aggregation function is used in the aggregation module to calculate the aggregation features of each node in the target subgraph to be tested, and link prediction is performed in the prediction module based on the aggregation features of each node in the target subgraph to be tested to determine the reasoning result.

[0013] Optionally, the graph neural network model includes a neighborhood-based filtering network model, and the aggregation function includes a primary neighborhood aggregation function based on the graph neural network.

[0014] Optionally, before obtaining the three sets of target information to be tested, it also includes: obtaining triplet information to be tested, the triplet information to be tested includes a unique node to be tested and a link path to be tested among the starting node to be tested and the target node to be tested; the above-mentioned obtaining of the target triplet information to be tested specifically includes: traversing the knowledge graph, and determining at least one target triplet information to be tested based on the unique node to be tested and the link path to be tested in the target triplet information to be tested.

[0015] According to the above technical solution, the first subgraph and the second subgraph can be searched from the starting node and the target node respectively, and the target subgraph is generated based on the intersection between the node searched in the last step of the first subgraph and the node searched in the last step of the second subgraph. This two-way search method can effectively reduce the amount of calculation when sampling the subgraph, which helps to improve the efficiency of generating the target subgraph. This solution can quickly and accurately generate the target subgraph. Therefore, the link prediction method using the above target subgraph sampling method is efficient and accurate. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] The above and other purposes, features and advantages of the present invention will become more apparent by describing the embodiments of the present invention in more detail in conjunction with the accompanying drawings. The accompanying drawings are used to provide a further understanding of the embodiments of the present invention and constitute a part of the specification. Together with the embodiments of the present invention, they are used to explain the present invention and do not constitute a limitation of the present invention. In the accompanying drawings, the same reference numerals generally represent the same components or steps.

[0017] Figure 1A schematic diagram showing how to sample a subgraph from a knowledge graph by using a one-way 2k-step search to obtain an intersection;

[0018] Figure 2 A schematic flowchart of a target subgraph sampling method of a knowledge graph according to an embodiment of the present invention is shown;

[0019] Figure 3 A schematic diagram showing a subgraph obtained by sampling a target subgraph of a knowledge graph according to an embodiment of the present invention;

[0020] Figure 4 A schematic flow chart showing a link prediction method based on a knowledge graph according to an embodiment of the present invention is shown;

[0021] Figure 5 A schematic diagram showing a knowledge graph according to an embodiment of the present invention;

[0022] Figure 6 A schematic diagram of a target subgraph to be detected according to an embodiment of the present invention is shown. DETAILED DESCRIPTION

[0023] In order to make the purpose, technical scheme and advantages of the present invention more obvious, the exemplary embodiments according to the present invention will be described in detail with reference to the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all the embodiments of the present invention, and it should be understood that the present invention is not limited to the exemplary embodiments described herein. Based on the embodiments of the present invention described in the present invention, all other embodiments obtained by those skilled in the art without creative work should fall within the protection scope of the present invention.

[0024] See also Figure 1 As shown in , it is a schematic diagram of sampling a subgraph from a knowledge graph by using a one-way 2k-step search to obtain the intersection. Figure 1 In the figure, circles represent nodes and lines between nodes represent paths. Figure 1 The upper left picture in the figure is the knowledge graph to be sampled, the upper right picture is the path obtained by searching 2k steps from node "1", the lower left picture is the path obtained by searching 2k steps from node e, and the lower right picture is the target subgraph obtained by taking the intersection of the paths obtained by the above two searches. Figure 1In the knowledge graph to be sampled shown, the node where "1" is located is the starting node, and the node where "e" is located is the target node. Among them, the path from the starting node "1" to the target node "e" can be "1-2-4-8-e", or "1-2-5-9-e". In each path, there are 3 nodes between the starting node "1" and the target node "e". The adjacent nodes are recorded as a 1-step path, then the maximum number of steps between the starting node "1" and the target node "e" is 4, that is, the longest path hyperparameter is 4. When the one-way 2k-step search method is used to obtain the intersection, if the longest path hyperparameter is an even number, the value of k can be 0.5 times the longest path hyperparameter. Figure 1 In the illustrated embodiment, the value of k is 0.5*4=2. It can be understood that, starting from the starting node "1", taking the path with the number of steps of 2*2=4 and the nodes constituting the path, the acquired paths include: "1-2-4-7-b", "1-2-4-7-c", "1-2-4-8-c", "1-2-4-8-e", "1-2-5-9-e", "1-2-5-9-f", "1-3-6-af" and "1-3-6-ag". Similarly, starting from the target node "e", taking the path with the number of steps of 2*2=4 and the nodes constituting the path, the acquired paths include: "e-8-4-2-1", "e-8-5-2-1", "e-9-5-2-1", "e-9-jmp", "e-9-jmq", ..., "ehkmq". By obtaining paths with the same nodes in the paths obtained through different search directions, all paths in the target subgraph to be obtained can be obtained. For example, all nodes in the path "1-2-4-8-e" and the path "e-8-4-2-1" are the same, and the two paths are actually one path. Then the path "1-2-4-8-e" (or "e-8-4-2-1") is a path in the target subgraph to be obtained. The same is true for other paths. The target subgraph obtained is Figure 1 The target subgraph is shown in the lower right figure of .

[0025] As mentioned above, in the related art, the subgraph sampled from the knowledge graph by using a one-way 2k-step search to obtain the intersection has too many redundant nodes and paths. Therefore, sampling the subgraph from the knowledge graph by using a one-way 2k-step search to obtain the intersection requires a lot of computation and time, which seriously affects the sampling efficiency of the subgraph. An embodiment of the present invention provides a target subgraph sampling method for a knowledge graph, which can reduce the computational complexity of the sampling process and quickly and accurately generate a target subgraph.

[0026] See also Figure 2As shown, it is a schematic flow chart of a target subgraph sampling method for a knowledge graph according to an embodiment of the present invention. The target subgraph is used to input into a graph neural network model for link prediction. The graph neural network model has a longest path hyperparameter, which represents the maximum number of steps between a starting node for generating a target subgraph and a target node for generating a target subgraph. The target subgraph sampling method for a knowledge graph includes step S210, step S220, and step S230.

[0027] Exemplarily, the target subgraph may be at least a partial area of ​​the knowledge graph, which may be an area of ​​interest. By inputting the target subgraph into a graph neural network model (GNN), the potential edges in the target subgraph may be obtained based on the attributes of the existing edges and nodes in the target subgraph. Specifically, a node may represent an entity, including: a person (e.g., Einstein), a place (e.g., Paris), an organization (e.g., Company A), a noun concept (e.g., physics), a feature (e.g., color, length), etc. An edge may represent a relationship between nodes, and by connecting two nodes in the knowledge graph, it indicates a certain connection between the entities represented by the two nodes. An edge is usually directed, that is, the direction of the relationship between nodes is clear, for example, "A is the father of B" and "B is the son of A" represent different directions. An edge may carry information about the type of relationship, for example, kinship: "father", "mother", "brother"; work relationship: "employed", "worked at"; geographical relationship: "located in", "border adjacent"; conceptual relationship: "belongs to", "contains"; time relationship: "occurs in", "before", "after"; etc. An edge may also carry additional information, such as the strength of the relationship, timestamp, etc. Each pair of nodes and edges can be considered as a triple (subject, predicate, object), where the subject is the initiator of the relationship, i.e., a node in the graph, the predicate is the type of relationship connecting the subject and the object, i.e., the type of edge, and the object is the receiver of the relationship, i.e., another node in the graph. For example, the triple <Einstein, discovery, relativity> describes the "discovery" relationship between Einstein and relativity. It can be understood that through link prediction, new edges (i.e., relationships) that may exist but have not yet been observed between the nodes in the graph can be obtained.

[0028] In step S210, a search is performed on the knowledge graph from the starting node according to the first step to obtain a first subgraph.

[0029] Exemplarily, in a knowledge graph, multiple entities and the relationship between at least some of the entities in the multiple entities may be included, wherein each entity is represented by a corresponding node in the knowledge graph. The knowledge graph may include multiple nodes, each of which may be used as a starting node, and the number of starting nodes may be one or more. Each starting node may correspond to one or more target nodes, and the target node may be a node that has an indirect relationship or a direct relationship with the starting node in the knowledge graph. For a certain starting node, a certain target node corresponding to the starting node may be directly connected by a single edge (direct relationship) to form a path containing two nodes (including only the starting node and the target node). The starting node and the target node may also be indirectly connected by one or more nodes (indirect relationship) to form one or more paths containing at least three nodes (including the starting node and the target node). In this case, the adjacent nodes in each path are directly connected by a single edge, and each path contains at least two edges. All paths searched by each starting node may together constitute the first subgraph. For each starting node, and any target node corresponding to the starting node, the first step can be defined by yourself, and the first step must be less than or equal to the maximum number of steps between the starting node and the target node. It can be understood that there can be one or more paths between the starting node and the target node, and the number of edges between adjacent nodes contained in each path is the number of steps of the path. The maximum number of steps can be selected from the steps corresponding to each path, and the maximum number of steps is the maximum number of steps between the starting node and the target node. For any starting node, all nodes directly connected to the starting node can be searched, and the cumulative number of steps of the current search is 1 step. For any node among all the nodes searched, all nodes directly connected to the node are continued to be searched according to the original search direction, and the cumulative number of steps of the current search is 2 steps. Repeat the above search process until the cumulative number of steps of the search is the first step, stop the search, retain all the nodes searched on the knowledge graph and the edges (relationships) between the nodes, and the first subgraph can be obtained.

[0030] In step S220, a search is performed on the knowledge graph from the target node according to a second number of steps to obtain a second subgraph; wherein the sum of the first number of steps and the second number of steps is the longest path hyperparameter.

[0031] Exemplarily, in the knowledge graph, each node can also be used as a target node, but for the same node, when the node is used as a target node, the node cannot be used as the starting node corresponding to itself at the same time, but can be used as the starting node corresponding to other target nodes. Similarly, the number of target nodes can be 1 or more. Each target node can correspond to 1 or more starting nodes, and the starting node can be a node that has an indirect relationship or a direct relationship with the target node in the knowledge graph. For a certain target node, a certain starting node corresponding to the target node can be directly connected by a single edge (direct relationship) to form a path containing two nodes (including only the starting node and the target node). The target node and the starting node can also be indirectly connected by 1 or more nodes (indirect relationship) to form one or more paths containing at least 3 nodes (including the starting node and the target node). In this case, the adjacent nodes in each path are directly connected by a single edge, and each path contains at least two edges. All paths searched by each target node can together constitute a second subgraph. For each starting node, and any target node corresponding to the starting node, the first step and the second step can be defined by yourself. You only need to ensure that the sum of the first step and the second step is equal to the longest path hyperparameter, which is the maximum number of steps between the target node and the starting node. The first step and the second step can be equal or unequal. It can be understood that there can be one or more paths between the target node and the starting node, and the number of edges between adjacent nodes contained in each path is the number of steps of the path. The maximum number of steps corresponding to each path can be selected, and the maximum number of steps is the maximum number of steps between the starting node and the target node, which is the longest path hyperparameter. For any target node, all nodes directly connected to the target node can be searched, then the current search cumulative number of steps is 1 step, for any node among all the searched nodes, continue to search all nodes directly connected to the node according to the original search direction, then the current search cumulative number of steps is 2 steps, repeat the above search process until the cumulative number of search steps is the second number of steps, stop the search, retain all the nodes searched on the knowledge graph and the edges (relationships) between the nodes, and you can get the second subgraph.

[0032] In step S230, a target subgraph is generated according to the first subgraph and the second subgraph, wherein in the target subgraph, the intersecting nodes in the nodes of the last step of the first subgraph and the second subgraph are retained, the non-intersecting nodes directly connected to the intersecting nodes are retained, other nodes directly or indirectly connected to all the intersecting nodes through specific nodes in other search steps are retained, and the connection relationship between any two nodes is included in all the retained nodes, and the specific nodes are nodes other than the start node and the target node.

[0033] Exemplarily, the node of the last step of the first subgraph is: the first target search node obtained by searching in the last step in the process of searching in the knowledge graph according to the first step number from the start node. Similarly, the node of the last step of the second subgraph is: the second target search node obtained by searching in the last step in the process of searching in the knowledge graph according to the second step number from the target node. It can be understood that the same node in the first target search node of the last step of the first subgraph and the second target search node of the last step of the second subgraph is an intersection node, and the different nodes in the first target search node and the second target search node (i.e., the nodes in the first target search node and the second target search node other than the intersection node) are non-intersection nodes. The target subgraph can be generated in any suitable manner, as long as the following conditions are met: in the target subgraph, the nodes of the last step of the first subgraph and the nodes of the last step of the second subgraph are retained, the non-intersecting nodes directly connected to the intersecting nodes are retained, and other nodes directly or indirectly connected to any intersecting node through specific nodes in other search steps except the last step are retained, and the connection relationship between any two nodes in the retained nodes is retained (wherein, the retained nodes include the retained intersecting nodes, retained non-intersecting nodes and retained other nodes mentioned above, and the connection relationship refers to the connection relationship between any two retained nodes in the nodes of the target subgraph shown in the first subgraph and the second subgraph). Specifically, the specific nodes are nodes other than the starting node and the target node. In other words, the nodes other than the intersecting nodes and the non-intersecting nodes retained in the target subgraph meet the following conditions: they are directly connected to the intersecting nodes, or are indirectly connected to the intersecting nodes through nodes other than the starting node and the target node. The remaining nodes in the first subgraph and the second subgraph are not retained in the target subgraph (correspondingly, the connection relationship between these nodes and other nodes is not retained). For example, all nodes in the first subgraph and all nodes in the second subgraph may be firstly taken as a union, and all nodes included in the union may be combined according to the connection relationship of each node in the knowledge graph to form a new subgraph (which may be called a third subgraph), and then the first node processing operation may be performed on the third subgraph, so as to retain the intersecting nodes, the non-intersecting nodes directly connected to the intersecting nodes, other nodes directly or indirectly connected to the intersecting nodes through specific nodes (nodes other than the starting node and the target node) in other search steps, and the original connection relationship of each retained node in the third subgraph, thereby obtaining the target subgraph. The first node processing operation may include: searching for other nodes directly or indirectly connected to the intersecting nodes through specific nodes in other search steps from the third subgraph, and searching for non-intersecting nodes directly connected to the intersecting nodes, and deleting nodes other than the intersecting nodes and the found nodes from the third subgraph, and deleting the connection relationship between the deleted nodes and other nodes.Alternatively, search the third subgraph for nodes that are not directly or indirectly connected to the intersecting nodes through specific nodes in other search steps, and search for non-intersecting nodes that are not directly connected to the intersecting nodes, and delete the found nodes from the third subgraph, and delete the connection relationship between the deleted nodes and other nodes. For another example, the first subgraph and the second subgraph may be processed by the second node processing operation respectively to retain the intersecting nodes in the first subgraph and the second subgraph, the non-intersecting nodes directly connected to the intersecting nodes, other nodes that are directly or indirectly connected to the intersecting nodes through specific nodes in other search steps, and the original connection relationship of each retained node in the knowledge graph, and then combine the nodes retained in the first subgraph, the nodes retained in the second subgraph, and the intersecting nodes according to the connection relationship of each node in the first subgraph and the second subgraph to obtain the target subgraph. The second node processing operation may include: searching from the first subgraph or the second subgraph for other nodes that are directly or indirectly connected to the intersecting node through a specific node in other search steps, and searching for non-intersecting nodes that are directly connected to the intersecting node, and deleting nodes other than the intersecting node and the found nodes from the first subgraph or the second subgraph, and deleting the connection relationship between the deleted nodes and other nodes; or, searching from the first subgraph or the second subgraph for other nodes that are not directly or indirectly connected to the intersecting node through a specific node in other search steps, and searching for non-intersecting nodes that are not directly connected to the intersecting node, and deleting the found nodes from the first subgraph or the second subgraph, and deleting the connection relationship between the deleted nodes and other nodes. Exemplarily, the above-mentioned first node processing operation and / or second node processing operation can be implemented by a back-off filtering operation, that is, starting from the node searched in the last step in the first subgraph or the second subgraph according to the search path and gradually backing out, for each node backed out, the non-intersecting nodes among these nodes that are not directly connected to the intersecting nodes, and the nodes other than the non-intersecting nodes that are not directly or indirectly connected to the intersecting nodes through specific nodes are deleted, and the connection relationship between the deleted nodes and other nodes is deleted.

[0034] See also Figure 3 As shown, it is a schematic diagram of obtaining a target subgraph through a target subgraph sampling method of a knowledge graph according to an embodiment of the present invention. Figure 3 In the figure, circles represent nodes and lines between nodes represent paths. Figure 3The upper left picture in the figure is the knowledge graph to be sampled, the left side of the upper right picture is the first subgraph obtained by searching the knowledge graph from the starting node "1" according to the first step number, the right side of the upper right picture is the second subgraph obtained by searching the knowledge graph from the target node "e" according to the second step number, the lower left picture is the result of deleting the non-intersecting nodes that are not directly connected to the intersecting nodes in the nodes searched in the last step in the first subgraph and the second subgraph after combining the first subgraph and the second subgraph to obtain the third subgraph, and the lower right picture is the target subgraph obtained based on the paths obtained from the above two searches. Figure 3 In the knowledge graph to be sampled shown, the node where "1" is located is the starting node, and the node where "e" is located is the target node. The maximum number of steps from the starting node "1" to the target node "e" is 4, that is, the longest path hyperparameter is 4. In this embodiment, the values ​​of the first step and the second step are both 2. From the starting node "1", a two-step search is performed on the knowledge graph, and the paths obtained include: "1-2-4", "1-2-5" and "1-3-6". All paths obtained by searching the starting node "1" constitute the first subgraph, wherein the first subgraph includes all nodes obtained by searching the starting node "1" in two steps, and each node in the first subgraph maintains the original connection relationship between the nodes on the knowledge graph. Similarly, the paths obtained from the target node "e" in a two-step search on the knowledge graph include: "e-8-4", "e-8-5", "e-9-5", "e-9-j", "ehj" and "ehk". All the paths obtained from the search of the target node "e" constitute the second subgraph, wherein the second subgraph includes all the nodes obtained from the two-step search based on the starting node "e", and the nodes in the second subgraph maintain the original connection relationship between the nodes on the knowledge graph. In the search process for obtaining the first subgraph, the nodes obtained in the last step are: node "4", node "5" and node "6". In the search process for obtaining the second subgraph, the nodes obtained in the last step are: node "4", node "5", node "j" and node "k". Therefore, the nodes in the last step of the first subgraph and the nodes in the last step of the second subgraph that intersect are nodes "4" and "5", and the non-intersecting nodes include nodes "6", nodes "j" and nodes "k". The first subgraph and the second subgraph can be combined through nodes "4" and "5" to obtain the third subgraph ( Figure 3 After the first subgraph and the second subgraph are combined to obtain the third subgraph, the non-intersecting nodes that are not directly connected to the intersecting nodes can be deleted to obtain an updated third subgraph, see Figure 3 Bottom left picture, Figure 3 The lower left figure shows the updated third subgraph obtained after deleting the non-intersecting nodes that are not directly connected to the intersecting nodes from the nodes searched in the last step for the third subgraph. Figure 3In the embodiment shown, a fallback filtering operation is used to delete nodes and connection relationships. In this embodiment, node "6", node "j", and node "k" among non-intersecting nodes can be deleted. After obtaining the updated third subgraph, the nodes that are not directly or indirectly connected to the intersecting nodes through specific nodes in other search steps can be searched in the updated third subgraph. In this embodiment, node "h" and node "3" are not directly or indirectly connected to any intersecting nodes through nodes other than the starting node "1" and the target node "e". Delete node "h" and node "3", and delete the connection relationship between the deleted nodes and other nodes, and retain the connection relationship between the retained nodes. The obtained paths are: "1-2-4-8-e", "1-2-5-8-e" and "1-2-5-9-e". The obtained paths together constitute the target subgraph as shown in FIG. Figure 3 As shown in the lower right figure of . It can be understood that Figure 3 The method of deleting nodes and connection relationships by back-off filtering operation to obtain the target subgraph is only an example, and other suitable methods can be used to generate Figure 3 The target subgraph is shown.

[0035] According to the above technical solution, the first subgraph and the second subgraph can be obtained by searching from the starting node and the target node respectively, and the target subgraph is generated based on the intersection between the node searched in the last step of the first subgraph and the node searched in the last step of the second subgraph. This two-way search method can effectively reduce the amount of calculation when sampling the subgraph, and help improve the generation efficiency of the target subgraph. This solution can quickly and accurately generate the target subgraph.

[0036] Optionally, a target subgraph is generated based on the first subgraph and the second subgraph, including: merging the first subgraph and the second subgraph to generate a third subgraph; in the third subgraph, determining the intersecting nodes and non-intersecting nodes between the nodes searched in the last step in the first subgraph and the nodes searched in the last step in the second subgraph; performing the following operations on the third subgraph to obtain the target subgraph: retaining the non-intersecting nodes directly connected to the intersecting nodes and the connection relationship between the two; and deleting the non-intersecting nodes indirectly connected to the intersecting nodes to obtain an updated third subgraph; in the updated third subgraph, deleting other nodes that are not directly or indirectly connected to the intersecting nodes through specific nodes and the connection relationship between the deleted nodes and other nodes to obtain the target subgraph.

[0037] Exemplarily, the third subgraph may include all nodes and connection relationships of the first subgraph and all nodes and connection relationships of the second subgraph, wherein all nodes of the first subgraph and all nodes of the second subgraph may have an intersection, and the nodes in the intersection are the same nodes searched by the first subgraph and the second subgraph in the last step, and the nodes in the intersection are recorded as intersection nodes, and the intersection nodes can be simultaneously used as the nodes searched by the first subgraph in the last step and the nodes searched by the second subgraph in the last step. The nodes searched by the first subgraph in the last step may not be completely the same as the nodes searched by the second subgraph in the last step. The different nodes searched by the first subgraph and the second subgraph in the last step are recorded as non-intersecting nodes. The third subgraph can be obtained by taking the union of the first subgraph and the second subgraph. For the third subgraph, when the non-intersecting nodes are directly connected to the intersecting nodes, the non-intersecting nodes and the connection relationship between the non-intersecting nodes and the intersecting nodes can be retained; when the non-intersecting nodes are not directly connected to the intersecting nodes, the non-intersecting nodes are deleted to obtain the updated third subgraph. In the updated third subgraph, other nodes that are not directly or indirectly connected to the intersecting nodes through specific nodes can be deleted, and the connection relationship between the deleted nodes and other nodes can be deleted. The third subgraph after the node and connection relationship deletion operation can be used as the target subgraph.

[0038] According to the above technical solution, by deleting the nodes in the third subgraph that are not on the path containing the intersecting nodes and the connection relationship between the deleted nodes and other nodes to obtain the target subgraph, the number of irrelevant nodes and irrelevant paths on the generated target subgraph can be reduced, thereby further improving the subgraph sampling efficiency.

[0039] Optionally, when the longest path hyperparameter is even, the first number of steps is equal to the second number of steps.

[0040] Exemplarily, the longest path hyperparameter may be an even number, in which case the first step number may be equal to the second step number, and the first step number and the second step number are equal to half of the path hyperparameter. For example, when the longest path hyperparameter is 4, the first step number and the second step number may both be 2.

[0041] In the above technical solution, since the sum of the first step and the second step is the longest path hyperparameter, the number of levels that need to be searched is relatively small, which can avoid repeated calculations on nodes and edges (relationships) between nodes, and help reduce the number of nodes that need to be calculated, thereby helping to save time for subgraph sampling.

[0042] Optionally, when the longest path hyperparameter is an odd number, the first step number k1 = (L+1) / 2, the second step number k2 = (L-1) / 2; or, the first step number k1 = (L-1) / 2, the second step number k2 = (L+1) / 2; where L is the longest path hyperparameter.

[0043] Exemplarily, the longest path hyperparameter can also be an odd number, in which case the first step and the second step can differ by one step. When the longest path hyperparameter is K (K is an odd number), the first step can be equal to (L+1) / 2 or (L-1) / 2, and the second step can be equal to (L-1) / 2 or (L+1) / 2. For example, when the longest path hyperparameter is equal to 5, the first step is equal to 2 and the second step is equal to 3; or, the first step is equal to 3 and the second step is equal to 2. The numerical relationship between the first step and the second step can be defined by oneself, and it can satisfy that the sum of the first step and the second step is equal to the longest path hyperparameter, and the absolute value of the difference between the first step and the second step is equal to 1. The embodiments of the present invention do not make specific limitations.

[0044] In the above technical scheme, when the longest path hyperparameter is an odd number, by setting the difference between the first step and the second step to 1, and the sum of the first step and the second step to the longest path hyperparameter, the number of levels to be searched can be reduced, and by setting the difference between the first step and the second step to 1, the first step and the second step can be made more balanced, so that the search path and search calculation corresponding to the starting node, as well as the search path and search calculation corresponding to the target node are more reasonable, further improving the subgraph sampling efficiency.

[0045] Optionally, a target subgraph is generated based on the first subgraph and the second subgraph, including: merging the first subgraph and the second subgraph to generate a third subgraph; in the third subgraph, determining the intersection node between the node searched in the last step in the first subgraph and the node searched in the last step in the second subgraph; performing the following operations on the third subgraph to obtain the target subgraph: for the third subgraph, starting from the node searched in the last step in the first subgraph, step by step performing a fallback filtering operation until falling back to the starting node, and starting from the node searched in the last step in the second subgraph, step by step performing a fallback filtering operation until falling back to the target node, to obtain the target subgraph, wherein the fallback filtering operation includes: for each node, when the node is not directly connected to the intersection node and is not indirectly connected to the intersection node through a preceding node, deleting the node and the connection relationship between the node and other nodes, wherein the preceding node is a node on the fallback path where the node is located and before the node.

[0046] For example, please refer to Figure 3The lower left figure in the figure is the result obtained by deleting each node in the first subgraph and the second subgraph through a fallback filtering operation on the basis of the third subgraph, when the node is not directly connected to the intersecting node and is not indirectly connected to the intersecting node through the preceding node, and the connection relationship between the node and other nodes. For the third subgraph, the nodes searched in the last step of the first subgraph are: node "4", node "5" and node "6". Taking node "6" as an example, fall back from node "6" to node "1" step by step, wherein the fallback path starts from node "6" and ends at node "1", and the fallback path is "6-3-1". It can be understood that in this embodiment, node "6" is the preceding node of node "3", and node "3" is the preceding node of node "1". On the fallback path, node "6" has no preceding node, and node "3" is a node that is not directly or indirectly connected to the intersecting node "4" or the intersecting node "5" through the preceding node "6". Node "6" and node "3" are deleted, and the connection relationship (edge) between the deleted node and other nodes is deleted. Since node "4" and node "5" themselves are intersecting nodes, the nodes on the fallback path where node "4" and node "5" are located are all directly or indirectly connected to node "4" or node "5" through the preceding node. In this case, the fallback filtering operation may not be performed, or the fallback filtering operation may be performed. It can be understood that during the fallback filtering operation for node "4" and node "5", no connection relationship between nodes is deleted from the third subgraph. Similarly, the nodes searched in the last step in the second subgraph are: node "4", node "5", node "j" and node "k". Taking node "j" as an example, node "j" is not directly connected to the intersecting nodes (node ​​"4" and node "5"), and node "j" has no preceding node, so delete node "j". Node "g" on the fallback path "jge" is directly connected to the intersecting node "5", so retain node "5". On the fallback path "jhe", by the same token, delete node "h". The fallback path where node "k" is located is the same. In summary, delete nodes "j", "h", and "k" from the second subgraph, and delete the connection relationship (edge) between the deleted nodes and other nodes. The final target subgraph is as follows. Figure 3 As shown in the lower right figure.

[0047] In the above technical solution, irrelevant nodes in the third subgraph can be deleted through gradual back-off filtering, and it helps to avoid accidental deletion of nodes associated with the starting node, so that the edges (relationships) between the retained nodes are more reasonable, thereby making the obtained target subgraph more reasonable.

[0048] According to another aspect of the present invention, a link prediction method based on knowledge graph is also provided. Figure 4As shown, it is a schematic flow chart of a link prediction method based on a knowledge graph according to an embodiment of the present invention. The link prediction method based on a knowledge graph includes: step S410, step S420 and step S430.

[0049] In step S410, target triplet information to be tested is obtained, where the target triplet information to be tested at least includes a start node to be tested and a target node to be tested.

[0050] See also Figure 5 As shown, Figure 5 Schematic diagram of a knowledge graph according to an embodiment of the present invention. Figure 5 In the illustrated embodiment, the target triplet information to be tested includes: the starting node to be tested "1" (node ​​"1" represents drug A), the target node to be tested "5" (node ​​"5" represents disease B), and the link path to be tested representing the preset relationship to be tested, and the link path to be tested is "whether drug A can treat disease B".

[0051] In step S420, according to the nodes included in the target triple information to be tested, the target subgraph sampling method described above is used to sample in the knowledge graph to obtain the target subgraph to be tested corresponding to the start node to be tested and the target node to be tested.

[0052] See also Figure 6 As shown, Figure 6 A schematic diagram of a target subgraph to be tested according to an embodiment of the present invention is shown. The target subgraph to be tested is based on Figure 5 The knowledge graph shown is obtained by sampling according to the sampling method of the above scheme, which will not be repeated here. It can be understood that in the target subgraph to be tested, the paths from the start node to be tested to the target node to be tested include: "1-2-5", "1-3-5", "1-2-3-5" and "1-3-2-5".

[0053] In step S430, the target subgraph to be tested and the target triplet information to be tested are input into the trained graph neural network model for reasoning to obtain the reasoning result.

[0054] Exemplarily, in the graph neural network model, an inference result can be obtained based on the input target subgraph to be tested and the input target triple information to be tested. Specifically, when the input target triple information to be tested only includes two of the starting node to be tested, the target node to be tested, and the link path to be tested between the two, the inference result that the graph neural network can obtain includes the missing information in the input target triple information to be tested, and the probability or score that the target triple information to be tested is established (that is, there is a link path to be tested between the starting node to be tested and the target node to be tested). When the input target triple information to be tested includes the starting node to be tested, the target node to be tested, and the link path to be tested between the two, the inference result that the graph neural network can obtain includes the probability or score that the target triple information to be tested is established (that is, there is a link path to be tested between the starting node to be tested and the target node to be tested). Please continue to refer to Figure 5 and Figure 6 As shown, the input link path to be tested can be a question with indicative meaning, such as "Can drug A treat disease B?", "What diseases can drug A treat?", etc. It can be understood that when there is a link path to be tested, at least one triple can be formed. Specifically, for the question "Can drug A treat disease B?", a complete triplet of target to be tested information can be formed: the starting node to be tested "1" representing drug A, the target node to be tested "5" representing disease B, and the link path to be tested "Is there a therapeutic relationship between drug A and disease B?" For this triplet, the sampling method provided in the above-mentioned embodiment of the present invention is used to perform the sampling. Figure 5 Sampling the knowledge graph shown can yield Figure 6The target subgraph to be tested is shown and will not be described in detail here. As for the question "What diseases can drug A treat?", the known information of the triples contained in this question includes: the starting node 1 to be tested representing drug A, and the link path to be tested "Is there a therapeutic relationship between drug A and the diseases on the knowledge graph?" Regarding the link path to be tested "Is there a therapeutic relationship between drug A and the diseases on the knowledge graph", although it does not indicate a specific disease, it limits the scope of the target nodes to be tested: all nodes representing diseases on the knowledge graph. Therefore, multiple triples can be determined in the knowledge graph. For each triple, the longest path hyperparameter can be defined to determine multiple paths of the triple to obtain the target subgraph to be tested (that is, the knowledge graph is sampled according to the sampling method provided in the above-mentioned embodiment of the present invention to obtain the target subgraph to be tested). Those skilled in the art can understand that graph neural network models for link prediction of knowledge graphs may include: Graph Convolutional Networks (GCNs), Graph Attention Networks (GATs), Relational Graph Convolutional Networks (R-GCNs), etc. The type of reasoning results output by the graph neural network model may be scores, ratings, probabilities, etc. Taking the type of reasoning result as a score as an example, the link path to be tested can be scored according to the score interval of [0, 100]. More specifically, the graph neural network model can score each path from the starting node to the target node, wherein the score of each path can be equal to the sum of the scores of the edges (relationships) between each adjacent node on the path. It can be understood that the higher the score, the greater the possibility of the existence of the link path to be tested. It is also possible to set a score threshold and determine whether there is a link path to be tested between the starting node to be tested and the target node to be tested by comparing the output score with the score threshold. For example, the score threshold is set to 50. Figure 6 The target subgraph to be tested is input into the trained graph neural network model, and the output reasoning result is: the score of the therapeutic relationship between drug A and disease B is 80 points, which is higher than the score threshold of 50. It can be considered that there is a therapeutic relationship between drug A and disease B.

[0055] In the above technical scheme, by inputting the target subgraph to be tested obtained based on the above target subgraph sampling method into the trained graph neural network model, the amount of calculation of the nodes and the relationships between the nodes of the graph neural network model can be reduced, and the inference results can be generated quickly and accurately.

[0056] Optionally, the trained graph neural network model is trained through the following training steps: obtaining multiple sample triple information, each sample triple information including a sample starting node, a sample target node and a link path between the two; according to each sample triple information, using the above-mentioned target subgraph sampling method to sample in the knowledge graph to obtain a sample target subgraph; based on multiple sample triple information and the corresponding multiple sample target subgraphs, training the graph neural network model to obtain a trained graph neural network model.

[0057] Exemplarily, from an existing knowledge graph, one or more sample target subgraphs can be obtained by sampling the knowledge graph according to the sampling method provided by the above embodiment of the present invention, and each sample target subgraph can include one or more sample triples. Each sample triple corresponds to a set of sample triple information, including: a sample starting node, a sample target node, and a link path between the two. Each sample triple is annotated with a set of label information, and the label information of each sample triple corresponds to the sample triple information of each sample triple. By inputting the sample target subgraph into the graph neural network model, the graph neural network model can be adjusted according to the inference results output by the graph neural network model and the label information corresponding to the sample triples in the sample target subgraph to obtain a graph neural network model that meets the preset requirements. In a specific embodiment, the multiple sample target subgraphs obtained by sampling the knowledge graph using the sampling method provided by the above embodiment of the present invention include multiple sample triples. For a certain sample triple, its corresponding sample triple information can be, for example, (drug A, disease B, drug A can treat disease B (or there is a therapeutic relationship between drug A and disease B)). In this group of sample triple information, drug A is used as the sample starting node, disease B is used as the sample target node, and drug A can treat disease B (or there is a therapeutic relationship between drug A and disease B) as the link path between the sample starting node and the sample target node. It can be understood that the label information of the sample triple is that there is a link path between the sample starting node and the sample target node. For another sample triple, its corresponding sample triple information can be, for example, (drug A, disease C, the side effect of drug A is disease C (or there is a causal relationship between drug A and disease C)). In this sample triple information, drug A is used as the sample starting node, disease C is used as the sample target node, and the side effect of drug A is disease C (or there is a causal relationship between drug A and disease C) as the link path between the sample starting node and the sample target node. It can be understood that the label information of the sample triple is that there is a link path between the sample starting node and the sample target node.

[0058] In the above technical solution, the target subgraph obtained based on the above target subgraph sampling method is used as a sample target subgraph, which can make the training speed of the graph neural network model faster and the reasoning accuracy of the trained graph neural network model higher.

[0059] Optionally, the graph neural network model includes an aggregation module and a prediction module. When the target subgraph to be tested and the link path to be tested are input into the trained graph neural network model for reasoning, an aggregation function is used in the aggregation module to calculate the aggregation features of each node in the target subgraph to be tested, and link prediction is performed in the prediction module based on the aggregation features of each node in the target subgraph to be tested to determine the reasoning result.

[0060] Exemplarily, in the aggregation module of the graph neural network model, for any starting node to be tested in the target subgraph to be tested, an aggregation function can be used to aggregate the features of nodes that are connected (including direct and indirect connections) to the node to form the aggregated features of the node. The aggregation function can be, for example: mean function (MeanAggregation), maximum pooling function (Max Pooling Aggregation), sum function (Sum Aggregation), attention mechanism function (Attention-based Aggregation), etc. The prediction module can enumerate the paths from the starting node to be tested to the target node to be tested, and evaluate each path to determine the inference result. Please continue to refer to Figure 6 As shown, in Figure 6 In the target subgraph to be tested shown, node "1" can be used as the starting node to be tested, and node "5" can be used as the target node to be tested. Among them, node "1" represents drug A, node "5" represents disease B, and node "2" represents gene C. In the prediction module of the graph neural network model, the prediction module enumerates all the paths from node "1" to node "5", and the paths that can be obtained include: "1-2-5", "1-3-5", "1-2-3-5" and "1-3-2-5". The graph neural network model can score each obtained path. If there is any path whose score meets the preset requirements, it can be considered that drug A can treat disease B based on the score of the path, that is, the path exists. For example, in the path "1-2-5", drug A can repair gene C, which is the cause of disease B. The graph neural network scores the path "1-2-5" based on the relationship between drug A and gene C and the relationship between gene C and disease B, and meets the preset requirements, and the inference result of "drug A can treat disease B" can be obtained. It can be understood that if the scores of all paths do not meet the preset requirements, the inference result of "drug A cannot treat disease B" can be obtained.

[0061] In the above technical scheme, the aggregation function can effectively utilize the direct information and hidden information contained in the target subgraph to be tested. By calculating the aggregation features of each node, the information contained in the node can be enriched, which helps to capture the hidden relationship between the nodes and make the output reasoning result more accurate.

[0062] Optionally, the graph neural network model includes a neighborhood-based filtering network model, and the aggregation function includes a primary neighborhood aggregation function based on the graph neural network.

[0063] Exemplarily, the graph neural network model can adopt a neighborhood-based filtering network model (Neural Bellman-Ford Network, NBFNet), and in NBFNet, a principal neighborhood aggregation function (Principal Neighbourhood Aggregation for Graph Nets, PNA aggregation function) based on a graph neural network can be adopted. In some embodiments, the PNA aggregation function can initialize the entities represented by each node in the target subgraph to be tested as a vector, and NBFNet can optimize the vector corresponding to each node through a parameterized dynamic programming operator to obtain the target vector corresponding to each node, and by calculating the similarity between the target vectors corresponding to each node, the potential link paths (edges) between the nodes of the target subgraph to be tested can be predicted.

[0064] In the above technical solution, the graph neural network model can combine the local structure perception ability of the PNA aggregation function and the path learning ability of NBFNet, so as to comprehensively improve the expression ability of the graph neural network model and the accuracy of link prediction.

[0065] Optionally, before obtaining the three sets of target information to be tested, it also includes: obtaining triplet information to be tested, the triplet information to be tested includes the starting node to be tested, the unique node to be tested among the target nodes to be tested, and the link path to be tested; the above-mentioned obtaining of the target triplet information to be tested specifically includes: traversing the knowledge graph, and determining at least one target triplet information to be tested based on the starting node to be tested, the unique node to be tested among the target nodes to be tested, and the link path to be tested in the triplet information to be tested.

[0066] Exemplarily, the triple information to be tested can be defined according to actual prediction needs, and it can include the starting node to be tested and the target node to be tested, which can be directly used as the target triple information to be tested; or it can include the starting node to be tested and the link path to be tested, then at least one triple can be determined in the knowledge graph according to the starting node to be tested and the link path to be tested, and each triple can be used as a target triple information to be tested; or it can include the link path to be tested and the target node to be tested, then at least one triple can be determined in the knowledge graph according to the link path to be tested and the target node to be tested, and each triple can be used as the target triple information to be tested; or it can include the starting node to be tested, the target node to be tested and the link path to be tested between the two, which can be directly used as the target triple unit to be tested.

[0067] Exemplarily, when the triple information to be tested only includes the starting node to be tested and the only node to be tested among the target nodes to be tested, the knowledge graph can be traversed, and based on the starting node to be tested in the triple information to be tested, the only node to be tested among the target nodes to be tested, and the link path to be tested, at least one triple information can be determined, and each triple information is used as the above-mentioned target triple information to be tested, and the target triple information to be tested makes up for the information of a node missing in the triple information to be tested. For example, when the triple information to be tested includes the starting node to be tested and the target node to be tested is missing, at least one target node to be tested can be obtained by traversing the knowledge graph. Exemplarily, each target triple information to be tested obtained after traversing the knowledge graph includes the nodes in the initial triple information to be tested and the nodes obtained after traversing the knowledge graph, and the types of the original nodes of each triple information to be tested and the nodes obtained after traversing the knowledge graph are different. Specifically, in each determined triple information to be tested, if the starting node to be tested is known, the determined target node is the target node to be tested. Exemplarily, the target subgraph sampling method described above can be used to sample in the knowledge graph according to the nodes included in each determined target triple information to be tested, and the target subgraphs corresponding to each determined target triple information to be tested are obtained as the target subgraph to be tested. The target subgraphs corresponding to each determined target triple information to be tested and the corresponding target triple information to be tested are input into the trained graph neural network model for reasoning to obtain the reasoning results corresponding to each target triple information to be tested. In a specific embodiment, the initial triple information to be tested may include drug A (as the starting node to be tested), and which diseases drug A can treat (as the link path to be tested). According to the link path to be tested "drug A can treat", at least one disease treated by drug A on the knowledge graph can be obtained (as the target node to be tested), and the determined at least one disease is then determined one-to-one to determine at least one complete target triple information to be tested. Each target triplet information to be tested determined may include drug A, a specific disease (as a target node to be tested), and a treatment relationship (as a link path to be tested). For each complete target triplet information to be tested determined, the starting node to be tested and the target node to be tested included in the target triplet information to be tested may be obtained. After obtaining the starting node to be tested and the target node to be tested, the longest path hyperparameter may be defined, and the knowledge graph may be sampled according to the sampling method provided in the above embodiment of the present invention to obtain a target subgraph to be tested.Exemplarily, each complete target triplet information to be tested determined can correspond to a target subgraph. For each target subgraph, the target subgraph and the target triplet information to be tested can be input into the trained graph neural network model, and the graph neural network model can accordingly output the inference result corresponding to the target subgraph. The inference result is used to indicate whether there is a link path to be tested between the start node to be tested and the target node to be tested in the group of target triplet information to be tested, and / or the probability of the existence of the link path to be tested, that is, the probability that drug A treats the target disease.

[0068] When the triple information is incomplete, the above technical solution can supplement the triple information by traversing the knowledge graph to obtain at least one target subgraph to be tested that can be calculated in the graph neural network model, and then obtain more comprehensive and accurate reasoning results for the link path to be tested.

[0069] Optionally, the triple information to be tested may also include a starting node to be tested and a target node to be tested. According to the nodes included in the triple information to be tested, the above-mentioned target subgraph sampling method is used to sample in the knowledge graph to obtain the target subgraph to be tested corresponding to the starting node to be tested and the target node to be tested. Specifically including: according to the starting node to be tested and the target node to be tested in the target triple information to be tested, the above-mentioned target subgraph sampling method is used to sample in the knowledge graph to obtain the target subgraph to be tested.

[0070] As described above, the target triple information to be tested can include the starting node to be tested, the target node to be tested, and the link path to be tested at the same time. In this case, there is no missing information that needs to be determined, and the target subgraph to be tested is determined directly based on the starting node to be tested, the target node to be tested, and the link path to be tested, and then the target subgraph to be tested and the link path to be tested can be input into the graph neural network model for reasoning. In a specific embodiment, for the question "Can drug A treat disease B?", a fixed triple can be formed: the starting node to be tested representing drug A, the target node to be tested representing disease B, and the link path to be tested "Is there a therapeutic relationship between drug A and disease B?" For the starting node to be tested representing drug A and the target node to be tested representing disease B in the triple, the knowledge graph where the triple is located can be sampled according to the sampling method provided in the above embodiment of the present invention to obtain a target subgraph to be tested. The specific sampling process has been described in detail in the sampling method provided in the above embodiment of the present invention, and it will not be repeated here.

[0071] In the above technical solution, the target triplet information to be tested includes both the starting node to be tested and the target node to be tested. In this case, the target subgraph to be tested can be directly determined. Although there is missing information, it is not necessary to determine the missing information. This solution can quickly determine the target subgraph to be tested and perform link prediction, with less calculation.

[0072] Optionally, the inference result includes at least one of the following results: the probability that there is a link path to be tested between the starting node to be tested and the target node to be tested, at least a portion of the path between the starting node to be tested and the target node to be tested, and a path score corresponding to at least a portion of the path between the starting node to be tested and the target node to be tested.

[0073] Exemplarily, in some embodiments, the inference result output by the trained graph neural network model may be the probability that there is a link path to be tested between the starting node to be tested and the target node to be tested. The higher the output probability, the higher the correlation between the starting node to be tested and the target node to be tested, and the greater the possibility that there is a link path to be tested between the starting node to be tested and the target node to be tested. In other embodiments, the inference result output by the trained graph neural network model may be at least a portion of the path between the starting node to be tested and the target node to be tested. The path can be used to explain the direct or indirect reasons why there may be a link path to be tested between the starting node to be tested and the target node to be tested. For example, when the trained graph neural network model is input with "whether there is a therapeutic relationship between drug A and disease B", the path "drug A-gene C-disease B" can be obtained, wherein drug A can repair gene C, gene C is one of the causes of disease B, and the path can explain why drug A and disease B may have a therapeutic relationship. In some other embodiments, the inference result output by the trained graph neural network model may be at least a portion of the path between the starting node to be tested and the target node to be tested, as well as the corresponding path scores. The higher the path score, the greater the possibility that there is a link path to be tested between the starting node to be tested and the target node to be tested, and the higher the reliability of the path corresponding to the reason for the possible existence of the link path to be tested between the starting node to be tested and the target node to be tested. It can be understood that the reasoning results output by the graph neural network can include one or more of the multiple reasoning results described in the above embodiments.

[0074] In the above technical solution, the possibility of the existence of a link path to be tested between the starting node to be tested and the target node to be tested can be quantified through probability, path and path score, which can make the reasoning result more objective and have a strong reference value.

[0075] Optionally, at least part of the paths are paths between the start node to be tested and the target node to be tested whose path scores are greater than a score threshold and whose rankings are before a preset ranking when the path scores are sorted from high to low.

[0076] Exemplarily, a score threshold and a preset ranking can be defined. The score threshold can be used to filter out paths with low correlation between the starting node to be tested and the target node to be tested. It can be understood that the path with a path score greater than the score threshold can be considered to be more reliable for explaining the reason why there may be a link path to be tested between the starting node to be tested and the target node to be tested, and it can be judged that the possibility of the link path to be tested between the starting node to be tested and the target node to be tested is greater. Similarly, the preset ranking can be used to filter out paths with low correlation between the starting node to be tested and the target node to be tested, and can also be used to limit the number of paths to be output. Specifically, before outputting the path between the starting node to be tested and the target node to be tested, the path score corresponding to each path can be obtained first, and then sorted from high to low according to the path score, retaining the path score greater than the score threshold and ranking before the preset ranking as at least part of the reasoning result output.

[0077] In the above technical solution, by setting the score threshold and the preset ranking, the number of output reasoning results can be made more reasonable, thereby making the retained reasoning results more referenceable.

[0078] Although example embodiments have been described herein with reference to the accompanying drawings, it should be understood that the above example embodiments are merely exemplary and are not intended to limit the scope of the present invention thereto. Various changes and modifications may be made therein by one of ordinary skill in the art without departing from the scope and spirit of the present invention. All such changes and modifications are intended to be included within the scope of the present invention as required by the appended claims.

[0079] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.

[0080] It should be noted that the above embodiments illustrate the present invention rather than limit it, and that those skilled in the art may devise alternative embodiments without departing from the scope of the appended claims. In the claims, any reference symbol between brackets shall not be construed as a limitation on the claims. The word "comprising" does not exclude the presence of elements or steps not listed in the claims. The word "one" or "an" preceding an element does not exclude the presence of a plurality of such elements. The present invention may be implemented by means of hardware comprising a number of different elements and by means of a suitably programmed computer. In a unit claim enumerating a number of devices, several of these devices may be embodied by the same hardware item. The use of the words first, second, and third, etc., does not indicate any order. These words may be interpreted as names.

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

Claims

1. A method for sampling a target subgraph of a knowledge graph, wherein the target subgraph is used to be input into a graph neural network model for link prediction, wherein the graph neural network model has a longest path hyperparameter, and the longest path hyperparameter represents the maximum number of steps between a starting node for generating the target subgraph and a target node for generating the target subgraph; characterized in that: The method comprises: Searching the knowledge graph from the starting node according to the first step to obtain a first subgraph; Searching the knowledge graph from the target node according to a second number of steps to obtain a second subgraph; wherein the sum of the first number of steps and the second number of steps is the longest path hyperparameter; A target subgraph is generated according to the first subgraph and the second subgraph, wherein in the target subgraph, the intersecting nodes in the nodes of the last step of the first subgraph and the second subgraph are retained, the non-intersecting nodes directly connected to the intersecting nodes are retained, the other nodes directly or indirectly connected to all the intersecting nodes through specific nodes in other search steps are retained, and the connection relationship between any two nodes in all the retained nodes is retained, and the specific nodes are nodes other than the starting node and the target node.

2. The target subgraph sampling method of the knowledge graph according to claim 1 is characterized in that: The generating a target subgraph according to the first subgraph and the second subgraph comprises: Merging the first subgraph and the second subgraph to generate a third subgraph; In the third subgraph, determining the intersecting nodes and non-intersecting nodes between the node searched in the last step in the first subgraph and the node searched in the last step in the second subgraph; Perform the following operations on the third subgraph to obtain the target subgraph: The non-intersecting nodes directly connected to the intersecting nodes and the connection relationship between the two are retained; and the non-intersecting nodes indirectly connected to the intersecting nodes are deleted to obtain an updated third subgraph; In the updated third subgraph, other nodes that are not directly or indirectly connected to the intersecting node through a specific node and the connection relationship between the deleted nodes and other nodes are deleted to obtain the target subgraph.

3. The target subgraph sampling method of the knowledge graph according to claim 1 is characterized in that: When the longest path hyperparameter is an even number, the first number of steps is equal to the second number of steps.

4. The target subgraph sampling method of the knowledge graph according to claim 1, characterized in that: When the longest path hyperparameter is an odd number, The first step number k1=(L+1) / 2, the second step number k2=(L-1) / 2; Or, the first step number k1=(L-1) / 2, the second step number k2=(L+1) / 2; Wherein, L is the longest path hyperparameter.

5. The target subgraph sampling method of the knowledge graph according to claim 1, characterized in that: The generating a target subgraph according to the first subgraph and the second subgraph comprises: Merging the first subgraph and the second subgraph to generate a third subgraph; In the third subgraph, determining the intersection node between the node searched in the last step in the first subgraph and the node searched in the last step in the second subgraph; Perform the following operations on the third subgraph to obtain the target subgraph: For the third subgraph, a fallback filtering operation is performed step by step from the node searched in the last step in the first subgraph until falling back to the starting node, and a fallback filtering operation is performed step by step from the node searched in the last step in the second subgraph until falling back to the target node, so as to obtain the target subgraph, wherein the fallback filtering operation includes: for each node, when the node is not directly connected to the intersecting node and is not indirectly connected to the intersecting node through a preceding node, deleting the node and the connection relationship between the node and other nodes, wherein the preceding node is a node on the fallback path where the node is located and before the node.

6. A link prediction method based on knowledge graph, characterized in that: The steps include: Acquire target triplet information to be tested, wherein the target triplet information to be tested includes at least a start node to be tested and a target node to be tested; According to the target triple information to be tested, the target subgraph sampling method described in any one of claims 1 to 5 is adopted to sample in the knowledge graph to obtain the target subgraph to be tested corresponding to the starting node to be tested and the target node to be tested; The target subgraph to be tested and the target triplet information to be tested are input into the trained graph neural network model for reasoning to obtain the reasoning result.

7. The link prediction method based on knowledge graph according to claim 6, characterized in that: The trained graph neural network model is trained through the following training steps: Acquire multiple sample triplet information, each of the sample triplet information includes a sample start node, a sample target node and a link path between the two; According to each of the sample triplet information, sampling is performed in the knowledge graph using the target subgraph sampling method described in any one of claims 1 to 5 to obtain a sample target subgraph; Based on the multiple sample triplet information and the corresponding multiple sample target subgraphs, the graph neural network model is trained to obtain the trained graph neural network model.

8. The link prediction method based on knowledge graph according to claim 6 or 7, characterized in that: The graph neural network model includes an aggregation module and a prediction module. When the target subgraph to be tested and the link path to be tested are input into the trained graph neural network model for reasoning, an aggregation function is used in the aggregation module to calculate the aggregation features of each node in the target subgraph to be tested, and link prediction is performed in the prediction module based on the aggregation features of each node in the target subgraph to be tested to determine the reasoning result.

9. The link prediction method based on knowledge graph according to claim 8, characterized in that: The graph neural network model includes a neighborhood-based filtering network model, and the aggregation function includes a primary neighborhood aggregation function based on the graph neural network.

10. The link prediction method based on knowledge graph according to claim 6, characterized in that: Before obtaining the three sets of information of the target to be tested, the method further includes: Acquire the triplet information to be tested, wherein the triplet information to be tested includes the only node to be tested among the start node to be tested and the target node to be tested and the link path to be tested; The obtaining of target triplet information to be tested specifically includes: The knowledge graph is traversed, and at least one target triplet information to be tested is determined based on the unique node to be tested and the link path to be tested in the triplet information to be tested.