Knowledge Graph Completion Method, Device, Computer Equipment and Storage Medium

By constructing and updating search particles in the knowledge graph using the particle swarm optimization algorithm, the problem of low efficiency in knowledge graph completion under large-scale nodes is solved, and fast and accurate knowledge graph completion is achieved.

CN114780741BActive Publication Date: 2025-08-01华润数字科技有限公司
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210404813.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-04-18
Publication Date
2025-08-01
Estimated Expiration
2042-04-18

AI Technical Summary

Technical Problem

Existing knowledge graph completion methods are inefficient when dealing with a large number of nodes, especially due to the inefficiency caused by random walk methods.

Method used

The particle swarm optimization algorithm is adopted to construct a knowledge graph through named entity recognition. The search particles are initialized and individual extreme values ​​and global values ​​are calculated. The particle positions are updated until the iteration threshold is reached, and the global optimal solution is obtained to complete the knowledge graph.

Benefits of technology

It enables rapid knowledge graph completion, improving completion efficiency and accuracy.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114780741B_ABST
    Figure CN114780741B_ABST
Patent Text Reader

Abstract

The embodiments of the present application belong to the field of artificial intelligence and relate to a method for knowledge graph completion, including obtaining a target document, constructing a target knowledge graph of the target document through named entity recognition; initializing a plurality of search particles, as well as the initial velocity and starting node of the search particles, and determining the path nodes of the search particles in the target knowledge graph according to the initial velocity and starting node; calculating the individual extreme value and the current global value of the search particles at the path nodes, and updating the path nodes based on the individual extreme value and the current global value until the update times of the search particles reach a preset maximum iteration threshold, determining that the update of the search particles is completed; obtaining the global optimal solution after the update of the search particles is completed, and complementing the target knowledge graph based on the global optimal solution to obtain a completed knowledge graph. The present application also provides a knowledge graph completion device, a computer device, and a storage medium. The present application realizes the efficient completion of the target knowledge graph.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of artificial intelligence technology, and in particular, to a method, apparatus, computer device, and storage medium for knowledge graph completion. Background Art

[0002] In recent years, knowledge graphs have been widely used in many fields such as finance, e-commerce, and healthcare. However, the cost of constructing a knowledge graph is high, and there is often a lack of relationships between nodes. For example, in Freebase, 66% of people lack the relationship of place of birth. Therefore, entity completion of such knowledge graphs is often required.

[0003] Currently, a representative knowledge graph completion method is the PRA (Path Ranking Algorithm) algorithm. The main idea of this algorithm is: starting from a certain node, using a random walk method, performing a depth-first search to obtain candidate paths, and using the paths connecting two entities as features to predict the relationship between the two entities. The learning stage is divided into three parts: feature extraction, feature calculation, and classifier construction. When the number of nodes in the knowledge graph is huge, the random walk method adopted by the PRA algorithm will result in low efficiency of graph completion. Summary of the Invention

[0004] The purpose of the embodiments of this application is to propose a method, apparatus, computer device, and storage medium for knowledge graph completion to solve the technical problem of low efficiency of current knowledge graph completion.

[0005] To solve the above technical problem, the embodiments of this application provide a method for knowledge graph completion, which adopts the following technical solutions:

[0006] Obtain a target document, and construct a target knowledge graph of the target document through named entity recognition;

[0007] Initialize multiple search particles, as well as the initial velocity and starting node of the search particles, and determine the path nodes of the search particles in the target knowledge graph according to the initial velocity and the starting node;

[0008] Calculate the individual extreme value and the current global value of the search particles at the path nodes, and update the path nodes based on the individual extreme value and the current global value until the update times of the search particles reach a preset maximum iteration threshold, and determine that the search particles are updated completely;

[0009] Obtain the global optimal solution after the search particles are updated completely, and complete the target knowledge graph based on the global optimal solution to obtain a completed knowledge graph.

[0010] Further, the step of calculating the individual extreme value and the current global value of the search particle at the path node includes:

[0011] Obtain all the path nodes passed by the search particle when reaching the current path node, and calculate the average semantic distance of the edges from each path node to the directly connected nodes;

[0012] Select the maximum value among the average semantic distances as the individual extreme value of the current path node, obtain the extreme value set composed of the individual extreme values of all the search particles in the current particle swarm size, and take the maximum value in the extreme value set as the current global value.

[0013] Further, after the step of taking the maximum value in the extreme value set as the current global value, it further includes:

[0014] Obtain the historical global value, determine whether the historical global value is greater than the current global value, and when the historical global value is greater than the current global value, replace the current global value with the historical global value.

[0015] Further, the step of updating the path node based on the individual extreme value and the current global value includes:

[0016] Obtain the preset inertia factor and learning factor, and calculate the update speed of the search particle based on the inertia factor, the learning factor, the individual extreme value and the current global value;

[0017] Move the search particle based on the update speed, and determine the next node reached by the search particle as the updated position of the search particle.

[0018] Further, before the step of moving the search particle based on the update speed, it further includes:

[0019] Calculate the product of the semantic distances between the departure node and the path node;

[0020] Determine whether the product of the semantic distances is greater than or equal to the preset constraint threshold, and when the product of the semantic distances is greater than or equal to the preset constraint threshold, calculate the update speed of the search particle.

[0021] Further, the step of calculating the product of the semantic distances between the departure node and the path node includes:

[0022] Obtain all the path nodes between the departure node and the current path node, and calculate the sub-semantic distance from the departure node to each path node;

[0023] Multiply the sub-semantic distances to obtain the product of the semantic distances.

[0024] Further, the step of calculating the sub-semantic distance from the starting node to each of the passing nodes includes:

[0025] Obtain the first connected edge node and the second connected edge node corresponding to the starting node and each of the passing nodes respectively;

[0026] Calculate the first embedding vector, the second embedding vector, the third embedding vector and the fourth embedding vector corresponding to the starting node, the passing node, the first connected edge node and the second connected edge node respectively;

