Semantic-driven-based few-sample knowledge graph completion method and semantic-driven-based few-sample knowledge graph completion system

By using semantic-driven methods to perform neighborhood semantic coding and negative sampling of entities in the knowledge graph completion method, the problem of insufficient model representation ability in the prior art is solved, and the effect of knowledge graph completion in few samples is significantly improved.

CN120146162APending Publication Date: 2025-06-13SOUTH CHINA NORMAL UNIV +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510116454.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-01-24
Publication Date
2025-06-13

AI Technical Summary

Technical Problem

The existing method of knowledge graph completion in the small sample has insufficient ability to represent entities and background relationships in the knowledge graph, resulting in poor completion results.

Method used

A semantic-driven method is adopted to perform neighborhood semantic coding on entities in the complete knowledge graph, and high-quality negative samples are generated through policy negative sampling to improve the distinguishing ability of the model.

Benefits of technology

By enhancing the model's ability to represent entities and background relationships, the effect of completing knowledge graphs with few samples is significantly improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120146162A_ABST
    Figure CN120146162A_ABST
Patent Text Reader

Abstract

The invention discloses a few-sample knowledge graph completion method and system based on semantic driving, and a knowledge graph completion model provided by the method is obtained through the training of the following steps: obtaining a task relationship, and a background triple, a graph entity and a background relationship in a background knowledge graph; according to the background triad and the background relationship, performing neighborhood semantic coding on the map entity to obtain a first embedded representation; performing relation coding on the task relation according to the first embedding representation to obtain a second embedding representation; according to the task relation, strategy negative sampling is carried out on the background triad, and a negative sampling triad is obtained; and according to the second embedded representation, the background triad and the negative sampling triad, performing parameter updating on the initialized knowledge graph completion model to obtain a trained knowledge graph completion model. The method can effectively improve the effect of few-sample knowledge graph completion. The invention relates to the technical field of knowledge graph completion.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of knowledge graph completion, and in particular to a few-shot knowledge graph completion method and system based on semantic drive. Background Art

[0002] Knowledge Graphs (KGs) store entities and their relationships in a structured form, providing a basis for fields such as semantic understanding and information retrieval. Due to the incompleteness of knowledge graphs, it may affect their performance in knowledge-intensive applications such as question answering and recommendation systems. Therefore, few-shot knowledge graph completion (FKGC), which enhances the completeness of knowledge graphs by inferring missing facts, has become one of the key technical contents of concern.

[0003] Currently, existing few-shot knowledge graph completion methods usually use techniques such as transfer learning and meta-learning to complete incomplete knowledge graphs. However, since these methods often only focus on the structural information in the knowledge graph to be completed, the model has poor representation ability for entities and background relationships in the knowledge graph, and the effect of few-shot knowledge graph completion is not satisfactory.

[0004] Therefore, the problems existing in the prior art still need to be solved and optimized urgently. Summary of the Invention

[0005] An object of the present invention is to solve at least to some extent one of the technical problems existing in the related art.

[0006] To this end, an object of an embodiment of the present invention is to provide a few-shot knowledge graph completion method and system based on semantic drive, wherein the method can effectively improve the effect of few-shot knowledge graph completion.

[0007] To achieve the above technical object, the technical solutions adopted in the embodiments of the present application include:

[0008] In a first aspect, an embodiment of the present application provides a few-shot knowledge graph completion method based on semantic drive, including:

[0009] Obtain a knowledge graph to be completed;

[0010] Input the knowledge graph to be completed into a trained knowledge graph completion model for knowledge graph completion to obtain a target knowledge graph;

[0011] The trained knowledge graph completion model is obtained through the following steps:

[0012] Obtain task relationships, as well as background triples, several graph entities, and background relationships in the background knowledge graph;

[0013] According to the background triples and the background relationships, perform neighborhood semantic encoding on all the graph entities to obtain a number of first embedding representations, where each first embedding representation is used to characterize the embedding representation of the target entity and the background relationship, and the target entity is any one of the graph entities;

[0014] According to all the first embedding representations, perform relationship encoding on the task relationship to obtain a number of second embedding representations, where each second embedding representation is used to characterize a first embedding representation aligned with the task relationship;

[0015] According to the task relationship, perform policy negative sampling on the background triples to obtain negative sampling triples;

[0016] According to all the second embedding representations, the background triples, and the negative sampling triples, update the parameters of the initialized knowledge graph completion model to obtain the trained knowledge graph completion model.

[0017] In addition, according to the method of the above embodiments of the present application, the following additional technical features may also be provided:

[0018] Further, in an embodiment of the present application, performing neighborhood semantic encoding on all the target entities according to the background triples and the background relationships to obtain a number of first embedding representations includes:

[0019] According to all the target entities, perform neighborhood screening and text generation on the background triples to obtain the text semantic description of each target entity, where the text semantic description is used to characterize the semantic information of the neighborhood entities and the semantic information of the target entity, and the neighborhood entities are the graph entities connected to the target entity in the background knowledge graph;

[0020] According to all the text semantic descriptions and the background triples, perform semantic encoding on the background relationships to obtain a number of the first embedding representations.

[0021] Further, in an embodiment of the present application, performing neighborhood screening and text generation on the background triples according to the target entity to obtain the text semantic description includes:

[0022] According to the target entity, perform entity neighborhood screening on the background triples to obtain a graph neighborhood set, where the graph neighborhood set includes a number of the neighborhood entities;

[0023] According to all the neighborhood entities, construct a prompt for the target entity to obtain an entity text prompt;

[0024] Input the entity text prompt into a pre-trained language model for text generation to obtain the text semantic description.

[0025] Further, in an embodiment of the present application, the entity neighborhood screening of the background triple according to the target entity to obtain a graph neighborhood set includes:

[0026] Obtain a first entity, the entity type of the first entity, and a first type weight, where the first entity is a graph entity other than the target entity in the background triple of the background knowledge graph, and the first type weight is the current type weight of the entity type;

[0027] Update the weight of the first type weight according to the entity type to obtain a second type weight, and the second type weight is less than the first type weight;

