OnT is a language model-based framework for ontology embeddings, enabling effective representation of concepts as points in hyperbolic space and axioms as hierarchical relationships between concepts. Built upon the HierarchyTransformer, this implementation provides enhanced capabilities for ontological reasoning through specialized embedding techniques such as concept rotation, transition, and existential quantifier representation. The model has been trained on various biomedical ontologies including GO, GALEN, and ANATOMY datasets. For the test of geometric-embedding methods, please refer to the BoxSquaredEL and TransBox.
The easiest way to get started is to install the package from PyPI ontology-transformer:
pip install ontology-transformer
The distribution is named ontology-transformer, while its Python import package is
lowercase ont. The root-level OnT.py file is retained as legacy research code and
is not the module installed from PyPI.
You can fine-tune the model directly from your OWL ontology file without any manual preprocessing:
from ont import OntologyTransformer
# Simply provide your OWL file path - that's it!
model = OntologyTransformer.fit(
owl_path="path/to/your/ontology.owl", # Your ontology file
output_dir="./my_ontology_model",
num_epochs=5,
batch_size=128,
eval_ratio=0.1 # Use 10% for evaluation
)
# The model is now fine-tuned on your ontology
# Use it immediately for encoding
embeddings = model.encode(["YourConcept1", "YourConcept2"])
# Save for later use
model.save("./my_ontology_model/final")
The data and models folders should be downloaded and unzipped to the root directory. The Google Drive links are all anonymous.
OnT.py: Main model implementation containing the OntologyTransformer class
data/: Contains training and testing data, download from here or from Zenodo View Dataset on Zenodo
models/: Stores pre-trained and fine-tuned models, download from here or from huggingface View Models on Hugging Face
normalization/: Scripts for normalizing the EL part of a given ontology. See normalization/Readme.md for details.
We recommend using Conda for a reproducible setup. The steps below install PyTorch, HierarchyTransformers, and a compatible sentence-transformers version, then perform a quick verification.
conda create -y -n ont python=3.12
conda activate ont
conda install -y pytorch torchvision torchaudio pytorch-cuda=12.1 -c pytorch -c nvidia
ontology-transformer supports sentence-transformers>=3.0, including 6.x; no 3.4.0 pin is required.pip install git+https://github.com/KRR-Oxford/HierarchyTransformers.git
pip install 'sentence-transformers>=3.0'
Then load the model and use it for inference or training as follows.
import torch
from ont import OntologyTransformer
# Load from Hugging Face (recommended)
ont = OntologyTransformer.from_pretrained('Hui97/OnT-MiniLM-L12-galen')
# entity names to be encoded.
entity_names = ["continuant", "occurrent", "independent continuant", "process"]
# get the entity embeddings
entity_embeddings = ont.encode(entity_names)
# role sentences to be encoded.
role_sentences = ["application attribute", "attribute", "chemical modifier", "chemical process modifier attribute"]
# get the role embeddings, consist of the rotation and scaling (regarded as 1 by default for model uploaded to huggingface)
role_rotations, _ = ont.encode_roles(role_sentences)
For training, run the following command. Remember to update the dataset_path and dataset_name in config.yaml :
python train_ont.py -c config.yaml
The following models are available on Hugging Face and can be loaded directly:
| Model Name | Base Model | Dimension | Training Dataset |
|---|---|---|---|
Hui97/OnT-MPNet-galen | MPNet | 768 | GALEN |
Hui97/OnT-MPNet-anatomy | MPNet | 768 | ANATOMY |
Hui97/OnT-MPNet-go | MPNet | 768 | GO |
Hui97/OnT-MiniLM-L12-galen | MiniLM-L12 | 384 | GALEN |
Hui97/OnT-MiniLM-L12-anatomy | MiniLM-L12 | 384 | ANATOMY |
Hui97/OnT-MiniLM-L12-go | MiniLM-L12 | 384 | GO |
All models can be loaded using:
from ont import OntologyTransformer
ont = OntologyTransformer.from_pretrained('Hui97/OnT-MiniLM-L12-galen')
43 commits
1 commits
Python
100.0%
OnT is a language model-based framework for ontology embeddings, enabling effective representation of concepts as points in hyperbolic space and axioms as hierarchical relationships between concepts. Built upon the HierarchyTransformer, this implementation provides enhanced capabilities for ontological reasoning through specialized embedding techniques such as concept rotation, transition, and existential quantifier representation. The model has been trained on various biomedical ontologies including GO, GALEN, and ANATOMY datasets. For the test of geometric-embedding methods, please refer to the BoxSquaredEL and TransBox.
The easiest way to get started is to install the package from PyPI ontology-transformer:
pip install ontology-transformer
The distribution is named ontology-transformer, while its Python import package is
lowercase ont. The root-level OnT.py file is retained as legacy research code and
is not the module installed from PyPI.
You can fine-tune the model directly from your OWL ontology file without any manual preprocessing:
from ont import OntologyTransformer
# Simply provide your OWL file path - that's it!
model = OntologyTransformer.fit(
owl_path="path/to/your/ontology.owl", # Your ontology file
output_dir="./my_ontology_model",
num_epochs=5,
batch_size=128,
eval_ratio=0.1 # Use 10% for evaluation
)
# The model is now fine-tuned on your ontology
# Use it immediately for encoding
embeddings = model.encode(["YourConcept1", "YourConcept2"])
# Save for later use
model.save("./my_ontology_model/final")
The data and models folders should be downloaded and unzipped to the root directory. The Google Drive links are all anonymous.
OnT.py: Main model implementation containing the OntologyTransformer class
data/: Contains training and testing data, download from here or from Zenodo View Dataset on Zenodo
models/: Stores pre-trained and fine-tuned models, download from here or from huggingface View Models on Hugging Face
normalization/: Scripts for normalizing the EL part of a given ontology. See normalization/Readme.md for details.
We recommend using Conda for a reproducible setup. The steps below install PyTorch, HierarchyTransformers, and a compatible sentence-transformers version, then perform a quick verification.
conda create -y -n ont python=3.12
conda activate ont
conda install -y pytorch torchvision torchaudio pytorch-cuda=12.1 -c pytorch -c nvidia
ontology-transformer supports sentence-transformers>=3.0, including 6.x; no 3.4.0 pin is required.pip install git+https://github.com/KRR-Oxford/HierarchyTransformers.git
pip install 'sentence-transformers>=3.0'
Then load the model and use it for inference or training as follows.
import torch
from ont import OntologyTransformer
# Load from Hugging Face (recommended)
ont = OntologyTransformer.from_pretrained('Hui97/OnT-MiniLM-L12-galen')
# entity names to be encoded.
entity_names = ["continuant", "occurrent", "independent continuant", "process"]
# get the entity embeddings
entity_embeddings = ont.encode(entity_names)
# role sentences to be encoded.
role_sentences = ["application attribute", "attribute", "chemical modifier", "chemical process modifier attribute"]
# get the role embeddings, consist of the rotation and scaling (regarded as 1 by default for model uploaded to huggingface)
role_rotations, _ = ont.encode_roles(role_sentences)
For training, run the following command. Remember to update the dataset_path and dataset_name in config.yaml :
python train_ont.py -c config.yaml
The following models are available on Hugging Face and can be loaded directly:
| Model Name | Base Model | Dimension | Training Dataset |
|---|---|---|---|
Hui97/OnT-MPNet-galen | MPNet | 768 | GALEN |
Hui97/OnT-MPNet-anatomy | MPNet | 768 | ANATOMY |
Hui97/OnT-MPNet-go | MPNet | 768 | GO |
Hui97/OnT-MiniLM-L12-galen | MiniLM-L12 | 384 | GALEN |
Hui97/OnT-MiniLM-L12-anatomy | MiniLM-L12 | 384 | ANATOMY |
Hui97/OnT-MiniLM-L12-go | MiniLM-L12 | 384 | GO |
All models can be loaded using:
from ont import OntologyTransformer
ont = OntologyTransformer.from_pretrained('Hui97/OnT-MiniLM-L12-galen')
43 commits
1 commits
Python
100.0%