[0027] Calculate a first similarity based on the first embedding vector and the second embedding vector, calculate a second similarity based on the third embedding vector and the fourth embedding vector, and perform a product calculation on the first similarity and the second similarity to obtain the sub-semantic distance.

[0028] To solve the above technical problem, an embodiment of the present application further provides a knowledge graph completion device, which adopts the following technical solutions:

[0029] A construction module, configured to obtain a target document and construct a target knowledge graph of the target document through named entity recognition;

[0030] An initialization module, configured to initialize a plurality of search particles, as well as the initial velocity and the starting node of the search particles, and determine the passing nodes of the search particles in the target knowledge graph according to the initial velocity and the starting node;

[0031] An update module, configured to calculate the individual extreme value and the current global value of the search particles at the passing nodes, and update the passing nodes based on the individual extreme value and the current global value until the update times of the search particles reach a preset maximum iteration threshold, and determine that the search particles are updated;

[0032] A completion module, configured to obtain the global optimal solution after the search particles are updated, and complete the target knowledge graph based on the global optimal solution to obtain a completed knowledge graph.

[0033] To solve the above technical problem, an embodiment of the present application further provides a computer device, which adopts the following technical solutions:

[0034] Obtain a target document and construct a target knowledge graph of the target document through named entity recognition;

[0035] Initialize a plurality of search particles, as well as the initial velocity and the starting node of the search particles, and determine the passing nodes of the search particles in the target knowledge graph according to the initial velocity and the starting node;

[0036] Calculate the individual extreme value and the current global value of the search particle at the path node, update the path node based on the individual extreme value and the current global value, and continue until the update times of the search particle reach the preset maximum iteration threshold, at which point it is determined that the update of the search particle is complete;

[0037] Obtain the globally optimal solution after the update of the search particle is complete, and complete the target knowledge graph based on the globally optimal solution to obtain a completed knowledge graph.

[0038] To solve the above technical problems, an embodiment of the present application further provides a computer-readable storage medium, which adopts the following technical solutions:

[0039] Obtain a target document, and construct a target knowledge graph of the target document through named entity recognition;

[0040] Initialize multiple search particles, as well as the initial velocity and starting node of the search particle. According to the initial velocity and the starting node, determine the path nodes of the search particle in the target knowledge graph;

[0041] Calculate the individual extreme value and the current global value of the search particle at the path node, update the path node based on the individual extreme value and the current global value, and continue until the update times of the search particle reach the preset maximum iteration threshold, at which point it is determined that the update of the search particle is complete;

[0042] Obtain the globally optimal solution after the update of the search particle is complete, and complete the target knowledge graph based on the globally optimal solution to obtain a completed knowledge graph.

[0043] The knowledge graph completion method proposed in the present application constructs a target knowledge graph of a target document by obtaining the target document and performing named entity recognition; then, initializes multiple search particles, as well as the initial velocity and starting node of the search particle, and determines the path nodes of the search particle in the target knowledge graph according to the initial velocity and the starting node; then, calculates the individual extreme value and the current global value of the search particle at the path node, and updates the path node based on the individual extreme value and the current global value until the update times of the search particle reach the preset maximum iteration threshold, at which point it is determined that the update of the search particle is complete, enabling efficient search for nodes in the target knowledge graph by the search particle; finally, obtains the globally optimal solution after the update of the search particle is complete, and completes the target knowledge graph based on the globally optimal solution to obtain a completed knowledge graph, thereby achieving fast completion of the target knowledge graph and improving the completion efficiency and accuracy of the knowledge graph. Description of the Drawings

[0044] To more clearly illustrate the solutions in this application, the following provides a brief introduction to the drawings required for the description of the embodiments of this application. Obviously, the drawings described below are some embodiments of this application. For those of ordinary skill in the art, without creative efforts, other drawings can be obtained based on these drawings.

[0045] Figure 1 is an exemplary system architecture diagram to which this application can be applied;

[0046] Figure 2 is a flowchart of an embodiment of the knowledge graph completion method according to this application;

[0047] Figure 3 is a schematic structural diagram of an embodiment of the knowledge graph completion device according to this application;

[0048] Figure 4 is a schematic structural diagram of an embodiment of the computer device according to this application.

[0049] Reference numerals: knowledge graph completion device 300, construction module 301, initialization module 302, update module 303, and completion module 304. Detailed implementation manners

[0050] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by those skilled in the technical field to which this application belongs; the terms used in the specification of this application are only for the purpose of describing specific embodiments and are not intended to limit this application; the terms "including" and "having" and any variations thereof in the specification and claims of this application and the above drawings are intended to cover non-exclusive inclusion. The terms "first", "second", etc. in the specification and claims of this application or the above drawings are used to distinguish different objects and not to describe a specific order.

[0051] Reference to "embodiment" herein means that a specific feature, structure, or characteristic described in connection with the embodiment can be included in at least one embodiment of this application. The phrase appears in various places in the specification and does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment mutually exclusive with other embodiments. Those skilled in the art explicitly and implicitly understand that the embodiments described herein can be combined with other embodiments.

[0052] To enable those skilled in the technical field to better understand the solutions of this application, the following will clearly and completely describe the technical solutions in the embodiments of this application with reference to the drawings.

[0053] Such as Figure 1As shown, the system architecture 100 may include terminal devices 101, 102, 103, a network 104, and a server 105. The network 104 is used to provide a medium for communication links between the terminal devices 101, 102, 103 and the server 105. The network 104 may include various connection types, such as wired, wireless communication links, or fiber optic cables, etc.

[0054] Users can use the terminal devices 101, 102, 103 to interact with the server 105 through the network 104 to receive or send messages, etc. Various communication client applications may be installed on the terminal devices 101, 102, 103, such as web browser applications, shopping applications, search applications, instant messaging tools, email clients, social platform software, etc.

[0055] The terminal devices 101, 102, 103 may be various electronic devices with a display screen and supporting web browsing, including but not limited to smart phones, tablets, e-book readers, MP3 players (Moving Picture Experts Group Audio Layer III), MP4 (Moving Picture Experts Group Audio Layer IV) players, laptop computers, and desktop computers, etc.