[0028] Calculate the entity similarity between the target entity and the first entity according to the second type weight to obtain an entity similarity score;

[0029] If there is at least one graph entity in the background knowledge graph that has not been calculated for entity similarity with the target entity, retain the entity similarity score, update the first entity according to the background knowledge graph, and then return to execute the step of obtaining the first entity, the entity type of the first entity, and the first type weight; or, if there is no graph entity in the background knowledge graph that has not been calculated for entity similarity with the target entity, screen the graph entities in the background knowledge graph according to all the entity similarity scores to obtain the graph neighborhood set.

[0030] Further, in an embodiment of the present application, encoding the task relationship according to the first embedding representation to obtain a second embedding representation includes:

[0031] Obtain a third embedding representation of the task relationship, as well as a target entity representation, an association relationship representation, and a neighborhood entity representation of the first embedding representation;

[0032] Perform neighborhood attention calculation on the third embedding representation according to the association relationship representation and the neighborhood entity representation to obtain a neighborhood attention score;

[0033] Aggregate neighborhood information for the target entity representation according to the neighborhood attention score, the association relationship representation, and the neighborhood entity representation to obtain an updated target entity representation;

[0034] Perform information dynamic aggregation on the third embedding representation according to the updated target entity representation to obtain the second embedding representation.

[0035] Further, in an embodiment of the present application, calculating a neighborhood attention score for the third embedding representation according to the association relationship representation and the neighborhood entity representation includes:

[0036] Constructing an attention value vector for the association relationship representation according to the neighborhood entity representation to obtain a neighborhood value vector;

[0037] Constructing an attention key vector for the association relationship representation according to the neighborhood value vector to obtain a relationship key vector;

[0038] Calculating a relationship weight for the third embedding representation according to the relationship key vector;

[0039] Calculating an attention score for the third embedding representation and the relationship key vector according to the relationship weight to obtain the neighborhood attention score.

[0040] Further, in an embodiment of the present application, performing policy negative sampling on the background triple according to the task relationship to obtain a negative sampling triple includes:

[0041] Obtaining a preset sampling policy set;

[0042] Performing policy matching on the task relationship according to the sampling policy set to obtain a target negative sampling policy corresponding to the task relationship, where the target negative sampling policy is a type negative sampling policy or a semantic negative sampling policy;

[0043] If the target negative sampling policy is a type negative sampling policy, obtaining the tail entity type information in the background triple, and updating the tail entity in the background triple according to the tail entity type information to obtain the negative sampling triple; or, if the target negative sampling policy is a semantic negative sampling policy, obtaining a plurality of candidate entities, and updating the semantic similarity of the tail entity in the background triple according to all the candidate entities to obtain the negative sampling triple.

[0044] Further, in an embodiment of the present application, updating the semantic similarity of the tail entity in the background triple according to all the candidate entities to obtain the negative sampling triple includes:

[0045] Obtaining a preset screening threshold;

[0046] Calculating the semantic similarity of the tail entity in the background triple according to all the candidate entities to obtain the candidate similarity of each candidate entity;

[0047] Sort and filter all the candidate entities according to the screening threshold and all the candidate similarities to obtain a number of screened entities;

[0048] Semantically replace and update the tail entity in the background triple according to all the screened entities to obtain the negative sampling triple.

[0049] In a second aspect, an embodiment of the present application provides a few-shot knowledge graph completion system based on semantic drive, including:

[0050] A first processing unit for obtaining a knowledge graph to be completed;

[0051] A second processing unit for inputting the knowledge graph to be completed into a trained knowledge graph completion model for knowledge graph completion to obtain a target knowledge graph;

[0052] The trained knowledge graph completion model is obtained through the following steps:

[0053] Obtain a task relationship, as well as background triples, a number of graph entities, and background relationships in a background knowledge graph;

[0054] According to the background triples and the background relationships, perform neighborhood semantic encoding on all the graph entities to obtain a number of first embedding representations, and each first embedding representation is used to characterize the embedding representation of a target entity and the background relationship, where the target entity is any one of the graph entities;

[0055] According to all the first embedding representations, perform relationship encoding on the task relationship to obtain a number of second embedding representations, and each second embedding representation is used to characterize a first embedding representation aligned with the task relationship;

[0056] Perform policy negative sampling on the background triples according to the task relationship to obtain negative sampling triples;

[0057] Update the parameters of the initialized knowledge graph completion model according to all the second embedding representations, the background triples, and the negative sampling triples to obtain the trained knowledge graph completion model.

[0058] In a third aspect, an embodiment of the present application further provides an electronic device, including:

[0059] At least one processor;

[0060] At least one memory for storing at least one program;

[0061] When the at least one program is executed by the at least one processor, the at least one processor implements the above method.

[0062] In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium, which stores a program executable by a processor, and the program executable by the processor is used to implement the above method when executed by the processor.

[0063] Some of the advantages and beneficial effects of the present application will be given in the following description, some will become apparent from the following description, or will be understood through the practice of the present application:

[0064] A method and system for few-shot knowledge graph completion based on semantic drive disclosed in an embodiment of the present application. Wherein, the method obtains a knowledge graph to be completed; inputs the knowledge graph to be completed into a trained knowledge graph completion model for knowledge graph completion to obtain a target knowledge graph; the trained knowledge graph completion model is trained through the following steps: obtaining task relationships, as well as background triples, a plurality of graph entities, and background relationships in a background knowledge graph; according to the background triples and the background relationships, performing neighborhood semantic encoding on all the graph entities to obtain a plurality of first embedding representations, each of the first embedding representations being used to represent the embedding representation of a target entity and the background relationship, where the target entity is any one of the graph entities; according to all the first embedding representations, performing relationship encoding on the task relationships to obtain a plurality of second embedding representations, each of the second embedding representations being used to represent a first embedding representation aligned with the task relationship; according to the task relationships, performing policy negative sampling on the background triples to obtain negative sampling triples; according to all the second embedding representations, the background triples, and the negative sampling triples, updating the parameters of an initialized knowledge graph completion model to obtain the trained knowledge graph completion model. This method performs neighborhood semantic encoding on all graph entities in the background knowledge graph based on the background triples and background relationships in the background knowledge graph, which can add neighborhood information to each graph entity, effectively enhancing the model's representation ability of entities and background relationships, and thus improving the model's completion effect on few-shot knowledge graphs. Description of the Drawings

