Skip to main content
QUICK REVIEW

[Paper Review] TorchKGE: Knowledge Graph Embedding in Python and PyTorch

Armand Boschin|arXiv (Cornell University)|Sep 7, 2020
Advanced Graph Neural NetworksComputer Science8 references7 citations
TL;DR

TorchKGE is a PyTorch-based open-source Python library for knowledge graph embedding that provides a fast, efficient, and user-friendly API for implementing and evaluating KG embedding models. It significantly accelerates link prediction evaluation—up to 24× faster than OpenKE and AmpliGraph—while supporting state-of-the-art models, negative sampling, and standardized evaluation metrics.

ABSTRACT

TorchKGE is a Python module for knowledge graph (KG) embedding relying solely on PyTorch. This package provides researchers and engineers with a clean and efficient API to design and test new models. It features a KG data structure, simple model interfaces and modules for negative sampling and model evaluation. Its main strength is a very fast evaluation module for the link prediction task, a central application of KG embedding. Various KG embedding models are also already implemented. Special attention has been paid to code efficiency and simplicity, documentation and API consistency. It is distributed using PyPI under BSD license. Source code and pointers to documentation and deployment can be found at https://github.com/torchkge-team/torchkge.

Motivation & Objective

  • Address the lack of a unified, efficient framework for training and evaluating knowledge graph embedding models across different programming languages and deep learning frameworks.
  • Improve reproducibility in KG embedding research by enabling consistent comparison of models under identical hardware and software conditions.
  • Provide a high-performance evaluation pipeline for link prediction, a core task in KG embedding, which is often the bottleneck in training workflows.
  • Offer a clean, PyTorch-native API with minimal dependencies, strong documentation, and community support to lower the barrier for researchers and engineers.
  • Enable rapid prototyping and benchmarking of new KG embedding architectures through modular design and off-the-shelf implementations.

Proposed method

  • Implement all models as subclasses of PyTorch's nn.Module to leverage automatic differentiation, GPU acceleration, and optimization tools.
  • Design a dedicated, highly optimized evaluation module for link prediction that computes scores for all candidate entities in a batched, vectorized manner.
  • Provide a modular data structure (KnowledgeGraph class) to manage training, validation, and test splits with configurable splitting strategies.
  • Integrate multiple negative sampling strategies (uniform, Bernoulli, positional) via a unified interface to support efficient training with negative hard examples.
  • Use PyPI for distribution and BSD licensing to ensure broad accessibility and community contributions.
  • Support loading of standard benchmark datasets (e.g., FB15k, WN18, YAGO3-10) through utility functions in the utils.datasets module.

Experimental results

Research questions

  • RQ1How can a unified, efficient, and reproducible framework for knowledge graph embedding be designed to enable fair model comparison across different research groups?
  • RQ2What performance gains can be achieved in link prediction evaluation by optimizing the scoring and ranking pipeline in a PyTorch-native implementation?
  • RQ3To what extent does a well-optimized evaluation module reduce training overhead and improve hyperparameter tuning efficiency?
  • RQ4Can a minimal-dependency, PyTorch-based library achieve competitive training speed while significantly outperforming existing frameworks in evaluation latency?
  • RQ5How does the performance of link prediction evaluation in TorchKGE compare to established libraries like OpenKE and AmpliGraph under identical hardware and hyperparameter settings?

Key findings

  • TorchKGE achieves a 24× speedup in link prediction evaluation compared to OpenKE when evaluating RESCAL on WN18, with evaluation times of 7.06 seconds vs. 178.4 seconds.
  • On average, TorchKGE is at least three times faster than OpenKE and AmpliGraph in link prediction evaluation across all models and datasets tested.
  • Training epoch times in TorchKGE are within a factor of two of OpenKE and AmpliGraph, indicating strong training efficiency despite the focus on evaluation speed.
  • The evaluation module in TorchKGE is highly optimized, reducing the time for link prediction on FB15k with ComplEx from 96.4 seconds (TorchKGE) to 354.7 seconds (AmpliGraph).
  • TorchKGE supports all major KG embedding models (TransE, TransD, RESCAL, ComplEx) and provides consistent, documented implementations with references to original papers.
  • The library’s performance advantage is most pronounced in evaluation workloads, where it outperforms OpenKE and AmpliGraph by up to 24×, making frequent evaluation during training practical and efficient.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.