A knowledge graph completion method based on a pre-trained language model

By integrating a multi-perspective generation paradigm and a re-evaluation model, the problem of insufficient modeling of knowledge graph structural information in existing technologies is solved, achieving transparent and interpretable knowledge graph completion and improving prediction accuracy.

CN120578769BActive Publication Date: 2026-11-27BEIJING INST OF TECH
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202510489027.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-04-18
Publication Date
2026-11-27
Estimated Expiration
2045-04-18

AI Technical Summary

Technical Problem

Existing knowledge graph completion methods based on pre-trained language models rely excessively on the textual information of triples, lack modeling of the structural information of knowledge graphs, and lack the ability to model and perceive global and multi-hop structures. This results in closed black boxes of prediction results, lacking a visible reasoning process and human-readable interpretability.

Method used

A multi-perspective generation paradigm is constructed. Relevant triples are obtained through a neighbor selection model and inserted into the text sequence. The target entity is generated at the triple level and the path level by combining a pre-trained language model. The results are fused and ranked using a re-evaluation model to achieve a transparent and interpretable reasoning process.

Benefits of technology

It effectively captures local triples and deep path structure knowledge, improves prediction accuracy, achieves transparent and interpretable knowledge graph completion, and enhances performance on the WN18RR and FB15K-237 datasets.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120578769B_ABST
    Figure CN120578769B_ABST
Patent Text Reader

Abstract

The application provides a knowledge graph completion method based on a pre-trained language model, comprising the following steps: S1, constructing a text sequence of a query pair given an input query pair; S2, obtaining a plurality of neighbor triples most relevant to the query pair through a neighbor selection model, and inserting the neighbor triples into the tail of the text sequence of the query pair to form a new text sequence; S3, adding instruction labels to the new text sequence, and inputting the new text sequence into a pre-trained language model to generate a target entity sequence at a triple level and a path level; and S4, determining two groups of target entities generated at the triple level and the path level, and if the determination result is consistency prediction, taking the prediction at the path level as the final prediction output. The application can enable the pre-trained language model to generate in multiple perspectives, effectively improve the knowledge graph completion capability of the pre-trained language model, and realize the explainability of the prediction result.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the fields of natural language processing and knowledge graph technology, and in particular to a knowledge graph completion method based on a pre-trained language model. Background Technology

[0002] Knowledge graphs aim to provide a robust data organization for storing, managing, querying, and retrieving massive amounts of information on the internet, playing a crucial supporting role in numerous downstream fields. However, despite the continuous growth in the number and scale of current knowledge graphs (e.g., DBpedia, Freebase, NELL, YAGO), they often suffer from incompleteness due to limitations in their knowledge capacity. Therefore, employing appropriate automated knowledge graph completion algorithms to mine potential ternary relations within knowledge graphs is of great significance. Among these, link prediction for entities and relations is one of the core technologies of knowledge graph completion, aiming to predict the links between entities and relations given a query pair. By combining existing knowledge in the knowledge graph, we can predict possible tail entities. To achieve the understanding of potential ternary relations in knowledge graphs. The excavation.

[0003] Traditional knowledge graph completion methods mainly target the symbol rules or structural embedding of knowledge graphs, construct logical systems or representation spaces, and use these systems or spaces to mine potential missing triple relations in knowledge graphs. However, they lack the representation and understanding of the semantic level of knowledge, resulting in a relative gap between knowledge graph representation learning and natural language processing tasks. With the deep development of language models, the combination of knowledge graph tasks and language models has emerged, showing strong generalization performance and higher prediction accuracy. For example, reference [1] inputs the text representation of the triple to be tested into the encoder-based pre-trained language model BERT to predict the truth value of the candidate triple from the perspective of text representation. On this basis, reference [2] constructs a dual-tower encoding model of query pairs and candidate entities and introduces the descriptive text of the entities. By sharing the encoding of candidate entities, the computational space consumption is greatly reduced, and the prediction accuracy is effectively improved. Unlike the above approaches, reference [3] constructs an encoder-decoder prediction generation framework, which uses the text and description information of the query triple as encoding information and generates the predicted target tail entity through the decoder end of the model, effectively utilizing the generation capability of the language model.

