Knowledge graph-based node embedding method, electronic device, and storage medium
By selecting a set of candidate nodes in the knowledge graph, calculating semantic similarity scores, constructing an objective function, and optimizing the coordinates of the nodes to be embedded, the problem of unreasonable node positions to be embedded is solved, and the visualization effect and practicality of the knowledge graph are improved.
Patent Information
- Application Number
- CN202511368037.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-24
- Publication Date
- 2026-01-27
- Estimated Expiration
- 2045-09-24
AI Technical Summary
When constructing knowledge graphs, existing technologies often introduce new nodes that lack direct association information with existing nodes, resulting in isolated, random, or inappropriate positions. This fails to accurately reflect their potential semantic association with the existing knowledge system and lacks rationality and interpretability.
By selecting a set of candidate nodes from the initial knowledge graph, calculating the semantic similarity score between the node to be embedded and the candidate nodes, selecting a set of anchor nodes, constructing an objective function, optimizing the coordinates of the node to be embedded based on semantic similarity and geometric distance, and using a large language model and force-directed layout algorithm for node embedding.
It effectively overcomes the limitations of traditional force-directed algorithms, improves the visualization and practicality of knowledge graphs, ensures that the nodes to be embedded are positioned in a reasonable manner within the graph to reflect their potential semantic context, and avoids local node overlap and overall readability degradation.
Smart Images

