CN110472067B - Knowledge graph representation learning method, knowledge graph representation learning device, computer equipment and storage medium - Google Patents

Knowledge graph representation learning method, knowledge graph representation learning device, computer equipment and storage medium Download PDF

Info

Publication number
CN110472067B
CN110472067B CN201910764648.9A CN201910764648A CN110472067B CN 110472067 B CN110472067 B CN 110472067B CN 201910764648 A CN201910764648 A CN 201910764648A CN 110472067 B CN110472067 B CN 110472067B
Authority
CN
China
Prior art keywords
triplet
entity
vector
knowledge graph
loss function
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.)
Active
Application number
CN201910764648.9A
Other languages
Chinese (zh)
Other versions
CN110472067A (en
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.)
Tencent Technology Shenzhen Co Ltd
Original Assignee
Tencent Technology Shenzhen Co Ltd
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 Tencent Technology Shenzhen Co Ltd filed Critical Tencent Technology Shenzhen Co Ltd
Priority to CN201910764648.9A priority Critical patent/CN110472067B/en
Publication of CN110472067A publication Critical patent/CN110472067A/en
Application granted granted Critical
Publication of CN110472067B publication Critical patent/CN110472067B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/30Information retrieval; Database structures therefor; File system structures therefor of unstructured textual data
    • G06F16/36Creation of semantic tools, e.g. ontology or thesauri
    • G06F16/367Ontology
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/04Architecture, e.g. interconnection topology
    • G06N3/045Combinations of networks
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/08Learning methods

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Life Sciences & Earth Sciences (AREA)
  • Computational Linguistics (AREA)
  • Data Mining & Analysis (AREA)
  • General Engineering & Computer Science (AREA)
  • General Health & Medical Sciences (AREA)
  • Health & Medical Sciences (AREA)
  • Artificial Intelligence (AREA)
  • Biomedical Technology (AREA)
  • Biophysics (AREA)
  • Evolutionary Computation (AREA)
  • Molecular Biology (AREA)
  • Computing Systems (AREA)
  • Mathematical Physics (AREA)
  • Software Systems (AREA)
  • Databases & Information Systems (AREA)
  • Animal Behavior & Ethology (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The application discloses a knowledge graph representation learning method, a device, a computer device and a storage medium, wherein the method comprises the following steps: generating a positive triplet vector for each triplet in the knowledge graph; determining a target entity to be replaced in each triplet and an entity class thereof, and constructing a negative triplet vector of the triplet for each triplet by using a generating model; determining a first loss function value of the generated model according to the negative case triplet vector of each triplet; determining a second loss function value according to the entity category of the target entity in each triplet, the positive triplet vector and the negative triplet vector of each triplet in the knowledge graph and by using a second loss function of the discrimination model; and optimizing the normal triplet vector, the generated model and the discrimination model of each triplet in the knowledge graph according to the first loss function value and the second loss function value until the optimization target is reached. The scheme of the application can improve the accuracy of knowledge graph representation learning.

Description

Knowledge graph representation learning method, knowledge graph representation learning device, computer equipment and storage medium
Technical Field
The present application relates to the field of knowledge graph technologies, and in particular, to a knowledge graph representation learning method, a knowledge graph representation learning device, a computer device, and a storage medium.
Background
Knowledge maps are intended to describe various entities and their interrelationships that exist in the real world, and they organize knowledge in the form of triples, e.g., the form of triples may be: (head entity, relationship, tail entity). Representation learning of knowledge-graph aims at representing entities and relationships in the knowledge-graph in low-dimensional vectors.
Wherein, the learning process of the representation of the knowledge graph involves optimizing the objective function by utilizing negative examples. Wherein, the real triples in the knowledge graph belong to positive examples, and the negative examples are the constructed triples in practice. For example, for one triplet in the knowledge graph, entities in other triples in the knowledge graph can be randomly extracted to replace a head entity or a tail entity in the triplet, so that the constructed triplet belongs to the negative example of the triplet.
In the existing knowledge graph representation learning process, a plurality of unreasonable negative examples are often constructed, for example, the pair of triples (Xiaoming, birth place, shanghai) may be a negative example of the relationship error between entities (Beijing, birth place, shanghai). While unreasonable negative examples can affect the optimization process of knowledge graph representation learning, thereby affecting the accuracy of the finally represented entities and relationships.
Disclosure of Invention
In view of the above, the present application provides a knowledge graph representation learning method, apparatus, computer device and storage medium, so as to optimize the representation learning of the knowledge graph and improve the accuracy of the knowledge graph representation learning.
In order to achieve the above object, in one aspect, the present application provides a knowledge graph representation learning method, including:
Each triplet in the knowledge graph is respectively expressed as a vector to obtain a positive triplet vector of each triplet, and the positive triplet vector of the triplet comprises: a first entity vector for each entity in the triplet and a relationship vector for a relationship in the triplet;
For each triplet, determining a target entity to be replaced in the triplet and an entity class of the target entity;
Generating a second entity vector for representing the target entity in each triplet by using a generation model in a generation type antagonism network, determining candidate entities from the knowledge graph according to entity categories of the target entity, and replacing a first entity vector of the target entity in positive triplet vectors of the triplet with the first entity vector of the candidate entity to obtain a negative triplet vector corresponding to the triplet, wherein the similarity between the first entity vector of the candidate entity and the second entity vector of the target entity accords with a set condition;
determining a first loss function value by using a first loss function of the generation model according to the negative case triplet vector of each triplet in the knowledge graph;
Determining a second loss function value according to the entity category of the target entity, the positive triplet vector and the negative triplet vector of each triplet in the knowledge graph and by using a second loss function of the discrimination model in the generated countermeasure network;
And optimizing the normal triplet vector of each triplet in the knowledge graph, the generating model and the judging model according to the first loss function value and the second loss function value and by combining a set training algorithm until the optimization target is reached.
In one possible implementation manner, the optimizing the normal triplet vector of each triplet in the knowledge graph, the generating model and the discriminating model in combination with the set training algorithm includes:
And optimizing the positive triplet vector of each triplet in the knowledge graph, the generation model and the discrimination model by combining a gradient descent algorithm.
In yet another possible implementation manner, determining a first loss function value according to the negative triplet vector of each triplet in the knowledge-graph by using the first loss function of the generation model includes:
And (3) carrying out negative-example triplet vectors (h ', R and t') of all triples in the knowledge graph, and calculating a first loss function value R G by using the following first loss function in the generation model:
Wherein S represents a set of positive triplet vectors (h, r, t) of all triples in the knowledge graph, wherein h is a head entity vector in the positive triplet vector, t is a tail entity vector in the positive triplet vector, r represents a relation vector, and negative triplet vectors (h ', r, t') belong to negative triplet vectors generated based on the positive triplet vector in S, wherein h 'is the head entity vector in the negative triplet, and t' is the tail entity vector in the negative triplet vector;
fD(h',r,t')=h'+r-t';
E represents averaging.
In yet another possible implementation manner, the determining a second loss function value according to the entity class of the target entity in each triplet, the positive triplet vector and the negative triplet vector of each triplet in the knowledge graph, and using the second loss function of the discriminant model in the generated countermeasure network includes:
Determining a second loss function value L G according to the entity class of the target entity in each triplet in the knowledge graph and the positive triplet vector (h, r, t) of each triplet, and by using the following second loss function in the discrimination model in the generated countermeasure network:
Wherein S represents a set of positive triplet vectors (h, r, t) of all triples in the knowledge graph, wherein h is a head entity vector in the positive triplet vector, t is a tail entity vector in the positive triplet vector, r represents a relation vector, and negative triplet vectors (h ', r, t') belong to negative triplet vectors generated based on the positive triplet vector in S, wherein h 'is the head entity vector in the negative triplet, and t' is the tail entity vector in the negative triplet vector;
fD(h,r,t)=h+r-t;
fD(h',r,t')=h'+r-t';
gamma is a set boundary value;
n is the total number of target entities to be replaced in each triplet contained in the knowledge graph, i represents one entity of the knowledge graph, and i is a natural number from 1 to n;
e i represents a first entity vector of a target entity to be replaced in the triplet, e i is a head entity vector or a tail entity vector in a normal triplet vector of the triplet;
e j is a first entity vector of an entity in the knowledge graph, which is the same as the entity class of the target entity represented by e i, e j∈N(ei) represents that the entity represented by e j belongs to the entity class of the target entity represented by e i;
W is a trained parameter in the discriminant model.
In yet another possible implementation, the triples include a head entity, a tail entity, and a relationship of the head entity to the tail entity;
the determining, for each triplet, a target entity to be replaced in the triplet includes:
Generating a random number for each triplet;
If the random number is larger than the set value, determining the head entity in the triplet as a target entity to be replaced;
and if the random number is not greater than the set value, determining the tail entity in the triplet as the target entity to be replaced.
In still another aspect, the present application further provides a knowledge graph representation learning device, including:
The vector initial generation unit is used for respectively representing each triplet in the knowledge graph into a vector to obtain a normal triplet vector of each triplet, and the normal triplet vector of the triplet comprises: a first entity vector for each entity in the triplet and a relationship vector for a relationship in the triplet;
A category determining unit, configured to determine, for each triplet, a target entity to be replaced in the triplet and an entity category of the target entity;
The vector generation unit is used for generating a second entity vector for representing the target entity in each triplet by using a generation model in a generation type antagonism network, determining a candidate entity from the knowledge graph according to the entity category of the target entity, and replacing a first entity vector of the target entity in a positive triplet vector of the triplet with the first entity vector of the candidate entity to obtain a negative triplet vector corresponding to the triplet, wherein the similarity of the first entity vector of the candidate entity and the second entity vector of the target entity accords with a set condition;
the first loss determining unit is used for determining a first loss function value by utilizing a first loss function of the generating model according to the negative case triplet vector of each triplet in the knowledge graph;
The second loss determining unit is used for determining a second loss function value according to the entity category of the target entity, the positive case triplet vector and the negative case triplet vector of each triplet in the knowledge graph and utilizing a second loss function of the discrimination model in the generated countermeasure network;
And the learning optimization unit is used for optimizing the normal triplet vector of each triplet, the generation model and the discrimination model in the knowledge graph according to the first loss function value and the second loss function value and in combination with a set training algorithm until the optimization target is reached.
In yet another possible implementation manner, the learning optimization unit is specifically configured to optimize the normal triplet vector, the generating model, and the discriminating model of each triplet in the knowledge graph according to the first loss function value and the second loss function value and in combination with a gradient descent algorithm.
In yet another possible implementation manner, the first loss determining unit is specifically configured to calculate a first loss function value R G by using a first loss function in the generation model as follows, where the first loss function is used to determine a negative case triplet vector (h ', R, t') of each triplet in the knowledge graph:
Wherein S represents a set of positive triplet vectors (h, r, t) of all triples in the knowledge graph, wherein h is a head entity vector in the positive triplet vector, t is a tail entity vector in the positive triplet vector, r represents a relation vector, and negative triplet vectors (h ', r, t') belong to negative triplet vectors generated based on the positive triplet vector in S, wherein h 'is the head entity vector in the negative triplet, and t' is the tail entity vector in the negative triplet vector;
fD(h',r,t')=h'+r-t';
E represents averaging.
In yet another aspect, the present application also provides a computer device, including:
A processor and a memory;
The processor is used for calling and executing the program stored in the memory;
The memory is used for storing the program, and the program is at least used for:
Each triplet in the knowledge graph is respectively expressed as a vector to obtain a positive triplet vector of each triplet, and the positive triplet vector of the triplet comprises: a first entity vector for each entity in the triplet and a relationship vector for a relationship in the triplet;
For each triplet, determining a target entity to be replaced in the triplet and an entity class of the target entity;
Generating a second entity vector for representing the target entity in each triplet by using a generation model in a generation type antagonism network, determining candidate entities from the knowledge graph according to entity categories of the target entity, and replacing a first entity vector of the target entity in positive triplet vectors of the triplet with the first entity vector of the candidate entity to obtain a negative triplet vector corresponding to the triplet, wherein the similarity between the first entity vector of the candidate entity and the second entity vector of the target entity accords with a set condition;
determining a first loss function value by using a first loss function of the generation model according to the negative case triplet vector of each triplet in the knowledge graph;
Determining a second loss function value according to the entity category of the target entity, the positive triplet vector and the negative triplet vector of each triplet in the knowledge graph and by using a second loss function of the discrimination model in the generated countermeasure network;
And optimizing the normal triplet vector of each triplet in the knowledge graph, the generating model and the judging model according to the first loss function value and the second loss function value and by combining a set training algorithm until the optimization target is reached.
In yet another aspect, the present application provides a storage medium having stored therein computer-executable instructions that, when loaded and executed by a processor, implement a knowledge-graph representation learning method as described in any one of the above.
According to the technical scheme, in the process of knowledge graph representation and learning, the negative example is generated by using the generation model of the generation type antagonism network, and the entity type of the target entity to be replaced in the triplet is considered in the process of generating the negative example, so that the candidate entity for replacing the target entity is consistent with the entity type of the target entity, the rationality of the generated negative example is improved, and the accuracy of representing the learned triplet vector is improved. In addition, in the process of knowledge graph representation learning, based on dynamic games between the generation model and the discrimination model in the generation type countermeasure network, the discrimination accuracy of the discrimination model can be improved, so that the vector of the triplet in the knowledge graph can be optimized more reasonably, and the vector representation of the triplet in the knowledge graph can be realized more accurately.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for the description of the embodiments will be briefly described below, and it is apparent that the drawings in the following description are only embodiments of the present application, and other drawings may be obtained according to the provided drawings without inventive effort for a person skilled in the art.
FIG. 1 shows a schematic diagram of a knowledge graph of the present application;
FIG. 2 shows a schematic diagram of a component structure of a computer device to which the solution of the application is applicable;
FIG. 3 is a flow chart of one embodiment of a knowledge graph representation learning method of the present application;
FIG. 4 is a schematic diagram of an implementation architecture of a knowledge graph representation learning method of the present application;
FIG. 5 is a schematic flow chart diagram of another embodiment of a knowledge graph representation learning method of the present application;
fig. 6 is a schematic diagram showing the composition and structure of an embodiment of a knowledge graph representation learning method according to the present application.
Detailed Description
In order to facilitate understanding of the solution of the present application, some concepts related to the present application will be described first:
The knowledge graph is a structured semantic knowledge base, describes concepts and related relations thereof in the physical world in a symbolic form, and basically comprises a triplet of entity-relation-entity; and, entities and their attribute-value pairs. The relationship triplet is used in the knowledge graph to represent the relationship of the entity to the entity, i.e. the triplet may be represented as (head entity, relationship, tail entity).
As shown in fig. 1, a schematic diagram of a knowledge graph is shown.
As can be seen from fig. 1, the birth place of the user 'Zhang San' is "Beijing", and then the relationship between the entity 'Zhang San' and the entity 'Beijing' can be represented by a triplet (Zhang San, birth place, beijing). Representations between other entities are also of the type.
Fig. 1 is an example of a knowledge graph, which can be applied to different fields in practical applications. The entities and relationships involved in the knowledge-graph may also vary in different fields of application. For example, in the field of games, the knowledge graph can describe rich semantic association between entities in the game, so that the knowledge graph can be used as an auxiliary information source of various application scenes of the game, for example, articles, props and the like can be recommended based on the knowledge graph in the game.
The representation learning of the knowledge graph is to obtain the vector representation of the triplet finally by continuously learning the vector representing the entity and the relation in the knowledge graph.
The problem of high calculation complexity caused by large data size of the knowledge graph can be effectively solved through the representation and learning of the knowledge graph.
In the embodiment of the application, the representation learning of the knowledge graph can be applied to computer equipment such as terminals, servers and the like. Fig. 2 is a schematic diagram showing the constitution of a computer apparatus to which the scheme of the present application is applied.
In fig. 2, the computer device 200 may include: a processor 201 and a memory 202.
Of course, the computer device may further include: a communication interface 203, an input unit 204 and a display 205 and a communication bus 206.
The processor 201, the memory 202, the communication interface 203, the input unit 204, the display 205, and the communication bus 206 are all used to perform communication.
In an embodiment of the present application, the processor 201 may be a central processing unit (cpu), a Digital Signal Processor (DSP), an off-the-shelf programmable gate array (FPGA), or other programmable logic device.
The processor may call a program stored in the memory 202, and in particular, the processor may perform operations performed on the computer device side in the embodiments shown in fig. 3 to 5.
The memory 202 is used to store one or more programs, and the programs may include program code that includes computer operation instructions, and in an embodiment of the present application, at least the programs for implementing the following functions are stored in the memory:
Each triplet in the knowledge graph is respectively expressed as a vector to obtain a positive triplet vector of each triplet, and the positive triplet vector of the triplet comprises: a first entity vector for each entity in the triplet and a relationship vector for a relationship in the triplet;
For each triplet, determining a target entity to be replaced in the triplet and an entity class of the target entity;
Generating a second entity vector for representing the target entity in each triplet by using a generation model in a generation type antagonism network, determining candidate entities from the knowledge graph according to entity categories of the target entity, and replacing a first entity vector of the target entity in positive triplet vectors of the triplet with the first entity vector of the candidate entity to obtain a negative triplet vector corresponding to the triplet, wherein the candidate entities are different from the target entity, and the similarity of the first entity vector of the candidate entity and the second entity vector of the target entity accords with a set condition;
determining a first loss function value by using a first loss function of the generation model according to the negative case triplet vector of each triplet in the knowledge graph;
Determining a second loss function value according to the entity category of the target entity, the positive triplet vector and the negative triplet vector of each triplet in the knowledge graph and by using a second loss function of the discrimination model in the generated countermeasure network;
and optimizing the normal triplet vector of each triplet in the knowledge graph, the generating model and the judging model according to the first loss function value and the second loss function value and according to a set training algorithm until the optimization target is reached.
In one possible implementation, the memory 202 may include a stored program area and a stored data area, wherein the stored program area may store an operating system, the above-mentioned programs, and the like; the storage data area may store data, such as vectors, etc., created during use of the computer device.
In addition, the memory 202 may include a high-speed random access memory, a nonvolatile memory, and the like.
The communication interface 203 may be an interface of a communication module, such as an interface of a GSM module.
The present application may also include an input unit 204, which may include a touch sensing unit that senses touch events on a touch display panel, a keyboard, and the like.
The display 205 includes a display panel such as a touch display panel or the like.
Of course, the computer device structure shown in fig. 2 does not limit the computer device in the embodiment of the present application, and the computer device may include more or less components than those shown in fig. 2, or may combine some components in practical applications.
In combination with the above, a knowledge graph representation learning method of the present application is described below.
As shown in fig. 3, which is a schematic flow chart illustrating an embodiment of a knowledge graph representation learning method according to the present application, the method according to the present embodiment may be applied to the aforementioned computer device, and the method may include:
s301, each triplet in the knowledge graph is respectively expressed as a vector, and a normal triplet vector of each triplet is obtained.
Wherein, the triples mentioned in this embodiment refer to triples representing entities and relationships. The triplet may include: head entity, relationship, and tail entity, e.g., three elements are (head entity, relationship, tail entity). There may be multiple triples in the knowledge-graph, which are triples that need to be represented as vectors by representation-learning techniques.
It will be appreciated that the vector representation of the knowledge-graph is a continuous training learning process, and thus, ultimately, an initial vector may be generated for each triplet. For example, a vector representation may be randomly generated by the computer device for each triplet within the knowledge-graph. Wherein the triplet vector of each triplet in this step is the triplet vector that subsequently needs to be optimized, i.e. the vector that eventually needs to represent the triplet. In order to distinguish from the negative instance representing the triplet generated during learning, the triplet vector generated for the triplet is referred to herein as a positive instance triplet vector.
Wherein the positive triplet vector of the triplet includes: the entity vector for each entity in the triplet and the relationship vector for the relationship in the triplet. To facilitate distinction from subsequently generated entity vectors, the entity vector of the entity in the positive example triplet is referred to as a first entity vector.
For example, a positive triplet vector may be expressed as: (h, r, t), wherein h is a vector of head entities, also referred to as head entity vector; t is a vector of tail entities, also called tail entity vector, r is a vector of relations, also called relation vector.
S302, for each triplet, determining a target entity to be replaced in the triplet and an entity class of the target entity.
It can be appreciated that, since the learning process of the representation of the knowledge graph needs to be continuously optimized by using the positive examples and the negative examples of the triples (i.e. the vectors of the triples and the vectors of the constructed false triples), the triples vectors as the negative examples need to be constructed. When the triplet vector of the negative example is constructed, the vector of one entity in the triplet vector corresponding to the triplet needs to be replaced by the vector of other entities in the knowledge graph, and according to the vector, in order to construct the negative example corresponding to the triplet, the entity to be replaced in the triplet needs to be determined.
The entity to be replaced in the triplet may be a head entity or a tail entity in the triplet. For ease of distinction, the entity to be replaced in a triplet is referred to as the target entity in the triplet.
It will be appreciated that determining the target entity to be replaced from the triplet may take the head entity or the tail entity in the triplet as the target entity in advance. Alternatively, to facilitate accuracy in representing learning, one entity in the triplet may be randomly selected as the target entity to be replaced.
In an alternative implementation, a random number may be generated by the computer device for each triplet. If the random number is larger than the set value, determining the head entity in the triplet as a target entity to be replaced; and if the random number is not greater than the set value, determining the tail entity in the triplet as the target entity to be replaced. For example, the set value may be 0.5, if the random number generated by the computer device (the random number may be a number between 0 and 1) is greater than 0.5, the head entity of the triplet is taken as the target entity, otherwise the tail entity of the triplet is taken as the target entity.
The computer equipment randomly generates a random number each time aiming at different triples, and the random numbers generated at different moments are different, so that the entities to be replaced in the different triples are also different.
Wherein the entity class of the target entity is used for characterizing the class of the entity, that is, the attribute characteristics of the entity, for example, the class of the entity can be divided into: name of person, place name, job category, etc. It will be appreciated that the category of the entity facilitates the analysis of the association between entities in the triplet construction process. For example, the place of birth of the user a can be only an entity belonging to the place name, and cannot be an entity of the work category.
It will be appreciated that for a computer device, the processing for each triplet may be processing a triplet vector, and thus determining the target entity to be replaced of a triplet and the class of the target entity herein may also be understood as determining the target entity to which the entity vector to be replaced in the triplet vector of the triplet belongs and the class of the target entity.
S303, generating a second entity vector for representing the target entity in each triplet by using a generation model in a generation type antagonism network, determining a candidate entity from the knowledge graph according to the entity category of the target entity, and replacing the first entity vector of the target entity in the positive triplet vector of the triplet with the first entity vector of the candidate entity to obtain a negative triplet vector corresponding to the triplet.
The generative countermeasure network (GENERATIVE ADVERSARIAL Networks, GAN) is a deep learning model, and is composed of a generative model (commonly known as a generator) and a discriminant model (commonly known as a discriminant). The generative model may be a multi-layer perceptron network or other deep neural network. The discriminant model may also be a model built of a deep neural network.
In the embodiment of the application, the generation model in the countermeasure network is generated to generate the entity vector for representing the entity in the knowledge graph, and the negative case triplet vector is constructed based on the generated entity vector and the triplet vector.
As an alternative, the triplet vector of each triplet in the knowledge graph and the entity class of the target entity to be replaced in each triplet may be input into the generation model of the generated countermeasure network, so that the generation model may finally generate, for each triplet, a negative-example triplet corresponding to the triplet.
For each triplet, the generating model of the generating countermeasure network generates a vector, the vector generates an entity vector for the target entity to be replaced in the triplet, and for convenience of distinguishing, the entity vector of the generating model is called a second entity vector.
As an alternative, the computer device may be set to a vector of m dimensions for each triplet. The M-dimensional vector may be randomly generated by the computer device, where the value of M is less than the set dimension M of the triplet vector of triples in the knowledge-graph, i.e., M < M. In this case, for each triplet, a vector of M dimensions corresponding to the triplet may also be input into the generating model, and correspondingly, the generating model may expand the vector of M dimensions to obtain an expanded vector of M dimensions. Wherein the expanded vector of M dimensions is used to characterize a second entity vector of the target entity to be replaced in the triplet.
For any triplet, after the second entity vector is constructed by the generating model, the candidate entity can be selected by the generating model. Wherein, the similarity between the first entity vector of the candidate entity and the second entity vector corresponding to the triplet meets the set condition. For example, the setting condition may be that the similarity between the first entity vector of the candidate entity and the second entity vector corresponding to the target entity in the triplet is highest. Alternatively, the similarity rank between the first entity vector and the second entity vector of the candidate entity belongs to the top setting bit.
Correspondingly, for each triplet, the generating model can replace the first entity vector of the target entity in the triplet vector of the triplet by the first entity vector of the candidate entity with the similarity with the second entity vector meeting the set condition, and thus, the formed triplet vector is the negative example triplet vector.
It will be appreciated that selecting the candidate entity is in effect selecting the first entity vector of the candidate entity for replacing the first entity vector of the target entity in the triplet, i.e. essentially selecting the first entity vector of the entity in the other triplet vector to replace the entity vector of the target entity in the triplet. On this basis, the candidate entity and the target entity do not belong to the same entity, and the entity which does not belong to the same entity may be: entities or entity names belonging to different triples are different.
As an alternative, for each triplet, the generating model may search, from the triplet vectors of the triples other than the triplet, for a first entity vector that has the highest similarity with the generated second entity vector and corresponds to the candidate entity of the same entity class as the target entity in the triplet. Then, the first entity vector of the target entity in the triplet vector of the triplet is replaced by the first entity vector of the candidate entity.
For example, for a triplet, if the vector of the triplet is expressed as (h, r, t), and assuming that the target entity to be replaced is the head entity, when constructing the negative triplet, the vector h in (h, r, t) needs to be replaced by the first entity vector h' of the candidate entity (here, the first entity vector of the found candidate entity is exemplified by the first entity vector of the head entity in a certain triplet vector). Wherein h ' belongs to other triplet vectors except (h, r, t) in the knowledge graph, h ' represents the same entity category of the candidate entity and the entity represented by h, and simultaneously, h ' is the entity vector with the highest similarity with h in the knowledge graph.
S304, determining a first loss function value by using the first loss function of the generation model according to the negative triplet vector of each triplet in the knowledge graph.
The first loss function is used for evaluating the reality degree of the entity vector generated by the generating model, that is, the first loss function can evaluate the approaching degree of the negative case triplet vector generated by the generating model and the positive case triplet vector in the knowledge graph.
It can be understood that, for any triplet vector in the knowledge graph, the vector of any entity has a specific relationship with the vector of another entity in the triplet vector and the vector of the relationship; meanwhile, for each triplet, since the negative sample triplet vector of the triplet is obtained by replacing the first entity vector of the target entity in the positive sample triplet vector of the triplet with the first entity vector of the candidate entity closest to the second entity vector generated by the generating model, the first loss function may be related to the negative sample triplet vector. That is, the negative case triplet vector constructed by the generative model may analyze the loss value of the generative model.
Wherein the first loss function may be set as desired.
In an alternative implementation, in one implementation, the vector loss function values (which may also be referred to as relationship function values) for each negative triplet vector may be calculated separately, and the first loss function value determined based on the vector loss function values for each negative triplet vector.
Specifically, the first loss function value R G may be calculated using a first loss function as shown in the following equation one:
Wherein S represents a set of normal triplet vectors (h, r, t) of all triples in the knowledge graph, wherein h is a head entity vector in the normal triplet vector, t is a tail entity vector in the normal triplet vector, and r represents a relation vector.
(H ', r, t') represents a negative triplet vector, where h 'is a head entity vector in the negative triplet and t' is a tail entity vector in the negative triplet vector;
(h ', r, t') belongs to a negative example triplet vector generated based on the positive example triplet vector in S. It may be understood that, because some target entities to be replaced in the triples are head entities and some target entities to be replaced in the triples are tail entities, the negative triplet vector for the different triples may be different from the positive triplet vector or may be different from the head entity vector or may be different from the tail entity vector, and for convenience of description, the negative triplet vectors are all denoted as (h ', r, t') in the embodiment of the present application.
F D (h ', r, t') is a h 'to t' relationship function (alternatively referred to as a vector loss function), where the relationship function can be expressed as the following equation two:
f D (h ', r, t')=h '+r-t' (formula two);
In formula one, [ ] + represents a function taking a positive value of [ (f D(h',r,t')]+=max(0,-fD (h ', r, t')) ] that is, -f D (h ', r, t') is greater than 0, then taking the value of-f D (h ', r, t'); otherwise, the value is 0.
E represents averaging, i.e., averaging [ -f D(h',r,t')]+ ] for all negative sample triples.
S305, determining a second loss function value according to the entity category of the target entity, the positive triplet vector and the negative triplet vector of each triplet in the knowledge graph and using the second loss function of the discrimination model in the generated countermeasure network.
In the application, the discrimination model in the generated countermeasure network is used for distinguishing the positive triplet vector corresponding to the triplet and the negative triplet vector generated by the generator according to the entity category of the entity to be replaced in each triplet, and combining the discrimination results. Wherein the discrimination result can determine the accuracy of discrimination of the discrimination model by a second loss function in the discrimination model.
The second loss function in the discrimination model can be set according to the requirement.
As an alternative, the second loss function value L G may be calculated using a second loss function as shown in equation three below:
wherein f D (h, r, t) =h+r-t;
Gamma is a set boundary value, and can be set according to experience or actual needs;
n is the total number of target entities to be replaced in each triplet contained in the knowledge graph, i represents one entity in the knowledge graph, and i is a natural number from 1 to n;
e i denotes the first entity vector of the target entity to be replaced in a triplet. Wherein e i is the head entity vector or the tail entity vector in the normal triplet vector of the triplet;
e j is a first entity vector of an entity in the knowledge graph, which is the same as the entity class of the target entity represented by e i, e j∈N(ei) represents that the entity represented by e j belongs to the entity class of the target entity represented by e i;
W is a trained parameter in the discriminant model.
S306, optimizing the normal triplet vector of each triplet in the knowledge graph, the generating model and the judging model according to the first loss function value and the second loss function value and by combining a set training algorithm until the optimization target is reached.
It can be understood that the goal of generating the model in the generating type countermeasure network is to generate the negative case triplet vector which is the same as the positive case triplet vector as much as possible, so that the discrimination model cannot recognize the negative case triplet vector; the objective of the discriminant model is to distinguish the positive case triplet vector (real triplet vector) from the negative case triplet vector (constructed false triplet vector) as far as possible, so that continuous game between the generation model and the discriminant model can be realized through continuous training and learning, and the balance is finally reached, namely the discriminant model cannot distinguish the positive case triplet vector and the negative case triplet vector. In this case, the generating model can finally generate a relatively real triplet vector, and the accuracy of the discrimination model in discriminating the real triplet vector and the constructed false triplet vector is relatively high, so that the normal triplet vector of the finally obtained triplet can accurately represent the triplet.
The normal triplet vector of each triplet, the internal parameters of the generated model and the discrimination model can be continuously adjusted according to the first loss function value and the second loss function value, and the step S302 is repeated until the optimization target is reached.
Wherein the optimization objective may be to characterize a condition that indicates the end of learning. In practical application, the first loss function value and the second loss function value tend to be stable and serve as optimization targets, namely after a plurality of adjacent optimizations, the change amplitude of the first loss function value and the second loss function value is smaller than a set value.
It will be appreciated that the training algorithm employed in the optimization process may be of many possibilities, and may be specifically selected as desired. Optionally, the application can optimize the normal triplet vector, the generating model and the judging model of each triplet in the knowledge graph by adopting a gradient descent method according to the first loss function value and the second loss function value until reaching the optimization target.
When the optimization target is reached, the normal triplet vector of each triplet in the knowledge graph is the triplet vector representing each learned triplet.
Therefore, in the process of knowledge graph representation and learning, the negative example is generated by using the generation model of the generation type countermeasure network, and in the process of generating the negative example, the entity type of the target entity to be replaced in the triplet is considered, so that the candidate entity for replacing the target entity is consistent with the entity type of the target entity, the rationality of the generated negative example is improved, and the accuracy of representing the learned triplet vector is improved. In addition, in the process of knowledge graph representation learning, based on dynamic games between the generation model and the discrimination model in the generation type countermeasure network, the discrimination accuracy of the discrimination model can be improved, so that the vector of the triplet in the knowledge graph can be optimized more reasonably, and the vector representation of the triplet in the knowledge graph can be realized more accurately.
For ease of understanding the solution of the present application, reference may be made to fig. 4, which shows a schematic diagram of an implementation architecture of the knowledge graph representation learning method of the present application.
As can be seen from fig. 4, after generating an initial vector representation for each triplet to be represented in the knowledge-graph, the triplet vector of each triplet that is initially generated is taken as a triplet vector sample (i.e. the aforementioned normal triplet vector), and the entity class of the entity to be replaced in each triplet is determined separately. The triplet vector samples of each triplet and the corresponding entity class are then input into a generation model in the generated countermeasure network, respectively.
By means of the generation model, a negative-example triplet vector can be constructed for each triplet. Meanwhile, the first loss function value may be calculated according to a first loss function of the generation model.
And the negative case triplet vector of each triplet output by the generating model, the triplet vector sample of each triplet and the entity category corresponding to each triplet are input into the discriminating model in the generating type countermeasure network.
The discrimination model distinguishes the negative sample triplet vector from the true triplet vector and calculates a second loss function value based on the second loss function value.
Therefore, based on the first loss function value and the second loss function value, the triplet vector sample can be continuously adjusted by adopting a gradient descent method (or other training algorithms), and internal parameters of the generation model and the discrimination model are adjusted, and the operations are continuously circulated until the optimization target is reached.
In order to facilitate understanding, a description will be given below of a learning method of knowledge graph representation of the application, taking a process of optimizing representation learning by a gradient descent method as an example, with reference to fig. 4. For example, referring to fig. 5, which shows a schematic flow chart of another embodiment of a knowledge graph representation learning method according to the present application, the method of the present embodiment may include:
s501, each triplet in the knowledge graph is respectively expressed as a vector, and a normal triplet vector of each triplet is obtained.
S502, generating a random number for each triplet, determining a target entity to be replaced from the triplet based on the random number, and determining the entity category of the target entity.
If the random number is larger than the set value, determining the head entity in the triplet as a target entity; if the random number is not greater than the set value, determining the tail entity in the triplet as the target entity.
S503, randomly generating a vector with m dimension for each triplet.
The dimension of the randomly generated vector is M dimension, and the M dimension is smaller than the dimension M of the triplet vector corresponding to the triplet in the knowledge graph.
The randomly generated m-dimensional vector is a random vector generated for the entity vector of the target entity in the triplet.
S504, the entity category, the normal triplet vector and the m-dimension vector of the target entity corresponding to each triplet are input into a generation model of the generation type countermeasure network.
The m-dimension vector corresponding to each triplet in the knowledge graph constitutes the 'noise' z input into the generation model.
S505, for each triplet, respectively expanding the M-dimensional vector corresponding to each triplet into an M-dimensional vector through the generation model, selecting a first entity vector of a candidate entity from other triplet vectors according to the entity type of the target entity in the triplet and the M-dimensional vector, and replacing the first entity vector of the target entity in the positive triplet vector of the triplet with the first entity vector of the candidate entity to obtain a negative triplet vector corresponding to the triplet.
For each triplet, the entity class of the candidate entity is the same as the entity class of the target entity in the triplet, and the similarity between the first entity vector of the candidate entity and the M-dimension vector corresponding to the triplet is the highest (here, a set condition is taken as an example).
As shown in fig. 4, the generative model may ultimately output negative example triplet vectors for each triplet.
S506, determining a first loss function value by using the first loss function of the generation model according to the negative triplet vector of each triplet in the knowledge graph.
For example, the first loss function may be found in equation one above.
S507, inputting the entity category, the positive triplet vector and the negative triplet vector of the target entity corresponding to each triplet in the knowledge graph into a discrimination model of the generated countermeasure network, and determining a second loss function value by using a second loss function set by the discrimination model.
This second loss function can be seen in equation three above.
S508, detecting whether the current optimization objective is reached according to the first loss function value and the second loss function value by combining a gradient descent method, if not, adjusting the normal triplet vector of each triplet in the knowledge graph, the internal parameters of the generated model and the internal parameters of the judging model, and returning to the step S502; if so, determining the normal triplet vector of each triplet in the knowledge graph at the current moment as the triplet vector representing each learned triplet, and ending the learning representing process.
For example, the optimization objective may be to set the number of iterations of the gradient descent, or the first loss function value and the second loss function value are in a steady state.
The application also provides a knowledge graph representation learning device corresponding to the knowledge graph representation learning method.
As shown in fig. 6, a schematic diagram of a knowledge graph representation learning apparatus according to the present application is shown. The apparatus may be applied to the aforementioned computer device. The apparatus may include:
the vector initial generation unit 601 is configured to respectively represent each triplet in the knowledge graph as a vector, and obtain a normal triplet vector of each triplet, where the normal triplet vector of the triplet includes: a first entity vector for each entity in the triplet and a relationship vector for a relationship in the triplet;
a category determining unit 602, configured to determine, for each triplet, a target entity to be replaced in the triplet and an entity category of the target entity;
A vector generating unit 603, configured to generate, for each triplet, a second entity vector for representing the target entity in the triplet by using a generation model in a generation type antagonism network, determine a candidate entity from the knowledge graph according to the entity class of the target entity, and replace a first entity vector of the target entity in a positive-example triplet vector of the triplet with a first entity vector of the candidate entity, so as to obtain a negative-example triplet vector corresponding to the triplet, where similarity between the first entity vector of the candidate entity and the second entity vector of the target entity meets a set condition;
A first loss determining unit 604, configured to determine a first loss function value according to a negative triplet vector of each triplet in the knowledge graph by using a first loss function of the generation model;
A second loss determining unit 605, configured to determine a second loss function value according to the entity class of the target entity, the positive triplet vector and the negative triplet vector of each triplet in the knowledge graph, and using a second loss function of the discrimination model in the generated countermeasure network;
The learning optimization unit 606 is configured to optimize the normal triplet vector, the generating model, and the discriminating model of each triplet in the knowledge graph according to the first loss function value and the second loss function value and in combination with a set training algorithm until an optimization objective is reached.
In one possible implementation manner, the learning optimization unit is specifically configured to optimize the normal triplet vector, the generating model, and the discriminating model of each triplet in the knowledge graph according to the first loss function value and the second loss function value and in combination with a gradient descent algorithm.
In yet another possible implementation manner, the first loss determining unit is specifically configured to calculate a first loss function value R G by using a first loss function in the generation model as follows, where the first loss function is used to determine a negative case triplet vector (h ', R, t') of each triplet in the knowledge graph:
Wherein S represents a set of positive triplet vectors (h, r, t) of all triples in the knowledge graph, wherein h is a head entity vector in the positive triplet vector, t is a tail entity vector in the positive triplet vector, r represents a relation vector, and negative triplet vectors (h ', r, t') belong to negative triplet vectors generated based on the positive triplet vector in S, wherein h 'is the head entity vector in the negative triplet, and t' is the tail entity vector in the negative triplet vector;
fD(h',r,t')=h'+r-t';
E represents averaging.
In yet another possible implementation manner, in an embodiment of the foregoing apparatus, the second loss determining unit is specifically configured to determine the second loss function value L G according to an entity class of the target entity in each triplet in the knowledge-graph, a normal triplet vector (h, r, t) of each triplet, and using the following second loss function in the discrimination model in the generated countermeasure network:
Wherein S represents a set of positive triplet vectors (h, r, t) of all triples in the knowledge graph, wherein h is a head entity vector in the positive triplet vector, t is a tail entity vector in the positive triplet vector, r represents a relation vector, and negative triplet vectors (h ', r, t') belong to negative triplet vectors generated based on the positive triplet vector in S, wherein h 'is the head entity vector in the negative triplet, and t' is the tail entity vector in the negative triplet vector;
fD(h,r,t)=h+r-t;
fD(h',r,t')=h'+r-t';
gamma is a set boundary value;
n is the total number of target entities to be replaced in each triplet contained in the knowledge graph, i represents one entity of the knowledge graph, and i is a natural number from 1 to n;
e i represents a first entity vector of a target entity to be replaced in the triplet, e i is a head entity vector or a tail entity vector in a normal triplet vector of the triplet;
e j is a first entity vector of an entity in the knowledge graph, which is the same as the entity class of the target entity represented by e i, e j∈N(ei) represents that the entity represented by e j belongs to the entity class of the target entity represented by e i;
W is a trained parameter in the discriminant model.
In yet another possible implementation, the triples include a head entity, a tail entity, and a relationship of the head entity to the tail entity;
the category determination unit includes:
a random number generation subunit, configured to generate a random number for each triplet;
a first entity determining subunit, configured to determine, if the random number is greater than a set value, a head entity in the triplet as a target entity to be replaced;
A second entity determining subunit, configured to determine, if the random number is not greater than a set value, a tail entity in the triplet as a target entity to be replaced;
and the category determining subunit is used for determining the entity category of the target entity determined by the first entity determining unit or the second entity determining unit.
In another aspect, the present application further provides a storage medium, where computer executable instructions are stored, where the computer executable instructions implement the knowledge graph representation learning method in any one of the above embodiments when loaded and executed by a processor.
It should be noted that, in the present specification, each embodiment is described in a progressive manner, and each embodiment is mainly described as different from other embodiments, and identical and similar parts between the embodiments are all enough to be referred to each other. For the apparatus class embodiments, the description is relatively simple as it is substantially similar to the method embodiments, and reference is made to the description of the method embodiments for relevant points.
Finally, it is further noted that relational terms such as first and second, and the like are used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Moreover, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises an element.
The previous description of the disclosed embodiments is provided to enable any person skilled in the art to make or use the present invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other embodiments without departing from the spirit or scope of the invention. Thus, the present invention is not intended to be limited to the embodiments shown herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
The foregoing is merely a preferred embodiment of the present invention and it should be noted that modifications and adaptations to those skilled in the art may be made without departing from the principles of the present invention, which are intended to be comprehended within the scope of the present invention.