[0065] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the following introduces the related technical solution drawings in the embodiments of the present application or the prior art. It should be understood that the drawings introduced below are only for conveniently and clearly expressing some embodiments of the technical solutions in the present application. For those skilled in the art, other drawings can be obtained based on these drawings without creative efforts.

[0066] Figure 1 It is a schematic flowchart of a method for few-shot knowledge graph completion based on semantic drive provided by an embodiment of the present application;

[0067] Figure 2 A schematic diagram of the training process of a knowledge graph completion model provided in an embodiment of the present application;

[0068] Figure 3 A schematic diagram of the structural framework of a semantically driven few-sample knowledge graph completion system provided in an embodiment of the present application;

[0069] Figure 4 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0070] Embodiments of the present application are described in detail below, and examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present application, and are not to be construed as limitations on the present application. For the step numbers in the following embodiments, they are only provided for the convenience of explanation, and the order between the steps is not limited in any way, and the execution order of each step in the embodiment can be adaptively adjusted according to the understanding of those skilled in the art.

[0071] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which this application belongs. The terms used herein are only for the purpose of describing the embodiments of this application and are not intended to limit this application.

[0072] At present, existing few-shot knowledge graph completion methods usually use transfer learning, meta-learning and other technologies to complete incomplete knowledge graphs. However, since these methods often only focus on the structural information in the knowledge graph to be completed, they ignore the semantic context in the knowledge graph. The model has poor representation ability for entities and background relationships in the knowledge graph, the generated embedding representation quality is poor, the few-shot knowledge graph reasoning ability is poor, and the effect of few-shot knowledge graph completion is unsatisfactory.

[0073] In addition, the existing technology usually relies on random selection or embedding distance-based selection of negative samples. For the random selection method, it mainly randomly replaces the tail entity in the triple with another graph entity in the background knowledge graph. This method easily generates low-quality negative samples, which ignores the impact of relational semantics on negative sampling. The model's ability to effectively distinguish between positive and negative samples is low, which makes the effect of few-sample knowledge graph completion unsatisfactory.

[0074] In addition, for the method of embedding distance, the generated negative samples may be similar in the embedding space. However, since it ignores the influence of relational semantics on negative sampling, the generated negative samples often confuse the model, making it difficult for the model to effectively distinguish between positive and negative samples. For example, there is a relation "author Of Book" and a triple ("George Orwell", "author Of Book", "1984"). From the perspective of the embedding space, "1985" may be very close to "1984" (because they are both numbers and may represent years). Based on the method of embedding distance, the tail entity "1984" may be replaced by "1985". However, from a semantic perspective, "1985" is not a book title. Therefore, "1985" is an invalid negative sample.

[0075] For another example, if there is a relation "official Language Of" and a triple ("English", "official Language Of", "United Kingdom"), from the perspective of the embedding space, since the entity "English" and the entity "England" are related in the word vectors, the distance between the entity "English" and the entity "England" in the embedding space is relatively close. However, from a semantic perspective, the entity "England" is a country or region rather than a language. Replacing the entity "English" with the entity "England" is also an invalid negative sample.

[0076] In view of this, the embodiments of the present invention provide a semantic-driven few-shot knowledge graph completion method and system. Among them, the method performs neighborhood semantic encoding on all graph entities in the background knowledge graph based on the background triples and background relations in the background knowledge graph. Specifically, it extracts the semantic descriptions of each target entity and its neighborhood entities through a pre-trained language model, which can introduce meaningful semantic information based on the neighborhood context for each target entity, is beneficial to improving the semantic richness of the entity representation of the target entity, is beneficial to enhancing the model's representation ability for entities and background relations, and thus improves the completion effect of the model on the few-shot knowledge graph.

[0077] In addition, the method also performs negative sampling on the background triples based on the task relationship, which can generate high-quality negative samples for the relationship context, is beneficial to improving the model's ability to effectively distinguish between positive and negative samples, and thus improves the completion effect of the few-shot knowledge graph.

[0078] Refer to Figure 1 and Figure 2 , in the embodiments of the present application, a semantic-driven few-shot knowledge graph completion method includes:

[0079] Step 110: Obtain the knowledge graph to be completed;

[0080] Step 120: Input the knowledge graph to be completed into the trained knowledge graph completion model for knowledge graph completion to obtain the target knowledge graph;

[0081] In the embodiments of the present application, an incomplete knowledge graph can be used as the knowledge graph to be completed, and then the knowledge graph to be completed is input into the trained knowledge graph completion model for completion, so as to obtain the target knowledge graph output by the knowledge graph completion model.

[0082] The trained knowledge graph completion model is trained through the following steps:

[0083] Step 130: Obtain the task relationship, as well as the background triples, a number of graph entities, and background relationships in the background knowledge graph;

[0084] In the embodiments of the present application, the task relationship is a new relationship that does not appear in the background knowledge graph; the background knowledge graph is a known semantic network used to describe various entities and concepts and their relationships, where the background triples are known triples, the graph entities are the known entities in the background knowledge graph, and the background relationships are used to describe the relationships between the graph entities.

[0085] Step 140: According to the background triples and the background relationships, perform neighborhood semantic encoding on all the graph entities to obtain a number of first embedding representations, and each first embedding representation is used to characterize the embedding representation of the target entity and the background relationship, where the target entity is any one of the graph entities;

[0086] In the embodiments of the present application, the neighborhood semantic encoding may be based on the background triples, add neighborhood information to each graph entity, and generate a corresponding first embedding representation for each graph entity after adding neighborhood information based on the background relationships and the graph entities after adding neighborhood information, and the first embedding representation is used to characterize the embedding representation of the corresponding graph entity and the background relationship.

