Fuzzy knowledge graph contrast embedding method and device, electronic equipment and storage medium
By constructing a fuzzy knowledge graph embedding method with head and tail entity views, and training the model by combining fuzzy RDF KG embedding loss and contrastive learning loss, the problem of insufficient fuzzy knowledge graph embedding quality in the existing technology is solved, and higher quality knowledge graph representation and better downstream task execution performance are achieved.
Patent Information
- Application Number
- CN202411567054.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-05
- Publication Date
- 2025-10-21
- Estimated Expiration
- 2044-11-05
AI Technical Summary
In existing technologies, negative samples generated by randomly replacing existing triplet entities are used for fuzzy knowledge graph embedding. This cannot effectively prototype the actual KG fuzziness, resulting in poor knowledge graph embedding quality.
By constructing the first view and the second view, the correlation of triples is represented from the perspective of the head entity and the tail entity respectively, and the knowledge graph embedding model is used for encoding. The fuzzy RDF KG embedding loss and contrastive learning loss are combined to train the model to obtain high-quality knowledge graph embedding.
It improves the quality of knowledge graph embedding, enhances the performance of downstream reasoning tasks, and enhances the accuracy and consistency of knowledge graph representation.
Smart Images

Figure CN119443219B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to a knowledge graph embedding method, and specifically to a fuzzy knowledge graph comparison embedding method, device, electronic device and storage medium. Background Art
[0002] Knowledge graphs (KGs) have crucial applications in various fields. For example, in finance, KGs enable deep perception and extensive interconnection of isolated data, enabling highly intelligent shared analysis. This helps clients expand the breadth and depth of their existing digital resources and support intelligent applications. For example, banks can leverage the significant application value of knowledge graphs across financial scenarios for risk assessment, credit rating, and fraud detection. Furthermore, knowledge graphs play a vital role in public security, healthcare, e-commerce, and other fields. In public security, knowledge graphs are used to process massive amounts of data, break down data silos, and uncover valuable insights. In healthcare, they can establish systematic and comprehensive knowledge bases, provide efficient retrieval, promote intelligent processing of massive amounts of data, and assist in diagnosis and treatment. In e-commerce, knowledge graphs are used for product recommendations and user profiling, enhancing personalized recommendations.
[0003] The core goal of knowledge graph embedding is to learn a low-dimensional vector representation for each entity and relationship, thereby enabling various downstream tasks such as entity classification, link prediction, and relationship reasoning while preserving the original graph structure. Therefore, whether executing complex downstream tasks in different domains or optimizing or completing the knowledge graph itself, knowledge graph embedding is essential. The quality of knowledge graph embedding has a crucial impact on the performance of downstream tasks.
[0004] Resource Description Framework (RDF) is rapidly becoming the standard data model for metadata management. Due to its applicability for semantic data modeling in open information extraction environments, as well as the openness of the environment and the decentralized maintenance characteristics of various users, RDF data inevitably contains errors, outdated and inconsistent information as its scale increases significantly.
[0005] Knowledge graphs (KGs) modeled using RDF are extremely useful resources in artificial intelligence applications. To rapidly build and continuously enrich knowledge graphs, automated construction and update mechanisms are often used. This inevitably introduces ambiguity or uncertainty, and ignoring this uncertainty can severely impact downstream tasks. Fuzzy RDF KGs have become a recent research hotspot due to their graph structure, semantic links, real-time updates, and cross-domain nature.
[0006] Current research on fuzzy RDF KGs faces challenges from three main aspects: (1) The inherent fuzziness of the real world. A large part of human knowledge is inherently imprecise. For example, in the industrial field, product design is often based on experience and probabilistic information. It is not enough to just consider the existence of relational facts, but also the corresponding likelihood should be measured, which is particularly valuable in practical applications such as biology and intelligent manufacturing. (2) Noise introduced by the construction process. In order to handle large amounts of data, most KGs are automatically extracted from web corpora using heuristic algorithms. The automated construction process often results in fuzzy knowledge graphs containing inaccurate facts. The validity of these facts needs to be quantified by metrics such as fuzziness and confidence. (3) The inherent properties of triples. Although fuzzy RDF KGs are effective in representing structured data, the symbolic nature of their triples often makes knowledge graphs difficult to operate.
[0007] To address this issue, many studies have embedded fuzzy knowledge graphs based on negative samples generated by randomly replacing existing triple entities. However, the fuzzy knowledge graphs in the real world are very complex, that is, there are many cases where the elements of triples do not match but are correlated. Embedding fuzzy knowledge graphs by randomly replacing existing triple entities with negative samples is not sufficient to prototype the actual KG fuzziness, resulting in poor quality of knowledge graph embedding generation. Summary of the Invention
[0008] The technical problem to be solved by the present invention is that the above-mentioned method commonly used in the prior art uses negative samples generated by randomly replacing existing triple entities to embed fuzzy knowledge graphs, which is not enough to prototype the actual KG fuzziness, resulting in poor quality of knowledge graph embedding. In order to solve the above problem, the present invention provides a fuzzy knowledge graph comparative embedding method, device, electronic device and storage medium.
[0009] The present invention includes:
[0010] In a first aspect, an embodiment of the present invention provides a fuzzy knowledge graph comparative embedding method, comprising:
[0011] Constructing a first view and a second view based on a fuzzy knowledge graph, wherein the fuzzy knowledge graph includes a plurality of triples, the first view being used to represent the correlation between the plurality of triples from the perspective of a head entity, and the second view being used to represent the correlation between the plurality of triples from the perspective of a tail entity;
[0012] Encoding the triples in the first view using a knowledge graph embedding model to obtain a first embedding, and encoding the triples in the second view using the knowledge graph embedding model to obtain a second embedding;
[0013] Training the knowledge graph embedding model based on fuzzy RDF KG embedding loss and contrastive learning loss to obtain a trained knowledge graph embedding model;
[0014] Obtain knowledge graph embedding based on the trained knowledge graph embedding model.
[0015] Optionally, constructing the first view and the second view based on the fuzzy knowledge graph includes:
[0016] Taking each triple in the plurality of triples as a node;
[0017] The first view is obtained by connecting the first node and the second node, and the second view is obtained by connecting the third node and the fourth node. The triples corresponding to the first node and the second node have the same head entity, and the triples corresponding to the third node and the fourth node have the same tail entity.
[0018] Optionally, encoding the triples in the first view using a knowledge graph embedding model to obtain a first embedding includes:
[0019] For each first triple in the first view, obtaining a first initial embedding of the first triple;
[0020] The first initial embedding is updated based on the attention coefficients of neighboring triplets of the first triplet to obtain the first embedding.
[0021] Optionally, encoding the triples in the second view using the knowledge graph embedding model to obtain a second embedding includes:
[0022] For each second triplet in the second view, obtaining a second initial embedding of the second triplet;
[0023] The second initial embedding is updated based on the attention coefficients of neighboring triplets of the second triplet to obtain the second embedding.
[0024] Optionally, before training the knowledge graph embedding model based on fuzzy RDF KG embedding loss and contrastive learning loss to obtain a trained knowledge graph embedding model, the method further includes:
[0025] Taking the triples in the fuzzy knowledge graph as positive triples;
[0026] Randomly replacing the entity relations and relations of the positive triples with other entities and relations to obtain negative triples;
[0027] The fuzzy RDF KG embedding loss is calculated based on the difference score of the positive triple and the difference score of the negative triple.
[0028] Optionally, the contrastive learning loss is determined based on the similarity between the first embedding and the second embedding corresponding to the triple in the fuzzy knowledge graph.
[0029] Optionally, the contrastive learning loss is:
[0030]
[0031] Among them, {x1,x2,...,x n} represents the first embedding corresponding to n triples in the fuzzy knowledge graph, {z1,z2,...,z n} represents the second embedding corresponding to n triples in the fuzzy knowledge graph, (x i ,z i ) represents the first embedding corresponding to the i-th triple in the fuzzy knowledge graph and the second embedding corresponding to the i-th triple in the fuzzy knowledge graph, τ represents the temperature parameter, sim(x i ,z i ) represents x i and z i The cosine similarity of , n is an integer greater than 2, and i is an integer less than or equal to n.
[0032] In a second aspect, an embodiment of the present invention further provides a fuzzy knowledge graph comparison and embedding device, comprising:
[0033] a construction module, configured to construct a first view and a second view based on a fuzzy knowledge graph, wherein the fuzzy knowledge graph includes a plurality of triples, the first view being configured to represent the correlation between the plurality of triples from the perspective of a head entity, and the second view being configured to represent the correlation between the plurality of triples from the perspective of a tail entity;
[0034] an encoding module, configured to encode the triples in the first view using a knowledge graph embedding model to obtain a first embedding, and to encode the triples in the second view using the knowledge graph embedding model to obtain a second embedding;
[0035] A training module, configured to train the knowledge graph embedding model based on fuzzy RDF KG embedding loss and contrastive learning loss to obtain a trained knowledge graph embedding model;
[0036] An acquisition module is used to obtain knowledge graph embedding based on the trained knowledge graph embedding model.
[0037] In a third aspect, an embodiment of the present invention provides an electronic device comprising: a memory, a processor, and a program stored in the memory and executable on the processor; the processor is configured to read the program in the memory to implement the steps of the fuzzy knowledge graph comparison and embedding method as described in the first aspect.
[0038] In a fourth aspect, an embodiment of the present invention provides a readable storage medium for storing a program, which, when executed by a processor, implements the steps in the fuzzy knowledge graph comparison and embedding method as described in the first aspect.
[0039] The beneficial effect of the present invention is that, in an embodiment of the present invention, a first view and a second view are first constructed by treating multiple triples in a fuzzy knowledge graph as nodes. The first view and the second view characterize the connection of multiple triples from different perspectives, and thus can be used as two consistent views in contrastive learning. Then, the method trains the knowledge graph embedding model based on the fuzzy RDF KG embedding loss and the contrastive learning loss. The degree of closeness of the representation of the same triple in different views can be used as an indicator for knowledge graph representation learning. Through contrastive learning, the quality of the learned knowledge graph embedding is higher, thereby improving the execution effect of the downstream reasoning tasks corresponding to the knowledge graph embedding. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] Attachment Figure 1 One of the flow charts of the fuzzy knowledge graph comparative embedding method provided in an embodiment of the present invention;
[0041] Attachment Figure 2 The second flowchart of the fuzzy knowledge graph comparison and embedding method provided by an embodiment of the present invention;
[0042] Attachment Figure 3a for Figure 2 A schematic diagram of constructing the first view and the second view portion;
[0043] Attachment Figure 3b for Figure 3a Example diagram of fuzzy knowledge graph in
[15] ;
[0044] Attachment Figure 3c for Figure 3a Example graph that treats triples as nodes;
[0045] Attachment Figure 3d for Figure 3a Example diagrams of the first and second views;
[0046] Attachment Figure 4 for Figure 2 A schematic diagram of obtaining the first embedded and second embedded parts;
[0047] Attachment Figure 5 for Figure 2Schematic diagram of the joint training of the knowledge graph embedding model in
[15] ;
[0048] Attachment Figure 6 A schematic diagram of the structure of a fuzzy knowledge graph comparison and embedding device provided by an embodiment of the present invention;
[0049] Attachment Figure 7 A schematic structural diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0050] In the embodiments of the present application, the term "and / or" describes the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B may represent three situations: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the objects associated before and after are in an "or" relationship. In the embodiments of the present application, the term "multiple" refers to two or more, and other quantifiers are similar. The terms "first", "second", etc. in the specification and claims of this application are used to distinguish similar objects, and are not used to describe a specific order or sequence. It should be understood that the terms used in this way can be interchangeable where appropriate, so that the embodiments of the present application can be implemented in an order other than those illustrated or described here, and the objects distinguished by "first" and "second" are generally of the same type, and the number of objects is not limited. For example, the first object can be one or more.
[0051] The following will be combined with the drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are only part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.
[0052] For ease of understanding, the following first provides corresponding explanations of the various nouns involved in this application.
[0053] See Figure 1 , Figure 1 This is a flow chart of the fuzzy knowledge graph comparison and embedding method provided by an embodiment of the present invention. This method specifically includes the following steps:
[0054] Step 101: construct a first view and a second view based on a fuzzy knowledge graph, wherein the fuzzy knowledge graph includes multiple triples, the first view is used to represent the correlation between the multiple triples from the perspective of the head entity, and the second view is used to represent the correlation between the multiple triples from the perspective of the tail entity.
[0055] Step 102: Encode the triples in the first view using the knowledge graph embedding model to obtain a first embedding, and encode the triples in the second view using the knowledge graph embedding model to obtain a second embedding.
[0056] Step 103: Train the knowledge graph embedding model based on fuzzy RDF KG embedding loss and contrastive learning loss to obtain a trained knowledge graph embedding model.
[0057] Step 104: Obtain knowledge graph embedding based on the trained knowledge graph embedding model.
[0058] In an embodiment of the present invention, a first view and a second view are first constructed by treating multiple triples in a fuzzy knowledge graph as nodes. The first view and the second view characterize the connection of multiple triples from different perspectives, and thus can be used as two consistent views in contrastive learning. This method then trains the knowledge graph embedding model based on the fuzzy RDF KG embedding loss and contrastive learning loss. The degree of similarity between the representations of the same triple in different views can be used as an indicator for knowledge graph representation learning. Through contrastive learning, the quality of the learned knowledge graph embedding is higher, thereby improving the execution effect of the downstream reasoning tasks corresponding to the knowledge graph embedding.
[0059] See Figure 2 and Figure 3a , it should be understood that Figure 2 The overall flow chart of this method is as follows: Figure 3a 、 Figure 4 and Figure 5 They are Figure 2 The enlarged schematic diagram of the three parts is shown in FIG. Figure 3b-3d for Figure 3a In step 101, by treating the triples in the fuzzy knowledge graph as nodes, two triple-level views can be generated, which can be used as two consistent views in contrastive learning. In some optional embodiments, step 101 includes:
[0060] Taking each triple in the plurality of triples as a node;
[0061] The first view is obtained by connecting the first node and the second node, and the second view is obtained by connecting the third node and the fourth node. The triples corresponding to the first node and the second node have the same head entity, and the triples corresponding to the third node and the fourth node have the same tail entity.
[0062] Exemplarily, for two triples of shared entities T1 = (s1, p1, o1) and T2 = (s2, p2, o2) in the fuzzy knowledge graph, there are two connection modes, namely, the connection mode of the shared head entity, i.e., s1 = s2 or s1 = o2; and the connection mode of the shared tail entity, i.e., o1 = s2 or o1 = o2.
[0063] Figure 3b is a specific example graph of a fuzzy knowledge graph, such as Figure 3c As shown in the figure, the triples in the fuzzy knowledge graph are regarded as nodes, and the nodes are connected according to the two connection modes mentioned above to obtain the following: Figure 3d Specifically, the first view (View I) and the second view (View II) are obtained by connecting the nodes according to the connection mode of the shared head entity, and the second view is obtained by connecting the nodes according to the connection mode of the shared tail entity.
[0064] It should be understood that for each triple in the fuzzy knowledge graph, the triple corresponds to a node in both the first view and the second view, and the fuzziness of each triple can be subsequently evaluated by the consistency between the representations learned from the first view and the second view.
[0065] In this embodiment, the first and second views can be viewed as consistent views of the fuzzy knowledge graph. The first view models the correlation between triples from the perspective of the head entity, while the second view represents the distribution of relationship triples from the perspective of the tail entity. Since triples sharing the same entity are always semantically related, normal triples in the fuzzy knowledge graph can easily find enough related neighboring triples in the first view to reconstruct the semantics learned from the second view.
[0066] In some optional embodiments, encoding the triples in the first view using a knowledge graph embedding model to obtain a first embedding includes:
[0067] For each first triple in the first view, obtaining a first initial embedding of the first triple;
[0068] The first initial embedding is updated based on the attention coefficients of neighboring triplets of the first triplet to obtain the first embedding.
[0069] In some optional embodiments, encoding the triples in the second view using the knowledge graph embedding model to obtain a second embedding includes:
[0070] For each second triplet in the second view, obtaining a second initial embedding of the second triplet;
[0071] The second initial embedding is updated based on the attention coefficients of neighboring triplets of the second triplet to obtain the second embedding.
[0072] In step 102, the embeddings of entities and relations in the fuzzy knowledge graph are randomly initialized. Then, a local modeling layer (i.e., a set of bidirectional long short-term memory (Bi-LSTM) network units) is constructed to learn the local relational structure within each triple. Local modeling can capture the local structural information in the triple.
[0073] like Figure 4 As shown, taking the triple (s, p, o) as an example, the formula (1) of the local information modeling layer is as follows, and the triple embedding q can be obtained by the following formula i :
[0074] q i =G local (s,p,o)=f concat (f BiLSTM (e s ,e p ,e o ))(1);
[0075] Among them, in the triple (s, p, o), s is used to represent the subject, p is used to represent the predicate, o is used to represent the object, and f is used to represent the object. concat () is used to characterize f BiLSTM () is a function for concatenating vectors, which is usually used to merge feature vectors from multiple different sources into a longer vector. BiLSTM () is used to represent a bidirectional long short-term memory network (Bidirectional Long Short-Term Memory, BiLSTM), which is used to input vector (e s ,e p ,e o ) performs sequence modeling to capture contextual information. (e s ,e p ,e o ) is used to represent the embedding representation vector of the subject, predicate, and object.
[0076] Since the above triples are embedded in q iThe internal relational structure of the input triples can be well captured, so in some embodiments, the triple embedding is used as the initial embedding. Specifically, for each first triple in the first view, the first initial embedding of the first triple is obtained according to the above formula (1); similarly, for each second triple in the second view, the second initial embedding of the second triple is obtained according to the above formula (1).
[0077] In some embodiments, a triple-level attention mechanism is introduced to learn the global triple representation of the first triple and the second triple. Since high-ambiguity triples have weaker connections with their neighboring entities, the attention mechanism can adaptively assign smaller attention weights to high-ambiguity triples.
[0078] The following takes the first triple as an example to illustrate: Based on its neighboring triples {q1,q2,...,q m}’s attention coefficient to update its embedding representation.
[0079] The attention coefficient (also called weight) between a given triplet i and its adjacent j-th triplet is calculated as follows:
[0080] att ij =f att (Wq i ,Wq j )(2);
[0081] Among them, att ij It is used to characterize the importance of its neighboring j-th triple to the given triple i. is a learnable linear augmentation matrix used to project the initial triplet representation into the same vector space, f att Used to characterize the attention function:
[0082] Furthermore, in some embodiments, in order to make the attention coefficients easier to compare between different triplets, they are normalized using the softmax function:
[0083]
[0084] Among them, m is used to represent the number of adjacent triples, att ik It is used to represent the weight between a given triple i and its neighboring k-th triple.
[0085] Furthermore, in some embodiments, to prevent information propagation from high-ambiguity triples, a hyperparameter is introduced As threshold:
[0086]
[0087] After calculating the weights between a given triple i and its neighboring triples in the above manner, the first initial embedding of the given triple is updated based on the attention coefficients of the neighboring triples of the given triple to obtain the first embedding. Specifically, this can be calculated using the sigmoid function:
[0088]
[0089] Among them, σ() is used to represent the sigmoid function,
[0090] For the second triplet in the second view, we can refer to the above content to perform attention aggregation on its neighborhood features to update its embedding and obtain its corresponding second embedding. The specific steps can be found in the above content and will not be repeated here.
[0091] For the second triplet, the second embedding is as follows:
[0092]
[0093] Among them, α i ' j It is used to characterize the importance of its neighboring j-th triple to the given triple i, q' j Used to characterize the jth triplet in its neighborhood.
[0094] It should be noted that for each triple in the fuzzy knowledge graph, the triple corresponds to a node in both the first and second views. However, because the first and second views are constructed using different connection patterns, the neighboring triples corresponding to the same triple in the first view may be different from the neighboring triples corresponding to the same triple in the second view, resulting in different embeddings. Using the above method, different embeddings corresponding to the same triple in the fuzzy knowledge graph can be obtained.
[0095] In step 103, the knowledge graph embedding model is trained based on the fuzzy RDF KG embedding loss and contrastive learning loss. Figure 5 , define the comprehensive objective function as follows:
[0096] L=L con +αL emb (7);
[0097] Among them, L emb Used to characterize the fuzzy RDF KG embedding loss, L conIt is used to characterize contrastive learning loss. α is a hyperparameter. In specific implementation, the hyperparameter can be dynamically adjusted according to different data sets to obtain the best model effect. Its specific value is not limited here.
[0098] Through the above method, the fuzzy RDF KG embedding loss and contrastive learning loss are combined to train the model. This mutually enhances the effect at each iteration, ultimately achieving the best embedding learning results. The following describes the fuzzy RDF KG embedding loss and contrastive learning loss, respectively.
[0099] Optionally, in some embodiments, before step 103, the method further includes:
[0100] Taking the triples in the fuzzy knowledge graph as positive triples;
[0101] Randomly replacing the entity relations and relations of the positive triples with other entities and relations to obtain negative triples;
[0102] The fuzzy RDF KG embedding loss is calculated based on the difference score of the positive triple and the difference score of the negative triple.
[0103] To calculate the fuzzy RDF KG embedding loss, first construct the negative triples:
[0104] The entity relations and relations of the positive triples are randomly replaced with other entities and relations to obtain the negative triples T′. Furthermore, to prevent noise, the negative triples in T′ are checked in T and the pseudo-negative triples are removed. The final negative triples are as follows:
[0105] T′={(s′,p,o)|s′∈L v}∪{(s,p,o′)|o′∈L v}∪{(s,p′,o)|p′∈L E}(8);
[0106] Among them, L v It is used to characterize the feature set related to the entity (subject, object), which can be understood as the attributes or features related to the entity in the triple. E A set of features used to characterize a relationship (predicate), representing the features or attributes of the relationship in a triple.
[0107] It should be noted that the knowledge graph embedding model provided in this embodiment is a translation operation performed on the low-dimensional embedding of entities at the triple level. Therefore, the more a triple conforms to the translation hypothesis, the better The more credible the triple should be.
[0108] In this embodiment, the training objective uses negative sampling to formalize a margin-based scoring function. The goal of this pairwise scoring function is to make the score of positive triples higher than that of negative triples. It allows the model to focus on triples with high membership (i.e., triples that are considered more important or reliable in the knowledge graph). The fuzzy RDF KG embedding loss is as follows:
[0109]
[0110] Among them, E(s,p,o) is used to represent the difference score of the positive example triple, E(s′,p′,o′) is used to represent the difference score of the negative example triple, γ>0 is used to represent the marginal value hyperparameter, and T′ is used to represent the set of negative example triplets.
[0111] Contrastive learning is a widely used self-supervised learning algorithm. Its core concept is to make the representations of positive pairs as consistent as possible, while the representations of negative pairs as dissimilar as possible. The negative sampling used in the fuzzy RDF KG embedding loss can guide the model to learn rich structural and semantic information within triples. To further effectively learn the knowledge graph embedding model, this example combines the contrastive learning loss with the knowledge graph embedding model training.
[0112] Contrastive learning can learn rich representations of key semantics in normal instances, while the lack of such features in abnormal triplets forces their representations to disperse in the latent vector space. Therefore, the consistency of the representations of triplets from different views can theoretically serve as a good learning signal. By learning and comparing between the first view and the second view, the knowledge graph embedding model can learn rich representations of key semantics in normal instances, thereby forcing abnormal triplets to stay away from the lack of such features in the latent vector space. It should be understood that in order to integrate contrastive learning into knowledge graph embedding, this embodiment uses normalized temperature-scaled cross entropy loss as the contrastive learning objective to jointly train the model.
[0113] Optionally, in some embodiments, the contrastive learning loss is determined based on the similarity between the first embedding and the second embedding corresponding to the triple in the fuzzy knowledge graph.
[0114] Specifically, we randomly sample a mini-batch of n examples from the fuzzy knowledge graph and define a training task on the augmented example pairs derived from the mini-batch, thus obtaining n first embeddings {x1,x2,...,x n} and n second embeddings {z1,z2,...,z n},(x i ,z i) are the corresponding embeddings of the same triple (the i-th triple) in the fuzzy knowledge graph in the first view and the second view respectively.
[0115] Optionally, the contrastive learning loss is:
[0116]
[0117] Among them, {x1,x2,...,x n} represents the first embedding corresponding to n triples in the fuzzy knowledge graph, {z1,z2,...,z n} represents the second embedding corresponding to n triples in the fuzzy knowledge graph, (x i ,z i ) represents the first embedding corresponding to the i-th triple in the fuzzy knowledge graph and the second embedding corresponding to the i-th triple in the fuzzy knowledge graph, τ represents the temperature parameter, sim(x i ,z i ) represents x i and z i The cosine similarity of , n is an integer greater than 2, and i is an integer less than or equal to n.
[0118] In this embodiment, contrastive learning in multiple views of the knowledge graph can learn rich key semantic representations in deterministic triples. However, in uncertain or anomalous triples, ambiguity can lead to the loss of triple features, causing their representations to be far apart in the latent vector space. Therefore, this embodiment uses the closeness of the representations of the same triple in different views as an indicator for knowledge graph representation learning. The credibility of each triple is evaluated based on the consistency between the representations learned from multiple views, thereby perceiving the uncertainty in the knowledge graph and learning better knowledge representations.
[0119] As a specific example, the following describes the values of the various hyperparameters in the knowledge graph embedding model during implementation. First, a grid search is performed on the three hyperparameters during training: the learning rate (lr), the margin (γ) in formula (9), and the attention threshold (μ) in formula (4) to determine the optimal hyperparameter combination. The value ranges of the hyperparameters are shown in Table 1.
[0120] Table 1 Grid search results for hyperparameters
[0121] Hyper-parameters Search space Learning rate (lr) [0.001,0.01,0.1] Margin(γ) [0.1,0.3,0.5,0.7,1.0] Attention threshold (μ) [0.001,0.01,0.05,0.1,0.2]
[0122] The learning rate is a key hyperparameter that controls the magnitude of model parameter updates. A smaller learning rate allows for more refined parameter adjustments, potentially leading to convergence to a more optimal solution over a longer training period. A larger learning rate, on the other hand, allows for faster model parameter updates, but can also lead to unstable convergence or premature regression to a suboptimal solution. To investigate the impact of the learning rate on model performance, this experiment varied it from 0.001 to 0.1. Experimental results show that when lr = 0.1, the model performs poorly across various parameter combinations. This is because a larger learning rate causes model parameters to update too quickly, potentially skipping the global optimal solution and preventing the model from fully learning the inherent structure and patterns of the data. As the learning rate decreases, the model updates more slowly, allowing for more refined parameter adjustments, thus facilitating convergence to a more optimal solution over a more stable training period. The model achieves optimal performance when lr = 0.01. However, as lr decreases further to 0.001, the performance deteriorates compared to higher lr values. Therefore, a moderate learning rate strikes a good balance between stable convergence and shorter training times, achieving optimal detection results.
[0123] γ is a parameter that controls the distance between negative and positive pairs in the fuzzy RDF KG embedding loss. To study the impact of γ, this experiment varied it from 0.1 to 1.0. Except for the case of lr = 0.01, where the optimal γ was 0.3 and the performance was comparable to that of γ = 0.1, the remaining optimal values were all 0.1. Overall, the optimal γ is 0.1.
[0124] μ is a parameter that controls the attention threshold. A smaller μ allows the encoder to focus on more irrelevant neighbors when learning the global triplet embedding representation, while a larger μ forces the encoder to focus on only a small number of closely related neighbor triplets. To study the impact of μ, this experiment varied it from 0.001 to 0.02. When μ = 0.02, the performance of all parameter combinations was suboptimal. This is because when μ is large, only a small amount of global contextual features are mined, lacking sufficient contextual information. As μ decreases, the encoder begins to focus on more neighbor triplets, thereby learning richer global information, and the performance continues to improve. The best performance is achieved at μ = 0.01. However, as μ continues to decrease, the situation changes in the opposite direction. This is because a smaller μ allows more irrelevant and highly ambiguous neighbors to participate in the representation learning process, leading to the problem of overfitting in representation learning.
[0125] Furthermore, the hyperparameter τ in formula (10) is used to control the degree of scaling of the similarity when calculating the loss function. A smaller τ will cause the similarity score to be amplified, so that the model will place more emphasis on the difference between positive sample pairs with high similarity and negative sample pairs with low similarity, resulting in the model to more strictly distinguish between positive and negative sample pairs during the learning process. A larger τ value will cause the similarity score to be reduced in the softmax function, making the model less sensitive to the difference between positive and negative sample pairs. According to experiments, the optimal value of τ is 0.5, which is in the middle.
[0126] In summary, as a specific embodiment, the above hyperparameter combination is: Learning rate (lr) = 0.01, Margin (γ) = 0.1, Attention threshold (μ) = 0.001, τ = 0.5.
[0127] The following will take a specific experiment as an example to illustrate the beneficial effects of the fuzzy knowledge graph comparative embedding method provided by an embodiment of the present invention.
[0128] First, we introduce the detailed experimental settings, including the benchmark dataset, comparison baseline methods, and evaluation metrics.
[0129] Dataset: In this experiment, the trained knowledge graph embedding model provided in this embodiment (referred to as A Joint Learning Framework for Fuzzy RDF KGContrastive Embedding (FuKCE) model in this experiment) is evaluated based on WN18RR. WN18RR was created to overcome the test data leakage problem in the original WN18 dataset. By excluding simple reverse relationships, it improves the fairness and accuracy of model evaluation. Based on WN18RR, three different fuzzy knowledge graphs WN18RR-N1, WN18RR-N2, and WN18RR-N3 were generated, with negative triples accounting for 5%, 10%, and 15% of the positive triples, respectively. On this basis, experiments were conducted on the model effects with different fuzzy triple ratios.
[0130] Baseline model: URGE is the first model for computing uncertain graph embeddings, but it cannot handle multi-class relations and only generates node embeddings. Therefore, the relation type is also ignored in the experiments. BEUrRE is the first model to adopt a geometric embedding method for UKG embedding. In this model, each entity is encoded as a Gumbel box representation whose volume represents the marginal probability. Relations are modeled by performing two affine transformations on the boxes of the head and tail entities. UKGsE first uses Word2Vec to pre-train word vectors and then learns the corresponding confidence levels through LSTM. UKGEbert builds on this and embeds latent commonsense semantics through BERT. In this model, each piece of knowledge is regarded as a short sentence and input into BERT for training. Subsequently, the uncertainty distribution of knowledge confidence is learned through a recurrent neural network. UPGAT is an uncertainty-aware graph attention mechanism used to capture probabilistic subgraph features while alleviating the irrelevant neighbor problem.
[0131] Evaluation metrics: Ranking metrics are used in this experiment to evaluate the performance of all compared methods. Specifically, all triples are sorted in ascending order according to their fuzzy membership in the target knowledge graph. In order to fairly evaluate the performance of knowledge graph verification, the following two evaluation metrics are used in this experiment:
[0132] Precision@K: represents the percentage of negative triples found among the top K triplets with the lowest fuzzy membership.
[0133] Recall@K: represents the proportion of recognized negative triples in all negative triples.
[0134] Implementation Details: All baseline methods and the proposed framework were implemented in PyTorch. Specifically, all models were optimized using the Adam optimizer, with a fixed batch size of 256. Model parameters were initialized using the default Xavier initializer, with an initial learning rate of 0.01. The embedding dimension of all models was fixed to 100. For hyperparameter selection, a grid search method was employed, which involves traversing a given parameter grid to find the optimal parameter settings. This involves exploring different ranges and combinations of parameter values and utilizing a validation set to help evaluate model performance.
[0135] In this experiment, a comprehensive comparative experiment was conducted on WN18RR-N1. The experimental results are shown in Table 2.
[0136] Table 2 Experimental results on WN18RR-N1
[0137]
[0138]
[0139] An analysis of the results in Table 2 shows that the FuKCE model significantly outperforms other methods regardless of the value of K. Specifically, in terms of Precision@K and Recall@K, FuKCE demonstrates extremely strong performance at all K values. In particular, when K = 1%, FuKCE achieves a high score of 0.942 for Precision@K, far exceeding all other models. When K = 5%, Precision@K drops slightly to 0.598, but it remains the highest among all models. This superiority demonstrates that the FuKCE model is highly robust and stable in terms of accuracy, maintaining its leading position across different K values.
[0140] UPGAT uses an enhanced attention mechanism to learn knowledge graph representations. While its performance is outstanding compared to other models, it is still inferior to the FuKCE method provided in this example. This is because UPGAT applies attention mechanisms from the perspectives of entities and relationships respectively. However, uncertainty in knowledge graphs typically occurs at the triple level. That is, entities naturally exist in the knowledge graph, and errors are often caused by mismatches between the head and tail entities and their corresponding relationships. Therefore, FuKCE uses triple-level embeddings as input and can effectively filter out highly ambiguous triplets.
[0141] As can be seen from the above content, the loss function of this embodiment mainly consists of two parts: fuzzy RDF KG embedding loss and contrastive learning loss. In this experiment, an ablation study was conducted based on the above content. In the two variants Variant_Kge and Variant_Con, only the translation-based fuzzy RDF KG embedding loss (i.e., negative sampling) and contrastive learning loss were used to train the model. The experimental results are shown in Table 3:
[0142] Table 3 Experimental results of ablation study
[0143]
[0144] Table 3 shows that the performance of the variant Var_Kge, which uses only the fuzzy RDF KG embedding loss, decreases across different k values. Precision, in particular, begins to drop significantly after ratio = 0.005. This indicates that while the knowledge graph embedding loss helps identify anomalies, it is less effective than the model combined with contrastive learning. The variant Var_Con, which uses only the contrastive learning loss, only produces results at k = 0.1%. This is because Var_Con relies primarily on the relative similarity between pairs of samples and fails to incorporate the global structural information of Var_Kge. When the feature differences between anomalies and normal samples are small, the model is unable to effectively distinguish between them. This results in saturated recognition of anomalies within a small top_k range, and further inability to distinguish between anomalies and normal samples in subsequent ratios. This suggests that models relying solely on contrastive learning loss lack the ability to capture anomalies globally, and are prone to instability and shortcomings in detection. Therefore, the limitations of these two loss functions indicate that in the anomaly detection task, a model with a single loss function is difficult to perform well in all scenarios. The method combining contrastive learning and knowledge graph embedding loss can better balance local features and global structures, thereby improving the overall performance of the model.
[0145] In order to explore the effect of the FuKCE model provided in this embodiment under different fuzzy triple ratios, experiments were carried out on WN18RR-N1, WN18RR-N2 and WN18RR-N3 respectively, and the experiments used the optimal parameter combination (i.e., the aforementioned Learning rate (lr) = 0.01, Margin (γ) = 0.1, Attention threshold (μ) = 0.001, τ = 0.5).
[0146] Experimental results show that Precision@K across different datasets shows a gradual downward trend as the proportion of fuzzy triples increases. WN18RR-N3 achieves the highest Precision across all K values, demonstrating that FuKCE can maintain high accuracy even when uncertainty levels are high. This is due to the method's fuzziness handling capabilities. When the proportion of negative triples is high, the impact of fuzzy triplets on the results is reduced by better distinguishing the embedding space. WN18RR-N1 performs the worst in Precision@K, likely because the model does not fully exploit the advantages of fuzziness at low uncertainty levels, resulting in slightly lower accuracy in practical applications. The performance trends of Recall@K across different datasets are relatively consistent, all gradually improving with increasing K values. Unlike Precision@K, Recall@K focuses more on the coverage of retrieval results, so as K increases, Recall naturally increases.
[0147] Overall, the FuKCE model shows a certain robustness on KGs with different ambiguity levels. The results of Precision@K and Recall@K show that as the ambiguity ratio increases, the model shows a balance between precision and recall.
[0148] Prior art fuzzy knowledge graph embedding methods primarily rely on synthetic negative triples to train models, generating negative triples by replacing the head or tail entity in a triple with a random entity. However, the method provided in this embodiment introduces contrastive learning, which does not require synthetic negative triples, to train the model. This method combines fuzzy RDF KG embedding loss with contrastive learning loss for joint training, thereby learning the degree of uncertainty in fuzzy triples. This results in a more effective model and further improves the quality of fuzzy knowledge graph embedding.
[0149] See Figure 6 , an embodiment of the present invention provides a fuzzy knowledge graph comparison and embedding device 600, comprising:
[0150] A construction module 601 is configured to construct a first view and a second view based on a fuzzy knowledge graph, wherein the fuzzy knowledge graph includes a plurality of triples, the first view being configured to represent the correlation between the plurality of triples from the perspective of a head entity, and the second view being configured to represent the correlation between the plurality of triples from the perspective of a tail entity;
[0151] An encoding module 602 is configured to encode the triples in the first view using a knowledge graph embedding model to obtain a first embedding, and to encode the triples in the second view using the knowledge graph embedding model to obtain a second embedding;
[0152] A training module 603 is used to train the knowledge graph embedding model based on fuzzy RDF KG embedding loss and contrastive learning loss to obtain a trained knowledge graph embedding model;
[0153] The acquisition module 604 is used to obtain the knowledge graph embedding based on the trained knowledge graph embedding model.
[0154] Optionally, the building module 601 includes:
[0155] a processing unit, configured to treat each triple of the plurality of triples as a node;
[0156] A connection unit is used to connect the first node and the second node to obtain the first view, and connect the third node and the fourth node to obtain the second view, wherein the triples corresponding to the first node and the second node have the same head entity, and the triples corresponding to the third node and the fourth node have the same tail entity.
[0157] Optionally, the encoding module 602 includes:
[0158] a first acquiring unit, configured to acquire, for each first triple in the first view, a first initial embedding of the first triple;
[0159] A first updating unit is configured to update the first initial embedding based on attention coefficients of neighboring triples of the first triple to obtain the first embedding.
[0160] Optionally, the encoding module 602 includes:
[0161] a second acquiring unit, configured to acquire, for each second triple in the second view, a second initial embedding of the second triple;
[0162] A second updating unit is configured to update the second initial embedding based on the attention coefficients of neighboring triples of the second triplet to obtain the second embedding.
[0163] Optionally, the fuzzy knowledge graph comparison and embedding device 600 further includes:
[0164] a processing module, configured to use triples in the fuzzy knowledge graph as positive example triples;
[0165] A replacement module, configured to randomly replace the entity relations and relations of the positive triples with other entities and relations to obtain negative triples;
[0166] A calculation module is used to calculate the fuzzy RDF KG embedding loss based on the difference score of the positive example triple and the difference score of the negative example triple.
[0167] Optionally, the contrastive learning loss is determined based on the similarity between the first embedding and the second embedding corresponding to the triple in the fuzzy knowledge graph.
[0168] Optionally, the contrastive learning loss is:
[0169]
[0170] Among them, {x1,x2,...,x n} represents the first embedding corresponding to n triples in the fuzzy knowledge graph, {z1,z2,...,z n} represents the second embedding corresponding to n triples in the fuzzy knowledge graph, (x i ,z i) represents the first embedding corresponding to the i-th triple in the fuzzy knowledge graph and the second embedding corresponding to the i-th triple in the fuzzy knowledge graph, τ represents the temperature parameter, sim(x i ,z i ) represents x i and z i The cosine similarity of , n is an integer greater than 2, and i is an integer less than or equal to n.
[0171] The fuzzy knowledge graph comparison and embedding device 600 provided in the embodiment of the present application can execute the above-mentioned method embodiment, and its implementation principle and technical effects are similar, which will not be repeated here in this embodiment.
[0172] It should be noted that the division of units in the embodiments of the present application is schematic and is merely a logical functional division. In actual implementation, other division methods may be used. Furthermore, the functional units in the various embodiments of the present application may be integrated into a single processing unit, or each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or software functional units.
[0173] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a processor-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for enabling a computer device (which can be a personal computer, server, or network device, etc.) or a processor to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0174] like Figure 7 As shown, an embodiment of the present application provides an electronic device 700, including: a memory 702, a processor 701, and a program stored on the memory 702 and executable on the processor 701; the processor 701 is used to read the program in the memory 702 to implement the steps in the fuzzy knowledge graph comparison embedding method as described above.
[0175] An embodiment of the present application also provides a readable storage medium, on which a program is stored. When the program is executed by a processor, the various processes of the above-mentioned fuzzy knowledge graph comparison and embedding method embodiment are implemented, and the same technical effect can be achieved. To avoid repetition, it will not be repeated here. Among them, the readable storage medium can be any available medium or data storage device that can be accessed by the processor, including but not limited to magnetic storage (such as floppy disk, hard disk, magnetic tape, magneto-optical disk (MO), etc.), optical storage (such as compact disk (CD), digital video disc (DVD), Blu-ray disc (BD), high-definition versatile disc (HVD), etc.), and semiconductor memory (such as read-only memory (ROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read only memory (EEPROM), non-volatile memory (NAND FLASH), solid state drive (SSD), etc.).
[0176] It should be noted that, in this document, the terms "comprises," "includes," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a process, method, article, or apparatus comprising a series of elements includes not only those elements but also other elements not explicitly listed, or elements inherent to such process, method, article, or apparatus. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of other identical elements in the process, method, article, or apparatus comprising the element.
[0177] Through the description of the above embodiments, those skilled in the art can clearly understand that the above embodiment methods can be implemented by means of software plus the necessary general hardware platform, and of course can also be implemented by hardware, but in many cases the former is a better embodiment. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, disk, CD-ROM), and includes a number of instructions for enabling a terminal (which can be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in each embodiment of the present application.
[0178] The embodiments of the present application are described above in conjunction with the accompanying drawings, but the present application is not limited to the above-mentioned specific implementation methods. The above-mentioned specific implementation methods are merely illustrative and not restrictive. Under the guidance of this application, ordinary technicians in this field can also make many forms without departing from the purpose of this application and the scope of protection of the claims, all of which are within the protection of this application.
Claims
1. A fuzzy knowledge graph contrast embedding method, characterized by: include: Constructing a first view and a second view based on a fuzzy knowledge graph, wherein the fuzzy knowledge graph includes a plurality of triples, the first view being used to represent the correlation between the plurality of triples from the perspective of a head entity, and the second view being used to represent the correlation between the plurality of triples from the perspective of a tail entity; Encoding the triples in the first view using a knowledge graph embedding model to obtain a first embedding, and encoding the triples in the second view using the knowledge graph embedding model to obtain a second embedding; Training the knowledge graph embedding model based on fuzzy RDF KG embedding loss and contrastive learning loss to obtain a trained knowledge graph embedding model; Obtain knowledge graph embedding based on the trained knowledge graph embedding model.
2. The method according to claim 1, wherein: The constructing of the first view and the second view based on the fuzzy knowledge graph includes: Taking each triple in the plurality of triples as a node; The first view is obtained by connecting the first node and the second node, and the second view is obtained by connecting the third node and the fourth node. The triples corresponding to the first node and the second node have the same head entity, and the triples corresponding to the third node and the fourth node have the same tail entity.
3. The method according to claim 1, wherein: The step of encoding the triples in the first view using the knowledge graph embedding model to obtain a first embedding includes: For each first triple in the first view, obtaining a first initial embedding of the first triple; The first initial embedding is updated based on the attention coefficients of neighboring triplets of the first triplet to obtain the first embedding.
4. The method according to claim 1, wherein: The step of encoding the triples in the second view by using the knowledge graph embedding model to obtain a second embedding includes: For each second triplet in the second view, obtaining a second initial embedding of the second triplet; The second initial embedding is updated based on the attention coefficients of neighboring triplets of the second triplet to obtain the second embedding.
5. The method according to claim 1, wherein: Before training the knowledge graph embedding model based on the fuzzy RDF KG embedding loss and the contrastive learning loss to obtain the trained knowledge graph embedding model, the method further includes: Taking the triples in the fuzzy knowledge graph as positive triples; Randomly replacing the entity relations and relations of the positive triples with other entities and relations to obtain negative triples; The fuzzy RDFKG embedding loss is calculated based on the difference score of the positive triple and the difference score of the negative triple.
6. The method according to any one of claims 1 to 5, wherein: The contrastive learning loss is determined based on a similarity between the first embedding and the second embedding corresponding to a triple in the fuzzy knowledge graph.
7. The method according to claim 6, wherein: The contrastive learning loss is: Among them, {x1,x2,...,x n } represents the first embedding corresponding to n triples in the fuzzy knowledge graph, {z1,z2,...,z n } represents the second embedding corresponding to n triples in the fuzzy knowledge graph, (x i ,z i ) represents the first embedding corresponding to the i-th triple in the fuzzy knowledge graph and the second embedding corresponding to the i-th triple in the fuzzy knowledge graph, τ represents the temperature parameter, sim(x i ,z i ) represents x i and z i The cosine similarity of , n is an integer greater than 2, and i is an integer less than or equal to n.
8. A fuzzy knowledge graph comparison and embedding device, characterized by: include: a construction module, configured to construct a first view and a second view based on a fuzzy knowledge graph, wherein the fuzzy knowledge graph includes a plurality of triples, the first view being configured to represent the correlation between the plurality of triples from the perspective of a head entity, and the second view being configured to represent the correlation between the plurality of triples from the perspective of a tail entity; an encoding module, configured to encode the triples in the first view using a knowledge graph embedding model to obtain a first embedding, and to encode the triples in the second view using the knowledge graph embedding model to obtain a second embedding; A training module, configured to train the knowledge graph embedding model based on fuzzy RDF KG embedding loss and contrastive learning loss to obtain a trained knowledge graph embedding model; An acquisition module is used to obtain knowledge graph embedding based on the trained knowledge graph embedding model.
9. An electronic device comprising: A memory, a processor, and a program stored in the memory and executable on the processor; wherein the processor is configured to read the program in the memory to implement the steps of the fuzzy knowledge graph comparison and embedding method as described in any one of claims 1 to 7.
10. A readable storage medium for storing a program, characterized in that: When the program is executed by a processor, the steps of the fuzzy knowledge graph comparison and embedding method as described in any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Fuzzy space-time RDF storage management method based on graph database Neo4j
CN117520582A
Fuzzy knowledge graph embedding method and device, electronic equipment and readable storage medium
CN118747525A