[0004] However, existing knowledge graph completion methods based on pre-trained language models rely excessively on the textual information of triples and are insufficient in modeling the structural information of knowledge graphs. This problem becomes more acute after further introducing entity descriptions. Although some literature [4] distinguishes between textual knowledge and knowledge graph knowledge through soft hint engineering, or independently models the embedding representation of entities and relations and integrates or distills this embedding rich in structural information into the language model, their indirect modeling methods not only lead to error accumulation problems, but also restrict the language model from directly modeling and understanding the structural information of knowledge graphs. Furthermore, they lack the ability to model and perceive the global and multi-hop structures of knowledge graphs, thus restricting the further improvement of the performance of such methods. In addition, the prediction results of current methods are closed black boxes, which do not give full play to the generative ability of language models, lack a visible reasoning process or human-readable interpretability, and damage the credibility of the prediction results.

[0005] References:

[0006] [1]Yao L, Mao C, Luo Y. KG-BERT: BERT for knowledge graph completion[J]. arXiv preprint arXiv:1909.03193, 2019. DOI: 10.48550 / arXiv.1909.03193.

[0007] [2]Wang L, Zhao W, Wei Z, et al. SimKGC: Simple Contrastive KnowledgeGraph Completion with Pre-trained Language Models[C] / / Proceedings of the 60thAnnual Meeting of the Association for Computational Linguistics (Volume 1:Long Papers). 2022: 4281-4294. DOI: 10.18653 / v1 / 2022.acl-long.295.

[0008] [3]Saxena A, Kochsiek A, Gemulla R. Sequence-to-Sequence KnowledgeGraph Completion and Question Answering[C] / / Proceedings of the 60th AnnualMeeting of the Association for Computational Linguistics (Volume 1: LongPapers). 2022: 2814-2828. DOI: 10.18653 / v1 / 2022.acl-long.201.

[0009] [4]Lv 10.18653 / v1 / 2022.findings-acl.282. Summary of the Invention

[0010] To address the aforementioned problems, this invention proposes a knowledge graph completion method based on a pre-trained language model, comprising:

[0011] S1, Given the input query pair Construct the text sequence of query pairs;

[0012] S2. Obtain several neighbor triples that are most relevant to the query pair through the neighbor selection model, and insert them into the end of the text sequence of the query pair to form a new text sequence.

[0013] S3. Add instruction labels to the new text sequence and input them into the pre-trained language model. Use a multi-view generation paradigm to generate target entity sequences at the triple level and path level.

[0014] S4. Determine the two sets of target entities generated at the triplet level and the path level. If the determination result is a consistent prediction, take the path level prediction as the final prediction output.

[0015] Furthermore, in step S1, the text sequence includes query pairs. Entity name, entity description text, relation Corresponding knowledge soft hint vector rows The relation name is defined, where the knowledge soft hint matrix corresponding to the knowledge soft hint vector row is updated during the training of the pre-trained language model.

[0016] Furthermore, in step S2, the neighbor selection model includes an encoder and a decoder, and the training method includes:

[0017] S21. Select triples adjacent to the query pairs in the knowledge graph and the training set to form an adjacency set. ;

[0018] S22. Treat triples in the adjacency set that contain the target entity corresponding to the query pair as positively correlated samples, and other triples as negatively correlated samples; train the neighbor selection model based on the positive and negatively correlated samples.

[0019] Furthermore, in step S22, the contrastive loss function used for training is:

[0020] ,in, This represents the input concatenated text vector. As the interval factor, This represents the set of decoding scores for negative samples. This represents the set of decoding scores for positive samples. This represents the decoding score of the neighbor selection model for the current triple prediction. .

[0021] Furthermore, in S3, the training method for the pre-trained language model is as follows:

[0022] Using triples from the knowledge graph and triples with paths as training data, the pre-trained language model is trained. The loss function is the same for both perspectives: ,in, Represents the length of the decoder's predicted sequence. Given a sequence of text as input, for The process involves generating characters step by step; then, the parameters of the pre-trained language model, including the knowledge soft hint matrix, are adjusted using the backpropagation algorithm. .

