A method, device, electronic device and storage medium for constructing a knowledge graph
Adjusting weights through neural network training solves the problem that the knowledge graph cannot quantify relationships, realizes the accurate representation of relationships between entities and quantifies influence, and improves the query accuracy of knowledge graphs.
Patent Information
- Application Number
- CN202310106037.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-02-13
- Publication Date
- 2024-11-01
- Estimated Expiration
- 2043-02-13
AI Technical Summary
The existing knowledge graph cannot quantitatively describe the relationships between entities, resulting in the inability to accurately represent the strength of the relationship.
By obtaining the knowledge graph architecture and data sets, using neural networks for training, adjusting the weight of the connection relationship between entities until the training is completed, forming a knowledge graph with weight.
Quantitative representation of inter-entities relationships is realized, which can more accurately represent the influence between entities and improve the accuracy of querying knowledge graphs.
Smart Images

Figure CN116049443B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of knowledge graph technology, in particular to a knowledge graph construction method, device, electronic device and storage medium Background Art
[0002] Knowledge graph is a semantic network that reveals the relationship between entities and can formally describe things in the real world and their relationships. Knowledge graph is an important branch of artificial intelligence technology and plays an important role in search engine construction, natural language processing, intelligent scenario analysis and other fields. However, the existing knowledge graph description of relationships is based on semantic information and is usually not quantifiable. Summary of the invention
[0003] The embodiments of the present application provide a method, device, electronic device and storage medium for constructing a knowledge graph, which are used to solve the technical problem that the description of relationships in existing knowledge graphs cannot be quantified.
[0004] The first aspect of the present invention provides a method for constructing a knowledge graph, comprising:
[0005] Acquire a knowledge graph architecture, wherein the knowledge graph architecture represents a semantic sequence in a single direction, the knowledge graph architecture includes at least two classes, each class represents different semantics in the semantic sequence, each class includes at least one entity, and entities between adjacent classes are fully connected;
[0006] Acquire a data set, the data set covers all entities of the class, each data in the data set includes two types of entities in the class and a quantified value of the entity, and the relationship between the entities in the data is consistent with the corresponding partial semantic relationship represented in the knowledge graph architecture;
[0007] The knowledge graph architecture is used as a neural network to train the data set until the neural network training is completed; wherein, during the training process, the quantized value of each entity located in the previous layer in the input-output direction in the data is assigned to the node corresponding to the neural network, and the output of the node on the neural network corresponding to the entity located in the next layer in the input-output direction in the data is obtained according to the current neural network weight, and the weight of the connection relationship between the entities is adjusted based on the error between the output and the actual value of the entity located in the next layer in the input-output direction in the data; wherein, the current neural network is a neural network obtained after training based on the previous data;
[0008] The weight of the connection relationship between the finally trained neural network and its corresponding entities is used as the knowledge graph.
[0009] Furthermore, in the present invention, the step of obtaining the knowledge graph architecture includes:
[0010] Entities are acquired and semantically classified, and the entities are distributed according to corresponding semantic categories and sequence positions according to the semantic sequence in the single direction.
[0011] Furthermore, in the present invention, the training of the knowledge graph architecture as a neural network through the data set includes:
[0012] An initial value is assigned to the weight of each edge in the fully connected relationship; wherein the weights are random numbers and are all less than 1, and the sum of the total weights of entities in the previous layer that have a connection relationship with the same entity is 1.
[0013] Furthermore, in the present invention, the weight of the connection relationship between entities is adjusted based on the error between the output of the neural network and the actual value, including: adjusting layer by layer in a direction from back to front of the neural network.
[0014] Furthermore, in the present invention, the layer-by-layer adjustment is performed using an error function gradient descent method.
[0015] A second aspect of the present invention provides a device for constructing a knowledge graph, comprising:
[0016] A knowledge graph acquisition module, used to acquire a knowledge graph architecture, wherein the knowledge graph architecture represents a semantic sequence in a single direction, and the knowledge graph architecture includes at least two classes, each of which represents different semantics in the semantic sequence, each of which includes at least one entity, and entities between adjacent classes are fully connected;
[0017] A data set acquisition module, used to acquire a data set, the data set covers all entities of the class, each data in the data set includes two types of entities in the class and the quantified value of the entity, and the relationship between the entities in the data is consistent with the corresponding partial semantic relationship represented in the knowledge graph architecture;
[0018] A training module, used to train the knowledge graph architecture as a neural network through the data set until the neural network training is completed; wherein, during the training process, the quantized value of each entity located in the previous layer in the data in the input-output direction is assigned to the node corresponding to the neural network, and the output of the node on the neural network corresponding to the entity located in the next layer in the input-output direction in the data is obtained according to the current neural network weight, and the weight of the connection relationship between entities is adjusted based on the error between the output and the actual value of the entity located in the next layer in the input-output direction in the data; wherein the current neural network is a neural network obtained after training based on the previous data. A completion module is used to use the weight of the connection relationship between the neural network and its corresponding entities that has been finally trained as a knowledge graph;
[0019] Furthermore, in the present invention, the knowledge graph acquisition module includes:
[0020] The entity classification module is used to obtain entities and perform semantic classification on the entities, and distribute the entities according to the corresponding semantic categories and sequence positions according to the semantic sequence in the single direction.
[0021] Furthermore, in the present invention, the training module includes:
[0022] The weight initial assignment module is used to assign an initial value to the weight of each edge in the fully connected relationship; wherein the weights are random numbers and are all less than 1, and the sum of the total weights of the entities in the previous layer that have a connection relationship with the same entity is 1.
[0023] According to a third aspect of the present invention, there is provided an electronic device comprising a processor, a memory and a computer program stored in the memory, wherein the computer program is configured to execute the method described in the first aspect of the present invention when executed by the processor.
[0024] A fourth aspect of the present invention provides a storage medium having a computer program stored thereon, wherein the computer program is used to execute the method described in the first aspect of the present invention.
[0025] In an embodiment of the present application, a method for constructing a knowledge graph is adopted, by obtaining a knowledge graph architecture, the knowledge graph architecture represents a semantic sequence in a single direction, the knowledge graph architecture includes at least two classes, each of the classes represents different semantics in the semantic sequence, each of the classes includes at least one entity, and the entities between adjacent classes are fully connected; a data set is obtained, the data set covers all entities of the class, each data in the data set includes two types of entities in the class and a quantized value of the entity, and the relationship between the entities in the data is consistent with the corresponding partial semantic relationship represented in the knowledge graph architecture; the knowledge graph architecture is used as a neural network through the data set Train until the neural network training is completed; wherein, during the training process, the quantized value of each entity located in the previous layer in the input-output direction in the data is assigned to the node corresponding to the neural network, and the output of the node corresponding to the entity located in the next layer in the input-output direction in the data on the neural network is obtained according to the current neural network weight, and the weight of the connection relationship between entities is adjusted based on the error between the output and the actual value of the entity located in the next layer in the input-output direction in the data; wherein, the current neural network is a neural network obtained after training based on the previous data; the weight of the connection relationship between the neural network and its corresponding entities after the final training is used as the knowledge graph. This application solves the problem that traditional knowledge graphs cannot reflect the quantitative relationship between entities, so that more accurate queries can be performed based on weighted knowledge graphs. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] The drawings constituting a part of the present application are used to provide a further understanding of the present application. The illustrative embodiments and descriptions of the present application are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0027] Figure 1 It is a flowchart of a method for constructing a knowledge graph according to an embodiment of the present application. DETAILED DESCRIPTION
[0028] It should be noted that, in the absence of conflict, the embodiments and features in the embodiments of the present application can be combined with each other. The present application will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.
[0029] It should be noted that the steps shown in the flowcharts of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and that, although a logical order is shown in the flowcharts, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0030] In view of the fact that the existing knowledge graph cannot reflect the strength of the relationship, the embodiments of the present invention provide a method for constructing a knowledge graph, so that the strength of the connection between entities is presented in the form of weights, which can represent the influence of one entity on another entity in the connection relationship. The present invention specifically realizes the visualization of the above-mentioned weights through the training process of the neural network. The neural network has a similar structure to the knowledge graph, which has multiple layers of nodes and a connection relationship between the layers. However, in addition to the input and output layers, the hidden layer inside the neural network is a black box. When the neural network training is completed, it can be put into use. People will not pay attention to the network structure of the black box matrix in the middle and the weights between the layers. The embodiments of the present application take a different approach. Starting from the essence of neural network training, the adjustment process of the weights in the above-mentioned training process is visualized, thereby turning the black box of the neural network into a white box and obtaining a knowledge graph with weights.
[0031] Therefore, this embodiment proposes a method for constructing a knowledge graph, such as Figure 1 The figure shows a flow chart of a method for constructing a knowledge graph. Figure 1 As shown, the method for constructing a knowledge graph includes the following steps:
[0032] Step S102: obtain a knowledge graph architecture, wherein the knowledge graph architecture represents a semantic sequence in a single direction, and the knowledge graph architecture includes at least two classes, each of which represents different semantics in the semantic sequence, and each of which includes at least one entity, and entities between adjacent classes are fully connected.
[0033] The above knowledge graph architecture is the same as the fully connected neural network architecture. Entities belonging to the same category in the semantic relationship in the knowledge graph constitute one layer of the neural network, and entities of different categories constitute other layers of the neural network. The number of entities in each layer does not have to be the same. In order to reduce dependence on human experience, entities in adjacent layers constitute a fully connected relationship. Even if an entity is actually unrelated to another entity in the adjacent layer, it is still necessary to establish a connection between the two. The relationship between them can be expressed by assigning a weight of 0 to the connection relationship. If an entity is actually related to another adjacent entity, the strength of the correlation can be expressed by adjusting the size of the weight.
[0034] There are many methods for obtaining knowledge graph architecture in the prior art, including but not limited to knowledge graph search engines, knowledge graph resource libraries, etc., wherein the knowledge graph search engine can be an information extraction and retrieval system based on machine learning, which extracts knowledge from natural language texts in any field into structured data, and performs continuous aggregation and error correction, thereby providing a parsable, searchable, and traceable knowledge system, wherein the knowledge graph resource library can include named entity recognition, entity query, relationship query, knowledge classification, knowledge question and answer, and other functions.
[0035] The acquisition of the knowledge graph architecture in the embodiments of the present invention can refer to the methods in the above-mentioned prior art, but the embodiments of the present invention are mainly aimed at a knowledge graph with a single-directional semantic relationship, that is, the knowledge graph architecture has clear layers, the first layer is only related to the second layer, the second layer is further related to the third layer, and so on backward. Therefore, in some embodiments, it is preferred that the knowledge graph architecture in the embodiments of the present invention is obtained in the following manner: obtain entities and semantically classify the entities, and distribute the entities according to the corresponding semantic categories and sequence positions according to the semantic sequence in the single direction.
[0036] Step S104, obtaining a data set, wherein the data set covers all entities of the class, each data in the data set includes two types of entities in the class and the quantitative value of the entity, and the relationship between the entities in the data is consistent with the corresponding partial semantic relationship represented in the knowledge graph architecture.
[0037] The above data set is used as training data, so the data in the data set corresponds to the entities in the above knowledge graph architecture, and the semantic relationships also correspond. Data sets come from many sources, including but not limited to web pages, databases, etc. Depending on the source, each data may not be able to completely correspond one-to-one with the entities in the knowledge graph architecture, but in order to be able to play a training role, the data should at least include two types of entities in the class in the knowledge graph and the semantic relationship between them.
[0038] Step S106, training the knowledge graph architecture as a neural network through the data set until the neural network training is completed; wherein, during the training process, the quantized value of each entity located in the previous layer in the data in the input-output direction is assigned to the node corresponding to the neural network, and the output of the node on the neural network corresponding to the entity located in the next layer in the input-output direction in the data is obtained according to the current neural network weight, and the weight of the connection relationship between entities is adjusted based on the error between the output and the actual value of the entity located in the next layer in the input-output direction in the data; wherein, the current neural network is a neural network obtained after training based on the previous data.
[0039] The input and output ends of the knowledge graph are selected as the input and output ends of the neural network respectively, and the hidden layer of the neural network is between the input and output ends. In this embodiment, the layer structure of these hidden layers and the meaning of each node, that is, the entity, are apparent. On this basis, one of the data in the data set is selected each time to obtain two different types of entities and their quantized values in the data, and define these two types of entities as first-type entities and second-type entities, wherein the first-type entity is located in the first layer in the input-output direction, and the second-type entity is located in the last layer in the input-output direction. The quantized value of the first-type entity is assigned to the corresponding entity in the knowledge graph, and the calculated value of each entity in the second-type entity is obtained by propagating backward according to the input-output direction and the weight of each edge in the current knowledge graph. By comparing the quantized value of the corresponding second entity in the data, the error at the second entity can be obtained. The above error is determined by the entity with an association relationship with the second entity in front of it and the strength of the associated weight. Therefore, in order to adjust the weight, the above error can be forwarded from the second entity according to the above error and the network structure, and the weight can be optimized. The above training process is similar to a supervised neural network training process, but the data is different from the training data required for a conventional neural network. The data in the embodiments of the present invention can correspond to any two different layers in the network, and do not necessarily have to be the input layer and the output layer. In this way, each data is trained and the weight is adjusted separately for the corresponding related layer. When the distance interval between the layers is small, the weight is adjusted in a small range. When the distance interval between the layers is large, the weight is adjusted in a large range.
[0040] In the above embodiment, at the beginning of training, an initial value is assigned to the weight of each edge in the fully connected relationship; wherein the weight is a random number and is less than 1, and the sum of the total weights of the entities in the previous layer that have a connection relationship with the same entity is 1. Subsequent data repeats the same process based on the weight adjusted last time, thereby performing multiple weight adjustments, and because the data set covers all entities, the weight of each connection relationship in the knowledge network can be adjusted.
[0041] Step S108: Use the weights of the connection relationships between the neural network and its corresponding entities that have finally been trained as the knowledge graph.
[0042] Therefore, as the training process progresses, the weights of each connection relationship in the knowledge graph are gradually adjusted, and they always appear and obtain more reliable weights after the training is completed. As a result, the obtained knowledge graph is a weighted knowledge graph, which can quantify the influence of one entity on another entity for entities with direct or indirect connection relationships, and can give more objective reasoning based on this knowledge network.
[0043] In the above embodiment, the weight of the connection relationship between entities is adjusted based on the error between the output and the actual value of the entity located in the latter layer in the input-output direction in step S106, including: adjusting layer by layer in the back-to-forward direction of the neural network.
[0044] The above process is called reverse error propagation. The so-called reverse direction is opposite to the input-output direction of the neural network, that is, the error is propagated from the output to the input direction, and the error on the latter node is related to the nodes that are directly or indirectly connected to the node. Therefore, the corresponding errors of these related nodes can be inferred by reverse reasoning. The specific reverse propagation error calculation includes the following steps:
[0045] Step S1061, obtaining the error of each node in the current node of the neural network in the error propagation direction;
[0046] Step S1062, segmenting each node error along the weight ratio of the edge between the next layer node and the current node in the error propagation direction to obtain a segmentation error;
[0047] Step S1063: propagate the segmentation error to the corresponding node in the previous layer, and sum the segmentation errors obtained for the same node in the previous layer to obtain the error of the same node.
[0048] The error of each node is obtained through the above-mentioned reverse error propagation, and the weight is readjusted according to the network structure so that the error is controlled within an acceptable range.
[0049] The error vanishing adjustment process is adjusted using the error function gradient descent method. The weight adjustment on each connection relationship is calculated by the following formula:
[0050] .
[0051] Among them, E is the error function; α is the learning rate, which is used to adjust the intensity of the change to prevent overshoot; W is the weight on a certain connection relationship.
[0052] represents the slope of the error function, .
[0053] In the above error function slope formula, k is the entity in the next layer, j is the entity in the previous layer, and t k is the quantized value corresponding to the next layer entity, o k is the computational cost of the next layer of entities, the simoid() function is the S activation function, and w j,k is the weight between the entity in layer j and the entity in layer k, o jis the output value of the j-layer entity, which is the result of weighted summation of the input signal connected to the j-layer entity and referencing the S activation function.
[0054] Another embodiment of the present invention provides an electronic device, including a processor, a memory, and a computer program stored in the memory, wherein the computer program is configured to execute the knowledge graph construction method described in the aforementioned embodiment when executed by the processor.
[0055] Another embodiment of the present invention provides a storage medium having a computer program stored thereon, wherein the computer program is used to execute the method for constructing a knowledge graph in the aforementioned embodiment.
[0056] These computer programs can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, so that the instructions executed on the computer or other programmable device provide instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps of the functions specified in one or more blocks can be implemented by different modules corresponding to different steps.
[0057] For example, a knowledge graph construction device of an embodiment of the present invention, which is composed of multiple functional modules, includes:
[0058] A knowledge graph acquisition module is used to acquire a knowledge graph architecture, wherein the knowledge graph architecture represents a semantic sequence in a single direction, and the knowledge graph architecture includes at least two classes, each of which represents different semantics in the semantic sequence, and each of which includes at least one entity, and the entities between adjacent classes are fully connected.
[0059] A data set acquisition module, used to acquire a data set, the data set covers all entities of the class, each data in the data set includes two types of entities in the class and the quantified value of the entity, and the relationship between the entities in the data is consistent with the corresponding partial semantic relationship represented in the knowledge graph architecture;
[0060] A training module, used to train the knowledge graph architecture as a neural network through the data set until the neural network training is completed; wherein, during the training process, after each input amount in the data is input into the neural network, the weight of the connection relationship between entities is adjusted based on the error between the output of the neural network and the actual value;
[0061] The completion module is used to use the weights of the connection relationships between the neural network and its corresponding entities that have been finally trained as the knowledge graph.
[0062] In the above embodiment, the knowledge graph acquisition module includes:
[0063] The entity classification module is used to obtain entities and perform semantic classification on the entities, and distribute the entities according to the corresponding semantic categories and sequence positions according to the semantic sequence in the single direction.
[0064] In the above embodiment, the training module includes:
[0065] The weight initial assignment module is used to assign an initial value to the weight of each edge in the fully connected relationship; wherein the weights are random numbers and are all less than 1, and the sum of the total weights of the entities in the previous layer that have a connection relationship with the same entity is 1.
[0066] The above program can be run in the processor, or it can be stored in the memory (or computer-readable medium), which includes permanent and non-permanent, removable and non-removable media. Information storage can be achieved by any method or technology. Information can be computer-readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, read-only compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined in this article, computer-readable media does not include temporary computer-readable media (transitory media), such as modulated data signals and carrier waves.
[0067] The above are only embodiments of the present application and are not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included within the scope of the claims of the present application.
Claims
1. The method for constructing a knowledge graph is characterized by: include: Obtain a knowledge graph architecture, wherein the knowledge graph architecture represents a semantic sequence in a single direction, the knowledge graph architecture includes at least two classes, each class represents different semantics in the semantic sequence, each class includes at least one entity, and entities between adjacent classes are fully connected; wherein the knowledge graph architecture is obtained through a knowledge graph search engine, which is an information extraction and retrieval system based on machine learning, which extracts knowledge from natural language texts in any field into structured data, and performs continuous aggregation and error correction, thereby providing a parseable, searchable, and traceable knowledge system; Acquire a data set, the data set covers all entities of the class, each data in the data set includes two types of entities in the class and a quantified value of the entity, and the relationship between the entities in the data is consistent with the corresponding partial semantic relationship represented in the knowledge graph architecture; The knowledge graph architecture is used as a neural network to train the data set until the neural network training is completed; wherein, during the training process, the quantized value of each entity located in the previous layer in the input-output direction in the data is assigned to the node corresponding to the neural network, and the output of the node on the neural network corresponding to the entity located in the next layer in the input-output direction in the data is obtained according to the current neural network weight, and the weight of the connection relationship between the entities is adjusted based on the error between the output and the actual value of the entity located in the next layer in the input-output direction in the data; wherein, the current neural network is a neural network obtained after training based on the previous data; The weight of the connection relationship between the finally trained neural network and its corresponding entities is used as the knowledge graph.
2. The method according to claim 1, characterized in that The obtaining of the knowledge graph architecture includes: Entities are acquired and semantically classified, and the entities are distributed according to corresponding semantic categories and sequence positions according to the semantic sequence in the single direction.
3. The method according to claim 1, characterized in that The step of training the knowledge graph architecture as a neural network through the data set includes: An initial value is assigned to the weight of each edge in the fully connected relationship; wherein the weights are random numbers and are all less than 1, and the sum of the total weights of entities in the previous layer that have a connection relationship with the same entity is 1.
4. The method according to claim 3, characterized in that The weight of the connection relationship between entities is adjusted based on the error between the output and the actual value of the entity located in the latter layer in the input-output direction in the data, including: adjusting layer by layer in a back-to-forward direction of the neural network.
5. The method according to claim 4, characterized in that The layer-by-layer adjustment is performed using an error function gradient descent method.
6. A device for constructing a knowledge graph, characterized in that: include: A knowledge graph acquisition module is used to acquire a knowledge graph architecture, wherein the knowledge graph architecture represents a semantic sequence in a single direction, and the knowledge graph architecture includes at least two classes, each of which represents different semantics in the semantic sequence, and each of which includes at least one entity, and entities between adjacent classes are fully connected; wherein the knowledge graph architecture is obtained through a knowledge graph search engine, and the knowledge graph search engine is an information extraction and retrieval system based on machine learning, which extracts knowledge from natural language texts in any field into structured data, and performs continuous aggregation and error correction, thereby providing a parseable, searchable, and traceable knowledge system; A data set acquisition module, used to acquire a data set, the data set covers all entities of the class, each data in the data set includes two types of entities in the class and the quantified value of the entity, and the relationship between the entities in the data is consistent with the corresponding partial semantic relationship represented in the knowledge graph architecture; A training module, used to train the knowledge graph architecture as a neural network through the data set until the neural network training is completed; wherein, during the training process, the quantized value of each entity located in the previous layer in the data in the input-output direction is assigned to the node corresponding to the neural network, and the output of the node on the neural network corresponding to the entity located in the next layer in the input-output direction in the data is obtained according to the current neural network weight, and the weight of the connection relationship between entities is adjusted based on the error between the output and the actual value of the entity located in the next layer in the input-output direction in the data; wherein, the current neural network is a neural network obtained after training based on the previous data; The completion module is used to use the weights of the connection relationships between the neural network and its corresponding entities that have been finally trained as the knowledge graph.
7. The device according to claim 6, characterized in that The knowledge graph acquisition module includes: The entity classification module is used to obtain entities and perform semantic classification on the entities, and distribute the entities according to the corresponding semantic categories and sequence positions according to the semantic sequence in the single direction.
8. The device according to claim 6, characterized in that The training module comprises: The weight initial assignment module is used to assign an initial value to the weight of each edge in the fully connected relationship; wherein the weights are random numbers and are all less than 1, and the sum of the total weights of the entities in the previous layer that have a connection relationship with the same entity is 1.
9. An electronic device, characterized in that: The method comprises a processor, a memory and a computer program stored in the memory, wherein the computer program is configured to execute the method according to any one of claims 1 to 5 when executed by the processor.
10. A storage medium, characterized in that: A computer program is stored thereon, and the computer program is used to execute the method described in any one of claims 1 to 5.