Claims (6)

1. A knowledge graph representation learning method, characterized by being applied to a game scene, the method comprising:
each triplet in the knowledge graph is respectively expressed as a vector to obtain a positive triplet vector of each triplet, and the positive triplet vector of the triplet comprises: a first entity vector for each entity in the triplet and a relationship vector for a relationship in the triplet; the knowledge graph is used for describing semantic association among entities in the game;
For each triplet, determining a target entity to be replaced in the triplet and an entity class of the target entity; the category of the target entity comprises at least one of a person name, a place name and a work category;
Generating a second entity vector for representing the target entity in each triplet by using a generation model in a generation type antagonism network, determining candidate entities with the same entity category as the target entity from the knowledge graph according to the entity category of the target entity, and replacing a first entity vector of the target entity in a positive triplet vector of the triplet with the first entity vector of the candidate entity to obtain a negative triplet vector corresponding to the triplet, wherein the similarity of the first entity vector of the candidate entity and the second entity vector of the target entity accords with a set condition; the setting conditions are as follows: the similarity between the first entity vector of the candidate entity and the second entity vector of the target entity is highest, or the similarity ranking between the first entity vector of the candidate entity and the second entity vector of the target entity belongs to the forefront setting bit;
determining a first loss function value by using a first loss function of the generation model according to the negative case triplet vector of each triplet in the knowledge graph;
Determining a second loss function value according to the entity category of the target entity, the positive triplet vector and the negative triplet vector of each triplet in the knowledge graph and by using a second loss function of the discrimination model in the generated countermeasure network;
Detecting whether the optimization target is reached currently according to the first loss function value and the second loss function value by combining a gradient descent algorithm, if not, adjusting the normal triplet vector of each triplet in the knowledge graph, the internal parameters of the generated model and the internal parameters of the judging model, and returning to the step of determining the target entity to be replaced in each triplet and the entity category of the target entity; if so, determining the normal triplet vector of each triplet in the knowledge graph at the current moment as the triplet vector representing each learned triplet, and ending the learning representing process; the optimization target is that the iteration times of gradient descent reach the set times, or the first loss function value and the second loss function value are in a stable state;
Wherein determining a first loss function value according to the negative triplet vector of each triplet in the knowledge graph by using the first loss function of the generation model includes: and (3) carrying out negative-example triplet vectors (h ', R and t') of all triples in the knowledge graph, and calculating a first loss function value R G by using the following first loss function in the generation model:
Wherein S represents a set of positive triplet vectors (h, r, t) of all triples in the knowledge graph, wherein h is a head entity vector in the positive triplet vector, t is a tail entity vector in the positive triplet vector, r represents a relation vector, and negative triplet vectors (h ', r, t') belong to negative triplet vectors generated based on the positive triplet vector in S, wherein h 'is the head entity vector in the negative triplet, and t' is the tail entity vector in the negative triplet vector; f D (h ', r, t')=h '+r-t'; e represents averaging;
Wherein determining a second loss function value according to the entity class of the target entity, the positive triplet vector and the negative triplet vector of each triplet in the knowledge graph, and using the generated second loss function of the discrimination model in the countermeasure network includes: determining a second loss function value L G according to the entity class of the target entity in each triplet in the knowledge graph and the positive triplet vector (h, r, t) of each triplet, and by using the following second loss function in the discrimination model in the generated countermeasure network:
Wherein S represents a set of positive triplet vectors (h, r, t) of all triples in the knowledge graph, wherein h is a head entity vector in the positive triplet vector, t is a tail entity vector in the positive triplet vector, r represents a relation vector, and negative triplet vectors (h ', r, t') belong to negative triplet vectors generated based on the positive triplet vector in S, wherein h 'is the head entity vector in the negative triplet, and t' is the tail entity vector in the negative triplet vector; f D(h,r,t)=h+r-t;fD (h ', r, t')=h '+r-t'; gamma is a set boundary value; n is the total number of target entities to be replaced in each triplet contained in the knowledge graph, i represents one entity of the knowledge graph, and i is a natural number from 1 to n; e i represents a first entity vector of a target entity to be replaced in the triplet, e i is a head entity vector or a tail entity vector in a normal triplet vector of the triplet; e j is a first entity vector of an entity in the knowledge graph, which is the same as the entity class of the target entity represented by e i, e j∈N(ei) represents that the entity represented by e j belongs to the entity class of the target entity represented by e i; w is a trained parameter in the discriminant model.
2. The method of claim 1, wherein the triples include a head entity, a tail entity, and a relationship of the head entity to the tail entity;
the determining, for each triplet, a target entity to be replaced in the triplet includes:
Generating a random number for each triplet;
If the random number is larger than the set value, determining the head entity in the triplet as a target entity to be replaced;
and if the random number is not greater than the set value, determining the tail entity in the triplet as the target entity to be replaced.
3. A knowledge-graph representation learning device, characterized by being applied to a game scene, the device comprising:
The vector initial generation unit is used for respectively representing each triplet in the knowledge graph into a vector to obtain a normal triplet vector of each triplet, and the normal triplet vector of the triplet comprises: a first entity vector for each entity in the triplet and a relationship vector for a relationship in the triplet; the knowledge graph is used for describing semantic association among entities in the game;
a category determining unit, configured to determine, for each triplet, a target entity to be replaced in the triplet and an entity category of the target entity; the category of the target entity comprises at least one of a person name, a place name and a work category;
The vector generation unit is used for generating a second entity vector for representing the target entity in each triplet by using a generation model in a generation type antagonism network, determining candidate entities with the same entity category as the target entity from the knowledge graph according to the entity category of the target entity, and replacing a first entity vector of the target entity in a positive triplet vector of the triplet with the first entity vector of the candidate entity to obtain a negative triplet vector corresponding to the triplet, wherein the similarity of the first entity vector of the candidate entity and the second entity vector of the target entity accords with a set condition; the setting conditions are as follows: the similarity between the first entity vector of the candidate entity and the second entity vector of the target entity is highest, or the similarity ranking between the first entity vector of the candidate entity and the second entity vector of the target entity belongs to the forefront setting bit;
the first loss determining unit is used for determining a first loss function value by utilizing a first loss function of the generating model according to the negative case triplet vector of each triplet in the knowledge graph;
The second loss determining unit is used for determining a second loss function value according to the entity category of the target entity, the positive case triplet vector and the negative case triplet vector of each triplet in the knowledge graph and utilizing a second loss function of the discrimination model in the generated countermeasure network;
The learning optimization unit is used for detecting whether the optimization target is reached currently according to the first loss function value and the second loss function value by combining a gradient descent algorithm, if not, adjusting the normal triplet vector of each triplet in the knowledge graph, the internal parameters of the generation model and the internal parameters of the discrimination model, and returning to the step of determining the target entity to be replaced in each triplet and the entity category of the target entity; if so, determining the normal triplet vector of each triplet in the knowledge graph at the current moment as the triplet vector representing each learned triplet, and ending the learning representing process; the optimization target is that the iteration times of gradient descent reach the set times, or the first loss function value and the second loss function value are in a stable state;
wherein the first loss determination unit is specifically configured to: and (3) carrying out negative-example triplet vectors (h ', R and t') of all triples in the knowledge graph, and calculating a first loss function value R G by using the following first loss function in the generation model:
Wherein S represents a set of positive triplet vectors (h, r, t) of all triples in the knowledge graph, wherein h is a head entity vector in the positive triplet vector, t is a tail entity vector in the positive triplet vector, r represents a relation vector, and negative triplet vectors (h ', r, t') belong to negative triplet vectors generated based on the positive triplet vector in S, wherein h 'is the head entity vector in the negative triplet, and t' is the tail entity vector in the negative triplet vector; f D (h ', r, t')=h '+r-t'; e represents averaging;
Wherein the second loss determination unit is specifically configured to: determining a second loss function value L G according to the entity class of the target entity in each triplet in the knowledge graph and the positive triplet vector (h, r, t) of each triplet, and by using the following second loss function in the discrimination model in the generated countermeasure network:
Wherein S represents a set of positive triplet vectors (h, r, t) of all triples in the knowledge graph, wherein h is a head entity vector in the positive triplet vector, t is a tail entity vector in the positive triplet vector, r represents a relation vector, and negative triplet vectors (h ', r, t') belong to negative triplet vectors generated based on the positive triplet vector in S, wherein h 'is the head entity vector in the negative triplet, and t' is the tail entity vector in the negative triplet vector; f D(h,r,t)=h+r-t;fD (h ', r, t')=h '+r-t'; gamma is a set boundary value; n is the total number of target entities to be replaced in each triplet contained in the knowledge graph, i represents one entity of the knowledge graph, and i is a natural number from 1 to n; e i represents a first entity vector of a target entity to be replaced in the triplet, e i is a head entity vector or a tail entity vector in a normal triplet vector of the triplet; e j is a first entity vector of an entity in the knowledge graph, which is the same as the entity class of the target entity represented by e i, e j∈N(ei) represents that the entity represented by e j belongs to the entity class of the target entity represented by e i; w is a trained parameter in the discriminant model.
4. The apparatus of claim 3, wherein the triples include a head entity, a tail entity, and a relationship of the head entity to the tail entity;
the category determination unit includes:
a random number generation subunit, configured to generate a random number for each triplet;
a first entity determining subunit, configured to determine, if the random number is greater than a set value, a head entity in the triplet as a target entity to be replaced;
And the second entity determining subunit is configured to determine the tail entity in the triplet as the target entity to be replaced if the random number is not greater than the set value.
5. A computer device for application in a game scene, the computer device comprising:
A processor and a memory;
The processor is used for calling and executing the program stored in the memory;
The memory is used for storing the program, and the program is at least used for:
each triplet in the knowledge graph is respectively expressed as a vector to obtain a positive triplet vector of each triplet, and the positive triplet vector of the triplet comprises: a first entity vector for each entity in the triplet and a relationship vector for a relationship in the triplet; the knowledge graph is used for describing semantic association among entities in the game;
For each triplet, determining a target entity to be replaced in the triplet and an entity class of the target entity; the category of the target entity comprises at least one of a person name, a place name and a work category;
Generating a second entity vector for representing the target entity in each triplet by using a generation model in a generation type antagonism network, determining candidate entities with the same entity category as the target entity from the knowledge graph according to the entity category of the target entity, and replacing a first entity vector of the target entity in a positive triplet vector of the triplet with the first entity vector of the candidate entity to obtain a negative triplet vector corresponding to the triplet, wherein the similarity of the first entity vector of the candidate entity and the second entity vector of the target entity accords with a set condition; the setting conditions are as follows: the similarity between the first entity vector of the candidate entity and the second entity vector of the target entity is highest, or the similarity ranking between the first entity vector of the candidate entity and the second entity vector of the target entity belongs to the forefront setting bit;
determining a first loss function value by using a first loss function of the generation model according to the negative case triplet vector of each triplet in the knowledge graph;
Determining a second loss function value according to the entity category of the target entity, the positive triplet vector and the negative triplet vector of each triplet in the knowledge graph and by using a second loss function of the discrimination model in the generated countermeasure network;
Detecting whether the optimization target is reached currently according to the first loss function value and the second loss function value by combining a gradient descent algorithm, if not, adjusting the normal triplet vector of each triplet in the knowledge graph, the internal parameters of the generated model and the internal parameters of the judging model, and returning to the step of determining the target entity to be replaced in each triplet and the entity category of the target entity; if so, determining the normal triplet vector of each triplet in the knowledge graph at the current moment as the triplet vector representing each learned triplet, and ending the learning representing process; the optimization target is that the iteration times of gradient descent reach the set times, or the first loss function value and the second loss function value are in a stable state;
Wherein determining a first loss function value according to the negative triplet vector of each triplet in the knowledge graph by using the first loss function of the generation model includes: and (3) carrying out negative-example triplet vectors (h ', R and t') of all triples in the knowledge graph, and calculating a first loss function value R G by using the following first loss function in the generation model:
Wherein S represents a set of positive triplet vectors (h, r, t) of all triples in the knowledge graph, wherein h is a head entity vector in the positive triplet vector, t is a tail entity vector in the positive triplet vector, r represents a relation vector, and negative triplet vectors (h ', r, t') belong to negative triplet vectors generated based on the positive triplet vector in S, wherein h 'is the head entity vector in the negative triplet, and t' is the tail entity vector in the negative triplet vector; f D (h ', r, t')=h '+r-t'; e represents averaging;
wherein determining a second loss function value according to the entity class of the target entity, the positive triplet vector and the negative triplet vector of each triplet in the knowledge graph, and using the generated second loss function of the discrimination model in the countermeasure network includes:
Determining a second loss function value L G according to the entity class of the target entity in each triplet in the knowledge graph and the positive triplet vector (h, r, t) of each triplet, and by using the following second loss function in the discrimination model in the generated countermeasure network:
Wherein S represents a set of positive triplet vectors (h, r, t) of all triples in the knowledge graph, wherein h is a head entity vector in the positive triplet vector, t is a tail entity vector in the positive triplet vector, r represents a relation vector, and negative triplet vectors (h ', r, t') belong to negative triplet vectors generated based on the positive triplet vector in S, wherein h 'is the head entity vector in the negative triplet, and t' is the tail entity vector in the negative triplet vector; f D(h,r,t)=h+r-t;fD (h ', r, t')=h '+r-t'; gamma is a set boundary value; n is the total number of target entities to be replaced in each triplet contained in the knowledge graph, i represents one entity of the knowledge graph, and i is a natural number from 1 to n; e i represents a first entity vector of a target entity to be replaced in the triplet, e i is a head entity vector or a tail entity vector in a normal triplet vector of the triplet; e j is a first entity vector of an entity in the knowledge graph, which is the same as the entity class of the target entity represented by e i, e j∈N(ei) represents that the entity represented by e j belongs to the entity class of the target entity represented by e i; w is a trained parameter in the discriminant model.
6. A storage medium having stored therein computer executable instructions which, when loaded and executed by a processor, implement the knowledge-graph representation learning method of any one of the preceding claims 1 to 2.
CN201910764648.9A 2019-08-19 2019-08-19 Knowledge graph representation learning method, knowledge graph representation learning device, computer equipment and storage medium Active CN110472067B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910764648.9A CN110472067B (en) 2019-08-19 2019-08-19 Knowledge graph representation learning method, knowledge graph representation learning device, computer equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910764648.9A CN110472067B (en) 2019-08-19 2019-08-19 Knowledge graph representation learning method, knowledge graph representation learning device, computer equipment and storage medium