[0087] In some embodiments, performing neighborhood semantic encoding on all the target entities according to the background triples and the background relationships to obtain a number of first embedding representations includes:

[0088] A1. According to all the target entities, perform neighborhood screening and text generation on the background triples to obtain the text semantic description of each target entity, and the text semantic description is used to characterize the semantic information of the neighborhood entities and the semantic information of the target entity, where the neighborhood entities are the graph entities connected to the target entity in the background knowledge graph;

[0089] In an embodiment of the present application, for a certain graph entity (i.e., the target entity) in the background knowledge graph, step A1 may be to obtain a plurality of neighborhood entities corresponding to the target entity based on the background triples, and then generate a text semantic description corresponding to the target entity based on all the neighborhood entities and the target entity.

[0090] Further, step A1, according to the target entity, performs neighborhood screening and text generation on the background triples to obtain a text semantic description, including:

[0091] A11. According to the target entity, perform entity neighborhood screening on the background triples to obtain a graph neighborhood set, where the graph neighborhood set includes a plurality of the neighborhood entities;

[0092] Further, the step A11, according to the target entity, performs entity neighborhood screening on the background triples to obtain a graph neighborhood set, includes:

[0093] A111. Obtain a first entity, the entity type of the first entity, and a first type weight, where the first entity is a graph entity other than the target entity in the background triples of the background knowledge graph, and the first type weight is the current type weight of the entity type;

[0094] A112. Update the weight of the first type weight according to the entity type to obtain a second type weight, where the second type weight is less than the first type weight;

[0095] A113. Calculate the entity similarity between the target entity and the first entity according to the second type weight to obtain an entity similarity score;

[0096] A114. If there is at least one graph entity in the background knowledge graph that has not been calculated for entity similarity with the target entity, retain the entity similarity score, update the first entity according to the background knowledge graph, and then return to execute the step of obtaining the first entity, the entity type of the first entity, and the first type weight;

[0097] Or, A115. If there is no graph entity in the background knowledge graph that has not been calculated for entity similarity with the target entity, perform graph entity screening on the background knowledge graph according to all the entity similarity scores to obtain the graph neighborhood set.

[0098] In the embodiment of the present application, for a certain target entity, first, all background triples in the background knowledge graph can be obtained, and then an initial entity set having a neighborhood relationship with the target entity is extracted from all the background triples; then, in a loop-based manner, one graph entity in the initial entity set is obtained through step A111 as the first entity, and the entity type of the first entity and the first type weight corresponding to the entity type in the current loop process are obtained.

[0099] It can be understood that step A112 can be to update the first type weight based on the update value corresponding to the entity type, so as to obtain a second type weight smaller than the first type weight, and the second type weight can be used as the first type weight of the entity type in the next loop process. Exemplarily, the second type weight can be expressed as:

[0100]

[0101] Wherein, is the second type weight of the first entity e i ; The first type weight of the first entity e i ; Δw is the update value corresponding to the entity type of the first entity.

[0102] It should be noted that in the embodiment of the present application, based on the second type weight smaller than the first type weight in step A112, for a certain loop process, it can ensure that after selecting a graph entity of a certain entity type in this loop process, the possibility of selecting other graph entities of the same entity type in subsequent loop processes is reduced, which is beneficial to increasing the diversity of the neighborhood, and further beneficial to improving the richness of the neighborhood semantic information introduced for each target entity, and beneficial to enhancing the model's representation ability of entities and background relationships.

[0103] It is worth mentioning that step A113 can be to obtain the entity similarity score between the target entity and the first entity based on the occurrence frequency of the first entity in the background knowledge graph and the second type weight, so as to assign a higher score to the graph entity that appears less frequently. Specifically, the entity similarity score can be expressed as:

[0104]

[0105] Wherein, S(e i ) is the entity similarity score; Fre(e i ) is the occurrence frequency of the first entity e i in the background knowledge graph; δ is the weight factor; Sim(e, e i ) is the semantic similarity between the target entity e and the first entity e i .

[0106] It should be noted that after obtaining the entity similarity score between the first entity and the target entity in the current loop process, it can be determined whether the first entity in the current loop process is the last graph entity in the background knowledge graph that has not been calculated for entity similarity with the target entity; if the first entity in the current loop process is not the last graph entity in the background knowledge graph that has not been calculated for entity similarity with the target entity, the entity similarity score of the first entity can be retained, and any graph entity in the background knowledge graph that has not been calculated for entity similarity with the target entity can be updated as the first entity in the next loop process, and then return to step A111 to execute the next loop process; or, if the first entity in the current loop process is the last graph entity in the background knowledge graph that has not been calculated for entity similarity with the target entity, several entity similarity scores with higher rankings can be selected from all the entity similarity scores as the target similarity scores, and a graph neighborhood set can be constructed based on the first entity corresponding to each target similarity score.

[0107] A12. Construct an entity text prompt for the target entity according to all the neighborhood entities to obtain an entity text prompt.

[0108] A13. Input the entity text prompt into a pre-trained language model for text generation to obtain the text semantic description.

[0109] In the embodiment of the present application, after obtaining the graph neighborhood set, each first entity in the graph neighborhood set is a neighborhood entity, and each neighborhood entity includes its entity name and entity type. Each neighborhood entity is used to provide context information for the target entity to help enrich the semantic text description of the target entity. The pre-trained language model can be a pre-trained large language model. There are already many specific large language models, and the present application will not elaborate here.

[0110] It can be understood that step A12 can construct an entity text prompt based on the entity name and entity type of each neighborhood entity, as well as the entity name and entity type of the target entity. This entity text prompt is used to help the pre-trained language model integrate the information of the neighborhood entities into the text description of the target entity, so as to obtain a coherent and insightful description of the target entity (i.e., the text semantic description).

[0111] A2. Semantically encode the background relationship according to all the text semantic descriptions and the background triples to obtain a plurality of the first embedding representations.