[0023] Furthermore, in S4, if the entity ranked first in the prediction set from the triplet perspective is the same entity as the entity ranked first in the path-level prediction, then the prediction is called a consistent prediction.

[0024] Furthermore, in S4, if the number of entities predicted from the triplet perspective... Or the number of identical entities predicted by the two perspectives is less than If the prediction is not accurate, it is considered difficult to predict. If the prediction is difficult to predict, the two sets of target entities are re-evaluated, merged, and sorted by confidence score to obtain the final prediction result.

[0025] Furthermore, in S4, re-evaluation is performed through a re-evaluation model, which consists of a dual-tower model based on the encoder. The training methods for the re-evaluation model include:

[0026] S41. Treat all triples in the knowledge graph as positive training examples and construct fake triples as negative examples.

[0027] S42. Select all triples from the training set. Split into query pairs With the target entity Two parts, input into the re-evaluation model for encoding;

[0028] S43. Calculate the cosine similarity between the two sets of encoded features and use it as a triple. Score the confidence level as true;

[0029] S44. Use contrastive learning to train the re-evaluation model and minimize the cosine distance between the query pair of the true triple and the target entity.

[0030] Furthermore, in S44, the training objective of the re-evaluation model is to minimize the cosine distance between the query pairs and the target entity for all positive sample triples. The contrastive learning loss function used during training is:

[0031] ,in, This is used as a margin factor to ensure that the model increases the scores of positive samples. This is a temperature coefficient used to adjust the relative importance of negative samples.

[0032] Furthermore, in S4, if the evaluation result is neither a consistent prediction nor a difficult prediction, then the path-level prediction is taken as the final prediction output.

[0033] The beneficial effects of this invention are as follows:

[0034] (1) This invention proposes a new multi-perspective generation paradigm that can effectively capture local triple-level knowledge and far-reaching path structure knowledge, and can simultaneously model textual and structural information, thus realizing a transparent and interpretable reasoning process.

[0035] (2) This invention proposes a re-evaluation model and a heuristic fusion ranking strategy for triples generated from multiple perspectives and two sets of inference results on the path. Through efficient cross-validation and fusion of multi-perspective generation results, the performance of inference is further improved.

[0036] (3) The present invention has achieved excellent performance on two standard datasets, WN18RR and FB15K-237, and has enabled the knowledge graph completion results to have a human-readable reasoning process. Attached Figure Description

[0037] To more clearly illustrate the technical solutions in the embodiments of this disclosure or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this disclosure. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0038] Figure 1 This is a flowchart illustrating a knowledge graph completion method based on a pre-trained language model according to an embodiment of the present invention.

[0039] Figure 2 This is a schematic diagram of the training process of a neighbor selection model according to an embodiment of the present invention;

[0040] Figure 3 This is a schematic diagram of a multi-view prediction generation process according to an embodiment of the present invention;

[0041] Figure 4 This is a flowchart illustrating a heuristic fusion strategy according to an embodiment of the present invention;

[0042] Figure 5 This is a schematic diagram of the training process of a re-evaluation model according to an embodiment of the present invention. Detailed Implementation

[0043] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be reviewed and described in detail below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0044] This invention provides a method for knowledge graph completion based on a pre-trained language model. The pre-trained language model can be a sequence-to-sequence encoder-decoder structure model such as T5 or BART. Figure 1 As shown, the method includes the following steps:

[0045] S1, Given the input query pair Construct the text sequence of query pairs;

[0046] S2. Obtain several neighbor triples that are most relevant to the query pair through the neighbor selection model, and insert them into the end of the text sequence of the query pair to form a new text sequence.

[0047] S3. Add instruction labels to the new text sequence and input them into the pre-trained language model for encoding. Adopt a multi-view generation paradigm, and the decoder alternately generates target entity sequences at the triple level and the path level.

