Knowledge graph representation learning method and device, storage medium and electronic device

By acquiring and training a knowledge graph representation learning model for a set of sample triples, the problem of low knowledge graph representation accuracy is solved and higher vector representation accuracy is achieved.

CN115114406BActive Publication Date: 2025-09-12TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210809749.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-07-11
Publication Date
2025-09-12
Estimated Expiration
2042-07-11

AI Technical Summary

Technical Problem

In the existing technology, the accuracy of knowledge graph representation as vector is low, mainly because the relationship information between triples is ignored.

Method used

By obtaining a set of sample triplets, including positive sample triplets and negative sample triplets, the initial representation learning model is trained until the target loss value meets the preset conditions. The loss value is determined using the first distance of the positive sample triplets and the second distance of the negative sample triplets as well as the predicted similarity and actual similarity to improve the accuracy of the model.

Benefits of technology

The accuracy of knowledge graph representation as vectors is improved, and the accuracy of modeling is improved by combining information at the triple granularity for model training.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115114406B_ABST
    Figure CN115114406B_ABST
Patent Text Reader

Abstract

This application discloses a knowledge graph representation learning method and apparatus, storage medium, and electronic device. The method comprises: obtaining a set of sample triples; and training an initial representation learning model to be trained using the set of sample triples until a target loss value corresponding to the initial representation learning model satisfies a preset loss condition, thereby obtaining a target representation learning model. This application addresses the technical issue of low accuracy in knowledge graph representations as vectors.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computers, and specifically, to a knowledge graph representation learning method and device, storage medium, and electronic device. Background Art

[0002] Knowledge graphs have become a hot topic of research in related technologies. Graphs are typically composed of several key elements, such as entities and their relationships. Graph information, often referred to as knowledge, can be used in many scenarios. For example, in search systems, search queries can be used to retrieve corresponding search answers from the graph. Therefore, for these high-level application scenarios, effectively representing these knowledge structures is crucial.

[0003] Currently, it's common to represent entities and relationships in knowledge graphs as vectors. However, existing technologies typically model entities and relationships themselves, using established models to represent entities and relationships in knowledge graphs as vectors. This approach focuses on modeling at the granularity of entities and relationships, but often overlooks the relationships between triples themselves. This results in low modeling accuracy, and consequently, low accuracy in representing knowledge graphs as vectors.

[0004] To address the above-mentioned problems, no effective solutions have been proposed so far. Summary of the Invention

[0005] The embodiments of the present application provide a knowledge graph representation learning method and device, a storage medium, and an electronic device to at least solve the technical problem of low accuracy in representing knowledge graphs as vectors.

[0006] According to one aspect of an embodiment of the present application, a method for representation learning of a knowledge graph is provided, comprising: obtaining a set of sample triples, wherein the sample triples in the sample triple set include: positive sample triples and negative sample triples, the positive sample triples are triples in the target knowledge graph, the negative sample triples are triples that do not appear in the target knowledge graph, the sample triples include a sample head entity, a sample relationship, and a sample tail entity, and the sample relationship is used to represent the relationship from the sample head entity to the sample tail entity; an initial representation learning model to be trained is trained by using the sample triple set until the initial The target loss value corresponding to the representation learning model satisfies the preset loss condition to obtain the target representation learning model, wherein the target representation learning model is used to encode the head entity, relationship, and tail entity in the triple in the target knowledge graph into a head entity vector, a relationship vector, and a tail entity vector, respectively. The target loss value is a loss value determined based on a first loss value and a second loss value. The first loss value is a loss value determined based on a first distance corresponding to the positive sample triple and a second distance corresponding to the negative sample triple. The second loss value is a loss value determined based on the predicted similarity and actual similarity between the positive sample triplets.

[0007] Optionally, the training of the initial representation learning model to be trained by the sample triple set includes: performing the i-th round of training on the initial representation learning model through the following steps, i is a positive integer greater than or equal to 1, and the initial representation learning model obtained in the 0th round of training is the initial representation learning model to be trained, including: inputting the first positive sample triple, the second positive sample triple, and the first negative sample triple used in the i-th round in the sample triple set into the initial representation learning model obtained in the i-1th round of training, to obtain the first positive sample representation vector set corresponding to the first positive sample triple output in the i-th round of training, the second positive sample representation vector set corresponding to the second positive sample triple, and the first negative sample representation vector set corresponding to the first negative sample triple; determining the predicted similarity between the first positive sample triple and the second positive sample triple based on the first positive sample representation vector set and the second positive sample representation vector set; determining the first positive sample triple based on the first positive sample representation vector set. The first distance corresponding to this triplet, and the second distance corresponding to the first negative sample are determined according to the first negative sample representation vector set; the first loss value obtained by the i-th round of training is determined by the first distance corresponding to the first positive sample triplet and the second distance corresponding to the first negative sample, and the second loss value obtained by the i-th round of training is determined by the predicted similarity between the first positive sample triplet and the second positive sample triplet, and the actual similarity between the first positive sample triplet and the second positive sample triplet; the target loss value obtained by the i-th round of training is obtained by the first loss value obtained by the i-th round of training and the second loss value obtained by the i-th round of training; if the target loss value obtained by the i-th round of training meets the preset loss condition, the training is terminated to obtain the target representation learning model, and if the target loss value obtained by the i-th round of training does not meet the preset loss condition, the model parameters of the initial representation learning model obtained by the i-1-th round of training are adjusted.

[0008] Optionally, determining the predicted similarity between the first positive sample triplet and the second positive sample triplet based on the first positive sample representation vector set and the second positive sample representation vector set includes: determining the first characterization vector of the first positive sample triplet through the first positive sample representation vector set, and determining the second characterization vector of the second positive sample triplet through the second positive sample representation vector set; and determining the predicted similarity between the first positive sample triplet and the second positive sample triplet based on the first characterization vector and the second characterization vector.

[0009] Optionally, determining the first characterization vector of the first positive sample triplet by the first positive sample representation vector set includes: determining the average of the first positive sample header vector, the first positive sample relationship vector, and the first positive sample tail vector in the first positive sample representation vector set as the first characterization vector of the first positive sample triplet, wherein the first positive sample header vector is a vector corresponding to the first positive sample header entity in the first positive sample triplet, the first positive sample relationship vector is a vector corresponding to the first positive sample relationship in the first positive sample triplet, and the first positive sample tail vector is a vector corresponding to the first positive sample tail entity in the first positive sample triplet. vector; determining the second characterization vector of the second positive sample triplet by the second positive sample representation vector set, including: determining the average of the second positive sample header vector, the second positive sample relationship vector, and the second positive sample tail vector in the second positive sample representation vector set as the second characterization vector of the second positive sample triplet, wherein the second positive sample header vector is the vector corresponding to the second positive sample header entity in the second positive sample triplet, the second positive sample relationship vector is the vector corresponding to the second positive sample relationship in the second positive sample triplet, and the second positive sample tail vector is the vector corresponding to the second positive sample tail entity in the second positive sample triplet.

[0010] Optionally, determining the predicted similarity between the first positive sample triplet and the second positive sample triplet based on the first characterization vector and the second characterization vector includes: determining the value of the cosine function of the first characterization vector and the second characterization vector as the predicted similarity between the first positive sample triplet and the second positive sample triplet.

[0011] Optionally, the method further includes: determining the actual similarity between the first positive sample triple and the second positive sample triple based on a link relationship between the first positive sample triple and the second positive sample triple in the target knowledge graph.

[0012] Optionally, determining the actual similarity between the first positive sample triplet and the second positive sample triplet based on the link relationship between the first positive sample triplet and the second positive sample triplet in the target knowledge graph includes: obtaining the total number of first link edges of the first positive sample triplet, the total number of second link edges of the second positive sample triplet, and the total number of third link edges between the first positive sample triplet and the second positive sample triplet; determining the sum of the first total number of link edges and the second total number of link edges as the total number of link edges; and determining the ratio of the third total number of link edges to the total number of link edges as the actual similarity between the first positive sample triplet and the second positive sample triplet.

[0013] Optionally, obtaining the first total number of link edges of the first positive sample triplet includes: obtaining the first number of link edges of the first positive sample head entity of the first positive sample triplet in the target knowledge graph, and the second number of link edges of the first positive sample tail entity in the target knowledge graph; determining the sum of the first number and the second number as the first total number of link edges; obtaining the second total number of link edges of the second positive sample triplet includes: obtaining the third number of link edges of the second positive sample head entity of the second positive sample triplet in the target knowledge graph, and the fourth number of link edges of the second positive sample tail entity in the target knowledge graph; determining the sum of the third number and the fourth number as the second total number of link edges; wherein, the relationship between the sample head entity and the sample tail entity is linked by the link edge in the target knowledge graph.

