Knowledge graph completion method based on difficult few negative samples and gnn weighted neighbor aggregation

By combining difficult, low-negative-sample aggregation with GNN-weighted neighbor aggregation, the problems of negative sample generation and neighbor information weighting in knowledge graph completion are solved, improving the prediction accuracy and stability of the model, reducing computational costs, and making it suitable for large-scale knowledge graphs.

CN122242667APending Publication Date: 2026-06-19SUZHOU UNIV

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
SUZHOU UNIV
Filing Date
2026-03-23
Publication Date
2026-06-19

AI Technical Summary

Technical Problem

Existing knowledge graph completion methods are insufficient in negative sample generation and neighbor information weighting, resulting in poor model performance on complex relationships and long-tail entities, and also incurring high computational costs.

Method used

We adopt a method based on difficult negative samples and GNN weighted neighbor aggregation. By obtaining the semantic representation of the entity, calculating the similarity of the neighbors and weighting the aggregation, we select difficult negative samples for comparative learning, optimize the model parameters, and improve the utilization of neighbor information and the model's discrimination ability.

Benefits of technology

It significantly improves the prediction accuracy and Top-K ranking quality of knowledge graph completion, enhances the robustness and stability of the model, reduces training computation costs, and is suitable for large-scale knowledge graphs and resource-constrained environments.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122242667A_ABST
    Figure CN122242667A_ABST
Patent Text Reader

Abstract

This invention discloses a knowledge graph completion method based on difficult few negative samples and GNN weighted neighbor aggregation, comprising the following steps: acquiring entities and their textual information in the knowledge graph, and generating semantic representations of entities through a text encoder; for each entity, acquiring its set of neighboring entities, and calculating the similarity between the central entity and each neighboring entity based on the semantic representation, mapping the similarity to aggregation weights; based on a graph neural network, using the aggregation weights to weighted aggregate the information of neighboring entities to generate a structurally enhanced representation of the entity; constructing a candidate negative sample set for each positive sample triple, and selecting a small number of negative samples that are semantically difficult to distinguish from the positive samples as difficult negative samples; constructing a contrastive learning objective based on the positive samples and difficult negative samples, training the model to bring the model closer to the positive samples and further away from the difficult negative samples in the representation space; using the trained model to perform completion prediction for missing triples; this invention significantly improves the performance of knowledge graph completion.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of knowledge graph technology, specifically to a knowledge graph completion method based on difficult few negative samples and GNN weighted neighbor aggregation. Background Technology

[0002] Knowledge graphs, as structured semantic networks, have been widely applied in fields such as search engines, recommendation systems, intelligent question answering, financial risk control, and medical diagnosis. By representing entities and their relationships, knowledge graphs provide a foundation for machines to understand and process complex information. However, despite the enormous application potential of knowledge graphs, constructing high-quality, large-scale knowledge graphs still faces many challenges. Currently, the construction of knowledge graphs often encounters problems such as difficulties in knowledge acquisition, unstable data quality, and insufficient representation of long-tail entities, resulting in existing graphs generally suffering from incomplete information and inaccurate relational reasoning.

[0003] Knowledge graph completion (KGC) technology aims to automatically predict and fill in missing relationships in a knowledge graph, thereby improving its completeness and usability. Among existing knowledge graph completion methods, some contrastive learning-based models have improved performance to some extent by constructing positive and negative sample pairs to optimize the model's discriminative ability. These methods enhance the accuracy of graph completion by learning the similarity and differences between positive and negative samples. However, these methods typically employ a random sampling strategy for generating negative samples, resulting in relatively simple generated negative samples that are difficult to provide sufficient training signals for the model, especially in handling long-tail entities and complex semantic relationships, where their effectiveness is limited.

[0004] Overall, existing knowledge graph completion methods have the following problems in terms of negative sample generation and neighbor information weighting: (1) the random negative sample generation strategy fails to pay attention to difficult negative samples, resulting in insufficient challenge during model training and affecting the model's performance on complex relationships and long-tail entities; (2) the neighbor node aggregation lacks a weighting mechanism and fails to dynamically adjust according to the similarity between nodes, making it difficult for the model to capture fine-grained relationship information. Therefore, there is still much room for improvement in the robustness and accuracy of existing methods in knowledge graph completion tasks. Summary of the Invention