[0056] The server 105 may be a server providing various services, such as a background server that supports the pages displayed on the terminal devices 101, 102, 103.

[0057] It should be noted that the knowledge graph completion method provided by the embodiments of the present application is generally executed by the server / terminal device. Correspondingly, the knowledge graph completion device is generally set in the server / terminal device.

[0058] It should be understood that Figure 1 the numbers of the terminal devices, the network, and the server in

[0059] Continue to refer to Figure 2 , which shows a flowchart of an embodiment of the knowledge graph completion method according to the present application. The knowledge graph completion method includes the following steps:

[0060] Step S201, obtain a target document, and construct a target knowledge graph of the target document through named entity recognition.

[0061] In this embodiment, a target document is obtained, and a target knowledge graph of the target document is constructed through named entity recognition. Among them, the target document can be a Chinese document of a given corpus. Entities in the target document can be recognized by an algorithm based on Bi-LSTM (Bidirectional Long Short-Term Memory) and CRF (Conditional Random Field) models, or an algorithm based on Bert (pre-trained language model); then, triples of (entity, relationship, entity) are constructed according to named entity recognition, and a target knowledge graph is constructed based on the triples, and all entity nodes and edge nodes in the target knowledge graph are obtained. For example, the target document is Di, and the target knowledge graph constructed from the target document is G. The set of all entity nodes in G is E, and the set of all edge nodes is R.

[0062] Step S202, initialize multiple search particles, as well as the initial velocity and starting node of the search particles. According to the initial velocity and the starting node, determine the path nodes of the search particles in the target knowledge graph.

[0063] In this embodiment, the search particles are moving particles, and the nodes in the target knowledge graph can be searched through the search particles. Specifically, multiple search particles are initialized. The initialization parameters of the search particles include: the maximum number of iterations T, the particle swarm size M, the initial velocity, and the initial position. The initial velocity of the search particles is a random velocity in the target knowledge graph, and the initial position is a starting node randomly selected in the target knowledge graph. Starting from this starting node and based on the initial velocity, the search particles search for nodes in the target knowledge graph, and the nodes reached by the search particles in the target knowledge graph are the path nodes.

[0064] Step S203, calculate the individual extreme value and the current global value of the search particles at the path nodes, update the path nodes of the search particles based on the individual extreme value and the current global value, and determine that the update of the search particles is completed until the update times of the search particles reach a preset maximum iteration threshold.

[0065] In this embodiment, when obtaining the initial velocity and departure node of the search particle, based on the initial velocity and departure node, the search particle can only find the next node. When the search particle conducts another search, both the velocity and position of the search particle will change. Specifically, calculate the individual extreme value and the current global value of the search particle at the passing node. When the search particle reaches each passing node, obtain all the passing nodes passed by the search particle, and calculate the number of nodes that each passing node can directly connect to, or the average semantic distance of the edges from each passing node to the nodes directly connected to the passing node; thereby, obtain the set composed of the number of all passing nodes passed by the search particle when reaching the current passing node, or the set composed of the average semantic distances of all passing nodes; select the maximum value from the set composed of the number of nodes or the set composed of the average semantic distances, and this maximum value is the individual extreme value of the search node at the current passing node. When the search particle searches the target knowledge graph, all search particles in the particle swarm size will set out simultaneously. Therefore, the global value is the individual extreme value of the maximum value in the set of current individual extreme values of all search particles in the particle swarm size.

[0066] When obtaining the individual extreme value and the current global value, update the velocity and position of the search particle based on the individual extreme value and the current global value, that is, adjust the velocity of the search particle and the node position of the search particle in the target knowledge graph until the update times of the search particle reach the preset maximum iteration times, and then stop the update.

[0067] Step S204, obtain the globally optimal solution after the update of the search particle is completed, and complete the target knowledge graph based on the globally optimal solution to obtain a completed knowledge graph.

[0068] In this embodiment, the globally optimal solution is the current global value calculated when the update times of the search particles in the particle swarm size reach the maximum iteration times. When obtaining this globally optimal solution, establish a direct edge from the departure node at the last iteration to this globally optimal solution, and the relationship is the relationship from the previous node of this globally optimal solution to this globally optimal solution. Based on this globally optimal solution and this relationship, complete the target knowledge graph to obtain a completed knowledge graph.

[0069] This application finds the optimal solution of the target knowledge graph through a particle swarm, finally obtains the missing entities, realizes the rapid completion of the target knowledge graph, and improves the completion efficiency and completion accuracy of the knowledge graph.

[0070] In some optional implementation manners of this embodiment, the step of calculating the individual extreme value and the current global value of the search particle at the passing node includes:

[0071] Obtain all the path nodes that the search particle has passed through when reaching the current path node, and calculate the average semantic distance of the edges from each of the path nodes to the directly connected nodes;

[0072] Select the maximum value among the average semantic distances as the individual extreme value of the current path node, obtain the extreme value set composed of the individual extreme values of all the search particles in the current particle swarm size, and use the maximum value in the extreme value set as the current global value.

[0073] In this embodiment, when calculating the individual extreme value of the search particle at the path node and the current global value of the search particle, obtain all the path nodes that the search particle has passed through when reaching the current path node, and calculate the average semantic distance of the edges from each path node to the directly connected nodes existing with the path node; then, select the maximum value among the average semantic distances as the individual extreme value of the search particle at the path node. For example, if there are three directly connected edge nodes for path node 1, calculate the semantic distances between these three directly connected edge nodes and the path node respectively, and then calculate the average value of these semantic distances to obtain the average semantic distance. When obtaining the individual extreme value of each search particle, obtain the extreme value set composed of the individual extreme values of all the search particles in the current particle swarm size, and use the maximum value in the extreme value set as the current global value of the search particle.

[0074] This embodiment calculates the individual extreme value and the current global value of the search particle, so that the speed and position of the search particle can be updated through the individual extreme value and the current global value, further improving the node search efficiency and accuracy of the particle in the knowledge graph.

[0075] In some optional implementation manners of this embodiment, after the step of using the maximum value in the extreme value set as the current global value, the following is further included:

