Skip to main content

OntoLearner: A Modular Python Library for Ontology Learning with LLMs.

Project description

OntoLearner Logo

OntoLearner: A Modular Python Library for Ontology Learning with LLMs

PyPI version PyPI Downloads License: MIT Hugging Face Collection pre-commit Documentation Status Maintenance DOI

OntoLearner is a modular and extensible architecture designed to support ontology learning and reuse. The conceptual and functional architecture of OntoLearner is shown as following. The framework comprises three core components—Ontologizers, Learning Tasks, and Learner Models—structured to enable reusable and customizable ontology engineering workflows.

🧪 Installation

OntoLearner is available on PyPI and you can install using pip:

pip install ontolearner

Next, verify the installation:

import ontolearner

print(ontolearner.__version__)

Please refer to Installation page for further options.

🔗 Essential Resources

Resource Info
📚 OntoLearner Documentation OntoLearner's extensive documentation website.
🤗 Datasets on Hugging Face Access curated, machine-readable ontologies.
🚀 Quickstart Get started quickly with OntoLearner’s main features and workflow.
🕸️ Learning Tasks Explore supported ontology learning tasks like LLMs4OL Paradigm tasks and Text2Onto.
🧠 Learner Models Browse and configure various learner models, including LLMs, Retrieval, or RAG approaches.
📚 Ontologies Documentations Review benchmark ontologies and datasets used for evaluation and training.
🧩 How to work with Ontologizer? Learn how to modularize and preprocess ontologies using the Ontologizer module.
🤗 Ontology Metrics Dashboard Benchmark ontologies with their metrics and complexity scores.

🚀 Quick Tour

Get started with OntoLearner in just a few lines of code. This guide demonstrates how to initialize ontologies, load datasets, and train an LLM-assisted learner for ontology engineering tasks.

Basic Usage - Automatic Download from Hugging Face:

from ontolearner import Wine

# 1. Initialize an ontologizer from OntoLearner
ontology = Wine()

# 2. Load the ontology automatically from HuggingFace
ontology.load()

# 3. Extract the learning task dataset
data = ontology.extract()

To see the ontology metadata you can print the ontology:

print(ontology)

Now, explore 150+ ready-to-use ontologies or read on how to work with ontologizers.

Learner Models:

from ontolearner import AutoRetrieverLearner, AgrO, train_test_split, evaluation_report

# 1. Programmatic import of an ontology
ontology = AgrO()
ontology.load()

# 2. Load tasks datasets
ontological_data = ontology.extract()

# 3. Split into train and test sets
train_data, test_data = train_test_split(ontological_data, test_size=0.2, random_state=42)

# 4. Initialize Learner
task = 'non-taxonomic-re'
ret_learner = AutoRetrieverLearner(top_k=5)
ret_learner.load(model_id='sentence-transformers/all-MiniLM-L6-v2')

# 5. Fit the model to training data and then predict over the test data
ret_learner.fit(train_data, task=task)
predicts = ret_learner.predict(test_data, task=task)

# 6. Evaluation
truth = ret_learner.tasks_ground_truth_former(data=test_data, task=task)
metrics = evaluation_report(y_true=truth, y_pred=predicts, task=task)
print(metrics)

Other learners:

LearnerPipeline: The OntoLearner also offers a streamlined LearnerPipeline class that simplifies the entire process of initializing, training, predicting, and evaluating a RAG setup into a single call.

# Import core components from the OntoLearner library
from ontolearner import LearnerPipeline, AgrO, train_test_split

# Load the AgrO ontology, which includes structured agricultural knowledge
ontology = AgrO()
ontology.load()  # Load ontology data (e.g., entities, relations, metadata)

# Extract relation instances from the ontology and split them into training and test sets
train_data, test_data = train_test_split(
    ontology.extract(),      # Extract annotated (head, tail, relation) triples
    test_size=0.2,           # 20% for evaluation
    random_state=42          # Ensures reproducible splits
)

