Simple and automated negative sampling for knowledge graph embedding

Yongqi Zhang, Quanming Yao, Lei Chen

TL;DR

NSCaching (Negative Sampling Caching) is a simple yet powerful framework that replaces complex, unstable GAN-based samplers with an efficient cache to track high-quality "hard" negative samples. By integrating Automated Machine Learning (AutoML) to balance exploration and exploitation, it consistently outperforms state-of-the-art methods in both accuracy and training efficiency across various Knowledge Graph and graph embedding tasks.

What Problem Does This Paper Address?

Knowledge Graph (KG) embedding involves representing entities and relations as low-dimensional vectors. To train these models, we need both positive triplets (known facts like (Steve Jobs, founded, Apple Inc.)) and negative triplets (non-observed facts).

An example of a knowledge graph showing entities and relations.

The challenge lies in negative sampling. Most possible triplets are "easy" negatives that the model can quickly classify, providing zero gradient and stalling the learning process—a phenomenon known as the vanishing gradient problem. While Generative Adversarial Networks (GANs) have been used to "mine" harder negatives, they are notoriously difficult to train, require pre-training, and add significant computational overhead. The authors seek a method that is as effective as GANs but as simple and efficient as uniform sampling.

Methods

The authors introduce NSCaching, which treats negative sampling as a memory problem rather than a generative one.

  1. The Cache: For each positive triplet, the algorithm maintains a small cache of negative triplets that currently yield large gradients.
  2. Sampling & Updating: During training, the model samples negatives directly from this cache (exploitation). Periodically, it refreshes the cache by sampling a new subset of candidates from the entire entity set, calculating their gradients, and keeping the "hardest" ones (exploration).
  3. AutoML Integration: The balance between exploration and exploitation is controlled by several hyperparameters (like cache size and softmax temperatures). The authors use SMAC (Sequential Model-based Algorithm Configuration), an AutoML technique, to automatically tune these parameters for different datasets and models.
  4. Generalization: Beyond KGs, they extend NSCaching to the skip-gram model used in graph embeddings (like Node2vec), replacing traditional frequency-based sampling.

Datasets

The researchers evaluated their method on a comprehensive suite of benchmarks:

  • Knowledge Graph: WN18, FB15K, and their more realistic variants WN18RR and FB15K237, plus the large-scale YAGO3-10.
  • Graph Embedding: Cora and Citeseer (citation networks).
  • Interpretability: FB13 was used to visualize how the cache content evolves during training.

Key Insights and Ideas

  • The Skewed Gradient Reality: The authors empirically show that the distribution of negative samples is highly skewed; only a tiny fraction of negatives provide meaningful information for training. CCDF of gradient norms showing that high-gradient negatives are rare and their distribution changes over time.

  • Distillation of GANs: NSCaching acts as a "distilled" version of a GAN. It achieves the same goal—sampling from the high-gradient tail of the distribution—without the instability of training a generator.

  • Implicit Self-Paced Learning: The cache naturally implements a curriculum. Early in training, "easy" negatives populate the cache. As the model improves, these become "too easy" (low gradient) and are replaced by progressively harder samples.
  • A Unified View: The paper demonstrates that traditional Bernoulli sampling, KBGAN, and IGAN can all be viewed as special, sub-optimal cases of the NSCaching framework with specific hyperparameter constraints.
CCDF of gradient norms showing that high-gradient negatives are rare and their distribution changes over time.

Key Results

  • Superior Accuracy: NSCaching consistently outperformed Bernoulli and GAN-based baselines across all tested scoring functions (TransE, TransD, DistMult, ComplEx, SimplE). For example, on WN18 with TransE, the Mean Reciprocal Rank (MRR) jumped from ~0.50 to ~0.78.
  • Efficiency: Unlike GAN methods, NSCaching does not require pre-training and has fewer parameters. It shows better "anytime" performance, reaching higher accuracy in less clock time.
  • Graph Embedding Gains: When applied to Node2vec, NSCaching improved node classification F1-scores on Cora and Citeseer, proving its versatility beyond just KGs.

Limitations and Future Work

  • False Negatives: Because KGs are incomplete, a "negative" sample might actually be a true fact missing from the data. While the authors show this isn't a major empirical issue (large-gradient samples rarely overlap with missing truths), it remains a theoretical concern.
  • Future Directions: The authors suggest using AutoML not just for sampling, but to search for the optimal scoring functions themselves (a task they explore in their related work, AutoSF).

For researchers in KG embedding, this paper provides a compelling argument: sometimes a well-managed cache and a bit of automation are all you need to beat a complex generative model.

Summary updated

BibTeX
@inproceedings{zhang2021simple,
  author = {Yongqi Zhang and Quanming Yao and Lei Chen},
  title = {{Simple and automated negative sampling for knowledge graph embedding}},
  booktitle = {VLDB J},
  year = {2021},
  url = {https://openreview.net/forum?id=TOIpHzYTTJz},
}
Figure