Knowledge graph reasoning method, device and equipment based on dual complex numbers and medium
By embedding entities and relationships in the knowledge graph into the dual complex space and using the non-interchangeability representation relationship mode of dual complex numbers, the problem of existing methods performing poorly when dealing with non-interchangeable combination relationships is solved, and more efficient knowledge graph inference completion is achieved.
Patent Information
- Application Number
- CN202411916264.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-24
- Publication Date
- 2025-04-18
AI Technical Summary
The existing knowledge graph inference completion method cannot effectively represent and distinguish when dealing with non-exchangeable combination relationships, resulting in poor model performance, large parameters and low computing efficiency.
The knowledge graph inference method based on dual complex numbers is adopted to embed entities and relationships into dual complex space, and various relational patterns are represented in two-dimensional space using the non-interchangeability of dual complex numbers, and trained through vector transformation models to achieve inference completion.
Without sacrificing model expressiveness, the amount of parameters is reduced and the computing efficiency of the knowledge graph inference completion task is improved.
Smart Images

Figure CN119849625A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of knowledge graph technology, and in particular to a knowledge graph reasoning method, device, equipment and medium based on dual complex numbers. Background Art
[0002] Knowledge graph is a graph database that describes the knowledge in the real world in a structured form. The basic unit is a triple (head entity, relationship, tail entity), and each triple corresponds to a corresponding factual information. Knowledge graph can facilitate the storage and representation of massive information and is widely used in information retrieval, intelligent question answering, recommendation system and other fields. However, in the early stage of knowledge graph construction, due to incomplete knowledge extraction and dynamic changes in entity relationships, there are missing entities or relationships in the constructed knowledge graph. Therefore, how to reasonably infer and complete the knowledge graph has attracted people's attention.
[0003] Existing knowledge graph reasoning completion methods generally rely on knowledge graph embedding (KGE) technology, which converts entities and relationships in knowledge graphs into appropriate vector representations through vector conversion models, and then uses these vectors to perform efficient reasoning completion tasks. However, when non-commutative combinations are included in the relationship, most existing models cannot effectively represent and distinguish them, resulting in poor performance in subsequent task processing. Models such as QuatE, Rotate3D, and DualE use three-dimensional space to represent non-commutative combinations and other relationships. Although this improves the expressiveness of the model, it also leads to problems such as large number of parameters and low computational efficiency. Therefore, how to reduce the number of parameters used in knowledge graph reasoning completion tasks and improve computational efficiency while ensuring the expressiveness of the model has become a technical problem that needs to be solved urgently. Summary of the invention
[0004] In order to solve the above technical problems, the present disclosure provides a knowledge graph reasoning method, device, equipment and medium based on dual complex numbers.
[0005] A first aspect of an embodiment of the present disclosure provides a knowledge graph reasoning method based on dual complex numbers, the method comprising:
[0006] Extracting a sample triple from the knowledge graph to be inferred, wherein the sample triple includes a first head entity, a first relation, and a first tail entity;
[0007] Performing negative sampling on the sample triplet to obtain a negative sample triplet, wherein the negative sample triplet includes a second head entity, a second relation, and a second tail entity;
[0008] The sample triplet and the negative sample triplet are determined as training data and input into a pre-established vector conversion model, and a first head entity vector, a first relationship vector and a first tail entity vector corresponding to the sample triplet are obtained, as well as a second head entity vector, a second relationship vector and a second tail entity vector corresponding to the negative sample triplet output by the vector conversion model, wherein the vector conversion model is used to embed entities and relationships into a dual complex space;
[0009] constructing a loss function based on the first head entity vector, the first relationship vector, the first tail entity vector, the second head entity vector, the second relationship vector, and the second tail entity vector, and training the vector conversion model based on the loss function to obtain a trained vector conversion model;
[0010] The knowledge graph to be inferred is inferred and completed based on the trained vector conversion model.
[0011] A second aspect of an embodiment of the present disclosure provides a knowledge graph reasoning device based on dual complex numbers, the device comprising:
[0012] An extraction module, used to extract a sample triple from the knowledge graph to be inferred, wherein the sample triple includes a first head entity, a first relation, and a first tail entity;
[0013] A negative sampling module, used for performing negative sampling on the sample triplet to obtain a negative sample triplet, wherein the negative sample triplet includes a second head entity, a second relation, and a second tail entity;
[0014] An input module, used to determine the sample triples and the negative sample triples as training data and input them into a pre-established vector conversion model, to obtain the first head entity vector, the first relationship vector and the first tail entity vector corresponding to the sample triples output by the vector conversion model, and the second head entity vector, the second relationship vector and the second tail entity vector corresponding to the negative sample triples, wherein the vector conversion model is used to embed entities and relationships into a dual complex space;
[0015] a training module, configured to construct a loss function based on the first head entity vector, the first relationship vector, the first tail entity vector, the second head entity vector, the second relationship vector, and the second tail entity vector, and train the vector conversion model based on the loss function to obtain a trained vector conversion model;
[0016] A completion module is used to perform reasoning and completion on the knowledge graph to be inferred based on the trained vector conversion model.
[0017] A third aspect of an embodiment of the present disclosure provides a computer device, including a memory and a processor, and a computer program, wherein the computer program is stored in the memory, and when the computer program is executed by the processor, the knowledge graph reasoning method based on dual complex numbers as described in the first aspect above is implemented.
[0018] A fourth aspect of an embodiment of the present disclosure provides a computer-readable storage medium, in which a computer program is stored. When the computer program is executed by a processor, the knowledge graph reasoning method based on dual complex numbers as described in the first aspect above is implemented.
[0019] Compared with the prior art, the technical solution provided by the embodiments of the present disclosure has the following advantages:
[0020] In the knowledge graph reasoning method, apparatus, device and medium based on dual complex numbers provided in the embodiments of the present disclosure, sample triples are extracted from the knowledge graph to be inferred, the sample triples include a first head entity, a first relationship and a first tail entity, negative sampling is performed on the sample triples to obtain negative sample triples, the negative sample triples include a second head entity, a second relationship and a second tail entity, the sample triples and the negative sample triples are determined as training data and input into a pre-established vector conversion model to obtain the first head entity vector, the first relationship vector and the first tail entity vector corresponding to the sample triples output by the vector conversion model, and the second head entity vector, the second relationship vector and the second tail entity vector corresponding to the negative sample triples, the vector conversion model is used to embed entities and relationships into the dual complex space, based on the first head entity vector, the first relationship vector, the first tail entity vector, the second head entity vector A loss function is constructed based on the vector, the second relation vector and the second tail entity vector, and the vector conversion model is trained based on the loss function to obtain the trained vector conversion model. The knowledge graph to be inferred is completed based on the trained vector conversion model. The dual complex space can be applied to the vector representation of the knowledge graph, and various relational patterns including non-commutative composition patterns are represented in two-dimensional space by using the non-commutativity of the dual complex numbers. A loss function is constructed based on the vector representation in the dual complex space and the vector conversion model is trained, so that the vector conversion model can effectively represent and distinguish various relational patterns. Compared with the use of three-dimensional space (such as QuatE, Rotate3D, DualE and other models) for vector representation, the dual complex space can reduce the amount of parameters without sacrificing the expressiveness of the model, thereby improving the computational efficiency of the knowledge graph reasoning completion task. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the principles of the present disclosure.
[0022] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0023] Figure 1 It is a flow chart of a knowledge graph reasoning method based on dual complex numbers provided by an embodiment of the present disclosure;
[0024] Figure 2 is a flowchart of a method for constructing a loss function provided by an embodiment of the present disclosure;
[0025] Figure 3 is a flowchart of another method for constructing a loss function provided by an embodiment of the present disclosure;
[0026] Figure 4 is a flowchart of another knowledge graph reasoning method based on dual complex numbers provided by an embodiment of the present disclosure;
[0027] Figure 5 It is a schematic diagram of the structure of a knowledge graph reasoning device based on dual complex numbers provided by an embodiment of the present disclosure;
[0028] Figure 6 It is a structural diagram of a computer device provided in an embodiment of the present disclosure. DETAILED DESCRIPTION
[0029] In order to more clearly understand the above-mentioned objectives, features and advantages of the present disclosure, the scheme of the present disclosure will be further described below. It should be noted that the embodiments of the present disclosure and the features in the embodiments can be combined with each other without conflict.
[0030] In the following description, many specific details are set forth to facilitate a full understanding of the present disclosure, but the present disclosure may also be implemented in other ways different from those described herein; it is obvious that the embodiments in the specification are only part of the embodiments of the present disclosure, rather than all of the embodiments.
[0031] It should be understood that the various steps described in the method embodiments of the present disclosure may be performed in different orders and / or in parallel. In addition, the method embodiments may include additional steps and / or omit the steps shown. The scope of the present disclosure is not limited in this respect.
[0032] Figure 1This is a flowchart of a knowledge graph reasoning method based on dual complex numbers provided by an embodiment of the present disclosure. The method can be executed by a knowledge graph reasoning device based on dual complex numbers. The knowledge graph reasoning device based on dual complex numbers can be implemented in software and / or hardware. The knowledge graph reasoning device based on dual complex numbers can be configured in an electronic device, such as a server or a terminal, wherein the terminal specifically includes a mobile phone, a computer or a tablet computer, etc. Figure 1 As shown, the knowledge graph reasoning method based on dual complex numbers provided in this embodiment includes the following steps:
[0033] S101. Extract sample triples from the knowledge graph to be inferred, where the sample triples include a first head entity, a first relationship, and a first tail entity.
[0034] In the disclosed embodiment, the knowledge graph to be inferred may include a large number of nodes and directed edges, where nodes represent entities and directed edges represent relationships. The two nodes connected by the directed edge are the head entity and the tail entity, respectively. The sample triples may be understood as a data set extracted from the knowledge graph to be inferred that contains the complete head entity, the tail entity, and the relationship between the head entity and the tail entity. The first relationship is the relationship between the first head entity and the first tail entity.
[0035] In the disclosed embodiment, the knowledge graph reasoning device based on dual plural numbers can obtain the knowledge graph to be reasoned after receiving the reasoning completion task of the knowledge graph, and extract triples containing the complete first head entity, first relationship and first tail entity as sample triples. Specifically, one or more sample triples can be extracted randomly or according to preset rules, which is not limited here.
[0036] In an exemplary implementation of the embodiments of the present disclosure, a knowledge graph reasoning device based on dual plural numbers can obtain the knowledge graph to be reasoned from the task information after receiving a reasoning and completion task of the knowledge graph, or query the knowledge graph corresponding to the identifier in a preset database according to the identifier of the knowledge graph to be reasoned contained in the task information, and determine it as the knowledge graph to be reasoned.
[0037] S102 . Perform negative sampling on the sample triplet to obtain a negative sample triplet, where the negative sample triplet includes a second head entity, a second relation, and a second tail entity.
[0038] The negative sample triples in the embodiments of the present disclosure can be understood as triples that do not exist in the knowledge graph. There is no relationship between the head entity and the tail entity contained in the negative sample triples. The negative sample triples can be used as comparisons or negative examples during the training process, thereby enhancing the model's ability to distinguish and improving model performance.
[0039] In the embodiment of the present disclosure, the knowledge graph reasoning device based on dual complex numbers can perform negative sampling on the sample triples after extracting them from the knowledge graph to be inferred, so as to obtain negative sample triples containing the second head entity, the second relationship, and the second tail entity. Specifically, one or more of the first head entity, the first relationship, and the first tail entity in the sample triplet can be randomly replaced to obtain the negative sample triples.
[0040] In an exemplary implementation of the embodiments of the present disclosure, the knowledge graph reasoning device based on dual complex numbers can generate a preset number of negative sample triplets for each sample triple.
[0041] Optionally, the knowledge graph reasoning device based on dual complex numbers can perform negative sampling on sample triples to obtain negative sample triples, and then detect and eliminate triples in the negative sample triples that are identical to the sample triples.
[0042] Specifically, in order to prevent the generated negative sample triplet from being the same as a certain sample triplet, resulting in the model being unable to effectively distinguish between positive and negative samples during the training process, thereby affecting the performance and accuracy of the model, the knowledge graph reasoning device based on dual complex numbers can detect whether there is a sample triplet that is the same as the negative sample triplet in the sample triplet after generating the negative sample triplet. If so, the current negative sample triplet will be eliminated.
[0043] S103. Determine the sample triples and the negative sample triples as training data and input them into a pre-established vector conversion model to obtain the first head entity vector, the first relationship vector and the first tail entity vector corresponding to the sample triples output by the vector conversion model, and the second head entity vector, the second relationship vector and the second tail entity vector corresponding to the negative sample triples. The vector conversion model is used to embed entities and relationships into a dual complex space.
[0044] The vector conversion model in the embodiment of the present disclosure can be understood as a neural network model for converting entities or relationships into low-dimensional vector representations in a dual complex space, and the vector conversion model includes at least an embedding layer.
[0045] In the embodiment of the present disclosure, the knowledge graph reasoning device based on dual complex numbers can, after obtaining the sample triples and the negative sample triples, determine the sample triples and the corresponding negative sample triples as training data and input them into a pre-established vector conversion model. The vector conversion model performs vector conversion on the first head entity, the first relationship and the first tail entity in the sample triples, embeds the first head entity, the first relationship and the first tail entity into the dual complex space, and obtains the first head entity vector corresponding to the first head entity, the first relationship vector corresponding to the first relationship, and the first tail entity vector corresponding to the first tail entity. The vector conversion model performs vector conversion on the second head entity, the second relationship and the second tail entity in the negative sample triples, embeds the second head entity, the second relationship and the second tail entity into the dual complex space, and obtains the second head entity vector corresponding to the second head entity, the second relationship vector corresponding to the second relationship, and the second tail entity vector corresponding to the second tail entity.
[0046] Specifically, for each dimension e of the entity vector e j It can be expressed in the dual complex space by the following formula:
[0047] e j =i+x j ∈+y j i∈
[0048] Where i is the imaginary unit, ∈ is the dual part, and x j ,y j is a real number.
[0049] The above equation can be equivalent to representing a point (x j ,y j ), for the sample triple (h, r, t), h represents the first head entity, r represents the first relation, and t represents the first tail entity. The first relation r can be obtained by going around the corresponding points (x j ,y j ), according to the non-commutativity of dual complex numbers, the first head entity vector H, the first relation vector R, and the first tail entity vector T have the following formula:
[0050]
[0051] For the first head entity vector H, the first relationship vector R and the first tail entity vector T, the jth dimension h j 、r j ,t j , the following formula holds:
[0052]
[0053] In the above formula, for each dimension r of the first relationship vector R j∈DC imposes constraints |r j |=1, then r j It is expressed as follows:
[0054]
[0055] Among them, θ r,j For r j The equivalent counterclockwise rotation angle in the Euclidean plane, x r,i ,y r,i h j The horizontal and vertical coordinates of the rotation center point equivalently expressed in the Euclidean plane.
[0056] The second head entity vector, the second relationship vector and the second tail entity vector and the relationship between the vectors are similar to the first head entity vector, the first relationship vector and the first tail entity vector, and are not described again here.
[0057] Common knowledge graph reasoning modes include symmetric / antisymmetric mode, inverse mode, and composition mode. When using dual complex space to represent triples in the knowledge graph, for symmetric / asymmetric mode, given a relationship r and entities x, y, if r(x, y) and r(y, x) hold, then:
[0058]
[0059] On the contrary, if r(x,y) and Established, then:
[0060]
[0061] For the inverse mode, given the relation r 1 ,r 2 and entities x,y, if r 1 (y,x) and r 2 (x,y) holds, then:
[0062]
[0063] For the composition mode, given the relation r 1 ,r 2 ,r 3 and entities x,y,z, if r 1 (x,z), r 2 (x,y) and r 3 (y,z) holds, then:
[0064]
[0065] If the relationship r 2 and the relationship 3Can be exchanged, then:
[0066]
[0067] If the relationship r 2 and the relationship 3 If it is not commutative, then:
[0068]
[0069] Therefore, the symmetric / antisymmetric patterns, inverse patterns, and composition patterns in the triples can all be reasonably represented in the dual complex space.
[0070] S104. Construct a loss function based on the first head entity vector, the first relationship vector, the first tail entity vector, the second head entity vector, the second relationship vector, and the second tail entity vector, and train the vector conversion model based on the loss function to obtain a trained vector conversion model.
[0071] In the embodiment of the present disclosure, the knowledge graph reasoning device based on dual complex numbers can construct a loss function based on the first head entity vector, the first relationship vector, the first tail entity vector, the second head entity vector, the second relationship vector, and the second tail entity vector after obtaining the first head entity vector, the first relationship vector, the first tail entity vector, the second head entity vector, the second relationship vector, and the second tail entity vector output by the vector conversion model. Based on the calculation result of the loss function, the model parameters of the vector conversion model are updated using the gradient descent method, and the next set of sample triplets and negative sample triplets are determined as new training data and input into the updated vector conversion model. The above steps are repeated until the loss value meets the preset requirements, and it is determined that the training of the vector conversion model is completed, wherein the Adam optimizer can be used to adjust the model parameters.
[0072] Among them, when the knowledge graph reasoning device based on dual complex numbers constructs a loss function based on the first head entity vector, the first relationship vector, the first tail entity vector, the second head entity vector, the second relationship vector and the second tail entity vector, the non-commutativity of the dual complex numbers can be utilized to model the relationship between entities in the knowledge graph as a rotation in the Euclidean plane. Specifically, the rotation operation in the Euclidean plane can be used to represent the relationship between the head entity and the tail entity. The loss function is constructed based on the difference between the result obtained by the rotation operation of the head entity vector in the Euclidean plane after the rotation angle corresponding to the relationship and the corresponding representation of the tail entity vector in the Euclidean plane.
[0073] S105. Perform reasoning completion on the knowledge graph to be inferred based on the trained vector conversion model.
[0074] In the disclosed embodiment, the knowledge graph reasoning device based on dual complex numbers can, after the vector conversion model is trained, perform reasoning completion on the knowledge graph to be reasoned based on the trained vector conversion model. Specifically, it can infer the relationship between related entities from the knowledge graph to be reasoned through a method based on similarity measurement, or discover potential facts through an inference engine, thereby achieving reasoning completion of the knowledge graph.
[0075] In an exemplary implementation of the disclosed embodiments, a knowledge graph reasoning device based on dual complex numbers can obtain a triple to be reasoned, wherein the triple to be reasoned includes a head entity element, a relationship element and a tail entity element, and there is an element to be verified and two elements extracted from the knowledge graph to be reasoned, wherein the element to be verified can be determined using an existing knowledge base or external resources, and the triple to be reasoned is input into a trained vector conversion model, and the vector conversion model converts the head entity element, the relationship element and the tail entity element into the dual complex space respectively, and outputs a target head entity vector, a target relationship vector and a target tail entity vector, and judges whether the triple to be reasoned is reasonable based on the target head entity vector, the target relationship vector and the target tail entity vector, and if it is reasonable, the knowledge graph to be reasoned is completed based on the triple to be reasoned.
[0076] The disclosed embodiment extracts sample triples from the knowledge graph to be inferred, the sample triples include a first head entity, a first relationship and a first tail entity, performs negative sampling on the sample triples to obtain negative sample triples, the negative sample triples include a second head entity, a second relationship and a second tail entity, determines the sample triples and the negative sample triples as training data and inputs them into a pre-established vector conversion model to obtain the first head entity vector, the first relationship vector and the first tail entity vector corresponding to the sample triples output by the vector conversion model, and the second head entity vector, the second relationship vector and the second tail entity vector corresponding to the negative sample triples, the vector conversion model is used to embed entities and relationships into a dual complex space, based on the first head entity vector, the first relationship vector, the first tail entity vector, the second head entity vector, the second relationship vector and the second tail entity vector A loss function is constructed based on the vector, and the vector conversion model is trained based on the loss function to obtain the trained vector conversion model. The knowledge graph to be inferred is completed based on the trained vector conversion model. The dual complex space can be applied to the vector representation of the knowledge graph, and various relationship patterns including non-commutative composition patterns are represented in two-dimensional space by using the non-commutativity of the dual complex numbers. A loss function is constructed based on the vector representation in the dual complex space and the vector conversion model is trained, so that the vector conversion model can effectively represent and distinguish various relationship patterns. Compared with the use of three-dimensional space (such as QuatE, Rotate3D, DualE and other models) for vector representation, the dual complex space can reduce the amount of parameters without sacrificing the expressiveness of the model, thereby improving the computational efficiency of the knowledge graph reasoning completion task.
[0077] Figure 2 is a flowchart of a method for constructing a loss function provided by an embodiment of the present disclosure, such as Figure 2 As shown, based on the above embodiment, the loss function can be constructed by the following method.
[0078] S201. Calculate a first distance score corresponding to the sample triple based on the first head entity vector, the first relationship vector, and the first tail entity vector.
[0079] The distance score in the embodiment of the present disclosure may be understood as a parameter used to measure the degree of proximity between the tail entity vector inferred from the head entity vector and the relationship vector in the triple and the actual tail entity vector.
[0080] In an embodiment of the present disclosure, a knowledge graph reasoning device based on dual complex numbers can calculate the first distance score corresponding to the sample triplet according to a preset distance score calculation formula after obtaining the first head entity vector, the first relationship vector and the first tail entity vector.
[0081] Optionally, S201 may include:
[0082] S2011. Calculate a first ideal tail entity vector in the dual complex space based on the first head entity vector and the first relationship vector.
[0083] S2012. Calculate a first distance score corresponding to the sample triple based on the absolute value of the difference between the first tail entity vector and the first ideal tail entity vector.
[0084] The first ideal tail entity vector may be understood as a tail entity vector inferred from the first head entity vector and the first relationship vector.
[0085] Specifically, the knowledge graph reasoning device based on dual complex numbers can calculate the embedded representation of each dimension of the first ideal tail entity vector in the dual complex space according to each dimension of the first head entity vector and each dimension of the first relationship vector, calculate the absolute value of the difference between each dimension of the first ideal tail entity vector and each dimension of the first tail entity vector, determine it as the distance corresponding to the current dimension, and sum the distances of each dimension, and obtain the first distance score corresponding to the sample triple based on the summation result, which can be specifically expressed as follows:
[0086]
[0087] Among them, d r (h, t) represents the first distance score corresponding to the sample triple, k is the embedding dimension of the entity and relationship, r j represents the jth dimension of the first relationship vector, h j represents the jth dimension of the first entity vector, t j represents the j-th dimension of the first tail entity vector, represents the j-th dimension of the first ideal tail entity vector.
[0088] S202: Calculate a second distance score corresponding to the negative sample triplet based on the second head entity vector, the second relationship vector, and the second tail entity vector.
[0089] In an embodiment of the present disclosure, a knowledge graph reasoning device based on dual complex numbers can calculate the second distance score corresponding to the negative sample triple according to a preset distance score calculation formula after obtaining the second head entity vector, the second relationship vector and the second tail entity vector.
[0090] Optionally, S202 may include:
[0091] S2021. Calculate the second ideal tail entity vector in the dual complex space based on the second head entity vector and the second relationship vector.
[0092] S2022. Calculate a second distance score corresponding to the negative sample triplet based on the absolute value of the difference between the second tail entity vector and the second ideal tail entity vector.
[0093] The second ideal tail entity vector may be understood as a tail entity vector inferred from the second head entity vector and the second relationship vector.
[0094] Specifically, the knowledge graph reasoning device based on dual complex numbers can calculate the embedded representation of each dimension of the second ideal tail entity vector in the dual complex space according to each dimension of the second head entity vector and each dimension of the second relationship vector, calculate the absolute value of the difference between each dimension of the second ideal tail entity vector and each dimension of the second tail entity vector, determine it as the distance corresponding to the current dimension, sum the distances of each dimension, and obtain the second distance score corresponding to the negative sample triplet based on the summation result. The specific calculation formula is similar to S201 and will not be repeated here.
[0095] S203: construct a loss function based on negative sampling loss based on the first distance score and the second distance score.
[0096] In the embodiment of the present disclosure, the knowledge graph reasoning device based on dual complex numbers can calculate the first distance score corresponding to the sample triple and the second distance score corresponding to the negative sample triple, and then construct a loss function based on negative sampling loss based on the first distance score and the second distance score. The loss function can be specifically expressed as follows:
[0097]
[0098] Among them, L represents the loss value, γ represents the fixed width boundary, σ represents the sigmoid function, m represents the size of the negative sampling scale, and d r (h i ′ ,t i ′ ) represents the second distance score corresponding to the i-th negative sample triplet, d r (h, t) represents the first distance score corresponding to the sample triplet.
[0099] The disclosed embodiment calculates the first distance score corresponding to the sample triplet based on the first head entity vector, the first relationship vector and the first tail entity vector, calculates the second distance score corresponding to the negative sample triplet based on the second head entity vector, the second relationship vector and the second tail entity vector, and constructs a loss function based on negative sampling loss based on the first distance score and the second distance score, which can prompt the vector conversion model to learn more discriminative features during the training process and improve the model performance in subsequent knowledge graph reasoning and completion tasks.
[0100] Figure 3 is a flowchart of another method for constructing a loss function provided by an embodiment of the present disclosure, such as Figure 3As shown, based on the above embodiment, the loss function can be constructed by the following method.
[0101] S301. A self-adversarial negative sampling method is used to construct negative sample triplets for sample triplets. The probability distribution of the self-adversarial negative sampling is determined based on the second distance score corresponding to each negative sample triplet.
[0102] The self-adversarial negative sampling in the embodiments of the present disclosure can be understood as a negative sampling method that generates more valuable negative samples by increasing the sampling frequency of negative samples that have not been effectively trained.
[0103] In the embodiment of the present disclosure, the knowledge graph reasoning device based on dual complex numbers can use the self-adversarial negative sampling method to construct the negative sample triples in the training data used in the next step after each iterative update of the model parameters during the model training process. Specifically, multiple candidate negative sample triples can be generated according to the sample triples in the training data used in the next step, and the second distance scores corresponding to each candidate negative sample triple are determined according to the current model parameters of the vector conversion model. Then, based on the second distance scores corresponding to each candidate negative sample triple, the probability distribution used when constructing the final negative sample triple is determined. The probability distribution can be specifically expressed as follows:
[0104]
[0105] Among them, p(h i ′ ,r,t i ′ ) represents the negative sample triplet of the i-th candidate (h i ′ ,r,t i ′ ) is selected, f r (h i ′ ,t i ′ )=-d r (h i ′ ,t i ′ ), d r (h i ′ ,t i ′ ) represents the second distance score corresponding to the i-th candidate negative sample triplet, f r (h j ′ ,t j ′ )=-d r (h j′ ,t j ′ ), d r (h j ′ ,t j ′ ) represents the second distance score corresponding to the j-th candidate negative sample triplet, and α represents the sampling temperature.
[0106] S302: Construct a loss function based on negative sampling loss based on the probability distribution, the first distance score, the second distance score and a preset regularization ratio.
[0107] In the embodiment of the present disclosure, the knowledge graph reasoning device based on dual complex numbers can construct a loss function based on negative sampling loss according to the probability distribution of self-adversarial negative sampling used in the current step, the first distance score corresponding to the vector representation of the sample triplet used in the current step, the second distance score corresponding to the vector representation of the negative sample triplet used in the current step, and the preset regularization ratio after inputting the sample triplet and the negative sample triplet used in the current step as training data into the vector conversion model. The loss function can be specifically expressed as follows:
[0108]
[0109] Among them, L represents the loss value, m represents the size of negative sampling, p(h i ′ ,r,t i ′ ) represents the negative sample triplet of the i-th candidate (h i ′ ,r,t i ′ ) is selected, d r (h i ′ ,t i ′ ) represents the second distance score corresponding to the i-th negative sample triplet, γ represents a fixed width boundary, σ represents the sigmoid function, and d r (h, t) represents the first distance score corresponding to the sample triplet, λ represents the regularization ratio, and h and t represent the first head entity and the first tail entity in the sample triplet, respectively.
[0110] The disclosed embodiment constructs negative sample triplets by adopting a self-adversarial negative sampling method for sample triplets. The probability distribution of the self-adversarial negative sampling is determined based on the second distance score corresponding to each negative sample triplet. A loss function based on negative sampling loss is constructed based on the probability distribution, the first distance score, the second distance score and a preset regularization ratio. This can improve the quality of negative samples, accelerate model training, and avoid model overfitting, so that the model has better generalization ability in real scenarios.
[0111] Figure 4 is a flowchart of another method for knowledge graph reasoning based on dual complex numbers provided by an embodiment of the present disclosure. Figure 4 As shown, based on the above embodiments, knowledge graph reasoning based on dual complex numbers can be performed by the following method.
[0112] S401. Obtain a data group to be inferred, where the data group to be inferred includes two elements in the knowledge graph to be inferred.
[0113] In the disclosed embodiment, the knowledge graph reasoning device based on dual complex numbers can extract a data group to be reasoned from the knowledge graph to be reasoned, or receive a data group to be reasoned specified by a user after the vector conversion model is trained. The data group to be reasoned includes two elements in the knowledge graph to be reasoned.
[0114] S402: Input the data group to be inferred into the trained vector conversion model to obtain two vectors to be inferred output by the vector conversion model.
[0115] In the embodiment of the present disclosure, the knowledge graph reasoning device based on dual complex numbers can input the data group to be reasoned into the trained vector conversion model, and the vector conversion model converts two elements in the data group to be reasoned into the dual complex space respectively, and outputs two vectors to be reasoned.
[0116] S403. Calculate the target vector corresponding to the missing target element in the data group to be inferred in the dual complex space based on the two vectors to be inferred, and determine the target element based on the target vector.
[0117] In the embodiment of the present disclosure, the knowledge graph reasoning device based on dual complex numbers can determine the calculation method of the corresponding target vector according to the attributes of the two elements in the data group to be inferred (i.e., the head entity, the relationship, or the tail entity) after obtaining the two vectors to be inferred corresponding to the reasoning data group, and calculate the two vectors to be inferred according to the calculation method to obtain the target vector corresponding to the missing target element in the data group to be inferred. For example, for the data group to be inferred containing the head entity element and the relationship element, the missing target element is the tail entity element. Based on the vector to be inferred h corresponding to the head entity element l The vector to be inferred r corresponding to the relation element l, calculate the target vector t corresponding to the missing target element l The process can be expressed as follows:
[0118]
[0119] After obtaining the target vector corresponding to the target element, the knowledge graph reasoning device based on dual complex numbers further determines the target element based on the target vector. Optionally, the knowledge graph reasoning device based on dual complex numbers can search for the entity with the highest similarity to the target vector in the vectors corresponding to each entity contained in the knowledge graph, and determine it as the missing tail entity in the data group to be inferred.
[0120] The disclosed embodiment obtains a data group to be inferred, which includes two elements in a knowledge graph to be inferred, inputs the data group to be inferred into a trained vector conversion model, obtains two vectors to be inferred output by the vector conversion model, calculates the target vector corresponding to the missing target element in the data group to be inferred in the dual complex space based on the two vectors to be inferred, and determines the target element based on the target vector. This can capture implicit information between elements in the dual complex space and improve the accuracy of reasoning and completing missing elements in the knowledge graph.
[0121] Figure 5 Schematic diagram of a knowledge graph reasoning device based on dual complex numbers provided by an embodiment of the present disclosure. Figure 5As shown, the knowledge graph reasoning device 500 based on dual complex numbers includes: an extraction module 510, a negative sampling module 520, an input module 530, a training module 540, and a completion module 550, wherein the extraction module 510 is used to extract sample triples from the knowledge graph to be inferred, and the sample triples include a first head entity, a first relationship, and a first tail entity; the negative sampling module 520 is used to negatively sample the sample triples to obtain negative sample triples, and the negative sample triples include a second head entity, a second relationship, and a second tail entity; the input module 530 is used to determine the sample triples and the negative sample triples as training data and input them into a pre-established vector conversion model to obtain the vector conversion model output by the vector conversion model. The first head entity vector, the first relationship vector and the first tail entity vector corresponding to the sample triplet, and the second head entity vector, the second relationship vector and the second tail entity vector corresponding to the negative sample triplet, the vector conversion model is used to embed entities and relationships into a dual complex space; a training module 540 is used to construct a loss function based on the first head entity vector, the first relationship vector, the first tail entity vector, the second head entity vector, the second relationship vector and the second tail entity vector, and train the vector conversion model based on the loss function to obtain a trained vector conversion model; a completion module 550 is used to perform reasoning and completion on the knowledge graph to be inferred based on the trained vector conversion model.
[0122] Optionally, the training module 540 includes: a first calculation unit, used to calculate the first distance score corresponding to the sample triplet based on the first head entity vector, the first relationship vector and the first tail entity vector; a second calculation unit, used to calculate the second distance score corresponding to the negative sample triplet based on the second head entity vector, the second relationship vector and the second tail entity vector; and a construction unit, used to construct a loss function based on negative sampling loss based on the first distance score and the second distance score.
[0123] Optionally, the first calculation unit includes: a first calculation subunit, used to calculate the first ideal tail entity vector in the dual complex space based on the first head entity vector and the first relationship vector; and a second calculation subunit, used to calculate the first distance score corresponding to the sample triplet based on the absolute value of the difference between the first tail entity vector and the first ideal tail entity vector.
[0124] Optionally, the second calculation unit includes: a third calculation subunit, used to calculate the second ideal tail entity vector in the dual complex space based on the second head entity vector and the second relationship vector; and a fourth calculation subunit, used to calculate the second distance score corresponding to the negative sample triplet based on the absolute value of the difference between the second tail entity vector and the second ideal tail entity vector.
[0125] Optionally, the dual complex-based knowledge graph reasoning device 500 further includes: a detection module, configured to detect and remove triples in the negative sample triples that are identical to the sample triples.
[0126] Optionally, the negative sampling module is specifically used to construct the negative sample triples by using a self-adversarial negative sampling method for the sample triples, and the probability distribution of the self-adversarial negative sampling is determined based on the second distance score corresponding to each negative sample triple; the construction unit is specifically used to construct a loss function based on negative sampling loss based on the probability distribution, the first distance score, the second distance score and a preset regularization ratio.
[0127] Optionally, the completion module 550 includes: an acquisition unit, used to acquire a data group to be inferred, the data group to be inferred includes two elements in the knowledge graph to be inferred; a conversion unit, used to input the data group to be inferred into a trained vector conversion model to obtain two vectors to be inferred output by the vector conversion model; a completion unit, used to calculate the target vector corresponding to the missing target element in the data group to be inferred in the dual complex space based on the two vectors to be inferred, and determine the target element based on the target vector.
[0128] The knowledge graph reasoning device based on dual complex numbers provided in this embodiment can execute the method described in any of the above embodiments. Its execution method and beneficial effects are similar and will not be repeated here.
[0129] Figure 6 It is a structural diagram of a computer device provided in an embodiment of the present disclosure.
[0130] like Figure 6 As shown, the computer device may include a processor 610 and a memory 620 storing computer program instructions.
[0131] Specifically, the processor 610 may include a central processing unit (CPU), or an application specific integrated circuit (ASIC), or may be configured to implement one or more integrated circuits of the embodiments of the present application.
[0132] The memory 620 may include a large capacity memory for information or instructions. By way of example and not limitation, the memory 620 may include a hard disk drive (HDD), a floppy disk drive, a flash memory, an optical disk, a magneto-optical disk, a tape, or a universal serial bus (USB) drive or a combination of two or more of these. Where appropriate, the memory 620 may include a removable or non-removable (or fixed) medium. Where appropriate, the memory 620 may be inside or outside the integrated gateway device. In a particular embodiment, the memory 620 is a non-volatile solid-state memory. In a particular embodiment, the memory 620 includes a read-only memory (ROM). Where appropriate, the ROM may be a mask-programmed ROM, a programmable ROM (PROM), an erasable PROM (EPROM), an electrically erasable PROM (Electrically Erasable Programmable ROM, EEPROM), an electrically rewritable ROM (EAROM) or a flash memory, or a combination of two or more of these.
[0133] The processor 610 reads and executes the computer program instructions stored in the memory 620 to perform the steps of the knowledge graph reasoning method based on dual complex numbers provided in the embodiment of the present disclosure.
[0134] In one example, the computer device may further include a transceiver 630 and a bus 640. Figure 6 As shown, the processor 610, the memory 620 and the transceiver 630 are connected via a bus 640 and communicate with each other.
[0135] The bus 640 includes hardware, software, or both. For example, but not limitation, the bus may include an Accelerated Graphics Port (AGP) or other graphics bus, an Extended Industry Standard Architecture (EISA) bus, a Front Side Bus (FSB), a Hyper Transport (HT) interconnect, an Industrial Standard Architecture (ISA) bus, an InfiniBand interconnect, a Low Pin Count (LPC) bus, a memory bus, a MicroChannel Architecture (MCA) bus, a Peripheral Component Interconnect (PCI) bus, a PCI-Express (PCI-X) bus, a Serial Advanced Technology Attachment (SATA) bus, a Video Electronics Standards Association Local Bus (VLB) bus, or other suitable buses or a combination of two or more of these. Where appropriate, the bus 640 may include one or more buses. Although embodiments of the present application describe and illustrate a particular bus, the present application contemplates any suitable bus or interconnect.
[0136] The embodiments of the present disclosure also provide a computer-readable storage medium, which may store a computer program. When the computer program is executed by a processor, the processor implements the knowledge graph reasoning method based on dual complex numbers provided by the embodiments of the present disclosure.
[0137] The above-mentioned storage medium may, for example, include a memory 620 of computer program instructions, and the above-mentioned instructions may be executed by the processor 610 of the knowledge graph reasoning device based on dual complex numbers to complete the knowledge graph reasoning method based on dual complex numbers provided in the embodiment of the present disclosure. Optionally, the storage medium may be a non-temporary computer-readable storage medium, for example, the non-temporary computer-readable storage medium may be a ROM, a random access memory (Random Access Memory, RAM), a compact disc read-only memory (Compact Disc ROM, CD-ROM), a magnetic tape, a floppy disk, and an optical data storage device, etc. The above-mentioned computer program may be written in any combination of one or more programming languages to perform the program code of the operation of the embodiment of the present disclosure, and the programming language includes an object-oriented programming language, such as Java, C++, etc., and also includes a conventional procedural programming language, such as "C" language or a similar programming language. The program code may be executed entirely on the user computing device, partially on the user device, as an independent software package, partially on the user computing device, partially on the remote computing device, or entirely on the remote computing device or server.
[0138] It should be noted that, in this article, relational terms such as "first" and "second" are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0139] The above description is only a specific embodiment of the present disclosure, so that those skilled in the art can understand or implement the present disclosure. Various modifications to these embodiments will be 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 the present disclosure. Therefore, the present disclosure will not be limited to the embodiments described herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A knowledge graph reasoning method based on dual complex numbers, characterized in that: The method comprises: Extracting a sample triple from the knowledge graph to be inferred, wherein the sample triple includes a first head entity, a first relation, and a first tail entity; Performing negative sampling on the sample triplet to obtain a negative sample triplet, wherein the negative sample triplet includes a second head entity, a second relation, and a second tail entity; The sample triplet and the negative sample triplet are determined as training data and input into a pre-established vector conversion model, and a first head entity vector, a first relationship vector and a first tail entity vector corresponding to the sample triplet are obtained, as well as a second head entity vector, a second relationship vector and a second tail entity vector corresponding to the negative sample triplet output by the vector conversion model, wherein the vector conversion model is used to embed entities and relationships into a dual complex space; constructing a loss function based on the first head entity vector, the first relationship vector, the first tail entity vector, the second head entity vector, the second relationship vector, and the second tail entity vector, and training the vector conversion model based on the loss function to obtain a trained vector conversion model; The knowledge graph to be inferred is inferred and completed based on the trained vector conversion model.
2. The method according to claim 1, characterized in that: The constructing a loss function based on the first head entity vector, the first relationship vector, the first tail entity vector, the second head entity vector, the second relationship vector, and the second tail entity vector includes: Calculating a first distance score corresponding to the sample triplet based on the first head entity vector, the first relationship vector, and the first tail entity vector; Calculating a second distance score corresponding to the negative sample triplet based on the second head entity vector, the second relationship vector, and the second tail entity vector; A loss function based on negative sampling loss is constructed based on the first distance score and the second distance score.
3. The method according to claim 2, characterized in that The calculating, based on the first head entity vector, the first relationship vector, and the first tail entity vector, a first distance score corresponding to the sample triplet includes: Calculate a first ideal tail entity vector in the dual complex space based on the first head entity vector and the first relationship vector; A first distance score corresponding to the sample triplet is calculated based on an absolute value of a difference between the first tail entity vector and the first ideal tail entity vector.
4. The method according to claim 2, characterized in that: The calculating, based on the second head entity vector, the second relationship vector, and the second tail entity vector, a second distance score corresponding to the negative sample triplet includes: Calculate a second ideal tail entity vector in the dual complex space based on the second head entity vector and the second relationship vector; A second distance score corresponding to the negative sample triplet is calculated based on an absolute value of a difference between the second tail entity vector and the second ideal tail entity vector.
5. The method according to claim 1, characterized in that After negative sampling is performed on the sample triplet to obtain a negative sample triplet, the method further includes: The triples in the negative sample triples that are identical to the sample triples are detected and eliminated.
6. The method according to claim 2, characterized in that The negative sampling of the sample triplet to obtain a negative sample triplet includes: Constructing the negative sample triplet by using a self-adversarial negative sampling method for the sample triplet, wherein the probability distribution of the self-adversarial negative sampling is determined based on the second distance score corresponding to each negative sample triplet; The constructing a loss function based on negative sampling loss based on the first distance score and the second distance score includes: A loss function based on negative sampling loss is constructed based on the probability distribution, the first distance score, the second distance score, and a preset regularization ratio.
7. The method according to any one of claims 1 to 6, characterized in that The reasoning and completing the knowledge graph to be inferred based on the trained vector conversion model includes: Obtaining a data group to be inferred, wherein the data group to be inferred includes two elements in the knowledge graph to be inferred; Inputting the data group to be inferred into the trained vector conversion model to obtain two vectors to be inferred output by the vector conversion model; A target vector corresponding to a target element missing in the data set to be inferred in the dual complex space is calculated based on the two vectors to be inferred, and the target element is determined based on the target vector.
8. A knowledge graph reasoning device based on dual complex numbers, characterized in that: The device comprises: An extraction module, used to extract a sample triple from the knowledge graph to be inferred, wherein the sample triple includes a first head entity, a first relation, and a first tail entity; A negative sampling module, used for performing negative sampling on the sample triplet to obtain a negative sample triplet, wherein the negative sample triplet includes a second head entity, a second relation, and a second tail entity; An input module, used to determine the sample triples and the negative sample triples as training data and input them into a pre-established vector conversion model, to obtain the first head entity vector, the first relationship vector and the first tail entity vector corresponding to the sample triples output by the vector conversion model, and the second head entity vector, the second relationship vector and the second tail entity vector corresponding to the negative sample triples, wherein the vector conversion model is used to embed entities and relationships into a dual complex space; a training module, configured to construct a loss function based on the first head entity vector, the first relationship vector, the first tail entity vector, the second head entity vector, the second relationship vector, and the second tail entity vector, and train the vector conversion model based on the loss function to obtain a trained vector conversion model; A completion module is used to perform reasoning and completion on the knowledge graph to be inferred based on the trained vector conversion model.
9. A computer device, characterized in that: include: Memory; processor; And a computer program; wherein, the computer program is stored in the memory and is configured to be executed by the processor to implement the knowledge graph reasoning method based on dual complex numbers as described in any one of claims 1-7.
10. A computer-readable storage medium, characterized in that: The storage medium stores a computer program, and when the computer program is executed by a processor, the knowledge graph reasoning method based on dual complex numbers as described in any one of claims 1 to 7 is implemented.