[0112] In the embodiments of the present application, for the text semantic description of each target entity, after splicing each target entity with its text semantic description, the spliced data can be input into the BERT language model to generate the entity embedding of each target entity. Then, since the background triple includes a head entity and a tail entity, and the target entity can be the head entity or the tail entity in the background triple. For the head entity of a certain background triple, the entity embedding of the head entity can be determined from the entity embeddings of all target entities. The entity embedding of the tail entity of this background triple is similar to the content of the entity embedding of the head entity. Based on the entity embedding of the head entity and the entity embedding of the tail entity, the embedding representation of the target entity and the background relationship in this background triple (i.e., the first embedding representation) can be determined. The first embedding representation can be expressed as:

[0113] h r =h t -h h

[0114] where h r is the first embedding representation; h t is the entity embedding of the tail entity in the background triple; h h is the entity embedding of the head entity in the background triple.

[0115] It can be understood that there are often multiple background triples in the background knowledge graph, and the background relationship may appear in multiple background triples. For different background triples, the embedding representations of the target entity and the background relationship on each background triple can be obtained respectively, so as to obtain several first embedding representations.

[0116] Step 150: According to all the first embedding representations, perform relationship encoding on the task relationship to obtain several second embedding representations, and each second embedding representation is used to characterize a first embedding representation aligned with the task relationship;

[0117] In the embodiments of the present application, step 150 can be to align the task relationship with each first embedding representation based on the relationship encoding module in the Graph Attention Networks (GAT), so as to obtain the second embedding representation including the semantic information of the task relationship and the neighborhood entity information.

[0118] In some embodiments, step 150: According to the first embedding representation, perform relationship encoding on the task relationship to obtain a second embedding representation, including:

[0119] B1. Obtain the third embedding representation of the task relationship, as well as the target entity representation, association relationship representation, and neighborhood entity representation of the first embedding representation;

[0120] In the embodiment of the present application, for a certain first embedding representation, first, a third embedding representation of the task relationship can be obtained. The obtaining method of this third embedding representation is similar to the obtaining method of the aforementioned first embedding representation and can be simply analogized. Step B1 may be to obtain the embedding representation of the target entity (i.e., the target entity representation) and the embedding representation of the neighborhood entities of the target entity (i.e., the neighborhood entity representation) based on the target entity indicated in the first embedding representation, and then determine the association relationship representation based on the target entity and its neighborhood entities.

[0121] B2. Calculate the neighborhood attention on the third embedding representation according to the association relationship representation and the neighborhood entity representation to obtain a neighborhood attention score;

[0122] Further, the step B2, calculating the neighborhood attention on the third embedding representation according to the association relationship representation and the neighborhood entity representation to obtain a neighborhood attention score, includes:

[0123] B21. Construct an attention value vector for the association relationship representation according to the neighborhood entity representation to obtain a neighborhood value vector;

[0124] B22. Construct an attention key vector for the association relationship representation according to the neighborhood value vector to obtain a relationship key vector;

[0125] B23. Calculate the weight for the third embedding representation according to the relationship key vector to obtain a relationship weight;

[0126] B24. Calculate the attention score for the third embedding representation and the relationship key vector according to the relationship weight to obtain the neighborhood attention score.

[0127] In the embodiment of the present application, step B21 may be to obtain a neighborhood value vector corresponding to the neighborhood entity representation and the association relationship representation based on the attention mechanism. The neighborhood value vector can be expressed as:

[0128]

[0129] where V mn is the neighborhood value vector; is the association relationship representation; is the neighborhood entity representation; W v is the value vector parameter matrix in the attention mechanism.

[0130] It can be understood that step B22 may be to convert the association relationship representation into a key vector in the attention mechanism to obtain a relationship key vector. The relationship key vector can be expressed as:

[0131]

[0132] Among them, K mn is the relational key vector; W k is the key vector parameter matrix in the attention mechanism.

[0133] Step B23 can first obtain the query vector corresponding to the third embedding representation, which can be obtained by linearly transforming the third embedding representation; then, calculate the correlation weight between the neighborhood relationship and the task relationship between the target entity and the neighborhood entity, so as to obtain the relationship weight, and the relationship weight can be expressed as:

[0134]

[0135] Among them, γ mn is the relationship weight; is the transpose of the query vector corresponding to the third embedding representation; W S is the weight matrix for the interaction between the query vector and the neighborhood relationship.

[0136] Step B24 can be to calculate the neighborhood attention score of the neighborhood entity based on the Softmax function. The neighborhood attention score is used to characterize the influence degree of the neighborhood entity on the task relationship, and the neighborhood attention score can be expressed as:

[0137]

[0138] Among them, α mn is the neighborhood attention score; m is the target entity; n is the neighborhood entity; Q S is the query vector corresponding to the third embedding representation; d k is the scaling factor.

[0139] B3. Aggregate the neighborhood information of the target entity representation according to the neighborhood attention score, the association relationship representation, and the neighborhood entity representation to obtain an updated target entity representation;

[0140] B4. Dynamically aggregate the information of the third embedding representation according to the updated target entity representation to obtain the second embedding representation.

[0141] In the embodiments of the present application, after obtaining the neighborhood attention score, step B3 can first obtain the neighborhood value vector corresponding to the association relationship representation and the neighborhood entity representation, and then aggregate the neighborhood information based on the neighborhood value vector and the neighborhood attention score, and update the target entity representation with the aggregated entity representation to obtain an updated target entity representation. The updated target entity representation is used to characterize the task relationship and the semantic features of the target entity neighborhood, and the updated target entity representation can be expressed as:

[0142]

[0143] Among them, is the updated target entity representation; σ is a non-linear activation function, such as the ReLU activation function; N(m) is the total number of neighborhood entities of the target entity m.

[0144] It can be understood that the information dynamic aggregation in step B4 can be to dynamically aggregate the query vector of the third embedding representation with the information of the task head entity and the task tail entity to generate a task-specific relationship representation (i.e., the second embedding representation), where the task head entity is the head entity in the triple corresponding to the task relationship, and the task tail entity is the head entity in the triple corresponding to the task relationship. The embedding representations of the task head entity and the task tail entity can be two different updated target entity representations. Specifically, step B4 can be to use a feed-forward neural network (FFN) to, based on attention-weighted aggregation of the embedding representation of the task head entity, the embedding representation of the task tail entity, and the third embedding representation, thereby obtaining the second embedding representation that captures the semantics of the task relationship and dynamically integrates the information of neighborhood entities.

