Knowledge graph relationship prediction method and device, electronic equipment and storage medium
By introducing a time-series knowledge graph with a time dimension into the knowledge graph, the problem of inaccurate relation prediction in static knowledge graphs is solved, and higher prediction accuracy is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- BEIJING BAIDU NETCOM SCI & TECH CO LTD
- Filing Date
- 2023-03-08
- Publication Date
- 2026-05-26
AI Technical Summary
Existing static knowledge graphs ignore changes in the effectiveness of knowledge over time, leading to inaccurate relationship predictions.
By employing a temporal knowledge graph, a temporal knowledge graph is obtained by adding a time dimension to the edges. The clue paths are traversed in the temporal directed graph, and the attention weights of the clue edges are determined according to the target time and relationship. The representation of the candidate entity is encoded, and the probability that the candidate entity and the target head entity meet the target relationship at the target time is predicted.
It improves the accuracy of relationship prediction by considering the temporal dimension of the knowledge graph, thus enhancing the precision of the prediction.
Smart Images

Figure CN116579421B_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of artificial intelligence technology, specifically to knowledge graphs, natural language processing, and other fields, and can be applied to intelligent question answering scenarios. In particular, it relates to relation prediction methods, devices, electronic devices, and storage media for knowledge graphs. Background Technology
[0002] One of the main uses of knowledge graphs is to assist in reasoning new facts, new relationships, new axioms, and new rules based on existing knowledge graphs.
[0003] In related technologies, relationship prediction based on knowledge graphs mostly targets static knowledge graphs. However, in practical applications, much of the structured knowledge in a knowledge graph is only valid within a specific timeframe. Static knowledge graphs in these technologies ignore the changes in validity over time, thus leading to inaccuracies in relationship prediction. Summary of the Invention
[0004] This disclosure provides a method, apparatus, electronic device, and storage medium for predicting relationships in a knowledge graph.
[0005] According to one aspect of this disclosure, a method for predicting relationships in a knowledge graph is provided, the method comprising:
[0006] Obtain a temporal knowledge graph and prediction condition information, wherein the prediction condition information includes: target time, target head entity, and target relationship;
[0007] Traverse the clue paths starting from the target head entity in the temporal knowledge graph to obtain a temporal directed graph that is a subgraph of the temporal knowledge graph. The temporal directed graph includes candidate entities other than the target head entity, and clue edges connecting the candidate entities.
[0008] Based on the target time and target relationship in the prediction condition information, determine the attention weight of the cue edge in the temporal directed graph;
[0009] Based on the time difference between the time indicated by the clue edge and the target time, and the attention weight of the clue edge, the representation of the candidate entity in the temporal directed graph is encoded.
[0010] Based on the characterization of the candidate entity, determine the probability that the candidate entity and the target head entity conform to the target relationship at the target time.
[0011] According to another aspect of this disclosure, a knowledge graph relation prediction apparatus is provided, comprising:
[0012] The acquisition module is used to acquire a time-series knowledge graph and prediction condition information, wherein the prediction condition information includes: target time, target head entity, and target relationship;
[0013] A generation module is used to traverse the clue paths starting from the target head entity in the temporal knowledge graph to obtain a temporal directed graph that is a subgraph of the temporal knowledge graph, wherein the temporal directed graph includes candidate entities other than the target head entity, and clue edges connecting the candidate entities.
[0014] The determination module is used to determine the attention weights of the cue edges in the temporal directed graph based on the target time and the target relationship in the prediction condition information;
[0015] The encoding module is used to encode the representation of the candidate entity in the temporal directed graph based on the time difference between the time indicated by the clue edge and the target time, and the attention weight of the clue edge.
[0016] The prediction module is used to determine, based on the characterization of the candidate entity, the probability that the candidate entity and the target head entity conform to the target relationship at the target time.
[0017] According to another aspect of this disclosure, an electronic device is provided, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, the instructions being executed by the at least one processor to enable the at least one processor to perform the method described in the first aspect of this disclosure.
[0018] According to another aspect of this disclosure, a non-transitory computer-readable storage medium is provided storing computer instructions for causing a computer to perform the method described in the first aspect of this disclosure.
[0019] According to another aspect of this disclosure, a computer program product is provided, including a computer program that, when executed by a processor, implements the method described in the first aspect of this disclosure.
[0020] The knowledge graph relation prediction method, apparatus, electronic device, and storage medium disclosed herein acquire a temporal knowledge graph, along with target time, target head entity, and target relation from prediction condition information. Then, it traverses the clue paths starting from the target head entity within the temporal knowledge graph to obtain a temporal directed graph, which serves as a subgraph of the temporal knowledge graph. Since the temporal directed graph includes candidate entities other than the target head entity, and clue edges connecting these candidate entities, the attention weights of the clue edges in the temporal directed graph can be determined based on the target time and target relation in the prediction condition information. Furthermore, based on the time difference between the time indicated by the clue edge and the target time, and the attention weights of the clue edges, the representations of the candidate entities in the temporal directed graph are encoded. Based on the representations of the candidate entities, the probability that a candidate entity and the target head entity conform to the target relation at the target time is obtained. Because a temporal knowledge graph is used for relation prediction, the accuracy of relation prediction is improved compared to the static knowledge graphs used in related technologies.
[0021] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of this disclosure, nor is it intended to limit the scope of this disclosure. Other features of this disclosure will become readily apparent from the following description. Attached Figure Description
[0022] The accompanying drawings are provided to better understand this solution and do not constitute a limitation of this disclosure. Wherein:
[0023] Figure 1 This is a flowchart illustrating a relationship prediction method for a knowledge graph provided in an embodiment of this disclosure;
[0024] Figure 2 This is a flowchart illustrating another knowledge graph relationship prediction method provided in this embodiment of the disclosure;
[0025] Figure 3 This is a schematic diagram of the original time-series knowledge graph;
[0026] Figure 4 A schematic diagram of an extended time-series knowledge graph;
[0027] Figure 5 This is a flowchart illustrating another knowledge graph relationship prediction method provided in this embodiment of the disclosure;
[0028] Figure 6 This is a schematic diagram of the structure of a knowledge graph relationship prediction device 600 provided in an embodiment of this disclosure;
[0029] Figure 7 A schematic block diagram of an example electronic device 700 that can be used to implement embodiments of the present disclosure is shown. Detailed Implementation
[0030] The exemplary embodiments of this disclosure are described below with reference to the accompanying drawings, including various details of the embodiments to aid understanding, and should be considered merely exemplary. Therefore, those skilled in the art will recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of this disclosure. Similarly, for clarity and brevity, descriptions of well-known functions and structures are omitted in the following description.
[0031] A knowledge graph consists of multiple nodes and edges connecting them. Nodes indicate entities, and edges indicate the relationships between the entities indicated by the connected nodes. Thus, knowledge triples (head entity, relation, tail entity) can be formed through the connections between nodes and edges. A knowledge triple is also called a knowledge point: the head entity and the tail entity have a certain relationship.
[0032] Knowledge graph reasoning mainly involves using existing knowledge graphs to assist in reasoning out new facts, new relationships, new axioms, and new rules.
[0033] In related technologies, relationship prediction for knowledge graphs is mostly based on static knowledge graphs. However, in practical applications, much of the structured knowledge in a knowledge graph is only valid within a specific timeframe. Static knowledge graphs in related technologies ignore the changes in validity over time, thus leading to inaccuracies in relationship prediction.
[0034] To address this issue, this embodiment of the disclosure performs reasoning on a time-series knowledge graph, taking the time dimension into account during the reasoning process, thereby resolving the problem of inaccurate relationship prediction in related technologies.
[0035] Temporal knowledge graphs, compared to static knowledge graphs, add a time dimension to the edges. In a temporal knowledge graph, nodes correspond to entities, and edges correspond to relations and time. Two nodes connected by an edge form a quadruple of information for a knowledge point (head entity, relation, tail entity, time), meaning that within the time corresponding to the edge, the head entity and the tail entity have the relation indicated by the edge.
[0036] To illustrate the relation prediction process of time-series knowledge graphs, a relation prediction method, apparatus, electronic device, and storage medium for knowledge graphs are provided.
[0037] Figure 1 This is a flowchart illustrating a knowledge graph relationship prediction method provided in an embodiment of this disclosure, such as... Figure 1 As shown, the relationship prediction methods for knowledge graphs include:
[0038] Step 101: Obtain the temporal knowledge graph and prediction condition information, including: target time, target head entity, and target relationship.
[0039] A temporal knowledge graph consists of multiple nodes and multiple edges. Each edge connects at least two nodes. Nodes in a temporal knowledge graph indicate entities. Edges in a temporal knowledge graph indicate relationships and time. As mentioned earlier, two nodes in a temporal knowledge graph connected by an edge form a four-tuple of information for a knowledge point (head entity, relationship, tail entity, time), meaning that the head entity and tail entity have the relationship indicated by the edge within the time corresponding to the edge.
[0040] Predictive condition information refers to the query conditions required for a single inference operation on a time-series knowledge graph. For example, predictive condition information can be generated based on question-and-answer content from the knowledge graph. The question could be: What was the nationality of person A in 1980? This question includes keywords such as person A, nationality, and 1980. In a four-tuple of information, person A is the head entity, nationality is the relation, and 1980 is the time. Therefore, the entity to be inferred is the tail entity within this four-tuple.
[0041] Step 102: Traverse the clue paths starting from the target head entity in the temporal knowledge graph to obtain a temporal directed graph that is a subgraph of the temporal knowledge graph. The temporal directed graph includes candidate entities other than the target head entity, and clue edges connecting the candidate entities.
[0042] To combine the advantages of path-based and subgraph-based methods, this embodiment introduces a directed graph as a query dependency subgraph structure. Traversing the thread paths in the temporal knowledge graph is typically based on a set length L, resulting in a temporal thread path of length L having the following form:
[0043]
[0044] Where e indicates an entity, e superscript indicates the order of entities in the thread path, r indicates a relationship, t indicates time, r superscript indicates the order of relationships in the thread path, and similarly, t superscript indicates the order of time in the thread path.
[0045] For a given inference, the quadruple information (e) used as prediction condition information. q ,r q ,? ,t q ), traverse the time-series knowledge graph with the target head entity e qStarting with a clue path, a temporally directed graph is obtained as a subgraph of the temporally ordered knowledge graph, wherein the temporally directed graph includes candidate entities e other than the target head entity. c , and the thread edges connecting the candidate entities.
[0046] Step 103: Determine the attention weights of the cue edges in the temporal directed graph based on the target time and the target relationship in the prediction condition information.
[0047] The target time and target relationship in the prediction condition information will affect the attention weight values of the cue edges in the temporal directed graph. The attention weight indicates the magnitude of the role played by the corresponding edge in the inference process corresponding to the prediction condition information. Therefore, in this embodiment of the disclosure, the magnitude of the role played by the edge in the inference process corresponding to the prediction condition information is determined based on the target time and target relationship in the prediction condition information.
[0048] Step 104: Based on the time difference between the time indicated by the cue edge and the target time, and the attention weight of the cue edge, the representation of the candidate entity in the temporal directed graph is encoded.
[0049] As one possible implementation, a graph neural network (GNN) model is used, based on the time t indicated by the cue edges and the target time t. q The time difference between them is Δt = tt q The candidate entities are encoded using the weights of the thread edges to obtain the representations of the candidate entities in the temporally directed graph.
[0050] Since the time indicated in the clue edge or prediction condition information is a specific year, month, date, or moment, that is, the clue edge or prediction condition information is absolute time, and since the GNN used for encoding cannot cover all absolute times during the training process, the embodiments of this disclosure use relative time as the encoding basis, which can cover more situations with fewer samples.
[0051] Step 105: Based on the representation of the candidate entity, determine the probability that the candidate entity and the target head entity conform to the target relationship at the target time.
[0052] In this embodiment, by acquiring a temporal knowledge graph and the target time, target head entity, and target relationship from the prediction condition information, the thread paths starting from the target head entity are traversed in the temporal knowledge graph to obtain a temporal directed graph as a subgraph of the temporal knowledge graph. Since the temporal directed graph includes candidate entities other than the target head entity and thread edges connecting the candidate entities, the attention weights of the thread edges in the temporal directed graph can be determined based on the target time and target relationship in the prediction condition information. Based on the time difference between the time indicated by the thread edge and the target time, and the attention weights of the thread edges, the representations of the candidate entities in the temporal directed graph are encoded. Based on the representations of the candidate entities, the probability that the candidate entity and the target head entity conform to the target relationship at the target time is obtained. Because a temporal knowledge graph is used for relationship prediction, the accuracy of relationship prediction is improved compared to the static knowledge graphs used in related technologies.
[0053] Figure 2 This is a flowchart illustrating another knowledge graph relationship prediction method provided in this disclosure embodiment, such as... Figure 2 As shown, the relationship prediction methods for knowledge graphs include:
[0054] Step 201: Obtain the temporal knowledge graph and prediction condition information, wherein the prediction condition information includes: target time, target head entity and target relationship.
[0055] Prediction condition information can be denoted as (e q ,t q ,? ,t q This includes: target header entity e q Target time t q Relationship with target r q We need to obtain the target tail entity.
[0056] For the form and acquisition process of time-series knowledge graphs and prediction condition information, please refer to the relevant descriptions in the foregoing embodiments, which will not be repeated in this embodiment.
[0057] To enrich the relationships in a temporal knowledge graph, it is necessary to refer to the extension methods in related technologies and extend the temporal knowledge graph with reverse relationships and ontology relationships. Figure 3 This is a schematic diagram of the original time-series knowledge graph. Figure 3 In the diagram, nodes are represented by circles, and edges are represented by straight line segments with direction. In... Figure 3 Adding reverse relations and ontology relations to the temporal knowledge graph shown yields... Figure 4 , Figure 4 A schematic diagram of an extended time-series knowledge graph. Figure 4In the diagram, edges indicating reverse relationships are represented by dashed lines with arrows, and the direction of the edge corresponding to the reverse relationship is... Figure 3 There are already edges pointing in the opposite direction, meaning that for... Figure 3 For each existing edge, create an edge pointing in the opposite direction. Figure 4 It also includes edges pointing to each node itself, and these edges correspond to ontology relationships. For example: for Figure 3 Quadruple information set of time-series knowledge graph any four-tuple information Add quadruple information with reverse relation r_rev (e c ,r_rev,e s ,t); for Figure 3 For each entity e∈v in the temporal knowledge graph, we add a quadruple (e,Identity,e,t) with the ontology relation Identity. q -1), where yes Figure 3 The set of entities in the temporal knowledge graph shown.
[0058] For a single inference, the prediction condition information is (e q ,r q ,? ,t q At time t q The extended time-series knowledge graph is denoted as
[0059] Here, v indicates the set of entities in the extended temporal knowledge graph. The set of relations in the extended temporal knowledge graph includes existing relations in the original knowledge graph, as well as the extended reverse relations and ontology relations. Indicates the set of quadruple information in the extended temporal knowledge graph. Indicates the time set in the expanded temporal knowledge graph.
[0060] Step 202: Traverse the clue paths starting from the target head entity in the temporal knowledge graph to obtain a temporal directed graph that is a subgraph of the temporal knowledge graph. The temporal directed graph includes candidate entities other than the target head entity and clue edges connecting the candidate entities.
[0061] Optionally, for the temporal knowledge graph obtained in the aforementioned steps, the target head entity e is traversed within the temporal knowledge graph. q Starting from the clue path, the entities in the clue path are selected as candidate entities e. The temporal knowledge graph subgraph formed by the clue paths is treated as a temporal directed graph.
[0062] As one possible implementation, each thread path includes L entities, and each thread path has the same start and end point. Nodes are arranged in an array, where each column corresponds to a path, nodes in the same column correspond to entities on that path, and are connected to each other in the order they appear on the path. Nodes in the same row of the array correspond to entities at the same depth in different paths. Nodes in the same row belonging to the same entity are merged to obtain a temporal directed graph.
[0063] Step 203: Determine the attention weights of the cue edges in the temporal directed graph based on the target time and target relationship in the prediction condition information.
[0064] Optionally, given a prediction condition information (e) q ,r q ,? ,t q In the case of any candidate entity e determined in the aforementioned steps, querying the quadruple information of the candidate entity in the temporally directed graph yields the fact quadruple (e) at time t. s (r,e,t), candidate entity e and target head entity e q The number of layers between them is l.
[0065] Based on this, and building upon the prediction condition information, the attention weights of the edges of the candidate entity are... It can be defined as:
[0066]
[0067] Where σ is the sigmoid function, and The parameters that the graph neural network model can learn can be referred to as the second bias parameter matrix. and the third bias parameter matrix ReLU is the activation function for the rectified linear unit. Similar to the RED-GNN transitive algorithm, it involves the target relation r. q The representation Representation of the neighboring entities of the candidate entity And the representation of the relationship r indicated by the thread edge. The representation obtained by performing a connection. It can be... Represented as:
[0068]
[0069] And The value space of is denoted as
[0070] Step 204: Determine the time displacement representation of the clue edge based on the time difference between the time indicated by the clue edge and the target time.
[0071] τ |Δt| A learnable representation of time displacement Δt, and τ |Δt| The value space of is denoted as
[0072] Step 205: Based on the attention weights of the clue edges, perform message passing on the temporal displacement representation of the clue edge, the representation of the neighboring entities of the candidate entity, and the relational representation of the clue edge to obtain the message propagation function.
[0073] Optionally, the time displacement τ is characterized |Δt| The representation of the neighboring entities and the relationship representation Perform fusion to obtain fusion characterization. Using the first bias parameter For the fusion characterization Apply the bias and the attention weights. For the fusion characterization Weighting is performed to obtain the message propagation function. First, through fusion, the representation embodies characteristics across multiple dimensions, including time, relationships, and entities. Second, this weighted fusion method demonstrates the importance of fused representations in reasoning under different inference conditions. The resulting message propagation function carries multi-dimensional characteristics and their significance for reasoning, thus enriching the connotation of the message propagation function.
[0074] For example, one possible implementation is a message propagation function. Represented as:
[0075]
[0076] Optionally, the first bias parameter is determined based on the range of values to which the time difference Δt belongs. Different first bias parameters are determined for different time situations, so that the value of the first bias parameter is more suitable for the corresponding inference requirements.
[0077] The value range indicates that the target time, relative to the time indicated by the clue edge, is at least one of past time (), current time (), and future time (). By classifying and discussing different time scenarios, the model is refined, enhancing its ability to handle diverse time situations.
[0078] For example:
[0079]
[0080] in All of these are learnable parameter values.
[0081] Step 206: Encode the candidate entities in the temporal directed graph according to the message propagation function to obtain the representation of the candidate entities.
[0082] Optionally, the message propagation function Substituting the message aggregation function δ, the candidate entities in the temporal directed graph are encoded to obtain the representation of the candidate entities. Through aggregation by the message aggregation function, the representation carries the structural features of the candidate entity's surroundings in multiple dimensions such as time, relationships, and entities.
[0083] For example, as one possible implementation, the representation of a candidate entity can be written as:
[0084]
[0085] Step 207: Based on the characterization of the candidate entity, determine the probability that the candidate entity and the target head entity conform to the target relationship at the target time.
[0086] In this embodiment, by acquiring a temporal knowledge graph and the target time, target head entity, and target relationship from the prediction condition information, the thread paths starting from the target head entity are traversed in the temporal knowledge graph to obtain a temporal directed graph as a subgraph of the temporal knowledge graph. Since the temporal directed graph includes candidate entities other than the target head entity and thread edges connecting the candidate entities, the attention weights of the thread edges in the temporal directed graph can be determined based on the target time and target relationship in the prediction condition information. Based on the time difference between the time indicated by the thread edge and the target time, and the attention weights of the thread edges, the representations of the candidate entities in the temporal directed graph are encoded. Based on the representations of the candidate entities, the probability that the candidate entity and the target head entity conform to the target relationship at the target time is obtained. Because a temporal knowledge graph is used for relationship prediction, the accuracy of relationship prediction is improved compared to the static knowledge graphs used in related technologies.
[0087] Figure 5 This is a flowchart illustrating another knowledge graph relationship prediction method provided in this disclosure embodiment, such as... Figure 5 As shown, the relationship prediction methods for knowledge graphs include:
[0088] Step 501: Obtain the temporal knowledge graph and prediction condition information, including: target time, target head entity, and target relationship.
[0089] Step 502: Traverse the clue paths starting from the target head entity in the temporal knowledge graph to obtain a temporal directed graph that is a subgraph of the temporal knowledge graph. The temporal directed graph includes candidate entities other than the target head entity and clue edges connecting the candidate entities.
[0090] Step 503: Determine the attention weights of the cue edges in the temporal directed graph based on the target time and the target relationship in the prediction condition information.
[0091] Step 504: Based on the time difference between the time indicated by the clue edge and the target time, and the attention weight of the clue edge, the representation of the candidate entity in the temporal directed graph is encoded.
[0092] Steps 501-504 can be referred to the relevant descriptions in the foregoing embodiments, and will not be repeated in this embodiment.
[0093] Step 505: The representation of the candidate entity is scored using a scoring function, and the probability that the candidate entity and the target head entity conform to the target relationship at the target time is determined based on the output of the scoring function.
[0094] Optionally, given a prediction condition information (e) q ,r q ,? ,t q ), and given the number of layers L, candidate entity e c The representation is denoted as Scoring function s(e q ,r q ,e c )and The following relationships can exist between them:
[0095]
[0096] in, These are learnable model parameters obtained through training.
[0097] To illustrate the training process of the scoring function, this embodiment can use artificially generated negative samples. For example, based on the existing time-series knowledge graph, the quadruple information in it can be used as positive samples, and one of the entities in the positive samples that is the answer can be randomly replaced with a negative sample entity that is different from the answer entity, thereby obtaining negative samples.
[0098] The scoring function is trained using a prepared set of positive and negative samples. During training, the difference between the predicted positive probability of the input sample and the actual probability of the sample being positive or negative is used as the loss function, calculated by substituting the cross-entropy value. The model parameters in the scoring function are then trained based on the loss function value, such as adjusting... The value is chosen to minimize the value of the loss function.
[0099] Step 506: When there are multiple candidate entities, based on the probability of each candidate entity, determine the target tail entity from the multiple candidate entities that conforms to the target relationship with the target head entity at the target time.
[0100] In the case of multiple candidate entities, the candidate entity with the highest probability can be selected from the multiple candidate entities as the target tail entity that conforms to the target relationship with the target head entity at the target time. This selection process further improves the accuracy of the obtained target tail entity.
[0101] In this embodiment, by acquiring a temporal knowledge graph and the target time, target head entity, and target relationship from the prediction condition information, the thread paths starting from the target head entity are traversed in the temporal knowledge graph to obtain a temporal directed graph as a subgraph of the temporal knowledge graph. Since the temporal directed graph includes candidate entities other than the target head entity and thread edges connecting the candidate entities, the attention weights of the thread edges in the temporal directed graph can be determined based on the target time and target relationship in the prediction condition information. Based on the time difference between the time indicated by the thread edge and the target time, and the attention weights of the thread edges, the representations of the candidate entities in the temporal directed graph are encoded. Based on the representations of the candidate entities, the probability that the candidate entity and the target head entity conform to the target relationship at the target time is obtained. Because a temporal knowledge graph is used for relationship prediction, the accuracy of relationship prediction is improved compared to the static knowledge graphs used in related technologies.
[0102] Figure 6 This is a schematic diagram of the structure of a knowledge graph relationship prediction device 600 provided in an embodiment of this disclosure, as shown below. Figure 6 As shown, it includes: an acquisition module 61, a generation module 62, a determination module 63, an encoding module 64, and a prediction module 65.
[0103] The acquisition module 61 is used to acquire a time-series knowledge graph and prediction condition information, wherein the prediction condition information includes: target time, target head entity, and target relationship;
[0104] The generation module 62 is used to traverse the clue paths starting from the target head entity in the temporal knowledge graph to obtain a temporal directed graph that is a subgraph of the temporal knowledge graph, wherein the temporal directed graph includes candidate entities other than the target head entity, and clue edges connecting the candidate entities.
[0105] The determination module 63 is used to determine the attention weight of the cue edge in the temporal directed graph based on the target time and the target relationship in the prediction condition information;
[0106] Encoding module 64 is used to encode the representation of the candidate entity in the temporal directed graph based on the time difference between the time indicated by the clue edge and the target time, and the attention weight of the clue edge.
[0107] The prediction module 65 is used to determine, based on the characterization of the candidate entity, the probability that the candidate entity and the target head entity conform to the target relationship at the target time.
[0108] Optionally, the encoding module 64 includes:
[0109] The first determining unit is used to determine the time displacement representation of the clue edge based on the time difference between the time indicated by the clue edge and the target time.
[0110] The message propagation unit is used to perform message propagation on the temporal displacement representation of the thread edge, the representation of the neighboring entities of the candidate entity, and the relational representation of the thread edge according to the attention weight of the thread edge, so as to obtain the message propagation function.
[0111] An aggregation unit is used to encode the candidate entities in the temporally directed graph according to the message propagation function to obtain the representation of the candidate entities.
[0112] Optionally, the aggregation unit is configured to: substitute the message propagation function into the message aggregation function to encode the candidate entities in the temporally directed graph to obtain the representation of the candidate entities.
[0113] Optionally, the transmission unit is configured to: fuse the time displacement representation, the neighbor entity representation, and the relationship representation to obtain a fused representation; bias the fused representation with a first bias parameter; and weight the fused representation with the attention weight to obtain the message propagation function.
[0114] Optionally, the transmission unit is further configured to: determine the first bias parameter based on the range of values to which the time difference belongs.
[0115] Optionally, the value range is used to indicate that the target time relative to the time indicated by the clue edge is at least one of past time, current time, and future time.
[0116] Optionally, the prediction module 65 is also used for:
[0117] When there are multiple candidate entities, a target tail entity that conforms to the target relationship with the target head entity at the target time is determined from the multiple candidate entities based on the probability of each candidate entity.
[0118] In this embodiment, by acquiring a temporal knowledge graph and the target time, target head entity, and target relationship from the prediction condition information, the thread paths starting from the target head entity are traversed in the temporal knowledge graph to obtain a temporal directed graph as a subgraph of the temporal knowledge graph. Since the temporal directed graph includes candidate entities other than the target head entity and thread edges connecting the candidate entities, the attention weights of the thread edges in the temporal directed graph can be determined based on the target time and target relationship in the prediction condition information. Based on the time difference between the time indicated by the thread edge and the target time, and the attention weights of the thread edges, the representations of the candidate entities in the temporal directed graph are encoded. Based on the representations of the candidate entities, the probability that the candidate entity and the target head entity conform to the target relationship at the target time is obtained. Because a temporal knowledge graph is used for relationship prediction, the accuracy of relationship prediction is improved compared to the static knowledge graphs used in related technologies.
[0119] According to embodiments of this disclosure, this disclosure also provides an electronic device, a readable storage medium, and a computer program product.
[0120] Figure 7 A schematic block diagram of an example electronic device 800 that can be used to implement embodiments of the present disclosure is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device may also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the present disclosure described and / or claimed herein.
[0121] like Figure 7As shown, device 700 includes a computing unit 701, which can perform various appropriate actions and processes based on a computer program stored in ROM (Read-Only Memory) 702 or a computer program loaded from storage unit 708 into RAM (Random Access Memory) 703. RAM 703 can also store various programs and data required for the operation of device 700. The computing unit 701, ROM 702, and RAM 703 are interconnected via bus 704. I / O (Input / Output) interface 705 is also connected to bus 704.
[0122] Multiple components in device 700 are connected to I / O interface 705, including: input unit 706, such as keyboard, mouse, etc.; output unit 707, such as various types of monitors, speakers, etc.; storage unit 708, such as disk, optical disk, etc.; and communication unit 709, such as network card, modem, wireless transceiver, etc. Communication unit 709 allows device 700 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.
[0123] The computing unit 701 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of the computing unit 701 include, but are not limited to, CPUs (Central Processing Units), GPUs (Graphics Processing Units), various special-purpose AI (Artificial Intelligence) computing chips, various computing units running machine learning model algorithms, DSPs (Digital Signal Processors), and any suitable processor, controller, microcontroller, etc. The computing unit 701 performs the various methods and processes described above, such as relation prediction methods. For example, in some embodiments, the relation prediction method may be implemented as a computer software program tangibly contained in a machine-readable medium, such as storage unit 708. In some embodiments, part or all of the computer program may be loaded and / or installed on device 700 via ROM 702 and / or communication unit 709. When the computer program is loaded into RAM 703 and executed by the computing unit 701, one or more steps of the relation prediction method described above may be performed. Alternatively, in other embodiments, the computing unit 701 may be configured to perform a relation prediction method by any other suitable means (e.g., by means of firmware).
[0124] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, FPGAs (Field Programmable Gate Arrays), ASICs (Application-Specific Integrated Circuits), ASSPs (Application-Specific Standard Products), SOCs (System-on-Chips), CPLDs (Complex Programmable Logic Devices), computer hardware, firmware, software, and / or combinations thereof. These various implementations may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.
[0125] The program code used to implement the methods of this disclosure may be written in any combination of one or more programming languages. This program code may be provided to a processor or controller of a general-purpose computer, special-purpose computer, or other programmable data processing apparatus, such that when executed by the processor or controller, the program code causes the functions / operations specified in the flowcharts and / or block diagrams to be implemented. The program code may be executed entirely on a machine, partially on a machine, as a standalone software package partially on a machine and partially on a remote machine, or entirely on a remote machine or server.
[0126] In the context of this disclosure, a machine-readable medium can be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, apparatus, or device. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can be, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, RAM, ROM, EPROM (Electrically Programmable Read-Only Memory) or flash memory, optical fiber, CD-ROM (Compact Disc Read-Only Memory), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
[0127] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device for displaying information to the user (e.g., a CRT (Cathode-Ray Tube) or LCD (Liquid Crystal Display) monitor); and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the computer. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).
[0128] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as data servers), or middleware components (e.g., application servers), or frontend components (e.g., user computers with graphical user interfaces or web browsers through which users can interact with implementations of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication (e.g., communication networks) of any form or medium. Examples of communication networks include LANs (Local Area Networks), WANs (Wide Area Networks), the Internet, and blockchain networks.
[0129] Computer systems can include clients and servers. Clients and servers are generally geographically separated and typically interact via communication networks. The client-server relationship is created by computer programs running on the respective computers and having a client-server relationship with each other. A server can be a cloud server, also known as a cloud computing server or cloud host, a hosting product within the cloud computing service ecosystem, addressing the shortcomings of traditional physical hosts and VPS (Virtual Private Server, or simply "VPS") services, such as high management difficulty and weak business scalability. Servers can also be servers for distributed systems or servers incorporating blockchain technology.
[0130] It's important to note that artificial intelligence (AI) is the study of enabling computers to simulate certain human thought processes and intelligent behaviors (such as learning, reasoning, thinking, and planning). It encompasses both hardware and software technologies. AI hardware technologies generally include sensors, dedicated AI chips, cloud computing, distributed storage, and big data processing. AI software technologies primarily include computer vision, speech recognition, natural language processing, machine learning / deep learning, big data processing, and knowledge graph technologies.
[0131] It should be understood that the various forms of processes shown above can be used to rearrange, add, or delete steps. For example, the steps described in this disclosure can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution disclosed in this disclosure can be achieved, and this is not limited herein.
[0132] The specific embodiments described above do not constitute a limitation on the scope of protection of this disclosure. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this disclosure should be included within the scope of protection of this disclosure.
Claims
1. A relation prediction method for knowledge graphs, the method being applied to intelligent question answering scenarios, comprising: Acquire a temporal knowledge graph and prediction condition information, wherein the prediction condition information includes: target time, target head entity and target relationship, the prediction condition information is the query condition information required to perform a reasoning on the temporal knowledge graph, and the prediction condition information is generated based on keywords extracted from the question and answer content of the temporal knowledge graph; Traverse the clue paths starting from the target head entity in the temporal knowledge graph to obtain a temporal directed graph that is a subgraph of the temporal knowledge graph. The temporal directed graph includes candidate entities other than the target head entity, and clue edges connecting the candidate entities. Based on the target time and target relationship in the prediction condition information, the attention weight of the clue edge in the temporal directed graph is determined. Each clue path includes L entities, and each clue path has the same start and end point. Based on the time difference between the time indicated by the clue edge and the target time, and the attention weight of the clue edge, the representation of the candidate entity in the temporal directed graph is encoded. Based on the characterization of the candidate entity, determine the probability that the candidate entity and the target head entity conform to the target relationship at the target time; The step of traversing the clue paths starting from the target head entity in the temporal knowledge graph to obtain a temporal directed graph that serves as a subgraph of the temporal knowledge graph includes: The nodes are arranged in an array, wherein each column in the array corresponds to a clue path, and the nodes in the same column correspond to entities on the clue path and are connected to each other in the order of their positions on the clue path. The nodes in the same row of the array correspond to entities at the same depth in different thread paths. The nodes in the same row of the array that belong to the same entity are merged to obtain the temporal directed graph.
2. The method according to claim 1, wherein, The step of encoding the representation of the candidate entity in the temporally directed graph based on the time difference between the time indicated by the clue edge and the target time, and the attention weight of the clue edge, includes: The time displacement representation of the clue edge is determined based on the time difference between the time indicated by the clue edge and the target time; Based on the attention weights of the clue edges, message passing is performed on the temporal displacement representation of the clue edges, the representation of the neighboring entities of the candidate entity, and the relational representation of the clue edges to obtain the message propagation function. The candidate entities in the temporal directed graph are encoded according to the message propagation function to obtain the representation of the candidate entities.
3. The method according to claim 2, wherein, The step of encoding the candidate entities in the temporal directed graph according to the message propagation function to obtain the representation of the candidate entities includes: The message propagation function is substituted into the message aggregation function to encode the candidate entities in the temporal directed graph to obtain the representation of the candidate entities.
4. The method according to claim 2, wherein, The step of performing message propagation on the temporal displacement representation of the clue edge, the representation of the neighboring entities of the candidate entity, and the relation representation of the clue edge based on the attention weight of the clue edge to obtain a message propagation function includes: The time displacement representation, the neighbor entity representation, and the relationship representation are fused to obtain a fused representation; The fused representation is biased using a first bias parameter and weighted using the attention weight to obtain the message propagation function.
5. The method according to claim 4, wherein, The method further includes: The first bias parameter is determined based on the range of values to which the time difference belongs.
6. The method according to claim 5, wherein, The value range is used to indicate that the target time is at least one of the past time, the current time, and the future time relative to the time indicated by the clue edge.
7. The method according to any one of claims 1-6, wherein, The step of determining the probability that the candidate entity and the target head entity conform to the target relationship at the target time based on the representation of the candidate entity includes: The candidate entity's representation is scored using a scoring function, and the probability that the candidate entity and the target head entity conform to the target relationship at the target time is determined based on the output of the scoring function.
8. The method according to any one of claims 1-6, wherein, The method further includes: When there are multiple candidate entities, a target tail entity that conforms to the target relationship with the target head entity at the target time is determined from the multiple candidate entities based on the probability of each candidate entity.
9. A relation prediction device for a knowledge graph, the device being applied in an intelligent question-answering scenario, comprising: The acquisition module is used to acquire a temporal knowledge graph and prediction condition information, wherein the prediction condition information includes: target time, target head entity and target relationship. The prediction condition information is the query condition information required to perform a reasoning on the temporal knowledge graph. The prediction condition information is generated based on keywords extracted from the question and answer content of the temporal knowledge graph. A generation module is used to traverse the clue paths starting from the target head entity in the temporal knowledge graph to obtain a temporal directed graph that is a subgraph of the temporal knowledge graph. The temporal directed graph includes candidate entities other than the target head entity and clue edges connecting the candidate entities. Each clue path includes L entities, and each clue path has the same start and end point. The determination module is used to determine the attention weights of the cue edges in the temporal directed graph based on the target time and the target relationship in the prediction condition information; The encoding module is used to encode the representation of the candidate entity in the temporal directed graph based on the time difference between the time indicated by the clue edge and the target time, and the attention weight of the clue edge. The prediction module is used to determine, based on the representation of the candidate entity, the probability that the candidate entity and the target head entity conform to the target relationship at the target time; The generation module is further configured to: The nodes are arranged in an array, wherein each column in the array corresponds to a clue path, and the nodes in the same column correspond to entities on the clue path and are connected to each other in the order of their positions on the clue path. The nodes in the same row of the array correspond to entities at the same depth in different thread paths. The nodes in the same row of the array that belong to the same entity are merged to obtain the temporal directed graph.
10. The apparatus according to claim 9, wherein, The encoding module includes: The first determining unit is used to determine the time displacement representation of the clue edge based on the time difference between the time indicated by the clue edge and the target time. The message propagation unit is used to perform message propagation on the temporal displacement representation of the thread edge, the representation of the neighboring entities of the candidate entity, and the relational representation of the thread edge according to the attention weight of the thread edge, so as to obtain the message propagation function. An aggregation unit is used to encode the candidate entities in the temporally directed graph according to the message propagation function to obtain the representation of the candidate entities.
11. The apparatus according to claim 10, wherein, The aggregation unit is used for: The message propagation function is substituted into the message aggregation function to encode the candidate entities in the temporal directed graph to obtain the representation of the candidate entities.
12. The apparatus according to claim 10, wherein, The transmission unit is used for: The time displacement representation, the neighbor entity representation, and the relationship representation are fused to obtain a fused representation; The fused representation is biased using a first bias parameter and weighted using the attention weight to obtain the message propagation function.
13. The apparatus according to claim 12, wherein, The transmission unit is further configured to: The first bias parameter is determined based on the range of values to which the time difference belongs.
14. The apparatus according to claim 13, wherein, The value range is used to indicate that the target time is at least one of the past time, the current time, and the future time relative to the time indicated by the clue edge.
15. The apparatus according to any one of claims 9-14, wherein, The prediction module is used for: The candidate entity's representation is scored using a scoring function, and the probability that the candidate entity and the target head entity conform to the target relationship at the target time is determined based on the output of the scoring function.
16. The apparatus according to any one of claims 9-14, wherein, The prediction module is also used for: When there are multiple candidate entities, a target tail entity that conforms to the target relationship with the target head entity at the target time is determined from the multiple candidate entities based on the probability of each candidate entity.
17. An electronic device comprising: At least one processor; as well as A memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor to enable the at least one processor to perform the method of any one of claims 1-8.
18. A non-transitory computer-readable storage medium storing computer instructions, wherein, The computer instructions are used to cause the computer to perform the method according to any one of claims 1-8.
19. A computer program product comprising a computer program that, when executed by a processor, implements the method according to any one of claims 1-8.