gpuRDF2Vec
A scalable GPU based implementation of RDF2Vec embeddings for large and dense Knowledge Graphs.
Table of contents
The content of this repository readme can be found here:
- gpuRDF2Vec
- Table of contents
- Package installation
- gpuRDF2Vec overview
- Quick start
- How it works
- License
- Roadmap
- Report issues and bugs
- Citation
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 scripts and pinned environments used for the ISWC 2025 benchmarks (gpuRDF2Vec and the
baselines) are in the v0.5.0 tag.
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/ # end-to-end benchmark harness and chart generator
└── 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, CBOW and order-aware skip-gram (RDF2Vec_oa) training on the GPU with PyTorch Lightning (single- or multi-GPU DDP), or skip-gram and CBOW on the CPU with gensim
- Walks generated once and trained on later:
prepare_corpuswrites them to Parquet,fit_from_walkstrains from the files - 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
- Benchmarks against jRDF2Vec and pyRDF2Vec: performance page
- The benchmark harness is in the performance folder; the scripts of the ISWC 2025 paper are in the
v0.5.0tag
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,
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:
.csv(with a header row).parquet.orc.nt,.nq- All supported RDFlib file formats
- Core
RDF2VecConfigparameters (see the configuration reference for defaults and details):- Walks:
walk_strategy("random","bfs"),walk_depth,walk_number,walk_weighted(biased random walks; requires aweightscolumn) - Model:
embedding_model("skipgram","cbow","order_aware_skipgram"),backend("pytorch","gensim"),vector_size,window_size,min_count,negative_samples - Training:
epochs,batch_size(training pairs per step, default 32768),learning_rate,min_learning_rate,sample(frequent-token subsampling),shrink_window,grad_clip_value,random_state,reproducible,cpu_count(gensim worker threads) - Execution:
multi_gpu(load_datarequires 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
- Walks:
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.
- Loading (
load_data): the triples are read with cuDF (Dask-cuDF withmulti_gpu=True). Every IRI and literal becomes an integer token (word2idx), and the encoded triples form a directed cuGraphMultiGraph, so parallel edges with different predicates are kept. - Walks (
fit): every start vertex (by default every subject) is repeatedwalk_numbertimes and the walks are generated in bulk by cuGraph:uniform_random_walks, orbiased_random_walkswithwalk_weighted=True. The predicate of every step is recovered from the edge that was actually traversed. On one GPU the walks are generated in chunks of up to 25 M walks and kept as int32 token matrices. BFS walks run one cuGraph BFS per start vertex and give one walk per root-to-leaf path, so their cost grows with the size of the graph. Withmulti_gpu=True, the walks are generated on all GPUs of the Dask cluster.prepare_corpuswrites the walks to Parquet instead, andfit_from_walkstrains from those files later, without the graph. - Training data (
backend="pytorch"): the walks stay in GPU memory as sequences. Every step takes a shuffled batch of walks, drops frequent tokens (sample, as in word2vec) and builds the (center, context) pairs of that batch on the GPU. Steps are sized to hold aboutbatch_sizepairs (default 32768) after subsampling and walks that end early. Withmulti_gpu=True, the walks are written to Parquet, the Dask client is closed, and each GPU reads its own block. - Training: skip-gram, CBOW or order-aware skip-gram with negative sampling, trained with
PyTorch Lightning the way word2vec trains: summed loss, sparse SGD with a learning rate that
decays linearly from
learning_ratetomin_learning_rate, and negatives drawn by token frequency^0.75. Withmulti_gpu=True, Lightning trains with DDP and averages the gradients every step. Withbackend="gensim", the walks are streamed from Parquet into gensim's Word2Vec on the CPU instead. - 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 viapip install "rdf2vecgpu[gensim]"andRDF2VecConfig(backend="gensim").
Report issues and bugs
In case you have found a bug or unexpected behaviour, please reach out by opening an issue:
-
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)
-
We aim to respond to open issues within 3 business days
-
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.6.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| rdf2vecgpu-0.6.0.tar.gz | 71.2 kB | Without provenance | Details for rdf2vecgpu-0.6.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| rdf2vecgpu-0.6.0-py3-none-any.whl | Python 3 | none | any | Details for rdf2vecgpu-0.6.0-py3-none-any.whl |
Total release size: 148.7 kB
Release files / rdf2vecgpu-0.6.0.tar.gz
| Download URL | rdf2vecgpu-0.6.0.tar.gz |
|---|---|
| Size | 71.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ba6666fee4d55a5702b0ee61dc78634498a9e787c2570ec58f1a4d24691b8495
|
|
BLAKE2b-256 checksum How to use checksums |
b0b1214102b9e037fa395b1cc2eb1e6318e0629e3eb2699660dde3a91bc8aef9
|
| 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.6.0-py3-none-any.whl
| Download URL | rdf2vecgpu-0.6.0-py3-none-any.whl |
|---|---|
| Size | 77.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
685a19275ecf60b02db35d0cfd90036b127d14f536750a475c0f8ef59a13fc91
|
|
BLAKE2b-256 checksum How to use checksums |
9cf3044bc769663f5006dc3f3d9f4247c8a11e21d29e14b87ff488d70fe1d8ed
|
| 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.6.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.