Figure CN120875000B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of knowledge graph technology, and in particular to a knowledge graph-based node embedding method, electronic device, and storage medium. Background Technology
[0002] Knowledge graphs, as a type of semantic network, can clearly represent entities (such as domain terms and technical documents) and their relationships in the form of nodes and edges, providing a powerful tool for the visual management and intelligent application of domain terms. To construct and visualize knowledge graphs, existing technologies typically employ the Force-Directed Layout Method, which automatically arranges nodes in the graph by simulating the attractive and repulsive forces between particles in a physical system. This ensures that connected nodes are close together and unconnected nodes repel each other, thereby generating a visual graph in two-dimensional or three-dimensional space.
[0003] However, existing technologies have significant limitations in handling the embedding problem of a newly introduced node that lacks direct edge connections to existing documents during the initial construction phase. For traditional force-directed layout methods, when the node to be embedded lacks direct edge connections to existing nodes, its layout mainly relies on the graph's topology. The new node's position may appear isolated, random, or inappropriately placed at the graph's edge, failing to truly reflect its potential semantic connection to the existing knowledge system. This results in the embedding position of the node lacking rationality and interpretability.
[0004] Therefore, there is an urgent need for a node embedding method that can determine a coordinate in an existing two-dimensional knowledge graph that accurately reflects the semantic relationship between the node to be embedded and multiple existing nodes. Summary of the Invention
[0005] The purpose of this application is to provide a knowledge graph-based node embedding method, electronic device, and storage medium to solve the above-mentioned problems.
[0006] To achieve the above objectives, firstly, this application proposes a node embedding method based on knowledge graphs, which includes:
[0007] When a node to be embedded is received, a set of candidate nodes is selected from the initial knowledge graph;
[0008] Calculate the semantic similarity score between the node to be embedded and each candidate node in the candidate node set;
[0009] Based on the semantic similarity score, an anchor node set is selected from the candidate node set, and each anchor node in the anchor node set is sorted in descending order according to its corresponding semantic similarity score.
[0010] Based on the coordinates to be determined of the node to be embedded, the known coordinates of each anchor node, the target distance reference value and weight coefficient corresponding to each anchor node, a target function is constructed.
[0011] The objective function is solved to obtain the target value of the coordinates to be determined, and the node to be embedded is embedded into the initial knowledge graph based on the target value.
[0012] In some implementations, before constructing the objective function based on the coordinates to be determined of the node to be embedded, the known coordinates of each anchor node, the target distance reference value corresponding to each anchor node, and the weight coefficient, the following steps are further included:
[0013] Based on the arrangement order of each anchor node in the set of anchor nodes, and the arithmetic mean of the Euclidean distance between any two nodes in the initial knowledge graph, the target distance reference value corresponding to each anchor node is calculated, and the target distance reference value is positively correlated with the arrangement order;
[0014] Based on the arrangement order of each anchor node in the set of anchor nodes, the weight coefficient corresponding to each anchor node is determined, and the weight coefficient is negatively correlated with the arrangement order.
[0015] In some implementations, solving the objective function to calculate the target value of the coordinates to be determined includes:
[0016] Use the geometric center of each anchor node as a reference node;
[0017] The reference coordinates of the reference node are used as the coordinates to be determined for the node to be embedded in order to solve the objective function, and the gradient information of the objective function at the reference coordinates is calculated.
[0018] Based on the gradient information and the least squares programming algorithm, the update direction is determined;
[0019] Based on the update direction and preset step size, a reference node for iteration is determined, and the iteration coordinates of the reference node are used as the coordinates to be determined for the node to be embedded to solve the objective function, and the gradient information of the objective function at the iteration coordinates is calculated.
[0020] The step of determining the update direction based on the gradient information and the least squares programming algorithm is re-executed until the preset convergence condition is met, and the iterative coordinates of the reference node of the latest iteration are used as the target value of the coordinates to be determined.
[0021] In some implementations, selecting a set of candidate nodes from the initial knowledge graph upon receiving a node to be embedded includes:
[0022] When a node to be embedded is received, candidate nodes that meet preset thresholds are selected from the initial knowledge graph to form a candidate node set. The preset thresholds include a preset node degree threshold and / or a preset centrality threshold.
[0023] In some implementations, calculating the semantic similarity score between the node to be embedded and each candidate node in the candidate node set includes:
[0024] Based on the node to be embedded and each candidate node in the candidate node set, construct a semantic similarity calculation instruction;
[0025] The semantic similarity calculation instruction is input into a preset large language model, and the output result of the preset large language model is obtained. The output result includes the semantic similarity score between the node to be embedded and each candidate node in the candidate node set.
[0026] In some implementations, before selecting a set of candidate nodes from the initial knowledge graph upon receiving a node to be embedded, the method further includes:
[0027] Obtain a set of technical documents, identify technical terms and document entities from the technical documents, and treat the technical terms as term nodes in an undirected graph and the document entities as document nodes in an undirected graph;
[0028] Based on the inclusion relationship between the technical terms and the document entities, the edges between the corresponding term nodes and document nodes are constructed to form an initial graph structure;
[0029] The force-directed layout algorithm is used to calculate the attractive and repulsive forces between nodes in the initial graph structure, and coordinate values are calculated and assigned to each node in the initial graph structure based on the attractive and repulsive forces to form an initial knowledge graph.
[0030] In some implementations, the step of calculating the attractive and repulsive forces between nodes in the initial graph structure using a force-directed layout algorithm, and calculating and assigning coordinate values to each node in the initial graph structure based on the attractive and repulsive forces to form an initial knowledge graph, includes:
[0031] Using a force-directed layout algorithm, the attractive force between two nodes connected by edges is calculated. The attractive force between two connected nodes is positively correlated with the deviation between the current distance and the preset ideal distance between them.
[0032] The force-directed layout algorithm is used to calculate the repulsive force between any two nodes. The repulsive force is negatively correlated with the square of the current distance between the nodes.
[0033] For each node, calculate the total resultant force of the attractive and repulsive forces acting on it.
[0034] Based on the total resultant force of each node, update the coordinate values of each node, and re-execute the steps of the force-directed layout algorithm to calculate the attractive force between two nodes connected by an edge, and the repulsive force between any two nodes, until the preset iteration conditions are met to form an initial knowledge graph.
[0035] In some implementations, updating the coordinate values of each node based on the total resultant force of each node includes:
[0036] Based on the current coordinates, current iteration step size, and total resultant force of each node, the new coordinates of each node are calculated, and the coordinate values of each node are updated according to the new coordinates of each node.
[0037] Secondly, to achieve the above objectives, this application also proposes an electronic device, comprising: one or more processors; and a memory for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors perform the knowledge graph-based node embedding method as described above.
[0038] Thirdly, to achieve the above objectives, this application also proposes a computer storage medium storing executable instructions, which, when executed by a processor, cause the processor to perform the knowledge graph-based node embedding method described above.
[0039] Compared with the prior art, the beneficial effects of this application include:
[0040] Firstly, by selecting a set of candidate nodes from the initial knowledge graph and calculating the semantic similarity score between the node to be embedded and these candidate nodes, it is possible to find a reasonable position in the initial two-dimensional knowledge graph that can reflect its potential semantic context, effectively overcoming the limitations of traditional force-oriented algorithms in such scenarios.
[0041] Secondly, by selecting the set of anchor nodes based on semantic similarity scores and constructing an objective function, we can avoid the problems of local node overlap and overall readability destruction that may be caused by simply placing the nodes to be embedded based on semantic similarity scores, thereby improving the visualization effect and practicality of the knowledge graph. Attached Figure Description
[0042] To more clearly illustrate the technical solutions of the embodiments of this application, the accompanying drawings used in the embodiments will be briefly described below. It should be understood that the following drawings only show some embodiments of this application and should not be regarded as a limitation on the scope of this application.
[0043] Figure 1 This is a flowchart illustrating a knowledge graph-based node embedding method in one embodiment.
[0044] Figure 2 This is a detailed flowchart illustrating the process of calculating the semantic similarity score between the node to be embedded and each candidate node in the candidate node set in one embodiment.
[0045] Figure 3 This is a schematic diagram illustrating the embedding of a node to be embedded in an initial knowledge graph in one embodiment.
[0046] Figure 4 This is a schematic diagram of the process of constructing an initial knowledge graph in one embodiment;
[0047] Figure 5 This is a detailed flowchart illustrating the process of calculating the attractive and repulsive forces between nodes in the initial graph structure using a force-directed layout algorithm in one embodiment, and calculating and assigning coordinate values to each node in the initial graph structure based on the attractive and repulsive forces to form an initial knowledge graph.
[0048] Figure 6 This is a schematic diagram of the electronic device involved in the knowledge graph-based node embedding method in the embodiments of this application. Detailed Implementation
[0049] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0050] All terms used in this application (including technical and scientific terms) have the meanings commonly understood by those skilled in the art, unless otherwise defined. It should be noted that the terms used herein should be interpreted in a manner consistent with the context of this specification, and not in an idealized or overly rigid way.
[0051] For example, the terms "first," "second," etc., used in this application may be used herein to describe various elements, but these elements are not limited by these terms. These terms are only used to distinguish the first element from another element.
[0052] For example, the terms "comprising" or "including" used in this application indicate the presence of features, steps, operations and / or components, but do not exclude the presence or addition of one or more other features, steps, operations or components.
[0053] As mentioned above, existing technologies have significant limitations in handling the embedding problem of newly introduced nodes that lack direct association with existing documents during the initial construction phase. For traditional force-oriented layout methods, when the node to be embedded lacks direct edge connections with existing nodes, its layout mainly relies on the graph's topology. The position of the new node may appear isolated, random, or inappropriately placed at the edge of the graph, failing to truly reflect its potential semantic association with the existing knowledge system. This results in the embedding position of the node lacking rationality and interpretability.
[0054] In recent years, Large Language Models (LLMs) have made significant progress in Natural Language Understanding (NLU) and semantic representation. While LLMs can provide similarity scores or rankings between new terms and nodes in the existing knowledge graph, there is still no direct and effective method to transform this discrete, pairwise similarity information into specific coordinates within the pre-existing two-dimensional knowledge graph layout that reflect the new term's comprehensive semantic relationships. Simply placing the new term next to its most similar node may ignore relationships with other secondary similar nodes or lead to local node overlap, compromising the overall readability of the graph. Furthermore, the semantic similarity information provided by LLMs and the geometric layout of the graph represent two different modalities. Effectively integrating the former into the optimization process of the latter to achieve semantically driven node localization remains a challenging technical problem.
[0055] Therefore, there is an urgent need for a node embedding method that can determine coordinates within a constructed two-dimensional knowledge graph that accurately reflect the semantic relationship between the node to be embedded and multiple existing nodes. To this end, this application proposes a knowledge graph-based node embedding method, electronic device, and storage medium, which can realize the localization and embedding of the node to be embedded within the knowledge graph.
[0056] like Figure 1 As shown in the figure, this application provides a node embedding method based on a knowledge graph, the method including the following steps:
[0057] Step S10: Upon receiving a node to be embedded, select a set of candidate nodes from the initial knowledge graph.
[0058] In this embodiment, the node to be embedded This refers to a new term node that is about to be embedded into the initial knowledge graph, which lacks direct association information with existing nodes during the initial graph construction phase.
[0059] For example, suppose the initial knowledge graph is constructed from technical documents on food safety related to food additives, containing nodes such as "food safety standards," "food additives," and "citric acid." Now, a new term to be embedded, "canned yellow peaches," has emerged. It was not included in the knowledge graph during the initial construction phase and has no direct association with existing documents. Therefore, "canned yellow peaches" is the node to be embedded and needs to be integrated into the existing initial knowledge graph to reflect its connection with the existing knowledge system.
[0060] For example, suppose the initial knowledge graph is built based on a set of technical documents in the field of artificial intelligence, containing term nodes such as "machine learning," "deep learning," and "natural language processing." Now, a new term, "federated learning," needs to be embedded. It was not included in the knowledge graph during the initial construction phase and has no direct association with existing documents. Therefore, "federated learning" is the node to be embedded and needs to be integrated into the existing initial knowledge graph to reflect its connection with the existing knowledge system.
[0061] An initial knowledge graph refers to a graph pre-built based on a collection of technical documents, where nodes already have two-dimensional coordinates. It can reflect the relationship between technical terms and the various technical documents in the collection.
[0062] Taking the aforementioned collection of technical documents in the field of artificial intelligence as an example, this study analyzed these documents and identified technical terms (such as "neural network," "supervised learning," and "feature extraction") and document entities (such as three papers on artificial intelligence). Based on the inclusion relationships between technical terms and document entities, an undirected graph was constructed, where technical terms are term nodes and document entities are document nodes. Next, a force-directed layout algorithm was used to calculate and assign two-dimensional coordinates to each node in the graph, forming a two-dimensional visual graph. This graph can intuitively show the relationships between different terms and documents; for example, the term node "neural network" is relatively close to the first and second document nodes that contain it in the graph. This constructed graph with two-dimensional coordinates is the initial knowledge graph.
[0063] Candidate Node Set This refers to the set of all nodes in the initial knowledge graph. Selected from the data for use with the nodes to be embedded technical terms The group of nodes that perform semantic comparisons, among which, .
[0064] In one implementation, the candidate node set may include All nodes in the knowledge graph. For example, if the initial knowledge graph has 100 nodes, including term nodes and document nodes, when the node to be embedded, "Federated Learning," appears, all 100 nodes are directly selected as the candidate node set. In this way, in subsequent semantic similarity calculations, "Federated Learning" will be compared with each of these 100 nodes to determine its association with the existing knowledge system.
[0065] However, considering computational overhead, another implementation may include only nodes of specific types (e.g., only nodes of the term type). For example, if the initial knowledge graph contains 60 term nodes and 40 document nodes, when processing the node to be embedded, "Federated Learning," only the 60 term nodes are selected as the candidate node set. This is because for new terms, the semantic connections with existing terms are more important than unrelated technical documents; by comparing the technical term "Federated Learning" with the term nodes, the position of "Federated Learning" in the knowledge graph can be determined more accurately.
[0066] Furthermore, a candidate node set can be formed by selecting candidate nodes from the initial knowledge graph that meet preset node degree thresholds and / or preset centrality thresholds, based on heuristic rules. For example, if the initial knowledge graph has 100 nodes, when processing the node to be embedded, "Federated Learning," a degree threshold of 3 is set. Nodes with a degree greater than or equal to 3 are selected. Assuming 30 nodes meet the criteria, these nodes may be term nodes such as "Machine Learning," "Deep Learning," and "Feature Extraction," which have many connections with other nodes in the knowledge graph and are of high importance. Using these 30 nodes as a candidate node set allows for more efficient semantic comparison, reduces computational load, and ensures that the selected nodes have a certain degree of representativeness and importance.
[0067] Step S20: Calculate the semantic similarity score between the node to be embedded and each candidate node in the candidate node set.
[0068] Semantic similarity score refers to the degree of similarity between two term nodes in terms of concept or meaning. The value can range from 0 to 1, with a higher value indicating greater semantic similarity.
[0069] In some implementations, such as Figure 2 As shown, step S20 includes:
[0070] Step S21: Construct a semantic similarity calculation instruction based on the node to be embedded and each candidate node in the candidate node set.
[0071] Step S22: Input the semantic similarity calculation instruction into the preset large language model and obtain the output result of the preset large language model.
[0072] In this embodiment, let the candidate node be... ,in, For each selected candidate node Construct a structure containing the node to be embedded. technical terms and candidate nodes The instructions for calculating the semantic similarity of text content are provided, where the text content depends on the node type, using either the text of a term node or the title of a document node. These instructions are then submitted to a pre-defined Large Language Model (LLM) for processing. The semantic similarity calculation instructions guide the pre-defined Large Language Model to accurately evaluate the semantic similarity. and It calculates semantic similarity in a specific context and outputs a numerical score.
[0073] For example, a feasible instruction for calculating semantic similarity could be: "Please act as an expert in a certain field. You have a 'query term' and an 'existing term' (or 'document title'). Please evaluate their semantic relevance in the technical field of this query term and give a score between 0 (completely irrelevant) and 1 (highly relevant or synonymous). Query term:" Existing terms / document titles: After processing this request, LLM will output a result, which includes the semantic similarity score between the node to be embedded and each candidate node in the candidate node set. .
[0074] In some implementations, multiple candidate nodes can be used. The organization submits its work in batches to the LLM for evaluation at once. After this step, a series of semantic similarity score pairs will be obtained: .
[0075] Furthermore, based on the initial knowledge graph and the technical field to which the node to be embedded belongs, the large language model used can be trained using the corpus corresponding to that technical field to obtain a more accurate semantic similarity score.
[0076] Step S30: Based on the semantic similarity score, select the anchor node set from the candidate node set.
[0077] In this embodiment, the anchor node set refers to the set of candidate nodes. The set of nodes that are most semantically related to the node to be embedded is selected from the data, and these nodes will serve as reference points for determining the location of the node to be embedded.
[0078] Specifically, a similarity threshold can be set. All satisfied candidate nodes Once initially selected, nodes can be further filtered by combining other node attributes (such as whether the node name contains a specific pattern).
[0079] The anchor nodes in the anchor node set are sorted in descending order according to their corresponding semantic similarity scores. This means that the anchor node with the highest score is listed first, indicating that it is most similar to the target anchor node. The semantic relationship is the closest.
[0080] The final set of anchor nodes For example, there are .in, The first to Nth anchor nodes are all existing nodes with known coordinates in the initial knowledge graph.
[0081] Step S40: Based on the coordinates to be determined of the node to be embedded, the known coordinates of each anchor node, the target distance reference value and weight coefficient corresponding to each anchor node, construct the objective function.
[0082] The core objective of this embodiment is to provide the node to be embedded. The optimal target value is calculated based on the coordinates to be determined. This target value should make the node to be embedded... The geometric distance relationship between the selected N anchor nodes on the two-dimensional plane best reflects the semantic similarity-based ranking relationship given by LLM.
[0083] Therefore, this application defines an objective function through step S40. This function aims to quantify and minimize the difference between the actual Euclidean distance from the node to be embedded to each anchor node and a target distance reference value determined based on the similarity score ranking of each anchor node.
[0084] Let the coordinates of the node to be embedded be... , Anchor node is , refers to the j-th anchor node, whose corresponding coordinates are The actual Euclidean distance from the node to be embedded to each anchor node is: .
[0085] objective function The core idea is: if the anchor point In In the semantic similarity ranking (from high to low), it ranks as the [number]. (i.e., its ranking is) ,in ),So arrive Euclidean distance It should be done as much as possible The Euclidean distances to each anchor point are sorted in ascending order and are in the first position. Bit. Objective function The definition is shown in the calculation formula (1):
[0086] (1)
[0087] in, These are the coordinates of the node to be embedded. It is the first Anchor nodes (according to) After sorting the semantic similarity from high to low, the ranking is as follows: The known two-dimensional coordinates of ). The coordinates of the node to be embedded are yet to be determined. Coordinates of anchor node The Euclidean distance between them. It is with anchor node The target distance reference value is related to the arrangement order in the set of anchor nodes, and the target distance reference value is positively correlated with the arrangement order.
[0088] For the ranking is For anchor point nodes, the target distance reference value can be taken as... . It is the arithmetic mean of the Euclidean distances between any two nodes in the initial knowledge graph. This means that the optimization process will attempt to make... To the most similar anchor node The distance approaches to the second similar anchor point The distance approaches And so on. This is a simplified goal aimed at maintaining consistency between distance ranking and LLM similarity order.
[0089] Is assigned to the first The weight coefficients of the constraint terms for each anchor node, wherein the weight coefficients are negatively correlated with the arrangement order, are used to adjust the contribution of different anchor nodes to the overall objective function. One feasible method for determining these weight coefficients is... This means that the higher the ranking (i.e., the better), the better. The more semantically similar the anchor points, the greater the influence of the distance constraint term in the objective function. Another feasible approach is to use semantic similarity scores. The absolute size or its normalized proportion in the similarity scores of all anchor nodes is set.
[0090] In addition, when constructing the objective function, a repulsion term can be introduced between the node to be embedded and all or some of the candidate nodes in the candidate node set, so as to avoid excessive overlap between the node to be embedded and the existing nodes after embedding, and further improve the aesthetics of the layout.
[0091] Step S50: Solve the objective function to obtain the target value of the coordinates to be determined, and embed the node to be embedded into the initial knowledge graph based on the target value.
[0092] In some implementations, in order to find the objective function The optimal target coordinate value is the minimum value. The geometric center of each anchor node can be used as a reference node, and the reference coordinates of the reference node can be used as the coordinates to be determined for the node to be embedded. The objective function is then solved, and the gradient information of the objective function at the reference coordinates is calculated. Based on the gradient information and the least squares programming algorithm, the update direction is determined. Based on the update direction and a preset step size, an iterative reference node is determined, and the iterative coordinates of the iterative reference node are used as the coordinates to be determined for the node to be embedded. The objective function is then solved, and the gradient information of the objective function at the iterative coordinates is calculated. Next, it is determined whether a preset convergence condition is met. If not, the step of determining the update direction based on the gradient information and the least squares programming algorithm is re-executed. If yes, the iterative coordinates of the latest determined iterative reference node are used as the target value of the coordinates to be determined.
[0093] When visualizing a knowledge graph, the nodes to be embedded It will appear in a carefully calculated position based on its semantic similarity ranking with multiple anchor nodes. Although the node to be embedded may not have direct structured edges connecting it to other nodes in the initial knowledge graph, its relative position in the two-dimensional plane itself contains rich semantic association information with its surrounding nodes (derived from LLM similarity scores), thereby enhancing the expressiveness and interpretability of the graph. Figure 3 As shown, the "canned yellow peaches" marked in red is the node to be embedded.
[0094] The knowledge graph-based node embedding method proposed in this application has two main aspects. First, by selecting a set of candidate nodes from the initial knowledge graph and calculating the semantic similarity score between the node to be embedded and these candidate nodes, a reasonable position reflecting its potential semantic context can be found in the initial two-dimensional knowledge graph, effectively overcoming the limitations of traditional force-directed algorithms in such scenarios. Second, by selecting a set of anchor nodes based on semantic similarity scores and constructing an objective function, the method avoids the problems of local node overlap and overall readability destruction that may result from simply placing the node to be embedded based on semantic similarity scores, thereby improving the visualization effect and practicality of the knowledge graph.
[0095] In one embodiment, such as Figure 4 As shown, prior to step S10, the following steps are included:
[0096] Step S01: Obtain a set of technical documents, identify technical terms and document entities from the set of technical documents, and treat the technical terms as term nodes in an undirected graph and the document entities as document nodes in an undirected graph.
[0097] In this embodiment, the technical document set refers to a group of technical documents used to construct the knowledge graph. These documents contain technical content and terminology specific to a particular field. Technical terms refer to words or phrases that appear in the technical documents and have specific technical meanings. Document entities refer to the technical documents themselves, serving as document nodes in the knowledge graph to represent the existence and attributes of the documents.
[0098] Let the collection of technical documents be , ,in, This is the first technical document up to the [number]th [page number]. This technical document This represents the total number of technical documents. Let the set of technical terms identified from the collection of technical documents be denoted as . , ,in, For the first technical term to the A technical term, It is the total number of technical terms.
[0099] Construct an undirected graph by treating technical terms as term nodes and document entities as document nodes. , It is the set of all nodes. It is a set of edges.
[0100] Each technical term A term node corresponding to a term in the diagram is represented as ,in, Every technical document A document node in the corresponding diagram is represented as ,in, The complete node set contains all term nodes and document nodes, represented as... .
[0101] Step S02: Based on the inclusion relationship between the technical terms and the document entities, construct the edges between the corresponding term nodes and document nodes to form an initial graph structure.
[0102] If a technical term Appears in technical documents In the middle, then in the term node and document nodes Add an edge between them. That is... .
[0103] Step S03: Using a force-directed layout algorithm, calculate the attractive and repulsive forces between nodes in the initial graph structure, and calculate and assign coordinate values to each node in the initial graph structure based on the attractive and repulsive forces to form an initial knowledge graph.
[0104] In this embodiment, the purpose of step S03 is to calculate and assign a coordinate value to each node in the undirected graph G.
[0105] Specifically, such as Figure 5 As shown, step S03 includes:
[0106] Step S031: Calculate the attraction between two nodes connected by an edge using the force-directed layout algorithm.
[0107] In this embodiment, attraction It only applies to edges Two directly connected nodes and Between them, attraction will attempt to pull these two connected nodes toward a predetermined ideal distance. The attraction between two connected nodes, and the current distance between the two connected nodes. Distance from ideal The deviations are positively correlated. For example, attractiveness can be expressed as... ,in, It is the attraction strength coefficient. This represents the current distance between two connected nodes. For the ideal distance, For nodes coordinates, For nodes The coordinate values.
[0108] Step S032: Calculate the repulsive force between any two nodes using the force-directed layout algorithm.
[0109] Repulsive force It acts on any two distinct nodes in the graph. and The repulsive force is between nodes (regardless of whether they are directly connected). This force attempts to push all nodes apart to prevent node overlap and to unfold the graph structure. The repulsive force is negatively correlated with the square of the current distance between nodes. For example, the repulsive force can be expressed as... ,in, It is the repulsive force strength coefficient.
[0110] Step S033: Calculate the total resultant force of each node for the attractive and repulsive forces acting on it.
[0111] This implementation adjusts the node positions through an iterative process. In each iteration... In the graph, for each node Its location The update depends on its current position. The total resultant force at that time Specifically, as shown in calculation formula (2):
[0112] (2)
[0113] in, Represents a node The set of all connected nodes.
[0114] Step S034: Update the coordinate values of each node based on the total resultant force of each node.
[0115] Specifically, based on the current coordinates of each node Current iteration step size Total synergy The new coordinates of each node are calculated. And update the coordinate values of each node according to the new coordinates of each node, as shown in the calculation formula (3):
[0116] (3)
[0117] in, This is the step size of the current iteration. This value usually decreases gradually as the number of iterations increases to help the system converge stably.
[0118] Step S035: Determine whether the preset iteration conditions are met.
[0119] The preset iteration conditions can be a preset maximum number of iterations, or the total energy change of the nodes in the graph being less than a certain threshold, or the movement of the node position being less than a certain threshold.
[0120] If the preset iteration conditions are not met, then steps S031 and S032 are re-executed.
[0121] If the preset iteration conditions are met, the iteration is terminated and step S036 is executed.
[0122] Step S036: Form the initial knowledge graph.
[0123] The final output of step S036 is the set of two-dimensional coordinates of all nodes in the initial knowledge graph G. ,in, For nodes The corresponding two-dimensional coordinates. This graph structure information and node position information will be saved.
[0124] In the knowledge graph-based node embedding method proposed in this application, a force-directed layout algorithm is applied to the constructed initial graph structure. Connected term nodes and document nodes gradually move closer under the influence of attraction, while unconnected nodes move away from each other under the influence of repulsion. After multiple iterations, the positions are continuously adjusted based on the calculation of attraction and repulsion, and each node gradually stabilizes in a suitable position, forming a two-dimensional initial knowledge graph that can intuitively reflect the relationship between terms and documents.
[0125] In one embodiment, a computer storage medium is provided that stores executable instructions that, when executed by a processor, cause the processor to perform the steps in the above method embodiments.
[0126] In one embodiment, an electronic device is also provided, including one or more processors; and a memory storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors perform the steps in the above method embodiments.
[0127] In one embodiment, such as Figure 6The diagram illustrates the structure of an electronic device used to implement an embodiment of this application. The electronic device 100 includes a central processing unit (CPU) 101, which can perform various appropriate actions and processes based on a program stored in a read-only memory (ROM) 102 or a program loaded from a storage portion 108 into a random access memory (RAM) 103. The RAM 103 also stores various programs and data required for the operation of the electronic device 100. The CPU 101, ROM 102, and RAM 103 are interconnected via a bus 104. An input / output (I / O) interface 105 is also connected to the bus 104.
[0128] The following components are connected to I / O interface 105: an input section 106 including a keyboard, mouse, etc.; an output section 107 including a cathode ray tube (CRT), liquid crystal display (LCD), etc., and speakers, etc.; a storage section 108 including a hard disk, etc.; and a communication section 109 including a network interface card such as a LAN card, modem, etc. The communication section 109 performs communication processing via a network such as the Internet. A drive 110 is also connected to I / O interface 105 as needed. A removable medium 111, such as a disk, optical disk, magneto-optical disk, semiconductor memory, etc., is installed on drive 110 as needed so that computer programs read from it can be installed into storage section 108 as needed.
[0129] Specifically, according to embodiments of this application, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments of this application include a computer program product comprising a computer-readable medium carrying instructions that, in such embodiments, can be downloaded and installed from a network via communication section 109, and / or installed from removable medium 111. When the instructions are executed by central processing unit (CPU) 101, the various method steps described in this application are performed.
[0130] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features therein. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of this application.
[0131] Furthermore, those skilled in the art will understand that although some embodiments herein include certain features included in other embodiments but not others, combinations of features from different embodiments are intended to be within the scope of this application and form different embodiments. The information disclosed in this background section is intended only to enhance the understanding of the general background of this application and should not be construed as an admission or in any way implying that such information constitutes prior art known to those skilled in the art.
Claims
1. A node embedding method based on knowledge graphs, characterized in that, The method includes: When a node to be embedded is received, a set of candidate nodes is selected from the initial knowledge graph, which refers to a graph pre-constructed based on a set of technical documents to reflect the relationship between technical terms and various technical documents in the set of technical documents; Calculate the semantic similarity score between the node to be embedded and each candidate node in the candidate node set; Based on the semantic similarity score, an anchor node set is selected from the candidate node set, and each anchor node in the anchor node set is sorted in descending order according to its corresponding semantic similarity score. Based on the coordinates to be determined of the node to be embedded, the known coordinates of each anchor node, the target distance reference value and weight coefficient corresponding to each anchor node, a target function is constructed. Using the geometric center of each anchor node as a reference node, and the reference coordinates of the reference node as the coordinates to be determined for the node to be embedded, the objective function is solved, and the gradient information of the objective function at the reference coordinates is calculated. Based on the gradient information and the least squares programming algorithm, the update direction is determined. Based on the update direction and a preset step size, the iterative reference node is determined, and the iterative coordinates of the iterative reference node are used as the coordinates to be determined for the node to be embedded, to solve the objective function, and the gradient information of the objective function at the iterative coordinates is calculated. The step of determining the update direction based on the gradient information and the least squares programming algorithm is repeated until a preset convergence condition is met. The iterative coordinates of the latest determined iterative reference node are used as the target value of the coordinates to be determined, and the node to be embedded is embedded into the initial knowledge graph based on the target value.
2. The knowledge graph-based node embedding method according to claim 1, characterized in that, Before constructing the objective function based on the coordinates to be determined of the node to be embedded, the known coordinates of each anchor node, the target distance reference value corresponding to each anchor node, and the weight coefficient, the following is also included: Based on the arrangement order of each anchor node in the set of anchor nodes, and the arithmetic mean of the Euclidean distance between any two nodes in the initial knowledge graph, the target distance reference value corresponding to each anchor node is calculated, and the target distance reference value is positively correlated with the arrangement order; Based on the arrangement order of each anchor node in the set of anchor nodes, the weight coefficient corresponding to each anchor node is determined, and the weight coefficient is negatively correlated with the arrangement order.
3. The knowledge graph-based node embedding method according to claim 1, characterized in that, The step of selecting a candidate node set from the initial knowledge graph upon receiving a node to be embedded includes: When a node to be embedded is received, candidate nodes that meet preset thresholds are selected from the initial knowledge graph to form a candidate node set. The preset thresholds include a preset node degree threshold and / or a preset centrality threshold.
4. The knowledge graph-based node embedding method according to claim 1, characterized in that, The calculation of the semantic similarity score between the node to be embedded and each candidate node in the candidate node set includes: Based on the node to be embedded and each candidate node in the candidate node set, construct a semantic similarity calculation instruction; The semantic similarity calculation instruction is input into a preset large language model, and the output result of the preset large language model is obtained. The output result includes the semantic similarity score between the node to be embedded and each candidate node in the candidate node set.
5. The knowledge graph-based node embedding method according to claim 1, characterized in that, Before selecting a candidate node set from the initial knowledge graph upon receiving a node to be embedded, the method further includes: Obtain a set of technical documents, identify technical terms and document entities from the technical documents, and treat the technical terms as term nodes in an undirected graph and the document entities as document nodes in an undirected graph; Based on the inclusion relationship between the technical terms and the document entities, the edges between the corresponding term nodes and document nodes are constructed to form an initial graph structure; The force-directed layout algorithm is used to calculate the attractive and repulsive forces between nodes in the initial graph structure, and coordinate values are calculated and assigned to each node in the initial graph structure based on the attractive and repulsive forces to form an initial knowledge graph.
6. The knowledge graph-based node embedding method according to claim 5, characterized in that, The process involves using a force-directed layout algorithm to calculate the attractive and repulsive forces between nodes in the initial graph structure, and then calculating and assigning coordinate values to each node based on these forces to form an initial knowledge graph. This includes: Using a force-directed layout algorithm, the attractive force between two nodes connected by edges is calculated. The attractive force between two connected nodes is positively correlated with the deviation between the current distance and the preset ideal distance between them. The force-directed layout algorithm is used to calculate the repulsive force between any two nodes. The repulsive force is negatively correlated with the square of the current distance between the nodes. For each node, calculate the total resultant force of the attractive and repulsive forces acting on it. Based on the total resultant force of each node, update the coordinate values of each node, and re-execute the steps of the force-directed layout algorithm to calculate the attractive force between two nodes connected by an edge, and the repulsive force between any two nodes, until the preset iteration conditions are met to form an initial knowledge graph.
7. The knowledge graph-based node embedding method according to claim 6, characterized in that, The process of updating the coordinate values of each node based on the total resultant force of each node includes: Based on the current coordinates, current iteration step size, and total resultant force of each node, the new coordinates of each node are calculated, and the coordinate values of each node are updated according to the new coordinates of each node.
8. An electronic device, characterized in that, include: One or more processors; Memory, used to store one or more programs. When the one or more programs are executed by the one or more processors, the one or more processors perform the knowledge graph-based node embedding method as described in any one of claims 1 to 7.
9. A computer storage medium, characterized in that, The storage medium stores executable instructions, which, when executed by a processor, cause the processor to perform the knowledge graph-based node embedding method as described in any one of claims 1 to 7.
Citation Information
Patent Citations
Document retrieval method based on knowledge graph and related equipment thereof
CN114780746A
Graph embedding training method, apparatus and device, and readable storage medium
CN117332122A