[0145] Step 160: According to the task relationship, perform policy negative sampling on the background triple to obtain a negative sampling triple;

[0146] In the embodiments of the present application, the semantic relationship between the task relationship and the entity can be utilized to perform policy negative sampling on the tail entity in the background triple, thereby obtaining a negative sampling triple.

[0147] Further, the step 160: According to the task relationship, perform policy negative sampling on the background triple to obtain a negative sampling triple, includes:

[0148] C1: Obtain a preset sampling policy set;

[0149] C2: According to the sampling policy set, perform policy matching on the task relationship to obtain a target negative sampling policy corresponding to the task relationship, and the target negative sampling policy is a type negative sampling policy or a semantic negative sampling policy;

[0150] C3: If the target negative sampling policy is a type negative sampling policy, then obtain the tail entity type information in the background triple, and according to the tail entity type information, perform type update on the tail entity in the background triple to obtain the negative sampling triple;

[0151] In the embodiments of the present application, the sampling strategy set includes a type negative sampling strategy and a semantic negative sampling strategy. Step C2 may first classify the relationship types of task relationships to obtain a relationship type classification result of the task relationships. The relationship type classification result is a unique relationship or an inclusive relationship. Among them, the unique relationship is used to indicate that there is a unique tail entity corresponding to the head entity of the task relationship. For example, the relationship type of the task relationship "capital of Country" is a unique relationship; while the inclusive relationship is used to indicate that there can be multiple tail entities corresponding to the head entity of the task relationship.

[0152] It can be understood that the embodiments of the present application do not limit the target negative sampling strategy corresponding to the relationship type. For example, when the relationship type is a unique relationship, the corresponding target negative sampling strategy can be a type negative sampling strategy or a semantic negative sampling strategy, and when the relationship type is an inclusive relationship, the corresponding target negative sampling strategy can be a negative sampling strategy other than the target negative sampling strategy corresponding to the unique relationship type.

[0153] It should be noted that if the target negative sampling strategy is a type negative sampling strategy, the tail entity type information in the background triple can be obtained, and an entity sample with the tail entity type information can be generated. Then, the tail entity in the background triple is replaced and updated with the entity sample to obtain a negative sampling triple.

[0154] Or, C4. If the target negative sampling strategy is a semantic negative sampling strategy, several candidate entities are obtained, and the tail entity in the background triple is updated in terms of semantic similarity according to all the candidate entities to obtain the negative sampling triple.

[0155] Further, the step C4, updating the tail entity in the background triple in terms of semantic similarity according to all the candidate entities to obtain the negative sampling triple, includes:

[0156] C41. Obtain a preset screening threshold;

[0157] C42. Calculate the semantic similarity of the tail entity in the background triple according to all the candidate entities to obtain the candidate similarity of each candidate entity;

[0158] C43. Sort and screen all the candidate entities according to the screening threshold and all the candidate similarities to obtain several screened entities;

[0159] C44. Update the tail entity in the background triple in terms of semantic replacement according to all the screened entities to obtain the negative sampling triple.

[0160] In the embodiment of the present application, if the target negative sampling strategy is the semantic negative sampling strategy, for a certain background triple, several candidate entities can be obtained from the background knowledge graph, and then the similarity scores (i.e., candidate similarities) between each candidate entity and the background triple are calculated respectively. Specifically, for a certain candidate entity, its candidate similarity can be expressed as:

[0161] S(t j ) = α·CosSim(t, t j ) + β·CosSim(r, t j )

[0162] where S(t j ) is the candidate similarity; α and β are important coefficients for balancing the entity similarity and relationship similarity between positive and negative samples; CosSim(t, t j ) is the cosine similarity between the tail entity t of the background triple and the candidate entity t j , that is, the entity similarity between positive and negative samples; CosSim(r, t j ) is the cosine similarity between the relationship r in the background triple and the candidate entity t j , that is, the relationship similarity between positive and negative samples.

[0163] It can be understood that after obtaining the candidate similarities of each candidate entity, based on the screening threshold, the candidate similarities of all candidate entities can be sorted and screened, so as to screen out several candidate entities with higher candidate similarities, and each candidate entity with a higher screened candidate similarity is determined as a screened entity. Moreover, step C44 can be to replace and update the tail entity in the background triple with each screened entity respectively, so as to obtain several negative sampling triples corresponding to the background triple.

[0164] Step 170, update the parameters of the initialized knowledge graph completion model according to all the second embedding representations, the background triple, and the negative sampling triples, so as to obtain the trained knowledge graph completion model.

[0165] In the embodiment of the present application, step 170 can be based on the contrast learning technology, input the background triple and the negative sampling triples into the initialized knowledge graph completion model for training, and optimize and update the second embedding representation and the parameters in the knowledge graph completion model based on the contrast loss function obtained during the training process, so as to obtain the trained knowledge graph completion model.

[0166] Next, a semantic-driven few-shot knowledge graph completion system proposed according to the embodiment of the present application will be described in detail with reference to the accompanying drawings.

[0167] Refer to Figure 3, A few-shot knowledge graph completion system based on semantic drive proposed in the embodiments of the present application includes:

[0168] A first processing unit 101, configured to obtain a knowledge graph to be completed;

[0169] A second processing unit 102, configured to input the knowledge graph to be completed into a trained knowledge graph completion model for knowledge graph completion to obtain a target knowledge graph;

[0170] The trained knowledge graph completion model is obtained through the following steps:

[0171] Obtain task relationships, as well as background triples, a number of graph entities, and background relationships in the background knowledge graph;

[0172] According to the background triples and the background relationships, perform neighborhood semantic encoding on all the graph entities to obtain a number of first embedding representations, and each first embedding representation is used to characterize the embedding representation of the target entity and the background relationship, where the target entity is any one of the graph entities;

[0173] According to all the first embedding representations, perform relationship encoding on the task relationships to obtain a number of second embedding representations, and each second embedding representation is used to characterize a first embedding representation aligned with the task relationship;