[0014] Optionally, obtaining the total number of the third link edges between the first positive sample triple and the second positive sample triple includes: in the case where there is a common entity between the first positive sample triple and the second positive sample triple, obtaining the fifth number of link edges contributed by the common entity to the first positive sample triple and the second positive sample triple in the target knowledge graph, and the sixth number of link edges directly linked in the target knowledge graph between entities other than the common entity in the first positive sample triple and the second positive sample triple; determining the sum of the fifth number and the sixth number as the total number of the third link edges; or, in the case where there is no common entity between the first positive sample triple and the second positive sample triple, determining the number of link edges directly linked between entities in the first positive sample triple and entities in the second positive sample triple in the target knowledge graph as the total number of the third link edges.

[0015] Optionally, determining the first distance corresponding to the first positive sample triplet based on the first positive sample representation vector set includes: vector addition of the first positive sample header vector and the first positive sample relationship vector in the first positive sample representation vector set to obtain the first conversion vector of the first positive sample triplet; determining the distance between the first conversion vector and the first positive sample tail vector in the first positive sample representation vector set as the first distance; determining the second distance corresponding to the first negative sample based on the first negative sample representation vector set includes: vector addition of the first negative sample header vector and the first negative sample relationship vector in the first negative sample representation vector set to obtain the second conversion vector of the first negative sample triplet; and determining the distance between the second conversion vector and the first negative sample tail vector in the first negative sample representation vector set as the second distance.

[0016] Optionally, after obtaining the target representation learning model, the method further includes: obtaining a target query statement and determining a query vector used to characterize the target query statement; searching for a candidate node matching the target query statement or the query vector in the target knowledge graph; when the candidate node is found, determining a set of candidate triples associated with the candidate node in the target knowledge graph, wherein each candidate triple in the candidate triple set includes the entity represented by the candidate node; obtaining a set of candidate representation vectors corresponding to the candidate triple set, wherein each group of candidate representation vectors in the candidate representation vector set includes a head entity vector, a relationship vector, and a tail entity vector obtained by respectively encoding the head entity, relationship, and tail entity in each candidate triple in the candidate triple set through the target representation learning model; searching for a target triple in the candidate triple set according to the query vector, wherein a group of candidate representation vectors corresponding to the target triple matches the query vector; generating a target query result matching the target query statement according to the target triple, and outputting the target query result.

[0017] According to another aspect of the embodiment of the present application, a representation learning device for a knowledge graph is also provided, including: an acquisition module for acquiring a set of sample triples, wherein the sample triples in the sample triple set include: positive sample triples and negative sample triples, the positive sample triples are triples in the target knowledge graph, the negative sample triples are triples that do not appear in the target knowledge graph, the sample triples include a sample head entity, a sample relationship, and a sample tail entity, and the sample relationship is used to represent the relationship from the sample head entity to the sample tail entity; a training module for training an initial representation learning model to be trained using the sample triple set. Practice until the target loss value corresponding to the initial representation learning model meets the preset loss condition to obtain a target representation learning model, wherein the target representation learning model is used to encode the head entity, relationship, and tail entity in the triples in the target knowledge graph into head entity vectors, relationship vectors, and tail entity vectors, respectively, and the target loss value is a loss value determined according to a first loss value and a second loss value, the first loss value is a loss value determined according to a first distance corresponding to the positive sample triple and a second distance corresponding to the negative sample triple, and the second loss value is a loss value determined according to the predicted similarity and actual similarity between the positive sample triplets.

[0018] According to another aspect of the embodiments of the present application, a computer-readable storage medium is also provided, in which a computer program is stored, wherein the computer program is configured to execute the above-mentioned knowledge graph representation learning method at runtime.

[0019] According to another aspect of the embodiments of the present application, a computer program product or computer program is provided, the computer program product or computer program including computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the above-described knowledge graph representation learning method.

[0020] According to another aspect of the embodiments of the present application, an electronic device is also provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor is configured to execute the above-mentioned knowledge graph representation learning method through the computer program.

[0021] In an embodiment of the present application, a method of modeling using positive sample triplets and negative sample triplets in a knowledge graph is adopted, and the model is trained by combining triple granularity. When training the model, two loss values ​​are applied, one of which is the loss value determined by the first distance corresponding to the positive sample triple and the second distance corresponding to the negative sample triple, and the other is the loss value determined based on the predicted similarity and actual similarity between the positive sample triplets. Because the information of triple granularity is combined in the process of model training, the purpose of improving the accuracy of modeling is achieved, thereby achieving the technical effect of improving the accuracy of the knowledge graph represented as a vector, and thus solving the technical problem of low accuracy of the knowledge graph represented as a vector. BRIEF DESCRIPTION OF THE DRAWINGS

[0022] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:

[0023] Figure 1 This is a schematic diagram of an application environment of an optional knowledge graph representation learning method according to an embodiment of the present application;

[0024] Figure 2 This is a flowchart of an optional knowledge graph representation learning method according to an embodiment of the present application;

[0025] Figure 3 is a schematic diagram of an optional target knowledge graph according to an embodiment of the present application;

[0026] Figure 4 is an optional vector relationship diagram according to an embodiment of the present application;

[0027] Figure 5 is an optional link edge schematic diagram according to an embodiment of the present application;

[0028] Figure 6 is another optional link edge schematic diagram according to an embodiment of the present application;

[0029] Figure 7 is another optional link edge schematic diagram according to an embodiment of the present application;

[0030] Figure 8 is another optional link edge schematic diagram according to an embodiment of the present application;

[0031] Figure 9 is another optional link edge schematic diagram according to an embodiment of the present application;

[0032] Figure 10 is an optional flow chart for calculating a target loss value according to an embodiment of the present application;

[0033] Figure 11 This is a schematic structural diagram of an optional knowledge graph representation learning device according to an embodiment of the present application;

[0034] Figure 12 This is a schematic diagram of the structure of an optional knowledge graph representation learning product according to an embodiment of the present application;

[0035] Figure 13 It is a schematic structural diagram of an optional electronic device according to an embodiment of the present application. DETAILED DESCRIPTION

[0036] In order to enable those skilled in the art to better understand the present invention, the following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments in the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts should fall within the scope of protection of this application.

[0037] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequential order. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in a sequence other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0038] According to one aspect of the embodiment of the present application, a method for learning a representation of a knowledge graph is provided. Optionally, in this embodiment, the method for learning a representation of a knowledge graph can be applied to Figure 1 In the hardware environment composed of the server 101 and the terminal device 103 shown in FIG. Figure 1 As shown, the server 101 is connected to the terminal 103 via a network and can be used to provide services for the terminal device or the application installed on the terminal device. The application can be a video application, an instant messaging application, a browser application, a game application, etc. A database 105 can be set on the server or independently of the server to provide data storage services for the server 101, for example, a knowledge graph storage server. The above-mentioned network can include but is not limited to: a wired network, a wireless network, wherein the wired network includes: a local area network, a metropolitan area network and a wide area network, and the wireless network includes: Bluetooth, WIFI and other networks that realize wireless communication. The terminal device 103 can be a terminal configured with an application, and can include but is not limited to at least one of the following: a mobile phone (such as an Android phone, an iOS phone, etc.), a laptop computer, a tablet computer, a PDA, a MID (Mobile Internet Device), a PAD, a desktop computer, a smart TV and other computer devices. The above-mentioned server can be a single server, or a server cluster consisting of multiple servers, or a cloud server.

[0039] Combine Figure 1 As shown, the above-mentioned knowledge graph representation learning method can be implemented on the server 101 through the following steps:

[0040] S1, obtain the sample triple set;

[0041] S2, training the initial representation learning model to be trained using the sample triple set until the target loss value corresponding to the initial representation learning model meets a preset loss condition, thereby obtaining a target representation learning model.

[0042] Optionally, in this embodiment, the above-mentioned knowledge graph representation learning method can also be implemented through terminal involvement, for example, Figure 1 It is implemented in the terminal device 103 shown; or it is implemented by the user terminal and the server together.

[0043] The above is only an example and is not specifically limited in this embodiment.

[0044] Alternatively, as an optional implementation, Figure 2 As shown in Figure 2, the representation learning method of the above knowledge graph includes:

[0045] Step S202: Obtain a set of sample triples, wherein the sample triples in the set of sample triples include: positive sample triples and negative sample triples, the positive sample triples are triples in the target knowledge graph, the negative sample triples are triples that do not appear in the target knowledge graph, and the sample triples include a sample head entity, a sample relationship, and a sample tail entity, wherein the sample relationship is used to represent the relationship between the sample head entity and the sample tail entity;

[0046] Step S204: The initial representation learning model to be trained is trained using the sample triple set until the target loss value corresponding to the initial representation learning model meets the preset loss condition, thereby obtaining a target representation learning model, wherein the target representation learning model is used to encode the head entity, relationship, and tail entity in the triple in the target knowledge graph into a head entity vector, a relationship vector, and a tail entity vector, respectively. The target loss value is a loss value determined based on a first loss value and a second loss value. The first loss value is a loss value determined based on a first distance corresponding to the positive sample triple and a second distance corresponding to the negative sample triple. The second loss value is a loss value determined based on the predicted similarity and the actual similarity between the positive sample triplets.

