Skip to main content

gpuRDF2Vec

A scalable GPU based implementation of RDF2Vec embeddings for large and dense Knowledge Graphs.

License: MIT

RDF2VecGPU_Image

Table of contents

The content of this repository readme can be found here:

Package installation

Install the package rdf2vecgpu by running the following command:

pip install rdf2vecgpu

This installs the package together with its GPU stack: PyTorch, PyTorch Lightning and the RAPIDS libraries cuDF, Dask-cuDF and cuGraph 25.6 (CUDA 12 builds).

Requirements

  • Python 3.12 or newer
  • Linux (on Windows, use WSL2; the RAPIDS pip wheels are Linux-only)
  • An NVIDIA GPU with a CUDA 12.x driver

If you need a specific PyTorch build for your CUDA version, install it first with the PyTorch selector, then install rdf2vecgpu. See the installation guide for multi-GPU setup and troubleshooting.

Optional extras

pip install "rdf2vecgpu[gensim]"   # CPU Word2Vec trainer, RDF2VecConfig(backend="gensim")
pip install "rdf2vecgpu[mlflow]"   # MLflow experiment tracking
pip install "rdf2vecgpu[wandb]"    # Weights & Biases experiment tracking
pip install "rdf2vecgpu[test]"     # test suite

The pinned environments used for the ISWC 2025 benchmarks (gpuRDF2Vec and the baselines) are in performance/env_files.

gpuRDF2Vec overview

RDF2Vec is a powerful technique to generate vector embeddings of entities in RDF graphs via random walks and Word2Vec. This repository provides a GPU-optimized reimplementation, enabling:

  • Speedups on dense graphs with millions of nodes
  • Scalability to industrial-scale knowledge bases
  • Reproducible experiments to test and qualify the overall implementation details

Repository Structure

.
├── src/rdf2vecgpu/         # the package
│   ├── gpu_rdf2vec.py      # GPU_RDF2Vec: load_data, fit, transform, save/load
│   ├── config.py           # RDF2VecConfig
│   ├── corpus/             # single- and multi-GPU walk generation (cuGraph)
│   ├── embedders/          # PyTorch Lightning Word2Vec, data loaders, gensim backend
│   ├── reader/             # KGFileReader: Parquet, CSV, ORC, N-Triples/N-Quads, rdflib
│   ├── helper/             # vocabulary construction
│   ├── logger/             # MLflow / W&B / no-op trackers
│   └── _compat.py          # cuGraph / dask compatibility patches
├── test/                   # unit and GPU end-to-end tests
├── docs/                   # Sphinx documentation (Read the Docs)
├── performance/            # ISWC 2025 benchmark scripts and environments
└── data_preparation/       # dataset conversion scripts

Capability overview

  • Random and BFS walk generation on the GPU with cuGraph, single- or multi-GPU, optionally weighted
  • Skip-gram and CBOW training on the GPU with PyTorch Lightning (single- or multi-GPU DDP), or on the CPU with gensim
  • Readers for Parquet, CSV, ORC, N-Triples/N-Quads and every RDF format rdflib parses
  • Literal handling (drop or bin numeric literals) and MLflow / W&B experiment tracking
  • The benchmark scripts of the ISWC 2025 paper are in the performance folder

Quick start

from rdf2vecgpu import GPU_RDF2Vec, RDF2VecConfig

# Bundle all hyperparameters in a config object
config = RDF2VecConfig(
    walk_strategy="random",
    walk_depth=4,
    walk_number=100,
    embedding_model="skipgram",
    epochs=5,
    batch_size=None,
    vector_size=100,
    window_size=5,
    min_count=1,
    learning_rate=0.01,
    negative_samples=5,
    random_state=42,
    reproducible=False,
    multi_gpu=False,
    generate_artifact=False,
    cpu_count=20,
)

# Instantiate the pipeline
gpu_rdf2vec_model = GPU_RDF2Vec(config=config)

# Path to the triple dataset
path = "data/wikidata5m/wikidata5m_kg.parquet"

# Read the file, build the vocabulary and the graph
edge_data = gpu_rdf2vec_model.load_data(path)

# Fit the Word2Vec model and transform the dataset to an embedding
embeddings = gpu_rdf2vec_model.fit_transform(edge_df=edge_data)