[0048] S4. Determine the two sets of target entities generated at the triplet level and the path level. If the determination result is a consistent prediction, take the prediction at the path level as the final prediction output.

[0049] If the judgment result is difficult to predict, the two sets of target entities are re-evaluated, then merged and sorted to obtain the final prediction result;

[0050] If the evaluation result is a general prediction, then the path-level prediction is taken as the final prediction output.

[0051] In step S1, To query the correct entity, To query the relationships between pairs, and to distinguish between knowledge graph knowledge and natural language text knowledge, emphasizing the structural knowledge of knowledge graphs, this invention introduces a knowledge soft hint matrix. ,in This represents the number of relations in the knowledge graph. This represents the dimension of the pre-trained language model. As part of the parameters of the pre-trained language model, they are learned and updated synchronously during the training process of the pre-trained language model. When constructing the input, the query pair is... Entity name, entity description text, relation Corresponding knowledge soft hint vector rows The relation names are concatenated in order to form a sequence of input text. For example, given the query pair "(Diamond Head, located at)", the corresponding text sequence is "Diamond Head [Diamond Head is an extinct volcano, its peak resembling a giant water lily leaf.] < Located at <mask>",in" <mask>"Indicates the target entity that needs to be predicted" The covering.

[0052] In step S2, to fully explore and utilize the structural knowledge of the knowledge graph and the contextual information of the query pairs, this invention designs a neighbor selection model based on encoder-decoder to score and filter the relevance between the query pair and its adjacent triples. For example... Figure 2 As shown, the methods for training the neighbor selection model include:

[0053] S21. Select triples adjacent to the query pairs in the knowledge graph and the training set to form an adjacency set. ;

[0054] S22. Treat triples in the adjacency set that contain the target entity corresponding to the query pair as positively correlated samples, and other triples as negatively correlated samples; train the neighbor selection model based on the positive and negatively correlated samples.

[0055] In step S21, the entities of the query pair are selected from the knowledge graph. Surrounding Triples in an adjacency subgraph constitute an adjacency set. :

[0056]

[0057] In the above formula, and Representing the first Entities or relations of order.

[0058] In step S22, the adjacency set is... Triples containing the target entity corresponding to the query pair are considered positively correlated examples, while triples not containing the target entity are considered negatively correlated examples. These two sets of examples are then used as the training sample set. Then, the query pair... The text is concatenated with the text of each triple in the neighbor set, and then fed into the encoder of the neighbor selection model for joint encoding. The decoder then determines the relevance between the two texts, with the determination target being... , This indicates that the triple is irrelevant to the query pair. This indicates that the triple is relevant to the query pair. Then, based on the positive and negative labels of the adjacent triples, the neighbor selection model is trained using the following contrastive loss function:

[0059]

[0060] In the above formula, This represents the input concatenated text vector. As the interval factor, This represents the set of decoding scores for negative samples. This represents the set of decoding scores for positive samples. This represents the decoding score of the neighbor selection model for the current triple prediction. , which is the relevance probability predicted by the decoder of the neighbor selection model.

[0061] After training, the neighbor selection model is responsible for calculating the relevance between all neighbor triples and the query pair during the prediction process of the pre-trained language model, and selecting the neighbor with the highest relevance. The relevant set consists of three triples. They are concatenated to the end of the query text sequence to form a new input text sequence.

[0062] In step S3, to distinguish the generation perspective of the current round, this invention defines instruction tags respectively. and The instructions "Predict tail / head entity:" and "Predict tail / head entity with path:" serve as guidance for the decoder of the current pre-trained language model to generate text from a triple or path perspective, and are inserted at the beginning of the new input text sequence to form a new input text sequence. Subsequently, as Figure 3 As shown, to enable a pre-trained language model to simultaneously understand the local knowledge of triples and the deep knowledge of multiple hops, especially through reasoning via multi-hop paths, and to visualize the reasoning process, the input text sequence is presented. The input is encoded in the encoder of a pre-trained language model, while the decoder alternately generates the target entity from the perspectives of triples and paths. The predicted sequence. For example... Figure 3 As shown, the methods for generating predictions include:

