OpenKE: An Open Toolkit for Knowledge Embedding

Xu Han, Shulin Cao, Xin Lv, Yankai Lin, Zhiyuan Liu, Maosong Sun, Juanzi Li

Abstract

Knowledge Graphs (KGs) are essential for modern AI, yet their symbolic nature poses challenges for machine learning. Knowledge Embedding (KE) addresses this by mapping entities and relations into continuous low-dimensional spaces. OpenKE is an open-source, high-performance toolkit designed to standardize and scale this process. By providing a unified framework with both CPU and GPU acceleration, OpenKE achieves over a 10x speedup compared to previous implementations, enabling the processing of massive datasets like the full Wikidata.

Introduction

While Knowledge Embedding has become a cornerstone of KG research, the field has long suffered from a "usability gap." Existing implementations are often inconsistent, inflexible, and lack the scalability required for real-world applications. Researchers frequently encounter incompatible interfaces and code optimized only for small-scale validation. OpenKE aims to bridge this gap by providing an industrial-strength solution that prioritizes operational efficiency and standardization.

Methods

OpenKE is built upon a modular architecture designed to decouple data management from model logic, allowing for greater flexibility and ease of use.

Modular Architecture

The toolkit organizes the embedding process into three distinct layers: Underlying Management, Model Settings, and Training/Evaluation. This structure allows users to configure datasets, model parameters, and training strategies independently, as illustrated in the mapping between user code and the framework's internal components.

The modular architecture of OpenKE and its mapping to user code.

Unified Mathematical Framework

A core innovation of OpenKE is its categorization of KE models into two primary components: a scoring function (measuring fact plausibility) and a loss function (typically margin-based or logistic). This abstraction enables users to implement new models simply by defining these two functions within the framework. The following table summarizes how various state-of-the-art models are represented within this unified structure.

Unified mathematical framework for knowledge embedding models supported by OpenKE.

Technical Highlights

  • Multi-Platform Support: The toolkit utilizes C++ for low-level data processing and multi-threaded CPU training, while leveraging TensorFlow and PyTorch for GPU acceleration.
  • Offset-based Negative Sampling: To overcome the bottleneck of filtering negative samples, OpenKE introduces an indexing trick using offsets. This allows for the generation of guaranteed negative samples in $O(1)$ time without expensive lookups.
  • Parallel Training: It supports both lock-free (Hogwild!-style) and synchronized gradient updates to maximize throughput on multi-core systems.

Datasets and Evaluation

OpenKE was evaluated using standard benchmarks and a massive real-world dataset:

  • FB15K: A dense subgraph of Freebase.
  • WN18: A subset of the WordNet lexical database.
  • Wikidata: The full version, containing over 40 million entities and 100 million facts—significantly larger than what most academic toolkits can handle.

Key Results and Insights

The toolkit demonstrates significant improvements in both speed and accuracy:

  • Massive Speedup: OpenKE achieved more than a 10x speedup over existing toolkits like KB2E. For instance, training TransE on FB15K was reduced from nearly 2 hours to just 76 seconds using 8 CPU threads.
  • Standardization Benefits: By providing a consistent pipeline, many models implemented in OpenKE performed better than originally reported, highlighting the impact of optimized training procedures.
  • Wikidata at Scale: OpenKE is the first toolkit to successfully provide stable embeddings for the entire Wikidata, achieving a Hits@100 of 90.6% on the link prediction task for tail entities.

Conclusion and Future Work

OpenKE provides a robust foundation for large-scale knowledge embedding. Future developments will focus on incorporating more complex architectures, such as neural network-based or path-based models, and implementing methods for incremental embedding updates to handle evolving KGs. The team also plans to maintain a public repository of pre-trained models to support the broader research community.

Summary updated

BibTeX
@inproceedings{han2018openke,
  author = {Xu Han and Shulin Cao and Xin Lv and Yankai Lin and Zhiyuan Liu and Maosong Sun and Juanzi Li},
  title = {{OpenKE: An Open Toolkit for Knowledge Embedding}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2018},
  doi = {10.18653/v1/d18-2024},
}
Figure