[0076] Obtain the historical global value, determine whether the historical global value is greater than the current global value, and when the historical global value is greater than the current global value, replace the current global value with the historical global value.

[0077] In this embodiment, when obtaining the current global value of the search particle, obtain the historical global value, where the historical global value can be the global value of the search particle at the same moment in history, or the global optimal solution obtained in the previous round of iteration of the particle swarm size. Determine whether the historical global value is greater than the current global value, and when it is determined that the historical global value is greater than the current global value, replace the current global value with the historical global value.

[0078] In this embodiment, by obtaining the historical global value, when the historical global value is greater than the current global value, the current global value is replaced with the historical global value, further realizing the optimal acquisition of the current global value and improving the accuracy of obtaining the current global value.

[0079] In some alternative implementation manners of this embodiment, the step of updating the path node based on the individual extreme value and the current global value includes:

[0080] Obtain a preset inertia factor and learning factor, and calculate the update velocity of the search particle based on the inertia factor, the learning factor, the individual extreme value, and the current global value;

[0081] Move the search particle based on the update velocity, and determine the next node reached by the search particle as the update position of the search particle.

[0082] In this embodiment, when the individual extreme value and the current global value are obtained, the path node is updated according to the individual extreme value and the current global value. Specifically, a preset inertia factor and learning factor are obtained, and the update velocity of the search particle is calculated based on the inertia factor, the learning factor, the individual extreme value, and the current global value. The search particle is moved based on the update velocity, and the next path node reached by the search particle is determined as the update position of the search particle. The calculation formulas for the update velocity and the update position are as follows:

[0083] v i = v i + c1 × rand() × (pbest i - x i ) + c2 × rand() × (gbest i - x i )

[0084] x i = x i + v i

[0085] Among them, ω is a preset non - negative inertia factor, C1 and C2 are learning factors, usually C1 = C2 = 2. The former is a local learning factor, and the latter is a social learning factor. rand() is a random number between (0, 1), pbest i represents the individual extreme value of search particle i, gbest i represents the current global value; v i is the update velocity of the search particle, and Xi is the update position of the search particle (i.e., the next path node).

[0086] In this embodiment, by obtaining a preset inertia factor and learning factor, and calculating the updated velocity of the search particle based on the inertia factor, learning factor, personal best value, and global best value; then, moving the search particle based on the updated velocity to obtain the updated position of the search particle, the accurate calculation of the updated velocity and updated position of the search particle is realized, and the search efficiency of the particle in the target knowledge graph is improved.

[0087] In some optional implementation manners of this embodiment, before the step of moving the search particle based on the updated velocity, the method further includes:

[0088] Calculating the product of the semantic distances between the starting node and the passing nodes;

[0089] Determining whether the product of the semantic distances is greater than or equal to a preset constraint threshold, and when the product of the semantic distances is greater than or equal to the preset constraint threshold, calculating the updated velocity of the search particle.

[0090] In this embodiment, before moving the search particle based on the updated velocity, a preset constraint threshold is obtained, and the velocity of the search particle is constrained based on this preset constraint threshold. Specifically, when the updated velocity is calculated, a preset constraint threshold Ts is obtained, and the product of the semantic distances from the starting node passed by the search particle to the current passing node is calculated. Wherein, this product of the semantic distances is the continuous multiplication of the semantic distances between the starting node and the current passing node. For example, the search particle starts from the starting node, based on the randomly initial velocity of the search particle, reaches the next node 1, and this node 1 is the passing node 1; then, the updated velocity of this passing node is calculated, and based on this updated velocity, the search particle is emitted from this passing node 1, so that the search particle reaches the next passing node 2, passing node 2... passing node n. Calculate the product of the semantic distances from the starting node to the current passing node of this search particle, determine whether this product of the semantic distances is greater than or equal to the preset constraint threshold, and when this product of the semantic distances is greater than or equal to the preset constraint threshold, calculate the updated velocity of this search particle; if this product of the semantic distances is less than the preset constraint threshold, then obtain the maximum limit velocity of this search particle. After that, the velocity of this search particle will no longer be updated and will search the target knowledge graph at this maximum limit velocity; this maximum limit velocity is the number of edges of the path between the current passing node and the starting node.

[0091] In this embodiment, by calculating the product of the semantic distances between the starting node and the passing nodes and constraining the product of the semantic distances according to the preset constraint threshold, it is avoided that the velocity of the search particle is too large and nodes that are too far away in the knowledge graph are searched, and the optimal value cannot be obtained.

[0092] In some optional implementation manners of this embodiment, the step of calculating the product of the semantic distances between the starting node and the passing nodes includes:

[0093] Obtain all the path nodes between the starting node and the current path node, and calculate the sub-semantic distances from the starting node to each of the path nodes;

[0094] Multiply the sub-semantic distances to obtain the product of the semantic distances.

[0095] In this embodiment, when calculating the product of the semantic distances between the starting node and the path nodes, obtain all the path nodes between the starting node and the current path node, and calculate the sub-semantic distances from the starting node to each of the path nodes; multiply the sub-semantic distances to obtain the product of the semantic distances.

[0096] In this embodiment, by multiplying the sub-semantic distances of all the path nodes passed through, the product of the semantic distances is obtained, so that the velocity of the search particle is constrained by the product of the semantic distances and a preset constraint threshold, avoiding the result distortion caused by the too large velocity of the search particle, and further improving the accuracy of the search particle in searching for nodes.

[0097] In some alternative implementation manners of this embodiment, the step of calculating the sub-semantic distance from the starting node to each of the path nodes includes:

[0098] Obtain the first connection edge node and the second connection edge node corresponding to the starting node and each of the path nodes respectively;

[0099] Calculate the first embedding vector, the second embedding vector, the third embedding vector and the fourth embedding vector corresponding to the starting node, the path node, the first connection edge node and the second connection edge node respectively;

[0100] Calculate the first similarity based on the first embedding vector and the second embedding vector, calculate the second similarity based on the third embedding vector and the fourth embedding vector, and perform a product calculation on the first similarity and the second similarity to obtain the sub-semantic distance.