[0063] S31, Encoding Input Text Sequence It directly generates all possible target entities, forming a set of predicted target entities from the perspective of triples. ;

[0064] In this step, the decoder simultaneously generates the name and description of the target entities, forming a set of target entities. For example, given the query pair "(Diamond Head, located in)", the generated sequence from the triple perspective is "Hawaii [is an archipelago state consisting of 132 islands in the central Pacific Ocean]", where the predicted target entity is... It means "Hawaii".

[0065] S32, Encoding the input text sequence It generates a multi-hop inference path starting from the query entity, along with the target entity name and description, forming a predicted target entity set from the path perspective. .

[0066] In this step, the decoder simultaneously generates a multi-hop inference path from the head entity to the tail entity, the name of the target entity, and a textual description of the target entity, forming a target entity set. For example, given the query pair "(Diamond Head, located in)", the path-level generated sequence is "Diamond Head  located in  Oahu  located in Honolulu  located in  Hawaii [is an archipelago consisting of 132 islands in the central Pacific Ocean]", where the predicted target entity is... It means "Hawaii".

[0067] The training method for the pre-trained language model is as follows: using triples and paths in the knowledge graph as training data, the pre-trained language model is trained. The loss function from both perspectives can be expressed as: ,in, This represents the length of the decoder's predicted sequence. Given a sequence of text as input, for The process involves generating characters step by step; then, the parameters of the pre-trained language model, including the knowledge soft hint matrix, are adjusted using the backpropagation algorithm. .

[0068] In step S4, as Figure 4 As shown, this invention proposes a heuristic fusion ranking strategy for cross-validating and merging two sets of results generated from different perspectives. Specifically, it performs fair confidence scoring on both sets of results within a unified framework, and then merges and ranks the results based on the scores. This aims to further improve the prediction accuracy and richness of the pre-trained language model through cross-validation of the two sets of prediction results. The fusion ranking strategy includes:

[0069] (1) If the entity ranked first in the prediction set from the perspective of triples If the entity is ranked first according to the path-level prediction. If the targets are the same entity, the prediction is called a consistent prediction. A consistent prediction indicates that the lists of target entities predicted from two perspectives are relatively consistent, making it a relatively simple prediction task. In this case, the path-level prediction result can be directly selected. This final prediction result is output without re-evaluation. The final output is then represented as:

[0070]

[0071] (2) If the number of entities predicted from the perspective of triples Or the number of identical entities predicted by the two perspectives is less than If the prediction fails, it is called a difficult prediction. A difficult prediction indicates a significant discrepancy between the predictions from the two perspectives, making it a more challenging prediction. Therefore, it is necessary to analyze the generated sets of target entities. and A re-evaluation model is used to apply a unified confidence score, which is then merged and sorted by confidence score for cross-validation of the two perspectives. The final output is a set of entities resulting from the merging of the two predictions and sorting by score.

[0072]

[0073] in, and As a predefined threshold, the experimental verification below... The value is 5. The value is 10.

[0074] (3) Results that are neither consistent predictions nor difficult predictions can be regarded as general predictions. To simplify the calculation, the path-level prediction results are directly used in this case. As the final output, that is: .

[0075] In strategy (2), the re-evaluation operation of the re-evaluation model requires additional computational overhead. Therefore, it is necessary to identify which predictions do not need to be re-evaluated in order to reduce the number of re-evaluation triples and unnecessary computation. The re-evaluation model consists of a dual-tower model based on an encoder, which evaluates the result set... and Conduct fair confidence scoring within a unified framework, such as... Figure 5 As shown, the training methods for the re-evaluation model include:

[0076] S41. Treat all triples in the knowledge graph as positive training examples and construct fake triples as negative examples.

[0077] S42. Select all triples from the training set. Split into query pairs With the target entity Two parts, input into the re-evaluation model for encoding;

[0078] S43. Calculate the cosine similarity between the two sets of encoded features and use it as a triple. Score the confidence level as true;

[0079] S44. Use contrastive learning to train the re-evaluation model and minimize the cosine distance between the query pair of the true triple and the target entity.