[0047] As an optional implementation, a triple can be represented by (head entity, relationship, tail entity), for example, triple1 = (e1_h, r1, e1_t), triple2 = (e2_h, r2, e2_t), triple3 = (e3_h, r3, e3_t), where e1_h, e2_h, e3_h are used to represent the head entities in triples triple1, triple2 and triple3, r1, r2, r3 are used to represent the relationships in triple1, triple2 and triple3, and e1_t, e2_t, e3_t are used to represent the tail entities in triple1, triple2 and triple3.

[0048] like Figure 3 In the target knowledge graph shown, entities include: entities: A, B, C, D, E, F; relationships: friends, appearances, couples, photos, posters. Figure 3 As an example of the target knowledge graph shown in the figure, (A, starred in, C) and (B, starred in, C) are Figure 3 For the triples in the target knowledge graph shown, assuming that the triple (A, starred, C) is represented by triple1, then triple1 = (A, starred, C), and the triple (B, starred, C) is represented by triple2, triple2 = (B, starred, C).

[0049] by Figure 3 Take the target knowledge graph shown as an example to model the training sample. Figure 3 The entities in the target knowledge graph shown in are sample entities, and the relationships between entities are sample relationships. Taking triple1 = (A, starred, C) as an example, A is the sample head entity, starred is the sample relationship, and C is the sample tail entity.

[0050] Since triple1 and triple2 are Figure 3 As shown in the target knowledge graph, triple1 and triple2 are positive sample triplets. Assuming triple3 is a negative sample triple, a negative sample triple can be constructed by randomly replacing the head entity and / or tail entity in the positive sample triple. For example, the sample head entity A in triple1=(A, starred in, C) is replaced by D in the target knowledge graph, and then the negative sample triple triple triple3=(D, starred in, C) is constructed, or, the sample tail entity C in triple1=(A, starred in, C) is replaced by B, and then the negative sample triple triple triple3=(A, starred in, B) is constructed, or, the sample head entity A in triple1=(A, starred in, C) is replaced by D in the target knowledge graph, and the sample tail entity C is replaced by B, and then the negative sample triple triple triple3=(D, starred in, B) is constructed.

[0051] In the above embodiment, Figure 3 The positive sample triples in the target knowledge graph shown, and the negative sample triples constructed based on the positive sample triples are used as triplets in the sample triple set. Modeling is performed using the positive sample triples and negative sample triples in the sample triple set. Specifically, the above-mentioned initial representation learning model is an initial model. The initial representation learning model is trained using the positive sample triples and negative sample triples in the sample triple set until the target loss value meets the preset loss condition. The training is terminated to obtain the target representation learning model, and the modeling is completed. The trained target representation learning model can be used to encode the head entity, relationship, and tail entity in the triples in the target knowledge graph into a head entity vector, a relationship vector, and a tail entity vector, respectively.

[0052] As an optional implementation, due to:

[0053] Head entity + relationship = tail entity formula 1

[0054] Assuming that the semantic vector of the head entity is V_entity1, the semantic vector of the relation is V_relation, and the semantic vector of the tail entity is V_entity2, the more the semantic vectors in the triples obtained through representation learning satisfy the following formula, the higher the accuracy of the established model in representing the triples:

[0055] V_entity1+V_relation=V_entity2 Formula 2

[0056] like Figure 4 The figure shows the semantic vector relationship diagram of the triples corresponding to Formula 2. Modeling can be done based on Formula 2. For triples with established relationships, the smaller the loss of Formula 2, the higher the accuracy of the model's representation learning of the triples.

[0057] Optionally, the training of the initial representation learning model to be trained by the sample triple set includes: performing the i-th round of training on the initial representation learning model through the following steps, i is a positive integer greater than or equal to 1, and the initial representation learning model obtained in the 0th round of training is the initial representation learning model to be trained, including: inputting the first positive sample triple, the second positive sample triple, and the first negative sample triple used in the i-th round in the sample triple set into the initial representation learning model obtained in the i-1th round of training, to obtain the first positive sample representation vector set corresponding to the first positive sample triple output in the i-th round of training, the second positive sample representation vector set corresponding to the second positive sample triple, and the first negative sample representation vector set corresponding to the first negative sample triple; determining the predicted similarity between the first positive sample triple and the second positive sample triple based on the first positive sample representation vector set and the second positive sample representation vector set; determining the first positive sample triple based on the first positive sample representation vector set. The first distance corresponding to this triplet, and the second distance corresponding to the first negative sample are determined according to the first negative sample representation vector set; the first loss value obtained by the i-th round of training is determined by the first distance corresponding to the first positive sample triplet and the second distance corresponding to the first negative sample, and the second loss value obtained by the i-th round of training is determined by the predicted similarity between the first positive sample triplet and the second positive sample triplet, and the actual similarity between the first positive sample triplet and the second positive sample triplet; the target loss value obtained by the i-th round of training is obtained by the first loss value obtained by the i-th round of training and the second loss value obtained by the i-th round of training; if the target loss value obtained by the i-th round of training meets the preset loss condition, the training is terminated to obtain the target representation learning model, and if the target loss value obtained by the i-th round of training does not meet the preset loss condition, the model parameters of the initial representation learning model obtained by the i-1-th round of training are adjusted.

[0058] As an optional embodiment, the model is trained multiple times until the target loss value corresponding to the model satisfies the above-mentioned preset convergence condition, and training is terminated. The above-mentioned i-th training can be any training session among the multiple training sessions. During each training session, the input of the model includes positive sample triplets and negative sample triplets. The number of positive sample triplets inputted during each training session is at least two, and the number of negative sample triplets is at least one.

[0059] In the following example, the positive sample triples used in the i-th training are the first positive sample triplet triple1 and the second positive sample triplet triple2, and the negative sample triplet is the first negative sample triplet triple3. The input of the initial representation learning model obtained in the i-1th round of training is:

[0060] The first positive sample triplet triple1 = (e1_h, r1, e1_t), the second positive sample triplet triple2 = (e2_h, r2, e2_t), and the first negative sample triplet triple3 = (e3_h, r3, e3_t).

[0061] The initial representation learning model obtained from the i-1th round of training encodes the sample entities and relationship entities in the input triple1, triple2, and triple3 to obtain the corresponding encoding vectors. The encoding method for the sample entities and sample relationships in triple1, triple2, and triple3 is:

[0062] V_e-text=word2vec(e_name)

[0063] Word2vec can be used to encode the text information of sample entities and sample relationships to obtain the corresponding initialization encoding vector V_e-text.

[0064] For triple1=(e1_h, r1, e1_t), e1_h, r1, and e1_t are encoded as follows to obtain the corresponding encoding vectors:

[0065] V_e1_h=word2vec(e1_h)

[0066] V_e1_t=word2vec(e1_t)

[0067] V_r1_r=word2vec(r1)

[0068] Through the above formula, the first positive sample representation vector set of the first positive sample triple triple1 is obtained: V_e1_h, V_e1_t and V_r1_r.

[0069] Similarly, for triple2=(e2_h, r2, e2_t), e2_h, r2, and e2_t are encoded as follows to obtain the corresponding encoding vectors:

[0070] V_e2_h=word2vec(e2_h)

[0071] V_e2_t=word2vec(e2_t)

[0072] V_r2_r=word2vec(r2)

[0073] Through the above formula, the second positive sample representation vector set of the second positive sample triple triple2 is obtained: V_e2_h, V_e2_t and V_r2_r.

[0074] For triple3=(e3_h, r3, e2_t), e3_h, r3, and e3_t are encoded as follows to obtain the corresponding encoding vectors:

[0075] V_e3_h=word2vec(e3_h)

[0076] V_e3_t=word2vec(e3_t)

[0077] V_r3_r=word2vec(r3)

[0078] Through the above formula, the first negative sample representation vector set of the first negative sample triple triple3 is obtained: V_e3_h, V_e3_t and V_r3_r.

[0079] As an optional implementation, word2vec is used to initialize the entity relationship vector in this application, and it can also be obtained based on other methods.

[0080] Optionally, determining the predicted similarity between the first positive sample triplet and the second positive sample triplet based on the first positive sample representation vector set and the second positive sample representation vector set includes: determining the first characterization vector of the first positive sample triplet through the first positive sample representation vector set, and determining the second characterization vector of the second positive sample triplet through the second positive sample representation vector set; and determining the predicted similarity between the first positive sample triplet and the second positive sample triplet based on the first characterization vector and the second characterization vector.

