Background
With the popularization and development of big data, large-scale knowledge maps storing a large amount of knowledge are more and more emphasized by people. Most knowledge maps are stored in the form of triples, for example, a triplet (Sichuan, province, and achievement) is a triplet, where Sichuan is a head entity, achievement is a tail entity, and province is a relationship between the head and tail entities, and the triplet represents the fact that the province of Sichuan is an achievement. This storage format is advantageous for storage on the internet. However, this form is discrete and thus not conducive to the computation of a knowledge graph. To address the computability problem of knowledge-graphs, methods of knowledge-graph representation learning are proposed, which aim to represent entities and relationships in knowledge-graphs as vectors in vector space. For a query (Sichuan, province, are), the representation learning method can easily give the predicted result of the tail entity, but lacks interpretability. Thus a multi-hop inference method of knowledge graph is proposed.
Specifically, for a query (head entity, relationship, are), the multi-hop inference of the knowledge-graph can be regarded as starting from the head entity (node in the graph), selecting the next relationship (edge in the graph) as an outgoing edge, and jumping to the next entity until the maximum number of hops is reached, the last located entity is the predicted tail entity, and the multi-hop path is an interpretable path.
A rare relationship is a definition in a knowledge graph, and specific meanings are those relationships that possess a small number of triples. In particular, a relationship may be considered a small-order relationship if the number of triples in the knowledge-graph to which it corresponds is less than a certain threshold.
MINERVA published on the 2017 NIPS conference was the earliest method to use reinforcement learning for knowledgegraph multi-hop inference. The method learns an agent (agent) which gives the probability of selecting each relationship as the next hop under the current entity, only the maximum number of hops is reached, if the correct tail entity stays at last, 1 is returned as feedback, otherwise 0 is returned as feedback. The MultiHop method disclosed in EMNLP of 2018 is an improvement on MINERVA, and provides a continuous feedback strategy for the problem of slow convergence caused by only two kinds of feedback, namely 0 and 1, of MINERVA, i.e. for paths which do not reach the correct tail entity, a feedback between 0 and 1 is also given, which is shown by learning through a knowledge graph.
Disclosure of Invention
The technical problem to be solved and the technical task to be solved by the invention are to perfect and improve the prior technical scheme, and provide a less-order relational model training method based on knowledge graph meta-information so as to achieve the aim that good training can be realized by a small amount of data. Therefore, the invention adopts the following technical scheme.
A few-time relation model training method based on knowledge graph meta-information is characterized by comprising the following steps:
1) initializing meta-model parameters;
2) performing iterative multi-round training on the common relation to obtain trained meta-model parameters, and circulating the steps as follows:
201) randomly sampling the common relation and the corresponding support set and query set;
202) applying a loss gradient on the support set to obtain a temporary model parameter;
203) calculating gradient loss on the query set and the temporary model parameters, and applying and updating the meta-model parameters;
3) and training the few-time relation model by using the meta-model parameters as initialization parameters.
According to the technical scheme, the relationships are divided into common relationships and less-order relationships, and are treated differently, so that the assumption that each relationship of the previous model has enough data to train is corrected.
The technical scheme uses the common relations to carry out meta-learning, and because the common relations contain enough data, great help can be provided for learning of the relations for a few times. The invention can learn common characteristics between different common relations which are irrelevant to the relations, and the common characteristics are embodied as parameters of the meta-model.
The technical scheme uses the parameters of the meta-model as initialization, the model with few relationships can have a good starting point, and the training can be well realized only by little data.
As a preferable technical means: in step 1), parameters of the meta-model are initialized randomly as a basis for the subsequent cyclic training.
As a preferable technical means: in step 2), this step consists of 3 cyclically executed substeps 201), 202) and 203), terminating the exit until a set training round is reached.
As a preferable technical means: in step 201), the general random sampling relationship is r, and for the general random sampling relationship, triples containing r are respectively formed into support sets
And query set
Wherein
And
the same number of triplets is contained and there is no intersection between the two.
As a preferable technical means: in step 202), the meta-model parameters θ and the support set
Training is carried out, and the loss function is applied to obtain the corresponding loss
And using the loss to calculate a gradient, obtaining new temporary parameters as follows:
where α is a learning rate parameter.
As a preferable technical means: in step 203), temporary meta-model parameter θ'
rAnd query set
Training is carried out, and the loss function is applied to obtain the corresponding loss
And using the loss to calculate a gradient, updating θ, which is defined as:
where β is another learning rate parameter.
As a preferable technical means: in step 3), for a small-order relation rsInitializing a few-time relation model by taking the finally obtained trained meta-model parameter theta in the step 2) as an initialization parameter, and then initializing all the contained rsTraining is performed on the triplets of (1).
Has the advantages that:
the invention distinguishes the common relation and the few-time relation, and overcomes the problem that the prior art does not distinguish the common relation and the few-time relation, but assumes that the common relation and the few-time relation have enough data for training, and the assumption is not true in the few-time relation, so that the model has poor performance in the few-time relation; according to the technical scheme, some characteristics irrelevant to the relation can be learned through a large amount of data of the common relation, and the characteristics can well guide the learning of the relation for a few times. The specific embodiment of the characteristics is the parameters of the meta-model, and the correspondingly guided embodiment is that the parameters of the meta-model can be used as the initialization of the least-order relation model; by using the parameters of the meta-model as initialization, the model with the few-time relationship can have a good starting point, and can be trained well only by little data.
Detailed Description
The technical scheme of the invention is further explained in detail by combining the drawings in the specification.
Before introducing specific steps, a multi-hop inference model in the knowledge graph needs to be introduced, and specifically, an agent (agent) is learned by using the idea of reinforcement learning to search for an inference path on the knowledge graph. The process of this search is a typical Markov Decision Process (MDP) which can be defined as:
the state is as follows: the state of the t-th hop may be defined as a triplet
Wherein r is
qIs a relation of a query, e
sIs the head entity of the query and,
is the entity where the current hop is located.
The actions are as follows: for state s
tThere will be corresponding action space
Comprises a
All outgoing edges and corresponding next entities. In addition, a return edge pointing to itself is added for each action space, since the number of hops is fixed, and the return edge is similar to a terminating action.
Transferring: for state s
tIf the agent selects an action space
An action in
Then the corresponding transfer function is defined as
And (3) feedback: if the entity is located when the maximum number of hops T is reached
Is the correct tail entity e
tThen the feedback is 1, otherwise a feedback between 0 and 1
Where f is a scoring function of the knowledge graph representation learning.
To address the MDP problem described above, the present invention uses a policy network to provide the agent with a probability of selecting each action. Wherein, a long-time memory network (LSTM) is used to store historical multi-hop path information, which is specifically defined as follows:
ht=LSTM(ht-1,at-1)
then we superimpose all the actions in the action space together, denoted At. The probability of each action given by the policy network is defined as:
wherein W1And W2Is the weight to be learned, ReLU is the activation function, and softmax is the logistic regression function.
Finally, a relationship r and a data set are given
The overall loss function is defined as:
after defining a multi-hop inference model in the knowledge graph, we present specific steps of the method, wherein both the meta model and the least-order relation model refer to the defined multi-hop inference model, as shown in fig. 1, the steps of the invention include:
a: random initialization of meta-model parameters
B: performing iterative multi-round training on the common relation to obtain trained meta-model parameters, and circulating the steps as follows:
b1: randomly sampling the common relation r and the corresponding support set and query set;
b2: applying a loss gradient to the support set to obtain temporary model parameters
B3: computing gradient penalties on the query set and the temporary model parameters, applying and updating meta-model parameters
C: training a hypo-relational model using meta-model parameters as initialization parameters
Further, in the step A, the step B,
and randomly initializing parameters of the meta-model as a basis for the subsequent cyclic training.
Further, in the step B,
this step consists of 3 substeps (B1, B2, and B3) performed in cycles until the exit is terminated after a certain training round is reached.
Further, in the step B1,
randomly sampling a common relation r, and for the common relation, randomly sampling a triple containing r to respectively form a support set
And query set
Wherein
And
the same number of triplets is contained and there is no intersection between the two.
Further, in the step B2,
in the existing meta-model parameters θ and support set
Training is carried out, and the corresponding loss is obtained by applying the previously defined loss function
And using the loss to calculate a gradient, obtaining new temporary parameters as follows:
where α is a learning rate parameter.
Further, in the step B3,
in temporary Meta-model parameter θ'
rAnd query set
Training is carried out, and the corresponding loss is obtained by applying the previously defined loss function
And calculating the gradient by using the loss, and updating theta, wherein the specific definition is as follows:
where β is another learning rate parameter.
Further, in the step C,
for a small order relation rsTaking the finally obtained trained meta-model parameter theta in the step B as an initialization parameter, initializing a less-order relation model, and then, initializing all the contained rsTraining on the triplets of (a).
In this embodiment:
1. the relationships are divided into common relationships and few-time relationships, and the relationships are treated differently, so that the assumption that each relationship of the previous model has enough data to train is corrected.
2. Meta-learning is performed using common relationships, which can provide great help for learning relationships a small number of times because common relationships contain a sufficient amount of data. The invention can learn common characteristics between different common relations which are irrelevant to the relations, and the common characteristics are embodied as parameters of the meta-model.
3. By using the parameters of the meta-model as initialization, the model with few relationships can have a good starting point and can be trained well with only little data.
The invention can design corresponding characteristics according to different less-order relations and then carry out training and learning. However, the overhead of manually generalizing features is very large, and there is no way to adapt to various knowledge maps well. Therefore, the invention can automatically learn common characteristics among common relations and be applied to the relations of few times so as to further efficiently save manpower.
The method for training a few-time relationship model based on knowledge graph spectral meta-information shown in fig. 1 is a specific embodiment of the present invention, has embodied the substantial features and advances of the present invention, and can be modified equivalently according to the practical use requirements and under the teaching of the present invention, which is within the scope of protection of the present solution.