[0080] In step S41, existing triples in the knowledge graph are considered as positive examples, and spurious triples that do not exist in the knowledge graph are constructed. And are considered as negative examples; positive and negative examples together constitute the training sample set, where Entities randomly selected from the knowledge graph, but not related to the query pair They cannot be combined to form actual triples in a knowledge graph.

[0081] In step S42, the query pair is re-evaluated. The text and description information are encoded, and the output features are max-pooled to obtain the encoded feature vector of the query pair. For the target entity The text and descriptive information are encoded to obtain the encoded feature vector of the target entity. .

[0082] In step S43, the cosine similarity between any query pair and the target entity is calculated using the cosine distance, as shown in the following formula:

[0083]

[0084] In step S44, the training objective of the re-evaluation model is to minimize the cosine distance between the query pairs and the target entity for all positive sample triples. Therefore, the re-evaluation model is trained using the following contrastive learning loss function:

[0085]

[0086] in, This is used as a margin factor to ensure that the model increases the scores of positive samples. This is a temperature coefficient used to adjust the relative importance of negative samples.

[0087] The trained re-evaluation model can be used in strategy (2) for the re-evaluation and ranking of hard-to-predict results. Specifically, the entity set is taken. All target entities and their corresponding query pairs Both are input into the re-evaluation model to obtain the cosine similarity between them, which is then used as the evaluation score. Finally, all entities within the set are sorted based on their evaluation scores to obtain the final ordered set. As the final output.

[0088] Finally, the pre-trained language model outputs a set of predicted target entities. High score Each entity and the input query pair Forming a triplet The newly discovered triples are inserted into the original knowledge graph, and the multi-hop paths generated from the path perspective can serve as visual evidence of the triples, thereby achieving transparent and interpretable completion of the knowledge graph.

[0089] Experimental verification

[0090] In one embodiment, the datasets used are the WN18RR dataset and the FB15K-237 dataset. WN18RR is a more challenging dataset obtained by removing multiple test leak source relationships and triples from the original WN18 dataset. FB15K-237 is a more realistic dataset obtained by removing additional interdependent relationships from the FB15K dataset.

[0091] This invention effectively enhances the performance of pre-trained language models on the WN18RR and FB15K-237 datasets. Specifically, this invention uses T5 as the base model for experiments, namely: S1, given an input query pair, construct the text sequence of the query pair; S2, the neighbor selection model obtains the most relevant neighbor triples to the query pair and inserts them at the end of the text sequence of the query pair; S3, the text sequence is input into the encoder for encoding, and the answer entity is generated at both the triple level and the path level using a multi-view generation paradigm; S4, the re-evaluation model evaluates, verifies, and merges the two sets of answer entities generated at the triple level and the path level, and then outputs the final prediction result.

[0092] This invention was experimentally validated on two standard datasets. KG-BERT, StAR, GenKGC, KGT5, CoLE, SimKGC, KG-S2S, CSProm-KG, PDKGC, BMKGC, COSIGN, and PEMLM were used as baseline models for comparison on four metrics: MRR, Hits@1, Hits@3, and Hits@10. The experimental results are shown in Tables 1 and 2, respectively.

[0093] The best result is indicated in bold, and the second best result is indicated by underline.

[0094] Table 1 Results on the WN18RR dataset

[0095]

[0096] Table 2 Results on the FB15k-237 dataset

[0097]

[0098] Those skilled in the art will understand that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope defined by the claims of the present invention.< / mask> < / mask>

Claims