[0101] In this embodiment, when calculating the sub-semantic distances between the starting node and each passing node, the first connected edge nodes and the second connected edge nodes corresponding to the starting node and each passing node are obtained. Among them, the first connected edge nodes are the edge nodes of all the connected edges of the starting node, and the second connected edge nodes are the edge nodes of all the connected edges of the passing node. The first embedding vector, the second embedding vector, the third embedding vector, and the fourth embedding vector corresponding to the starting node, the passing node, the first connected edge node, and the second connected edge node are calculated respectively. The embedding vector can be calculated by BERT (pre-trained language model). Then, the first similarity is calculated based on the first embedding vector and the second embedding vector, the second similarity is calculated based on the third embedding vector and the fourth embedding vector, and the product of the first similarity and the second similarity is calculated to obtain the sub-semantic distance. Since there may be more than one connected edge corresponding to the starting node and the passing node respectively, each starting node and passing node may correspond to multiple first connected edge nodes and multiple second connected edge nodes respectively; when calculating the third embedding vector corresponding to the first connected edge node and the fourth embedding vector corresponding to the second connected edge node, there will be multiple third embedding vectors and multiple fourth embedding vectors. When calculating the similarity between the third embedding vectors, the third embedding vectors and the fourth embedding vectors are respectively summed to obtain the first summation result and the second summation result; based on the first summation result and the second summation result, the second similarity is calculated. The calculation formula of the sub-semantic distance is as follows:

[0102] Ds(E i ,E j )=sim(E i ,E j )×sim(∑R Ei ,∑R Ej )

[0103] Where sim(E i ,E j ) is the first similarity, E i is the first embedding vector corresponding to the starting node i, and E j is the second embedding vector corresponding to the passing node j; sim(∑R Ei ,∑R Ej ) is the second similarity, R Ei is the first summation result of the third embedding vectors corresponding to the first connected edge nodes, and R Ej is the second summation result of the fourth embedding vectors corresponding to the second connected edge nodes. The first similarity and the second similarity are the cosine similarities of vectors.

[0104] In this embodiment, by calculating the similarities between different nodes and calculating the sub-semantic distance according to the similarity, the accurate calculation of the sub-semantic distance is realized.

[0105] Those of ordinary skill in the art can understand that all or part of the processes in the methods of the above embodiments can be completed by instructing relevant hardware through computer-readable instructions. These computer-readable instructions can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above methods. Among them, the aforementioned storage medium can be a non-volatile storage medium such as a magnetic disk, an optical disk, a read-only memory (ROM), or a random access memory (RAM), etc.

[0106] It should be understood that although the steps in the flowchart of the accompanying drawings are shown in sequence according to the indication of the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless there is a clear indication in this article, the execution of these steps does not have a strict order limit, and they can be executed in other orders. Moreover, at least a part of the steps in the flowchart of the accompanying drawings may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be executed alternately or alternately with at least a part of other steps or sub-steps or stages of other steps.

[0107] Further reference Figure 3 to Figure 2 As an implementation of the method shown above, an embodiment of a knowledge graph completion device is provided in this application. This device embodiment corresponds to the method embodiment shown in Figure 2 and can be specifically applied to various electronic devices.

[0108] As shown in Figure 3 , the knowledge graph completion device 300 described in this embodiment includes: a construction module 301, an initialization module 302, an update module 303, and a completion module 304. Among them:

[0109] The construction module 301 is configured to obtain a target document and construct a target knowledge graph of the target document through named entity recognition;

[0110] In this embodiment, a target document is obtained, and a target knowledge graph of the target document is constructed through named entity recognition. Among them, the target document can be a Chinese document of a given corpus. Entities in the target document can be recognized through an algorithm based on a Bi-LSTM (Bidirectional Long Short-Term Memory) and CRF (Conditional Random Field) model, or an algorithm based on a Bert (pre-trained language model). Then, triples of (entity, relationship, entity) are constructed according to the named entity recognition, and a target knowledge graph is constructed based on the triples, and all entity nodes and edge nodes in the target knowledge graph are obtained. For example, if the target document is Di, the target knowledge graph constructed from the target document is G, the set of all entity nodes in G is E, and the set of all edge nodes is R.

[0111] An initialization module 302 is configured to initialize a plurality of search particles, as well as the initial velocity and departure node of the search particles, and determine the path nodes of the search particles in the target knowledge graph according to the initial velocity and the departure node.

[0112] In this embodiment, the search particle is a moving particle, and the nodes in the target knowledge graph can be searched through the search particle. Specifically, a plurality of search particles are initialized. The initialization parameters of the search particle include: the maximum number of iterations T, the particle swarm size M, the initial velocity, and the initial position. The initial velocity of the search particle is a random velocity in the target knowledge graph, and the initial position is a departure node randomly selected in the target knowledge graph. Starting from the departure node and based on the initial velocity, the search particle searches for nodes in the target knowledge graph, and the node reached by the search particle in the target knowledge graph is the path node.

[0113] An update module 303 is configured to calculate the individual extreme value and the current global value of the search particle at the path node, and update the path node based on the individual extreme value and the current global value until the update times of the search particle reach a preset maximum iteration threshold, and determine that the update of the search particle is completed.

[0114] In this embodiment, when obtaining the initial velocity and the departure node of the search particle, based on the initial velocity and the departure node, the search particle can only find the next node. When the search particle searches again, both the velocity and the position of the search particle will change. Specifically, calculate the individual extreme value and the current global value of the search particle at the passing node. When the search particle reaches each passing node, obtain all the passing nodes passed by the search particle, and calculate the number of nodes that each passing node can directly connect to, or the average semantic distance of the edges from each passing node to the nodes directly connected to the passing node; thereby, obtain the set composed of the number of all passing nodes passed by the search particle when reaching the current passing node, or the set composed of the average semantic distance of all passing nodes; select the maximum value from the set composed of the number of nodes or the set composed of the average semantic distance, and this maximum value is the individual extreme value of the search node at the current passing node. When the search particle searches the target knowledge graph, all the search particles in the particle swarm size will set out simultaneously. Therefore, the global value is the individual extreme value of the maximum value in the set of the current individual extreme values of all the search particles in the particle swarm size.