[0005] Purpose of the invention: The purpose of this invention is to provide a knowledge graph completion method based on difficult few negative samples and GNN weighted neighbor aggregation, which solves the problems of existing knowledge graph completion methods, such as the general reliance on a large number of random negative samples for contrastive learning training, insufficient effectiveness of negative samples and large computational cost; and the lack of differentiated weight allocation for graph structure neighbor information during aggregation, making it difficult to highlight neighbors that are more relevant to the target entity.

[0006] Technical solution: The knowledge graph completion method based on difficult few negative samples and GNN weighted neighbor aggregation described in this invention includes the following steps:

[0007] (1) Obtain entities and their text information from the knowledge graph, and generate semantic representations of the entities through a text encoder;

[0008] (2) For each entity, obtain its set of neighboring entities, and calculate the similarity between the central entity and each neighboring entity based on semantic representation, and map the similarity into aggregation weight;

[0009] (3) Based on graph neural networks, aggregate weights are used to weight and aggregate the information of neighboring entities to generate an enhanced structural representation of the entities;

[0010] (4) Construct a set of candidate negative samples for each positive sample triplet, and select a small number of negative samples that are semantically indistinguishable from the positive samples as difficult negative samples;

[0011] (5) Construct a contrastive learning objective based on positive samples and difficult negative samples, and train the model so that the model can bring positive samples closer and move difficult negative samples further away in the representation space;

[0012] (6) Use the trained model to complete and predict missing triples.

[0013] Furthermore, in step (2), the similarity is mapped to the aggregation weight as follows: the neighboring entities are weighted based on semantic similarity, so that the neighbors that are semantically similar to the central entity receive higher aggregation weights, and the neighbors that are semantically unrelated receive lower weights, thereby improving the discriminativeness of the structural representation.

[0014] Furthermore, in step (4), the specific process of screening difficult negative samples is as follows: Select samples from the candidate negative samples that have similar scores or are ranked higher than the positive samples under the current model to form a small but challenging set of negative samples to replace a large number of random negative samples in training.

[0015] Furthermore, in step (5), the contrast learning objective adopts a loss function based on the similarity of positive and negative samples. By optimizing this objective, the model can simultaneously improve its ability to discriminate relationships between entities in both the semantic space and the structural space.

[0016] Furthermore, in step (5), the contrastive learning training employs a phased parameter update strategy: In the first phase, with the graph neural network parameters fixed, only the text encoder parameters are updated to establish a stable entity semantic representation foundation; in the second phase, based on the semantic representation, the parameters of the text encoder and the graph neural network are jointly updated, enabling the structure-enhanced representation to further learn discriminative features on a stable semantic foundation.

[0017] Furthermore, the graph neural network employs a multi-head attention mechanism for weighted aggregation of neighboring entities: each attention head independently calculates the attention weights between the central entity and neighboring entities, and performs a weighted summation of the neighboring entity information based on the attention weights to obtain the aggregation result of that head; the aggregation results of multiple attention heads are concatenated or fused to generate the final structure-enhanced representation; through the multi-head attention mechanism, the model can capture the diverse semantic contributions of neighboring entities from different representation subspaces.

[0018] Further, step (6) is as follows: based on the entity representation obtained from training, the candidate entities are scored and ranked according to similarity, and the best prediction result or Top-K candidate list is output.

[0019] The knowledge graph completion method system based on difficult few negative samples and GNN weighted neighbor aggregation described in this invention includes:

[0020] Text encoding module: used to encode the text information of entities into semantic vectors;

[0021] Neighbor weighted aggregation module: used to weight and aggregate neighbor entities based on semantic similarity to generate structure-enhanced representations;

[0022] Difficult Negative Sample Generation Module: Used to filter out a small number of negative samples that are difficult to distinguish from positive samples from the candidate negative samples;

[0023] The contrastive learning training module is used to construct contrastive learning objectives based on positive samples and difficult negative samples, and to optimize model parameters.

[0024] The completion inference module is used to predict and output missing triples based on the optimized model.

[0025] An electronic device according to the present invention includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program, when loaded onto the processor, implements any of the methods described herein.

[0026] The present invention provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements any of the methods described herein.

[0027] Beneficial Effects: Compared with existing technologies, this invention has the following significant advantages: It significantly improves the prediction accuracy and Top-K ranking quality of knowledge graph completion. In the representation learning process of knowledge graph completion, this invention introduces a similarity-based weighted aggregation mechanism for entity neighborhood information. This gives higher weight to neighboring nodes that are semantically closer to the central entity and contribute more to the current relationship reasoning, while reducing the contribution of weakly related or noisy neighbors, thus constructing a more discriminative entity representation. Due to the improved discriminativeness of the entity representation, the model can more accurately distinguish between real tail / head entities and a large number of approximate candidate entities when predicting links. The score ranking of candidate entities better fits the constraints of real relationships, thereby improving the overall completion accuracy, candidate ranking consistency, and the reliability of the reasoning results.

[0028] Improving the "high-quality utilization" of neighbor information, suppressing noise propagation, and enhancing robustness: Existing technologies in GNN neighbor aggregation often employ uniform aggregation or attention allocation based solely on structure. This can easily treat low-relevance, faultyly connected, and weakly evidenced neighbors equally with high-relevance neighbors, leading to the injection of invalid information into entity representations and its spread through multi-layer message passing. This results in the accumulation of structural noise, representational bias, and even inference errors. This invention generates aggregation weights through semantic similarity evaluation, making the overall neighbor information entering the aggregation stage "higher quality." On the one hand, it emphasizes the evidentiary contribution of high-relevance neighbors; on the other hand, it effectively suppresses the interference of weakly relevant neighbors, reducing the amplification effect of noise during propagation. This allows the model to maintain strong stability and robustness even under conditions of sparse graphs, uneven neighborhood quality, and complex relationship patterns, reducing performance fluctuations caused by neighborhood noise.

[0029] Enhancing the ability to distinguish difficult candidate entities and improving performance in long-tail entity and complex relationship scenarios: Many erroneous predictions in knowledge graph completion stem from high similarity or semantic similarity between candidate entities. Especially in long-tail entity, fine-grained relationship, and ambiguous entity scenarios, random negative samples are often too "easy," failing to force the model to learn effective discrimination boundaries. This invention introduces a contrastive learning mechanism using a small number of difficult negative samples. More challenging samples are selected from the candidate negative samples for optimization, allowing the model training process to focus more on "difficult example discrimination." By widening the gap between positive and negative samples in the representation space through contrastive learning, the ability to characterize fine-grained differences is improved, resulting in stronger discrimination and generalization capabilities in semantically similar entities, complex relationship inference, and long-tail scenarios.

[0030] While reducing the size of negative samples, this invention maintains or improves performance, significantly reducing training computation costs and resource consumption. Existing contrastive learning-based KGC methods typically rely on a large number of negative samples to maintain training signal strength, resulting in high computational frequency of negative sample scores for each positive sample, high training overhead, and high GPU and computing resource consumption. This invention uses a difficult negative sample selection mechanism to replace a large number of random negative samples with a small number of effective negative samples. This reduces invalid computation while maintaining training signal strength, significantly lowering the costs of similarity calculation, score calculation, and gradient update during the training phase. This reduces training time and peak GPU / RAM usage, thereby improving training efficiency and engineering deployability, making it particularly suitable for training and iteration in large-scale knowledge graphs or resource-constrained environments.

[0031] Improving the stability of representation learning and reducing the risk of performance degradation caused by oversmoothing and erroneous aggregation: In GNN-like methods, if neighbor information is repeatedly propagated and aggregated without differentiation, oversmoothing or erroneous information can easily occur, causing different entity representations to converge or be dragged down by noise, leading to performance degradation. This invention suppresses the influence of low-relevance neighbors through similarity weighting, making message passing more focused on credible neighbor evidence, reducing the dominant role of erroneous neighborhood information in representation learning, mitigating the risk of training instability and performance degradation caused by noise propagation and over-aggregation, making the model easier to converge and maintaining relatively stable performance output across different training epochs.

[0032] This invention achieves synergistic enhancement of structural and semantic information, improving the interpretability and consistency of representations. It explicitly introduces semantic similarity factors into the neighbor aggregation weights, enabling the structural aggregation process to no longer rely solely on graph connectivity but rather reflect the consistency principle of "semantic relevance—structural support." The weighting mechanism explains why some neighbors contribute more to prediction (higher similarity, greater weight), thereby improving the interpretability of the structurally enhanced representation. Simultaneously, the synergistic constraints of semantics and structure help reduce inconsistencies caused by semantic conflicts and structural noise, resulting in better alignment of entity representations in the semantic and structural spaces.

[0033] The inference stage is more efficient and the output results are easier to integrate into downstream systems: Because the entity representations learned by this invention are more discriminative and the score distribution of candidate ranking is clearer, the inference stage can obtain more reliable Top-K results in a smaller candidate set, which is beneficial for the direct use of the completion results in downstream systems such as question answering, retrieval, and recommendation. In addition, this invention does not require the introduction of complex additional rules and artificial features, and the output results are in a unified form, which is convenient for encapsulation and invocation as a modular capability in engineering systems.

[0034] The implementation is simple and easy to integrate with existing frameworks and adapt to different knowledge graphs: This invention is mainly based on the existing general framework of "text encoding + GNN structure encoding + contrastive learning optimization", and adds a similarity evaluation and weight generation module, a weighted neighbor aggregation module, and a difficult negative sample screening module. The above modules have good pluggability and are suitable for different types of knowledge graph data (dense / sparse, different relation scales, different text information richness). They can be quickly migrated and deployed without relying on complex manual feature engineering, and have strong versatility and promotion value. Attached Figure Description

[0035] Figure 1 This is a schematic diagram of the model structure of the present invention;

[0036] Figure 2 This is a flowchart of the present invention. Detailed Implementation

[0037] The technical solution of the present invention will be further described below with reference to the accompanying drawings.

[0038] like Figure 2 As shown, this invention provides a knowledge graph completion method based on difficult few negative samples and GNN weighted neighbor aggregation, including the following steps: taking head and tail entities as input, firstly, a text encoder is used to obtain head / tail text embeddings; then, neighbor attention weights are calculated using GAT and similarity-weighted neighbor aggregation is performed to obtain head / tail structure embeddings; based on the entity representation, a small number of difficult negative samples are generated, and cosine similarity is used to construct a contrastive learning optimization target to update model parameters, thereby improving entity discrimination ability and realizing knowledge graph completion. The specific implementation process is as follows:

[0039] S1, such as Figure 2 As shown, data preprocessing and parameter initialization are performed, the input data format is defined, and the knowledge graph data is standardized to obtain structured training data. This provides a unified data foundation for subsequent text encoding, structure aggregation, and difficult negative sample generation. The specific process is as follows:

[0040] S11. Constructing the Dataset and Defining the Task. Based on user input, set the knowledge graph G=(E,R), where E is the entity set and R is the relation set; construct the training triple set T={(h,r,t)|h,t∈E,r∈R}, where (h,r,t) represent the head entity, relation, and tail entity, respectively. For the knowledge graph completion task, this invention uses tail entity prediction (h,r,?) or head entity prediction (?,r,t) as the inference target, and uses real triples as positive samples during the training phase. The knowledge graph dataset includes entity-relation triples, used to represent entities and the semantic relationships between them. For example, for the query triple (New YorkCity, located_in,?), New York City is the head entity, located_in is the relation, and the correct answer needs to be predicted from the candidate tail entity set. Candidate tail entities include New York State, Manhattan, North America, etc. Each entity contains a name and a text description (desc), and each relation is represented as a phrase (rel).

[0041] S12. Parameter Initialization and Hyperparameter Setting. The Xavier method is used to initialize the learnable parameters: if the input dimension of a layer is n and the output dimension is m, the parameters are initialized uniformly within the interval [-√(6 / (n+m)), √(6 / (n+m))]. Model hyperparameters are set, including the embedding dimension d (768), maximum sequence length, dropout probability (e.g., 0.1), learning rate, and temperature coefficient τ. The text encoder is initialized using a pre-trained language model, and the structural encoder is initialized using a graph attention network.

[0042] S2, such as Figure 1 As shown, a textual encoder is constructed to generate head / tail textual embeddings. The specific implementation process is as follows:

