WO2025200055A1 - 一种知识图谱链路预测方法 - Google Patents

一种知识图谱链路预测方法

Info

Publication number
WO2025200055A1
WO2025200055A1 PCT/CN2024/087157 CN2024087157W WO2025200055A1 WO 2025200055 A1 WO2025200055 A1 WO 2025200055A1 CN 2024087157 W CN2024087157 W CN 2024087157W WO 2025200055 A1 WO2025200055 A1 WO 2025200055A1
Authority
WO
WIPO (PCT)
Prior art keywords
entity
sample
expression
model
relationship
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
PCT/CN2024/087157
Other languages
English (en)
French (fr)
Inventor
钱鹏江
蒋亦樟
姚健
方伟
王闯
邱辰宇
张欣
王士同
范超
陈爱国
顾逸
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Jiangnan University
Original Assignee
Jiangnan University
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Jiangnan University filed Critical Jiangnan University
Priority to GB2512021.3A priority Critical patent/GB2645089A/en
Publication of WO2025200055A1 publication Critical patent/WO2025200055A1/zh
Anticipated expiration legal-status Critical
Pending legal-status Critical Current

Links

Classifications

    • G—PHYSICS
    • G06—COMPUTING OR CALCULATING; COUNTING
    • G06N—COMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N5/00—Computing arrangements using knowledge-based models
    • G06N5/02—Knowledge representation; Symbolic representation
    • G06N5/022—Knowledge engineering; Knowledge acquisition
    • G—PHYSICS
    • G06—COMPUTING OR CALCULATING; COUNTING
    • G06F—ELECTRIC DIGITAL DATA PROCESSING
    • G06F18/00—Pattern recognition
    • G06F18/10—Pre-processing; Data cleansing
    • G—PHYSICS
    • G06—COMPUTING OR CALCULATING; COUNTING
    • G06F—ELECTRIC DIGITAL DATA PROCESSING
    • G06F18/00—Pattern recognition
    • G06F18/20—Analysing
    • G06F18/25—Fusion techniques
    • G—PHYSICS
    • G06—COMPUTING OR CALCULATING; COUNTING
    • G06F—ELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00—Handling natural language data
    • G06F40/10—Text processing
    • G06F40/12—Use of codes for handling textual entities
    • G06F40/151—Transformation
    • G06F40/16—Automatic learning of transformation rules, e.g. from examples
    • G—PHYSICS
    • G06—COMPUTING OR CALCULATING; COUNTING
    • G06F—ELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00—Handling natural language data
    • G06F40/20—Natural language analysis
    • G—PHYSICS
    • G06—COMPUTING OR CALCULATING; COUNTING
    • G06F—ELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00—Handling natural language data
    • G06F40/20—Natural language analysis
    • G06F40/205—Parsing
    • G—PHYSICS
    • G06—COMPUTING OR CALCULATING; COUNTING
    • G06F—ELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00—Handling natural language data
    • G06F40/20—Natural language analysis
    • G06F40/205—Parsing
    • G06F40/216—Parsing using statistical methods
    • G—PHYSICS
    • G06—COMPUTING OR CALCULATING; COUNTING
    • G06F—ELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00—Handling natural language data
    • G06F40/20—Natural language analysis
    • G06F40/279—Recognition of textual entities
    • G—PHYSICS
    • G06—COMPUTING OR CALCULATING; COUNTING
    • G06F—ELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00—Handling natural language data
    • G06F40/20—Natural language analysis
    • G06F40/279—Recognition of textual entities
    • G06F40/284—Lexical analysis, e.g. tokenisation or collocates
    • G—PHYSICS
    • G06—COMPUTING OR CALCULATING; COUNTING
    • G06F—ELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00—Handling natural language data
    • G06F40/20—Natural language analysis
    • G06F40/279—Recognition of textual entities
    • G06F40/289—Phrasal analysis, e.g. finite state techniques or chunking
    • G06F40/295—Named entity recognition
    • G—PHYSICS
    • G06—COMPUTING OR CALCULATING; COUNTING
    • G06F—ELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00—Handling natural language data
    • G06F40/30—Semantic analysis
    • G—PHYSICS
    • G06—COMPUTING OR CALCULATING; COUNTING
    • G06F—ELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00—Handling natural language data
    • G06F40/40—Processing or translation of natural language
    • G—PHYSICS
    • G06—COMPUTING OR CALCULATING; COUNTING
    • G06N—COMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N20/00—Machine learning
    • G—PHYSICS
    • G06—COMPUTING OR CALCULATING; COUNTING
    • G06N—COMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00—Computing arrangements based on biological models
    • G06N3/02—Neural networks
    • G06N3/04—Architecture, e.g. interconnection topology
    • G—PHYSICS
    • G06—COMPUTING OR CALCULATING; COUNTING
    • G06N—COMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00—Computing arrangements based on biological models
    • G06N3/02—Neural networks
    • G06N3/04—Architecture, e.g. interconnection topology
    • G06N3/042—Knowledge-based neural networks; Logical representations of neural networks
    • G—PHYSICS
    • G06—COMPUTING OR CALCULATING; COUNTING
    • G06N—COMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00—Computing arrangements based on biological models
    • G06N3/02—Neural networks
    • G06N3/04—Architecture, e.g. interconnection topology
    • G06N3/044—Recurrent networks, e.g. Hopfield networks
    • G—PHYSICS
    • G06—COMPUTING OR CALCULATING; COUNTING
    • G06N—COMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00—Computing arrangements based on biological models
    • G06N3/02—Neural networks
    • G06N3/04—Architecture, e.g. interconnection topology
    • G06N3/044—Recurrent networks, e.g. Hopfield networks
    • G06N3/0442—Recurrent networks, e.g. Hopfield networks characterised by memory or gating, e.g. long short-term memory [LSTM] or gated recurrent units [GRU]
    • G—PHYSICS
    • G06—COMPUTING OR CALCULATING; COUNTING
    • G06N—COMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00—Computing arrangements based on biological models
    • G06N3/02—Neural networks
    • G06N3/04—Architecture, e.g. interconnection topology
    • G06N3/045—Combinations of networks
    • G—PHYSICS
    • G06—COMPUTING OR CALCULATING; COUNTING
    • G06N—COMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00—Computing arrangements based on biological models
    • G06N3/02—Neural networks
    • G06N3/04—Architecture, e.g. interconnection topology
    • G06N3/045—Combinations of networks
    • G06N3/0455—Auto-encoder networks; Encoder-decoder networks
    • G—PHYSICS
    • G06—COMPUTING OR CALCULATING; COUNTING
    • G06N—COMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00—Computing arrangements based on biological models
    • G06N3/02—Neural networks
    • G06N3/04—Architecture, e.g. interconnection topology
    • G06N3/0464—Convolutional networks [CNN, ConvNet]
    • G—PHYSICS
    • G06—COMPUTING OR CALCULATING; COUNTING
    • G06N—COMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00—Computing arrangements based on biological models
    • G06N3/02—Neural networks
    • G06N3/04—Architecture, e.g. interconnection topology
    • G06N3/047—Probabilistic or stochastic networks
    • G—PHYSICS
    • G06—COMPUTING OR CALCULATING; COUNTING
    • G06N—COMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00—Computing arrangements based on biological models
    • G06N3/02—Neural networks
    • G06N3/04—Architecture, e.g. interconnection topology
    • G06N3/0475—Generative networks
    • G—PHYSICS
    • G06—COMPUTING OR CALCULATING; COUNTING
    • G06N—COMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00—Computing arrangements based on biological models
    • G06N3/02—Neural networks
    • G06N3/04—Architecture, e.g. interconnection topology
    • G06N3/048—Activation functions
    • G—PHYSICS
    • G06—COMPUTING OR CALCULATING; COUNTING
    • G06N—COMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00—Computing arrangements based on biological models
    • G06N3/02—Neural networks
    • G06N3/08—Learning methods
    • G—PHYSICS
    • G06—COMPUTING OR CALCULATING; COUNTING
    • G06N—COMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00—Computing arrangements based on biological models
    • G06N3/02—Neural networks
    • G06N3/08—Learning methods
    • G06N3/084—Backpropagation, e.g. using gradient descent
    • G—PHYSICS
    • G06—COMPUTING OR CALCULATING; COUNTING
    • G06N—COMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00—Computing arrangements based on biological models
    • G06N3/02—Neural networks
    • G06N3/08—Learning methods
    • G06N3/088—Non-supervised learning, e.g. competitive learning
    • G—PHYSICS
    • G06—COMPUTING OR CALCULATING; COUNTING
    • G06N—COMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00—Computing arrangements based on biological models
    • G06N3/02—Neural networks
    • G06N3/08—Learning methods
    • G06N3/0895—Weakly supervised learning, e.g. semi-supervised or self-supervised learning
    • G—PHYSICS
    • G06—COMPUTING OR CALCULATING; COUNTING
    • G06N—COMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00—Computing arrangements based on biological models
    • G06N3/02—Neural networks
    • G06N3/08—Learning methods
    • G06N3/09—Supervised learning
    • G—PHYSICS
    • G06—COMPUTING OR CALCULATING; COUNTING
    • G06N—COMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N5/00—Computing arrangements using knowledge-based models
    • G06N5/01—Dynamic search techniques; Heuristics; Dynamic trees; Branch-and-bound
    • G—PHYSICS
    • G06—COMPUTING OR CALCULATING; COUNTING
    • G06N—COMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N5/00—Computing arrangements using knowledge-based models
    • G06N5/02—Knowledge representation; Symbolic representation
    • G—PHYSICS
    • G06—COMPUTING OR CALCULATING; COUNTING
    • G06N—COMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N5/00—Computing arrangements using knowledge-based models
    • G06N5/04—Inference or reasoning models
    • G—PHYSICS
    • G06—COMPUTING OR CALCULATING; COUNTING
    • G06N—COMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N7/00—Computing arrangements based on specific mathematical models
    • G06N7/01—Probabilistic graphical models, e.g. probabilistic networks

