OpenUKGE: An open-source Python library for uncertain knowledge graph embedding
Project description
OpenUKGE
An Open‑Source Python Library for Uncertain Knowledge Graph Embedding
🌍 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_datasetutility - 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:
- Different hardware configurations require different PyTorch builds.
- Official recommendation: PyTorch developers advise users to install it manually using the appropriate wheel for their environment.
- 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
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 directorynl27k_UKGE_demo.py– example demonstration scriptrequirements.txt– python dependenciesLICENSE– 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:
- PyTorch
- UKGE (Chen et al., 2019)
- UKGsE (Yang et al., 2020)
- PASSLEAF (Chen et al., 2021)
- BEUrRE (Chen et al., 2021)
- unKR (Wang et al., 2024)
💡 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file openukge-1.0.0.tar.gz.
File metadata
- Download URL: openukge-1.0.0.tar.gz
- Upload date:
- Size: 66.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dcb4f2b846224a3d821ffc1985a3bdfd7732e3b88fd8134c3c186280fb0ce95c
|
|
| MD5 |
bc83f116b496ff994f6f61999c157681
|
|
| BLAKE2b-256 |
7b004635ab9618374cedcbe43acd17609d19d14dc37aae3a51c688a8decc4713
|
File details
Details for the file openukge-1.0.0-py3-none-any.whl.
File metadata
- Download URL: openukge-1.0.0-py3-none-any.whl
- Upload date:
- Size: 100.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5cae34c53a81a681d10c1c7c6b389b5a1177b644ad5814c550a3dde4d18b0742
|
|
| MD5 |
87f262c9ab956a2b01aaf42d1524dc17
|
|
| BLAKE2b-256 |
8ec08f2318e45962a13d214a6719dd77a5262c09ae0f317c90ed7114c257e08b
|