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.1.tar.gz (66.9 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.1-py3-none-any.whl (100.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for openukge-1.0.1.tar.gz
Algorithm Hash digest
SHA256 ff67e5958fe67e9673134b76b2d60cae213e6aca5dc26a0764f6ae4c75d9aa8d
MD5 c98cc32e6913881f412368fec5a9760e
BLAKE2b-256 c9b074324e87682d8c228d8de1a459fecd98661cca64966131d2fead322ac079

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for openukge-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b79eb32a8eb7fca7defe0398cc96f7286330f4a6e1ab41ba4f0ac8464912af90
MD5 7e3ad384c1d02e37c1cfb728751ea30f
BLAKE2b-256 e88bdd692b28c8724feaf2c13ceaa64d66ff942b19c6ec9ea5a03608ae0b89ae

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