1. A knowledge graph completion method based on a pre-trained language model, characterized in that, The method includes: S1. Given an input query pair, construct the text sequence of the query pair; S2. Obtain several neighbor triples that are most relevant to the query pair through the neighbor selection model, and insert them into the end of the text sequence of the query pair to form a new text sequence. S3. Add instruction labels to the new text sequence and input them into the pre-trained language model. Use a multi-view generation paradigm to generate target entity sequences at the triple level and path level. S4. Determine the two sets of target entities generated at the triplet level and the path level. If the determination result is a consistent prediction, take the prediction at the path level as the final prediction output. In step S2, the neighbor selection model includes an encoder and a decoder, and the training method includes: S21. Select triples that are adjacent to the query pairs in the knowledge graph and the training set to form an adjacency set. S22. Treat triples in the adjacency set that contain the target entity corresponding to the query pair as positively correlated samples, and triples that do not contain the target entity as negatively correlated samples with the query pair. Use the two sets of samples as training sample sets. Concatenate the text of the query pair with the text of each triple in the adjacency set and feed them into the encoder of the neighbor selection model for joint encoding. Determine the correlation between the two at the decoder. Then, based on the positive and negative labels of the adjacency triples, use the contrastive loss function to train the neighbor selection model.

2. The knowledge graph completion method according to claim 1, characterized in that, In step S1, the text sequence includes the entity name of the query pair, the entity description text, the knowledge soft hint vector row corresponding to the relation, and the relation name. The knowledge soft hint matrix corresponding to the knowledge soft hint vector row is updated when training the pre-trained language model.

3. The knowledge graph completion method according to claim 1, characterized in that, In step S22, the contrastive loss function for training is: ,in, This represents the input concatenated text vector. As the interval factor, This represents the set of decoding scores for negative samples. This represents the set of decoding scores for positive samples. This represents the decoding score of the neighbor selection model for the current triple prediction. .

4. The knowledge graph completion method according to claim 1, characterized in that, In S3, the training method for the pre-trained language model is as follows: Using triples from the knowledge graph and triples with paths as training data, the pre-trained language model is trained. The loss function is the same for both perspectives: ,in, Represents the length of the decoder's predicted sequence. Given a sequence of text as input, for The system generates characters step by step; then it adjusts the parameters of the pre-trained language model, including the knowledge soft hint matrix, through the backpropagation algorithm.

5. The knowledge graph completion method according to claim 1, characterized in that, In S4, if the entity ranked first in the prediction set from the perspective of triples is the same entity as the entity ranked first in the path-level prediction, then the prediction is called a consistent prediction.

6. The knowledge graph completion method according to claim 1, characterized in that, In S4, if the number of entities predicted from the triplet perspective... Or the number of identical entities predicted by the two perspectives is less than If so, then this prediction is called difficult to predict; If the result is difficult to predict, the two sets of target entities are re-evaluated, then merged and sorted by confidence score to obtain the final prediction result; and This is a predefined threshold.

7. The knowledge graph completion method according to claim 6, characterized in that, In S4, re-evaluation is performed using a re-evaluation model, which consists of a dual-tower model based on an encoder. The training methods for the re-evaluation model include: S41. Treat all triples in the knowledge graph as positive training examples and construct fake triples as negative examples. S42. Select all triples from the training set. Split into query pairs With the target entity Two parts, input into the re-evaluation model for encoding; S43. Calculate the cosine similarity between the two sets of encoded features and use it as a triple. Score the confidence level as true; S44. Use contrastive learning to train the re-evaluation model and minimize the cosine distance between the query pair of the true triple and the target entity.

8. The knowledge graph completion method according to claim 7, characterized in that, In S44, the training objective of the re-evaluation model is to minimize the cosine distance between query pairs and target entities for all positive triplet pairs. The contrastive learning loss function used during training is: ,in, This is used as a margin factor to ensure that the model increases the scores of positive samples. This is a temperature coefficient used to adjust the relative importance of negative samples.

9. The knowledge graph completion method according to claim 6, characterized in that, In S4, if the evaluation result is neither a consistent prediction nor a difficult prediction, then the path-level prediction is taken as the final prediction output.

Citation Information

Patent Citations

  • Single-sample knowledge graph completion method based on path enhancement and entity metric cooperation

    CN117689015A

  • Pre-training language model knowledge graph completion method in combination with comparative learning

    CN117829280A

  • Open knowledge graph completion method and device based on pre-training language model prompt fine tuning

    CN117892807A

  • Knowledge graph completion method and system based on entity description and soft prompt enhancement

    CN118536588A