[0043] S21. Text input organization method. For any training sample (h,r,t), organize the head entity side input and the tail entity side input respectively, so as to obtain the head entity representation related to the relation conditions and the tail entity representation that maintains independent semantics.

[0044] S22. Head Textual Embedding Generation. The head entity name, head entity description, and relational text are concatenated and separated by a special marker [SEP]. This concatenation is then input into a text encoder to obtain: e_text^(h,r)=BERT(name_h ∥ desc_h ∥ [SEP] ∥ rel_r), where e_text^(h,r)∈R^d represents the semantic embedding of the head entity under relational condition r, enabling the model to jointly consider the matching information of "head entity semantics - relational semantics".

[0045] S23. Tail Textual Embedding Generation. Input the tail entity name and tail entity description into the text encoder to obtain: e_text^t=BERT(name_t ∥ desc_t), where e_text^t∈R^d represents the independent semantic embedding of the tail entity, used for similarity matching with the head entity side representation.

[0046] S24. Normalization and Regularization. To improve training stability, L2 normalization and dropout regularization can be applied to the output embedding, thereby reducing overfitting and improving the comparability of representations.

[0047] S3, such as Figure 1 As shown, a structural encoder (GAT) is constructed, similarity-weighted aggregation is performed, and head / tail structural embeddings are generated. The specific implementation process is as follows:

[0048] S31. Neighbor Set Construction. For a given sample (h,r,t), obtain the one-hop neighbor sets N(h) and N(t) for the head entity h and tail entity t, respectively. The neighbors consist of entities in the knowledge graph that are connected to the target entity. Unlike traditional methods that only aggregate on one side, this invention constructs neighbor contexts for both the head and tail sides to enhance the structural recognizability of entity representations.

[0049] S32. GAT Input and Two-Sided Structural Enhancement. Using the target entity text embedding as the central node representation and the neighboring entity text embeddings as the neighboring node representations, the input GAT is used for attention-weighted aggregation, yielding: Head entity structure embedding: e_struct^(h,r)=GAT(e_text^(h,r), {e_text^j | j∈N(h)}); Tail entity structure embedding: e_struct^t=GAT(e_text^t, {e_text^j | j∈N(t)}). The above process corresponds to the output of the "GAT + Similarity-Weighted Aggregation" module in the diagram to "Head / Tail Structural Embedding".

[0050] S33. Attention Weight Calculation Mechanism. For node i and its neighbor j, calculate the attention weight α_ij = softmax(LeakyReLU(a^T[Wh_i ∥ Wh_j])), where W is the learnable weight matrix, a is the attention vector, and ∥ represents concatenation; then, the neighbor information is weighted and summed to obtain the aggregation result h'i = σ(Σ{j∈N(i)} α_ij W h_j), where σ is the activation function. Preferably, GAT uses a multi-head attention mechanism (e.g., 4 attention heads) to enhance the modeling ability of different neighbor semantic / structural factors.

[0051] S34. Explanation of the role of structural aggregation. Through similarity-weighted neighbor aggregation, the model can adaptively learn the importance weights of different neighbors for the prediction of the current entity, thereby forming a higher quality structural context representation and improving the ability to distinguish easily confused entities.

[0052] S4, such as Figure 1 As shown, Hard Negative Sample Generation is performed to construct a small number of high-quality negative samples. The specific implementation process is as follows:

[0053] S41. Construction of candidate negative samples. For each positive sample triple (h,r,t), construct a candidate set {(h,r,t') | t'∈E, t'≠t} by replacing the tail entity, or construct a candidate set {(h',r,t) | h'∈E, h'≠h} by replacing the head entity; the candidate samples share relations or entity conditions with the positive samples, making them more deceptive.

[0054] S42. Difficult Negative Sample Screening and Few Negative Sample Mechanism. For candidate negative samples, calculate their similarity to positive samples in the representation space. Select the Top-K negative samples with the highest scores and closest to the decision boundary as the difficult negative sample set (e.g., K=32). Obtain higher quality training signals with a smaller negative sample size and avoid noise and computational waste caused by a large number of low-quality negative samples.

