Skip to main content

OpenUKGE: An open-source Python library for uncertain knowledge graph embedding

Project description

OpenUKGE

An Open‑Source Python Library for Uncertain Knowledge Graph Embedding

License Python PyTorch

🌍 Overview

Uncertain knowledge graphs (UKGs), which associate each triple with a confidence score, enable more reliable knowledge completion and uncertainty-aware reasoning compared to deterministic knowledge graphs. However, heterogeneous implementations, diverse programming languages, and inconsistent evaluation settings of existing uncertain knowledge graph embedding (UKGE) methods hinder fair comparison and practical adoption.

OpenUKGE addresses these challenges by providing a unified, reproducible Python framework for UKGE research, supporting standardized model implementation, dataset integration, and evaluation protocols.

🧩 Key Features

  • Native UKG Support: Natively processes quadruples of the form (head, relation, tail, confidence)
  • Unified Model Interface: Multiple UKGE models with consistent APIs for easy comparison
  • Benchmark Datasets: Integrated with standard UKG datasets (cn15k, nl27k, ppi5k, onet20k) and few-shot variants, with automatic download support via download_dataset utility
  • Comprehensive Evaluation: Supports confidence prediction (MSE, MAE, ECE), link prediction (MR, MRR, Hit@k), and ranking quality (nDCG) metrics
  • Advanced Training Utilities: Includes specialized trainers with semi-supervised learning and few-shot learning support
  • High Reproducibility: Standardized experimental pipelines to ensure consistent and comparable results
  • Extensible Architecture: Easy to extend with new models, datasets, or evaluation metrics

📦 Installation

1. Install PyTorch for your system

⚙️OpenUKGE depends on PyTorch, but it is not included in the default dependency list. The reason is:

  1. Different hardware configurations require different PyTorch builds.
  2. Official recommendation: PyTorch developers advise users to install it manually using the appropriate wheel for their environment.
  3. Avoiding compatibility issues: Including PyTorch directly in install_requires often causes failed installations or large downloads on systems without matching CUDA libraries.

Example for torch 2.3.0 + CUDA 12.1:

pip install torch==2.3.0+cu121 -f https://download.pytorch.org/whl/torch_stable.html

Example (CPU-only):

pip install torch --index-url https://download.pytorch.org/whl/cpu

2. Install OpenUKGE package

  • Install from source
git clone https://github.com/Chienking1997/OpenUKGE.git  
cd OpenUKGE  
pip install .
  • Install by pypi
pip install OpenUKGE

🚀 Quick Start

You can quickly start training with one of the example scripts under the examples/ directory.
For instance, to train on the NL27K dataset using the UKGE model:

python examples/nl27k/UKGE/nl27k_UKGE_train.py

Other example scripts for different datasets and models are available in the examples/ folder (e.g., cn15k, nl27k, ppi5k, etc.).

Take training the UKGE model using the NL27K dataset as an example.

1️⃣ Import the required modules

from openukge.data import nl27k
from openukge.models import UKGE
from openukge.training import UKGETrainer, OptimBuilder, EarlyStop
from openukge.loss import UKGELoss
from openukge.utils import seed_everything

2️⃣ Fix seeds, load data, define model, loss, optimizer & early stopping for modules

seed_everything()
data = nl27k.load_data('data', num_neg=10, batch_size=512)
model = UKGE(data.num_ent, data.num_rel, emb_dim=128)
loss = UKGELoss()
opt = {'optimizer': {'type': 'Adam', 'lr': 0.001}}
optimizer = OptimBuilder(opt)
early_stop = EarlyStop(patience=2, min_delta=0, 
                       monitor="mse", mode="min", 
                       monitor_mode="tail")

3️⃣ Train and valid the model

trainer = UKGETrainer(data, model, loss, 
                      optimizer, early_stop, 
                      save_path="best_nl27k-mse.pt")
trainer.fit(epochs=100, eval_freq=2)

4️⃣ Output the comprehensive evaluation results of the model

trainer.test()

📂 Project Structure (overview)

  • openukge/ – main source code directory
  • nl27k_UKGE_demo.py – example demonstration script
  • requirements.txt – python dependencies
  • LICENSE – GPL‑3.0 Open Source License

🪪 License

This project is licensed under the GNU General Public License v3.0 (GPL‑3.0).

See LICENSE for details.

🤝 Acknowledgements

OpenUKGE builds upon:


💡 Contributing

Contributions are very welcome. You can:

  • Submit issues to report bugs or request features
  • Fork the repository and create pull requests
  • Extend the framework by adding new models, new datasets, or new evaluation metrics

📬 Contact

For questions, suggestions, or collaborations:
📧 chienking1997@outlook.com

We hope OpenUKGE becomes your go‑to tool for uncertain knowledge graph representation learning and drives advancement in this research area.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

openukge-1.0.2.tar.gz (67.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

openukge-1.0.2-py3-none-any.whl (100.6 kB view details)

Uploaded Python 3

File details

Details for the file openukge-1.0.2.tar.gz.

File metadata

  • Download URL: openukge-1.0.2.tar.gz
  • Upload date:
  • Size: 67.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.20

File hashes

Hashes for openukge-1.0.2.tar.gz
Algorithm Hash digest
SHA256 cc6a13265c9ec20d9a61c951fdd314aa69d32f6f8fbc0b96bc17eb768af91231
MD5 2e0fb21d99b7821e857f68f96b7d4817
BLAKE2b-256 29a5166bff828683c6cfba28cd11efe4f2c34be0dd40277ba62c31dbcdf18e24

See more details on using hashes here.

File details

Details for the file openukge-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: openukge-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 100.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.20

File hashes

Hashes for openukge-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 dada6ba40b99882004783ad025515297c3b1ca298aaffb7ab59e6a080e41ca10
MD5 f2ce8ee7490f041168087ba0eb2888e6
BLAKE2b-256 a11394e9570df33502fe4796e015d0fb624713b8f46189c6470d9153af851ec6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page