[0081] As an optional implementation, the first characterization vector is the overall expression of the first positive sample triple, the second characterization vector is the overall expression of the second positive sample triple, and the fun function is the characterization function of the triple as a whole.

[0082] Optionally, determining the first characterization vector of the first positive sample triplet by the first positive sample representation vector set includes: determining the average of the first positive sample header vector, the first positive sample relationship vector, and the first positive sample tail vector in the first positive sample representation vector set as the first characterization vector of the first positive sample triplet, wherein the first positive sample header vector is a vector corresponding to the first positive sample header entity in the first positive sample triplet, the first positive sample relationship vector is a vector corresponding to the first positive sample relationship in the first positive sample triplet, and the first positive sample tail vector is a vector corresponding to the first positive sample tail entity in the first positive sample triplet. vector; determining the second characterization vector of the second positive sample triplet by the second positive sample representation vector set, including: determining the average of the second positive sample header vector, the second positive sample relationship vector, and the second positive sample tail vector in the second positive sample representation vector set as the second characterization vector of the second positive sample triplet, wherein the second positive sample header vector is the vector corresponding to the second positive sample header entity in the second positive sample triplet, the second positive sample relationship vector is the vector corresponding to the second positive sample relationship in the second positive sample triplet, and the second positive sample tail vector is the vector corresponding to the second positive sample tail entity in the second positive sample triplet.

[0083] As an optional implementation, the fun function can be implemented based on avgpooling, that is, the sum and average of the head and tail entities and the relationship vectors between entities are used to represent the overall expression of the triple.

[0084] For the first positive sample triple triple1:

[0085] fun(triple1)=avgpooing(V_e1_h,V_r1_r,V_e1_t)

[0086] That is, the first representation vector of the first positive sample triple is obtained by adding the average of V_e1_h, V_e1_t, and V_r1_r in the first positive sample representation vector set. The value of fun(triple1) is the average of V_e1_h, V_e1_t, and V_r1_r. Similarly, the value of fun(triple2) is the average of V_e2_h, V_e2_t, and V_r2_r.

[0087] Optionally, determining the predicted similarity between the first positive sample triplet and the second positive sample triplet based on the first characterization vector and the second characterization vector includes: determining the value of the cosine function of the first characterization vector and the second characterization vector as the predicted similarity between the first positive sample triplet and the second positive sample triplet.

[0088] As an optional implementation, the first representation vector of the first positive sample triple is fun(triple1), and the second representation vector of the second representation vector of the second positive sample triple is fun(triple2). The predicted similarity sim(triple1,triple2) between the first positive sample triple and the second positive sample triple is obtained by the following formula:

[0089] sim(triple1,triple2)=cosine(fun(triple1),fun(triple2))

[0090] Wherein, cosine is the cosine function, and the value of the cosine function of the first characterization vector fun(triple1) and the second characterization vector fun(triple2) is the predicted similarity sim(triple1,triple2) between the first positive sample triple and the second positive sample triple.

[0091] Optionally, the method further includes: determining the actual similarity between the first positive sample triple and the second positive sample triple based on a link relationship between the first positive sample triple and the second positive sample triple in the target knowledge graph.

[0092] As an optional implementation, Figure 3 Taking the target knowledge graph shown as an example, the actual similarity Sim_score can be determined between the first positive sample triple triple1 and the second positive sample triple triple2 according to the link relationship between the entities in the target knowledge graph.

[0093] Optionally, determining the actual similarity between the first positive sample triple and the second positive sample triple according to the link relationship between the first positive sample triple and the second positive sample triple in the target knowledge graph includes: obtaining the total number of first link edges of the first positive sample triple, the total number of second link edges of the second positive sample triple, and the total number of third link edges between the first positive sample triple and the second positive sample triple;

[0094] Specifically, obtaining the total number of first link edges of the first positive sample triples includes: obtaining the total number of first link edges of the first positive sample triples, including: obtaining the first number of link edges of the first positive sample head entity of the first positive sample triples in the target knowledge graph, and the second number of link edges of the first positive sample tail entity in the target knowledge graph; determining the sum of the first number and the second number as the total number of the first link edges; obtaining the total number of second link edges of the second positive sample triples, including: obtaining the third number of link edges of the second positive sample head entity of the second positive sample triples in the target knowledge graph, and the fourth number of link edges of the second positive sample tail entity in the target knowledge graph; determining the sum of the third number and the fourth number as the total number of the second link edges; wherein, the relationship between the sample head entity and the sample tail entity in the target knowledge graph is linked by the link edge.

[0095] As an optional implementation, Figure 3 Taking the target knowledge graph shown as an example, the first positive sample triplet triple1 = (A, starred in, C), and the second positive sample triplet triple2 = (B, starred in, C).

[0096] Combine Figure 3 In the target knowledge graph shown in the figure, the edge used to represent the relationship between entities is called a link edge. For example, the link edge between entities B and C in the figure is used to indicate that the relationship between entities B and C is B appears in C.

[0097] The total number of linked edges, count(triple*), is the number of all linked edges involved by the head and tail entities of the triple. The total number of first linked edges of the first positive triple is count(triple1), which is the number of all linked edges involved by the first positive head entity and the first positive tail entity in the first positive triple. The total number of second linked edges of the second positive triple is count(triple2), which is the number of all linked edges involved by the second positive head entity and the second positive tail entity in the second positive triple.

[0098] For the first positive sample header entity A, the number of link edges involved is 5. All the link edges connected to A in the target knowledge graph include: the link edge from A to C, the link edge from A to D, the link edge from D to A, the link edge from A to B, and the link edge from B to A, such as Figure 5 There are 5 link edges shown. Then the first quantity is count(head_entity=A)=5.

[0099] Similarly, for the first positive sample tail entity C, all the links connected to C in the target knowledge graph include: the link from A to C, the link from B to C, and the link from C to F. Then the second number is count(tail_entity=C)=3. Figure 6 The 3 link edges shown.

[0100] The total number of first link edges Count(triple1)=count(head_entity=A)+count(tail_entity=C)=5+3=8.

[0101] For the second positive sample head entity B, all the links connected to B in the target knowledge graph include: links from A pointing to B, links from A to B, links from B to C, and links from B to E. Then the third number is count(head_entity=B)=4. Figure 7 The 4 link edges shown.

[0102] Similarly, for the second positive sample tail entity C, the number of all link edges involved is 3, including: the link edge from A to C, the link edge from B to C, and the link edge from C to F. The fourth quantity is count(tail_entity=C)=3.

[0103] The total number of second link edges Count(triple1)=count(head_entity=B)+count(tail_entity=C)=4+3=7.

[0104] Specifically, the total number of the third link edges between the first positive sample triple and the second positive sample triple is obtained, including: in the case where there is a common entity between the first positive sample triple and the second positive sample triple, obtaining the fifth number of link edges contributed by the common entity to the first positive sample triple and the second positive sample triple in the target knowledge graph, and the sixth number of link edges directly linked between entities other than the common entity in the first positive sample triple and the second positive sample triple in the target knowledge graph; determining the sum of the fifth number and the sixth number as the total number of the third link edges; or, in the case where there is no common entity between the first positive sample triple and the second positive sample triple, determining the number of link edges directly linked between entities in the first positive sample triple and entities in the second positive sample triple in the target knowledge graph as the total number of the third link edges.

[0105] As an optional implementation, Figure 3In the target knowledge graph shown in FIG, the first positive sample triple triple1 = (A, starring, C), the second positive sample triple triple2 = (B, starring, C) as an example, entity C is a common entity of triple1 and triple2, such as Figure 8 As shown in , the link edge contributed by entity C to the first positive sample triple triple1 is the link edge between C and A, that is, the number of link edges contributed by entity C to the first positive sample triple triple1 is 1, and the link edge contributed by entity C to the second positive sample triple triple2 is the link edge between C and B, that is, the number of link edges contributed by entity C to the second positive sample triple triple2 is 1. Therefore, the fifth number of link edges contributed by the common entity C to the first positive sample triple triple1 and the second positive sample triple triple2 in the target knowledge graph is 2.

[0106] The entity other than the common entity C in the first positive sample triplet triple1 is A, and the entity other than the common entity C in the second positive sample triplet triple2 is B, such as Figure 8 The directly connected edges between B and C are: the edge from A to B and the edge from B to C, so the sixth number is 2. The total number of third link edges count(triple1,triple2)=2+2=4.

[0107] As an optional implementation, Figure 3 In the target knowledge graph shown, take the first positive sample triple (A, couple, D) and the second positive sample triple (B, starred, C) as examples. There is no common entity between (A, couple, D) and (B, starred, C). Figure 9 As shown in (A, couple, D) and (B, starring, C), the link edges directly linking entity A and entity B include: the link edge pointing from A to B, and the link edge pointing from B to A. In this case, the number of link edges directly linking the entities in the first positive sample triplet and the entities in the second positive sample triplet in the target knowledge graph is 2, that is, the total number of third link edges is 2.