[0115] When obtaining the individual extreme value and the current global value, update the velocity and position of the search particle based on the individual extreme value and the current global value, that is, adjust the velocity of the search particle and the node position of the search particle in the target knowledge graph until the update times of the search particle reach the preset maximum iteration times, and then stop the update.

[0116] In some optional implementation manners of this embodiment, the update module 303 includes:

[0117] The first obtaining unit is used to obtain all the passing nodes passed by the search particle when reaching the current passing node, and calculate the average semantic distance of the edges from each passing node to the directly connected nodes;

[0118] The selection unit is used to select the maximum value in the average semantic distances as the individual extreme value of the current passing node, obtain the extreme value set composed of the individual extreme values of all the search particles in the current particle swarm size, and use the maximum value in the extreme value set as the current global value.

[0119] In this embodiment, when calculating the individual extreme value of a search particle at a path node and the current global value of the search particle, all the path nodes passed by the search particle when reaching the current path node are obtained, and the average semantic distance from each path node to the edge of the directly connected node of the path node is calculated; then, the maximum value among the average semantic distances is selected as the individual extreme value of the current search particle at the path node. For example, if there are three directly connected edge nodes for path node 1, the semantic distances between these three directly connected edge nodes and the path node are calculated respectively, and then the average value of the semantic distances is calculated to obtain the average semantic distance. When obtaining the individual extreme value of each search particle, an extreme value set composed of the individual extreme values of all search particles in the current particle swarm size is obtained, and the maximum value in the extreme value set is used as the current global value of the search particle.

[0120] In some alternative implementation manners of this embodiment, the update module 303 further includes:

[0121] The first confirmation unit is configured to obtain a historical global value, determine whether the historical global value is greater than the current global value, and when the historical global value is greater than the current global value, replace the current global value with the historical global value.

[0122] In this embodiment, when obtaining the current global value of the search particle, a historical global value is obtained, where the historical global value may be the global value of the search particle at the same moment in history, or the global optimal solution obtained in the previous iteration of the particle swarm size. It is determined whether the historical global value is greater than the current global value, and when it is determined that the historical global value is greater than the current global value, the current global value is replaced with the historical global value.

[0123] In some alternative implementation manners of this embodiment, the update module 303 further includes:

[0124] The first calculation unit is configured to obtain a preset inertia factor and learning factor, and calculate the update speed of the search particle based on the inertia factor, the learning factor, the individual extreme value, and the current global value;

[0125] The update unit is configured to move the search particle based on the update speed and determine that the next node reached by the search particle is the updated position of the search particle.

[0126] In this embodiment, when obtaining the individual extreme value and the current global value, the path nodes are updated according to the individual extreme value and the current global value. Specifically, a preset inertia factor and learning factor are obtained, and based on the inertia factor, learning factor, individual extreme value, and current global value, the update speed of the search particle is calculated. The search particle is moved based on the update speed, and the next path node reached by the search particle is determined as the update position of the search particle. The calculation formulas for the update speed and update position are as follows:

[0127] v i =v i +c1×rand()×(pbest i -x i )+c2×rand()×(gbest i -x i )

[0128] x i =x i +v i

[0129] Where ω is a preset non - negative inertia factor, C1 and C2 are learning factors, usually C1 = C2 = 2. The former is the local learning factor, and the latter is the social learning factor. rand() is a random number between (0, 1), pbest i represents the individual extreme value of the search particle i, and gbest i represents the current global value; v i is the update speed of the search particle, and Xi is the update position of the search particle (i.e., the next path node).

[0130] In some alternative implementation manners of this embodiment, the update module 303 further includes:

[0131] A second calculation unit, configured to calculate the product of the semantic distances between the departure node and the path node;

[0132] A second confirmation unit, configured to determine whether the product of the semantic distances is greater than or equal to a preset constraint threshold, and calculate the update speed of the search particle when the product of the semantic distances is greater than or equal to the preset constraint threshold.

[0133] In this embodiment, before moving the search particle based on the update speed, a preset constraint threshold is obtained, and the speed of the search particle is constrained based on the preset constraint threshold. Specifically, when the update speed is calculated, a preset constraint threshold Ts is obtained, and the product of the semantic distances from the path nodes passed by the search particle starting from the starting node to the current path node is calculated. Wherein, the product of the semantic distances is the continuous multiplication of the semantic distances between the starting node and the current path node. For example, the search particle starts from the starting node and reaches the next node 1 based on the randomly initial speed of the search particle, and this node 1 is the path node 1; then, the update speed of this path node is calculated, and a search particle is sent from this path node 1 based on this update speed, so that the search particle reaches the next path node 2, path node 2... path node n. Calculate the product of the semantic distances from the starting node to the current path node of the search particle, and determine whether the product of the semantic distances is greater than or equal to the preset constraint threshold. When the product of the semantic distances is greater than or equal to the preset constraint threshold, calculate the update speed of the search particle; if the product of the semantic distances is less than the preset constraint threshold, obtain the maximum limit speed of the search particle. After that, the speed of the search particle will no longer be updated, and the target knowledge graph will be searched at this maximum limit speed; the maximum limit speed is the number of edges on the path between the current path node and the starting node.

[0134] In some alternative implementation manners of this embodiment, the second calculation unit includes:

[0135] A third calculation unit, configured to obtain all path nodes between the starting node and the current path node, and calculate the sub-semantic distances from the starting node to each path node;

[0136] A fourth calculation unit, configured to multiply the sub-semantic distances to obtain the product of the semantic distances.

[0137] In this embodiment, when calculating the product of the semantic distances between the starting node and the path node, all path nodes between the starting node and the current path node are obtained, and the sub-semantic distances from the starting node to each path node are calculated; the sub-semantic distances are multiplied to obtain the product of the semantic distances.

[0138] In some alternative implementation manners of this embodiment, the third calculation unit includes:

