Source-linked AI summary
PyKEEN-NSX: A Modular Framework for Static, Dynamic and Schema-Aware Negative Sampling in PyKEEN
Ivan Diliso, Nicola Fanizzi, Claudia d'Amato
TL;DR
KGE frameworks often lack a unified way to develop and compare advanced negative samplers for knowledge graphs. PyKEEN-NSX separates context-dependent candidate-pool generation from negative selection in a modular PyKEEN extension. Its six samplers remain compatible with existing workflows, while analysis across four datasets shows constrained pools often trigger random fallback, replacing the intended criterion to a large extent.
Problem
KGE libraries generally support only basic negative-sampling strategies and lack a unified framework for developing and comparing advanced customized samplers.
Method
PyKEEN-NSX factors negative sampling into a context-conditioned candidate-pool generator and a selector, implementing six samplers within PyKEEN.
Results
Across four datasets, constrained pools frequently fall below the requested negative count, and integrated link-prediction performance can approach Random’s Mean Reciprocal Rank of 0.686.
Takeaways & Limitations
Pool size becomes measurable before training, making fallback substitution controllable and observable rather than an implicit assumption.
Abstract
from arXiv · showhide
Embedding methods have become popular due to their scalability on link prediction and/or triple classification tasks on Knowledge Graphs (KGs). Embedding models are trained relying on both positive and negative samples of triples. However, since KGs generally contain only positive assertions, negative samples are artificially generated through negative sampling strategies, ranging from simple random corruption to more sophisticated approaches that exploit structural, semantic, or embedding information. The design and implementation of advanced negative samplers remains challenging, as most popular Knowledge Graph Embedding (KGE) libraries provide support only for basic strategies and lack a unified framework for developing more advanced and customized solutions. To address this gap, we introduce PyKEEN-NSX, an extension of PyKEEN, the popular KGE framework, that provides a modular engineered abstraction for negative sampling. The proposed architecture separates the generation of candidate negative pools, conditioned on an explicit context, from the selection strategy, enabling the development and integration of static, schema-aware and dynamic approaches within a consistent framework. Based on this abstraction, we implement six negative samplers, while remaining fully compatible with existing PyKEEN workflows and pipelines. As a proof of concept, we study negative availability across four datasets, showing that constrained pools frequently fall below the requested number of negatives, so that the encoded criterion is to a large extent replaced by the random fallback that supplements them.
1. Introduction
PyKEEN and similar KGE frameworks make advanced negative-sampler development and fair comparison difficult because sampling is exposed as one monolithic operation. PyKEEN-NSX addresses this by separating candidate-pool generation from negative selection while supporting multiple sampler families.
- KG embedding models train with artificially generated negative triples because knowledge graphs primarily contain positive assertions.
- Most frameworks require each sampler to reimplement batching, target selection, filtering, and tensor handling around its distinguishing criterion.
- PyKEEN-NSX makes the common pool-generation and selection factorization explicit, so new strategies define their pool while retaining shared components.
- The extension implements six static, schema-aware, and dynamic samplers compatible with existing KGE models in PyKEEN.
- Constrained pools frequently fail to provide the requested negatives, causing random fallback to replace the intended criterion to a large extent.
2. A General Abstraction for Negative Samplers
Negative samplers share a two-stage structure: a context-dependent pool generator proposes admissible corruptions, and a selector draws the negatives used for training.
- A corrupted triple replaces its head, tail, or both with entities drawn from the knowledge graph’s entity set.
- The pool generator 𝒫_s(τ; Ω) returns entities admissible for corrupting target s under assertions, schema, or auxiliary-model state Ω.
- The selector σ(𝒫_s(τ; Ω), k) draws the k negative entities used for training from the generated pool.
3. PyKEEN-NSX
PyKEEN-NSX packages shared negative-sampling operations in an extensible PyKEEN base class. Pool generation and selection are exposed as hooks, allowing six static, schema-aware, and dynamic samplers to share the same workflow.
- The abstract class inherits from PyKEEN’s NegativeSampler and centralizes replication, target choice, tensor assembly, caching, and fallback handling.
- Figure 1 depicts shared corruption utilities and a default uniform selector, with new strategies introduced through highlighted pool-generator hooks.
- Defining only the pool generator is sufficient for a new strategy because the selector and other components have default behavior.
- The extension provides static Corrupt, Relational, and schema-aware Typed variants, plus dynamic NearestNeighbour and Adversarial samplers.
4. Preliminary Negative Sampling Analysis
The analysis measures how often constrained negative pools cannot satisfy the requested count and examines the effect of fallback on link prediction. Structural constraints can make integrated samplers approach random-corruption performance.
- For each sampler and dataset, the analysis reports the fraction of triples whose pool contains fewer than k negatives and therefore triggers random fallback.
- The study covers YAGO4-20, DBpedia50K, ARCO20, and WHOW5, while excluding dynamic samplers from availability analysis because their pools contain k nearest entities by construction.
- Under RotatE on ARCO20 with k = 40, integrated scores approach Random’s Mean Reciprocal Rank of 0.686 as pool shortfall grows.
- Relational cannot supply forty negatives for 99% of ARCO20 triples and reaches Mean Reciprocal Rank 0.674 with integration, indistinguishable from random corruption.
- Corrupt is short on 16% of ARCO20 triples and reaches Mean Reciprocal Rank 0.370 under the reported evaluation.
5. Conclusions and Future Work
PyKEEN-NSX factors negative sampling into context-conditioned pool generation and selection, unifying multiple strategies under one interface. The analysis shows constrained pools often fail to supply the requested negatives, making fallback behavior observable and motivating broader future extensions.
- PyKEEN-NSX factors negative sampling into a context-conditioned pool generator and a selector.
- The abstraction unifies static, schema-aware, and dynamic strategies while allowing new samplers to be defined through their pool alone.
- Constrained pools, especially structural ones, rarely reach the requested k, so random fallback can replace the encoded criterion.
- The extension makes fallback substitution controllable and observable without training.
- Future work includes selector-side score-based strategies, broader evaluation, performance optimization, and parallel implementation.
Declaration on Generative AI
The authors report using DeepL Write, Grammarly, and ChatGPT for grammar checking, rephrasing, and rewording, followed by author review and editing.
- The authors used DeepL Write, Grammarly, and ChatGPT for grammar checking, rephrasing, and rewording, then reviewed and edited the content.