Training method and device of graph embedding model, computing device and readable medium
By dynamically updating the negative sample cache during the training process of the graph embedding model and retaining negative samples with higher scores, the problem of gradient zeroing too fast caused by uniform random sampling is solved, and the training effect and efficiency of the model are improved.
Patent Information
- Application Number
- CN201811526711.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2018-12-13
- Publication Date
- 2024-10-11
- Estimated Expiration
- 2038-12-13
AI Technical Summary
In the existing technology, when negative samples are extracted using uniform random sampling, the gradient of the graph embedding model may return to zero too quickly, leading to premature termination of training and affecting the accuracy of the graph embedding model.
During the training process of the graph embedding model, the negative sample cache is dynamically updated, negative samples with higher scores are retained, and corresponding negative samples are selected from the cache to participate in training to avoid the gradient from returning to zero too quickly.
It improves the training effect and efficiency of the graph embedding model, making the trained model embedding efficiency more efficient and accurate.
Smart Images

Figure CN111324776B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer application technology, and in particular to a training method and apparatus for a graph embedding model, a computing device, and a readable medium. Background Art
[0002] Knowledge graph is a very special graph data structure, where each node is an entity and the edge represents a relation. Therefore, in terms of physical representation, knowledge graph is generally saved as a bunch of triplets, for example, it can be represented as (h, r, t), where h∈ε is the head entity, is a relation, and t∈ε is the tail entity. Therefore, the meaning of a triple is that h and t have a relation of r. Such triple expressions are difficult to be processed by subsequent algorithms because the similarity between the two entities h and t is difficult to be quantitatively calculated. Therefore, graph embedding is a very important way to process knowledge graphs, which plays a vital role in the use of subsequent algorithms. The processing of graph embedding is mainly implemented by graph embedding models. Therefore, the training of graph embedding models in knowledge graphs is very important in the processing of knowledge graphs.
[0003] In the existing knowledge graph, every triple is real, that is, a positive sample, and there are generally no negative samples. Therefore, in the training process of the graph embedding model, how to find suitable negative samples (negative sampling) is a very critical issue. All triples that do not exist in the knowledge graph can be used as negative samples. Therefore, the number of potential negative samples is huge. How to select effective negative samples will not only seriously affect the efficiency of the graph embedding algorithm, but also significantly improve the effect of the graph embedding model. In the prior art, uniform random sampling is often used to extract negative samples. The graph embedding model is trained based on the extracted negative samples.
[0004] However, the uniform random sampling method used in the prior art to extract negative samples may result in poor performance of the extracted negative samples, and the evaluation function may give them a low score. When such negative samples are used to train the graph embedding model, the gradient of the graph embedding model will return to zero too quickly, and the training of the graph embedding model will be terminated prematurely, resulting in poor accuracy of the trained graph embedding model. Summary of the invention
[0005] Based on the above technical problems, the present invention provides a training method and apparatus for a graph embedding model, a computing device and a readable medium to improve the accuracy of the trained graph embedding model.
[0006] The present invention provides a method for training a graph embedding model, wherein the method comprises:
[0007] Get the triple set of the knowledge graph used for training;
[0008] In each iterative training process of at least part of the iterative training process: firstly update the negative sample caches corresponding to the triples, and then select the corresponding negative samples for each triple from the corresponding negative sample caches to participate in the training of the graph embedding model, or firstly select the corresponding negative samples for each triple from the corresponding negative sample caches to participate in the training of the graph embedding model, and then update the negative sample caches corresponding to each triple;
[0009] The negative sample cache corresponding to each triplet is updated so that negative samples with higher corresponding scores are retained in the negative sample cache.
[0010] The present invention also provides a training device for a graph embedding model, wherein the device comprises:
[0011] An acquisition module is used to obtain a set of triples of the knowledge graph used for training;
[0012] A training module, used for: in each iterative training process of at least part of the iterative training process: first updating the negative sample caches corresponding to the triples, and then selecting the corresponding negative samples for each triple from the corresponding negative sample caches to participate in the training of the graph embedding model, or first selecting the corresponding negative samples for each triple from the corresponding negative sample caches to participate in the training of the graph embedding model, and then updating the negative sample caches corresponding to each triple;
[0013] The negative sample cache corresponding to each triplet is updated so that negative samples with higher corresponding scores are retained in the negative sample cache.
[0014] The present invention also provides a computing device, comprising:
[0015] Processor; and
[0016] A memory having executable codes stored thereon, which, when executed by the processor, causes the processor to execute the method described above.
[0017] The present invention also provides a non-transitory machine-readable storage medium having executable codes stored thereon. When the executable codes are executed by a processor of an electronic device, the processor is caused to execute the method as described above.
[0018] The training method and apparatus, computing device and readable medium of the graph embedding model of the present invention can retain the negative samples with higher scores in the negative sample cache by updating the negative sample cache corresponding to each triple, and then select the corresponding negative samples from the negative sample cache to participate in the training of the graph embedding model based on the updated negative sample cache. The graph embedding model can be trained with the negative samples with high scores, and the negative samples with high scores can avoid the gradient function returning to zero too quickly during the training of the graph embedding model, thereby improving the training effect of the graph embedding model and making the embedding efficiency and accuracy of the trained graph embedding model higher. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] The above and other objects, features and advantages of the present disclosure will become more apparent through a more detailed description of exemplary embodiments of the present disclosure in conjunction with the accompanying drawings, wherein like reference numerals generally represent like components in the exemplary embodiments of the present disclosure.
[0020] Figure 1 Flow chart of an embodiment of a method for training a graph embedding model of the present invention.
[0021] Figure 2 Flow chart of another embodiment of the method for training a graph embedding model of the present invention.
[0022] Figure 3 The present invention is a flowchart of another embodiment of the method for training a graph embedding model.
[0023] Figure 4 A structural diagram of an embodiment of a training device for a graph embedding model of the present invention.
[0024] Figure 5 This is a structural diagram of another embodiment of the training device for the graph embedding model of the present invention.
[0025] Figure 6 A schematic diagram of the structure of a computing device that can be used to implement the training method of the graph embedding model according to an embodiment of the present invention is shown. DETAILED DESCRIPTION
[0026] The preferred embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although the preferred embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be limited by the embodiments described herein. On the contrary, these embodiments are provided to make the present disclosure more thorough and complete, and to fully convey the scope of the present disclosure to those skilled in the art.
[0027] The training of graph embedding models is a very important task in knowledge graphs. There are two key points in the training of graph embedding models: (A) the selection of evaluation functions and (B) negative sample sampling. The evaluation function is a function that models the relationship between h, r, and t in the triple (h, r, t). The evaluation result of the evaluation function will determine the optimization goal of the graph embedding algorithm. Negative sample sampling is the key to the optimization calculation. Since the triplets in the knowledge graph as training data are real and can be used as positive samples during training, all triplets that do not belong to the knowledge graph may be negative samples. Therefore, the number of potential negative samples is huge. How to select effective negative samples will not only seriously affect the efficiency of the graph embedding algorithm, but also significantly affect the embedding effect of the graph embedding model.
[0028] For example, given a (h, r, t) in a training data set, its negative sample set can be expressed as:
[0029]
[0030] Where ∪ represents the union operation. From the above representation, we can know that negative samples can be formed by replacing the head entity or the tail entity of the triples in the training data set to obtain triples that do not exist in the training data.
[0031] Table 1 below shows an implementation process of the graph embedding model algorithm.
[0032] Table 1
[0033]
[0034] Uniform random sampling is the most commonly used negative sample sampling method. In addition, the prior art also discloses a Generative Adversarial Network (GAN) that is used to replace uniform random sampling and achieves better embedding effects. Among them, the most important observation is that "most negative samples have very small estimated scores (scores obtained from the evaluation function)". Therefore, in uniform random sampling, the negative samples extracted are likely to have very small estimated scores, which will lead to the problem that the gradient returns to zero too quickly when it should not return to zero during the training of the graph model, thereby terminating the training of the graph embedding model algorithm prematurely. Therefore, in negative sample sampling, how to quickly find negative samples with high estimated scores is the core problem. GAN solves this problem by training a generator constructed by a neural network while training the original model. In particular, the generator will give a score distribution of negative samples, and negative samples will be extracted based on this. The generator can simulate the distribution of negative samples very well, and therefore can effectively give negative samples with higher estimated scores, thereby avoiding the problem of gradients returning to zero too quickly during training.
[0035] However, the problem that existing work has overlooked is that it is not necessary to model the complex overall distribution of negative samples. Especially in the later stages of training, only the negative samples with large scores are useful, and these only account for a small proportion of all negative samples. GAN can model the distribution as a whole, but at the same time, it spends a lot of time and parameters on useless small-score negative samples. Therefore, the GAN-based model is inefficient. In addition, the selection of negative samples is a discrete optimization problem, and reinforcement learning must be used to train the GAN-based graph embedding model; and reinforcement learning itself is very unstable and slow to train. Therefore, the GAN-based method is also difficult to train.
[0036] Based on the above problems, the present invention will realize a method of utilizing computer cache to retain only high-scoring negative samples, thereby effectively and quickly learning graph embedding models. In particular, a cache mechanism will be established for each triplet present in the training data. This cache will be dynamically updated during the algorithm iteration process during model training, and negative samples will be extracted from this cache. Because only high-scoring negative samples are retained in the cache, the problem of gradients returning to zero too quickly can be effectively avoided. In addition, the mechanism of the present invention has no redundant training parameters, and can be trained in the same way as the original model (because there are no more parameters to be trained). Therefore, the cache-based model training mechanism of the present invention can achieve similar or higher effects as GAN, but the speed can be faster and the training can be more stable.
[0037] In addition, based on the above effects of the present invention, the present invention needs to explore the space composed of all negative samples as much as possible, so as to reduce the bias caused by sample selection. In general, in order to obtain good learning effects, the cache design should achieve two goals:
[0038] (1) Retain negative samples with overestimated scores (to avoid the problem of gradients returning to zero too quickly during training);
[0039] (2) Explore the sample space composed of all negative samples as much as possible (S′ (h,r,t) constitute).
[0040] The training scheme of the graph embedding model of the present invention comes into being under the above background. The specific implementation method can refer to the description of the following embodiments.
[0041] Figure 1 FIG. 1 is a flow chart of an embodiment of a method for training a graph embedding model of the present invention. Figure 1 As shown, the training method of the graph embedding model of this embodiment may specifically include the following steps:
[0042] S100, obtaining a set of triples of a knowledge graph for training;
[0043] S101, in each iterative training process of at least part of the iterative training process: first update the negative sample caches corresponding to the triples, and then select the corresponding negative samples for each triple from the corresponding negative sample caches to participate in the training of the graph embedding model, or first select the corresponding negative samples for each triple from the corresponding negative sample caches to participate in the training of the graph embedding model, and then update the negative sample caches corresponding to each triple;
[0044] The negative sample cache corresponding to each triplet is updated so that negative samples with higher corresponding scores are retained in the negative sample cache.
[0045] The execution subject of the training method of the graph embedding model of the present embodiment may be a graph embedding model training device, and the graph embedding model training device may be an electronic device with a physical entity, which can receive a set of triples of the knowledge graph for input training, and perform training processing based on each triple in the set of triples. For example, in each iterative training process in at least part of the iterative training process: the negative sample cache corresponding to each triple may be updated first, and then the corresponding negative sample may be selected from the corresponding negative sample cache for each triple to participate in the training of the graph embedding model, or the corresponding negative sample may be selected from the corresponding negative sample cache for each triple to participate in the training of the graph embedding model, and then the negative sample cache corresponding to each triple may be updated; however, the negative sample cache corresponding to each triple updated at this time is used to directly obtain the corresponding negative sample from the negative sample cache to participate in the training of the graph embedding model in the next iterative training.
[0046] In addition, the training device for the graph embedding model of this embodiment can also be a software integrated application, and the implementation method is the same.
[0047] In this embodiment, a negative sample cache can be pre-set for each triple in the knowledge graph. For example, the negative sample cache corresponding to each triple may include: a head cache and / or a tail cache; wherein the head cache is used to store N1 negative samples whose head entities are inconsistent with the corresponding triples; the tail cache is used to store M1 negative samples whose tail entities are inconsistent with the corresponding triples; N1 and M1 are both positive integers.
[0048] Specifically, for each triple, the header cache is used to store N1 negative samples whose header entities are inconsistent with the header entity of the triple. Since the negative samples only have header entities that are different from the corresponding triple, in order to save the storage space of the header cache, the header cache can only store N1 entities that are inconsistent with the header entity of the triple. For example, for N1 negative samples, only N1 unit-length cache spaces are allocated to store the corresponding negative sample header entities.
[0049] Similarly, for each triple, the tail cache is used to store M1 negative samples whose head entity is inconsistent with the tail entity of the triple. Since only the head and tail entities of the negative sample are different from the corresponding triple, in order to save the storage space of the tail cache, the tail cache can only store M1 entities that are inconsistent with the tail entity of the triple. For example, for M1 negative samples, only M1 unit-length cache space is allocated to store the tail entity of the corresponding negative sample.
[0050] During specific training, only negative samples in the head buffer or only negative samples in the tail buffer may be selected according to a pre-set configuration, or negative samples may be randomly selected from the head buffer and the tail buffer.
[0051] For example, in step S101 of this embodiment, "selecting corresponding negative samples from the corresponding negative sample caches for each triple to participate in the training of the graph embedding model" can be implemented in the following manner:
[0052] For a triple, when the triple has a corresponding head cache and a tail cache, first randomly select a first negative sample set from the corresponding head cache, and randomly select a second negative sample set from the corresponding tail cache, and then randomly select a preset number of negative samples from the first negative sample set and the second negative sample set as negative samples of the triple to participate in the training of the graph embedding model.
[0053] In this implementation scheme, taking the example of randomly selecting negative samples from the head cache and the tail cache, the first negative sample set can be randomly selected from the head cache corresponding to the triple, and the second negative sample set can be randomly selected from the tail cache corresponding to the triple, and then a preset number of negative samples are randomly selected from the first negative sample set and the second negative sample set as the negative samples of the triple to participate in the training of the graph embedding model. In this embodiment, the number of negative samples included in the first negative sample set and the second negative sample set and the preset number can be set according to the determined evaluation function. Because the evaluation functions from different categories have different corresponding gradient functions, and the number of negative samples required by the gradient function is also different. Therefore, the preset number of negative samples can be set with reference to the gradient function corresponding to the classification of the evaluation function, and then the number of negative samples in the first negative sample set and the second negative sample set can be set according to the preset number. Since the preset number of negative samples participating in the training can be randomly selected from the first negative sample set and the second negative sample set, the number of negative samples in the first negative sample set and the second negative sample set must be greater than the preset number.
[0054] For example, in practical applications, when only one negative sample needs to be selected for training, both the first negative sample set and the second negative sample set may include only one negative sample, and at this time, one of the first negative sample set and the second negative sample set may be randomly selected to participate in the training. When multiple negative samples need to be selected for training, multiple negative samples may be set in the first negative sample set and the second negative sample set to facilitate random selection.
[0055] Optionally, before the above-mentioned step S101 "each iterative training in at least part of the iterative training process", it may also include: using the unique identifier of each triplet to index the corresponding negative sample cache, so that the negative sample cache pre-set for each triplet can be found, so as to facilitate the subsequent update of the negative sample cache in the corresponding negative sample cache. For example, when implemented, it may specifically include any one of the following three methods:
[0056] The first method: using the address of each triplet to index the corresponding negative sample cache. Here, the storage address of each triplet can uniquely identify each triplet, so the address of each triplet can be used to index the corresponding negative sample cache.
[0057] The second method: perform string hashing on the characters of each triple in the memory, and use the string hashing result to index the corresponding negative sample cache;
[0058] The third party is: performing string hashing on the specific physical meaning of each triple, and using the string hashing result to index the corresponding negative sample cache. In one embodiment of the present invention, the physical meaning of the triple may specifically be the semantic information expressed by the triple.
[0059] Each triple (h, r, t) ∈ S in the training data set has a unique identifier, for example, the unique identifier can be represented by an integer value, which can be recorded as I (h, r, t). (h,r,t) It can be obtained by replacing the head entity or the tail entity. From the above embodiment, it can be known that two sets of caches, head cache H and tail cache T, can be designed for each triple (h, r, t).
[0060] Header cache H: retains high-scoring negative samples obtained by replacing the head, i.e. The header cache H is indexed by I(h,r,t) as the address. Since only the header entity is replaced, the index is Only the head that stores the above negative samples is used;
[0061] Similarly, the tail cache T: retains the high-scoring negative samples obtained by replacing the tail, that is, T is indexed by Ih,r,t as the address. Since only the tail entity is replaced, the index is Only the tail of the above negative samples is stored;
[0062] Similarly, in this embodiment, the actual retention in H I(h,r,t) and T I(h,r,t) In , only the markers corresponding to h′, t′∈ε are needed. Therefore, for each (h, r, t) head cache H and tail cache T, the total memory size required is 2N1.
[0063] Similarly, we can perform string hashing on the bytes in the memory of each triple, and based on the hash result, we can also index the corresponding negative sample cache; or we can perform string hashing on the specific physical meaning of each triple, and based on the hash result, we can also index the corresponding negative sample cache. For example, the specific physical meaning of a triple can be expressed as (employee A, employed, company B), and string hashing can be performed based on the specific physical meaning.
[0064] The training method of the graph embedding model of the present embodiment updates the negative sample cache corresponding to each triplet, so that the negative samples with higher corresponding scores are retained in the negative sample cache. Then, based on the updated negative sample cache, the corresponding negative samples are selected from the negative sample cache to participate in the training of the graph embedding model. The graph embedding model can be trained with negative samples with high scores. Moreover, negative samples with high scores can avoid the gradient function returning to zero too quickly during the training of the graph embedding model, thereby improving the training effect of the graph embedding model and making the embedding efficiency and accuracy of the trained graph embedding model higher.
[0065] Figure 2 FIG. 1 is a flow chart of another embodiment of a method for training a graph embedding model of the present invention. Figure 2 As shown, in this embodiment, the specific description is Figure 1 In the illustrated embodiment, if the negative sample cache corresponding to each triple includes a header cache, correspondingly, “updating the negative sample caches corresponding to each triple” in step S101 may specifically include the following steps:
[0066] S200, for each triple, randomly sample N2 negative samples whose head entities are inconsistent with the triple from the negative sample space of the triple, where N2 is a positive integer;
[0067] For example, referring to the above embodiment, the header cache may only include header entities that are different from the corresponding triplet. For each triplet, since only the header is different, N2 negative samples whose header entities are inconsistent with the triplet are randomly sampled from the negative sample space of the triplet. This can also be achieved by randomly selecting N2 head entities that are inconsistent with the head entity of the triplet.
[0068] S201, selecting N1 negative samples from the N1 negative samples already in the header buffer of the triple and the sampled N2 negative samples;
[0069] At this time, correspondingly, N1 header entities may be selected from the N1 header entities in the header cache of the triple and the randomly selected N2 header entities.
[0070] S202: Use the selected N1 negative samples to update the header cache of the triplet.
[0071] Correspondingly, the header cache of the triplet may be updated with the selected N1 header entities.
[0072] In addition, it should be noted that, in this embodiment, before starting at least part of the iterative process, it may also include: for each triple, randomly selecting N1 head entities that are inconsistent with the head entity of the triple and putting them into the head cache of the triple to initialize the head cache of the triple. This process is a process of initializing the head cache. During initialization, the head cache in each triple may not contain the head entity of the negative sample with the highest score, but after the update of this embodiment, the head cache can only include the head entity of the negative sample with the highest score.
[0073] For example, step S201 "selecting N1 negative samples from the N1 negative samples already in the header cache of the triplet and the sampled N2 negative samples" may specifically include: using an evaluation function to calculate the scores of the N1+N2 negative samples of the triplet; and then selecting N1 negative samples from the N1+N2 negative samples based on the scores of the N1+N2 negative samples.
[0074] Furthermore, the step of “selecting N1 negative samples from N1+N2 negative samples according to the scores of N1+N2 negative samples” may include any of the following two methods:
[0075] (a) Select the top N1 negative samples with the highest scores from N1+N2 negative samples;
[0076] (b) For each negative sample in the N1+N2 negative samples, the extraction probability of the negative sample is calculated based on the scores of the N1+N2 negative samples; according to the extraction probabilities corresponding to each of the N1+N2 negative samples, N1 negative samples are extracted from the N1+N2 negative samples in sequence.
[0077] For example, the probability of extracting negative samples in this embodiment can be expressed by the following formula:
[0078]
[0079] Where p(h′|r,t) is the extraction probability of negative sample (h′|r,t); f(h′,r,t) is the score of the evaluation function for negative sample (h′,r,t); f(h,r,t) is the score of the evaluation function for any triple (h,r,t) in the header cache H1, then ∑ h∈H1 e f(h,r,t) Meaning: For each header entity in the header cache H1, the corresponding triple (h, r, t) is obtained. f(h ,r,t) , and then sum them. Of course, in practical applications, other methods can also be used to set the probability of extracting negative samples, so that negative samples with high scores have a higher probability of being extracted.
[0080] The training method of the graph embedding model of the present embodiment updates the head cache corresponding to each triplet through the above scheme, so that the head cache can retain the corresponding negative samples with higher scores. Then, based on the updated head cache, when the corresponding negative samples are selected from the head cache to participate in the training of the graph embedding model, the graph embedding model can be trained with the negative samples with high scores. Moreover, the negative samples with high scores can avoid the gradient function returning to zero too quickly during the training of the graph embedding model, thereby improving the training effect of the graph embedding model and making the embedding efficiency and accuracy of the trained graph embedding model higher.
[0081] Figure 3 FIG. 4 is a flow chart of another embodiment of the training method of the graph embedding model of the present invention. Figure 2 As shown, in this embodiment, the specific description is Figure 1 In the illustrated embodiment, if the negative sample cache corresponding to each triple includes a tail cache, correspondingly, "updating the negative sample caches corresponding to each triple" in step S101 may specifically include the following steps:
[0082] S300, for each triple, randomly sample M2 negative samples whose tail entities are inconsistent with the triple from the negative sample space of the triple, where M2 is a positive integer;
[0083] and Figure 2 Similar to the embodiment shown, referring to the tail cache in the above embodiment, only tail entities different from the corresponding triplet may be included. For each triplet, since only the tail is different, M2 negative samples whose tail entities are inconsistent with the triplet are randomly sampled from the negative sample space of the triplet. This can also be achieved by randomly selecting M2 tail entities that are inconsistent with the tail entity of the triplet.
[0084] S301, selecting M1 negative samples from the M1 negative samples already in the tail buffer of the triple and the sampled M2 negative samples;
[0085] Similarly, correspondingly, M1 tail entities can be selected from the M1 tail entities in the tail cache of the triple and the M2 tail entities randomly selected.
[0086] S302: Use the selected M1 negative samples to update the tail cache of the triplet.
[0087] Correspondingly, the tail cache of the triplet can be updated with the selected M1 tail entities.
[0088] Similarly, it should be noted that, in this embodiment, before starting at least part of the iterative process, it may also include: for each triple, randomly selecting M1 tail entities that are inconsistent with the tail entity of the triple and putting them into the tail cache of the triple to initialize the tail cache of the triple. Similarly, during the process of initializing the tail cache, the tail cache in each triple may not contain the tail entity of the negative sample with the highest score during initialization, but after the update of this embodiment, the tail cache may only include the tail entity of the negative sample with the highest score.
[0089] For example, step S301 "selecting M1 negative samples from the M1 negative samples already in the tail cache of the triplet and the sampled M2 negative samples" may specifically include: using an evaluation function to calculate the scores of the M1+M2 negative samples of the triplet; and selecting M1 negative samples from the M1+M2 negative samples based on the scores of the M1+M2 negative samples.
[0090] Furthermore, the step of “selecting M1 negative samples from M1+M2 negative samples according to the scores of M1+M2 negative samples” may include the following two methods:
[0091] (A) Select the top M1 negative samples with the highest scores from M1+M2 negative samples;
[0092] (B) For each negative sample in the M1+M2 negative samples, the extraction probability of the negative sample is calculated based on the scores of the M1+M2 negative samples; according to the extraction probabilities corresponding to each of the M1+M2 negative samples, M1 negative samples are extracted from the M1+M2 negative samples in sequence.
[0093] The probability of negative sample extraction can be obtained by using the above Figure 2 The formula for the probability of extracting relevant negative samples in the illustrated embodiment may also be implemented by other formulas, so that negative samples with high scores have a higher probability of being extracted, which will not be described one by one here.
[0094] The training method of the graph embedding model of this embodiment updates the tail cache corresponding to each triplet through the above scheme, so that the tail cache can retain the corresponding negative samples with higher scores. Then, based on the updated tail cache, when the corresponding negative samples are selected from the tail cache to participate in the training of the graph embedding model, the graph embedding model can be trained with the negative samples with high scores. Moreover, the negative samples with high scores can avoid the gradient function returning to zero too quickly during the training of the graph embedding model, thereby improving the training effect of the graph embedding model and making the embedding efficiency and accuracy of the trained graph embedding model higher.
[0095] Based on the above Figure 1-Figure 3 As described in the embodiment shown, the two groups of caches based on each triplet described above, namely the head cache HI (h,r,t) and tail buffer TI(h,r,t) , the algorithm is iterated according to the algorithm flow shown in Table 2. Specifically, the algorithm is iterated K times as a whole; and K*M》N, ensuring that each triple can be iterated multiple times. In each iteration, first select a batch of sample data S of size m batch (Step 24), then for each batch The positive samples in the cache are negatively sampled (steps 26-28); based on the sampled positive and negative samples, the embedded model parameters are updated (step 29); and finally the cache is updated. It should be noted that in this embodiment, the head cache H I(h,r,t) All operations and descriptions also apply to the tail buffer TI (h,r,t) , you can only describe the head buffer HI in the following description (h,r,t) Related operations.
[0096] Table 2
[0097]
[0098]
[0099] Among them, step 27 adopts uniform random sampling for the following reasons: in the key points, when selecting negative samples, both the score should be high and the entire sample space should be explored as much as possible. (h,r,t) Negative samples with relatively high scores have been retained in the , and uniform random sampling is adopted to ensure exploration. Step 210 needs to update the existing head cache and tail cache, wherein the detailed steps of updating the head cache are shown in Table 3 below, and in actual applications, the tail cache can be updated in the same way.
[0100] Table 3
[0101]
[0102] Similarly, we need to retain negative samples with high scores, but we also want to explore the negative sample space as much as possible. Therefore, when updating H′ I(h,r,t) Before, we first select N2 entities from the entire sample space to form R m , this set will be combined with H I(h,r,t) Take a union (steps 33-34). Then, from this superset H′ I(h,r,t) Resample the N1 head entities as the updated cache. Note that steps 36-310 in Table 3 perform importance sampling according to the estimated scores; in fact, we can sort them according to their scores and then take the N1 entities with the highest scores, but this will not allow for a high enough exploration, resulting in a decrease in embedding performance.
[0103] The training method of the graph embedding model in the above embodiment can retain the negative samples with higher corresponding scores in the negative sample cache by updating the negative sample cache corresponding to each triplet, and then select the corresponding negative samples from the negative sample cache to participate in the training of the graph embedding model based on the updated negative sample cache. The graph embedding model can be trained with the negative samples with high scores. Moreover, the negative samples with high scores can avoid the gradient function returning to zero too quickly during the training of the graph embedding model, thereby improving the training effect of the graph embedding model and making the embedding efficiency and accuracy of the trained graph embedding model higher.
[0104] In the graph embedding algorithm process shown in Table 2 above, in each iteration process, negative samples are first selected from the negative sample cache for this iteration training (steps 27-29), and then the negative sample cache is updated (step 210). However, in another embodiment of the present invention, in each iteration process, the negative sample cache may be updated first, and then negative samples are selected from the negative sample cache for this iteration training.
[0105] Figure 4 FIG. 1 is a structural diagram of an embodiment of a training device for a graph embedding model of the present invention. Figure 4 As shown, the training device of the graph embedding model of this embodiment may specifically include:
[0106] An acquisition module 10 is used to acquire a set of triples of a knowledge graph for training;
[0107] The training module 11 is used for: in each iterative training process of at least part of the iterative training process: first updating the negative sample caches corresponding to each triple in the triple set obtained by the acquisition module 10, and then selecting corresponding negative samples for each triple from the corresponding negative sample caches to participate in the training of the graph embedding model, or first selecting corresponding negative samples for each triple from the corresponding negative sample caches to participate in the training of the graph embedding model, and then updating the negative sample caches corresponding to each triple;
[0108] The negative sample cache corresponding to each triplet is updated so that negative samples with higher corresponding scores are retained in the negative sample cache.
[0109] The training device for the graph embedding model of this embodiment, by adopting the above-mentioned modules to realize the training of the graph embedding model, has the same implementation principle and technical effects as those of the above-mentioned related method embodiments. For details, please refer to the records of the above-mentioned related method embodiments, which will not be repeated here.
[0110] Figure 5 FIG. 1 is a structural diagram of another embodiment of a training device for a graph embedding model of the present invention. Figure 5 As shown, the training device of the graph embedding model of this embodiment, in the above Figure 4Based on the technical solutions of the illustrated embodiments, the technical solutions of the present invention are further described in more detail.
[0111] In the training device of the graph embedding model of this embodiment, the negative sample cache corresponding to each triple includes: a head cache and / or a tail cache;
[0112] The head cache is used to store N1 negative samples whose head entities are inconsistent with corresponding triples; the tail cache is used to store M1 negative samples whose tail entities are inconsistent with corresponding triples; N1 and M1 are both positive integers.
[0113] Further optionally, in the training device for the graph embedding model of this embodiment, the training module 11 is used for:
[0114] For a triple, when the triple has a corresponding head cache and a tail cache, first randomly select a first negative sample set from the corresponding head cache, and randomly select a second negative sample set from the corresponding tail cache, and then randomly select a preset number of negative samples from the first negative sample set and the second negative sample set as negative samples of the triple to participate in the training of the graph embedding model.
[0115] Further optionally, if Figure 5 As shown, the training device for the graph embedding model of this embodiment further includes: an indexing module 12 is used to use the unique identifier of each triple to index the corresponding negative sample cache.
[0116] Correspondingly, the training module 11 is used to first update the negative sample cache corresponding to each triplet in the triplet set obtained by the index module 12 during each iterative training process in at least part of the iterative training process.
[0117] Further optionally, the index module 12 is used to: use the address of each triple to index the corresponding negative sample cache; or, perform string hashing on the characters of each triple in the memory, and use the result of the string hashing to index the corresponding negative sample cache; or, perform string hashing on the specific physical meaning of each triple, and use the result of the string hashing to index the corresponding negative sample cache.
[0118] Further optionally, in the training device of the graph embedding model of the present embodiment, the training module 11 is used for: if the negative sample cache corresponding to each triple includes a head cache, for each triple, randomly sampling N2 negative samples whose head entities are inconsistent with the triple from the negative sample space of the triple, where N2 is a positive integer; selecting N1 negative samples from the N1 negative samples already in the head cache of the triple and the sampled N2 negative samples; and updating the head cache of the triple with the selected N1 negative samples.
[0119] Further optionally, in the training device of the graph embedding model of the present embodiment, the training module 11 is used for: if only head entities of negative samples are stored in the head cache, randomly selecting N2 head entities that are inconsistent with the head entity of the triplet; selecting N1 head entity from the N1 head entities in the head cache of the triplet and the randomly selected N2 head entities; and updating the head cache of the triplet with the selected N1 head entities.
[0120] Further optionally, if Figure 5 As shown, the training device of the graph embedding model of this embodiment also includes: a first initialization module 13 is used to randomly select N1 head entities that are inconsistent with the head entity of the triplet for each triplet and put them into the head cache of the triplet to initialize the head cache of the triplet.
[0121] Correspondingly, the index module 12 may guide the corresponding header cache based on the initialization setting of the first initialization module 13 .
[0122] Further optionally, in the training device of the graph embedding model of the present embodiment, the training module 11 is used to: use an evaluation function to calculate the scores of the N1+N2 negative samples of the triplet; and select N1 negative samples from the N1+N2 negative samples based on the scores of the N1+N2 negative samples.
[0123] Further optionally, in the training device of the graph embedding model of the present embodiment, the training module 11 is used to: select the top N1 negative samples with the highest scores from the N1+N2 negative samples; or, for each negative sample in the N1+N2 negative samples, calculate the extraction probability of the negative sample based on the scores of the N1+N2 negative samples; and extract N1 negative samples from the N1+N2 negative samples in sequence according to the extraction probabilities corresponding to each of the N1+N2 negative samples.
[0124] Further optionally, in the training device of the graph embedding model of the present embodiment, the training module 11 is used to: for each triple, randomly sample M2 negative samples whose tail entities are inconsistent with the triple from the negative sample space of the triple, where M2 is a positive integer; select M1 negative samples from the M1 negative samples already in the tail cache of the triple and the sampled M2 negative samples; and update the tail cache of the triple with the selected M1 negative samples.
[0125] Further optionally, in the training device of the graph embedding model of the present embodiment, the training module 11 is used for: if only tail entities of negative samples are stored in the tail cache, randomly selecting M2 tail entities that are inconsistent with the tail entity of the triplet; selecting M1 tail entities from the M1 tail entities in the tail cache of the triplet and the randomly selected M2 tail entities; and updating the tail cache of the triplet with the selected M1 tail entities.
[0126] Further optionally, if Figure 5 As shown, the training device of the graph embedding model of this embodiment also includes: a second initialization module 14 is used to randomly select M1 tail entities that are inconsistent with the tail entity of the triplet for each triplet and put them into the tail cache of the triplet to initialize the tail cache of the triplet.
[0127] Correspondingly, the index module 12 may guide the corresponding tail cache based on the initialization setting of the second initialization module 14 .
[0128] Further optionally, in the training device of the graph embedding model of the present embodiment, the training module 11 is used to: use an evaluation function to calculate the scores of the M1+M2 negative samples of the triplet; and select M1 negative samples from the M1+M2 negative samples based on the scores of the M1+M2 negative samples.
[0129] Further optionally, in the training device of the graph embedding model of the present embodiment, the training module 11 is used to: select the first M1 negative samples with the highest scores from the M1+M2 negative samples; or, for each negative sample in the M1+M2 negative samples, calculate the extraction probability of the negative sample based on the scores of the M1+M2 negative samples; and extract M1 negative samples from the M1+M2 negative samples in sequence according to the extraction probabilities corresponding to each of the M1+M2 negative samples.
[0130] The training device for the graph embedding model of this embodiment, by adopting the above-mentioned modules to realize the training of the graph embedding model, has the same implementation principle and technical effects as those of the above-mentioned related method embodiments. For details, please refer to the records of the above-mentioned related method embodiments, which will not be repeated here.
[0131] Figure 6 A schematic diagram of the structure of a computing device that can be used to implement the training method of the graph embedding model according to an embodiment of the present invention is shown.
[0132] See also Figure 6 , the computing device 1000 includes a memory 1010 and a processor 1020 .
[0133] The processor 1020 may be a multi-core processor or may include multiple processors. In some embodiments, the processor 1020 may include a general-purpose main processor and one or more special coprocessors, such as a graphics processing unit (GPU), a digital signal processor (DSP), etc. In some embodiments, the processor 1020 may be implemented using a customized circuit, such as an application-specific integrated circuit (ASIC) or a field programmable gate array (FPGA).
[0134] The memory 1010 may include various types of storage units, such as system memory, read-only memory (ROM), and permanent storage devices. Among them, ROM can store static data or instructions required by the processor 1020 or other modules of the computer. The permanent storage device may be a readable and writable storage device. The permanent storage device may be a non-volatile storage device that does not lose the stored instructions and data even after the computer is powered off. In some embodiments, the permanent storage device uses a large-capacity storage device (such as a magnetic or optical disk, flash memory) as a permanent storage device. In some other embodiments, the permanent storage device may be a removable storage device (such as a floppy disk, optical drive). The system memory may be a readable and writable storage device or a volatile readable and writable storage device, such as a dynamic random access memory. The system memory may store some or all instructions and data required by the processor at run time. In addition, the memory 1010 may include any combination of computer-readable storage media, including various types of semiconductor memory chips (DRAM, SRAM, SDRAM, flash memory, programmable read-only memory), and disks and / or optical disks may also be used. In some embodiments, the memory 1010 may include a readable and / or writable removable storage device, such as a laser disc (CD), a read-only digital versatile disc (such as a DVD-ROM, a double-layer DVD-ROM), a read-only Blu-ray disc, an ultra-density optical disc, a flash memory card (such as an SD card, a mini SD card, a Micro-SD card, etc.), a magnetic floppy disk, etc. The computer-readable storage medium does not include carrier waves and transient electronic signals transmitted wirelessly or wired.
[0135] The memory 1010 stores executable codes, and when the executable codes are processed by the processor 1020, the processor 1020 can execute the training method of the graph embedding model mentioned above.
[0136] The training of the graph embedding model according to the present invention has been described in detail above with reference to the accompanying drawings.
[0137] In addition, the method according to the present invention may also be implemented as a computer program or a computer program product, which includes computer program code instructions for executing the above steps defined in the above method of the present invention.
[0138] Alternatively, the present invention may also be implemented as a non-temporary machine-readable storage medium (or computer-readable storage medium, or machine-readable storage medium) on which executable code (or computer program, or computer instruction code) is stored. When the executable code (or computer program, or computer instruction code) is executed by a processor of an electronic device (or computing device, server, etc.), the processor executes the various steps of the above-mentioned method according to the present invention.
[0139] Those skilled in the art will further appreciate that the various illustrative logical blocks, modules, circuits, and algorithm steps described in connection with the disclosure herein may be implemented as electronic hardware, computer software, or a combination of both.
[0140] The flow chart and block diagram in the accompanying drawings show the possible architecture, function and operation of the system and method according to multiple embodiments of the present invention. In this regard, each square box in the flow chart or block diagram can represent a part of a module, program segment or code, and the part of the module, program segment or code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two continuous square boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs the specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0141] The embodiments of the present invention have been described above, and the above description is exemplary, not exhaustive, and is not limited to the disclosed embodiments. Many modifications and variations will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described embodiments. The terms used herein are selected to best explain the principles of the embodiments, practical applications, or improvements to the technology in the market, or to enable other persons of ordinary skill in the art to understand the embodiments disclosed herein.
Claims
1. A training method for graph embedding models, in, The method comprises: Obtain a set of triples of a knowledge graph for training, each triple in the set of triples being a positive sample; In each iterative training process of at least part of the iterative training process: first update the negative sample caches corresponding to the triples, then select the corresponding negative samples for each triple from the corresponding negative sample caches as the negative samples of the triples to participate in the training of the graph embedding model, or first select the corresponding negative samples for each triple from the corresponding negative sample caches as the negative samples of the triples to participate in the training of the graph embedding model, then update the negative sample caches corresponding to each triple; Among them, the negative sample cache corresponding to each triple is updated so that negative samples with higher corresponding scores are retained in the negative sample cache. The score is a score calculated by using an evaluation function on the negative sample. The evaluation function is a function used to model the relationship between the head entity, the tail entity, and the relationship in the triple.
2. The method according to claim 1, in, The negative sample cache corresponding to each triplet includes: a head cache and / or a tail cache; The head cache is used to store N1 negative samples whose head entities are inconsistent with corresponding triples; the tail cache is used to store M1 negative samples whose tail entities are inconsistent with corresponding triples; N1 and M1 are both positive integers.
3. The method according to claim 2, in, The selecting corresponding negative samples for each triplet from the corresponding negative sample caches as negative samples of the triplet to participate in the training of the graph embedding model includes: For a triple, when the triple has a corresponding head cache and a tail cache, first randomly select a first negative sample set from the corresponding head cache, and randomly select a second negative sample set from the corresponding tail cache, and then randomly select a preset number of negative samples from the first negative sample set and the second negative sample set as negative samples of the triple to participate in the training of the graph embedding model.
4. The method according to claim 1, in, Prior to each iteration of training in at least part of the iterative training process, the method comprises: The unique identifier of each triplet is used to index the corresponding negative sample cache.
5. The method according to claim 4, in, The method of using the unique identifier of each triplet to index the corresponding negative sample cache includes: Use the address of each triplet to index the corresponding negative sample cache; Alternatively, character strings of the triples in the memory are hashed, and the result of the string hashing is used to index the corresponding negative sample cache; Alternatively, a string hash is performed on the specific physical meaning of each triple, and the result of the string hash is used to index the corresponding negative sample cache.
6. The method according to claim 2, in, When the negative sample cache corresponding to each triplet includes the header cache, the negative sample caches corresponding to each triplet are updated, including: For each triple, randomly sample N2 negative samples whose head entities are inconsistent with the triple from the negative sample space of the triple, where N2 is a positive integer; Selecting N1 negative samples from the N1 negative samples already in the header buffer of the triplet and the sampled N2 negative samples; Use the selected N1 negative samples to update the header cache of the triplet.
7. The method according to claim 6, in, The header cache only stores the header entities of negative samples; The randomly sampling N2 negative samples whose head entities are inconsistent with the triplet from the negative sample space of the triplet includes: randomly selecting N2 head entities that are inconsistent with the head entity of the triplet; The selecting N1 negative samples from the N1 negative samples already in the header cache of the triplet and the N2 negative samples sampled comprises: selecting N1 header entities from the N1 header entities in the header cache of the triplet and the N2 header entities randomly selected; The updating the header cache of the triplet using the selected N1 negative samples includes: updating the header cache of the triplet using the selected N1 header entities.
8. The method according to claim 7, in, Prior to starting the at least partial iterative process, the method further comprises: For each triple, N1 header entities that are inconsistent with the header entity of the triple are randomly selected and put into the header cache of the triple to initialize the header cache of the triple.
9. The method according to claim 6, in, Selecting N1 negative samples from the N1 negative samples already in the header buffer of the triplet and the N2 negative samples sampled comprises: Using an evaluation function, calculate the scores of the N1+N2 negative samples of the triplet; According to the scores of the N1+N2 negative samples, N1 negative samples are selected from the N1+N2 negative samples.
10. The method according to claim 9, in, According to the scores of the N1+N2 negative samples, selecting N1 negative samples from the N1+N2 negative samples includes: Select the top N1 negative samples with the highest scores from the N1+N2 negative samples; or, For each negative sample in the N1+N2 negative samples, the extraction probability of the negative sample is calculated based on the scores of the N1+N2 negative samples; and N1 negative samples are extracted from the N1+N2 negative samples in sequence according to the extraction probabilities corresponding to each of the N1+N2 negative samples.
11. The method according to claim 2, in, When the negative sample cache corresponding to each triplet includes the tail cache, the negative sample caches corresponding to each triplet are updated, including: For each triple, randomly sample M2 negative samples whose tail entities are inconsistent with the triple from the negative sample space of the triple, where M2 is a positive integer; Selecting M1 negative samples from the M1 negative samples already in the tail buffer of the triple and the sampled M2 negative samples; Use the selected M1 negative samples to update the tail cache of the triplet.
12. The method according to claim 11, in, Only the tail entities of negative samples are saved in the tail cache; The randomly sampling M2 negative samples whose tail entities are inconsistent with the triplet from the negative sample space of the triplet comprises: randomly selecting M2 tail entities that are inconsistent with the tail entity of the triplet; The selecting M1 negative samples from the existing M1 negative samples in the tail buffer of the triple and the sampled M2 negative samples comprises: selecting M1 tail entities from the M1 tail entities in the tail buffer of the triple and the randomly selected M2 tail entities; The updating the tail cache of the triplet using the selected M1 negative samples includes: updating the tail cache of the triplet using the selected M1 tail entities.
13. The method according to claim 12, in, Prior to starting the at least partial iterative process, the method further comprises: For each triple, M1 tail entities that are inconsistent with the tail entity of the triple are randomly selected and put into the tail cache of the triple to initialize the tail cache of the triple.
14. The method according to claim 11, in, Selecting M1 negative samples from the M1 negative samples already in the tail buffer of the triple and the sampled M2 negative samples comprises: Using an evaluation function, calculate the scores of the M1+M2 negative samples of the triplet; According to the scores of the M1+M2 negative samples, M1 negative samples are selected from the M1+M2 negative samples.
15. The method according to claim 14, in, According to the scores of the M1+M2 negative samples, selecting M1 negative samples from the M1+M2 negative samples includes: Select the top M1 negative samples with the highest scores from the M1+M2 negative samples; or, For each negative sample in the M1+M2 negative samples, the extraction probability of the negative sample is calculated based on the scores of the M1+M2 negative samples; and M1 negative samples are extracted from the M1+M2 negative samples in sequence according to the extraction probabilities corresponding to each of the M1+M2 negative samples.
16. A training device for a graph embedding model, in, The device comprises: An acquisition module, used to acquire a set of triples of a knowledge graph for training, each triple in the set of triples being a positive sample; A training module, used for: in each iterative training process of at least part of the iterative training process: first updating the negative sample caches corresponding to each triple, and then selecting the corresponding negative samples for each triple from the corresponding negative sample caches as the negative samples of the triple to participate in the training of the graph embedding model, or first selecting the corresponding negative samples for each triple from the corresponding negative sample caches as the negative samples of the triple to participate in the training of the graph embedding model, and then updating the negative sample caches corresponding to each triple; Among them, the negative sample cache corresponding to each triple is updated so that negative samples with higher corresponding scores are retained in the negative sample cache. The score is a score calculated by using an evaluation function on the negative sample. The evaluation function is a function used to model the relationship between the head entity, the tail entity, and the relationship in the triple.
17. The device according to claim 16, in, The negative sample cache corresponding to each triplet includes: a head cache and / or a tail cache; The head cache is used to store N1 negative samples whose head entities are inconsistent with corresponding triples; the tail cache is used to store M1 negative samples whose tail entities are inconsistent with corresponding triples; N1 and M1 are both positive integers.
18. The device according to claim 17, in, The training module is used to: For a triple, when the triple has a corresponding head cache and a tail cache, first randomly select a first negative sample set from the corresponding head cache, and randomly select a second negative sample set from the corresponding tail cache, and then randomly select a preset number of negative samples from the first negative sample set and the second negative sample set as negative samples of the triple to participate in the training of the graph embedding model.
19. The device according to claim 16, in, The device also includes: The indexing module is used to use the unique identifier of each triplet to index the corresponding negative sample cache.
20. The device according to claim 19, in, The index module is used to: Use the address of each triplet to index the corresponding negative sample cache; Alternatively, character strings of the triples in the memory are hashed, and the result of the string hashing is used to index the corresponding negative sample cache; Alternatively, a string hash is performed on the specific physical meaning of each triple, and the result of the string hash is used to index the corresponding negative sample cache.
21. The device according to claim 17, in, The training module is used to: If the negative sample cache corresponding to each triple includes a header cache, for each triple, N2 negative samples whose header entities are inconsistent with the triple are randomly sampled from the negative sample space of the triple, where N2 is a positive integer; Selecting N1 negative samples from the N1 negative samples already in the header buffer of the triplet and the sampled N2 negative samples; Use the selected N1 negative samples to update the header cache of the triplet.
22. The device according to claim 21, in, The training module is used to: If the header cache only stores the header entities of negative samples, randomly select N2 header entities that are inconsistent with the header entity of the triplet; Select N1 header entities from the N1 header entities in the header cache of the triple and the N2 header entities randomly selected; Update the header cache of the triple with the selected N1 header entities.
23. The device according to claim 22, in, The device also includes: The first initialization module is used to randomly select N1 header entities that are inconsistent with the header entity of the triplet for each triplet and put them into the header cache of the triplet to initialize the header cache of the triplet.
24. The device according to claim 21, in, The training module is used to: Using an evaluation function, calculate the scores of the N1+N2 negative samples of the triplet; According to the scores of the N1+N2 negative samples, N1 negative samples are selected from the N1+N2 negative samples.
25. The device according to claim 24, in, The training module is used to: Select the top N1 negative samples with the highest scores from the N1+N2 negative samples; or, For each negative sample in the N1+N2 negative samples, the extraction probability of the negative sample is calculated based on the scores of the N1+N2 negative samples; and N1 negative samples are extracted from the N1+N2 negative samples in sequence according to the extraction probabilities corresponding to each of the N1+N2 negative samples.
26. The device according to claim 17, in, The training module is used to: For each triple, randomly sample M2 negative samples whose tail entities are inconsistent with the triple from the negative sample space of the triple, where M2 is a positive integer; Selecting M1 negative samples from the M1 negative samples already in the tail buffer of the triple and the sampled M2 negative samples; Use the selected M1 negative samples to update the tail cache of the triplet.
27. The device according to claim 26, in, The training module is used to: If only the tail entities of negative samples are stored in the tail cache, M2 tail entities that are inconsistent with the tail entity of the triple are randomly selected; Select M1 tail entities from the M1 tail entities in the tail cache of the triple and the M2 tail entities randomly selected; Update the tail cache of the triple with the selected M1 tail entities.
28. The device according to claim 27, in, The device also includes: The second initialization module is used to randomly select M1 tail entities that are inconsistent with the tail entity of the triplet for each triplet and put them into the tail cache of the triplet to initialize the tail cache of the triplet.
29. The device according to claim 26, in, The training module is used to: Using an evaluation function, calculate the scores of the M1+M2 negative samples of the triplet; According to the scores of the M1+M2 negative samples, M1 negative samples are selected from the M1+M2 negative samples.
30. The device according to claim 29, in, The training module is used to: Select the top M1 negative samples with the highest scores from the M1+M2 negative samples; or, For each negative sample in the M1+M2 negative samples, the extraction probability of the negative sample is calculated based on the scores of the M1+M2 negative samples; and M1 negative samples are extracted from the M1+M2 negative samples in sequence according to the extraction probabilities corresponding to each of the M1+M2 negative samples.
31. A computing device, include: processor; as well as A memory having executable codes stored thereon, which, when executed by the processor, causes the processor to execute the method according to any one of claims 1 to 15.
32. A non-transitory machine-readable storage medium having executable code stored thereon, which, when executed by a processor of an electronic device, causes the processor to execute the method as claimed in any one of claims 1 to 15.