[0108] Optionally, the sum of the first total number of linked edges and the second total number of linked edges is determined as the total number of linked edges; and the ratio of the third total number of linked edges to the total number of linked edges is determined as the actual similarity between the first positive sample triplet and the second positive sample triplet.

[0109] As an optional implementation, Figure 3 In the target knowledge graph shown, the first positive sample triple triple1 = (A, starred, C) and the second positive sample triple triple2 = (B, starred, C) are taken as examples:

[0110] Through the above embodiment, the total number of first link edges is Count(triple1) = count(head_entity = A) + count(tail_entity = C) = 5 + 3 = 8. The total number of second link edges is Count(triple1) = count(head_entity = B) + count(tail_entity = C) = 4 + 3 = 7. The total number of link edges is count(triple1) + count(triple2) = 15, and the total number of third link edges is count(triple1, triple2) = 2 + 2 = 4.

[0111] Then the actual similarity between the first positive sample triple and the second positive sample triple is: Sim_score = count(triple1,triple2) / (count(triple1)+count(triple2)) = 4 / 15

[0112] Optionally, determining the first distance corresponding to the first positive sample triplet based on the first positive sample representation vector set includes: vector addition of the first positive sample header vector and the first positive sample relationship vector in the first positive sample representation vector set to obtain the first conversion vector of the first positive sample triplet; determining the distance between the first conversion vector and the first positive sample tail vector in the first positive sample representation vector set as the first distance; determining the second distance corresponding to the first negative sample based on the first negative sample representation vector set includes: vector addition of the first negative sample header vector and the first negative sample relationship vector in the first negative sample representation vector set to obtain the second conversion vector of the first negative sample triplet; and determining the distance between the second conversion vector and the first negative sample tail vector in the first negative sample representation vector set as the second distance.

[0113] As an optional implementation, take the first positive sample representation vector set of the first positive sample triplet triple1: V_e1_h, V_e1_t and V_r1_r, and the first negative sample representation vector set of the first negative sample triplet triple3: V_e3_h, V_e3_t and V_r3_r as an example, where,

[0114] The first conversion vector of the first positive sample triple is: V_e1_h+V_r1_r, and the first distance is D(V_e1_h+V_r1_r, V_e1_t).

[0115] The second conversion vector of the first negative sample triplet is: V_e2_h+V_r2_r, and the second distance is D(V_e3_h+V_r3_r, V_e3_t).

[0116] The first loss value is calculated using the following loss function:

[0117]

[0118] Where S is the set of positive triples, S' is the set of negative triples, and negative triples in the set of negative triples are constructed by replacing the head or tail entity in the positive triples. In the formula, ei_h is the head entity in the positive triple, ei_r is the relation in the positive triple, and ei_t is the tail entity in the positive triple. ej_h is the head entity in the negative triple, ej_r is the relation in the negative triple, and ej_t is the tail entity in the negative triple.

[0119] δ is a constant greater than 0 and can be set according to actual conditions. D() is a distance function. Here, the vector Euclidean distance function is used to measure whether a triple is established or not. Note that the greater the distance, the smaller the possibility that the triple is positive. Therefore, the loss function hopes that the distance of the positive sample triple tends to be smaller than that of the negative sample by δ.

[0120] For the above first distance D(V_e1_h+V_r1_r, V_e1_t) and the second distance D(V_e3_h+V_r3_r, V_e3_t), the first loss value can be calculated by the above loss function:

[0121] Loss_trans=δ+D(V_e1_h+V_r1_r,V_e1_t)-D(V_e3_h+V_r3_r,V_e3_t)

[0122] In addition to the above loss function, this application proposes a relationship function for constructing tuples. Here, regression characterization is performed based on similarity, and the loss function is completed based on MSE, as follows:

[0123]

[0124] Among them, sim(triple1, triple2) is the predicted similarity, sim_score is the actual similarity, S is the set of positive sample triplets, and the actual similarity Sim_score between the first positive sample triplet triple1 and the second positive sample triplet triple12 in the above embodiment, as well as the predicted similarity sim(triple1, triple2) are applied to the above loss function to obtain a second loss value.

[0125] The final function's Loss function is a weighted sum of the above two parts:

[0126] Loss=lambda1*Loss_trans+lambda2*Loss_sim

[0127] Lambda1 and lambda2 are pre-set hyperparameters that can be set according to actual conditions. The weighted sum of the first loss value and the second loss value is the target loss value.

[0128] As an optional implementation, Figure 10 It is a flowchart for calculating the loss during the training process, which includes a first loss value and a second loss value. The first loss value is a loss value obtained based on the first distance corresponding to the input first positive sample triplet triple1 and the second distance corresponding to the first negative sample triplet triple13. The second loss value is a loss value obtained based on the predicted similarity and actual similarity between the first positive sample triplet triple1 and the second positive sample triplet triple2.

[0129] Optionally, after obtaining the target representation learning model, the method further includes: obtaining a target query statement and determining a query vector used to characterize the target query statement; searching for a candidate node matching the target query statement in the target knowledge graph; when the candidate node is found, determining a set of candidate triples associated with the candidate node in the target knowledge graph, wherein each candidate triple in the candidate triple set includes the entity represented by the candidate node; obtaining a set of candidate representation vectors corresponding to the candidate triple set, wherein each group of candidate representation vectors in the candidate representation vector set includes a head entity vector, a relationship vector, and a tail entity vector obtained by respectively encoding the head entity, relationship, and tail entity in each candidate triple in the candidate triple set through the target representation learning model; searching for a target triple in the candidate triple set according to the query vector, wherein a group of candidate representation vectors corresponding to the target triple matches the query vector; generating a target query result matching the target query statement according to the target triple, and outputting the target query result.

[0130] As an optional implementation, after obtaining the trained target representation learning model, the entities and relationships in the target knowledge graph can be represented by vectors.

[0131] The following is an example to illustrate Figure 3Taking the target knowledge graph shown as an example, assuming that the target query statement is query=C's leading actor, the target query statement query="C's leading actor" can be vectorized using the above-trained target representation learning model or other methods in the prior art to obtain the query vector of the target query statement.

[0132] You can search for candidate nodes related to "C's starring actor" in the target knowledge graph. For example, if A, B, and F in the target knowledge graph are directly linked to C, then the candidate nodes are A, B, and F.

[0133] In the target knowledge graph, it can be determined that the triplets related to the candidate nodes A, B, and F include: (B, starred, C), (A, starred, C), and (C, poster, F). The candidate triplet set includes (B, starred, C), (A, starred, C), and (C, poster, F).

[0134] The trained target representation learning model can be used to represent the head entity, relationship, and tail entity in (B, starred, C), (A, starred, C), and (C, poster, F) as vectors. The query vector of the target query statement can be used to find the matching target triple in the vector representations corresponding to (B, starred, C), (A, starred, C), and (C, poster, F). Specifically, the distance between the vectors can be used. The closer the distance, the more similar the vectors are. The distance between the vectors can be used to determine that (B, starred, C) and (A, starred, C) are the triples that best match the target query statement, and the target query results can be obtained as B and A. In this way, answer = [B, A] can be pulled out from the target knowledge graph.

[0135] As an optional implementation, the present application is based on a tuple-granular graph entity relationship vector representation learning method, so that the graph knowledge learning model can not only effectively characterize the entity relationship information within the triple, but also characterize the information between triples.

[0136] It is understandable that in the specific implementation of this application, related data such as user information is involved. When the above embodiments of this application are applied to specific products or technologies, user permission or consent is required, and the collection, use and processing of relevant data must comply with relevant laws, regulations and standards of relevant countries and regions.

[0137] It should be noted that for the aforementioned method embodiments, for the sake of simplicity, they are all expressed as a series of action combinations, but those skilled in the art should be aware that this application is not limited by the order of the actions described, because according to this application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by this application.

[0138] According to another aspect of the embodiment of the present application, a knowledge graph representation learning device for implementing the above-mentioned knowledge graph representation learning method is also provided. Figure 11 As shown, the device includes: an acquisition module 1102, which is used to acquire a sample triple set, wherein the sample triples in the sample triple set include: positive sample triples and negative sample triples, the positive sample triples are triples in the target knowledge graph, the negative sample triples are triples that do not appear in the target knowledge graph, the sample triples include a sample head entity, a sample relationship, and a sample tail entity, and the sample relationship is used to represent the relationship between the sample head entity and the sample tail entity; a training module 1104, which is used to train the initial representation learning model to be trained by using the sample triple set until the initial representation learning model is trained. The target loss value corresponding to the representation learning model satisfies the preset loss condition to obtain the target representation learning model, wherein the target representation learning model is used to encode the head entity, relationship, and tail entity in the triples in the target knowledge graph into head entity vectors, relationship vectors, and tail entity vectors, respectively. The target loss value is a loss value determined based on a first loss value and a second loss value. The first loss value is a loss value determined based on a first distance corresponding to the positive sample triple and a second distance corresponding to the negative sample triple. The second loss value is a loss value determined based on the predicted similarity and actual similarity between the positive sample triplets.