[0139] A second acquisition unit, configured to acquire a first connection edge node and a second connection edge node respectively corresponding to the starting node and each path node;

[0140] A fifth calculation unit, configured to calculate first embedding vectors, second embedding vectors, third embedding vectors, and fourth embedding vectors corresponding to the starting node, the path node, the first connection edge node, and the second connection edge node respectively;

[0141] A sixth computing unit, configured to calculate a first similarity based on the first embedding vector and the second embedding vector, calculate a second similarity based on the third embedding vector and the fourth embedding vector, and perform a product calculation on the first similarity and the second similarity to obtain the sub-semantic distance.

[0142] In this embodiment, when calculating the sub-semantic distance between the departure node and each path node, the first connection edge node and the second connection edge node corresponding to the departure node and each path node are obtained. Among them, the first connection edge node is the edge node of all the connection edges of the departure node, and the second connection edge node is the edge node of all the connection edges of the path node. The first embedding vector, the second embedding vector, the third embedding vector, and the fourth embedding vector corresponding to the departure node, the path node, the first connection edge node, and the second connection edge node are calculated respectively, and the embedding vector can be calculated by bert (pre-trained language model). Then, a first similarity is calculated based on the first embedding vector and the second embedding vector, a second similarity is calculated based on the third embedding vector and the fourth embedding vector, and a product calculation is performed on the first similarity and the second similarity to obtain the sub-semantic distance. Among them, there may be more than one connection edge corresponding to the departure node and the path node respectively. Therefore, each departure node and path node may respectively correspond to multiple first connection edge nodes and multiple second connection edge nodes; when calculating the third embedding vector corresponding to the first connection edge node and the fourth embedding vector corresponding to the second connection edge node, there will be multiple third embedding vectors and multiple fourth embedding vectors. When calculating the similarity between the third embedding vectors, the third embedding vector and the fourth embedding vector are respectively summed to obtain a first summation result and a second summation result; based on the first summation result and the second summation result, the second similarity is calculated. The calculation formula of the sub-semantic distance is as follows:

[0143] Ds(E i ,E j ) = sim(E i ,E j ) × sim(∑R Ei ,∑R Ej )

[0144] Wherein, sim(E i ,E j ) is the first similarity, E i is the first embedding vector corresponding to the departure node i, and E j is the second embedding vector corresponding to the path node j; sim(∑R Ei ,∑R Ej ) is the second similarity, R Ei is the first summation result of the third embedding vector corresponding to the first connection edge node, and REj It is the second summation result of the fourth embedding vector corresponding to the second connection edge node. The first similarity and the second similarity are the cosine similarities of vectors.

[0145] The completion module 304 is used to obtain the global optimal solution after the search particle update is completed, and complete the target knowledge graph based on the global optimal solution to obtain a completed knowledge graph.

[0146] In this embodiment, the global optimal solution is the current global value calculated when the update times of the search particles in the particle swarm size reach the maximum number of iterations. When obtaining this global optimal solution, a direct edge from the starting node at the last iteration to this global optimal solution is established, and the relationship is the relationship from the previous node of this global optimal solution to this global optimal solution. Based on this global optimal solution and this relationship, the target knowledge graph is completed to obtain a completed knowledge graph.

[0147] The knowledge graph completion device proposed in this embodiment realizes the rapid completion of the target knowledge graph, and improves the completion efficiency and accuracy of the knowledge graph.

[0148] To solve the above technical problems, an embodiment of the present application also provides a computer device. Specifically, please refer to Figure 4 , Figure 4 which is the basic structural block diagram of the computer device in this embodiment.

[0149] The computer device 6 includes a memory 61, a processor 62, and a network interface 63 that are communicatively connected to each other through a system bus. It should be noted that only the computer device 6 with components 61-63 is shown in the figure, but it should be understood that it is not required to implement all the shown components, and more or fewer components can be alternatively implemented. Among them, those skilled in the art of the present technology can understand that a computer device here is a device that can automatically perform numerical calculations and / or information processing according to pre-set or stored instructions, and its hardware includes but is not limited to microprocessors, application specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), digital signal processors (DSPs), embedded devices, etc.

[0150] The computer device can be a desktop computer, a notebook, a palm computer, a cloud server and other computing devices. The computer device can perform human-computer interaction with users through means such as a keyboard, a mouse, a remote control, a touchpad or a voice control device.

[0151] The memory 61 includes at least one type of readable storage medium, which includes flash memory, hard disk, multimedia card, card-type memory (e.g., SD or DX memory, etc.), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, magnetic disk, optical disc, etc. In some embodiments, the memory 61 may be an internal storage unit of the computer device 6, such as the hard disk or memory of the computer device 6. In other embodiments, the memory 61 may also be an external storage device of the computer device 6, such as a plug-in hard disk, Smart Media Card (SMC), Secure Digital (SD) card, FlashCard, etc. equipped on the computer device 6. Of course, the memory 61 may also include both the internal storage unit and the external storage device of the computer device 6. In this embodiment, the memory 61 is generally used to store the operating system and various application software installed on the computer device 6, such as computer-readable instructions of the knowledge graph completion method. In addition, the memory 61 may also be used to temporarily store various data that have been output or will be output.

[0152] In some embodiments, the processor 62 may be a central processing unit (CPU), controller, microcontroller, microprocessor, or other data processing chip. The processor 62 is generally used to control the overall operation of the computer device 6. In this embodiment, the processor 62 is used to run the computer-readable instructions stored in the memory 61 or process data, such as running the computer-readable instructions of the knowledge graph completion method.

[0153] The network interface 63 may include a wireless network interface or a wired network interface, and the network interface 63 is generally used to establish a communication connection between the computer device 6 and other electronic devices.

[0154] The computer device proposed in this embodiment realizes the rapid completion of the target knowledge graph, improving the completion efficiency and accuracy of the knowledge graph.

[0155] The present application also provides another implementation manner, that is, to provide a computer-readable storage medium storing computer-readable instructions that can be executed by at least one processor, so that the at least one processor executes the steps of the knowledge graph completion method as described above.

[0156] The computer-readable storage medium proposed in this embodiment realizes the rapid completion of the target knowledge graph, improving the efficiency and accuracy of knowledge graph completion.

[0157] From the description of the above embodiments, those skilled in the art can clearly understand that the above-described embodiment methods can be implemented by means of software plus a necessary general hardware platform. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disc) and includes several instructions for causing a terminal device (which can be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in various embodiments of the present application.

[0158] Obviously, the above-described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. The accompanying drawings show the preferred embodiments of the present application, but do not limit the patent scope of the present application. The present application can be implemented in many different forms. On the contrary, the purpose of providing these embodiments is to make the understanding of the disclosed content of the present application more thorough and comprehensive. Although the present application has been described in detail with reference to the foregoing embodiments, for those skilled in the art, they can still modify the technical solutions described in the foregoing specific embodiments, or perform equivalent replacements on some of the technical features. Any equivalent structure directly or indirectly using the content of the specification and drawings of the present application in other related technical fields shall be within the scope of the patent protection of the present application by the same token.

Claims

1. A knowledge graph completion method, characterized in that, Including the following steps: Obtain a target document and construct a target knowledge graph of the target document through named entity recognition; Initialize multiple search particles, as well as the initial velocity and departure node of the search particles, and determine the path nodes of the search particles in the target knowledge graph according to the initial velocity and the departure node; Calculate the individual extreme value and the current global value of the search particles at the path nodes, and update the path nodes based on the individual extreme value and the current global value until the update times of the search particles reach a preset maximum iteration threshold, and determine that the update of the search particles is completed. Among them, the step of calculating the individual extreme value and the current global value of the search particles at the path nodes includes: Obtain all the path nodes that the search particle has passed through to reach the current path node, and calculate the average semantic distance of the edges from each path node to the directly connected nodes; Select the maximum value among the average semantic distances as the individual extreme value of the current path node, obtain the extreme value set composed of the individual extreme values of all the search particles in the current particle swarm size, and use the maximum value in the extreme value set as the current global value; Obtain the global optimal solution after the update of the search particles is completed, and complement the target knowledge graph based on the global optimal solution to obtain a complemented knowledge graph.

2. The knowledge graph completion method according to claim 1, wherein After the step of using the maximum value in the extreme value set as the current global value, it further includes: Obtain the historical global value, determine whether the historical global value is greater than the current global value, and when the historical global value is greater than the current global value, replace the current global value with the historical global value.

3. The knowledge graph completion method according to claim 1, wherein The step of updating the path nodes based on the individual extreme value and the current global value includes: Obtain a preset inertia factor and learning factor, and calculate the update velocity of the search particles based on the inertia factor, the learning factor, the individual extreme value, and the current global value; Move the search particles based on the update velocity, and determine the next node reached by the search particles as the updated position of the search particles.

4. The knowledge graph completion method according to claim 3, wherein Before the step of moving the search particles based on the update velocity, it further includes: Calculate the product of the semantic distances between the departure node and the path nodes; Determine whether the product of the semantic distances is greater than or equal to a preset constraint threshold, and when the product of the semantic distances is greater than or equal to the preset constraint threshold, calculate the update velocity of the search particles.

5. The method for completing a knowledge graph according to claim 4, wherein The step of calculating the product of the semantic distances between the departure node and the path nodes includes: Obtain all the path nodes between the departure node and the current path node, and calculate the sub-semantic distances from the departure node to each path node; Multiply the sub-semantic distances to obtain the product of the semantic distances.

6. The knowledge graph completion method according to claim 5, characterized in that The step of calculating the sub-semantic distances from the departure node to each path node includes: Obtain the first connected edge node and the second connected edge node corresponding to the departure node and each path node respectively; Calculate the first embedding vector, the second embedding vector, the third embedding vector, and the fourth embedding vector corresponding to the starting node, the passing node, the first connection edge node, and the second connection edge node, respectively; Calculate the first similarity based on the first embedding vector and the second embedding vector, calculate the second similarity based on the third embedding vector and the fourth embedding vector, and perform a product calculation on the first similarity and the second similarity to obtain the sub-semantic distance.

7. A knowledge graph completion device, characterized in that, The knowledge graph completion device is used to implement the steps of the knowledge graph completion method according to any one of claims 1 to 6. The knowledge graph completion device includes: A construction module, configured to obtain a target document and construct a target knowledge graph of the target document through named entity recognition; An initialization module, configured to initialize a plurality of search particles, as well as the initial velocity and the starting node of the search particles, and determine the passing nodes of the search particles in the target knowledge graph according to the initial velocity and the starting node; An update module, configured to calculate the individual extreme value and the current global value of the search particles at the passing nodes, and update the passing nodes based on the individual extreme value and the current global value until the update times of the search particles reach a preset maximum iteration threshold, and determine that the search particles are updated. completed, wherein the update module includes a first acquisition unit and a selection unit; The first acquisition unit is configured to acquire all the passing nodes that the search particles pass through when reaching the current passing node, and calculate the average value of the semantic distances of the edges from each passing node to the directly connected nodes; The selection unit is configured to select the maximum value among the average semantic distances as the individual extreme value of the current passing node, obtain an extreme value set composed of the individual extreme values of all the search particles in the current particle swarm size, and use the maximum value in the extreme value set as the current global value; A completion module, configured to obtain the global optimal solution after the search particles are updated, and complete the target knowledge graph based on the global optimal solution to obtain a completed knowledge graph.

8. A computer device, including a memory and a processor, wherein the memory stores computer-readable instructions, and when the processor executes the computer-readable instructions, the steps of the knowledge graph completion method according to any one of claims 1 to 6 are implemented.

9. A computer-readable storage medium, characterized in that, Computer-readable instructions are stored on the computer-readable storage medium, and when the computer-readable instructions are executed by a processor, the steps of the knowledge graph completion method according to any one of claims 1 to 6 are implemented.

Citation Information

Patent Citations

  • Knowledge graph optimization method and device based on particle swarm algorithm

    CN111078891A

  • Knowledge graph completion method and device, computer equipment and storage medium

    CN111814480A