Negative sample generation method and device based on knowledge graph event element importance
By analyzing the importance levels of triple elements in a knowledge graph, negative samples are generated using random noise injection, relation inversion, and semantic adversarial replacement, and their rationality is verified. This solves the problem of unreasonable negative samples in existing technologies, achieves diverse and reasonable negative sample generation, and improves the performance of the model.
Patent Information
- Application Number
- CN202511422244.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-30
- Publication Date
- 2026-01-13
Smart Images

Figure CN121328680A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data processing, specifically to a method and apparatus for generating negative samples based on the importance of event elements in a knowledge graph. Background Technology
[0002] Knowledge graph negative sample generation has irreplaceable strategic value for improving model reliability and optimizing decision-making quality. In the field of science and technology knowledge graphs, data sparsity is particularly prominent because data in this domain is often scattered across multiple sources, and some data may be incomplete or missing. Although knowledge graph information fusion can integrate information from different data sources and increase relationships between entities, thus alleviating data sparsity to some extent, data source noise, errors, or contextual issues are unavoidable and can still mislead the generation of negative samples in the knowledge graph.
[0003] In addition, information in the scientific and technological field must strictly adhere to disciplinary constraints (e.g., geological disaster prediction requires a safety factor of >1.5 for negative sample areas), but traditional methods (e.g., random sampling in buffer zones) are prone to generating samples that violate domain knowledge (e.g., misselecting potential suitable areas), leading to model bias. Furthermore, the rationality of negative samples lacks quantitative indicators, relies on manual verification, and is difficult to apply on a large scale.
[0004] Current research on negative sample generation methods based on knowledge graphs in the technology field mainly focuses on three major directions: adversarial generation, rule constraints, and multimodal enhancement.
[0005] (1) Adversarial Generation and Hybrid Augmentation: The APT-ST-AN model combines spatiotemporal attribute inference (such as "next" relation chain extended positive examples) with FGSM adversarial negative sampling to generate high-quality hard negative examples, improving MRR by 38.3% in APT attack prediction. 2 IXKG enhances the discriminativeness of entity embeddings by mixing head and tail entities or high-scoring negative samples under the same relation, achieving a more than 10% improvement in Hits@10 in models such as TransE.
[0006] (2) Rule constraints and semantic guidance: Invalid negative triples are filtered based on geospatial topological relationships (such as "nearby" and "containment"), reducing the error rate by 40%2; at the same time, a relationship replacement strategy (such as adjusting the entity / relationship replacement ratio) is introduced to optimize the accuracy of relationship link prediction.
[0007] (3) Multimodal expansion: LightSense Technology generates visual negative samples by erasing / filling the core region of RGBD images, which improves the anti-occlusion ability of autonomous driving models; geometric attribute correction (such as "parallel to non-parallel") only requires 4K samples to optimize the multimodal inference model.
[0008] Ensuring the legitimacy of negative sample generation focuses on handling false negative samples and ensuring compliance with domain logic:
[0009] (1) False Negatives processing: Cascaded LLM relabeling (RLHN) uses GPT-4o to correct 56% of the erroneous negative labels in MSMARCO, improving nDCG@10 by 1.0 points; Adaptive denoising mixing (DeMix) improves training convergence efficiency by pre-classifying false negative samples and synthesizing some positive examples.
[0010] (2) Domain logic compliance: Geological disaster prediction requires a safety factor of >1.5 for negative sample regions, enabling the random forest model to achieve an AUC of 0.909; molecular generation embeds chemical valence constraints to avoid invalid structures. In addition, relation signatures (domain / range constraints) are incorporated into the loss function to differentiate semantically invalid negative samples, significantly improving the semantic correctness of link prediction.
[0011] The main problems with negative sample generation in knowledge graphs in the current technology field are as follows:
[0012] 1. Randomly generated negative samples do not exist in the positive samples, but they are actually true.
[0013] 2. Randomly replacing triples may generate low-quality negative samples, i.e., combinations that cannot exist in reality.
[0014] This patent addresses the aforementioned shortcomings by designing solutions for negative sample classification and negative sample validity verification. It aims to provide a progressively learning negative sample library and a method for eliminating unreasonable negative samples, thereby improving the validity of negative sample generation and its effectiveness. Summary of the Invention
[0015] To address the problems in the prior art, this application provides a method and apparatus for generating negative samples based on the importance of event elements in a knowledge graph, so as to improve the diversity, rationality and effectiveness of negative samples.
[0016] To solve at least one of the above problems, this application provides the following technical solution:
[0017] In a first aspect, this application provides a method for generating negative samples based on the importance of event elements in a knowledge graph, characterized in that the method includes:
[0018] Obtain triple data from the knowledge graph as a positive sample set;
[0019] A positive sample is randomly selected from the set of positive samples. A triplet element is randomly extracted from the selected positive sample and its importance is analyzed. The importance level of the positive sample is defined according to the importance level of the triplet element. The triplet elements in the set of positive samples are divided into multiple importance levels according to their importance. The factors for evaluating the importance of triplet elements include: the degree of the node or the number of times the relation occurs, and the composition of the element.
[0020] Negative samples are generated from positive samples in the positive sample set, and the generation method of negative samples is selected according to the importance level of the positive samples. The generation methods of negative samples include: random noise injection, relation inversion, and semantic adversarial substitution. The reasonableness test is performed on the obtained negative samples: if the result of the reasonableness test is within the set threshold range, it is retained as the target negative sample; otherwise, it is discarded.
[0021] Furthermore, methods for classifying triplet elements in the positive sample set into multiple importance levels based on their importance include:
[0022] Count the frequency of the degree or relation of each node in the positive sample set; classify the nodes into levels based on the frequency of the degree or relation and assign scores to each level;
[0023] The components of triplet elements in the positive sample set are divided into multiple levels and assigned scores respectively; the degree or relation of each node in the triplet appears the same as the level and score of the element's components; the components of the elements include subject, type, influence, association, time, location, and background;
[0024] The final score of the triplet element is obtained by adding the degree or relation frequency of the nodes of the triplet element to the composition score of the element. This score represents the importance of the triplet element.
[0025] The triplet elements in the positive sample set are divided into multiple importance levels according to their final scores.
[0026] Furthermore, the step of selecting the generation method of negative samples based on the importance level of positive samples includes:
[0027] The triplet elements in the positive sample set are divided into three levels, from low to high importance: low level, medium level, and high level, which are the importance levels of the positive samples.
[0028] Low-level positive samples are transformed into negative samples by injecting random noise; medium-level positive samples are transformed into negative samples by reversing the relationship; and high-level positive samples are transformed into negative samples by semantic adversarial substitution.
[0029] Furthermore, the random noise injection includes: selecting a low-level triplet and randomly replacing one element;
[0030] The relation inversion includes: selecting a mid-level triplet, inverting the relation part of the triplet, and generating a new triplet;
[0031] The semantic adversarial replacement includes: selecting a high-level triplet, selecting an element in the triplet as the word to be replaced; masking the word to be replaced; and by predicting the probability of the masked word, selecting a word that is similar to the original word but has a different semantic meaning to replace it, thereby obtaining a new triplet.
[0032] Furthermore, the step of performing a reasonableness check on the generated negative samples includes:
[0033] Check whether the generated negative samples are existing positive samples, and delete the negative samples that are the same as the positive samples;
[0034] Based on the triples of negative samples, the triples in the positive sample set are filtered for similarity, and positive samples with similarity higher than a set threshold are grouped into a high similarity candidate set.
[0035] Calculate the matching degree between positive samples in the high similarity candidate set and the generated negative samples, and retain the negative samples whose matching degree is within the set threshold range.
[0036] Furthermore, the step of filtering triples in the positive sample set based on the similarity of triples from negative samples includes:
[0037] The graph embedding model is used to map triples in the negative and positive sample sets to a high-dimensional space.
[0038] Calculate the distance between the vectors of positive and negative samples;
[0039] Positive samples whose distance from negative samples exceeds a set threshold are filtered out to form a candidate set;
[0040] The step of calculating the matching degree between positive samples in the high similarity candidate set and the generated negative samples includes:
[0041] Positive samples from the high similarity candidate set and the negative samples generated from them are combined into positive-negative sample pairs and input into the pre-trained language model. The pre-trained language model encodes the positive-negative sample pairs and calculates the similarity between the encoded positive-negative sample pairs.
[0042] Set a threshold for the degree of matching, and retain negative samples whose degree of matching falls within the set threshold range.
[0043] Furthermore, the negative sample generation method based on the importance of knowledge graph event elements also includes:
[0044] The target negative samples are divided into a primary negative sample library and an advanced negative sample library, wherein the importance of negative samples in the primary negative sample library is lower than that of negative samples in the advanced negative sample library;
[0045] When training a model using negative samples, first use a primary negative sample library to train the model and obtain a primary model; then use a higher-level negative sample library to train the primary model.
[0046] Secondly, this application provides a negative sample generation device based on the importance of event elements in a knowledge graph, comprising:
[0047] The data acquisition module is used to acquire triple data from the knowledge graph as a positive sample set.
[0048] The sample evaluation module is used to randomly select a positive sample from the positive sample set, randomly extract a triplet element from the selected positive sample and analyze the importance of the element, and define the importance level of the positive sample according to the importance level of the triplet element; the triplet elements in the positive sample set are divided into multiple importance levels according to their importance; the factors for evaluating the importance of triplet elements include: the degree of the node or the number of times the relationship occurs, and the composition of the element;
[0049] The sample transformation module is used to generate negative samples from positive samples in the positive sample set, and selects the generation method of negative samples according to the importance level of the positive samples. The generation methods of negative samples include: random noise injection, relation inversion, and semantic adversarial replacement. The module performs a reasonableness test on the obtained negative samples: if the result of the reasonableness test is within the set threshold range, it is retained as the target negative sample; otherwise, it is discarded.
[0050] Thirdly, this application provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the steps of the negative sample generation method based on the importance of knowledge graph event elements.
[0051] Fourthly, this application provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the negative sample generation method based on the importance of knowledge graph event elements.
[0052] Fifthly, this application provides a computer program product, including a computer program / instructions that, when executed by a processor, implement the steps of the negative sample generation method based on the importance of knowledge graph event elements.
[0053] As described above, this application provides a method and apparatus for generating negative samples based on the importance of event elements in a knowledge graph. First, positive samples are randomly selected. Then, a triplet element is randomly extracted from the selected positive samples, and its importance is analyzed. The importance level of the positive sample is defined based on the importance level of the triplet element. Then, different negative sample generation methods are selected according to different importance levels to generate negative samples from positive samples. Finally, the rationality of the generated negative samples is verified. If rational, they are retained; otherwise, they are discarded. This process is repeated until all negative samples are generated. This method calculates the importance of samples based on the triplet element importance analysis method, generates negative samples through different methods, and then verifies the reliability of the generated negative samples. This approach can generate diverse negative samples while ensuring their rationality. Attached Figure Description
[0054] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0055] Figure 1 This is one of the flowcharts illustrating the negative sample generation method based on the importance of event elements in the knowledge graph in this application embodiment;
[0056] Figure 2 This is the second flowchart illustrating the negative sample generation method based on the importance of event elements in the knowledge graph in this application embodiment;
[0057] Figure 3 This is the third flowchart illustrating the negative sample generation method based on the importance of event elements in knowledge graphs in this application embodiment;
[0058] Figure 4 This is the fourth flowchart illustrating the negative sample generation method based on the importance of event elements in the knowledge graph in this application embodiment;
[0059] Figure 5 This is a structural diagram of the negative sample generation device based on the importance of event elements in the knowledge graph in the embodiments of this application;
[0060] Figure 6 This is a schematic diagram of the structure of the electronic device in the embodiments of this application.
[0061] Figure label:
[0062] Electronic device 9600, central processing unit 9100, memory 9140, communication module 9110, input unit 9120, audio processor 9130, display 9160, power supply 9170, buffer memory 9141, application / function storage unit 9142, data storage unit 9143, driver storage unit 9144, antenna 9111, speaker 9131, microphone 9132. Detailed Implementation
[0063] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0064] The acquisition, storage, use, and processing of data in this application all comply with the relevant provisions of national laws and regulations.
[0065] Terminology Explanation:
[0066] Knowledge graph: A knowledge graph is a structured way of representing knowledge, which uses the form of a graph (nodes and edges) to describe entities (such as people, places, events) and their relationships in the real world.
[0067] Negative sample generation: In machine learning, negative samples are samples that do not meet the target conditions (such as incorrect answers). Negative sample generation involves intentionally constructing such samples to help the model better distinguish between positive and negative patterns.
[0068] Reasonableness test: The process of verifying whether a result or hypothesis conforms to common sense or logical rules, ensuring that it is reasonable and credible.
[0069] Data sparsity: The lack of sufficient data to support the relationships between some entities can lead to a decrease in the accuracy of applications such as recommendation and search.
[0070] To address the problems in existing technologies, this application provides a method and apparatus for generating negative samples based on the importance of event elements in a knowledge graph. First, positive samples are randomly selected, and the importance of the sample elements is analyzed based on the triplet elements of the positive samples. Second, a negative sample generation method is selected according to different importance levels. Finally, the rationality of the generated negative samples is verified. If rational, they are retained; otherwise, they are discarded. The above process is repeated until all negative samples are generated. This method calculates the importance of samples based on the triplet element importance analysis method, generates negative samples through different methods, and then verifies the reliability of the generated negative samples. This approach can generate diverse negative samples while ensuring their rationality.
[0071] To improve the diversity, rationality, and effectiveness of negative samples, this application provides an embodiment of a negative sample generation method based on the importance of event elements in a knowledge graph. See [link to embodiment]. Figure 1 and Figure 2 The negative sample generation method based on the importance of event elements in a knowledge graph specifically includes the following:
[0072] Step S101: Obtain the triple data of the knowledge graph as a positive sample set.
[0073] In this embodiment, a knowledge graph is a structured graphical data representation used to represent entities and the relationships between them. Its basic unit is a triple. A triple consists of three elements, typically represented as (entity 1, relation, entity 2), also known as the head entity, relation, or tail entity. Nodes in a knowledge graph usually represent entities, while edges represent the relationships between entities. These nodes and edges form directed or undirected graphs to represent various complex relationships in the real world. Knowledge graphs are usually stored in some form of database, such as a graph database. In this embodiment, triples can be randomly selected from the database as positive samples.
[0074] Step S102: Randomly select a positive sample from the positive sample set, randomly extract a triplet element from the selected positive sample, and define the importance level of the positive sample according to the importance level of the triplet element; the triplet elements in the positive sample set are divided into multiple importance levels according to their importance; the factors for evaluating the importance of triplet elements include: the degree of the node or the number of times the relation occurs, and the composition of the element.
[0075] Optionally, in this embodiment, the negative sample generation process is as follows: First, randomly select any element of the positive sample (triple) to analyze its importance; then, select the generation method for the negative sample according to its importance. High-level samples use semantic adversarial substitution to replace words in the short sentence to generate negative samples. Medium-level samples use relation inversion to construct negative samples. Low-level samples randomly replace the elements of the triple.
[0076] Optionally, in this embodiment, the method for classifying triplet elements in the positive sample set into multiple importance levels based on their importance includes: counting the number of times the degree or relation of each node in the positive sample set appears; classifying the triplet elements into levels based on the number of times the degree or relation of each node appears and assigning scores to each level; classifying the components of the triplet elements in the positive sample set into multiple levels and assigning scores to each level; the number of times the degree or relation of each node in the triplet appears is the same as the level type and score value of the component of the element; the components of the element include subject, type, influence, association, time, location, and background; adding the level score of the number of times the degree or relation of the node of the triplet element appears to the level score of the component of the element to obtain the final score of the triplet element, which is the importance level of the triplet element; and classifying the triplet elements in the positive sample set into multiple importance levels according to the final score.
[0077] For example, the element importance analysis process in the generation phase is as follows: Figure 3 As shown. First, the importance of any element in the positive sample is calculated using two different methods to obtain scores for level 1 and level 2 respectively; then the sum of the two scores is calculated as the total importance score; finally, the importance of the sample is classified according to the total score. Among them, the two methods of calculating importance are: (1) Count the number of times the degree / relationship of each node in the knowledge graph formed by the positive sample appears, and divide the nodes and relationships into four levels according to the number of times the degree / relationship appears (the more times it appears, the higher the level, and the higher the score (1-4)), forming level library 1. Query the score of the randomly selected element in level library 1, and this score is the score of level 1. (2) Judge the element composition of the randomly selected element, and assign a score according to the composition (background: 1; time, place: 2; influence, association: 3; subject, type: 4.), which is the score of level 2.
[0078] Random replacement / random noise injection: Select one or more elements to perturb. The perturbation can be done by node perturbation or relationship perturbation.
[0079] Semantic Adversarial Substitution: This patent utilizes BERT's Masked Language Modeling (MLM) feature (BERT Masked LM) for semantic adversarial substitution. It generates adversarial examples by predicting the masked words, resulting in more natural and semantically consistent adversarial examples. The input text to the BERT Masked LM model is in short sentence form. These short sentences are processed by transforming triples based on the relation elements of the positive samples. For example, "head node" is the "relation description" of "tail node".
[0080] For example, the specific method of this semantic adversarial substitution includes: First, transforming the entity or relation part of the triple into a short sentence. For example, the triple (entity, relation, entity 2) can be transformed into "Entity 1 is the relation description of entity 2". Next, selecting one or more words to be replaced and masking them. For example, in the sentence "Entity 1 is the relation description of entity 2", selecting the "relation description" part for masking, becoming "Entity 1 is [MASK] of entity 2". Then, the sentence with [MASK] is input into the BERT model. The BERT model predicts the masked word using contextual information (i.e., other words in the sentence). BERT outputs a probability distribution representing the predicted probability of each possible word at the masked position. Typically, the word with the highest probability is selected as the replacement word. For example, if the position of "[MASK]" is most likely "causal relationship", then BERT predicts "causal relationship" and replaces it back. After BERT's prediction, the replaced sentence is obtained, such as "Entity 1 is the causal relationship of entity 2". This sentence becomes a new negative sample, which is semantically similar to the original sample but structurally or semantically different, thus generating an effective adversarial negative sample.
[0081] Relation Inversion: This method reverses the direction of the relation in the original triples to generate new triples. For example, if the original relation is "located in", the inverted relation might be "contains". This method can generate high-quality, hard-to-distinguish adversarial negative samples, improving the model's robustness, generalization ability, and inference accuracy.
[0082] In this embodiment, triples of different levels represent entities and relationships of varying importance. For example, high-level triples may contain core, highly influential relationships or entities, while low-level triples may contain peripheral, less influential elements. This embodiment designs a method for calculating sample importance, classifying samples into different importance levels. By employing different negative sample generation methods for triples of different levels, negative samples with different characteristics can be generated, which helps increase the diversity of negative samples and thus improves the robustness and generalization ability of the model.
[0083] Step S103: Use positive samples from the positive sample set to generate negative samples, and select the generation method of negative samples according to the importance level of the positive samples. The generation methods of negative samples include: random noise injection, relation inversion, and semantic adversarial replacement; perform a rationality test on the generated negative samples: if the result of the rationality test is within the set threshold range, then retain it as the target negative sample, otherwise discard it.
[0084] Optionally, in this embodiment, after generating negative samples during the generation phase, the validation phase performs a rationality verification on the negative samples. The rationality verification is as follows: Figure 4As shown. The verification mainly consists of two steps: 1. Preliminary verification: whether it is an existing positive sample; 2. Subsequent verification: semantic rationality verification. "Whether it is an existing positive sample" only requires determining whether the generated negative sample exists in the positive sample set. The semantic rationality verification first performs a preliminary screening of the samples in the positive sample library based on the triplet of the negative sample, selecting a high-similarity candidate set; then, the large model (Qwen-Max-0919) is used to calculate the matching degree between the samples in the high-similarity candidate set and the generated negative samples, deciding whether to retain them based on the matching degree. For example, the large model uses triplet matching between the positive sample library and the generated negative samples, retaining samples with matching values between 0.2 and 0.8 (too high is considered similar, too low is considered logically unreasonable as it is the opposite of the positive sample). The retained negative samples are divided into a primary negative sample library (low level) and a high-level negative sample library (medium and high levels) according to the previously calculated sample importance, and are stored separately. The above process is repeated until all negative samples are generated.
[0085] Optionally, in this embodiment, the step of filtering the triples in the positive sample set based on the triples of the negative samples includes: using a graph embedding model (such as TransE, DistMult, ComplEx, etc.) to map the triples in the negative and positive sample sets to a high-dimensional space, calculating the distance between the vectors of the positive and negative samples, and then filtering out the positive samples whose distance threshold with the negative samples exceeds a set threshold to form a candidate set.
[0086] Optionally, in this embodiment, the step of calculating the matching degree between positive samples in the high similarity candidate set and the generated negative samples includes: using a large model (such as Qwen-Max-0919), converting the positive samples in the high similarity candidate set and the negative samples generated therefrom into short texts or sentences, then forming positive-negative sample pairs and inputting them into the large model, which encodes the positive-negative sample pairs, converting them into high-dimensional vector representations. This vector representation contains the semantic information of each text. Then, the similarity between the encoded vectors of the positive and negative samples is calculated. Commonly used similarity calculation methods include cosine similarity, Euclidean distance, dot product similarity, etc. Qwen-Max-0919 returns a matching score, representing the matching degree between the generated negative samples and the positive samples. This score is usually a floating value between 0 and 1. The closer the value is to 1, the more similar the two are semantically; the closer the value is to 0, the greater the semantic difference. A threshold for the matching degree is set, and negative samples with matching degrees within the set threshold range are retained.
[0087] In this embodiment, similarity calculation typically focuses on quantifying the degree of similarity between two objects. The main goal is to select candidate positive samples from the positive sample library that have a high semantic similarity to the generated negative samples. Matching degree calculation is used to avoid generating invalid negative samples. For example, when generating negative samples, sometimes the generated samples may only randomly modify a single element of the triplet, but these modifications may not lead to effective semantic differences. This embodiment uses similarity and matching degree comparisons with positive samples to control the quality of the generated negative samples, avoiding excessive similarity or difference between negative and positive samples in certain aspects, ensuring that the negative samples have sufficient diversity for more effective model training.
[0088] Optionally, in this embodiment, during training, the model first undergoes primary learning based on low-level negative samples. After the learning is complete, advanced learning is performed based on the primary model to obtain the final trained model. In this embodiment, low-level negative samples are usually errors that are relatively easy to identify. They may be simple noise data or obvious relational reversals, such as "Zhang San is a driver" becoming "Zhang San is not a driver." The generation process of these negative samples is simple, and their semantic differences with positive samples are usually large. The model can easily learn how to distinguish between correct and incorrect predictions through these samples. After the primary learning stage, the model can effectively identify some simple negative sample errors. Next, more complex and difficult mid-to-high-level negative samples are introduced. These negative samples usually have higher semantic similarity and may only be minor modifications or logical conflicts of positive samples. For example, the negative sample generated by reversing the relation "Zhang San is a driver" becomes "The driver is Zhang San," or a negative sample with a high degree of semantic overlap with the original sample. The design of this negative sample generation can simulate the human learning process during training, that is, first carry out the learning of primary and junior high school, and then carry out the learning of senior high school. It can more reasonably realize the transition of knowledge learning, so that the model can not only perform well on simple negative samples, but also make accurate judgments on complex and subtle negative samples.
[0089] As described above, the negative sample generation method based on the importance of event elements in a knowledge graph provided in this application first randomly selects positive samples, then randomly extracts a triplet element from the selected positive samples and analyzes the importance of that element. The importance level of the positive sample is defined based on the importance level of the triplet element. Then, different negative sample generation methods are selected according to different importance levels to generate negative samples from positive samples. Finally, the rationality of the generated negative samples is verified. If rational, they are retained; otherwise, they are discarded. The above process is repeated until all negative samples are generated. This method calculates the importance of samples based on the triplet element importance analysis method, generates negative samples through different methods, and then verifies the reliability of the generated negative samples. This not only generates diverse negative samples but also ensures the rationality of the negative samples.
[0090] To improve the diversity, rationality, and effectiveness of negative samples, this application provides an embodiment of a negative sample generation apparatus based on the importance of knowledge graph event elements, which implements all or part of the aforementioned negative sample generation method based on the importance of knowledge graph event elements. See [link to embodiment]. Figure 5 The negative sample generation device based on the importance of event elements in a knowledge graph specifically includes the following components:
[0091] Data acquisition module 10 is used to acquire triple data from the knowledge graph as a positive sample set;
[0092] The sample evaluation module 20 is used to randomly select a positive sample from the positive sample set, randomly extract a triplet element from the selected positive sample and analyze the importance of the element, and define the importance level of the positive sample according to the importance level of the triplet element; the triplet elements in the positive sample set are divided into multiple importance levels according to their importance; the factors for evaluating the importance of triplet elements include: the degree of the node or the number of times the relationship occurs, and the composition of the element;
[0093] The sample transformation module 30 is used to generate negative samples from positive samples in the positive sample set, and select the generation method of negative samples according to the importance level of the positive samples. The generation methods of negative samples include: random noise injection, relation inversion, and semantic adversarial replacement. The generated negative samples are subjected to a rationality test: if the result of the rationality test is within the set threshold range, it is retained as the target negative sample; otherwise, it is discarded.
[0094] As described above, the negative sample generation device based on the importance of event elements in a knowledge graph provided in this application first randomly selects positive samples, then randomly extracts a triplet element from the selected positive samples and analyzes the importance of that element. The importance level of the positive sample is defined based on the importance level of the triplet element. Then, different negative sample generation methods are selected according to different importance levels to generate negative samples from positive samples. Finally, the rationality of the generated negative samples is verified. If rational, they are retained; otherwise, they are discarded. The above process is repeated until all negative samples are generated. This method calculates the importance of samples based on the triplet element importance analysis method, generates negative samples through different methods, and then verifies the reliability of the generated negative samples. This not only generates diverse negative samples but also ensures the rationality of the negative samples.
[0095] From a hardware perspective, in order to improve the diversity, rationality, and effectiveness of negative samples, this application provides an embodiment of an electronic device for implementing all or part of the negative sample generation method based on the importance of knowledge graph event elements. The electronic device specifically includes the following components:
[0096] The system comprises a processor, memory, a communications interface, and a bus; wherein the processor, memory, and communications interface communicate with each other via the bus; the communications interface is used to realize information transmission between the negative sample generation device based on the importance of knowledge graph event elements and core business systems, user terminals, and related databases and other related devices; the logic controller can be a desktop computer, tablet computer, or mobile terminal, etc., and this embodiment is not limited to these. In this embodiment, the logic controller can be implemented with reference to the embodiments of the negative sample generation method based on the importance of knowledge graph event elements and the embodiments of the negative sample generation device based on the importance of knowledge graph event elements in the embodiments, the contents of which are incorporated herein, and repeated details will not be described again.
[0097] It is understood that the user terminal may include smartphones, tablet computers, network set-top boxes, portable computers, desktop computers, personal digital assistants (PDAs), in-vehicle devices, smart wearable devices, etc. Among these, the smart wearable devices may include smart glasses, smartwatches, smart bracelets, etc.
[0098] In practical applications, the negative sample generation method based on the importance of knowledge graph event elements can be partially executed on the electronic device side as described above, or all operations can be completed on the client device. The choice can be made based on the processing power of the client device and the limitations of the user's usage scenario. This application does not impose any limitations on this. If all operations are completed on the client device, the client device may further include a processor.
[0099] The aforementioned client device may have a communication module (i.e., a communication unit) that can communicate with a remote server to achieve data transmission. The server may include a server on the task scheduling center side; in other implementation scenarios, it may also include a server on an intermediate platform, such as a server on a third-party server platform that has a communication link with the task scheduling center server. The server may include a single computer device, a server cluster consisting of multiple servers, or a distributed server structure.
[0100] Figure 6 This is a schematic block diagram illustrating the system configuration of the electronic device 9600 according to an embodiment of this application. Figure 6 As shown, the electronic device 9600 may include a central processing unit 9100 and a memory 9140; the memory 9140 is coupled to the central processing unit 9100. It is worth noting that... Figure 6This is an example; other types of structures can also be used to supplement or replace this structure to achieve telecommunications functions or other functions.
[0101] In one embodiment, the negative sample generation method based on the importance of knowledge graph event elements can be integrated into the central processing unit 9100. The central processing unit 9100 can be configured to perform the following control:
[0102] Step S101: Obtain the triple data of the knowledge graph as a positive sample set;
[0103] Step S102: Randomly select a positive sample from the positive sample set, randomly extract a triplet element from the selected positive sample and analyze the importance of the element, and define the importance level of the positive sample according to the importance level of the triplet element; the triplet elements in the positive sample set are divided into multiple importance levels according to their importance; the factors for evaluating the importance of triplet elements include: the degree of the node or the number of times the relation occurs, and the composition of the element;
[0104] Step S103: Use positive samples from the positive sample set to generate negative samples, and select the generation method of negative samples according to the importance level of the positive samples. The generation methods of negative samples include: random noise injection, relation inversion, and semantic adversarial replacement; perform a rationality test on the generated negative samples: if the result of the rationality test is within the set threshold range, then retain it as the target negative sample, otherwise discard it.
[0105] As described above, the electronic device provided in this application first randomly selects positive samples, then randomly extracts a triplet element from the selected positive samples and analyzes the importance of that element. The importance level of the positive sample is defined based on the importance level of the triplet element. Then, different negative sample generation methods are selected according to different importance levels to generate negative samples from the positive samples. Finally, the rationality of the generated negative samples is verified. If rational, they are retained; otherwise, they are discarded. This process is repeated until all negative samples are generated. This method calculates the importance of the samples based on the triplet element importance analysis method, generates negative samples through different methods, and then verifies the reliability of the generated negative samples. This approach can generate diverse negative samples while ensuring their rationality.
[0106] In another embodiment, the negative sample generation device based on the importance of knowledge graph event elements can be configured separately from the central processing unit 9100. For example, the negative sample generation device based on the importance of knowledge graph event elements can be configured as a chip connected to the central processing unit 9100, and the function of the negative sample generation method based on the importance of knowledge graph event elements can be realized through the control of the central processing unit.
[0107] like Figure 6 As shown, the electronic device 9600 may further include: a communication module 9110, an input unit 9120, an audio processor 9130, a display 9160, and a power supply 9170. It is worth noting that the electronic device 9600 does not necessarily need to include these components. Figure 6 All components shown; in addition, the electronic device 9600 may also include Figure 6 For components not shown, please refer to existing technologies.
[0108] like Figure 6 As shown, the central processing unit 9100, sometimes also referred to as a controller or operating control, may include a microprocessor or other processor device and / or logic device, which receives inputs and controls the operation of various components of the electronic device 9600.
[0109] The memory 9140 may be, for example, one or more of a cache, flash memory, hard drive, removable media, volatile memory, non-volatile memory, or other suitable devices. It may store the aforementioned failure-related information, and also store a program for executing that information. The central processing unit 9100 may execute the program stored in the memory 9140 to perform information storage or processing, etc.
[0110] Input unit 9120 provides input to central processing unit 9100. Input unit 9120 may be, for example, a keypad or touch input device. Power supply 9170 provides power to electronic device 9600. Display 9160 displays images and text. Display may be, for example, an LCD display, but is not limited thereto.
[0111] The memory 9140 can be a solid-state memory, such as a read-only memory (ROM), random access memory (RAM), a SIM card, etc. It can also be a memory that retains information even when power is off, can be selectively erased, and contains more data; examples of this type of memory are sometimes referred to as EPROMs. The memory 9140 can also be some other type of device. The memory 9140 includes a buffer memory 9141 (sometimes referred to as a buffer). The memory 9140 may include an application / function storage unit 9142 for storing application programs and function programs or processes for executing the operation of the electronic device 9600 via the central processing unit 9100.
[0112] The memory 9140 may also include a data storage unit 9143 for storing data, such as contacts, digital data, pictures, sounds, and / or any other data used by the electronic device. The driver storage unit 9144 of the memory 9140 may include various drivers for the electronic device's communication functions and / or for performing other functions of the electronic device (such as messaging applications, address book applications, etc.).
[0113] The communication module 9110 is a transmitter / receiver that sends and receives signals via the antenna 9111. The communication module 9110 (transmitter / receiver) is coupled to the central processing unit 9100 to provide input signals and receive output signals, which is the same as in a conventional mobile communication terminal.
[0114] Based on different communication technologies, multiple communication modules 9110 can be configured in the same electronic device, such as cellular network modules, Bluetooth modules, and / or wireless LAN modules. The communication module 9110 (transmitter / receiver) is also coupled to a speaker 9131 and a microphone 9132 via an audio processor 9130 to provide audio output via the speaker 9131 and receive audio input from the microphone 9132, thereby realizing typical telecommunications functions. The audio processor 9130 may include any suitable buffer, decoder, amplifier, etc. Additionally, the audio processor 9130 is coupled to a central processing unit 9100, enabling on-device recording via the microphone 9132 and on-device playback of stored audio via the speaker 9131.
[0115] Embodiments of this application also provide a computer-readable storage medium capable of implementing all steps of the negative sample generation method based on the importance of knowledge graph event elements, where the execution subject is a server or client, as described in the above embodiments. The computer-readable storage medium stores a computer program that, when executed by a processor, implements all steps of the negative sample generation method based on the importance of knowledge graph event elements, where the execution subject is a server or client, as described in the above embodiments. For example, when the processor executes the computer program, it implements the following steps:
[0116] Step S101: Obtain the triple data of the knowledge graph as a positive sample set;
[0117] Step S102: Randomly select a positive sample from the positive sample set, randomly extract a triplet element from the selected positive sample and analyze the importance of the element, and define the importance level of the positive sample according to the importance level of the triplet element; the triplet elements in the positive sample set are divided into multiple importance levels according to their importance; the factors for evaluating the importance of triplet elements include: the degree of the node or the number of times the relation occurs, and the composition of the element;
[0118] Step S103: Use positive samples from the positive sample set to generate negative samples, and select the generation method of negative samples according to the importance level of the positive samples. The generation methods of negative samples include: random noise injection, relation inversion, and semantic adversarial replacement; perform a rationality test on the generated negative samples: if the result of the rationality test is within the set threshold range, then retain it as the target negative sample, otherwise discard it.
[0119] As described above, the computer-readable storage medium provided in this application first randomly selects positive samples, then randomly extracts a triplet element from the selected positive samples and analyzes the importance of that element. The importance level of the positive sample is defined based on the importance level of the triplet element. Then, different negative sample generation methods are selected according to different importance levels to generate negative samples from positive samples. Finally, the rationality of the generated negative samples is verified. If rational, they are retained; otherwise, they are discarded. This process is repeated until all negative samples are generated. This method calculates the importance of samples based on the triplet element importance analysis method, generates negative samples through different methods, and then verifies the reliability of the generated negative samples. This approach can generate diverse negative samples while ensuring their rationality.
[0120] Embodiments of this application also provide a computer program product capable of implementing all steps in the negative sample generation method based on the importance of knowledge graph event elements, where the execution subject is a server or client, as described in the above embodiments. When executed by a processor, this computer program / instruction implements the steps of the negative sample generation method based on the importance of knowledge graph event elements. For example, the computer program / instruction implements the following steps:
[0121] Step S101: Obtain the triple data of the knowledge graph as a positive sample set;
[0122] Step S102: Randomly select a positive sample from the positive sample set, randomly extract a triplet element from the selected positive sample and analyze the importance of the element, and define the importance level of the positive sample according to the importance level of the triplet element; the triplet elements in the positive sample set are divided into multiple importance levels according to their importance; the factors for evaluating the importance of triplet elements include: the degree of the node or the number of times the relation occurs, and the composition of the element;
[0123] Step S103: Use positive samples from the positive sample set to generate negative samples, and select the generation method of negative samples according to the importance level of the positive samples. The generation methods of negative samples include: random noise injection, relation inversion, and semantic adversarial replacement; perform a rationality test on the generated negative samples: if the result of the rationality test is within the set threshold range, then retain it as the target negative sample, otherwise discard it.
[0124] As described above, the computer program product provided in this application first randomly selects positive samples, then randomly extracts a triplet element from the selected positive samples and analyzes the importance of that element. Based on the importance level of the triplet element, the importance level of the positive sample is defined. Then, different negative sample generation methods are selected according to different importance levels to generate negative samples from positive samples. Finally, the rationality of the generated negative samples is verified. If rational, they are retained; otherwise, they are discarded. The above process is repeated until all negative samples are generated. This method calculates the importance of samples based on the triplet element importance analysis method, generates negative samples through different methods, and then verifies the reliability of the generated negative samples. This not only generates diverse negative samples but also ensures the rationality of the negative samples.
[0125] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, apparatus, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0126] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (devices), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0127] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0128] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0129] Specific embodiments have been used to illustrate the principles and implementation methods of this invention. The descriptions of the embodiments above are only for the purpose of helping to understand the method and core ideas of this invention. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this invention. Therefore, the content of this specification should not be construed as a limitation of this invention.
Claims
1. A method for generating negative samples based on the importance of event elements in a knowledge graph, characterized in that, The method includes: Obtain triple data from the knowledge graph as a positive sample set; A positive sample is randomly selected from the set of positive samples. A triplet element is randomly extracted from the selected positive sample and its importance is analyzed. The importance level of the positive sample is defined according to the importance level of the triplet element. The triplet elements in the set of positive samples are divided into multiple importance levels according to their importance. The factors for evaluating the importance of triplet elements include: the degree of the node or the number of times the relation occurs, and the composition of the element. Negative samples are generated from positive samples in the positive sample set, and the generation method of negative samples is selected according to the importance level of the positive samples. The generation methods of negative samples include: random noise injection, relation inversion, and semantic adversarial substitution. The generated negative samples are subjected to a rationality test: if the result of the rationality test is within the set threshold range, it is retained as the target negative sample; otherwise, it is discarded.
2. The negative sample generation method based on the importance of event elements in a knowledge graph according to claim 1, characterized in that, Methods for classifying triplet elements in a positive sample set into multiple importance levels based on their importance include: Count the frequency of occurrence of the degree or relation of each node in the positive sample set; classify the nodes into levels based on the frequency of occurrence of the degree or relation and assign scores to each level; The components of the triplet elements in the positive sample set are divided into multiple levels and assigned scores respectively; the degree or relation of each node in the triplet appears the same as the level and score of the component; the components of the element include subject, type, influence, association, time, location, and background. The final score of the triplet element is obtained by adding the degree or relation frequency of the nodes of the triplet element to the composition score of the element. This score represents the importance of the triplet element. The triplet elements in the positive sample set are divided into multiple importance levels according to their final scores.
3. The negative sample generation method based on the importance of event elements in a knowledge graph according to claim 1, characterized in that, The step of selecting the generation method of negative samples based on the importance level of positive samples includes: The triplet elements in the positive sample set are divided into three levels, from low to high importance: low level, medium level, and high level, which are the importance levels of the positive samples. Low-level positive samples are transformed into negative samples by injecting random noise; medium-level positive samples are transformed into negative samples by reversing the relationship; and high-level positive samples are transformed into negative samples by semantic adversarial substitution.
4. The negative sample generation method based on the importance of event elements in a knowledge graph according to claim 3, characterized in that: The random noise injection includes: selecting a low-level triplet and randomly replacing one element; The relation inversion includes: selecting a mid-level triplet, inverting the relation part of the triplet, and generating a new triplet; The semantic adversarial replacement includes: selecting a high-level triplet, selecting an element in the triplet as the word to be replaced; masking the word to be replaced; and by predicting the probability of the masked word, selecting a word that is similar to the original word but has a different semantic meaning to replace it, thereby obtaining a new triplet.
5. The negative sample generation method based on the importance of event elements in a knowledge graph according to claim 1, characterized in that, The step of performing a reasonableness check on the generated negative samples includes: Check whether the generated negative samples are existing positive samples, and delete the negative samples that are the same as the positive samples; Based on the triples of negative samples, the triples in the positive sample set are filtered for similarity, and positive samples with similarity higher than a set threshold are grouped into a high similarity candidate set. Calculate the matching degree between positive samples in the high similarity candidate set and the generated negative samples, and retain the negative samples whose matching degree is within the set threshold range.
6. The negative sample generation method based on the importance of event elements in a knowledge graph according to claim 5, characterized in that: The step of filtering triples in the positive sample set based on the similarity of triples in the negative sample set includes: The graph embedding model is used to map triples in the negative and positive sample sets to a high-dimensional space. Calculate the distance between the vectors of positive and negative samples; Positive samples whose distance from negative samples exceeds a set threshold are filtered out to form a candidate set; The step of calculating the matching degree between positive samples in the high similarity candidate set and the generated negative samples includes: Positive samples from the high similarity candidate set and the negative samples generated from them are combined into positive-negative sample pairs and input into the pre-trained language model. The pre-trained language model encodes the positive-negative sample pairs and calculates the similarity between the encoded positive-negative sample pairs. Set a threshold for the degree of matching, and retain negative samples whose degree of matching falls within the set threshold range.
7. The negative sample generation method based on the importance of event elements in a knowledge graph according to claim 1, characterized in that, Also includes: The target negative samples are divided into a primary negative sample library and an advanced negative sample library, wherein the importance of negative samples in the primary negative sample library is lower than that of negative samples in the advanced negative sample library; When training a model using negative samples, first use a primary negative sample library to train the model and obtain a primary model; then use a higher-level negative sample library to train the primary model.
8. A negative sample generation device based on the importance of event elements in a knowledge graph, characterized in that, The device includes: The data acquisition module is used to acquire triple data from the knowledge graph as a positive sample set. The sample evaluation module is used to randomly select a positive sample from the positive sample set, randomly extract a triplet element from the selected positive sample and analyze the importance of the element, and define the importance level of the positive sample according to the importance level of the triplet element; the triplet elements in the positive sample set are divided into multiple importance levels according to their importance; the factors for evaluating the importance of triplet elements include: the degree of the node or the number of times the relationship occurs, and the composition of the element; The sample transformation module is used to generate negative samples from positive samples in the positive sample set, and selects the generation method of negative samples according to the importance level of the positive samples. The generation methods of negative samples include: random noise injection, relation inversion, and semantic adversarial replacement. The module performs a reasonableness test on the obtained negative samples: if the result of the reasonableness test is within the set threshold range, it is retained as the target negative sample; otherwise, it is discarded.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the steps of the negative sample generation method based on the importance of event elements in a knowledge graph as described in any one of claims 1 to 7.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When executed by a processor, the computer program implements the steps of the negative sample generation method based on the importance of knowledge graph event elements as described in any one of claims 1 to 7.
Citation Information
Patent Citations
Knowledge representation learning method and device
CN113204652A
Sample sampling method and device for production failure analysis and storage medium
CN115034527A
Hierarchical knowledge graph embedding framework method for link prediction
CN118469000A
System for extracting semantic triples for building a knowledge base
US10482384B1
Device, a computer program and a computer-implemented method for determining negative samples for training a knowledge graph embedding of a knowledge graph
US20230025314A1