[0139] Optionally, the above-mentioned device is also used to perform the i-th round of training on the initial representation learning model through the following steps, where i is a positive integer greater than or equal to 1, and the initial representation learning model obtained in the 0th round of training is the initial representation learning model to be trained, including: inputting the first positive sample triplet, the second positive sample triplet, and the first negative sample triplet used in the i-th round in the sample triplet set into the initial representation learning model obtained in the i-1th round of training, to obtain the first positive sample representation vector set corresponding to the first positive sample triplet output in the i-th round of training, the second positive sample representation vector set corresponding to the second positive sample triplet, and the first negative sample representation vector set corresponding to the first negative sample triplet; determining the predicted similarity between the first positive sample triplet and the second positive sample triplet based on the first positive sample representation vector set and the second positive sample representation vector set; determining the first distance corresponding to the first positive sample triplet based on the first positive sample representation vector set. , and according to the first negative sample representation vector set, determine the second distance corresponding to the first negative sample; determine the first loss value obtained in the i-th round of training through the first distance corresponding to the first positive sample triplet and the second distance corresponding to the first negative sample, and determine the second loss value obtained in the i-th round of training through the predicted similarity between the first positive sample triplet and the second positive sample triplet and the actual similarity between the first positive sample triplet and the second positive sample triplet; obtain the target loss value obtained in the i-th round of training through the first loss value obtained in the i-th round of training and the second loss value obtained in the i-th round of training; if the target loss value obtained in the i-th round of training meets the preset loss condition, end the training to obtain the target representation learning model; if the target loss value obtained in the i-th round of training does not meet the preset loss condition, adjust the model parameters of the initial representation learning model obtained in the i-1-th round of training.

[0140] Optionally, the above-mentioned device is also used to determine the first representation vector of the first positive sample triplet through the first positive sample representation vector set, and determine the second representation vector of the second positive sample triplet through the second positive sample representation vector set; and determine the predicted similarity between the first positive sample triplet and the second positive sample triplet based on the first representation vector and the second representation vector.

[0141] Optionally, the above-mentioned device is also used to determine the average value of the first positive sample header vector, the first positive sample relationship vector, and the first positive sample tail vector in the first positive sample representation vector set as the first representation vector of the first positive sample triplet, wherein the first positive sample header vector is the vector corresponding to the first positive sample header entity in the first positive sample triplet, the first positive sample relationship vector is the vector corresponding to the first positive sample relationship in the first positive sample triplet, and the first positive sample tail vector is the vector corresponding to the first positive sample tail entity in the first positive sample triplet; determining the second representation vector of the second positive sample triplet through the second positive sample representation vector set includes: determining the average value of the second positive sample header vector, the second positive sample relationship vector, and the second positive sample tail vector in the second positive sample representation vector set as the second representation vector of the second positive sample triplet, wherein the second positive sample header vector is the vector corresponding to the second positive sample header entity in the second positive sample triplet, the second positive sample relationship vector is the vector corresponding to the second positive sample relationship in the second positive sample triplet, and the second positive sample tail vector is the vector corresponding to the second positive sample tail entity in the second positive sample triplet.

[0142] Optionally, the apparatus is further configured to determine a value of a cosine function of the first characterization vector and the second characterization vector as a predicted similarity between the first positive sample triplet and the second positive sample triplet.

[0143] Optionally, the above-mentioned device is also used to determine the actual similarity between the first positive sample triple and the second positive sample triple based on the link relationship between the first positive sample triple and the second positive sample triple in the target knowledge graph.

[0144] Optionally, the above-mentioned device is also used to obtain the total number of first link edges of the first positive sample triplet, the total number of second link edges of the second positive sample triplet, and the total number of third link edges between the first positive sample triplet and the second positive sample triplet; determine the sum of the first total number of link edges and the second total number of link edges as the total number of link edges; and determine the ratio of the third total number of link edges to the total number of link edges as the actual similarity between the first positive sample triplet and the second positive sample triplet.

[0145] Optionally, the above-mentioned device is also used to obtain the first number of link edges of the first positive sample head entity of the first positive sample triple in the target knowledge graph, and the second number of link edges of the first positive sample tail entity in the target knowledge graph; determine the sum of the first number and the second number as the total number of the first link edges; obtain the second total number of link edges of the second positive sample triple, including: obtaining the third number of link edges of the second positive sample head entity of the second positive sample triple in the target knowledge graph, and the fourth number of link edges of the second positive sample tail entity in the target knowledge graph; determine the sum of the third number and the fourth number as the total number of the second link edges; wherein, the relationship between the sample head entity and the sample tail entity in the target knowledge graph is linked by the link edge.

[0146] Optionally, the above-mentioned device is also used to obtain the fifth number of link edges contributed by the common entity to the first positive sample triple and the second positive sample triple in the target knowledge graph, and the sixth number of link edges directly linked in the target knowledge graph between entities other than the common entity in the first positive sample triple and the second positive sample triple; determine the sum of the fifth number and the sixth number as the third total number of link edges; or, in the case that the first positive sample triple and the second positive sample triple do not have the common entity, determine the number of link edges directly linked between entities in the first positive sample triple and entities in the second positive sample triple in the target knowledge graph as the third total number of link edges.

[0147] Optionally, the above-mentioned device is also used to perform vector addition on the first positive sample header vector and the first positive sample relationship vector in the first positive sample representation vector set to obtain the first transformation vector of the first positive sample triplet; determine the distance between the first transformation vector and the first positive sample tail vector in the first positive sample representation vector set as the first distance; determine the second distance corresponding to the first negative sample based on the first negative sample representation vector set, including: performing vector addition on the first negative sample header vector and the first negative sample relationship vector in the first negative sample representation vector set to obtain the second transformation vector of the first negative sample triplet; and determine the distance between the second transformation vector and the first negative sample tail vector in the first negative sample representation vector set as the second distance.

[0148] Optionally, the above-mentioned device is also used to obtain a target query statement after obtaining the target representation learning model, and determine a query vector used to represent the target query statement; search for a candidate node that matches the target query statement or the query vector in the target knowledge graph; when the candidate node is found, determine a set of candidate triples associated with the candidate node in the target knowledge graph, wherein each candidate triple in the candidate triple set includes the entity represented by the candidate node; obtain a set of candidate representation vectors corresponding to the candidate triple set, wherein each group of candidate representation vectors in the candidate representation vector set includes a head entity vector, a relationship vector, and a tail entity vector obtained by encoding the head entity, the relationship, and the tail entity in each candidate triple in the candidate triple set through the target representation learning model; according to the query vector, search for a target triple in the candidate triple set, wherein a group of candidate representation vectors corresponding to the target triple matches the query vector; according to the target triple, generate a target query result that matches the target query statement, and output the target query result.

[0149] According to one aspect of the present application, a computer program product is provided, comprising a computer program / instructions containing program code for executing the method illustrated in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network via the communication portion 1209 and / or installed from a removable medium 1211. When the computer program is executed by the central processing unit 1201, the various functions provided in the embodiments of the present application are performed.

[0150] The serial numbers of the above embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.

[0151] Figure 12 The block diagram schematically shows a computer system structure of an electronic device used to implement an embodiment of the present application.

[0152] It should be noted that Figure 12 The computer system 1200 of the electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.

[0153] like Figure 12As shown, the computer system 1200 includes a central processing unit (CPU) 1201, which can perform various appropriate actions and processes according to the program stored in the read-only memory (ROM) 1202 or the program loaded from the storage part 1208 into the random access memory (RAM) 1203. Various programs and data required for system operation are also stored in the random access memory 1203. The CPU 1201, the read-only memory 1202, and the random access memory 1203 are connected to each other via a bus 1204. An input / output interface 1205 (i.e., an I / O interface) is also connected to the bus 1204.

[0154] The following components are connected to the input / output interface 1205: an input section 1206 including a keyboard, a mouse, and the like; an output section 1207 including devices such as a cathode ray tube (CRT), a liquid crystal display (LCD), and a speaker; a storage section 1208 including a hard disk; and a communication section 1209 including a network interface card such as a local area network card or a modem. The communication section 1209 performs communication processing via a network such as the Internet. A drive 1210 is also connected to the input / output interface 1205 as needed. Removable media 1211, such as a magnetic disk, an optical disk, a magneto-optical disk, or a semiconductor memory, is installed in the drive 1210 as needed, so that computer programs read therefrom can be installed into the storage section 1208 as needed.

