Knowledge graph completion method and system based on semantic interaction matching network
By employing a semantic interaction matching network approach, and utilizing an interactive subgraph encoder and matching processor, the semantic interactions between entity neighbors are captured. This solves the problem of knowledge graph completion in small sample scenarios, achieves efficient completion in specific domains, and improves the application effect of knowledge graphs.
Patent Information
- Application Number
- CN202210605631.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-31
- Publication Date
- 2025-10-21
- Estimated Expiration
- 2042-05-31
AI Technical Summary
Existing knowledge graph completion techniques have limited performance in small sample scenarios and struggle to effectively utilize scarce training data. This is especially true in fields such as petroleum, energy, industry, medicine, and the judiciary, where knowledge graphs are incomplete and mainstream methods fail to achieve good results.
We employ a semantic interaction matching network approach, which captures semantic interactions between entity neighbors through an interactive subgraph encoder and a matching processor. We construct a support set, a query set, and a negative sample set, and optimize the parameters using a loss function to achieve knowledge graph completion.
It enhances the versatility and scalability of knowledge graph completion technology, enabling effective completion of knowledge graphs in specific domains and improving the accuracy and coverage of the completed information.
Smart Images

Figure CN115129884B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of knowledge graph completion. More specifically, the present invention relates to a knowledge graph completion method and system based on a semantic interactive matching network. Background Art
[0002] A knowledge graph is a large-scale semantic network knowledge base. As a typical form of structured data representation, it is essentially a semantic network consisting of linked entities and the relationships between them. It employs a symbolic knowledge representation approach, using [head entity, relationship, tail entity] triples to describe specific knowledge, representing and storing this knowledge in the form of a directed graph. Due to its excellent properties of representing human prior knowledge, such as rich semantics, friendly structure, and ease of understanding, knowledge graphs have recently achieved widespread and successful application in various fields, including natural language processing, intelligent question answering, recommendation systems, prediction systems, and information extraction systems.
[0003] In order to strongly support knowledge graph reasoning tasks, the widespread application and excellent results of knowledge graphs have also put forward urgent requirements for knowledge graph completion technology, especially completion technology when training data is scarce.
[0004] Due to the incompleteness of knowledge graphs, the goal of knowledge graph completion is to find missing facts. Initial research on knowledge graph completion primarily relied on knowledge graph embedding modules to embed each entity and relation into a low-dimensional vector space. This allows all entities and relations to express their semantics as a continuous vector space. The most prominent TransE and TransH models attempt to address the different roles of entities in different relations by projecting them onto hyperplanes with specific relations. TransR proposes projecting entities onto a space with specific relations rather than onto hyperplanes. Furthermore, the RESCAL model assigns a vector to each entity and a matrix to each relation, then uses a bilinear scoring function to capture the latent semantics of head-tail entity pairs. In recent years, some work has used convolutional neural networks to define scoring functions. Since knowledge graphs are also graph-structured data, recent work has also applied graph neural networks to knowledge graph embedding. However, these methods require sufficient training data. The small number of training examples is insufficient to capture the semantic meaning of these models, which can severely limit their performance in small-sample scenarios.
[0005] For many real-world scenarios, collecting and labeling data is time-consuming and labor-intensive. This also leads to incomplete information and scarce sample data in knowledge graphs in specific fields such as petroleum, energy, industry, healthcare, and justice, where high-quality labeled samples are extremely scarce for specific tasks. When dealing with such tasks, various mainstream knowledge graph completion technologies find it difficult to achieve good results. With the development of small-sample learning technology, although small-sample learning tools have made great efforts to address this challenge, they mainly focus on simply aggregating entity neighbors to represent small-sample references, while enhancing the potential semantic relevance within the neighborhood has been largely ignored. Summary of the Invention
[0006] An object of the present invention is to solve at least the above problems and to provide at least the advantages which will be described hereinafter.
[0007] Another object of the present invention is to provide a knowledge graph completion method based on a semantic interaction matching network, which enhances entity representation by capturing semantic interactions between entity neighbors, realizes the completion of knowledge graphs for small sample data, and achieves good results, greatly improving the versatility and scalability of knowledge graph completion technology, and promoting the popularization of knowledge graphs in specific fields that are currently not yet perfect.
[0008] In order to achieve these purposes and other advantages according to the present invention, a knowledge graph completion method based on a semantic interaction matching network is provided, which includes the following steps:
[0009] S1. Divide the knowledge graph dataset into training subset, validation subset and test subset;
[0010] S2. Set the initial parameters K, θ1, and θ2; K is the support set size; θ1 is the learning parameter of the interactive subgraph encoder; θ2 is the learning parameter of the interactive matching processor;
[0011] S3. Build support set, query set and negative sample set based on the dataset;
[0012] S4, converting the triplets in the support set, query set, and negative sample set into the first subgraph representation, the second subgraph representation, and the third subgraph representation respectively through the interactive subgraph encoder;
[0013] S5. Input the first subgraph representation and the second subgraph representation into the interactive matching processor to calculate a similarity score of one; input the first subgraph representation and the third subgraph representation into the interactive matching processor to calculate a similarity score of two;
[0014] S6. Introduce the loss function and calculate the loss function value L based on the test subset, similarity score 1 and similarity score 2; update the parameters θ1 and θ2 based on the training subset according to the gradient descent method; and update the parameter K based on the validation subset;
[0015] S7, repeat S3 to S6 until the training process is completed, and obtain the knowledge graph completion model;
[0016] S8. Input the knowledge graph to be completed into the knowledge graph completion model. The triple corresponding to the highest score is the completion information, and the completion information is added to the knowledge graph to be completed.
[0017] Preferably, in the method for completing the knowledge graph based on the semantic interaction matching network, step S3 is specifically as follows:
[0018] A data set is extracted from the training subset and K triplets are extracted from the data set to form a support set. The remaining triplets in the data set form a query set. For any triple in the query set, one of the tail entities that is inconsistent with the tail entity of the triple is queried in the tail entity dictionary of the data set, and the queried tail entity is replaced with the tail entity of the triple. The negative sample set is constructed using the triples after the tail entity replacement.
[0019] Preferably, in the method for completing the knowledge graph based on the semantic interaction matching network, step S4 is specifically as follows:
[0020] For any triple in the support set, find its first-order head neighbor and tail neighbor, and input them into the interactive subgraph encoder to obtain the first subgraph representation corresponding to the triple;
[0021] For any triple in the query set, find its first-order head neighbor and tail neighbor, and input them into the interactive subgraph encoder to obtain the second subgraph representation corresponding to the triple;
[0022] For any triple in the negative sample set, find its first-order head neighbor and tail neighbor, and input them into the interactive subgraph encoder to obtain the third subgraph representation corresponding to the triple.
[0023] Preferably, in the knowledge graph completion method based on semantic interaction matching network, the loss function expression in step S6 is:
[0024]
[0025] Where Q - r is the negative sample set, Q r For the query set, is the triplet of the negative sample set; is the triple of the query set; S ris the support set; r is the boundary separating the query set and the negative sample set.
[0026] The present invention also provides a knowledge graph completion system based on a semantic interactive matching network, which includes:
[0027] A data preprocessing module is used to divide the data set into training subset, validation subset and test subset;
[0028] Parameter setting module, which is used to set the initial parameters K, θ1, θ2; K is the support set size; θ1 is the learning parameter of the interactive subgraph encoder; θ2 is the learning parameter of the interactive matching processor;
[0029] The text generation module is used to construct the support set, query set and negative sample set based on the dataset;
[0030] An encoder conversion module, which is used to convert the triplets in the support set, query set and negative sample set into the first subgraph representation, the second subgraph representation and the third subgraph representation respectively through the interactive subgraph encoder;
[0031] a matching processor conversion module, configured to input the first subgraph representation and the second subgraph representation into the interactive matching processor to calculate a similarity score of one; and input the first subgraph representation and the third subgraph representation into the interactive matching processor to calculate a similarity score of two;
[0032] The parameter update module is used to introduce the loss function and calculate the loss function value L based on the test subset, similarity score 1 and similarity score 2; update the parameters θ1 and θ2 based on the training subset according to the gradient descent method; and update the parameter K based on the validation subset;
[0033] The model building module is used to train each triple until the training process is completed to obtain the knowledge graph completion model;
[0034] The testing module is used to input the knowledge graph to be completed into the knowledge graph completion model. The triple corresponding to the highest score is the completion information, and the completion information is added to the knowledge graph to be completed.
[0035] The present invention also provides an electronic device, comprising: at least one processor, and a memory communicatively connected to the at least one processor, wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor performs the above-mentioned method.
[0036] The present invention also provides a storage medium on which a computer program is stored. When the program is executed by a processor, the above method is implemented.
[0037] The present invention has at least the following beneficial effects:
[0038] 1. This invention achieves good results by introducing an interactive subgraph encoder and an interactive matching processor to complete the knowledge graph for small sample data. This technology greatly improves the versatility and scalability of knowledge graph completion technology, and promotes the popularization of knowledge graphs in specific fields where they are currently underdeveloped (including but not limited to fields such as petroleum, energy, industry, medicine, and justice, where high-quality annotated samples are extremely scarce for specific tasks);
[0039] 2. The present invention proposes a hierarchical cross-domain knowledge collaborative inference framework with good performance and differential privacy, which takes into account the interactions between entity neighbors and support sets to capture fine-grained semantic meanings, thereby better representing entity and small sample relationships; in order to make full use of the relationships on the knowledge graph, the present invention uses interaction-inspired relationship embeddings to enhance the representation of neighbors, and uses a transformer of interactive subgraph encoders and interactive subgraph matching processors to capture interactions within the community for better semantics; the present invention uses transformers (to model, taking into account the semantic interactions between neighbors that may construct representations. Since the present invention does not use position encoding, it is order-invariant to neighbor representations. Therefore, the transformer can learn how to interact with embeddings of arbitrary order instead of capturing position-related features.
[0040] Other advantages, objectives and features of the present invention will be reflected in part from the following description and will be understood by those skilled in the art through study and practice of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] Figure 1 Schematic diagram of the process of the knowledge graph completion method based on semantic interactive matching network according to the present invention;
[0042] Figure 2 Schematic diagram of the converter structure of the present invention. DETAILED DESCRIPTION
[0043] The present invention will be further described in detail below with reference to the accompanying drawings and embodiments so that those skilled in the art can implement the invention with reference to the description.
[0044] It should be understood that terms such as “having”, “including” and “comprising” used herein do not preclude the existence or addition of one or more other elements or combinations thereof.
[0045] It should be noted that the experimental methods described in the following embodiments are conventional methods unless otherwise specified, and the reagents and materials can be obtained from commercial channels unless otherwise specified.
[0046] In the description of the present invention, the terms "horizontal", "longitudinal", "up", "down", "front", "back", "left", "right", "vertical", "horizontal", "top", "bottom", "inside", "outside" and the like to indicate orientations or positional relationships are based on the orientations or positional relationships shown in the accompanying drawings and are only for the convenience of describing the present invention and simplifying the description. They do not indicate or imply that the device or element referred to must have a specific orientation, be constructed and operate in a specific orientation, and therefore should not be understood as limiting the present invention.
[0047] like Figure 1 As shown, the present invention provides a knowledge graph completion method based on a semantic interactive matching network, which includes the following steps:
[0048] S1. Divide the knowledge graph dataset (a dataset obtained by extracting and organizing knowledge graph text information downloaded from websites such as Baidu Encyclopedia or Wikipedia) into a training subset, a validation subset, and a test subset;
[0049] S2. Set the initial parameters K, θ1, and θ2; K is the support set size; θ1 is the learning parameter of the interactive subgraph encoder; θ2 is the learning parameter of the interactive matching processor;
[0050] S3. Construct support set, query set and negative sample set based on the dataset: extract a dataset from the training subset and extract K triplets from the dataset to form the support set, and the remaining triplets in the dataset form the query set; for any triple in the query set, query one of the tail entities that is inconsistent with the tail entity of the triple in the tail entity dictionary of the dataset, and replace the queried tail entity with the tail entity of the triple, and construct the negative sample set with the triple replaced by the tail entity; the specific process of negative sample construction: for a triple T in the query set, its tail entity is T t , randomly get an entity dictionary with T in the tail of the dataset t Different tail entities X t , to replace the tail entity T of T t ;
[0051] S4. Convert the triplets in the support set, query set, and negative sample set into the first subgraph representation, the second subgraph representation, and the third subgraph representation respectively through the interactive subgraph encoder:
[0052] For any triple in the support set, find its first-order head neighbor and tail neighbor, and input them into the interactive subgraph encoder to obtain the first subgraph representation corresponding to the triple;
[0053] For any triple in the query set, find its first-order head neighbor and tail neighbor, and input them into the interactive subgraph encoder to obtain the second subgraph representation corresponding to the triple;
[0054] For any triple in the negative sample set, find its first-order head neighbor and tail neighbor, and input them into the interactive subgraph encoder to obtain the third subgraph representation corresponding to the triple;
[0055] S5. Input the first subgraph representation and the second subgraph representation into the interactive matching processor to calculate a similarity score of one; input the first subgraph representation and the third subgraph representation into the interactive matching processor to calculate a similarity score of two;
[0056] S6. Introduce the loss function and calculate the loss function value L based on the test subset, similarity score 1 and similarity score 2; update the parameters θ1 and θ2 based on the training subset according to the gradient descent method; and update the parameter K based on the validation subset;
[0057] The loss function expression is:
[0058]
[0059] Where Q - r is the negative sample set, Q r For the query set, is the triplet of the negative sample set; is the triple of the query set; S r is the support set; r is the boundary separating the query set and the negative sample set;
[0060] S7, repeat S3 to S6 until the training process is completed, and obtain the knowledge graph completion model;
[0061] S8. Input the knowledge graph to be completed into the knowledge graph completion model. The triple corresponding to the highest score is the completion information, and the completion information is added to the knowledge graph to be completed.
[0062] In the above technical solution, the present invention proposes a new small sample learning scheme, namely the semantic interaction matching network, which enhances the potential semantic correlation within the neighborhood and thus obtains more comprehensive completion information. This scheme enhances entity representation by capturing the semantic interactions between entity neighbors. Specifically, the present invention divides all tasks into three subsets: training subset, validation subset and test subset. There is no overlap between these three subsets, that is, the intersection of these three sets is an empty set, which ensures that small sample relationships will not reappear in different processes.
[0063] In order to make full use of the training set, for each task T in the training subset r , the present invention starts from task T r Randomly select K triples from all triples as the support set S r , and take the triples that are not drawn as the query set Q rFor different training periods, the task T r The support set S r The selection of is a dynamic sampling process.
[0064] The interactive subgraph encoder and the interactive subgraph matching processor each include a converter, and the converter architecture is as follows: Figure 2 As shown;
[0065] This paper adopts the Query-Key-Value attention mechanism. For a set of matrices, The dot product attention can be calculated as:
[0066]
[0067] Where N is the length of the query, M is the length of the key, dk is the dimension of the key, and dv is the dimension of the value. Unlike single-head attention, multi-head attention can focus on information from different subspaces:
[0068] MultiHeadAttn(Q,K,V)=Concat(head1,...,head H )W O ,
[0069]
[0070] in, and is the projection matrix. H is the number of attention heads, d model represents the dimension of the input token embedding. In the encoder of the transformer, we set Q, K, and V to be the input embedding x, which is called self-attention.
[0071] Position-level feedforward network (FFN): consists of two linear layers and ReLU activation function:
[0072] FFN(x)=ReLU(xW1+b1)W2+b2,
[0073] Among them, W1, b1, W2, and b2 are learnable parameters.
[0074] Residual Connection and Normalization: The encoder layer of the transformer is represented as follows:
[0075] H′=LayerNorm(SelfAttention(x)+x),
[0076] H=LayerNorm(FFN(H′)+H′),
[0077] Among them, SelfAttention() represents the self-attention module; LayerNorm() represents the layer normalization operation; FFN() represents the position-level feedforward network.
[0078] The present invention designs an interactive subgraph encoder to encode entity-induced subgraphs into a vector representation; an interactive matching processor is designed to learn interactive representations between the support set and the query sample, and between the support set and the negative sample set, and further accurately calculate the similarity scores of the query sample and the negative sample set; in fact, the present invention uses a merged relational representation to adaptively encode the head and tail neighbors of a triple (the head neighbor is the triple preceding the triple, and the tail neighbor is the triple following the triple). According to this method, the transformer layer is integrated to capture the potential correlation within the neighborhood and the semantic diversity of the support set. Finally, the similarity score is estimated using the attention mechanism;
[0079] (1) The working principle of the interactive subgraph encoder is as follows:
[0080] Step 1: Denote a triplet from the support set / query set / negative sample set by e as one of the labels for its interaction with its neighbors. For a given triplet (h, r, t) of a small sample relation r, denote the first-order neighbors of the triplet e as N e ={(r e i , n e i )}, where e∈{h,t},r e i is the connection between the triplet e and its neighbor n e i Because the relationship can reflect the semantic connection between entities, the present invention will e i With neighbors e i It is concretized into the neighborhood representation hn e i , which can be expressed as:
[0081]
[0082] Among them, σ() represents the activation function, En e i 、Rn e i Neighbors n e i Connecting triplet e and its neighbor n e i The relationship e i⊕ is the concatenation operation, W1 is a learnable transformation matrix, and b1 is a learnable bias vector.
[0083] Step 2: To obtain specific task relationships, the present invention constructs an embedding of task relationships and further refines the relative relationships, which can be expressed as follows:
[0084]
[0085] Among them, E h and E t are the embeddings of the head and tail neighbors respectively, W2 and b2 are the trainable parameters of the biased linear layer. Thus, the representative of the triplet e with relative relationship is expressed as:
[0086]
[0087] Thus, the triplet e, its neighbors N e and the relationships between them are encoded into vectors.
[0088] Step 3: The present invention uses a transformer to perform modeling. The multi-head self-attention scheme allows the transformer to capture different aspects of the underlying hidden state. e and The present invention sets the first input embedding as h e , and the rest of the input embeddings are set as Since the present invention does not use position encoding, the order of neighbor representations is invariant. Therefore, the transformer can learn to interact with embeddings of arbitrary order instead of capturing position-dependent features. The hidden state of the l-th transformer layer is represented as Its subscript i∈{0,1,2,…,|N e |} represents the index of the hidden state. It can also be expressed as:
[0089] z l =Transformer(z l-1 ),
[0090]
[0091] Where l = 1, 2, ..., L, represents the number of converter layers, z 0 is the input of the first layer converter.
[0092] Step 4: Aggregate the interactive hidden states to obtain subgraph representation:
[0093]
[0094]
[0095] Among them, z' e represents the average pooling of the transformer over the last hidden state. z0 L is the last hidden state of entity e, W3 and W4 are learnable linear layer matrices, and b3 and b4 are bias vectors. e is the final representation of the subgraph.
[0096] Step 5: For a given triple (h, r, t), two subgraph representations can be obtained, namely o h and o t , corresponding to the head neighbor subgraph and the tail neighbor subgraph respectively. h With o t Combined, as a triple representation, the calculation result is:
[0097]
[0098] Where W5 is the weight matrix, b5 is the bias vector, and p represents the semantics of the small sample relation r based on a given triple.
[0099] (2) The working principle of the interactive matching processor is as follows:
[0100] The present invention applies another transformer (interactive subgraph matching processor) to capture the diverse information of query examples and support sets. In the present invention, a task T r From a query set Q r and a support set S r Composition. r An example query in For example, the detailed working steps of the interactive matching processor are as follows:
[0101] Step A: For a given query example and support set The subgraph representation p is calculated in the interactive subgraph encoder q and
[0102] Step B: Compute the hidden state c of the transformer i , i represents the index of c:
[0103] c=Transformer(c 0 ),
[0104]
[0105] Among them, c 0is the input of the transformer. Since different support examples contain different semantic meanings of few-shot relations, it is necessary to focus on the aggregate support set.
[0106] Step C: i The attention score is expressed as:
[0107]
[0108]
[0109] Among them, α i is the attention score, π() is a metric function, and the dot product is used in this model. D(c0) represents the dimension of the hidden state.
[0110] Step D: Calculate the attentional prototype of relation r:
[0111]
[0112] Step E: Estimate the similarity score of the query sample:
[0113]
[0114] Here, π() is the same as the metric function π() in step 3.
[0115] Similarly, the similarity score of the negative sample set is calculated. It is only necessary to replace the above query set with the negative sample set. The similarity score calculated in the interactive matching processor is the similarity score of the negative sample set.
[0116] The present invention also provides a knowledge graph completion system based on a semantic interactive matching network, which includes:
[0117] A data preprocessing module is used to divide the data set into training subset, validation subset and test subset;
[0118] Parameter setting module, which is used to set the initial parameters K, θ1, θ2; K is the support set size; θ1 is the learning parameter of the interactive subgraph encoder; θ2 is the learning parameter of the interactive matching processor;
[0119] The text generation module is used to construct the support set, query set and negative sample set based on the dataset;
[0120] An encoder conversion module, which is used to convert the triplets in the support set, query set and negative sample set into the first subgraph representation, the second subgraph representation and the third subgraph representation respectively through the interactive subgraph encoder;
[0121] a matching processor conversion module, configured to input the first subgraph representation and the second subgraph representation into the interactive matching processor to calculate a similarity score of one; and input the first subgraph representation and the third subgraph representation into the interactive matching processor to calculate a similarity score of two;
[0122] The parameter update module is used to introduce the loss function and calculate the loss function value L based on the test subset, similarity score 1 and similarity score 2; update the parameters θ1 and θ2 based on the training subset according to the gradient descent method; and update the parameter K based on the validation subset;
[0123] The model building module is used to train each triple until the training process is completed to obtain the knowledge graph completion model;
[0124] The testing module is used to input the knowledge graph to be completed into the knowledge graph completion model. The triple corresponding to the highest score is the completion information, and the completion information is added to the knowledge graph to be completed.
[0125] This paper cleverly applies two transformation modules (an interactive subgraph encoder and an interactive subgraph matching processor) to perform interactive subgraph encoding and interactive matching, enabling knowledge graph completion for small sample data and achieving promising results. This technology significantly enhances the versatility and scalability of knowledge graph completion, promoting the widespread adoption of knowledge graphs in specific domains where they are currently underdeveloped.
[0126] The present invention also provides an electronic device, comprising: at least one processor, and a memory communicatively connected to the at least one processor, wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor performs the above-mentioned method.
[0127] The present invention also provides a storage medium on which a computer program is stored. When the program is executed by a processor, the above method is implemented.
[0128] <Example 1>
[0129] The present invention will be further described by taking the petroleum field as an example:
[0130] Background: 1. Crude oil can be categorized by relative density into light, medium, heavy, and extra-heavy crude oil. 2. Light crude oil refers to crude oil with a relative density less than 0.870, is light in color, and contains more oil than asphaltene. 3. Heavy crude oil refers to crude oil with a relative density between 0.920 and 1.000, is dark in color, rich in colloids and asphaltene, and contains less gasoline. 4. Extra-heavy crude oil refers to crude oil with a relative density greater than 1.000.
[0131] Download the knowledge graph from (Wikipedia or Baidu Encyclopedia) and obtain (incomplete) triples: <Crude oil, classified by relative density, light crude oil, medium crude oil, heavy crude oil, extra heavy crude oil><Light crude oil, relative density, less than 0.870><Light crude oil, color, light><Light crude oil, gasoline content, high><Light crude oil, asphaltene content, low><Medium crude oil, relative density, ?><Medium crude oil, color, ?><Medium crude oil, gasoline content, ?><Medium crude oil, asphaltene content, ?><Heavy crude oil, relative density, between 0.920 and 1.000><Heavy crude oil, color, dark><Heavy crude oil, gasoline content, low><Heavy crude oil, asphaltene content, high><Extra heavy crude oil, relative density, greater than 1.000><Extra heavy crude oil, color, ?><Extra heavy crude oil, gasoline content, ?><Extra heavy crude oil, asphaltene content, ?>;
[0132] The above-mentioned triple knowledge graph data set to be completed is input into the knowledge graph completion system of the present invention, and the completion information obtained after the knowledge graph completion method of the present invention is used to complete the knowledge graph is: <extra heavy crude oil, color, very dark><extra heavy crude oil, gasoline content, little><extra heavy crude oil, asphaltene content, a lot>; compared with the prior art, the present invention can obtain additional completion information by aggregating semantic information between neighbors: <medium crude oil, relative density, between 0.870 and 0.920><medium crude oil, color, medium depth><medium crude oil, gasoline content, more><medium crude oil, asphaltene content, medium>.
[0133] The technical solution of the present invention also takes into account the semantic information between neighbors, and the obtained completion information can obtain more completion information and has a higher completion information accuracy compared with other existing knowledge graph completion solutions; this also enables the knowledge graph completion solution of the present invention to be applied to fields such as petroleum, energy, industry, medical care, and justice, where high-quality labeled samples are extremely scarce for specific tasks, and achieve good results.
[0134] The number of devices and processing scales described herein are intended to simplify the description of the present invention. Applications, modifications, and variations of the present invention will be readily apparent to those skilled in the art.
[0135] Although the embodiments of the present invention have been disclosed above, they are not limited to the applications listed in the description and implementation methods. They can be fully applied to various fields suitable for the present invention. For those familiar with the art, additional modifications can be easily implemented. Therefore, without departing from the general concept defined by the claims and the scope of equivalents, the present invention is not limited to the specific details and illustrations shown and described herein.
Claims
1. A knowledge graph completion method based on semantic interaction matching network, characterized by: The following steps are involved: S1. Divide the knowledge graph dataset into training subset, validation subset and test subset; S2. Set the initial parameters K, θ1, and θ2; K is the support set size; θ1 is the learning parameter of the interactive subgraph encoder; θ2 is the learning parameter of the interactive matching processor; S3. Construct support set, query set and negative sample set based on the knowledge graph dataset; S4, converting the triplets in the support set, query set, and negative sample set into the first subgraph representation, the second subgraph representation, and the third subgraph representation respectively through the interactive subgraph encoder; S5. Input the first subgraph representation and the second subgraph representation into the interactive matching processor to calculate a similarity score of one; input the first subgraph representation and the third subgraph representation into the interactive matching processor to calculate a similarity score of two; The interactive matching processor works as follows: Step A: For a given query set of triples =(h i , r, t i ) and support set , and calculate its subgraph representation p in the interactive subgraph encoder q and ; Step B: Compute the hidden state c of the transformer i , i represents the index of c: c = Transformer (c0) c0=[P q ,P s1 ,…,P sk ] Among them, c0 is the input terminal of the transformer; Step C: i The attention score is expressed as: Among them, α i is the attention score, π( ) is a metric function; D(c0) represents the dimension of the hidden state; Step D: Calculate the attention prototype of relation r: Step E: Estimate the similarity score of the query sample: Where π( ) is the same as the metric function π( ) in step 3; The similarity score calculated in the interactive matching processor is the similarity score of the negative sample set; S6. Introduce the loss function and calculate the loss function value L based on the test subset, similarity score 1 and similarity score 2; update the parameters θ1 and θ2 based on the training subset according to the gradient descent method; and update the parameter K based on the validation subset; S7, repeat S3 to S6 until the training process is completed, and obtain the knowledge graph completion model; S8. Input the knowledge graph to be completed into the knowledge graph completion model. The triple corresponding to the highest score is the completion information, and the completion information is added to the knowledge graph to be completed.
2. The knowledge graph completion method based on semantic interaction matching network according to claim 1, characterized in that: Step S3 is specifically as follows: A training subset dataset is extracted from the training subset and K triples are extracted from the dataset to form a support set, and the remaining triples in the dataset form a query set; For any triple in the query set, one of the tail entities that is inconsistent with the tail entity of the triple is searched in the tail entity dictionary of the dataset, and the queried tail entity is replaced with the tail entity of the triple, and the negative sample set is constructed using the triple with the replaced tail entity.
3. The knowledge graph completion method based on semantic interaction matching network according to claim 2 is characterized in that: Step S4 is specifically as follows: For any triple in the support set, find its first-order head neighbor and tail neighbor, and input them into the interactive subgraph encoder to obtain the first subgraph representation corresponding to the triple; For any triple in the query set, find its first-order head neighbor and tail neighbor, and input them into the interactive subgraph encoder to obtain the second subgraph representation corresponding to the triple; For any triple in the negative sample set, find its first-order head neighbor and tail neighbor, and input them into the interactive subgraph encoder to obtain the third subgraph representation corresponding to the triple.
4. The knowledge graph completion method based on semantic interaction matching network according to claim 3 is characterized in that: The loss function expression in step S6 is: ; Where Q - r is the negative sample set, Q r For the query set, is the triplet of the negative sample set; is the triple of the query set; S r is the support set; γ is the boundary separating the query set and the negative sample set.
5. The knowledge graph completion system based on semantic interaction matching network is characterized by: include: The data preprocessing module is used to divide the knowledge graph dataset into training subset, validation subset and test subset; Parameter setting module, which is used to set the initial parameters K, θ1, θ2; K is the support set size; θ1 is the learning parameter of the interactive subgraph encoder; θ2 is the learning parameter of the interactive matching processor; The text generation module is used to construct the support set, query set and negative sample set based on the knowledge graph dataset; An encoder conversion module, which is used to convert the triplets in the support set, query set and negative sample set into the first subgraph representation, the second subgraph representation and the third subgraph representation respectively through the interactive subgraph encoder; a matching processor conversion module, configured to input the first subgraph representation and the second subgraph representation into the interactive matching processor to calculate a similarity score of one; and input the first subgraph representation and the third subgraph representation into the interactive matching processor to calculate a similarity score of two; The interactive matching processor works as follows: Step A: For a given query set of triples =(h i , r, t i ) and support set , and calculate its subgraph representation p in the interactive subgraph encoder q and ; Step B: Compute the hidden state c of the transformer i , i represents the index of c: c = Transformer (c0) c0=[P q ,P s1 ,…,P sk ] Among them, c0 is the input terminal of the transformer; Step C: i The attention score is expressed as: Among them, α i is the attention score, π( ) is a metric function; D(c0) represents the dimension of the hidden state; Step D: Calculate the attention prototype of relation r: Step E: Estimate the similarity score of the query sample: Where π( ) is the same as the metric function π( ) in step 3; The similarity score calculated in the interactive matching processor is the similarity score of the negative sample set; The parameter update module is used to introduce the loss function and calculate the loss function value L based on the test subset, similarity score 1 and similarity score 2; update the parameters θ1 and θ2 based on the training subset according to the gradient descent method; and update the parameter K based on the validation subset; The model building module is used to train each triple until the training process is completed to obtain the knowledge graph completion model; The testing module is used to input the knowledge graph to be completed into the knowledge graph completion model. The triple corresponding to the highest score is the completion information, and the completion information is added to the knowledge graph to be completed.
6. An electronic device, characterized in that include: At least one processor, and a memory communicatively connected to the at least one processor, wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to cause the at least one processor to perform the method according to any one of claims 1 to 4.
7. A storage medium having a computer program stored thereon, characterized in that When the program is executed by a processor, the method according to any one of claims 1 to 4 is implemented.
Citation Information
Patent Citations
Middle school experiment-oriented knowledge graph dynamic knowledge completion method
CN114218398A
Knowledge graph relation prediction method based on feature extraction
CN114385831A