# Initialize the learning pipeline using a dense retriever
pipeline = LearnerPipeline(
    retriever_id='sentence-transformers/all-MiniLM-L6-v2',  # Hugging Face model ID for retrieval
    batch_size=10,       # Number of samples to process per batch (if batching is enabled internally)
    top_k=5              # Retrieve top-5 most relevant support instance per query
)

# Run the pipeline on the training and test data
# The pipeline performs: fit() → predict() → evaluate() in sequence
outputs = pipeline(
    train_data=train_data,
    test_data=test_data,
    evaluate=True,           # If True, computes precision, recall, and F1-score
    task='non-taxonomic-re'  # Specifies that we are doing non-taxonomic relation prediction
)

# Print the evaluation metrics (precision, recall, F1)
print("Metrics:", outputs['metrics'])

# Print the total elapsed time for training and evaluation
print("Elapsed time:", outputs['elapsed_time'])

# Print the full output dictionary (includes predictions)
print(outputs)

⭐ Contribution

We welcome contributions to enhance OntoLearner and make it even better! Please review our contribution guidelines in CONTRIBUTING.md before getting started. You are also welcome to assist with the ongoing maintenance by referring to MAINTENANCE.md. Your support is greatly appreciated.

If you encounter any issues or have questions, please submit them in the GitHub issues tracker.

💡 Acknowledgements

If you find this repository helpful or use OntoLearner in your work or research, feel free to cite our publication:

@inproceedings{babaei2023llms4ol,
  title={LLMs4OL: Large language models for ontology learning},
  author={Babaei Giglou, Hamed and D’Souza, Jennifer and Auer, S{\"o}ren},
  booktitle={International Semantic Web Conference},
  pages={408--427},
  year={2023},
  organization={Springer}
}

or:

@software{babaei_giglou_2025_15399783,
  author       = {Babaei Giglou, Hamed and D'Souza, Jennifer and Aioanei, Andrei and Mihindukulasooriya, Nandana and Auer, Sören},
  title        = {OntoLearner: A Modular Python Library for Ontology Learning with LLMs},
  month        = may,
  year         = 2025,
  publisher    = {Zenodo},
  version      = {v1.3.0},
  doi          = {10.5281/zenodo.15399783},
  url          = {https://doi.org/10.5281/zenodo.15399783},
}

This software is archived in Zenodo under the DOI DOI and is licensed under License: MIT.

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

ontolearner-1.4.9.tar.gz (493.0 kB view details)

Uploaded Source

Built Distribution

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

ontolearner-1.4.9-py3-none-any.whl (221.7 kB view details)

Uploaded Python 3

File details

Details for the file ontolearner-1.4.9.tar.gz.

File metadata

  • Download URL: ontolearner-1.4.9.tar.gz
  • Upload date:
  • Size: 493.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.10.19 Linux/6.11.0-1018-azure

File hashes

Hashes for ontolearner-1.4.9.tar.gz
Algorithm Hash digest
SHA256 9ecbb131afcf331c7b3022ffd5b47ddfc2ced3590d67473dd04b8fe46067307a
MD5 28d09d76388bc1cbe858f71f11d8d5c4
BLAKE2b-256 58b9b3be27e4c30c49afe6a95b06266029a730c6d98398551d9d8b42be9611dc

See more details on using hashes here.

File details

Details for the file ontolearner-1.4.9-py3-none-any.whl.

File metadata

  • Download URL: ontolearner-1.4.9-py3-none-any.whl
  • Upload date:
  • Size: 221.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.10.19 Linux/6.11.0-1018-azure

File hashes

Hashes for ontolearner-1.4.9-py3-none-any.whl
Algorithm Hash digest
SHA256 d6326ea5e218e9d89aca37f24b05bc1c347186af12fcffadd36e0985a4360086
MD5 afb0ac71a475066d41daec08fdce7357
BLAKE2b-256 f7ea4cb3fee9603c66b2d3835f0d3bd3df280a553fa2763d7ffa6039531e5c0f

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