[0155] In particular, according to an embodiment of the present application, the processes described in the various method flow charts can be implemented as computer software programs. For example, an embodiment of the present application includes a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for executing the methods shown in the flow charts. In such an embodiment, the computer program can be downloaded and installed from a network via the communication section 1209 and / or installed from a removable medium 1211. When the computer program is executed by the central processing unit 1201, the various functions defined in the system of the present application are performed.

[0156] According to another aspect of the embodiment of the present application, an electronic device for implementing the above-mentioned knowledge graph representation learning method is also provided. The electronic device can be Figure 1 The terminal device or server shown in FIG. This embodiment is described by taking the electronic device as a terminal device as an example. Figure 13As shown, the electronic device includes a memory 1302 and a processor 1304. The memory 1302 stores a computer program, and the processor 1304 is configured to execute the steps in any of the above method embodiments through the computer program.

[0157] Optionally, in this embodiment, the electronic device may be located in at least one network device among a plurality of network devices of a computer network.

[0158] Optionally, in this embodiment, the processor may be configured to execute the following steps through a computer program:

[0159] S1, obtaining a set of sample triples, wherein the sample triples in the set of sample triples include: positive sample triples and negative sample triples, the positive sample triples are triples in the target knowledge graph, the negative sample triples are triples that do not appear in the target knowledge graph, the sample triples include a sample head entity, a sample relationship, and a sample tail entity, and the sample relationship is used to represent the relationship between the sample head entity and the sample tail entity;

[0160] S2. The initial representation learning model to be trained is trained by using the set of sample triples until the target loss value corresponding to the initial representation learning model meets the preset loss condition, thereby obtaining a target representation learning model, wherein the target representation learning model is used to encode the head entity, relationship, and tail entity in the triples in the target knowledge graph into a head entity vector, a relationship vector, and a tail entity vector, respectively. The target loss value is a loss value determined based on a first loss value and a second loss value. The first loss value is a loss value determined based on a first distance corresponding to the positive sample triple and a second distance corresponding to the negative sample triple. The second loss value is a loss value determined based on the predicted similarity and the actual similarity between the positive sample triplets.

[0161] Alternatively, those skilled in the art will appreciate that Figure 13 The structure shown is for illustration only, and the electronic device may also be a smart phone (such as an Android phone, an iOS phone, etc.), a tablet computer, a PDA, a mobile Internet device (MID), a PAD, or other terminal devices. Figure 13 It does not limit the structure of the electronic device. For example, the electronic device may also include Figure 13 More or fewer components (such as network interfaces, etc.) as shown in, or with Figure 13 Different configurations shown.

[0162] Among them, the memory 1302 can be used to store software programs and modules, such as the program instructions / modules corresponding to the knowledge graph representation learning method and device in the embodiment of the present application. The processor 1304 executes various functional applications and data processing by running the software programs and modules stored in the memory 1302, that is, realizing the above-mentioned knowledge graph representation learning method. The memory 1302 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 1302 may further include a memory remotely located relative to the processor 1304, and these remote memories may be connected to the terminal via a network. Examples of the above-mentioned networks include but are not limited to the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof. Among them, the memory 1302 can be used for information such as the target knowledge graph, but is not limited to it. As an example, Figure 13 As shown, the memory 1302 may include, but is not limited to, the acquisition module 1102 and the training module 1104 in the knowledge graph representation learning device. In addition, it may also include, but is not limited to, other module units in the knowledge graph representation learning device, which will not be repeated in this example.

[0163] Optionally, the transmission device 1306 is configured to receive or send data via a network. Specific examples of the network may include a wired network and a wireless network. In one embodiment, the transmission device 1306 includes a network interface controller (NIC), which can be connected to other network devices and a router via a network cable to communicate with the Internet or a local area network. In one embodiment, the transmission device 1306 is a radio frequency (RF) module, which is configured to communicate with the Internet wirelessly.

[0164] In addition, the above-mentioned electronic device also includes: a display 1308 for displaying the above-mentioned target knowledge graph; and a connection bus 1310 for connecting the various module components in the above-mentioned electronic device.

[0165] In other embodiments, the terminal device or server may be a node in a distributed system, wherein the distributed system may be a blockchain system, and the blockchain system may be a distributed system formed by connecting multiple nodes through network communication. The nodes may form a peer-to-peer (P2P) network, and any computing device, such as a server, terminal, or other electronic device, may become a node in the blockchain system by joining the peer-to-peer network.

[0166] According to one aspect of the present application, a computer-readable storage medium is provided, and a processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes the knowledge graph representation learning method provided in the above-mentioned various optional implementations.

[0167] Optionally, in this embodiment, the computer-readable storage medium may be configured to store a computer program for performing the following steps:

[0168] S1, obtaining a set of sample triples, wherein the sample triples in the set of sample triples include: positive sample triples and negative sample triples, the positive sample triples are triples in the target knowledge graph, the negative sample triples are triples that do not appear in the target knowledge graph, the sample triples include a sample head entity, a sample relationship, and a sample tail entity, and the sample relationship is used to represent the relationship between the sample head entity and the sample tail entity;

[0169] S2. The initial representation learning model to be trained is trained by using the set of sample triples until the target loss value corresponding to the initial representation learning model meets the preset loss condition, thereby obtaining a target representation learning model, wherein the target representation learning model is used to encode the head entity, relationship, and tail entity in the triples in the target knowledge graph into a head entity vector, a relationship vector, and a tail entity vector, respectively. The target loss value is a loss value determined based on a first loss value and a second loss value. The first loss value is a loss value determined based on a first distance corresponding to the positive sample triple and a second distance corresponding to the negative sample triple. The second loss value is a loss value determined based on the predicted similarity and the actual similarity between the positive sample triplets.

[0170] Optionally, in this embodiment, a person of ordinary skill in the art may understand that all or part of the steps in the various methods of the above embodiments may be completed by instructing the hardware related to the terminal device through a program, and the program may be stored in a computer-readable storage medium, which may include: a flash drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.

[0171] The serial numbers of the above embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.

[0172] If the integrated units in the above embodiments are implemented in the form of software functional units and sold or used as independent products, they can be stored in the above-mentioned computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for enabling one or more computer devices (which can be personal computers, servers, or network devices, etc.) to execute all or part of the steps of the methods described in each embodiment of the present application.

[0173] In the above embodiments of the present application, the description of each embodiment has its own focus. For parts that are not described in detail in a certain embodiment, please refer to the relevant description of other embodiments.

[0174] In the several embodiments provided in this application, it should be understood that the disclosed client can be implemented in other ways. Among them, the device embodiments described above are merely illustrative. For example, the division of the units is merely a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, and can be electrical or other forms.

[0175] The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected to achieve the purpose of this embodiment according to actual needs.

[0176] In addition, the functional units in the various embodiments of the present application may be integrated into a single processing unit, or each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or software functional units.

[0177] The above is only a preferred embodiment of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.

Claims

1. A knowledge graph representation learning method, characterized in that: include: Obtain a set of sample triples, wherein the sample triples in the set of sample triples include: positive sample triples and negative sample triples, the positive sample triples are triples in the target knowledge graph, the negative sample triples are triples that do not appear in the target knowledge graph, the sample triples include a sample head entity, a sample relationship, and a sample tail entity, the sample relationship is used to represent the relationship between the sample head entity and the sample tail entity, the entities include people and events, and the relationships include person relationships and event relationships related to the people; Training the initial representation learning model to be trained using the set of sample triples until a target loss value corresponding to the initial representation learning model satisfies a preset loss condition, thereby obtaining a target representation learning model, wherein the target loss value is a loss value determined based on a first loss value and a second loss value, the first loss value being a loss value determined based on a first distance corresponding to the positive sample triples and a second distance corresponding to the negative sample triples, and the second loss value being a loss value determined based on a predicted similarity and an actual similarity between the positive sample triplets; Determine the query vector used to represent the target query statement, and use the target representation learning model to encode the head entity, relationship, and tail entity in the triple in the target knowledge graph into a head entity vector, a relationship vector, and a tail entity vector, respectively. Determine the target triple that matches the target query statement through the distance between the vectors to obtain the target query result.

