Knowledge sampling method and device based on knowledge graph and related equipment
By selecting a starting node in the knowledge graph and generating M-tuples based on distance and semantic relationships to control the transition probability, the problem of low path quality and uncontrollability caused by random path sampling is solved, thus achieving high-quality knowledge graph sampling.
Patent Information
- Application Number
- CN202210798948.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-07-08
- Publication Date
- 2026-08-25
- Estimated Expiration
- 2042-07-08
AI Technical Summary
In existing knowledge graph sampling methods, random path sampling results in low path quality, which cannot effectively reflect the overall structure of the knowledge graph and the semantic relationships between entities. Furthermore, the sampling is uncontrollable and cannot control the sampling bias in different domains.
In the knowledge graph, a starting node is selected, and M-tuples are generated by transitioning along directed edges with different probabilities. The transition probabilities are determined based on the distance and semantic relationship between the current node and its neighboring nodes, until the sampling path reaches the set length.
It improves the quality of sampling paths, better reflects the structure and semantic relationships of knowledge graphs, controls sampling bias, and enhances the controllability and quality of sampling paths.
Smart Images

Figure CN115309909B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of natural language processing technology, and more specifically, to a knowledge sampling method, apparatus and related equipment based on knowledge graphs. Background Technology
[0002] Currently, artificial intelligence technology is moving from perceptual intelligence to cognitive intelligence. Research on language understanding and knowledge mining is deepening, and the value of factual and common sense knowledge is gradually becoming apparent.
[0003] Domain knowledge graphs contain association patterns and contextual semantics of knowledge within that domain. When applying them to natural language understanding tasks such as entity extraction and relation recognition, or to intelligent applications such as question answering and recommendation, it is necessary to first sample and represent the knowledge in the knowledge graph. Most existing methods represent domain knowledge based on random path sampling and knowledge embedding. Random path sampling is completely random, which may result in paths containing a large number of duplicate entities, ambiguous semantics, and semantic irrelevance, leading to low-quality sampled paths that fail to accurately reflect the overall structure of the knowledge graph and the semantic relationships between entities. Furthermore, completely random sampling makes the sampling method unadjustable and uncontrollable, making it impossible to control sampling biases across different domains. Summary of the Invention
[0004] In view of the above problems, this application is proposed to provide a knowledge sampling method, apparatus, device, and storage medium based on knowledge graphs, so as to avoid the uncontrollability of existing random sampling methods and the inability to control sampling bias in different fields. The specific solution is as follows:
[0005] Firstly, a knowledge sampling method based on knowledge graphs is provided, including:
[0006] Obtain the target knowledge graph;
[0007] Select at least one node from the target knowledge graph as the starting node;
[0008] For each starting node, the nodes in the target knowledge graph are transferred along the directed edges with different probabilities. Each time a node is transferred, an M-tuple is generated based on the two nodes before and after the transfer and the directed edges. The M-tuple includes at least the head entity, the tail entity, and the relation name between the head and tail entities. During each transfer, the probability of the current node being transferred to any neighboring node is determined based on the distance between the nodes previously visited by the current node and the neighboring nodes, and / or the semantic relationship between the current node and the neighboring nodes.
[0009] The generated M-tuples are added to the sampling path corresponding to the starting node until the length of the sampling path reaches the set length, thus obtaining the final sampling path corresponding to each starting node.
[0010] Secondly, a knowledge sampling device based on a knowledge graph is provided, including:
[0011] The knowledge graph acquisition unit acquires the target knowledge graph.
[0012] The starting node selection unit is used to select at least one node in the target knowledge graph as a starting node;
[0013] The node transfer unit is used to transfer each starting node along directed edges between nodes in the target knowledge graph with different probabilities. Each time a node undergoes a transfer, an M-tuple is generated based on the two nodes before and after the transfer and the directed edges. The M-tuple includes at least a head entity, a tail entity, and the relation name between the head and tail entities. The probability of the current node transferring to any neighboring node during each transfer is determined based on the distance between the nodes previously traversed by the current node and the neighboring nodes, and / or the semantic relationship between the current node and the neighboring nodes.
[0014] The sampling path determination unit is used to add the generated M-tuples to the sampling path corresponding to the starting node until the length of the sampling path reaches the set length, so as to obtain the final sampling path corresponding to each starting node.
[0015] Thirdly, a knowledge sampling device is provided, including: a memory and a processor;
[0016] The memory is used to store programs;
[0017] The processor is used to execute the program to implement the various steps of the knowledge sampling method based on knowledge graphs as described above.
[0018] Fourthly, a storage medium is provided on which a computer program is stored, which, when executed by a processor, implements the various steps of the knowledge sampling method based on knowledge graphs as described above.
[0019] By employing the above technical solution, this application selects a starting node in the target knowledge graph, and then transfers nodes in the target knowledge graph along directed edges with different probabilities. Each time a node undergoes a transfer, an M-tuple is generated based on the two nodes before and after the transfer and the directed edge. This M-tuple includes at least a head entity, a tail entity, and the relation name between the head and tail entities. During each transfer, the probability of transferring from the current node to any neighboring node is determined based on the distance between the nodes previously traversed by the current node and the neighboring nodes, and / or the semantic relationship between the current node and the neighboring nodes. Thus, it can be seen that the walking sampling in this application is not completely random. Each time a node is transferred, the transfer probability can be determined by referring to the distance between the nodes previously traversed by the current node and the next neighboring node. Based on this, the guiding sampling tendency can be controlled, such as controlling the tendency to walk and sample around the starting node, or controlling the tendency to walk and sample in a depth direction away from the starting node, thereby reflecting the affinity of the knowledge graph in terms of homogeneity and structure. Furthermore, the transition probability can be determined by referring to the semantic relationship between the current node and the next neighbor node. Based on this, walking sampling can be performed along semantically clear relationships to improve the quality of the sampling path.
[0020] After each transfer generates an M-tuple, it can be added to the sampling path corresponding to the starting node until the length of the sampling path reaches the set length, thus obtaining the final sampling path corresponding to each starting node. Attached Figure Description
[0021] Various other advantages and benefits will become apparent to those skilled in the art upon reading the following detailed description of preferred embodiments. The accompanying drawings are for illustrative purposes only and are not intended to limit the scope of this application. Furthermore, the same reference numerals denote the same parts throughout the drawings. In the drawings:
[0022] Figure 1 A flowchart illustrating the knowledge sampling method provided in this application embodiment;
[0023] Figure 2 This is a schematic diagram of a knowledge sampling device provided in an embodiment of this application;
[0024] Figure 3 This is a schematic diagram of the structure of the knowledge sampling device provided in the embodiments of this application. Detailed Implementation
[0025] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0026] This application provides a knowledge sampling scheme based on knowledge graphs, which leverages the sampling bias within the knowledge graph to ensure that the sampled paths better reflect the overall structure of the knowledge graph and the semantic relationships between entities. Training data can be generated based on these sampled paths to train downstream task models, such as entity recognition models and relation extraction models.
[0027] The proposed solution can be implemented using a terminal with data processing capabilities, such as a mobile phone, computer, server, or cloud platform.
[0028] Next, combined Figure 1 The knowledge sampling method described in this application may include the following steps:
[0029] Step S100: Obtain the target knowledge graph.
[0030] The target knowledge graph is the knowledge graph of the target domain to be sampled. The knowledge sampled from the target knowledge graph can be used to train natural language processing models in the target domain, such as entity recognition models and relation extraction models. The target knowledge graph contains semantic information of knowledge in the target domain.
[0031] In this step, the structure of the target knowledge graph can be either a directed instance graph without ontology constraints or a directed semantic web subject to ontology constraints. Target Knowledge Graph A knowledge graph can contain a certain number of entities ξ, with clear and explicit relationships and names between them. These relationships are represented as follows:
[0032] Step S110: Select at least one node in the target knowledge graph as the starting node.
[0033] Specifically, in order to obtain a sampling path, the starting point of the path needs to be selected first. Therefore, a starting node can be selected in the target knowledge graph. The number of starting nodes can be one or more. Each starting node will eventually obtain a corresponding sampling path. That is, the number of selected starting nodes is consistent with the number of sampling paths obtained in the end.
[0034] Optionally, when selecting a starting node in the target knowledge graph, a random selection method can be used to randomly select a specified number of nodes as the starting node. Alternatively, the user can specify the starting node, or other strategies can be used to select the starting node.
[0035] Step S120: For each starting node, the nodes in the target knowledge graph are transferred along the directed edges with different probabilities. Each time a node undergoes a transfer, an M-tuple is generated based on the two nodes before and after the transfer and the directed edges.
[0036] Specifically, the node before the transition represents the head entity, and the node after the transition represents the tail entity. The directed edge between them represents the relation name between the two entities. Based on this, each time a node is transitioned, an M-tuple can be generated according to the two nodes before and after the transition and the directed edge. The M-tuple includes at least the head entity, the tail entity, and the relation name between the head and tail entities. That is, the M-tuple can be a triple, which includes the head entity, the tail entity, and the relation name between the head and tail entities. An example of a triple is: (Liu Moumou, Work, 《XXX》).
[0037] Furthermore, an M-tuple can also be a quintuple, which includes: a head entity and its concept, a tail entity and its concept, and the relation name between the head and tail entities. An example of a quintuple is: (Liu Moumou, singer, work, "XXX", song).
[0038] In this step, nodes are transferred along directed edges when sampling the path. That is, when transferring from the current node to the next node, it is only possible to transfer to a neighboring node of the current node.
[0039] Define the current node as v. Let V be the set of neighboring nodes of node v. Then, when node v moves to another node x in the graph, if x does not belong to the set of neighboring nodes of node v, the neighboring node will be determined by the set of neighboring nodes of node v. The corresponding transition probability is 0.
[0040] Furthermore, during each transition, the probability of transitioning from the current node v to any neighboring node x is determined based on the distance between the nodes previously traversed by the current node v (i.e., nodes preceding the current node v in the sampling path) and the neighboring node x, and / or the semantic relationship between the current node v and the neighboring node x. In other words, the probability of transitioning from the current node v to any neighboring node x can be influenced by two factors: the distance between the nodes previously traversed by the current node v and the neighboring node x, and the semantic relationship between the current node v and the neighboring node x.
[0041] It is understandable that different neighboring nodes may have different distances between the nodes that the current node v has previously traversed, and the semantic relationships between different neighboring nodes and the current node v may also be different. Therefore, when the current node v moves to different neighboring nodes, the corresponding transition probability may also be different. The specific transition probability can be controlled by a preset sampling strategy.
[0042] Step S130: Add the generated M-tuples to the sampling path corresponding to the starting node until the length of the sampling path reaches the set length, and obtain the final sampling path corresponding to each starting node.
[0043] Specifically, starting from each starting node, an M-tuple is generated after each transition. The generated M-tuple is then added to the sampling path corresponding to the starting node until the length of the sampling path reaches the set length, thus obtaining the final sampling path corresponding to the starting node.
[0044] Ultimately from knowledge graph In the process, a set of several sampling paths is collected, P = {p1, p2, p3, ..., p...}. n In set P, each sampling path p i p is a sequence consisting of several M-tuples i ={o1, o2, o3, ..., o m Taking the M-tuple as an example, the quintet can be represented as follows: e i and e j Let c represent the head entity and the tail entity respectively. i and c j r represents the concepts corresponding to the head entity and the tail entity. ij The name of the relationship between entities.
[0045] Since the sampling path is transferred along the directed edge, in two adjacent quintuples in the sampling path, the tail entity in the first quintuple is the same as the head entity in the second quintuple, thus ensuring the continuity of the path.
[0046] The set length corresponding to the sampling path can be a threshold number of quintuples contained in the sampling path. Generally, the set length can be 3, 4, 5, etc.
[0047] The knowledge sampling method provided in this application selects a starting node in the target knowledge graph, and then moves the nodes in the target knowledge graph along directed edges with different probabilities. Each time a node is moved, an M-tuple is generated based on the two nodes before and after the move and the directed edge. The M-tuple includes at least a head entity, a tail entity, and the relation name between the head and tail entities. Each time the node moves, the probability of moving from the current node to any neighboring node is determined based on the distance between the nodes previously traversed by the current node and the neighboring nodes, and / or the semantic relationship between the current node and the neighboring nodes. Thus, it can be seen that the walking sampling in this application is not completely random walking sampling. Each time a node moves, the distance between the nodes previously traversed by the current node and the next neighboring node can be referenced to determine the transfer probability. Based on this, the sampling tendency can be controlled, such as controlling the tendency to walk and sample around the starting node, or controlling the tendency to walk and sample in a depth direction away from the starting node, thereby reflecting the affinity of the knowledge graph in terms of homogeneity and structure.
[0048] Furthermore, the semantic relationship between the current node and its next neighbor node can be referenced to determine the transition probability. Based on this, walking sampling can be performed along semantically clear relationships to improve the quality of the sampling path. For example, the entity represented by the current node is "Liu Moumou". Most of its neighbor nodes have a relationship with the current node as "friend's name", while a small number of neighbor nodes have a relationship with the current node as "birthplace population". If the current node is transitioned to the neighbor node corresponding to "friend's name", the resulting quintuple, when converted into a training statement, might result in a training statement such as "What is the name of Liu Moumou's friend?" If the current node is transitioned to the neighbor node corresponding to "birthplace population", the resulting quintuple, when converted into a training statement, might result in a training statement such as "How many people are in Liu Moumou's birthplace?" For training statements like "What is the name of Liu Moumou's friend", because there are too many corresponding entity labels, such as person A and person B, which are all correct answers, the model needs to predict too many entity targets during training. This will result in low model discrimination of the knowledge vector representations of person A and person B, affecting the performance of downstream tasks.
[0049] Therefore, the fewer semantic relationships between the current node and its neighboring nodes, the clearer the semantic relationship; conversely, the more semantic relationships, the more ambiguous they are. Training a model based on ambiguous statements can lead to poor model loss convergence, large oscillations, increased training difficulty, low accuracy in knowledge representation, and slow training speed. Therefore, in this embodiment, the transition probability can be determined by referring to the semantic relationship between the current node and its next neighboring node. Based on this, sampling can be performed along semantically clear relationships, improving the quality of the sampling path. This ensures that when training the model with subsequently generated training statements, the training difficulty is reduced, the accuracy of knowledge representation is improved, and the model's convergence speed is accelerated.
[0050] In some embodiments of this application, the process of determining the probability of the current node moving to any neighboring node in step S120 above is described. This process is based on the distance between the current node and the neighboring nodes that it has previously traversed, and / or the semantic relationship between the current node and the neighboring nodes.
[0051] In one possible implementation:
[0052] The transfer score for the current node to move to any neighboring node can be determined first based on the distance between the nodes previously visited by the current node and the neighboring nodes, and / or the semantic relationship between the current node and the neighboring nodes.
[0053] Furthermore, for any target neighbor node:
[0054] The probability of the current node moving to the target neighbor node is determined based on the transfer score of the current node moving to the target neighbor node and the sum of the transfer scores of the current node moving to each neighbor node.
[0055] The scheme described in this embodiment determines the transfer score of the current node when it moves to a neighboring node, and further converts the transfer score into a transfer probability. In one optional approach, the conversion of the transfer score into the transfer probability is as follows:
[0056]
[0057] Among them, t i Let represent the i-th transition, v be the current node in the knowledge graph, and p(x) be the probability of transitioning to another node x in the graph. Where π vx This represents the transition score between node v and node x. Let N be the set of neighboring nodes of node v. v Let V be the number of neighboring nodes of node v, and let V be a value.
[0058] Furthermore, the process of determining the transfer score for the current node to any neighboring node can be based solely on the distance between the nodes previously traversed by the current node and the neighboring node, or solely on the semantic relationship between the current node and the neighboring node. Of course, it can also be based on both of the above factors simultaneously.
[0059] Here, the nodes that have been visited before the current node can be any one or more nodes in the sampling path that precede the current node. In this embodiment, the previous node of the current node is used as an example for illustration. The process of determining the transfer score of the current node to any neighboring node may include:
[0060] S1. Determine the first transfer score for the current node to transfer to the neighboring node based on the distance between the previous node of the current node and the neighboring node.
[0061] The previous node of the current node v can be represented as node e, where e = t i-2 .
[0062] Optionally, the distance d between node e and node x ex It can be the shortest number of jumps between node e and node x, with a value range of {0, 1, 2}. Different shortest jump numbers correspond to different transition score settings. The transition score setting corresponding to the shortest jump number 0 is controlled by the first hyperparameter p, and the transition score setting corresponding to the shortest jump number 2 is controlled by the second hyperparameter q.
[0063] Based on the shortest number of jumps between the current node's previous node e and its neighbor node x, the corresponding transition score setting value is selected as the first transition score α for the current node v to transition to its neighbor node x. pq (e, x).
[0064] An example of different shortest jump counts d ex The correspondence between the transfer score setting and the corresponding transfer score setting is as follows:
[0065]
[0066] Therefore, the hyperparameter *p* controls the tolerance for the sampling path to re-transfer to already visited nodes. A lower *p* value results in a higher first transfer score and a greater transfer probability, meaning the sampling path is more likely to transfer to already visited nodes, causing it to tend to traverse near the starting node. The hyperparameter *q* controls the bias in allowing the sampling path to transfer to deeper nodes. A lower *q* value results in a higher first transfer score and a greater transfer probability, meaning the sampling path will move away from the starting node.
[0067] By weighing the propensity of p and q, the tendency of sampling path walks can be guided, thereby reflecting the affinity of the domain knowledge graph in terms of homogeneity and structure.
[0068] The method provided in this step allows users to control the tendency of the sampling path to wander by setting different p and q values.
[0069] S2. Determine the second transfer score for the current node to transfer to the neighboring node based on the semantic relationship between the current node and the neighboring node.
[0070] Specifically, among the neighboring nodes of the current node, some have the same semantic relationship as the current node, while others have different semantic relationships. For example, if the entity represented by the current node is "Liu Moumou", then the relationships between its neighboring nodes A, B, and C and the current node are all "work relationship", while the relationship between node D and the current node is "birthplace population". The fewer the number of semantic relationships, the clearer the semantic relationship.
[0071] When moving from the current node to the next node, the selection of the transfer object from among the neighboring nodes can be based on semantically clear relationships, that is, a preference is given to transferring along relationship types with fewer semantic relationships. Using the example above, since the semantic relationship "birthplace population" has only one instance, while the semantic relationship "works relationship" has three instances, node D can be preferentially selected as the next transfer node. This means that the second transfer score for node D is set higher than that for nodes A, B, and C.
[0072] One possible implementation of step S2 is as follows:
[0073] For any target neighbor node of the current node:
[0074] S21. Determine the target relationship name between the current node and the target neighbor node.
[0075] Define the semantic relationship between the current node v and the target neighbor node x as r, that is, the target relationship name is r.
[0076] S22. Count the total number of neighboring nodes of the current node that have the target relation name with the current node.
[0077] Define the total number of neighboring nodes of the current node that have the target relation name r with the current node as follows:
[0078] S23, Based on the total number The number N of all neighboring nodes of the current node vAnd the third hyperparameter λ, to determine the second transition score of the current node v to the target neighbor node x.
[0079] Specifically, to ensure that nodes transition along semantically explicit relationships, a total number can be set. The larger the score, the higher the second transition score. The smaller the value, the better. Here, the hyperparameter λ is the penalty coefficient.
[0080] An optional method for calculating the second transfer score is as follows:
[0081]
[0082] Where λ≥0,
[0083] The larger the λ value, the more the sampling path tends to move along semantically explicit relationships.
[0084] S3. Determine the total transfer score of the current node to the neighboring node based on the first transfer score and / or the second transfer score.
[0085] Specifically, the first transition score α can be directly applied. pq (e, x) represents the total transition score π for the current node v to move to its neighbor node x. vx Alternatively, the second transfer score can be directly transferred. The total transition score π for the current node v to move to its neighbor node x vx Of course, the first transition score α can also be considered. pq (e, x) and second transition score Determine the total transfer score π vx For example:
[0086] The first transition score α pq (e, x) and second transition score Multiply, and the result is the total transfer score π. vx :
[0087]
[0088] As described in the above scheme, the total transfer score from the current node v to its neighbor node x can be varied by adjusting the three hyperparameters p, q, and λ. Therefore, different sampling strategies can be set by different combinations of p, q, and λ values to control the sampling bias of the sampling path in knowledge graphs of different domains.
[0089] In some embodiments of this application, based on the aforementioned final sampling paths, a corresponding training statement can be generated for each final sampling path based on the M-tuple sequence contained therein, and the training statement is used as training data for the entity recognition model.
[0090] The knowledge sampling device based on knowledge graphs provided in the embodiments of this application is described below. The knowledge sampling device based on knowledge graphs described below can be referred to in correspondence with the knowledge sampling method based on knowledge graphs described above.
[0091] See Figure 2 , Figure 2 This is a schematic diagram of the structure of a knowledge sampling device based on a knowledge graph disclosed in an embodiment of this application.
[0092] like Figure 2 As shown, the device may include:
[0093] Knowledge graph acquisition unit 11: Acquire the target knowledge graph;
[0094] The starting node selection unit 12 is used to select at least one node in the target knowledge graph as a starting node;
[0095] The node transfer unit 13 is used to transfer each starting node along directed edges between nodes in the target knowledge graph with different probabilities. Each time a node undergoes a transfer, an M-tuple is generated based on the two nodes before and after the transfer and the directed edges. The M-tuple includes at least a head entity, a tail entity, and the relation name between the head and tail entities. During each transfer, the probability of the current node transferring to any neighboring node is determined based on the distance between the nodes previously traversed by the current node and the neighboring nodes, and / or the semantic relationship between the current node and the neighboring nodes.
[0096] The sampling path determination unit 14 is used to add the generated M-tuples to the sampling path corresponding to the starting node until the length of the sampling path reaches the set length, so as to obtain the final sampling path corresponding to each starting node.
[0097] Optionally, the process by which the node transfer unit determines the probability of the current node transferring to any neighboring node based on the distance between the nodes previously traversed by the current node and the neighboring nodes, and / or the semantic relationship between the current node and the neighboring nodes, includes:
[0098] Based on the distance between the nodes previously visited by the current node and the neighboring nodes, and / or the semantic relationship between the current node and the neighboring nodes, determine the transfer score for the current node to move to any neighboring node;
[0099] For any target neighbor node:
[0100] The probability of the current node moving to the target neighbor node is determined based on the transfer score of the current node moving to the target neighbor node and the sum of the transfer scores of the current node moving to each neighbor node.
[0101] Optionally, the process by which the node transfer unit determines the transfer score for the current node to transfer to any neighboring node based on the distance between the nodes previously traversed by the current node and the neighboring nodes, and / or the semantic relationship between the current node and the neighboring nodes, may include:
[0102] Based on the distance between the previous node of the current node and the neighboring node, determine the first transfer score for the current node to transfer to the neighboring node;
[0103] Based on the semantic relationship between the current node and the neighboring nodes, determine the second transfer score for the current node to transfer to the neighboring nodes;
[0104] Based on the first transfer score and / or the second transfer score, determine the total transfer score for the current node to transfer to the neighboring node.
[0105] Optionally, the process by which the node transfer unit determines the first transfer score for the current node to transfer to the neighboring node based on the distance between the current node's previous node and the neighboring node may include:
[0106] Determine the shortest number of jumps between the previous node of the current node and the neighboring nodes. The shortest number of jumps is in the range of {0,1,2}. Different shortest number of jumps correspond to different transfer score settings. The transfer score setting corresponding to the shortest number of jumps 0 is controlled by the first hyperparameter p, and the transfer score setting corresponding to the shortest number of jumps 2 is controlled by the second hyperparameter q.
[0107] Based on the shortest number of jumps between the current node's previous node and the neighboring node, a corresponding transfer score setting value is selected as the first transfer score for the current node to transfer to the neighboring node.
[0108] Optionally, the process by which the node transfer unit determines the second transfer score for the current node to transfer to the neighboring node based on the semantic relationship between the current node and the neighboring nodes may include:
[0109] For any target neighbor node of the current node:
[0110] Determine the target relationship name between the current node and the target neighbor node;
[0111] Count the total number of neighboring nodes of the current node that have the target relation name with the current node;
[0112] Based on the total number, the number of all neighboring nodes of the current node, and the third hyperparameter λ, a second transfer score is determined for the current node to move to the target neighboring node, wherein the larger the total number, the smaller the second transfer score.
[0113] Optionally, the process by which the node transfer unit determines the total transfer score for the current node to transfer to the neighboring node based on the first transfer score and / or the second transfer score may include:
[0114] The product of the first transfer score and the second transfer score is taken as the total transfer score for the current node to transfer to the neighboring node.
[0115] Optionally, the process by which the starting node selection unit selects at least one node in the target knowledge graph as the starting node may include:
[0116] A specified number of nodes are randomly selected from the target knowledge graph as starting nodes, and the specified number is not less than 1.
[0117] Optionally, the M-tuple is a triple; or, the M-tuple is a quintuple, which includes: a head entity and its concept, a tail entity and its concept, and a relation name between the head and tail entities.
[0118] Optionally, the apparatus of this application may further include: a training statement generation unit, configured to generate a corresponding training statement for each final sampling path after obtaining each final sampling path, based on the M-tuple sequence contained therein, wherein the training statement is used as training data for an entity recognition model.
[0119] The knowledge graph-based knowledge sampling device provided in this application can be applied to knowledge sampling devices, such as terminals: mobile phones, computers, etc. Optionally, Figure 3 The hardware structure block diagram of the knowledge sampling device is shown below. Figure 3 The hardware structure of a knowledge sampling device may include: at least one processor 1, at least one communication interface 2, at least one memory 3, and at least one communication bus 4;
[0120] In this embodiment of the application, the number of processor 1, communication interface 2, memory 3, and communication bus 4 is at least one, and processor 1, communication interface 2, and memory 3 communicate with each other through communication bus 4;
[0121] Processor 1 may be a central processing unit (CPU), an application-specific integrated circuit (ASIC), or one or more integrated circuits configured to implement embodiments of the present invention.
[0122] Memory 3 may include high-speed RAM, and may also include non-volatile memory, such as at least one disk storage device;
[0123] The memory stores a program, which the processor can call. The program is used for:
[0124] Obtain the target knowledge graph;
[0125] Select at least one node from the target knowledge graph as the starting node;
[0126] For each starting node, the nodes in the target knowledge graph are transferred along the directed edges with different probabilities. Each time a node is transferred, an M-tuple is generated based on the two nodes before and after the transfer and the directed edges. The M-tuple includes at least the head entity, the tail entity, and the relation name between the head and tail entities. During each transfer, the probability of the current node being transferred to any neighboring node is determined based on the distance between the nodes previously visited by the current node and the neighboring nodes, and / or the semantic relationship between the current node and the neighboring nodes.
[0127] The generated M-tuples are added to the sampling path corresponding to the starting node until the length of the sampling path reaches the set length, thus obtaining the final sampling path corresponding to each starting node.
[0128] Optionally, the refined and extended functions of the program can be found in the description above.
[0129] This application embodiment also provides a storage medium that can store a program suitable for execution by a processor, the program being used for:
[0130] Obtain the target knowledge graph;
[0131] Select at least one node from the target knowledge graph as the starting node;
[0132] For each starting node, the nodes in the target knowledge graph are transferred along the directed edges with different probabilities. Each time a node is transferred, an M-tuple is generated based on the two nodes before and after the transfer and the directed edges. The M-tuple includes at least the head entity, the tail entity, and the relation name between the head and tail entities. During each transfer, the probability of the current node being transferred to any neighboring node is determined based on the distance between the nodes previously visited by the current node and the neighboring nodes, and / or the semantic relationship between the current node and the neighboring nodes.
[0133] The generated M-tuples are added to the sampling path corresponding to the starting node until the length of the sampling path reaches the set length, thus obtaining the final sampling path corresponding to each starting node.
[0134] Optionally, the refined and extended functions of the program can be found in the description above.
[0135] Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0136] The various embodiments in this specification are described in a progressive manner. Each embodiment focuses on the differences from other embodiments. The various embodiments can be combined as needed, and the same or similar parts can be referred to each other.
[0137] The above description of the disclosed embodiments enables those skilled in the art to make or use this application. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of this application. Therefore, this application is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A knowledge sampling method based on knowledge graphs, characterized in that, include: Obtain the target knowledge graph; Select at least one node from the target knowledge graph as the starting node; For each starting node, a transition occurs along directed edges between nodes in the target knowledge graph with varying probabilities. Each time a node undergoes a transition, an M-tuple is generated based on the two nodes before and after the transition, as well as the directed edges. The M-tuple is a triple or quintuple that includes at least a head entity, a tail entity, and the relation name between the head and tail entities. During each transition, the probability of the current node transitioning to any neighboring node is determined based on the distance between the nodes previously visited by the current node and the neighboring nodes, and the semantic relationship between the current node and the neighboring nodes. The process of determining the probability of the current node transitioning to any neighboring node based on the distance between the nodes previously visited by the current node and the neighboring nodes, and the semantic relationship between the current node and the neighboring nodes, includes: determining the probability based on the distance between the previous node and the current node's neighboring nodes. The distance between neighboring nodes is used to determine a first transfer score for the current node to move to a neighboring node. For any target neighboring node of the current node: the target relationship name between the current node and the target neighboring node is determined; the total number of neighboring nodes with the target relationship name is counted among all the current node's neighboring nodes; based on the total number, the total number of all the current node's neighboring nodes, and a third hyperparameter, a second transfer score for the current node to move to a target neighboring node is determined, wherein the larger the total number, the smaller the second transfer score; the product of the first transfer score and the second transfer score is used as the total transfer score for the current node to move to the neighboring node; based on the total transfer score, the probability of moving from the current node to any neighboring node is determined. Add the generated M-tuples to the sampling path corresponding to the starting node until the length of the sampling path reaches the set length, and obtain the final sampling path corresponding to each starting node. For each final sampling path, a corresponding training statement is generated based on the M-tuple sequence contained therein. The training statement is used as training data for the entity recognition model.
2. The method according to claim 1, characterized in that, The process of determining the probability of transitioning from the current node to any neighboring node based on the total transition score includes: For any target neighbor node: The probability of the current node moving to the target neighbor node is determined based on the transfer score of the current node moving to the target neighbor node and the sum of the total transfer scores of the current node moving to each neighbor node.
3. The method according to claim 1, characterized in that, The step of determining the first transfer score for the current node to transfer to the neighboring node based on the distance between the current node's previous node and the neighboring node includes: Determine the shortest number of jumps between the previous node of the current node and the neighboring nodes. The shortest number of jumps is in the range of {0,1,2}. Different shortest number of jumps correspond to different transfer score settings. The transfer score setting corresponding to the shortest number of jumps 0 is controlled by the first hyperparameter, and the transfer score setting corresponding to the shortest number of jumps 2 is controlled by the second hyperparameter. Based on the shortest number of jumps between the current node's previous node and the neighboring node, a corresponding transfer score setting value is selected as the first transfer score for the current node to transfer to the neighboring node.
4. The method according to any one of claims 1-3, characterized in that, At least one node is selected from the target knowledge graph as the starting node, including: A specified number of nodes are randomly selected from the target knowledge graph as starting nodes, and the specified number is not less than 1.
5. The method according to any one of claims 1-3, characterized in that, The quintuple includes: the head entity and its concept, the tail entity and its concept, and the relation name between the head and tail entities.
6. A knowledge sampling device based on a knowledge graph, characterized in that, include: The knowledge graph acquisition unit acquires the target knowledge graph. The starting node selection unit is used to select at least one node in the target knowledge graph as a starting node; A node transfer unit is used to transfer each starting node along directed edges in the target knowledge graph with different probabilities. Each time a node undergoes a transfer, an M-tuple is generated based on the two nodes before and after the transfer, and the directed edges. The M-tuple is a triple or quintuple that includes at least a head entity, a tail entity, and the relation name between the head and tail entities. During each transfer, the probability of the current node transferring to any neighboring node is determined based on the distance between the nodes previously traversed by the current node and the neighboring nodes, and the semantic relationship between the current node and the neighboring nodes. The process of determining the probability of the current node transferring to any neighboring node based on the distance between the nodes previously traversed by the current node and the neighboring nodes, and the semantic relationship between the current node and the neighboring nodes, includes: based on the current node's previous... The distance between a node and its neighboring nodes is used to determine a first transfer score for the current node to move to a neighboring node. For any target neighboring node of the current node: the target relationship name between the current node and the target neighboring node is determined; the total number of neighboring nodes that have the target relationship name with the current node is counted; based on the total number, the total number of all neighboring nodes of the current node, and a third hyperparameter, a second transfer score for the current node to move to a target neighboring node is determined, wherein the larger the total number, the smaller the second transfer score; the product of the first transfer score and the second transfer score is used as the total transfer score for the current node to move to a neighboring node; based on the total transfer score, the probability of moving from the current node to any neighboring node is determined. The sampling path determination unit is used to add the generated M-tuple to the sampling path corresponding to the starting node until the length of the sampling path reaches the set length, so as to obtain the final sampling path corresponding to each starting node. The training statement generation unit is used to generate a corresponding training statement for each final sampling path based on the M-tuple sequence contained therein. The training statement is used as training data for the entity recognition model.
7. A knowledge sampling device, characterized in that, include: Memory and processor; The memory is used to store programs; The processor is used to execute the program to implement each step of the knowledge sampling method based on knowledge graphs as described in any one of claims 1 to 5.
8. A storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements each step of the knowledge sampling method based on knowledge graphs as described in any one of claims 1 to 5.
Citation Information
Patent Citations
Training method and device of reasoning model, and reasoning method and device
CN113590782A