[0055] S43. Explanation of the effect of difficult negative samples. Because difficult negative samples are closer to positive samples and are more easily confused, the model can learn more fine-grained discriminative features during contrastive learning, thereby improving the ability to identify correct entities and enhancing generalization performance.

[0056] S5, such as Figure 1 As shown, a contrastive learning objective is constructed based on cosine similarity to update the model parameters. The specific implementation process is as follows:

[0057] S51. Similarity scoring function. Calculate the cosine similarity of the sample (h,r,t) as the matching score: score(h,r,t)=cos(e_(h,r), e_t)=(e_(h,r)·e_t) / (||e_(h,r)||×||e_t||), where the values ​​of e_(h,r) and e_t are determined during the training phase.

[0058] S52. Contrastive Learning Loss Function. For each positive sample and its set of difficult negative samples N, construct the InfoNCE loss: L = -log( exp(score(h,r,t) / τ) / (exp(score(h,r,t) / τ)+Σ_{(h',r,t')∈N} exp(score(h',r',t') / τ)) ), where τ is the temperature coefficient (e.g., 0.05). By maximizing the positive sample score and minimizing the difficult negative sample score, the parameters of the text encoder and the structural encoder are effectively updated.

[0059] S53. Parameter Update Strategy. In the first stage, only the text encoder parameters are updated; in the second stage, both the text encoder and GAT parameters are updated simultaneously, enabling the structure-enhanced representation to further improve discriminative power and accelerate convergence on the basis of stable semantics.

[0060] S6. Use the learned entity vector representations to perform knowledge graph completion reasoning and evaluation. The specific implementation process is as follows:

[0061] S61. Reasoning and Ranking. For incomplete triples (h,r,?), the head entity and relation are input into the text encoder and (in the second stage) aggregated by the GAT structure to obtain the head entity representation e_(h,r). For all candidate tail entities t'∈E, score(h,r,t') is calculated and sorted by score. The Top-1 or Top-K is taken as the prediction result.

[0062] S62. Evaluation Metrics. The completion performance is quantitatively evaluated using the mean reciprocal ranking (MRR) and Hits@K (K=1, 3, 10), where MRR is the average of the reciprocal rankings of the correct answers for each query, and Hits@K is the proportion of correct entities that appear in the top K.

[0063] S63. Explanation of Method Effects. This invention improves the model's ability to distinguish similar entities with fine granularity by combining a mechanism of "text encoding to obtain semantic representation + GAT similarity-weighted neighbor aggregation to obtain structurally enhanced representation + difficult few negative sample contrast learning optimization," thereby improving the prediction accuracy and ranking quality of knowledge graph completion.

[0064] S7. Model performance optimization and parameter tuning to ensure robustness across different datasets:

[0065] S71. Hyperparameter Settings. bert-base-uncased is used as the text encoder, and the GAT layer as the structure encoder, with a hidden layer size of 768 for both. The GAT uses four attention heads with a dropout rate of 0.1. The learning rate is selected from {5e-4, 5e-5, 1e-5} via grid search, the temperature parameter τ = 0.05, and the margin γ = 0.02.

[0066] S72. Parameter updates were performed using the AdamW optimizer, coupled with a linear learning rate decay strategy. Training was conducted on a single A100 GPU with a batch size of 768. Different training epochs were used for different datasets: 11 epochs for FB15k-237 and 70 epochs for WN18RR.

[0067] S73. Model Robustness Validation. Experiments were conducted on two benchmark datasets, FB15k-237 and WN18RR, to validate the effectiveness of the method on knowledge graphs of different sizes and densities. FB15k-237 contains 14,541 entities and 237 relations, exhibiting a rich variety of relation types; WN18RR contains 40,943 entities and 11 relations, with a relatively sparse structure but rich semantic hierarchy.

[0068] Through the above implementation methods, the knowledge graph completion method based on a progressive structure-enhanced semantic framework proposed in this invention effectively solves the problems of insufficient fusion of semantic and structural information and incomplete neighbor context representation in existing methods. By establishing a stable semantic foundation through a phased training strategy before fusing structural information, enriching the structural context through a bidirectional neighbor aggregation mechanism, and ensuring the stability of the training process through an embedded cache queue mechanism, the performance of knowledge graph completion is significantly improved.

Claims

1. A knowledge graph completion method based on difficult few negative samples and GNN weighted neighbor aggregation, characterized in that, Includes the following steps: (1) Obtain entities and their text information from the knowledge graph, and generate semantic representations of the entities through a text encoder; (2) For each entity, obtain its set of neighboring entities, and calculate the similarity between the central entity and each neighboring entity based on semantic representation, and map the similarity into aggregation weight; (3) Based on graph neural networks, aggregate weights are used to weight and aggregate the information of neighboring entities to generate an enhanced structural representation of the entities; (4) Construct a set of candidate negative samples for each positive sample triplet, and select a small number of negative samples that are semantically indistinguishable from the positive samples as difficult negative samples; (5) Construct a contrastive learning objective based on positive samples and difficult negative samples, and train the model so that the model can bring positive samples closer and move difficult negative samples further away in the representation space; (6) Use the trained model to complete and predict missing triples.

2. The knowledge graph completion method based on difficult few negative samples and GNN weighted neighbor aggregation as described in claim 1, characterized in that, In step (2), the similarity is mapped to the aggregation weight as follows: the neighbor entities are weighted based on semantic similarity, so that the neighbors that are semantically similar to the central entity get higher aggregation weights and the neighbors that are semantically unrelated get lower weights, thereby improving the discriminativeness of the structural representation.

3. The knowledge graph completion method based on difficult few negative samples and GNN weighted neighbor aggregation as described in claim 1, characterized in that, In step (4), the specific process of screening difficult negative samples is as follows: Select samples from the candidate negative samples that have similar scores or are ranked higher than the positive samples under the current model to form a small but challenging set of negative samples to replace a large number of random negative samples in training.

4. The knowledge graph completion method based on difficult few negative samples and GNN weighted neighbor aggregation as described in claim 1, characterized in that, In step (5), the contrast learning objective adopts a loss function based on the similarity of positive and negative samples. By optimizing this objective, the model can simultaneously improve its ability to discriminate relationships between entities in both the semantic space and the structural space.

5. The knowledge graph completion method based on difficult few negative samples and GNN weighted neighbor aggregation as described in claim 1, characterized in that, In step (5), the contrastive learning training employs a phased parameter update strategy: In the first phase, with the graph neural network parameters fixed, only the text encoder parameters are updated to establish a stable entity semantic representation foundation; in the second phase, based on the semantic representation, the parameters of the text encoder and the graph neural network are jointly updated, enabling the structure-enhanced representation to further learn discriminative features on a stable semantic foundation.

6. The knowledge graph completion method based on difficult few negative samples and GNN weighted neighbor aggregation as described in claim 1, characterized in that, Graph neural networks employ a multi-head attention mechanism for weighted aggregation of neighboring entities: each attention head independently calculates the attention weights between the central entity and its neighboring entities, and then sums the neighboring entity information based on these attention weights to obtain the aggregation result for that head. The aggregation results of multiple attention heads are spliced ​​or fused to generate the final structure-enhanced representation; Through the multi-head attention mechanism, the model is able to capture the diverse semantic contributions of neighboring entities from different representation subspaces.

7. The knowledge graph completion method based on difficult few negative samples and GNN weighted neighbor aggregation as described in claim 1, characterized in that, Step (6) is as follows: Based on the entity representation obtained from training, the candidate entities are scored and ranked according to similarity, and the best prediction result or Top-K candidate list is output.

8. A knowledge graph completion method system based on difficult few negative samples and GNN weighted neighbor aggregation, characterized in that, include: Text encoding module: used to encode the text information of entities into semantic vectors; Neighbor weighted aggregation module: used to weight and aggregate neighbor entities based on semantic similarity to generate structure-enhanced representations; Difficult Negative Sample Generation Module: Used to filter out a small number of negative samples that are difficult to distinguish from positive samples from the candidate negative samples; The contrastive learning training module is used to construct contrastive learning objectives based on positive samples and difficult negative samples, and to optimize model parameters. The completion inference module is used to predict and output missing triples based on the optimized model.

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 computer program is loaded into the processor, it implements the method of any one of claims 1-7.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the method described in any one of claims 1-7.