2. The method according to claim 1, characterized in that The training of the initial representation learning model to be trained by using the sample triple set includes: The initial representation learning model is trained for the i-th round by the following steps, where i is a positive integer greater than or equal to 1, and the initial representation learning model obtained in the 0th round of training is the initial representation learning model to be trained, including: Inputting the first positive sample triplet, the second positive sample triplet, and the first negative sample triplet used in the i-th round of training in the sample triplet set into the initial representation learning model obtained in the i-1th round of training, obtaining a first positive sample representation vector set corresponding to the first positive sample triplet output in the i-th round of training, a second positive sample representation vector set corresponding to the second positive sample triplet, and a first negative sample representation vector set corresponding to the first negative sample triplet; Determining a predicted similarity between the first positive sample triplet and the second positive sample triplet based on the first positive sample representation vector set and the second positive sample representation vector set; Determining the first distance corresponding to the first positive sample triplet based on the first positive sample representation vector set, and determining the second distance corresponding to the first negative sample based on the first negative sample representation vector set; Determine a first loss value obtained in the i-th round of training by using the first distance corresponding to the first positive sample triplet and the second distance corresponding to the first negative sample; and determine a second loss value obtained in the i-th round of training by using the predicted similarity between the first positive sample triplet and the second positive sample triplet and the actual similarity between the first positive sample triplet and the second positive sample triplet; Obtaining a target loss value obtained in the i-th round of training by combining the first loss value obtained in the i-th round of training and the second loss value obtained in the i-th round of training; When the target loss value obtained in the i-th round of training meets the preset loss condition, the training is terminated to obtain the target representation learning model. When the target loss value obtained in the i-th round of training does not meet the preset loss condition, the model parameters of the initial representation learning model obtained in the i-1-th round of training are adjusted.

3. The method according to claim 2, characterized in that The determining, based on the first positive sample representation vector set and the second positive sample representation vector set, a predicted similarity between the first positive sample triplet and the second positive sample triplet, includes: Determine a first representation vector of the first positive sample triplet by using the first positive sample representation vector set, and determine a second representation vector of the second positive sample triplet by using the second positive sample representation vector set; Determine a predicted similarity between the first positive sample triplet and the second positive sample triplet according to the first characterization vector and the second characterization vector.

4. The method according to claim 3, characterized in that The determining the first representation vector of the first positive sample triplet by using the first positive sample representation vector set includes: determining the average of the first positive sample header vector, the first positive sample relationship vector, and the first positive sample tail vector in the first positive sample representation vector set as the first representation vector of the first positive sample triplet, wherein the first positive sample header vector is a vector corresponding to the first positive sample header entity in the first positive sample triplet, the first positive sample relationship vector is a vector corresponding to the first positive sample relationship in the first positive sample triplet, and the first positive sample tail vector is a vector corresponding to the first positive sample tail entity in the first positive sample triplet; Determining the second characterization vector of the second positive sample triplet through the second positive sample representation vector set, including: determining the average of the second positive sample header vector, the second positive sample relationship vector, and the second positive sample tail vector in the second positive sample representation vector set as the second characterization vector of the second positive sample triplet, wherein the second positive sample header vector is a vector corresponding to the second positive sample header entity in the second positive sample triplet, the second positive sample relationship vector is a vector corresponding to the second positive sample relationship in the second positive sample triplet, and the second positive sample tail vector is a vector corresponding to the second positive sample tail entity in the second positive sample triplet.

5. The method according to claim 3, characterized in that The determining, according to the first characterization vector and the second characterization vector, the predicted similarity between the first positive sample triplet and the second positive sample triplet includes: The value of the cosine function of the first characterization vector and the second characterization vector is determined as the predicted similarity between the first positive sample triplet and the second positive sample triplet.

6. The method according to claim 2, characterized in that The method further comprises: The actual similarity between the first positive sample triple and the second positive sample triple is determined according to the link relationship between the first positive sample triple and the second positive sample triple in the target knowledge graph.

7. The method according to claim 6, characterized in that The determining the actual similarity between the first positive sample triple and the second positive sample triple according to the link relationship between the first positive sample triple and the second positive sample triple in the target knowledge graph includes: Obtaining the total number of first link edges of the first positive sample triples, the total number of second link edges of the second positive sample triples, and the total number of third link edges between the first positive sample triples and the second positive sample triples; Determine the sum of the total number of the first link edges and the total number of the second link edges as the total number of link edges; The ratio of the third total number of link edges to the total number of link edges is determined as the actual similarity between the first positive sample triplet and the second positive sample triplet.

8. The method according to claim 7, characterized in that Obtaining the total number of first link edges of the first positive sample triple, including: obtaining a first number of link edges of the first positive sample head entity of the first positive sample triple in the target knowledge graph, and a second number of link edges of the first positive sample tail entity in the target knowledge graph; determining the sum of the first number and the second number as the total number of the first link edges; Obtaining the total number of second link edges of the second positive sample triplet, including: obtaining a third number of link edges of the second positive sample head entity of the second positive sample triplet in the target knowledge graph, and a fourth number of link edges of the second positive sample tail entity in the target knowledge graph; determining the sum of the third number and the fourth number as the total number of the second link edges; Among them, the relationship between the sample head entity and the sample tail entity is linked by the link edge in the target knowledge graph.

9. The method according to claim 7, characterized in that Obtaining the total number of third link edges between the first positive sample triplet and the second positive sample triplet includes: In the case where there is a common entity between the first positive sample triple and the second positive sample triple, obtain the fifth number of link edges contributed by the common entity to the first positive sample triple and the second positive sample triple in the target knowledge graph, and the sixth number of link edges directly linked between entities other than the common entity in the first positive sample triple and the second positive sample triple in the target knowledge graph; determine the sum of the fifth number and the sixth number as the third total number of link edges; or, In the case that there is no common entity between the first positive sample triple and the second positive sample triple, the number of link edges directly linking the entity in the first positive sample triple and the entity in the second positive sample triple in the target knowledge graph is determined as the third total number of link edges.

10. The method according to claim 2, characterized in that Determining the first distance corresponding to the first positive sample triplet according to the first positive sample representation vector set includes: performing vector addition on a first positive sample header vector and a first positive sample relationship vector in the first positive sample representation vector set to obtain a first transformation vector of the first positive sample triplet; and determining a distance between the first transformation vector and a first positive sample tail vector in the first positive sample representation vector set as the first distance; Determining the second distance corresponding to the first negative sample according to the first negative sample representation vector set includes: performing vector addition on the first negative sample head vector and the first negative sample relationship vector in the first negative sample representation vector set to obtain a second transformation vector of the first negative sample triplet; and determining the distance between the second transformation vector and the first negative sample tail vector in the first negative sample representation vector set as the second distance.

11. The method according to any one of claims 1 to 10, characterized in that After obtaining the target representation learning model, the method further includes: Obtaining a target query statement and determining a query vector for representing the target query statement; Searching for candidate nodes matching the target query statement in the target knowledge graph; In the case where the candidate node is found, determining a set of candidate triples associated with the candidate node in the target knowledge graph, wherein each candidate triple in the set of candidate triples includes the entity represented by the candidate node; Obtaining a set of candidate representation vectors corresponding to the set of candidate triples, wherein each set of candidate representation vectors in the set of candidate representation vectors includes a head entity vector, a relationship vector, and a tail entity vector obtained by respectively encoding the head entity, the relationship, and the tail entity in each candidate triple in the set of candidate triples using the target representation learning model; searching for a target triple in the set of candidate triples according to the query vector, wherein a set of candidate representation vectors corresponding to the target triple matches the query vector; A target query result matching the target query statement is generated according to the target triple, and the target query result is output.

12. A knowledge graph representation learning device, characterized in that: include: An acquisition module is configured to acquire a set of sample triples, wherein the sample triples in the set of sample triples include: positive sample triples and negative sample triples, the positive sample triples are triples in the target knowledge graph, the negative sample triples are triples that do not appear in the target knowledge graph, the sample triples include a sample head entity, a sample relationship, and a sample tail entity, the sample relationship is used to represent the relationship between the sample head entity and the sample tail entity, the entities include people and events, and the relationships include person relationships and event relationships related to the people; a training module, configured to train an initial representation learning model to be trained using the set of sample triples until a target loss value corresponding to the initial representation learning model satisfies a preset loss condition, thereby obtaining a target representation learning model, wherein the target loss value is a loss value determined based on a first loss value and a second loss value, the first loss value being a loss value determined based on a first distance corresponding to the positive sample triples and a second distance corresponding to the negative sample triples, and the second loss value being a loss value determined based on a predicted similarity and an actual similarity between the positive sample triplets; Determine the query vector used to represent the target query statement, and use the target representation learning model to encode the head entity, relationship, and tail entity in the triple in the target knowledge graph into a head entity vector, a relationship vector, and a tail entity vector, respectively. Determine the target triple that matches the target query statement through the distance between the vectors to obtain the target query result.

13. A computer-readable storage medium, characterized in that The computer-readable storage medium includes a stored program, wherein the program can be executed by a terminal device or a computer to execute the method described in any one of claims 1 to 11.

14. A computer program product comprising a computer program / instructions, characterized in that When the computer program / instructions are executed by a processor, the steps of the method according to any one of claims 1 to 11 are implemented.

15. An electronic device comprising a memory and a processor, characterized in that: A computer program is stored in the memory, and the processor is configured to execute the method according to any one of claims 1 to 11 through the computer program.

Citation Information

Patent Citations

  • Knowledge graph representation learning model training method and device and electronic equipment

    CN111680109A

  • Q&a method, q&a device, computer equipment and storage medium

    WO2021000676A1