[0174] According to the task relationships, perform policy negative sampling on the background triples to obtain negative sampling triples;

[0175] According to all the second embedding representations, the background triples, and the negative sampling triples, update the parameters of the initialized knowledge graph completion model to obtain the trained knowledge graph completion model.

[0176] Refer to Figure 4 , The embodiments of the present application further provide an electronic device, including:

[0177] At least one processor 201;

[0178] At least one memory 202, configured to store at least one program;

[0179] When the at least one program is executed by the at least one processor 201, the at least one processor 201 implements the above method embodiments.

[0180] Similarly, it can be understood that the content in the above method embodiments is applicable to the device embodiments of the present application. The functions specifically implemented by the device embodiments of the present application are the same as those in the above method embodiments, and the beneficial effects achieved are also the same as those in the above method embodiments.

[0181] The embodiment of the present application also provides a computer-readable storage medium, which stores a program executable by a processor 201. The program executable by the processor 201 is used to implement the above method embodiment when executed by the processor 201.

[0182] Similarly, the content in the above method embodiment is applicable to this computer-readable storage medium embodiment. The functions specifically implemented by this computer-readable storage medium embodiment are the same as those in the above method embodiment, and the beneficial effects achieved are also the same as those in the above method embodiment.

[0183] In some alternative embodiments, the functions / operations mentioned in the block diagram may not occur in the order mentioned in the operation diagram. For example, depending on the functions / operations involved, two consecutive blocks shown may actually be executed substantially simultaneously or the blocks can sometimes be executed in the reverse order. In addition, the embodiments presented and described in the flowcharts of the present application are provided by way of example for the purpose of providing a more comprehensive understanding of the technology. The disclosed methods are not limited to the operations and logical flows presented herein. Alternative embodiments are contemplated where the order of various operations is changed and where sub-operations described as part of a larger operation are executed independently.

[0184] In addition, although the present application is described in the context of functional modules, it should be understood that, unless otherwise stated to the contrary, one or more of the functions and / or features may be integrated in a single physical device and / or software module, or one or more functions and / or features may be implemented in separate physical devices or software modules. It can also be understood that a detailed discussion of the actual implementation of each module is not necessary for understanding the present application. Rather, given the attributes, functions, and internal relationships of the various functional modules in the devices disclosed herein, the actual implementation of the modules will be understood within the ordinary skills of an engineer. Thus, those skilled in the art can implement the present application as set forth in the claims without undue experimentation. It can also be understood that the specific concepts disclosed are merely illustrative and are not intended to limit the scope of the present application, which is determined by the full scope of the appended claims and their equivalents.

[0185] If a function is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or a part of this technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the method of the embodiments of this application. The aforementioned storage medium includes: various media such as USB flash drives, mobile hard disks, read-only memories (ROMs), random access memories (RAMs), magnetic disks, or optical discs that can store program codes.

[0186] The logic and / or steps represented in the flowchart or described in other ways herein, for example, can be considered as a definite sequence list of executable instructions for implementing logical functions, and can be specifically implemented in any computer-readable medium for use by an instruction execution system, apparatus, or device (such as a computer-based system, a system including a processor, or other systems that can fetch instructions from the instruction execution system, apparatus, or device and execute the instructions), or used in combination with these instruction execution systems, apparatus, or devices. For the purposes of this specification, a "computer-readable medium" can be any device that can contain, store, communicate, propagate, or transport a program for use by or in combination with an instruction execution system, apparatus, or device.

[0187] More specific examples (non-exhaustive list) of computer-readable media include the following: an electrical connection part with one or more wirings (electronic device), a portable computer disk cartridge (magnetic device), random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), an optical fiber device, and a portable compact disc read-only memory (CDROM). Additionally, a computer-readable medium can even be paper or other suitable media on which a program can be printed, because the program can be obtained electronically, for example, by optically scanning the paper or other media, followed by editing, interpretation, or, if necessary, other appropriate processing, and then storing it in a computer memory.

[0188] It should be understood that each part of the present application can be implemented by hardware, software, firmware, or a combination thereof. In the above-described embodiments, multiple steps or methods can be implemented by software or firmware stored in a memory and executed by a suitable instruction execution system. For example, if implemented by hardware, as in another embodiment, any one or a combination of the following techniques well known in the art can be used: discrete logic circuits having logic gate circuits for implementing logical functions on data signals, application specific integrated circuits having appropriate combinational logic gate circuits, programmable gate arrays (PGAs), field programmable gate arrays (FPGAs), etc.

[0189] In the foregoing description of the present specification, the descriptions referring to the terms "one embodiment / example", "another embodiment / example", or "certain embodiments / examples", etc. mean that the specific features, structures, materials, or characteristics described in connection with the embodiments or examples are included in at least one embodiment or example of the present application. In the present specification, the schematic representations of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials, or characteristics described may be combined in any one or more embodiments or examples in a suitable manner.

[0190] Although the embodiments of the present application have been shown and described, those of ordinary skill in the art can understand that various changes, modifications, substitutions, and variations can be made to these embodiments without departing from the principles and spirit of the present application. The scope of the present application is defined by the claims and their equivalents.

[0191] The above has specifically described the preferred embodiments of the present application, but the present application is not limited to the embodiments. Those skilled in the art can make various equivalent deformations or substitutions without departing from the spirit of the present application, and these equivalent deformations or substitutions are all included within the scope defined by the claims of the present application.

Claims

1. A semantically driven few-sample knowledge graph completion method, characterized in that: include: Get the knowledge graph to be completed; Inputting the knowledge graph to be completed into the trained knowledge graph completion model to complete the knowledge graph and obtain the target knowledge graph; The trained knowledge graph completion model is trained by the following steps: Obtain task relations, as well as background triples, several graph entities, and background relations in the background knowledge graph; According to the background triples and the background relations, neighborhood semantic encoding is performed on all the graph entities to obtain a plurality of first embedding representations, each of which is used to represent an embedding representation of the relationship between a target entity and the background, and the target entity is any one of the graph entities; According to all the first embedding representations, the task relationship is relationally encoded to obtain a plurality of second embedding representations, each of the second embedding representations being used to represent a first embedding representation aligned with the task relationship; According to the task relationship, strategically negative sampling is performed on the background triplet to obtain a negative sampling triplet; According to all the second embedding representations, the background triples and the negative sampling triples, the parameters of the initialized knowledge graph completion model are updated to obtain the trained knowledge graph completion model.

