Efficient Non-Sampling Knowledge Graph Embedding

Zelong Li, Jianchao Ji, Zuohui Fu, Yingqiang Ge, Shuyuan Xu, Chong Chen, Yongfeng ZhangWWW 2021 · DOI

Abstract

Knowledge Graph (KG) is a flexible structure that is able to describe the complex relationship between data entities. Currently, most KG embedding models are trained based on negative sampling, i.e., the model aims to maximize some similarity of the connected entities in the KG, while minimizing the similarity of the sampled disconnected entities. Negative sampling helps to reduce the time complexity of model learning by only considering a subset of negative instances, which may fail to deliver stable model performance due to the uncertainty in the sampling procedure. To avoid such deficiency, we propose a new framework for KG embedding—Efficient Non-Sampling Knowledge Graph Embedding (NS-KGE). The basic idea is to consider all of the negative instances in the KG for model learning, and thus to avoid negative sampling. The framework can be applied to square-loss based knowledge graph embedding models or models whose loss can be converted to a square loss. A natural side-effect of this non-sampling strategy is the increased computational complexity of model learning. To solve the problem, we leverage mathematical derivations to reduce the complexity of non-sampling loss function, which eventually provides us both better efficiency and better accuracy in KG embedding compared with existing models. Experiments on benchmark datasets show that our NS-KGE framework can achieve a better performance on efficiency and accuracy over traditional negative sampling based models, and that the framework is applicable to a large class of knowledge graph embedding models.

Introduction

Knowledge Graphs (KGs) represent facts as triplets: (head entity, relation, tail entity). To utilize these graphs in downstream AI tasks, researchers "embed" them into continuous vector spaces. Traditionally, these models are trained using negative sampling. Since a graph only contains observed "true" facts, models require "false" facts (negatives) to learn discriminative boundaries. Due to the millions of possible false triplets, standard practice involves randomly sampling a small subset for every true triplet.

However, negative sampling introduces three major flaws: instability from random noise, information loss by ignoring the vast majority of negative data, and an efficiency bottleneck as the overhead of generating samples grows with graph size. Researchers from Rutgers and Tsinghua University have developed NS-KGE, a framework that trains Knowledge Graph Embedding (KGE) models using all possible negative examples, eliminating the need for sampling entirely.

Methodology

The NS-KGE framework aims to minimize a square-loss function that accounts for every single possible triplet in the graph. Naively, calculating the loss for all pairs would result in a complexity of $O(d \cdot |E|^2 \cdot |R|)$, which is computationally prohibitive for large graphs. The core innovation of NS-KGE is a mathematical derivation that disentangles the interactions between head, relation, and tail entities.

By leveraging the structure of factorization-based models, the authors rewrite the "all-entity" component of the loss as a product of three independent terms. This reduces the complexity to $O(d^2(|E| + |R|))$, where $d$ is the embedding dimension. Since $d$ is typically much smaller than the number of entities $|E|$, this makes "whole-data" training not only possible but significantly faster than sampling-based methods. The framework is versatile, adapting to architectures such as DistMult, SimplE, ComplEx, and TransE.

Evaluation and Results

The authors evaluated NS-KGE on two gold-standard benchmarks: FB15K237 and WN18RR. The results demonstrate that the non-sampling approach provides a more stable and comprehensive signal for model learning.

HR@10 performance on FB15K237 comparing baseline sampling with NS-KGE across different models.

Efficiency Gains

On the FB15K237 dataset, NS-DistMult completed training in just 53 seconds, compared to 3,546 seconds for the standard sampling-based version—a 66.9x speedup. Because the complexity is reduced, the entire dataset can often be trained in a single batch on standard GPU hardware.

Accuracy Improvements

Across almost all metrics, including Mean Reciprocal Rank (MRR) and Hit Ratio (HR), the NS-KGE versions outperformed their sampling-based counterparts. For instance, NS-TransE improved HR@10 on FB15K237 from 0.316 to 0.447. Similar trends were observed on the WN18RR dataset, particularly for translation-based models.

HR@10 performance on WN18RR showing significant gains for NS-KGE, particularly for TransE.

Conclusion

NS-KGE offers a robust alternative to negative sampling by utilizing the full structural context of the Knowledge Graph. While the current framework is optimized for square loss, it demonstrates superior efficiency and accuracy across multiple model architectures. Future research will focus on extending this non-sampling approach to Graph Neural Networks (GNNs) and incorporating entity attributes.

Summary updated

BibTeX
@inproceedings{li2021efficient,
  author = {Zelong Li and Jianchao Ji and Zuohui Fu and Yingqiang Ge and Shuyuan Xu and Chong Chen and Yongfeng Zhang},
  title = {{Efficient Non-Sampling Knowledge Graph Embedding}},
  booktitle = {The Web Conference},
  year = {2021},
  doi = {10.1145/3442381.3449859},
}
Figure