Definitions

  • Existing knowledge graph completion methods are mainly divided into: completion based on embedding models, completion based on description models, and combining graph structure information and semantic description information (joint models); among them, description models use text descriptions of entities and relationships, use pre-trained language models to encode descriptions as feature representations, and use features to match missing parts, such as KG-BERT and MTL-KGC; although such models can utilize information from outside the graph structure, they need to input text directly into the pre-trained language model, resulting in a large amount of memory and time required for training, and the inference speed is significantly slowed down; there is little research on joint models, and existing research does not fully utilize the structural information in the graph; most models directly align description features to the graph structure, but inappropriate alignment methods will destroy the text description information.
  • the data set is input into the initialized precoding model, and each entity description text and each relationship description text are preprocessed respectively; a pooling operation is performed on the preprocessed entity description text and each relationship description text to obtain the entity semantic expression of each entity description text and the relationship semantic expression of each relationship description text; an embedding operation is performed on all entity semantic expressions and all relationship semantic expressions to obtain entity embedding vectors and relationship embedding vectors;
  • a triple set is constructed, and the triple set is divided into a training set and a test set.
  • the inverse relationship triples corresponding to the training set are added to the training set to obtain the target training set;
  • the inverse relationship triples corresponding to the test set are added to the test set to obtain the target test set;
  • the input sequences corresponding to each sample are simultaneously input into the main mask model. After being processed by multiple layers of Transformer blocks, the vectors at the last mask position corresponding to each input sequence are output. The vectors at the last mask position corresponding to each input sequence are input into the classification layer. After a softmax operation, the probability of each entity distribution corresponding to each input sequence is output.
  • the parameters of the model are calculated until all samples in the target training set are extracted to obtain the parameters of the main mask model of the current round; the evaluation function is used to evaluate the main mask model of the current round. If the performance of the main mask model of the current round is better than that of the main mask model of the previous round, the weight of the main mask model of the current round is saved and the next round of training is carried out until the preset number of training rounds is reached. The training is terminated to obtain the trained main mask model;
  • entity_des represents entity description
  • relation_des represents relationship description
  • e i represents the i-th entity semantic expression, i ⁇ [1,n], n represents the number of entities
  • r j represents the j-th relation semantic expression, j ⁇ [1,m]
  • m represents the number of relations
  • n the number of entities
  • m the number of relations
  • E the entity embedding vector
  • R the relationship embedding vector
  • Embeddings [E, R] represents the embedding layer vector.
  • each mask triplet corresponding to each sample is constructed at the same time, and each input sequence corresponding to the remaining samples is obtained.
  • the input sequence corresponding to sample A is input into the main mask model.
  • the input sequence corresponding to sample A is processed by the 12-layer Transformer block.
  • z num represents the input of the numth layer
  • z 0 represents the input of the first layer
  • the classification layer is a feedforward neural network, and the input dimension of the classification layer is The output dimension is the number of entities; Input into the classification layer, and then through the softmax operation, the entity classification probability is obtained, and its expression is:
  • constructing the loss function includes:
  • a loss function is constructed; wherein the loss function is a cross entropy loss function, and its expression is:
  • yi represents the actual label of the i-th entity, and yi takes 0 or 1; when yi takes 1, it means that the i-th entity is a label; when yi takes 0, it means that the i-th entity is not a label; represents the i-th probability corresponding to the i-th entity in the entity distribution probability; N represents the number of all entities; i represents the index value.
  • the initialization of the main mask model further comprises extracting samples from the target training set according to a preset batch size, and obtaining the sample set:
  • each entity structure embedding expression and each relationship structure embedding expression of the embedding model randomly initialize each entity structure embedding expression and each relationship structure embedding expression of the embedding model, and integrate each entity structure embedding expression and each relationship structure embedding expression into an entity embedding matrix and a relationship embedding matrix respectively;
  • the entity embedding vector obtained by the precoding model contains multiple entity semantic expressions;
  • the relationship embedding vector obtained by the precoding model contains multiple relationship semantic expressions;
  • the entity semantic expression and relationship semantic expression corresponding to each sample in the sample set are combined with the embedding model
  • the entity structure embedding expression and the relationship structure embedding expression corresponding to the model are spliced to obtain the splicing features corresponding to each sample; the splicing features corresponding to each sample are input into the fusion module to obtain the fused head entity expression and each relationship expression corresponding to each sample; according to the fused head entity expression and each relationship expression corresponding to each sample, the fusion mask triples corresponding to each sample are constructed; the corresponding position vector is added to each element in each fusion mask triple, and the start and end flag vectors of the main mask model are combined to obtain the fusion input sequence corresponding to each sample;
  • Each fused input sequence corresponding to each sample is simultaneously input into the main mask model.
  • the step of splicing the entity semantic expression and the relationship semantic expression corresponding to each sample in the sample set with the entity structure embedding expression and the relationship structure embedding expression corresponding to the embedding model to obtain splicing features corresponding to each sample; and inputting the splicing features corresponding to each sample into a fusion module to obtain fused head entity expressions and relationship expressions corresponding to each sample includes:
  • any sample B from the sample set define the entity semantic expression and relationship semantic expression corresponding to sample B as the semantically rich description expression u from the precoding model; define the corresponding entity structure embedding expression and relationship structure embedding expression in the embedding model as the embedding expression v with structural information from the embedding model;
  • the semantically rich description expression u from the pre-coding model and the structurally information embedded expression v from the embedding model are concatenated to obtain the concatenated feature c.
  • the splicing features corresponding to sample B are input into the fusion module.
  • the fusion information is extracted to obtain the fused head entity and relationship expression, which is expressed as follows:
  • each fusion mask triple corresponding to each sample based on each fused head entity expression and each relationship expression corresponding to each sample; adding a corresponding position vector to each element in each fusion mask triple, and combining the start and end flag vectors of the main mask model to obtain each fusion input sequence corresponding to each sample includes:
  • the fusion mask triplet corresponding to sample B is constructed; the corresponding position vector is added to each element in the fusion mask triplet corresponding to sample B, and combined with the start and end flag vectors of the main mask model, the fusion input sequence corresponding to sample B is obtained, which is expressed as follows:
  • x input_fusion represents the fusion input sequence corresponding to sample B
  • E CLS represents the start symbol of the sequence
  • E SEP represents the end symbol of the sequence
  • E mask represents the mask vector;
  • each fusion mask triple corresponding to each sample is constructed at the same time, and each fusion input sequence corresponding to each sample is obtained.
  • constructing the loss function includes:
  • the knowledge graph link prediction method described in the present invention uses a precoding model to encode and summarize the long text descriptions of entities and relationships into features of semantic information; since the text description does not change, the precoding operation only needs to be performed once before model training, and the resulting embedding layer represents all entities.
  • the semantic expression of entities and relations is realized through the embedding layer, which is used in subsequent training and reasoning to alleviate the problems caused by long text encoding.
  • This method innovatively uses the pre-encoding method to effectively reduce the training pressure of the model and improve the reasoning speed of the model.
  • the knowledge graph link prediction method described in the present invention takes into account that semantic information should be independent of structural information, and the two are expressions from different information sources; and is inspired by early fusion in multimodal learning.
  • a simple fusion module is used before inputting the main mask model to first splice the semantic expression and the embedded expression into one expression, and then the most suitable fusion expression is obtained through a learnable fusion module; this method does not require the description features to be aligned to the graph structure, and there is no need to consider that inappropriate alignment will destroy the text description information, thereby ensuring the integrity of the text description information and improving the accuracy of the prediction.
  • FIG1 is a schematic diagram of the structure of a knowledge graph algorithm based on a pre-coded masked language model provided by the present invention
  • Figure 2 shows the input vector of the main mask model in the pre-encoded mask language model
  • Figure 1 is a schematic diagram of the knowledge graph algorithm structure based on the pre-coded masked language model provided by the present invention; in order to solve the problem that the training language model requires inputting long texts and causes the reasoning speed to slow down, the present invention adopts a knowledge graph chain based on the pre-coded masked language model.
  • the model consists of two BERTs (bidirectional Transformer encoder representations). The specific steps include:
  • S102 Input the data set into the initialized precoding model, preprocess each entity description text and each relationship description text respectively; perform a pooling operation on each preprocessed entity description text and each relationship description text to obtain the entity semantic expression of each entity description text and the relationship semantic expression of each relationship description text, which are expressed as follows:
  • entity_des represents entity description
  • relation_des represents relationship description
  • e i represents the i-th entity semantic expression, i ⁇ [1,n], n represents the number of entities
  • r j represents the j-th relation semantic expression, j ⁇ [1,m]
  • m represents the number of relations
  • n the number of entities
  • m the number of relations
  • E the entity embedding vector
  • R the relationship embedding vector
  • Embeddings [E, R] represents the embedding layer vector
  • S104 Initialize the main mask model and extract batch_size samples from the target training set according to the preset batch size batch_size to obtain a sample set;
  • S105 Construct each mask triplet corresponding to each sample in the sample set; add the corresponding position vector to each element in each mask triplet, and combine the start and end flag vectors of the main mask model to obtain each input sequence corresponding to each sample, including:
  • x input represents the input sequence corresponding to sample A
  • E CLS represents the start symbol of the sequence
  • E SEP represents the end symbol of the sequence
  • E h represents the head entity feature representation corresponding to sample A
  • E r represents the relationship feature representation corresponding to sample A
  • E mask represents the mask vector
  • each mask triple corresponding to each sample in the sample set is constructed at the same time, and each input sequence corresponding to each sample is obtained;
  • the input sequence structure of the main mask model is shown in Figure 2. Since the BERT model needs to consider the relative position of each element in the input sequence to better capture the structure and relationship in the sequence, when using BERT for knowledge graph completion tasks, adding corresponding position encodings to the input at each position can provide relative position information of entities and relationships, allowing the model to better understand the relationship between different elements in the input sequence.
  • S106 Input each input sequence corresponding to each sample into the main mask model at the same time. After being processed by multiple layers of Transformer blocks, the vector at the last mask position corresponding to each input sequence is output. The vector at the last mask position corresponding to each input sequence is input into the classification layer. After a softmax operation, the entity distribution corresponding to each input sequence is output, including:
  • the input sequence corresponding to sample A is input into the main mask model.
  • the input sequence corresponding to sample A will be processed by the 12-layer Transformer block.
  • z num represents the input of the numth layer
  • z 0 represents the input of the first layer
  • Link prediction (head entity ⁇ relation ⁇ ?) can be regarded as a multi-classification problem of the mask vector; therefore, the classification layer is used to obtain the entity classification probability; the classification layer is a feedforward neural network, and the input dimension of the classification layer is The output dimension is the number of entities; after the softmax operation, the entity classification probability is obtained, and its expression is:
  • S107 Construct a loss function based on the distribution probability of each entity corresponding to each input sequence; wherein the loss function is a cross entropy loss function, and its expression is:
  • each fusion input sequence corresponding to each sample is obtained as the input sequence of the main mask model
  • FIG3 is a schematic diagram of a knowledge graph algorithm based on a framework of pre-encoding fusion structural information and semantic information provided by the present invention
  • the knowledge graph completion based on the framework of fusion structural information and semantic information consists of three stages, namely, the pre-encoding stage, the fusion stage, and the encoding stage; the specific steps include:
  • entity_des represents entity description
  • relation_des represents relationship description
  • e i represents the i-th entity semantic expression, i ⁇ [1,n], n represents the number of entities
  • r j represents the j-th relation semantic expression, j ⁇ [1,m]
  • m represents the number of relations
  • n the number of entities
  • m the number of relations
  • E the entity embedding vector
  • R the relationship embedding vector
  • Rmbeddings [E, R] represents the embedding layer vector
  • the semantically rich description expression u from the pre-coding model and the structurally information embedded expression v from the embedding model are concatenated to obtain the concatenated feature c.
  • the splicing features corresponding to sample B are input into the fusion module.
  • the fusion information is extracted to obtain the fused head entity and relationship expression, which is expressed as follows:
  • S306 Constructing fusion mask triples corresponding to each sample based on the fused head entity expressions and relationship expressions corresponding to each sample; adding corresponding position vectors to each element in each fusion mask triple, and combining the start and end flag vectors of the main mask model to obtain fusion input sequences corresponding to each sample, including:
  • x input_fusion represents the fusion input sequence corresponding to sample B
  • E CLS represents the start symbol of the sequence
  • E SEP represents the end symbol of the sequence
  • E mask represents the mask vector;
  • each fusion mask triple corresponding to each sample is constructed, and each fusion input sequence corresponding to each sample is obtained;
  • S305 and S306 belong to the fusion module in the framework of pre-encoded fusion structural information and semantic information.
  • this fusion module the prediction accuracy of the overall fusion framework can be improved by fusing structural information and semantic information, while ensuring the integrity of text description information;
  • the adopted embedding model is a translation model; then constructing the loss function includes:
  • the translation model transforms relationships into transformations between entities, directing the sum of the head entity and relationship vectors to the tail entity.
  • the expected vector is expressed as h + r ⁇ t.
  • e h represents the embedding vector of the head entity in the translation model
  • e r represents the embedding vector of the relation in the translation model
  • e t represents the embedding vector of the tail entity in the translation model
  • represents the two-norm calculation
  • f(h,r,t) represents the scoring function
  • K represents the negatively sampled entity set
  • tk represents the kth entity in the negatively sampled entity set
  • the score of the scoring function f(h,r,t) is between [-1,1]. The closer the score is to 1, the more the mapping between the head entity vector and the relationship vector can point to the tail entity, that is, the better the model performance is.
  • the translation model's predicted output is the entity with the highest score, and its expression is:
  • E is the set of all entities; t res_i represents the entity with the highest score;
  • yi represents the actual label of the i-th entity, and yi takes 0 or 1; when yi takes 1, it means that the i-th entity is a label; when yi takes 0, it means that the i-th entity is not a label; represents the i-th probability corresponding to the i-th entity in the entity distribution probability; N represents the number of all entities; i represents the index value;
  • L CE classification loss
  • ⁇ the weight of contrast loss
  • L S contrast loss
  • S310 Based on the target test set, construct a test set fusion mask triplet to obtain a test set fusion input sequence; input the test set fusion input sequence into the trained main mask model and output the entity classification probability; predict potential entities through the entity classification probability.
  • WN18RR is a subset of the WordNet data set that describes the association features between English words while retaining the symmetric, asymmetric, and compositional relationships in the WordNet dataset. It is used to evaluate link prediction tasks.
  • UMLS Uniform Medical Language System
  • Table 1 The scales of the two benchmark datasets are shown in Table 1, namely:
  • the entity has filtered out the triples that did not appear in the training set, and the verification
  • the entities and relations in the validation set and test set are also those that appeared in the training set; the data in the validation set and test set do not participate in model optimization, and the subsequent experimental conclusions are all evaluation results of the two models on the test set; the text descriptions of the entities and relations in the dataset use the content defined by the BERT-based knowledge graph embedding algorithm (KG-BERT).
  • the missing triples (head entity, relationship, ?) in the knowledge graph may correspond to multiple tail entities. According to convention, when evaluating, all possible entities (except label entities) that have appeared in the training set, validation set, and test set need to be removed from the candidate triples; among the filtered entities, the softmax value output by the classification layer is used for ranking; the true answer of the i-th triple in the test set is ranked as rank i among all entities.
  • MR refers to the average value of all rank i in the test set, and its expression is:
  • This indicator reflects the ranking of the true answer among the candidate entities under average circumstances.
  • MRR refers to the average of the reciprocals of all rank i in the test set, and its expression is:
  • Hits@n refers to the average value of all ranks i ⁇ n in the test set, where n is usually 10, 3, or 1. Its expression is:
  • This indicator model reflects whether the model can rank the true answer into the top n, focusing only on the model's high ranking performance; the larger the Hits@n, the better the model's inference performance.
  • the experimental environment will affect the experimental results.
  • the experimental environment is shown in Table 2 for research reference, namely:
  • KG-BERT the masked language model based on precoding and the framework for fusing structural information and semantic information based on precoding provided by the present invention were selected in the experiment for comparison on the WN18RR and UMLS test sets;
  • the input of KG-BERT is text, while the input of the model provided by the present invention is all precoded expressions;
  • the inference speed of KG-BERT is related to the entity scale in the dataset, and the more entities, the longer the inference speed; as shown in Table 4, Table 4 shows the accelerated inference effect brought about by avoiding encoding long text under the precoding mechanism; among them, Ours-1 represents the masked language model based on precoding provided by the present invention, and Ours-2 represents the framework for fusing structural information and semantic information based on precoding provided by the present invention; it can be seen from Table 4 that the model provided by the present invention has a significant effect on the improvement of inference speed.
  • Ours-2 represents the framework for fusing structural information and semantic information based on precoding
  • the selected benchmark models are divided into three categories: embedding-based models, description-based models and joint models; among them, the embedding-based models include: the transformation embedding model (TransE) for modeling multi-relational data, the knowledge graph embedding model based on complex spatial relationship rotation (RotatE), the bilinear diagonal model (DistMult), and the convolutional two-dimensional knowledge graph embedding model (ConvE); the description-based models include: the BERT-based knowledge graph embedding algorithm (KG-BERT), the multi-task knowledge graph completion algorithm (MTL_KGC); the joint models include: the pre-trained knowledge graph embedding model (Pretrain-KGE), the structure-enhanced knowledge graph text representation learning (StAR), and the joint language semantics and structure embedding model (LASS) for knowledge graph completion.
  • the embedding-based models include: the transformation embedding model (TransE) for modeling multi-relational data, the knowledge graph embedding model based on complex spatial relationship rotation (
  • Table 5 shows the specific experimental results of Ours-1 and Ours-2 provided by the present invention on the WN18RR dataset and the UMLS dataset respectively; Among them, on the WN18RR dataset, MRR and H its@1, H its@3, H its@10 are used as evaluation indicators; on the UMLS dataset, MR and Hits@10 is used as the evaluation metric. In addition, except for Ours-1 and Ours-2 provided in this paper, the rest of the experimental results are taken from the original paper. In Table 5, “-” indicates data not described in the paper, bold indicates the best result under this metric, and underlined indicates the next best result under this metric.
  • Figure 4 shows an example analysis of 6 missing triplets selected from the WN18RR dataset; among them, bold indicates that the prediction result is consistent with the label, and the number before the result is the ranking of the true answer; on these incomplete triplets, the results of the framework based on pre-coding that integrates structural information and semantic information (Ours-2) are better than those of the masked language model based on pre-coding (Ours-1).

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Artificial Intelligence (AREA)
  • Computational Linguistics (AREA)
  • Data Mining & Analysis (AREA)
  • Evolutionary Computation (AREA)
  • General Health & Medical Sciences (AREA)
  • Health & Medical Sciences (AREA)
  • Software Systems (AREA)
  • Mathematical Physics (AREA)
  • Computing Systems (AREA)
  • Life Sciences & Earth Sciences (AREA)
  • Molecular Biology (AREA)
  • Biomedical Technology (AREA)
  • Biophysics (AREA)
  • Audiology, Speech & Language Pathology (AREA)
  • Computer Vision & Pattern Recognition (AREA)
  • Evolutionary Biology (AREA)
  • Bioinformatics & Computational Biology (AREA)
  • Bioinformatics & Cheminformatics (AREA)
  • Probability & Statistics with Applications (AREA)
  • Algebra (AREA)
  • Computational Mathematics (AREA)
  • Mathematical Analysis (AREA)
  • Mathematical Optimization (AREA)
  • Pure & Applied Mathematics (AREA)
  • Medical Informatics (AREA)
  • Machine Translation (AREA)
  • Management, Administration, Business Operations System, And Electronic Commerce (AREA)

Abstract

本发明涉及知识图谱补全任务技术领域,具体指一种知识图谱链路预测方法,包括:利用预编码模型得到嵌入层向量,并构建对应掩码三元组;对掩码三元组中各元素加上对应位置编码,得到对应输入序列,并将其输入至训练好的主掩码模型中,输出实体分类概率;根据实体分类概率,预测潜在可能实体;还包括:将嵌入层向量对应的语义信息与嵌入模型得到的结构信息拼接,得到融合后的头实体与关系表达,并构建对应融合掩码三元组;对融合掩码三元组中各元素加上对应位置编码,得到对应融合输入序列;本发明使用预编码方法,有效减轻模型的训练压力,提高模型的推理速度;并在输入主掩码模型前使用融合模块,保证了文本描述信息的完整性,提高了预测精确度。

Description

一种知识图谱链路预测方法 技术领域
本发明涉及知识图谱补全任务技术领域,尤其是指一种知识图谱链路预测方法。
背景技术
知识图是一种用于表示和组织知识的图形模型,以三元组的形式描述实体之间的关系,其中,实体包含真实世界的实体,如对象、概念、时间等,关系表示他们的连接和交互;三元组的组成范式为(头,关系,尾),其中,头和尾是实体,关系联系了头实体和尾实体。目前,已经有许多人工手机的知识图谱,但是实体之间仍然存在许多缺失的关系;知识图谱旨在利用已知的实体和关系来准确地预测未知的关系来增强知识图谱信息。
现有的知识图谱补全方法主要分为:基于嵌入模型的补全、基于描述模型的补全以及结合图谱结构信息和语义描述信息(联合模型);其中,描述模型使用实体和关系的文本描述,使用预训练语言模型将描述编码作为特征表示,利用特征匹配缺失部分,如KG-BERT、MTL-KGC;这类模型虽然能够利用来自图谱结构之外的信息,但需要将文本直接输入到预训练语言模型中,导致训练需要大量的内存和时间,并且推理速度也显著减慢;在联合模型方面的研究较少,且现有研究并没有充分利用图谱中的结构信息;多数模型直接将描述特征对齐到图谱结构中,但不恰当的对齐方法会破坏文本描述信息。
综上,现有技术对于知识图谱补全算法存在的问题有:(1)基于描述的知识补全算法依赖预训练语言模型,但预训练语言模型的文本编码会严重影响推理速度;(2)融合结合信息和语义描述信息时,直接将描述特征对齐到图谱结构中,其中不恰当的对齐方式会破坏文本描述信息。
发明内容
为此,本发明所要解决的技术问题在于克服现有技术中基于描述的知识补全算法依赖预训练语言模型,但预训练语言模型的文本编码会严重影响推理速度的问题;融合结合信息和语义描述信息时,直接将描述特征对齐到图谱结构中,其中不恰当的对齐方式会破坏文本描述信息的问题。
为解决上述技术问题,本发明提供了一种知识图谱链路预测方法,包括:
获取数据集合;其中,数据集合包括实体描述文本集合、关系描述文本集合;获取各个实体描述文本对应的索引值,构建索引集合;
将数据集合输入至初始化后的预编码模型中,分别对各个实体描述文本和各个关系描述文本进行预处理;对预处理后的各个实体描述文本和各个关系描述文本进行池化操作,得到各个实体描述文本的实体语义表达、各个关系描述文本的关系语义表达;对所有实体语义表达、所有关系语义表达进行嵌入操作,得到实体嵌入向量和关系嵌入向量;
根据实体嵌入向量和关系嵌入向量,结合索引集合,构建三元组集合,将三元组集合划分为训练集和测试集,将训练集对应的逆关系三元组添加至训练集中,得到目标训练集;将测试集对应的逆关系三元组添加到测试集中,得到目标测试集;
初始化主掩码模型,按照预设的批量大小,从目标训练集中抽取样本,得到样本集合;构建样本集合中各个样本对应的各个掩码三元组;对各个掩码三元组中各个元素分别添加对应的位置向量,结合主掩码模型的开始和结束标志向量,得到各个样本对应的各个输入序列;
将各个样本对应的各个输入序列同时输入至主掩码模型中,经过多层的Transformer块处理,输出各个输入序列对应的最后一层掩码位置上的向量;将各个输入序列对应的最后一层掩码位置上的向量输入至分类层中,经过softmax操作,输出各个输入序列对应的各个实体分布概率;
构建损失函数,并利用Adam优化器最小化损失函数值,更新主掩码模 型的参数,直至抽取完目标训练集中所有样本,得到当前轮次主掩码模型的参数;利用评价函数评估当前轮次主掩码模型,若当前轮次主掩码模型表现优于上一轮次主掩码模型表现,则保存当前轮次主掩码模型的权重,进行下一轮次训练,直到达到预设的训练轮数,结束训练,得到训练好的主掩码模型;
基于目标测试集,构建测试集掩码三元组,从而得到测试集输入序列;将测试集输入序列输入至训练好的主掩码模型中,输出实体分类概率;通过实体分类概率,预测潜在可能实体。
优选地,所述将数据集合输入至初始化后的预编码模型中,分别对各个实体描述文本和各个关系描述文本进行预处理;对预处理后的各个实体描述文本和各个关系描述文本进行池化操作,得到各个实体描述文本的实体语义表达、各个关系描述文本的关系语义表达;对所有实体语义表达、所有关系语义表达进行嵌入操作,得到实体嵌入向量和关系嵌入向量包括:
通过池化操作,将实体描述文本、关系描述文本概括成语义表达,其表达式为:

其中,entity_des表示实体描述;relation_des表示关系描述;表示第i个实体描述文本;表示第j个关系描述文本;ei表示第i个实体语义表达,i∈[1,n],n表示实体数量;rj表示第j个关系语义表达,j∈[1,m],m表示关系数量;
对实体语义表达、关系语义表达进行嵌入操作,得到实体嵌入向量、关系嵌入向量,其表达式为:
E=[e1;e2;...;en]
R=[r1;r2;...;rm]
Embeddings=[E,R]
其中,n表示实体数量;m表示关系数量;E表示实体嵌入向量;R表示关系嵌入向量;Embeddings=[E,R]表示嵌入层向量。
优选地,所述构建样本集合中各个样本对应的各个掩码三元组;对各个掩码三元组中各个元素分别添加对应的位置向量,结合主掩码模型的开始和结束标志向量,得到各个样本对应的各个输入序列包括:
从样本集合中任选一个样本A,构建样本A对应的掩码三元组;将样本A对应的掩码三元组中的各个元素上添加上对应的位置向量,结合主掩码模型的开始和结束标志向量,得到样本A对应的输入序列,其表达式为:
其中,xinput表示样本A对应的输入序列;ECLS表示序列的开始符号;ESEP表示序列的结束符号;Eh表示样本A对应的头实体特征表示;Er表示样本A对应的关系特征表示;Emask表示掩码向量;表示序列第s个位置对应的位置编码;
基于上述操作,同时构建各个样本对应的各个掩码三元组,并得到其余各个样本对应的各个输入序列。
优选地,所述将各个样本对应的各个输入序列同时输入至主掩码模型中,经过多层的Transformer块处理,输出各个输入序列对应的最后一层掩码位置上的向量;将各个输入序列对应的最后一层掩码位置上的向量输入至分类层中,经过softmax操作,输出各个输入序列对应的各个实体分布概率包括:
对样本集合中样本A对应的输入序列进行如下操作:
将样本A对应的输入序列输入到主掩码模型中,样本A对应的输入序列会经过12层的Transformer块处理;最后一层的Emask位置上的向量可以作为带预测实体的表达,其表达式为:
znum=Transformer(znum-1),num=1,2,...,12
z0=xinput
其中,znum表示第num层的输入;z0表示第一层的输入;表示最后一层Emask位置上的向量;表示最后输出Emask的值;
分类层为一个前馈神经网络,所述分类层的输入维度为的维度,输出维度为实体数量;将输入至分类层中,再经过softmax操作,得到实体分类概率,则其表达式为:
其中,表示实体分类概率;
基于上述操作,将样本集合中各个样本对应的各个输入序列同时输入至主掩码模型中,输出各个输入序列对应的各个实体分布概率。
优选地,所述构建损失函数包括:
基于各个输入序列对应的各个实体分布概率,构建损失函数;其中,所述损失函数为交叉熵损失函数,其表达式为:
其中,yi表示第i个实体的实际标签,yi取0或1;当yi取1时表示第i个实体是标签;当yi取0时表示第i个实体不是标签;表示第i个实体在实体分布概率中对应的第i个概率;N表示所有实体的数量;i表示索引值。
优选地,所述初始化主掩码模型,按照预设的批量大小,从目标训练集中抽取样本,得到样本集合后还包括:
在预设范围内,随机初始化嵌入模型的各个实体结构嵌入表达和各个关系结构嵌入表达,将各个实体结构嵌入表达和各个关系结构嵌入表达分别整合为实体嵌入矩阵和关系嵌入矩阵;
通过预编码模型得到的实体嵌入向量中包含多个实体语义表达;通过预编码模型得到的关系嵌入向量包含多个关系语义表达;
将样本集合中各个样本对应的实体语义表达、关系语义表达,与嵌入模 型对应的实体结构嵌入表达、关系结构嵌入表达进行拼接,得到各个样本对应的各个拼接特征;将各个样本对应的各个拼接特征输入至融合模块中,得到各个样本对应的融合后的各个头实体表达和各个关系表达;根据各个样本对应的融合后的各个头实体表达和各个关系表达,构建各个样本对应的各个融合掩码三元组;对各个融合掩码三元组中的各个元素添加对应的位置向量,结合主掩码模型的开始和结束标志向量,得到各个样本对应的各个融合输入序列;
将各个样本对应的各个融合输入序列同时输入至主掩码模型中。
优选地,所述将样本集合中各个样本对应的实体语义表达、关系语义表达,与嵌入模型对应的实体结构嵌入表达、关系结构嵌入表达进行拼接,得到各个样本对应的各个拼接特征;将各个样本对应的各个拼接特征输入至融合模块中,得到各个样本对应的融合后的各个头实体表达和各个关系表达包括:
在样本集合中任选一个样本B,将样本B对应的实体语义表达、关系语义表达定义为来自预编码模型富含语义信息的描述表达u;将嵌入模型中对应的实体结构嵌入表达、关系结构嵌入表达定义为来自嵌入模型带有结构信息的嵌入表达v;
将来自预编码模型富含语义信息的描述表达u和来自嵌入模型带有结构信息的嵌入表达v进行拼接,得到拼接特征c,其拼接特征为两个表达的拼接结果,其表达式为:
c(u,v)=[u,v]
将样本B对应的拼接特征输入到融合模块中,通过降维的方式,提取融合信息,得到融合后的头实体与关系表达,其表达式为:

其中,表示样本B对应的融合后的头实体表达;表示样本B对应的 融合后的关系表达;
基于上述操作,对样本集合中各个样本同时进行拼接,得到各个样本对应的各个拼接特征,并得到各个样本对应的融合后的各个头实体表达和各个关系表达。
优选地,所述根据各个样本对应的融合后的各个头实体表达和各个关系表达,构建各个样本对应的各个融合掩码三元组;对各个融合掩码三元组中的各个元素添加对应的位置向量,结合主掩码模型的开始和结束标志向量,得到各个样本对应的各个融合输入序列包括:
基于样本B对应的融合后的头实体表达和关系表达,构建样本B对应的融合掩码三元组;将样本B对应的融合掩码三元组中各个元素上分别添加对应的位置向量,结合主掩码模型的开始和结束标志向量,得到样本B对应的融合输入序列,其表达式为:
其中,xinput_fusion表示样本B对应的融合输入序列;ECLS表示序列的开始符号;ESEP表示序列的结束符号;表示样本B对应的融合后的头实体表达;表示样本B对应的融合后的关系表达;Emask表示掩码向量;表示序列第s个位置对应的位置编码;
基于上述操作,通过各个样本对应的融合后的各个头实体表达和各个关系表达,同时构建各个样本对应的各个融合掩码三元组,并得到各个样本对应的各个融合输入序列。
优选地,所述嵌入模型为翻译模型。
优选地,所述构建损失函数包括:
基于翻译模型原理,采用评分函数为余弦相似度函数,定义头实体和关系的嵌入向量之和ehr,其表达式为:
ehr=|eh+er|
其中,eh表示翻译模型中的头实体的嵌入向量;er表示翻译模型中的关系的嵌入向量;et表示翻译模型中的尾实体的嵌入向量;||||表示二范数计算;f(h,r,t)表示评分函数;
在训练过程中,将负采样加入翻译模型损失函数中进行计算,作为对比损失LS,使得翻译模型学习到正比例得分高于负比例得分的嵌入表示,其表达式为:
其中,K表示负采样的实体集合;tk表示负采样的实体集合中第k个实体;将交叉熵损失函数作为分类损失LCE,其表达式为:
其中,yi表示第i个实体的实际标签,yi取0或1;当yi取1时表示第i个实体是标签;当yi取0时表示第i个实体不是标签;表示第i个实体在实体分布概率中对应的第i个概率;N表示所有实体的数量;i表示索引值;
主掩码模型优化总损失函数L为分类损失和对比损失的加权和,其表达式为
L=LCE+αLS
其中,LCE表示分类损失;α表示对比损失的权重;LS表示对比损失。
本发明的上述技术方案相比现有技术具有以下有益效果:
(1)本发明所述的一种知识图谱链路预测方法,采用预编码模型将实体和关系的长文本描述编码概括成语义信息的特征;由于文本描述不会变化,因此预编码操作仅需要在模型训练前进行一次,得到的嵌入层表示了所有实 体和关系的语义表达,后续训练与推理都使用该嵌入层,减轻了长文本编码带来的问题;本方法创新地使用了预编码的方法,有效减轻了模型的训练压力,并提高了模型的推理速度;
(2)本发明所述的一种知识图谱链路预测方法,考虑到语义信息应当独立于结构信息,二者是来自不同信息源的表达;并启发于多模态学习中的早期融合(Early fusion),在输入主掩码模型前使用简单的融合模块,将语义表达和嵌入表达先拼接为一个表达,然后再经过可学习的融合模块得到最适合的融合表达;本方法不需要将描述特征对齐到图谱结构中,无需考虑不恰当的对齐方式会破坏文本描述信息,保证了文本描述信息的完整性,提高了预测的精确度。
附图说明
为了使本发明的内容更容易被清楚的理解,下面根据本发明的具体实施例并结合附图,对本发明作进一步详细的说明,其中:
图1是本发明所提供的基于预编码的掩码语言模型的知识图谱算法结构示意图;
图2是基于预编码的掩码语言模型中主掩码模型的输入向量;
图3是本发明所提供的基于预编码的融合结构信息与语义信息的框架的知识图谱算法示意图;
图4是WN18RR数据集上选取的6个缺失三元组的实例分析。
具体实施方式
下面结合附图和具体实施例对本发明作进一步说明,以使本领域的技术人员可以更好地理解本发明并能予以实施,但所举实施例不作为对本发明的限定。
参照图1所示,图1为本发明所提供的基于预编码的掩码语言模型的知识图谱算法结构示意图;为了解决训练语言模型需要输入长文本而导致推理速度减慢的问题,本发明采用了基于预编码的掩码语言模型进行知识图谱链 路的预测;其中,该模型由两个BERT(双向Transformer编码器表示)组成;具体步骤包括:
S101:获取数据集合Sd={(dese,desr)};其中,数据集合Sd包括实体描述文本集合dese、关系描述文本集合desr;获取各个实体描述文本对应的索引值,构建索引集合;
S102:将数据集合输入至初始化后的预编码模型中,分别对各个实体描述文本和各个关系描述文本进行预处理;对预处理后的各个实体描述文本和各个关系描述文本进行池化操作,得到各个实体描述文本的实体语义表达、各个关系描述文本的关系语义表达,其表达式为:

其中,entity_des表示实体描述;relation_des表示关系描述;表示第i个实体描述文本;表示第j个关系描述文本;ei表示第i个实体语义表达,i∈[1,n],n表示实体数量;rj表示第j个关系语义表达,j∈[1,m],m表示关系数量;
对所有实体语义表达、所有关系语义表达进行嵌入操作,得到实体嵌入向量和关系嵌入向量,其表达式为:
E=[e1;e2;...;en]
R=[r1;r2;...;rm]
Embeddings=[E,R]
其中,n表示实体数量;m表示关系数量;E表示实体嵌入向量;R表示关系嵌入向量;Embeddings=[E,R]表示嵌入层向量;
S103:根据实体嵌入向量和关系嵌入向量,结合索引集合,构建三元组集合,将三元组集合划分为训练集Strain={h,r,t}和测试集Stest={h,r,t},将训练集Strain对应的逆关系三元组(t,r-,h)添加至训练集中,得到目标训练集将测试集Stest对应的逆关系三元组(t,r-,h)添加到测试集中,得到 目标测试集
S104:初始化主掩码模型,按照预设的批量大小batch_size,从目标训练集中抽取batch_size个样本,得到样本集合;
S105:构建样本集合中各个样本对应的各个掩码三元组;对各个掩码三元组中各个元素分别添加对应的位置向量,结合主掩码模型的开始和结束标志向量,得到各个样本对应的各个输入序列,包括:
从样本集合中任选一个样本A,以样本A为例,构建样本A对应的掩码三元组;将样本A对应的掩码三元组中的各个元素上添加上对应的位置向量,结合主掩码模型的开始和结束标志向量,得到样本A对应的输入序列,其表达式为:
其中,xinput表示样本A对应的输入序列;ECLS表示序列的开始符号;ESEP表示序列的结束符号;Eh表示样本A对应的头实体特征表示;Er表示样本A对应的关系特征表示;Emask表示掩码向量;表示序列第s个位置对应的位置编码;
基于上述操作,同时构建样本集合中各个样本对应的各个掩码三元组,并得到各个样本对应的各个输入序列;
其中,主掩码模型的输入序列构成如图2所示;由于BERT模型需要考虑输入序列中各个元素的相对位置,以便更好地捕捉序列中的结构和关系,因此,在使用BERT进行知识图谱补全任务时,为各个位置的输入附加上对应的位置编码可以提供实体与关系的相对位置信息,使得模型能够更好地理解输入序列中不同元素之间的关系;
S106:将各个样本对应的各个输入序列同时输入至主掩码模型中,经过多层的Transformer块处理,输出各个输入序列对应的最后一层掩码位置上的向量;将各个输入序列对应的最后一层掩码位置上的向量输入至分类层中,经过softmax操作,输出各个输入序列对应的各个实体分布,包括:
以样本A为例,将样本A对应的输入序列输入到主掩码模型,样本A对应的输入序列会经过12层的Transformer块处理,最后一层的Emask位置上的向量可以作为带预测实体的表达,其表达式为:
znum=Transformer(znum-1),num=1,2,...,12
z0=xinput
其中,znum表示第num层的输入;z0表示第一层的输入;表示最后一层Emask位置上的向量;表示最后输出Emask的值;
链路预测(头实体→关系→?)可以视为对经过掩码向量的多分类问题;因此,采用分类层得到实体分类概率;分类层为一个前馈神经网络,所述分类层的输入维度为的维度,输出维度为实体数量;再经过softmax操作,得到实体分类概率,则其表达式为:
其中,表示实体分类概率;
基于上述操作,将S105得到的样本集合中各个样本对应的各个输入序列同时输入至主掩码模型中,输出各个输入序列对应的各个实体分布概率;
S107:基于各个输入序列对应的各个实体分布概率,构建损失函数;其中,所述损失函数为交叉熵损失函数,其表达式为:
其中,yi表示第i个实体的实际标签,yi取0或1;当yi取1时表示第i个实体是标签;当yi取0时表示第i个实体不是标签;表示第i个实体的概率;N表示所有实体的数量;i表示索引值;该损失函数的目的是为了使得正确实体的概率尽可能大;
假设某数据集共有40943个实体,每个实体对应一个索引值;预设批量 大小为256,则每次读取256条数据,构建256个掩码三元组,得到的输入序列为256行5列的数据;将该输入序列输入至主掩码模型中,最终输出的是256行40943列的概率;其中,分类层输出的实体分类概率为经过softmax的分布在0到1之间的概率,40943个概率之和为1;
S108:利用Adam优化器最小化损失函数值,更新主掩码模型的参数,直至抽取完目标训练集中所有样本,得到当前轮次主掩码模型的参数;利用评价函数评估当前轮次主掩码模型,若当前轮次主掩码模型表现优于上一轮次主掩码模型表现,则保存当前轮次主掩码模型的权重,进行下一轮次训练,直到达到预设的训练轮数,结束训练,得到训练好的主掩码模型;
S109:基于目标测试集,构建测试集掩码三元组,从而得到测试集输入序列;将测试集输入序列输入至训练好的主掩码模型中,输出实体分类概率;通过实体分类概率,预测潜在可能实体。
根据上述步骤可以得出该模型的算法流程如下:

基于上述实施例,在本实施例中为了提高知识图谱链路的预测精度,基于预编码的融合结构信息与语义信息的框架,获取各个样本对应的各个融合输入序列作为主掩码模型的输入序列;
参照图3所示,图3为本发明所提供的基于预编码的融合结构信息与语义信息的框架的知识图谱算法示意图;基于融合结构信息和语义信息的框架下的知识图谱补全有三个阶段组成,即预编码阶段、融合阶段和编码阶段;具体步骤包括:
S301:获取数据集合Sd={(dese,desr)};其中,数据集合Sd包括实体描述文本集合dese、关系描述文本集合desr;获取各个实体描述文本对应的索引值,构建索引集合;
S302:将数据集合输入至初始化后的预编码模型中,分别对各个实体描述文本和各个关系描述文本进行预处理;对预处理后的各个实体描述文本和各个关系描述文本进行池化操作,得到各个实体描述文本的实体语义表达、 各个关系描述文本的关系语义表达,其表达式为:

其中,entity_des表示实体描述;relation_des表示关系描述;表示第i个实体描述文本;表示第j个关系描述文本;ei表示第i个实体语义表达,i∈[1,n],n表示实体数量;rj表示第j个关系语义表达,j∈[1,m],m表示关系数量;
对所有实体语义表达、所有关系语义表达进行嵌入操作,得到实体嵌入向量和关系嵌入向量,其表达式为:
E=[e1;e2;...;en]
R=[r1;r2;...;rm]
Embeddings=[E,R]
其中,n表示实体数量;m表示关系数量;E表示实体嵌入向量;R表示关系嵌入向量;Rmbeddings=[E,R]表示嵌入层向量;
S303:根据实体嵌入向量和关系嵌入向量,结合索引集合,构建三元组集合,将三元组集合划分为训练集Strain={h,r,t}和测试集Stest={h,r,t},将训练集Strain对应的逆关系三元组(t,r-,h)添加至训练集中,得到目标训练集将测试集Stest对应的逆关系三元组(t,r-,h)添加到测试集中,得到目标测试集
在范围内,随机初始化嵌入模型的各个实体结构嵌入表达和各个关系结构嵌入表达,将各个实体结构嵌入表达和各个关系结构嵌入表达分别整合为实体嵌入矩阵和关系嵌入矩阵;其中,dim表示嵌入层向量的特征维度;
S304:初始化主掩码模型,按照预设的批量大小batch_size,从目标训练集中抽取batch_size个样本,得到样本集合;
S305:将样本集合中各个样本对应的实体语义表达、关系语义表达,与 嵌入模型对应的实体结构嵌入表达、关系结构嵌入表达进行拼接,得到各个拼接特征;将各个拼接特征输入至融合模块中,得到各个样本对应的融合后的各个头实体表达和各个关系表达,包括:
在样本集合中任选一个样本B,以样本B为例,将样本B对应的实体语义表达、关系语义表达定义为来自预编码模型富含语义信息的描述表达u;将嵌入模型中对应的实体结构嵌入表达、关系结构嵌入表达定义为来自嵌入模型带有结构信息的嵌入表达v;
将来自预编码模型富含语义信息的描述表达u和来自嵌入模型带有结构信息的嵌入表达v进行拼接,得到拼接特征c,其拼接特征为两个表达的拼接结果,其表达式为:
c(u,v)=[u,v]
将样本B对应的拼接特征输入到融合模块中,通过降维的方式,提取融合信息,得到融合后的头实体与关系表达,其表达式为:

其中,表示样本B对应的融合后的头实体表达;表示样本B对应的融合后的关系表达;
基于上述操作,对样本集合中各个样本同时进行拼接,得到各个样本对应的各个拼接特征,并得到各个样本对应的融合后的各个头实体表达和各个关系表达;
S306:根据各个样本对应的融合后的各个头实体表达和各个关系表达,构建各个样本对应的各个融合掩码三元组;对各个融合掩码三元组中的各个元素添加对应的位置向量,结合主掩码模型的开始和结束标志向量,得到各个样本对应的各个融合输入序列,包括:
以样本B为例,基于样本B对应的融合后的头实体表达和关系表达,构建样本B对应的融合掩码三元组;将样本B对应的融合掩码三元组中各个元 素上分别添加对应的位置向量,结合主掩码模型的开始和结束标志向量,得到样本B对应的融合输入序列,其表达式为:
其中,xinput_fusion表示样本B对应的融合输入序列;ECLS表示序列的开始符号;ESEP表示序列的结束符号;表示样本B对应的融合后的头实体表达;表示样本B对应的融合后的关系表达;Emask表示掩码向量;表示序列第s个位置对应的位置编码;
基于上述操作,通过各个样本对应的融合后的各个头实体表达和各个关系表达,同时构建各个样本对应的各个融合掩码三元组,并得到各个样本对应的各个融合输入序列;
其中,所述S305和S306属于基于预编码的融合结构信息与语义信息的框架中的融合模块,通过该融合模块,凭借融合结构信息与语义信息可以提高整体融合框架的预测精度,同时保证了文本描述信息的完整性;
S307:将各个样本对应的各个融合输入序列同时输入至主掩码模型中,经过多层的Transformer块处理,输出各个融合输入序列对应的最后一层掩码位置上的向量;将各个融合输入序列对应的最后一层掩码位置上的向量输入至分类层中,经过softmax操作,输出各个融合输入序列对应的各个实体分布概率;
S308:在本发明的一个具体实施例中,所采用的嵌入模型为翻译模型;则构建损失函数包括:
翻译模型原理是将关系变现为实体间的转化,将头实体和关系向量的之和指向尾实体,期望向量表现如h+r≈t;采用评分函数为余弦相似度函数,定义头实体和关系的嵌入向量之和ehr,其表达式为:
ehr=|eh+er|
其中,eh表示翻译模型中的头实体的嵌入向量;er表示翻译模型中的关系的嵌入向量;et表示翻译模型中的尾实体的嵌入向量;||||表示二范数计算;f(h,r,t)表示评分函数;
在传统翻译模型的训练过程中,通常加入负采样操作,这样能够有效提高模型的泛化性能,解决样本之间的不平衡问题,加强模型的鲁棒性;本发明将负采样加入损失函数中进行计算,作为对比损失,使得翻译模型学习到正比例得分高于负比例得分的嵌入表示,其表达式为:
其中,K表示负采样的实体集合;tk表示负采样的实体集合中第k个实体;
评分函数f(h,r,t)的评分在[-1,1]之间,评分越接近1,表明头实体向量与关系向量的映射越能指向尾实体,即模型的性能越好;在预测尾实体问题(头实体、关系、?)上翻译模型的预测输出为最高评分的实体,其表达式为:
其中,E为所有实体集合;tres_i表示评分最高的实体;
将交叉熵损失函数作为分类损失LCE,其表达式为
其中,yi表示第i个实体的实际标签,yi取0或1;当yi取1时表示第i个实体是标签;当yi取0时表示第i个实体不是标签;表示第i个实体在实体分布概率中对应的第i个概率;N表示所有实体的数量;i表示索引值;
主掩码模型优化总损失函数L为分类损失和对比损失的加权和,其表达式为
L=LCE+αLS
其中,LCE表示分类损失;α表示对比损失的权重;LS表示对比损失;
S309:利用Adam优化器最小化损失函数值,更新主掩码模型的参数,直至抽取完目标训练集中所有样本,得到当前轮次主掩码模型的参数;利用评价函数评估当前轮次主掩码模型,若当前轮次主掩码模型表现优于上一轮次主掩码模型表现,则保存当前轮次主掩码模型的权重,进行下一轮次训练,直到达到预设的训练轮数,结束训练,得到训练好的主掩码模型;
S310:基于目标测试集,构建测试集融合掩码三元组,从而得到测试集融合输入序列;将测试集融合输入序列输入至训练好的主掩码模型中,输出实体分类概率;通过实体分类概率,预测潜在可能实体。
根据上述步骤得到本模型算法流程如下:

为了验证本发明中的基于预编码的掩码语言模型以及基于预编码的融合结构信息与语义信息的框架的推理性能,对所述基于预编码的掩码语言模型以及基于预编码的融合结构信息与语义信息的框架进行实验:
一、实验数据集
本实验利用两个基准数据集:WN18RR和UMLS(一体化医学语言系统);WN18RR属于WordNet数据子集,描述英语单词之间关联特征的数据集,同时保留WordNet数据集中的对称、非对称和组合关系,用于评估链路预测任务;UMLS(一体化医学语言系统)数据集是针对生物医学和健康领域的小型知识图谱;两个基准数据集的规模如表1所示,即:
表1数据集规格
需要注意的是,实体已经过滤掉在训练集中未出现的三元组,并且验证 集和测试集中的实体和关系也均为训练集中出现过的;验证集和测试集中的数据不参与模型优化,后续实验结论均为两个模型在测试集上的评估结果;数据集内的实体和关系的文本描述使用基于BERT的知识图谱嵌入算法(KG-BERT)所定义的内容。
二、实验评价指标
知识图谱的缺损三元组(头实体,关系,?)可能对应着多个尾实体,依照惯例在进行评估时,需要从候选三元组中去除所有出现过的训练集、验证集、测试集中的所有可能实体(除了标签实体);在过滤后的实体中,以分类层输出的softmax值进行排名;测试集中第i个三元组的真实答案在所有实体中的排名为ranki。
1、平均排名(MR)
MR指测试集中所有ranki的平均值,其表达式为:
该指标反映了平均情况下真实答案在候选实体中的排名;其中,MR越低,说明模型的推理性能越好;
2、平均排名倒数(MRR)
MRR指测试集中所有的ranki的倒数的平均值,其表达式为:
相较于MR,该指标更关注模型能否在候选实体中找到真实答案的高排名;MRR越高,说明模型推理性能越好;
3、排名前n结点平均数(Hits@n)
Hits@n指测试集中所有的ranki≤n的平均值,其中,n通常取10、3、1,其表达式为:
该指标模型反映模型能否将真实答案排名到前n,只关注模型的高排名表现;Hits@n越大,说明模型推理性能越好。
三、实验环境
实验环境会影响实验结果,本实验环境如表2所示,供研究参考,即:
表2实验环境
四、参数设置
参数设置会影响实验结果,本实验详尽参数设置如表3所示,即:
表3参数设置

五、实验结果
为了比较本发明中预编码机制的推理速度优势,在实验中选取KG-BERT与本发明所提供的基于预编码的掩码语言模型以及基于预编码的融合结构信息与语义信息的框架在WN18RR和UMLS测试集上进行对比;KG-BERT的输入为文本,而本发明所提供的模型的输入均为预编码表达;KG-BERT的推理速度与数据集中的实体规模有关,实体越多,推理速度越长;参照表4所示,表4显示出了在预编码机制下避免编码长文本所带来的加速度推理效果;其中,Ours-1表示本发明所提供的基于预编码的掩码语言模型,Ours-2表示本发明所提供的基于预编码的融合结构信息与语义信息的框架;从表4中可以看出,本发明所提供的模型在推理速度上的进步有显著效果,另外,由于Ours-2需要使用嵌入模型,从而导致推理速度不如Ours-1;
表4推理速度比较
为了公平合理地比较本发明模型以及融合框架的推理性能,选取的基准模型分为三类:基于嵌入的模型、基于描述的模型和联合模型;其中,基于嵌入的模型包括:用于建模多关系数据的转换嵌入模型(TransE)、基于复数空间关系旋转的知识图谱嵌入模型(RotatE)、双线性对角模型(DistMult)、卷积二维知识图谱嵌入模型(ConvE);基于描述的模型包括:基于BERT的知识图谱嵌入算法(KG-BERT)、多任务知识图谱补全算法(MTL_KGC);联合模型包括:预训练知识图谱嵌入模型(Pretrain-KGE)、结构增强的知识图谱文本表示学习(StAR)、知识图完成的联合语言语义和结构嵌入模型(LASS)。
参照表5所示,表5为本发明所提供的Ours-1和Ours-2分别在WN18RR数据集、UMLS数据集上的具体实验结果;其中,在WN18RR数据集上,以MRR和H its@1、H its@3、H its@10作为评价指标;在UMLS数据集上,以MR和 Hits@10作为评价指标;另外,除了本发明所提供的Ours-1和Ours-2,其余实验结果均取自原论文结果;且表5中“-”表示论文中未作说明的数据,加粗体表示该指标下最好的结果,下划线表示该指标下次好的结果。
表5实验结果
根据实验结果可以得出,在UMLS数据集上,本发明所提供的Ours-1和Ours-2分别取得了最好和次好的效果;在WN18RR数据集上,本发明所提供的Ours-1和Ours-2在平均排名倒数(MRR)、排名前一结点平均数(Hits@1)、排名前三结点平均数(Hits@3)三个指标上取得了最好的效果,但是在Hits@10指标上我们的模型效果位列第三;通过分析可以认为,本发明所提出的模型在预测高排名方面更有优势;从直观结果上可以认为,基于预编码的融合结构信息与语义信息的框架(Ours-2)相比未加入融合的基于预编码的掩码语言模型(Ours-1),在各项指标上均有优化,因此本发明所提供的融合框架是有效的。
为了更加直观地表现知识图谱补全算法的意义,参照图4所示,图4展示了在WN18RR数据集上选取6个缺失三元组的实例分析;其中,黑体表示预测结果和标签一致,结果前的数字为真实答案的排名;在这些不完整三元组上,基于预编码的融合结构信息与语义信息的框架(Ours-2)的结果均好于基于预编码的掩码语言模型(Ours-1)。
知识图谱能够在医疗辅助诊断方面发挥重要作用;医疗知识图谱的构建可以从多种数据源中获取信息,包括临床试验、学术论文、病历信息等,这有助于提供更全面的信息,为医生提供更多维度的数据支持。在构建了结构化的医学知识图谱后,知识图谱补全能够填补知识图谱中的信息缺失,提供更全面、准确的医学知识,从而增强对患者病情的理解和提供更精准的诊断。补全的知识可以为医生提供更多的选择和决策支持;当面临复杂的病例时,医生可以依赖于更全面、细致的知识图谱,做出更明智的诊断和治疗决策。
知识图谱可能存在信息不完整的情况,特别是在涉及新的疾病、治疗方法或最新研究进展时;知识图谱补全可以通过整合最新的医学文献、研究数据以及临床实践,为医生提供最新、全面的医学信息。
除此之外,一个拥有大量医学信息的知识图谱可以用于构建辅助医疗问答系统;结合自然语言处理中的实体识别、关系识别、意图推断、问答匹配、语言生成等技术,问答系统能够针对病人提出的问题给出建议性回答,提供即时的信息,帮助患者更好地理解病情、症状和治疗选项;对于病人提出的非疑难杂症常见问题,系统能够自动回复以减轻医生解答负担,使医生能够更专注于复杂的病例和临床决策;在一些医疗资源不足的地区,医疗问答系统可以通过互联网使医学知识更广泛地传播,弥补医疗资源不足的问题。
显然,上述实施例仅仅是为清楚地说明所作的举例,并非对实施方式的限定。对于所属领域的普通技术人员来说,在上述说明的基础上还可以做出其它不同形式变化或变动。这里无需也无法对所有的实施方式予以穷举。而由此所引申出的显而易见的变化或变动仍处于本发明创造的保护范围之中。

Claims (10)

  1. 一种知识图谱链路预测方法,其特征在于,包括:
    获取数据集合;其中,数据集合包括实体描述文本集合、关系描述文本集合;获取各个实体描述文本对应的索引值,构建索引集合;
    将数据集合输入至初始化后的预编码模型中,分别对各个实体描述文本和各个关系描述文本进行预处理;对预处理后的各个实体描述文本和各个关系描述文本进行池化操作,得到各个实体描述文本的实体语义表达、各个关系描述文本的关系语义表达;对所有实体语义表达、所有关系语义表达进行嵌入操作,得到实体嵌入向量和关系嵌入向量;
    根据实体嵌入向量和关系嵌入向量,结合索引集合,构建三元组集合,将三元组集合划分为训练集和测试集,将训练集对应的逆关系三元组添加至训练集中,得到目标训练集;将测试集对应的逆关系三元组添加到测试集中,得到目标测试集;
    初始化主掩码模型,按照预设的批量大小,从目标训练集中抽取样本,得到样本集合;构建样本集合中各个样本对应的各个掩码三元组;对各个掩码三元组中各个元素分别添加对应的位置向量,结合主掩码模型的开始和结束标志向量,得到各个样本对应的各个输入序列;
    将各个样本对应的各个输入序列同时输入至主掩码模型中,经过多层的Transformer块处理,输出各个输入序列对应的最后一层掩码位置上的向量;将各个输入序列对应的最后一层掩码位置上的向量输入至分类层中,经过softmax操作,输出各个输入序列对应的各个实体分布概率;
    构建损失函数,并利用Adam优化器最小化损失函数值,更新主掩码模型的参数,直至抽取完目标训练集中所有样本,得到当前轮次主掩码模型的参数;利用评价函数评估当前轮次主掩码模型,若当前轮次主掩码模型表现优于上一轮次主掩码模型表现,则保存当前轮次主掩码模型的权重,进行下一轮次训练,直到达到预设的训练轮数,结束训练,得到训练好的主掩码模型;
    基于目标测试集,构建测试集掩码三元组,从而得到测试集输入序列; 将测试集输入序列输入至训练好的主掩码模型中,输出实体分类概率;通过实体分类概率,预测潜在可能实体。
  2. 根据权利要求1所述的一种知识图谱链路预测方法,其特征在于,所述将数据集合输入至初始化后的预编码模型中,分别对各个实体描述文本和各个关系描述文本进行预处理;对预处理后的各个实体描述文本和各个关系描述文本进行池化操作,得到各个实体描述文本的实体语义表达、各个关系描述文本的关系语义表达;对所有实体语义表达、所有关系语义表达进行嵌入操作,得到实体嵌入向量和关系嵌入向量包括:
    通过池化操作,将实体描述文本、关系描述文本概括成语义信息特征,其表达式为:

    其中,entity_des表示实体描述;relation_des表示关系描述;表示第i个实体描述文本;表示第j个关系描述文本;ei表示第i个实体语义表达,i∈[1,n],n表示实体数量;rj表示第j个关系语义表达,j∈[1,m],m表示关系数量;
    对实体语义表达、关系语义表达进行嵌入操作,得到实体嵌入向量、关系嵌入向量,其表达式为:
    E=[e1;e2;...;en]
    R=[r1;r2;...;rm]
    Embeddings=[E,R]
    其中,n表示实体数量;m表示关系数量;E表示实体嵌入向量;R表示关系嵌入向量;Embeddings=[E,R]表示嵌入层向量。
  3. 根据权利要求1所述的一种知识图谱链路预测方法,其特征在于,所述构建样本集合中各个样本对应的各个掩码三元组;对各个掩码三元组中各个元素分别添加对应的位置向量,结合主掩码模型的开始和结束标志向量,得到各个样本对应的各个输入序列包括:
    从样本集合中任选一个样本A,构建样本A对应的掩码三元组;将样本A 对应的掩码三元组中的各个元素上添加上对应的位置向量,结合主掩码模型的开始和结束标志向量,得到样本A对应的输入序列,其表达式为:
    其中,xinput表示样本A对应的输入序列;ECLS表示序列的开始符号;ESEP表示序列的结束符号;Eh表示样本A对应的头实体特征表示;Er表示样本A对应的关系特征表示;Emask表示掩码向量;表示序列第s个位置对应的位置编码;
    基于上述操作,同时构建各个样本对应的各个掩码三元组,并得到各个样本对应的各个输入序列。
  4. 根据权利要求3所述的一种知识图谱链路预测方法,其特征在于,所述将各个样本对应的各个输入序列同时输入至主掩码模型中,经过多层的Transformer块处理,输出各个输入序列对应的最后一层掩码位置上的向量;将各个输入序列对应的最后一层掩码位置上的向量输入至分类层中,经过softmax操作,输出各个输入序列对应的各个实体分布概率包括:
    对样本集合中样本A对应的输入序列进行如下操作:
    将样本A对应的输入序列输入到主掩码模型中,样本A对应的输入序列会经过12层的Transformer块处理;最后一层的Emask位置上的向量可以作为带预测实体的表达,其表达式为:
    znum=Transformer(znum-1),num=1,2,...,12
    z0=xinput
    其中,znum表示第num层的输入;z0表示第一层的输入;表示最后一层Emask位置上的向量;表示最后输出Emask的值;
    分类层为一个前馈神经网络,所述分类层的输入维度为的维度,输出维度为实体数量;将输入至分类层中,再经过softmax操作,得到实体分类概率,则其表达式为:
    其中,表示实体分类概率;
    基于上述操作,将样本集合中各个样本对应的各个输入序列同时输入至主掩码模型中,输出各个输入序列对应的各个实体分布概率。
  5. 根据权利要求1所述的一种知识图谱链路预测方法,其特征在于,所述构建损失函数包括:
    基于各个输入序列对应的各个实体分布概率,构建损失函数;其中,所述损失函数为交叉熵损失函数,其表达式为:
    其中,yi表示第i个实体的实际标签,yi取0或1;当yi取1时表示第i个实体是标签;当yi取0时表示第i个实体不是标签;表示第i个实体在实体分布概率中对应的第i个概率;N表示所有实体的数量;i表示索引值。
  6. 根据权利要求1所述的一种知识图谱链路预测方法,其特征在于,所述初始化主掩码模型,按照预设的批量大小,从目标训练集中抽取样本,得到样本集合后还包括:
    在预设范围内,随机初始化嵌入模型的各个实体结构嵌入表达和各个关系结构嵌入表达,将各个实体结构嵌入表达和各个关系结构嵌入表达分别整合为实体嵌入矩阵和关系嵌入矩阵;
    通过预编码模型得到的实体嵌入向量中包含多个实体语义表达;通过预编码模型得到的关系嵌入向量包含多个关系语义表达;
    将样本集合中各个样本对应的实体语义表达、关系语义表达,与嵌入模型对应的实体结构嵌入表达、关系结构嵌入表达进行拼接,得到各个样本对应的各个拼接特征;将各个样本对应的各个拼接特征输入至融合模块中,得到各个样本对应的融合后的各个头实体表达和各个关系表达;根据各个样本对应的融合后的各个头实体表达和各个关系表达,构建各个样本对应的各个融合掩码三元组;对各个融合掩码三元组中的各个元素添加对应的位置向量,结合主掩码模型的开始和结束标志向量,得到各个样本对应的各个融合输入序列;
    将各个样本对应的各个融合输入序列同时输入至主掩码模型中。
  7. 根据权利要求6所述的一种知识图谱链路预测方法,其特征在于,所述将样本集合中各个样本对应的实体语义表达、关系语义表达,与嵌入模型对应的实体结构嵌入表达、关系结构嵌入表达进行拼接,得到各个样本对应的各个拼接特征;将各个样本对应的各个拼接特征输入至融合模块中,得到各个样本对应的融合后的各个头实体表达和各个关系表达包括:
    在样本集合中任选一个样本B,将样本B对应的实体语义表达、关系语义表达定义为来自预编码模型富含语义信息的描述表达u;将嵌入模型中对应的实体结构嵌入表达、关系结构嵌入表达定义为来自嵌入模型带有结构信息的嵌入表达v;
    将来自预编码模型富含语义信息的描述表达u和来自嵌入模型带有结构信息的嵌入表达v进行拼接,得到拼接特征c,其拼接特征为两个表达的拼接结果,其表达式为:
    c(u,v)=[u,v]
    将样本B对应的拼接特征输入到融合模块中,通过降维的方式,提取融合信息,得到融合后的头实体与关系表达,其表达式为

    其中,表示样本B对应的融合后的头实体表达;表示样本B对应的融合后的关系表达;
    基于上述操作,对样本集合中各个样本同时进行拼接,得到各个样本对应的各个拼接特征,并得到各个样本对应的融合后的各个头实体表达和各个关系表达。
  8. 根据权利要求7所述的一种知识图谱链路预测方法,其特征在于,所述根据各个样本对应的融合后的各个头实体表达和各个关系表达,构建各个样本对应的各个融合掩码三元组;对各个融合掩码三元组中的各个元素添加对应的位置向量,结合主掩码模型的开始和结束标志向量,得到各个样本对应的 各个融合输入序列包括:
    基于样本B对应的融合后的头实体表达和关系表达,构建样本B对应的融合掩码三元组;将样本B对应的融合掩码三元组中各个元素上分别添加对应的位置向量,结合主掩码模型的开始和结束标志向量,得到样本B对应的融合输入序列,其表达式为:
    其中,xinput_fusion表示样本B对应的融合输入序列;ECLS表示序列的开始符号;ESEP表示序列的结束符号;表示样本B对应的融合后的头实体表达;表示样本B对应的融合后的关系表达;Emask表示掩码向量;表示序列第s个位置对应的位置编码;
    基于上述操作,通过各个样本对应的融合后的各个头实体表达和各个关系表达,同时构建各个样本对应的各个融合掩码三元组,并得到各个样本对应的各个融合输入序列。
  9. 根据权利要求6所述的一种知识图谱链路预测方法,其特征在于,所述嵌入模型为翻译模型。
  10. 根据权利要求9所述的一种知识图谱链路预测方法,其特征在于,所述构建损失函数包括:
    基于翻译模型原理,采用评分函数为余弦相似度函数,定义头实体和关系的嵌入向量之和ehr,其表达式为:
    ehr=|eh+er|
    其中,eh表示翻译模型中的头实体的嵌入向量;er表示翻译模型中的关系的嵌入向量;et表示翻译模型中的尾实体的嵌入向量;|| ||表示二范数计算;f(h,r,t)表示评分函数;
    在训练过程中,将负采样加入翻译模型损失函数中进行计算,作为对比损失LS,使得翻译模型学习到正比例得分高于负比例得分的嵌入表示,其表 达式为:
    其中,K表示负采样的实体集合;tk表示负采样的实体集合中第k个实体;
    将交叉熵损失函数作为分类损失LCE,其表达式为:
    其中,yi表示第i个实体的实际标签,yi取0或1;当yi取1时表示第i个实体是标签;当yi取0时表示第i个实体不是标签;表示第i个实体在实体分布概率中对应的第i个概率;N表示所有实体的数量;i表示索引值;
    主掩码模型优化总损失函数L为分类损失和对比损失的加权和,其表达式为:
    L=LCE+αLS
    其中,LCE表示分类损失;α表示对比损失的权重;LS表示对比损失。
PCT/CN2024/087157 2024-03-27 2024-04-11 一种知识图谱链路预测方法 Pending WO2025200055A1 (zh)

Priority Applications (1)

Application Number Priority Date Filing Date Title
GB2512021.3A GB2645089A (en) 2024-03-27 2024-04-11 Knowledge graph link prediction method

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202410358013.XA CN117952206B (zh) 2024-03-27 2024-03-27 一种知识图谱链路预测方法
CN202410358013.X 2024-03-27

Publications (1)

Publication Number Publication Date
WO2025200055A1 true WO2025200055A1 (zh) 2025-10-02

Family

ID=90793045

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2024/087157 Pending WO2025200055A1 (zh) 2024-03-27 2024-04-11 一种知识图谱链路预测方法

Country Status (3)

Country Link
CN (1) CN117952206B (zh)
GB (1) GB2645089A (zh)
WO (1) WO2025200055A1 (zh)

Cited By (14)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN121072906A (zh) * 2025-11-10 2025-12-05 上海交通大学 基于知识图谱的老年人地铁出行目的地活动类型预测方法
CN121212728A (zh) * 2025-11-25 2025-12-26 中国人民解放军国防科技大学 基于梯度特征与社区结构的岗位人员推荐解释方法及装置
CN121257687A (zh) * 2025-12-04 2026-01-02 嘉兴大学 一种多模态知识图谱稀疏信息增强系统
CN121303119A (zh) * 2025-11-13 2026-01-09 中科世通亨奇(北京)科技有限公司 一种基于gan和模板自动构建的三元组抽取方法及装置
CN121580309A (zh) * 2025-11-27 2026-02-27 山东浪潮智慧建筑科技有限公司 建筑规范文档布局组件关系智能抽取方法、设备及介质
CN121636476A (zh) * 2025-11-26 2026-03-10 国网辽宁省电力有限公司物资分公司 基于多模态文档解析与知识图谱语义映射的电力项目物资清册智能生成方法及系统
CN121659076A (zh) * 2025-12-12 2026-03-13 合肥工业大学设计院(集团)有限公司 融合深度学习的勘察场景监控违规行为自动识别方法及系统
CN121681847A (zh) * 2026-02-11 2026-03-17 云南师范大学 一种基于结构与语义融合的对比学习知识图谱嵌入方法
CN121902948A (zh) * 2026-01-09 2026-04-21 齐鲁工业大学(山东省科学院) 基于文化基因图谱约束的民间文学类非遗aigc再生方法
CN121980192A (zh) * 2026-03-30 2026-05-05 中国电子科技集团公司第五十四研究所 一种基于三元组胶囊网络的卫星观测需求生成方法
CN122177321A (zh) * 2026-05-13 2026-06-09 济南大学 一种水泥基材料的关系补全方法、系统、设备及介质
CN122221189A (zh) * 2026-05-19 2026-06-16 国网江西省电力有限公司电力科学研究院 基于复合标注联合训练的电力小样本实体抽取方法及系统
CN122432342A (zh) * 2026-06-18 2026-07-21 国网浙江省电力有限公司科技创新中心 一种小样本领域知识文本扩充方法及系统
CN122432342B (zh) * 2026-06-18 2026-08-21 国网浙江省电力有限公司科技创新中心 一种小样本领域知识文本扩充方法及系统

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN118798348B (zh) * 2024-09-13 2024-11-22 深圳市互盟科技股份有限公司 一种设备终端的算力分配方法及系统
CN120146189B (zh) * 2025-02-26 2025-09-02 中国科学院文献情报中心 一种基于掩码机制的大模型文本逆向推理增强方法

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113190691A (zh) * 2021-05-28 2021-07-30 齐鲁工业大学 一种知识图谱的链路预测方法及系统
CN113535972A (zh) * 2021-06-07 2021-10-22 吉林大学 一种融合上下文语义的知识图谱链路预测模型、方法及装置
WO2022234273A1 (en) * 2021-05-06 2022-11-10 Hivemap Limited Project data processing method and apparatus
CN116127921A (zh) * 2023-02-16 2023-05-16 广东工业大学 一种实体关系联合三元组的知识抽取方法及系统
CN117708341A (zh) * 2023-11-21 2024-03-15 中国人民解放军国防科技大学 一种基于嵌入维度自动学习的知识图谱链路预测方法

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US11625543B2 (en) * 2020-05-31 2023-04-11 Salesforce.Com, Inc. Systems and methods for composed variational natural language generation
CN115081445A (zh) * 2022-06-23 2022-09-20 江西师范大学 一种基于多任务学习的短文本实体消歧方法
CN117131520A (zh) * 2023-08-02 2023-11-28 杭州电子科技大学 基于动态掩膜和生成恢复的两阶段图像隐私保护方法与系统
CN116956940A (zh) * 2023-08-03 2023-10-27 杭州电子科技大学 一种基于多向式遍历与提示学习的文本事件抽取方法

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2022234273A1 (en) * 2021-05-06 2022-11-10 Hivemap Limited Project data processing method and apparatus
CN113190691A (zh) * 2021-05-28 2021-07-30 齐鲁工业大学 一种知识图谱的链路预测方法及系统
CN113535972A (zh) * 2021-06-07 2021-10-22 吉林大学 一种融合上下文语义的知识图谱链路预测模型、方法及装置
CN116127921A (zh) * 2023-02-16 2023-05-16 广东工业大学 一种实体关系联合三元组的知识抽取方法及系统
CN117708341A (zh) * 2023-11-21 2024-03-15 中国人民解放军国防科技大学 一种基于嵌入维度自动学习的知识图谱链路预测方法

Cited By (15)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN121072906A (zh) * 2025-11-10 2025-12-05 上海交通大学 基于知识图谱的老年人地铁出行目的地活动类型预测方法
CN121303119A (zh) * 2025-11-13 2026-01-09 中科世通亨奇(北京)科技有限公司 一种基于gan和模板自动构建的三元组抽取方法及装置
CN121212728B (zh) * 2025-11-25 2026-02-24 中国人民解放军国防科技大学 基于梯度特征与社区结构的岗位人员推荐解释方法及装置
CN121212728A (zh) * 2025-11-25 2025-12-26 中国人民解放军国防科技大学 基于梯度特征与社区结构的岗位人员推荐解释方法及装置
CN121636476A (zh) * 2025-11-26 2026-03-10 国网辽宁省电力有限公司物资分公司 基于多模态文档解析与知识图谱语义映射的电力项目物资清册智能生成方法及系统
CN121580309A (zh) * 2025-11-27 2026-02-27 山东浪潮智慧建筑科技有限公司 建筑规范文档布局组件关系智能抽取方法、设备及介质
CN121257687A (zh) * 2025-12-04 2026-01-02 嘉兴大学 一种多模态知识图谱稀疏信息增强系统
CN121659076A (zh) * 2025-12-12 2026-03-13 合肥工业大学设计院(集团)有限公司 融合深度学习的勘察场景监控违规行为自动识别方法及系统
CN121902948A (zh) * 2026-01-09 2026-04-21 齐鲁工业大学(山东省科学院) 基于文化基因图谱约束的民间文学类非遗aigc再生方法
CN121681847A (zh) * 2026-02-11 2026-03-17 云南师范大学 一种基于结构与语义融合的对比学习知识图谱嵌入方法
CN121980192A (zh) * 2026-03-30 2026-05-05 中国电子科技集团公司第五十四研究所 一种基于三元组胶囊网络的卫星观测需求生成方法
CN122177321A (zh) * 2026-05-13 2026-06-09 济南大学 一种水泥基材料的关系补全方法、系统、设备及介质
CN122221189A (zh) * 2026-05-19 2026-06-16 国网江西省电力有限公司电力科学研究院 基于复合标注联合训练的电力小样本实体抽取方法及系统
CN122432342A (zh) * 2026-06-18 2026-07-21 国网浙江省电力有限公司科技创新中心 一种小样本领域知识文本扩充方法及系统
CN122432342B (zh) * 2026-06-18 2026-08-21 国网浙江省电力有限公司科技创新中心 一种小样本领域知识文本扩充方法及系统

Also Published As

Publication number Publication date
GB2645089A (en) 2026-07-22
CN117952206A (zh) 2024-04-30
CN117952206B (zh) 2024-05-31

Similar Documents

Publication Publication Date Title
CN117952206B (zh) 一种知识图谱链路预测方法
CN113297364B (zh) 一种面向对话系统中的自然语言理解方法及装置
CN110781680B (zh) 基于孪生网络和多头注意力机制的语义相似度匹配方法
JP2025077914A (ja) セマンティックグラフモデルに基づく法案インテリジェント分析方法及びシステム
CN114722839B (zh) 人机协同对话交互系统及方法
CN117316466B (zh) 一种基于知识图谱与自然语言处理技术的临床决策方法、系统及设备
CN111428443A (zh) 一种基于实体上下文语义交互的实体链接方法
CN114036934A (zh) 一种中文医学实体关系联合抽取方法和系统
CN118899077A (zh) 一种基于多模态大模型的中医舌诊分析系统及方法
CN111897944A (zh) 基于语义空间共享的知识图谱问答系统
CN115063709A (zh) 基于跨模态注意与分层融合的多模态情感分析方法及系统
CN114861654A (zh) 一种中文文本中基于词性融合的对抗训练的防御方法
CN113807079A (zh) 一种基于序列到序列的端到端实体和关系联合抽取方法
CN116467440B (zh) 基于李氏人工肝病历的多层次语义文本分类方法
CN110851620A (zh) 一种基于文本嵌入和结构嵌入联合的知识表示方法
CN116089618B (zh) 融合三元损失和标签嵌入的图注意力网络文本分类模型
CN116052858A (zh) 一种基于bert和特征融合的智能导诊方法
CN119669530B (zh) 基于llm的知识图谱生成式辅助教学答疑方法及系统
CN118035286B (zh) 一种基于医疗大模型的信息查询系统
CN118674036A (zh) 一种学习细粒度通用知识的跨域小样本关系抽取方法和装置
Qin Machine translation technology based on natural language processing
CN117421387A (zh) 一种融合关系语义信息的医疗文本实体关系联合抽取方法
CN120494098A (zh) 面向多领域文本的层次化语义理解与智能问答生成方法
CN119357368A (zh) 一种基于不确定性知识图谱的语义推理方法
CN119028508A (zh) 一种轻量级空间适配器增强的医学报告生成方法

Legal Events

Date Code Title Description
ENP Entry into the national phase

Ref document number: 202512021

Country of ref document: GB

Kind code of ref document: A

Free format text: PCT FILING DATE = 20240411

WWE Wipo information: entry into national phase

Ref document number: 2512021.3

Country of ref document: GB

121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 24932342

Country of ref document: EP

Kind code of ref document: A1

WWP Wipo information: published in national office

Ref document number: 2512021.3

Country of ref document: GB