PyKEEN-NSX: A Modular Framework for Static, Dynamic and Schema-Aware Negative Sampling in PyKEEN

Ivan Diliso, Nicola Fanizzi, Claudia d'AmatoarXiv 2026

TL;DR

PyKEEN-NSX introduces a modular extension to the popular PyKEEN library that unifies negative sampling strategies for Knowledge Graph Embeddings (KGE) by separating candidate pool generation from selection. In doing so, it exposes a critical, previously hidden flaw in advanced negative samplers: highly constrained candidate pools frequently run out of valid negatives, forcing frameworks to silently fall back on random corruption and undermining the very strategies researchers intend to test.

What Problem Does This Paper Address?

Knowledge Graphs (KGs) store real-world facts as triples (subject, predicate, object). Because KGs are inherently incomplete, researchers use Knowledge Graph Embedding (KGE) models to predict missing links. Training these models requires a contrastive approach: the model must learn to distinguish true facts from false ones (negative samples).

Since KGs typically only contain positive statements, negatives must be artificially generated under the Local Closed-World Assumption (LCWA)—usually by taking a true triple and randomly swapping the subject or object with another entity. While simple random corruption is standard, it often produces trivial or false negatives, leading to suboptimal model performance.

To fix this, researchers have proposed advanced negative samplers that leverage graph structure, entity types, or schema rules. However, these advanced strategies are usually scattered across isolated repositories and tightly coupled to specific embedding models. Even worse, existing KGE libraries treat negative sampling as a single monolithic operation, making it impossible to cleanly compare different strategies or measure a fundamental constraint: do these advanced strategies actually have enough valid negative entities to sample from?

Methods

The authors introduce PyKEEN-NSX, an extension that breaks down any negative sampling strategy into a clean, two-part abstraction:

  1. Pool Generator ($\mathcal{P}$): Generates a pool of admissible candidate negative entities based on a specific context (e.g., graph assertions, schema/ontology constraints, or the state of an auxiliary model).
  2. Selector ($\sigma$): Draws the requested $k$ negative samples from that pool (defaulting to a uniform random draw).
Figure 1: Architecture of PyKEEN-NSX. The abstract base class provides the shared corruption utilities and a default uniform selector 𝜎; a new strategy is obtained by defining its pool generator 𝒫through the highlighted hooks. Custom classes introduced by the extension are shown under/over each component.

By isolating the pool generator, PyKEEN-NSX allows researchers to implement new sampling strategies simply by defining how the candidate pool is built. The framework ships with six pre-implemented samplers covering static, schema-aware, and dynamic approaches.

Crucially, the framework exposes a new parameter called integrate. When a constrained pool contains fewer candidates than the requested number of negatives ($k$), integrate defines the fallback policy: it can draw with replacement, return the undersized pool as-is, or top it up with random entities. This makes the point where an advanced strategy degrades into random corruption completely measurable and controllable.

Datasets

The authors evaluated negative availability and link prediction performance across four datasets:

  • YAGO4-20
  • DBpedia50K
  • ARCO20 (Rich in schema axioms/ontologies)
  • WHOW5

Key Insights and Ideas

  • The Negative Availability Crisis: Once you restrict negative samples using structural or semantic rules (e.g., "only sample entities that match the expected domain/range of the relation"), the size of the candidate pool varies wildly from triple to triple.
  • The Silent Fallback Deception: When the candidate pool is too small to satisfy the requested number of negatives ($k$), common practice has been to silently pad the remaining slots with random entities. PyKEEN-NSX reveals that for many triples, the advanced criteria are completely overridden by this random fallback.
  • Pre-training Compatibility Check: Because PyKEEN-NSX makes the pool generator explicit, researchers can calculate the "shortfall curve" (the percentage of triples that fail to meet the required pool size) before running any expensive training loops. This serves as an immediate check of whether a strategy is even compatible with a given dataset.

Key Results

The authors evaluated the samplers on the ARCO20 dataset using the RotatE model with a standard target of $k = 40$ negatives per positive triple.

The results highlight a stark reality:

  • The Relational sampler (which restricts candidates based on shared relations) could not supply 40 negatives for 99% of the triples in ARCO20.
  • When forced to use its "pure" form without random fallback, the Relational sampler's Mean Reciprocal Rank (MRR) plummeted to 0.254. When allowed to integrate random fallback, its score jumped to 0.674—nearly identical to pure Random sampling (0.686). This proves the advanced logic was doing virtually no work; the random fallback was driving the performance.
  • The Corrupt sampler faced a shortfall on 16% of triples, achieving an MRR of 0.370 in its pure form versus 0.686 with random integration.
Figure 3: Link prediction evaluation (Mean Reciprocal Rank) on ARCO20 (RotatE, 𝑘= 40), for each sampler in its pure form and with random fallback (integrate).

Limitations and Future Work

While PyKEEN-NSX successfully unifies pool generation, the Selector side of the framework is still basic. Advanced, score-based selection strategies—such as NSCaching and self-adversarial sampling, which weight candidates based on current model scores—are not yet implemented within this modular architecture.

Additionally, the authors note that future iterations will focus on performance optimizations, including parallel implementation and caching mechanisms to speed up the computation of complex, dynamic candidate pools.

Summary updated

BibTeX
@misc{diliso2026pykeen,
  author = {Ivan Diliso and Nicola Fanizzi and Claudia d'Amato},
  title = {{PyKEEN-NSX: A Modular Framework for Static, Dynamic and Schema-Aware Negative Sampling in PyKEEN}},
  year = {2026},
  eprint = {2608.30652},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2608.30652},
}
Figure