Publications (2)

Publication Number Publication Date
CN110472067A CN110472067A (en) 2019-11-19
CN110472067B true CN110472067B (en) 2024-05-07

Family

ID=68511092

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910764648.9A Active CN110472067B (en) 2019-08-19 2019-08-19 Knowledge graph representation learning method, knowledge graph representation learning device, computer equipment and storage medium

Country Status (1)

Country Link
CN (1) CN110472067B (en)

Families Citing this family (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111275189A (en) * 2020-02-25 2020-06-12 支付宝(杭州)信息技术有限公司 Network representation learning method, system and device
CN111783858B (en) * 2020-06-19 2022-07-15 厦门市美亚柏科信息股份有限公司 Method and device for generating category vector
CN111738000B (en) * 2020-07-22 2020-11-24 腾讯科技(深圳)有限公司 Phrase recommendation method and related device
CN113312854B (en) * 2021-07-19 2021-11-02 成都数之联科技有限公司 Type selection recommendation method and device, electronic equipment and readable storage medium
CN114239834B (en) * 2021-11-17 2022-07-19 中国人民解放军军事科学院国防科技创新研究院 Adversary relationship reasoning method and device based on multi-round confrontation attribute sharing
CN114077681B (en) * 2022-01-19 2022-04-12 腾讯科技(深圳)有限公司 Image data processing method and device, computer equipment and storage medium
CN118036732A (en) * 2024-04-11 2024-05-14 神思电子技术股份有限公司 Social event pattern relation completion method and system based on critical countermeasure learning

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20130204810A1 (en) * 2012-02-08 2013-08-08 Nec Corporation Discriminant model learning device, method and program
CN109376249A (en) * 2018-09-07 2019-02-22 桂林电子科技大学 A kind of knowledge mapping embedding grammar based on adaptive negative sampling
CN109634939A (en) * 2018-12-28 2019-04-16 中国农业银行股份有限公司 A kind of the determination method, apparatus and electronic equipment of missing values

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20130204810A1 (en) * 2012-02-08 2013-08-08 Nec Corporation Discriminant model learning device, method and program
CN109376249A (en) * 2018-09-07 2019-02-22 桂林电子科技大学 A kind of knowledge mapping embedding grammar based on adaptive negative sampling
CN109634939A (en) * 2018-12-28 2019-04-16 中国农业银行股份有限公司 A kind of the determination method, apparatus and electronic equipment of missing values

Also Published As

Publication number Publication date
CN110472067A (en) 2019-11-19

Similar Documents

Publication Publication Date Title
CN110472067B (en) Knowledge graph representation learning method, knowledge graph representation learning device, computer equipment and storage medium
CN111095293B (en) Image aesthetic processing method and electronic equipment
Gazalba et al. Comparative analysis of k-nearest neighbor and modified k-nearest neighbor algorithm for data classification
CN107992887B (en) Classifier generation method, classification device, electronic equipment and storage medium
Cervante et al. Binary particle swarm optimisation for feature selection: A filter based approach
CN109241412B (en) Recommendation method and system based on network representation learning and electronic equipment
CN110298415A (en) A kind of training method of semi-supervised learning, system and computer readable storage medium
JP2021533474A (en) Node classification method, model training method, and its equipment, equipment and computer program
CN108287881A (en) A kind of optimization method found based on random walk relationship
CN108875090B (en) Song recommendation method, device and storage medium
CN105975596A (en) Query expansion method and system of search engine
TWI721374B (en) Recommendation method, device and electronic equipment based on multiple classifiers
KR20190118937A (en) System and method for optimization of hyperparameter
CN113761359B (en) Data packet recommendation method, device, electronic equipment and storage medium
CN108009058A (en) Warping apparatus recognition methods and device and electronic equipment
Fong et al. Gesture recognition from data streams of human motion sensor using accelerated PSO swarm search feature selection algorithm
WO2021253938A1 (en) Neural network training method and apparatus, and video recognition method and apparatus
CN111882048A (en) Neural network structure searching method and related equipment
Nguyen et al. Mutual information estimation for filter based feature selection using particle swarm optimization
CN110942001A (en) Method, device, equipment and storage medium for identifying finger vein data after expansion
KR20230165085A (en) Method and system for quantitatively evaluating alignment between multimodal feature vectors
JP2007018530A (en) Forgetting histogram calculation device, and outlier degree calculation device using same
Bhardwaj et al. User intent classification using memory networks: A comparative analysis for a limited data scenario
WO2020075462A1 (en) Learner estimating device, learner estimation method, risk evaluation device, risk evaluation method, and program
CN111209428A (en) Image retrieval method, device, equipment and computer readable storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant