Enhancing PyKEEN with Multiple Negative Sampling Solutions for Knowledge Graph Embedding Models

Claudia d'Amato, Ivan Diliso, Nicola Fanizzi, Zafar SaeedarXiv 2025

TL;DR

Researchers have developed a modular extension for PyKEEN, a widely used Knowledge Graph Embedding (KGE) framework, that integrates advanced static and dynamic negative sampling strategies. This toolkit allows engineers and researchers to move beyond basic random corruption, enabling more robust training, customization, and fairer benchmarking of KGE models.

What Problem Does This Paper Address?

Knowledge Graphs (KGs) store real-world facts as triples (subject, relation, object), but they inherently suffer from incompleteness and only contain positive statements. To train KGE models for tasks like link prediction, frameworks rely on contrastive learning, which requires distinguishing true facts from false ones.

Because explicit negative facts don't exist in the graph, libraries typically rely on the Local Closed-World Assumption (LCWA)—randomly swapping out the subject or object entity to create a "negative" triple. However, this uniform random corruption often generates trivial or logically impossible negatives, which limits how well the model can grasp complex underlying semantics. While advanced negative sampling (NS) strategies exist in literature, they have historically been scattered across isolated repositories and tightly coupled to specific model architectures.

Methods

The authors bridge this gap by introducing a standardized, modular architecture built directly on top of PyKEEN’s abstract classes.

Fig. 1. Class inheritance diagram based on PyKEEN ’s class structure. Custom classes introduced by our extension are highlighted in color.

The core of the extension is the SubsetNegativeSampler, which allows each triple to dynamically define its own tailored "negative pool" based on structural or semantic constraints. The extension introduces two main categories of advanced samplers:

  1. Static Samplers:
  2. Corrupt Sampling: Leverages structural relation information from the positive instance set.
  3. Typed Sampling: Restricts negative candidates to entities that match the domain and range classes of the relation (or entities of the same class if schema data is missing).
  4. Relational Sampling: Assumes head-tail pairs participate in only one relation, swapping relations to find negatives.
  5. Dynamic Samplers:
  6. Nearest Neighbor & Adversarial Sampling: These strategies use a pre-trained auxiliary model (like RESCAL) to find "harder," more informative negative samples in the vector space on the fly based on embedding similarity.

Additionally, the authors implemented a custom data loader to ingest external metadata (like JSON files for domain/range and class memberships) and a NullPythonSetFilterer to cleanly handle triples for which no valid negative sample can be generated.

Comparison of Negative Samplers Across SOTA KGE Libraries

Datasets

The extension provides standardized data and metadata formatting for four canonical benchmarks:

  • YAGO4-20
  • DBpedia50K
  • WN18 (Schema-less lexical database)
  • FB15K (Schema-rich subset of Freebase)

The empirical evaluation specifically focused on WN18 and FB15K to demonstrate the extension's functionality across different graph structures.

Key Insights and Ideas

  • The Shrinking Pool Dilemma: Advanced static strategies drastically reduce the size of the negative pool. For instance, the Corrupt strategy on YAGO4-20 reduces the available candidate pool to just 4% of the total entity set.
  • The Random Fallback Trap: When a strict strategy (like Relational or Typed) cannot find enough valid negatives to meet the requested negative-to-positive ratio, the system must supplement the pool with random entities. At high negative counts, this means advanced samplers end up behaving almost identically to basic random corruption, diluting their intended algorithmic benefits.
  • Auxiliary Model Dependency: Dynamic strategies like Adversarial sampling are highly sensitive to the quality of their guiding auxiliary model. If the auxiliary model performs poorly, the generated "hard negatives" actually degrade downstream link prediction performance.

Key Results

The authors validated their extension by testing 12 different KGE models (spanning translation-based, semantic similarity-based, and geometric-based approaches) on FB15K and WN18 using the Hits@10 metric.

The experiments confirmed that the choice of negative sampling strategy significantly impacts model performance based on the dataset's structural properties. Crucially, they showed that simply increasing the number of negative samples per positive instance yielded diminishing returns across all models. This quantitative plateau happens because the random fallback mechanism increasingly overrides the custom sampling logic as the requested negative count grows.

Limitations and Future Work

A notable limitation is computational overhead: the Nearest Neighbor dynamic strategy had to be excluded from the empirical evaluation because calculating dense similarity matrices for every single triple is highly resource-intensive.

To address this, the authors note that future work will focus heavily on performance optimization. This includes implementing intelligent caching strategies to accelerate runtime computation, exploring parallel and distributed implementations, and integrating a broader variety of negative sampling methods into the ecosystem.

Summary updated

BibTeX
@misc{damato2025enhancing,
  author = {Claudia d'Amato and Ivan Diliso and Nicola Fanizzi and Zafar Saeed},
  title = {{Enhancing PyKEEN with Multiple Negative Sampling Solutions for Knowledge Graph Embedding Models}},
  year = {2025},
  eprint = {2508.05587},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2508.05587},
}
Figure