Ontolearn is an open-source software library for structured machine learning in Python. Ontolearn includes modules for processing knowledge bases, inductive logic programming and ontology engineering.
Project description
Ontolearn
Ontolearn is an open-source software library for description logic learning problem. Find more in the Documentation.
Learning algorithms:
- Drill → Neuro-Symbolic Class Expression Learning
- EvoLearner → EvoLearner: Learning Description Logics with Evolutionary Algorithms
- NCES2 → (soon) Neural Class Expression Synthesis in ALCHIQ(D)
- NCES → Neural Class Expression Synthesis
- NERO → (soon) Learning Permutation-Invariant Embeddings for Description Logic Concepts
- CLIP → (soon) Learning Concept Lengths Accelerates Concept Learning in ALC
- CELOE → Class Expression Learning for Ontology Engineering
- OCEL → A limited version of CELOE
Installation
pip install ontolearn
or
git clone https://github.com/dice-group/Ontolearn.git && conda create --name onto python=3.8.18 && conda activate onto
pip3 install -e . && python -c "import ontolearn"
wget https://files.dice-research.org/projects/Ontolearn/KGs.zip -O ./KGs.zip && unzip KGs.zip
pytest -p no:warnings -x # Running 158 tests takes ~ 3 mins
Description Logic Concept Learning
from ontolearn.concept_learner import CELOE
from ontolearn.knowledge_base import KnowledgeBase
from ontolearn.learning_problem import PosNegLPStandard
from ontolearn.search import EvoLearnerNode
from owlapy.model import OWLClass, OWLClassAssertionAxiom, OWLNamedIndividual, IRI, OWLObjectProperty, OWLObjectPropertyAssertionAxiom
from owlapy.render import DLSyntaxObjectRenderer
# (1) Load a knowledge graph.
kb = KnowledgeBase(path='KGs/father.owl')
# (2) Initialize a learner.
model = CELOE(knowledge_base=kb)
# (3) Define a description logic concept learning problem.
lp = PosNegLPStandard(pos={OWLNamedIndividual(IRI.create("http://example.com/father#stefan")),
OWLNamedIndividual(IRI.create("http://example.com/father#markus")),
OWLNamedIndividual(IRI.create("http://example.com/father#martin"))},
neg={OWLNamedIndividual(IRI.create("http://example.com/father#heinz")),
OWLNamedIndividual(IRI.create("http://example.com/father#anna")),
OWLNamedIndividual(IRI.create("http://example.com/father#michelle"))})
# (4) Learn description logic concepts best fitting (3).
dl_classifiers=model.fit(learning_problem=lp).best_hypotheses(2)
# (5) Inference over unseen individuals
namespace = 'http://example.com/father#'
# (6) New Individuals
julia = OWLNamedIndividual(IRI.create(namespace, 'julia'))
julian = OWLNamedIndividual(IRI.create(namespace, 'julian'))
thomas = OWLNamedIndividual(IRI.create(namespace, 'thomas'))
# (7) OWLClassAssertionAxiom about (6)
male = OWLClass(IRI.create(namespace, 'male'))
female = OWLClass(IRI.create(namespace, 'female'))
axiom1 = OWLClassAssertionAxiom(individual=julia, class_expression=female)
axiom2 = OWLClassAssertionAxiom(individual=julian, class_expression=male)
axiom3 = OWLClassAssertionAxiom(individual=thomas, class_expression=male)
# (8) OWLObjectPropertyAssertionAxiom about (6)
has_child = OWLObjectProperty(IRI.create(namespace, 'hasChild'))
# Existing Individuals
anna = OWLNamedIndividual(IRI.create(namespace, 'anna'))
markus = OWLNamedIndividual(IRI.create(namespace, 'markus'))
michelle = OWLNamedIndividual(IRI.create(namespace, 'michelle'))
axiom4 = OWLObjectPropertyAssertionAxiom(subject=thomas, property_=has_child, object_=julian)
axiom5 = OWLObjectPropertyAssertionAxiom(subject=julia, property_=has_child, object_=julian)
# 4. Use loaded class expressions for predictions
predictions = model.predict(individuals=[julia, julian, thomas, anna, markus, michelle],
axioms=[axiom1, axiom2, axiom3, axiom4, axiom5],
hypotheses=dl_classifiers)
print(predictions)
"""
(¬female) ⊓ (∃ hasChild.⊤) male
julia 0.0 0.0
julian 0.0 1.0
thomas 1.0 1.0
anna 0.0 0.0
markus 1.0 1.0
michelle 0.0 0.0
"""
Fore more please refer to the examples folder.
Deployment
pip install gradio
To deploy EvoLearner on the Family knowledge graph. Available models to deploy: EvoLearner, NCES, CELOE and OCEL.
python deploy_cl.py --model evolearner --path_knowledge_base KGs/Family/family-benchmark_rich_background.owl
Run the help command to see the description on this script usage:
python deploy_cl.py --help
Citing
Currently, we are working on our manuscript describing our framework. If you find our work useful in your research, please consider citing the respective paper:
# DRILL
@inproceedings{demir2023drill,
author = {Demir, Caglar and Ngomo, Axel-Cyrille Ngonga},
booktitle = {The 32nd International Joint Conference on Artificial Intelligence, IJCAI 2023},
title = {Neuro-Symbolic Class Expression Learning},
url = {https://www.ijcai.org/proceedings/2023/0403.pdf},
year={2023}
}
# NCES2
@inproceedings{kouagou2023nces2,
author={Kouagou, N'Dah Jean and Heindorf, Stefan and Demir, Caglar and Ngonga Ngomo, Axel-Cyrille},
title={Neural Class Expression Synthesis in ALCHIQ(D)},
url = {https://papers.dice-research.org/2023/ECML_NCES2/NCES2_public.pdf},
booktitle={Machine Learning and Knowledge Discovery in Databases},
year={2023},
publisher={Springer Nature Switzerland},
address="Cham"
}
# NCES
@inproceedings{kouagou2023neural,
title={Neural class expression synthesis},
author={Kouagou, N’Dah Jean and Heindorf, Stefan and Demir, Caglar and Ngonga Ngomo, Axel-Cyrille},
booktitle={European Semantic Web Conference},
pages={209--226},
year={2023},
publisher={Springer Nature Switzerland}
}
# EvoLearner
@inproceedings{heindorf2022evolearner,
title={Evolearner: Learning description logics with evolutionary algorithms},
author={Heindorf, Stefan and Bl{\"u}baum, Lukas and D{\"u}sterhus, Nick and Werner, Till and Golani, Varun Nandkumar and Demir, Caglar and Ngonga Ngomo, Axel-Cyrille},
booktitle={Proceedings of the ACM Web Conference 2022},
pages={818--828},
year={2022}
}
# CLIP
@inproceedings{kouagou2022learning,
title={Learning Concept Lengths Accelerates Concept Learning in ALC},
author={Kouagou, N’Dah Jean and Heindorf, Stefan and Demir, Caglar and Ngonga Ngomo, Axel-Cyrille},
booktitle={European Semantic Web Conference},
pages={236--252},
year={2022},
publisher={Springer Nature Switzerland}
}
In case you have any question, please contact: onto-learn@lists.uni-paderborn.de
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
Hashes for ontolearn-0.6.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ba13ce0825c50c517b490e4e83b10db3b05338e40c8709e6337e92eef3dd86ff |
|
MD5 | 06e90649bab0e7c74799ba5e4a68cbe0 |
|
BLAKE2b-256 | ab0ef3bff524e52b198ca4fc6ae69ff1c803b5f200bb9c66819d9d4adb76a643 |