2. The method according to claim 1, characterized in that According to the background triples and the background relations, neighborhood semantic encoding is performed on all the target entities to obtain a plurality of first embedding representations, including: According to all the target entities, the background triples are subjected to neighborhood screening and text generation to obtain a text semantic description of each target entity, wherein the text semantic description is used to characterize the semantic information of the neighborhood entity and the semantic information of the target entity, and the neighborhood entity is a graph entity connected to the target entity in the background knowledge graph; According to all the text semantic descriptions and the background triples, the background relationship is semantically encoded to obtain a plurality of the first embedding representations.

3. The method according to claim 2, characterized in that According to the target entity, the background triples are subjected to neighborhood screening and text generation to obtain a text semantic description, including: According to the target entity, the background triplet is subjected to entity neighborhood screening to obtain a graph neighborhood set, wherein the graph neighborhood set includes a plurality of the neighborhood entities; Constructing a prompt for the target entity according to all the neighborhood entities to obtain an entity text prompt; The entity text prompt is input into a pre-trained language model to generate text, thereby obtaining the text semantic description.

4. The method according to claim 3, characterized in that The entity neighborhood screening of the background triplet is performed according to the target entity to obtain a graph neighborhood set, including: Obtaining a first entity, an entity type and a first type weight of the first entity, wherein the first entity is a graph entity other than the target entity in the background triple of the background knowledge graph, and the first type weight is a current type weight of the entity type; According to the entity type, the first type weight is updated to obtain a second type weight, where the second type weight is less than the first type weight; Calculating entity similarity between the target entity and the first entity according to the second type weight to obtain an entity similarity score; If there is at least one graph entity in the background knowledge graph whose entity similarity has not been calculated with the target entity, the entity similarity score is retained, and the first entity is updated according to the background knowledge graph, and then the step of obtaining the first entity, the entity type of the first entity and the first type weight is returned to execute; or, if there is no graph entity in the background knowledge graph whose entity similarity has not been calculated with the target entity, the background knowledge graph is screened for graph entities according to all the entity similarity scores to obtain the graph neighborhood set.

5. The method according to claim 1, characterized in that According to the first embedding representation, the task relationship is relationally encoded to obtain a second embedding representation, including: Acquire a third embedding representation of the task relationship, and a target entity representation, an associated relationship representation, and a neighborhood entity representation of the first embedding representation; Performing neighborhood attention calculation on the third embedding representation according to the association relationship representation and the neighborhood entity representation to obtain a neighborhood attention score; Aggregating neighborhood information of the target entity representation according to the neighborhood attention score, the association relationship representation, and the neighborhood entity representation to obtain an updated target entity representation; According to the updated target entity representation, information is dynamically aggregated on the third embedding representation to obtain the second embedding representation.

6. The method according to claim 5, characterized in that The performing neighborhood attention calculation on the third embedding representation according to the association relationship representation and the neighborhood entity representation to obtain a neighborhood attention score includes: According to the neighborhood entity representation, constructing an attention value vector for the association relationship representation to obtain a neighborhood value vector; Constructing an attention key vector for the association relationship representation according to the neighborhood value vector to obtain a relationship key vector; According to the relationship key vector, weight calculation is performed on the third embedding representation to obtain a relationship weight; According to the relationship weight, an attention score is calculated for the third embedding representation and the relationship key vector to obtain the neighborhood attention score.

7. The method according to claim 1, characterized in that The step of performing strategic negative sampling on the background triplet according to the task relationship to obtain a negative sampling triplet includes: Get the preset sampling strategy set; According to the sampling strategy set, the task relationship is matched with a strategy to obtain a target negative sampling strategy corresponding to the task relationship, wherein the target negative sampling strategy is a type negative sampling strategy or a semantic negative sampling strategy; If the target negative sampling strategy is a type negative sampling strategy, the type information of the tail entity in the background triplet is obtained, and the type of the tail entity in the background triplet is updated according to the tail entity type information to obtain the negative sampling triplet; or, if the target negative sampling strategy is a semantic negative sampling strategy, several candidate entities are obtained, and the semantic similarity of the tail entity in the background triplet is updated according to all the candidate entities to obtain the negative sampling triplet.

8. A semantically driven few-sample knowledge graph completion system, characterized in that: include: A first processing unit is used to obtain a knowledge graph to be completed; A second processing unit is used to input the knowledge graph to be completed into a trained knowledge graph completion model to complete the knowledge graph and obtain a target knowledge graph; The trained knowledge graph completion model is trained by the following steps: Obtain task relations, as well as background triples, several graph entities, and background relations in the background knowledge graph; According to the background triples and the background relations, neighborhood semantic encoding is performed on all the graph entities to obtain a plurality of first embedding representations, each of which is used to represent an embedding representation of the relationship between a target entity and the background, and the target entity is any one of the graph entities; According to all the first embedding representations, the task relationship is relationally encoded to obtain a plurality of second embedding representations, each of the second embedding representations being used to represent a first embedding representation aligned with the task relationship; According to the task relationship, strategically negative sampling is performed on the background triplet to obtain a negative sampling triplet; According to all the second embedding representations, the background triples and the negative sampling triples, the parameters of the initialized knowledge graph completion model are updated to obtain the trained knowledge graph completion model.

9. An electronic device, characterized in that: include: at least one processor; at least one memory for storing at least one program; When the at least one program is executed by the at least one processor, the at least one processor implements the method according to any one of claims 1 to 7.

10. A computer-readable storage medium storing a program executable by a processor, characterized in that: The program executable by the processor is used to implement the method according to any one of claims 1 to 7 when executed by the processor.