# Write embedding to file format. Return format is a cuDF dataframe
embeddings.to_parquet("data/wikidata5m/wikidata5m_embeddings.parquet", index=False)
  • Supported file formats:
  • Core RDF2VecConfig parameters (see the configuration reference for defaults and details):
    • Walks: walk_strategy ("random", "bfs"), walk_depth, walk_number, walk_weighted (biased random walks; requires a weights column)
    • Model: embedding_model ("skipgram", "cbow"), backend ("pytorch", "gensim"), vector_size, window_size, min_count, negative_samples, learning_rate
    • Training: epochs, batch_size (if None, Lightning's batch-size tuner picks it on a single GPU), tune_batch_size, random_state, reproducible, cpu_count (gensim worker threads)
    • Execution: multi_gpu (requires a Dask client), num_nodes, generate_artifact
    • Literals: literal_predicates, literal_strategy, literal_n_bins, literal_bin_strategy
    • Tracking: tracker ("none", "mlflow", "wandb"), tracker_kwargs, tracker_run_name

How it works

The data stays on the GPU from loading to training, except for RDF formats that are parsed with rdflib; only the gensim backend trains on the CPU. The design and the benchmarks against CPU-based RDF2Vec implementations are described in the ISWC 2025 paper.

  1. Loading (load_data): the triples are read with cuDF (Dask-cuDF with multi_gpu=True). Every IRI and literal becomes an integer token (word2idx), and the encoded triples form a directed cuGraph MultiGraph, so parallel edges with different predicates are kept.
  2. Walks (fit): every start vertex (by default every subject) is repeated walk_number times and the walks are generated in bulk by cuGraph: uniform_random_walks, or biased_random_walks with walk_weighted=True. The predicate of every step is recovered from the edge that was actually traversed. BFS walks run one cuGraph BFS per start vertex, so their cost grows with the size of the graph. With multi_gpu=True, the walks are generated on all GPUs of the Dask cluster.
  3. Training data (backend="pytorch"): the walks are turned into (center, context) pairs with cuDF and handed to PyTorch through DLPack without leaving the GPU. The data loader indexes into these GPU tensors instead of copying batches.
  4. Training: Skip-gram with negative sampling or CBOW, trained with PyTorch Lightning (Adam, 16-bit mixed precision). On a single GPU, Lightning's batch-size tuner picks the batch size unless batch_size is set or tune_batch_size=False. With multi_gpu=True, the pairs are written to Parquet, the Dask cluster is released, and Lightning trains with DDP: each GPU reads its own block of the pairs and gradients are averaged every step. With backend="gensim", the walks are streamed from Parquet into gensim's Word2Vec on the CPU instead.
  5. Output (transform): the embedding matrix is copied into a cuDF table with one row per token (token, word, embedding_*), optionally written to Parquet.

Contributor notes (the Dask persist / broadcast=True patterns and the cuGraph / dask compatibility patches) are in CONTRIBUTING.md.

License

The overview of the used MIT license can be found here

Roadmap

  • Order aware Word2Vec following the details of Ling, Wang, et al. "Two/too simple adaptations of word2vec for syntax problems.. Issue item
  • Provide spilling to single GPU training to work around potential OOM issues faced during rdf2vec training Issue Item
  • Provide weighted walks for spatial datasets Issue item
  • Provide logging capabilities of complete Word2Vec pipeline for Wandb and mlflow. Issue item
  • Optional gensim Word2Vec trainer backend (backend="gensim") alongside the default PyTorch Lightning trainer. It trains on the CPU and streams the walk corpus from Parquet with constant memory, which suits machines with many CPU cores and few or small GPUs. Available since 0.5.0 (the first PyPI release that contains it); opt in via pip install "rdf2vecgpu[gensim]" and RDF2VecConfig(backend="gensim").

Report issues and bugs

In case you have found a bug or unexpected behaviour, please reach out by opening an issue:

  1. When opening an issue, please tag the issue with the label Bug. Please include the following information:

    • Environment: OS, Python/CUDA/PyTorch/RAPIDS versions (cuDF, cuGraph)
    • Reproduction steps: Exact commands or small code snippet
    • Input data graph format & size (attach a minimal sample if possible)
    • Observed vs. expected behavior
    • Error messages/ stack traces (copy-paste or attach logs)
  2. We aim to respond to open issues within 3 business days

  3. If you have identified a fix, fork the repo, branch off main, implement & test then open a PR referencing the issue. See CONTRIBUTING.md for the development setup, tests and docs build.

Citation

If you use gpuRDF2Vec in your research, please cite the following paper:

@inproceedings{boeckling2025gpurdf2vec,
  author    = {B{\"o}ckling, Martin and Paulheim, Heiko},
  editor    = {Garijo, Daniel and Kirrane, Sabrina and Salatino, Angelo and Shimizu, Cogan and Acosta, Maribel and Nuzzolese, Andrea Giovanni and Ferrada, Sebasti{\'a}n and Soulard, Thibaut and Kozaki, Kouji and Takeda, Hideaki and Gentile, Anna Lisa},
  title     = {{gpuRDF2vec} -- Scalable {GPU}-Based {RDF2vec}},
  booktitle = {The Semantic Web -- {ISWC} 2025},
  series    = {Lecture Notes in Computer Science},
  year      = {2025},
  publisher = {Springer Nature Switzerland},
  address   = {Cham},
  pages     = {240--257},
  isbn      = {978-3-032-09530-5},
  doi       = {10.1007/978-3-032-09530-5_14}
}

Metadata

Release files for rdf2vecgpu 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rdf2vecgpu 0.5.0
File Size Uploaded Provenance Actions
rdf2vecgpu-0.5.0.tar.gz 53.1 kB Without provenance Details for rdf2vecgpu-0.5.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for rdf2vecgpu 0.5.0
File Interpreter ABI Platform Actions
rdf2vecgpu-0.5.0-py3-none-any.whl Python 3 none any Details for rdf2vecgpu-0.5.0-py3-none-any.whl

Total release size: 111.6 kB

Release files / rdf2vecgpu-0.5.0.tar.gz

Download URL rdf2vecgpu-0.5.0.tar.gz
Size 53.1 kB
Tags Source
SHA-256 checksum
How to use checksums
975f4709d156b9b8afa29a40dca8c2e6c08b3f16143050067c46b75ccd43fed1
BLAKE2b-256 checksum
How to use checksums
e6dd186c1be9e6c0284be47f8c9f0831d9b50889ba65981427c3d8fc64e5fa9c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.15 {"installer":{"name":"uv","version":"0.11.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"AlmaLinux","version":"10.2","id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / rdf2vecgpu-0.5.0-py3-none-any.whl

Download URL rdf2vecgpu-0.5.0-py3-none-any.whl
Size 58.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8aa8fd60f05885a32a839a67c1b0259033694f83a5c2604da7e4545a52908779
BLAKE2b-256 checksum
How to use checksums
31f72640f2c4b7734b320e2a00981713e9af0b5474c9f96afd00ee2225ad43d8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.15 {"installer":{"name":"uv","version":"0.11.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"AlmaLinux","version":"10.2","id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for rdf2vecgpu 0.5.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page