DeepOnto

repository·main·Indexed 43 days ago

https://github.com/krr-oxford/deeponto

A Python package for ontology engineering using deep learning. It provides tools for ontology alignment via BERTMap and BERTMapLt, subsumption prediction through BERTSubs, and ontology pruning. Version 0.9.3.

Tokens
25.8K
Snippets
76
Records
97
Agent score
56%

What's inside DeepOnto

  1. Available Tools and Resources in DeepOnto

    main

    DeepOnto integrates several specialized systems for ontology engineering:

    • BERTMap: A BERT-based ontology matching (OM) system.
    • Bio-ML: An OM resource used in the OAEI Bio-ML track.
    • BERTSubs: A system for ontology subsumption prediction.
    • OntoLAMA: An evaluation framework for language models in ontology subsumption inference.
    • HiT (External): A hierarchy embedding model (available on Huggingface Hub).
  2. What is BERTMap and how does it work?

    main

    BERTMap is a BERT-based ontology matching (OM) system designed to align ontologies using semantic and structural information. The system operates through five main components:

    1. Text semantics corpora construction: Builds corpora from input ontologies, and optionally from input mappings and auxiliary ontologies.
    2. BERT synonym classifier: A module trained on synonym and non-synonym samples extracted from the text semantics corpora.
    3. Sub-word Inverted Index: A tool used for candidate selection during mapping prediction by indexing tokenized class annotations.
    4. Mapping Predictor: Integrates an edit distance-based string matching module with the fine-tuned BERT synonym classifier. It narrows down target class candidates using the inverted index, applies string matching for 'easy' mappings, and then applies BERT matching for complex ones.
    5. Mapping Refiner: Refines results via two modules:
      • Mapping extension: An iterative process based on the locality principle.
      • Mapping repair: Utilizes the LogMap debugger to fix inconsistencies.

    Note: A lightweight version called BERTMapLt is available, which excludes the BERT module and the mapping refiner.

  3. Use the Taxonomy classes for graph-based machine learning

    main

    DeepOnto provides several taxonomy classes to represent ontological hierarchies as directed graphs, which is useful for graph-based machine learning.

    • Taxonomy: A basic class built upon networkx.DiGraph where nodes represent entities and edges represent subsumptions.
    • OntologyTaxonomy: An extension of Taxonomy that uses a structural reasoner to enrich the ontology with inferred subsumptions (beyond just asserted ones). Each node represents a named class with an rdfs:label attribute. The root node is owl:Thing.
    • WordnetTaxonomy: A wrapper for the WordNet knowledge graph to provide easy access to its hierarchy.
  4. How OntologyVerbaliser works

    main

    The OntologyVerbaliser is a recursive concept verbaliser designed to convert complex ontology concepts into natural language text.

    It operates using a two-step process:

    1. Splitting: It decomposes a complex concept $C$ into a sub-formula tree.
    2. Verbalising & Merging: It verbalises the leaf nodes (atomic concepts or object properties) using their names, then recursively merges these verbalised child nodes based on the logical pattern found at their parent node.

    This approach is based on the methodology proposed in the paper 'Language Model Analysis for Ontology Subsumption Inference' (Findings of ACL 2023).

  5. OntoLAMA Dataset Overview and Task Types

    main

    OntoLAMA is a set of language model (LM) probing datasets designed for ontology subsumption inference (SI) or ontology completion.

    Key concepts:

    • Subsumption Inference (SI): Formulated in a Natural Language Inference (NLI) style. A sub-concept and super-concept are verbalized into a premise and hypothesis using a template.
    • Atomic SI: Involves only atomic named concepts.
    • Complex SI: Involves both atomic and complex concepts.
    • biMNLI: A task derived from MNLI.
  6. Understand the Ontology base class

    main

    The Ontology class is the primary interface for interacting with ontologies in deeponto. It is built as a Python wrapper around the OWLAPI library.

    Key features of the Ontology class include:

    • Special Entity Access: Provides convenient access to standard OWL entities like owl:Thing and owl:Nothing.
    • Entity Indexing: Automatically indexes entities in the ontology's signature using their IRIs as keys for fast lookup.
    • Reasoning Capabilities: Includes an OntologyReasoner attribute that provides facilities for classifying entities, checking entailment, and other reasoning tasks.

    Because it is strongly dependent on OWLAPI, developers familiar with OWLAPI can easily extend these Python classes for custom ontology engineering purposes.

    from deeponto.onto import Ontology
    
    # Example usage (conceptual)
    ontology = Ontology(path_to_file)
    thing = ontology.owl_thing
    reasoner = ontology.ontology_reasoner
  7. Core Ontology Processing Modules

    main

    The deeponto.onto.Ontology class is the main entry point. It provides access to OWLAPI features like querying ancestors/descendants, modifying axioms, and retrieving annotations.

    DeepOnto extends this core with several specialized sub-modules:

    • OntologyReasoner (OntologyReasoner): Conducts reasoning activities like obtaining inferred subsumers/subsumees and checking entailment/consistency.
    • OntologyPruner (OntologyPruner): Extracts sub-ontologies using pruning algorithms.
    • OntologyVerbaliser (OntologyVerbaliser): Transforms complex logical expressions into textual sentences.
    • OntologyProjector (OntologyProjector): Transforms an ontology's TBox into a set of RDF triples (OWL2Vec* algorithm).
    • OntologyNormaliser (OntologyNormaliser): Performs $\mathcal{EL}$ normalisation to support geometric ontology embeddings.
    • OntologyTaxonomy (OntologyTaxonomy): Extracts the subsumption hierarchy as a directed acyclic graph (DAG).
    from deeponto.onto import Ontology
    # The Ontology class is the primary interface for interacting with ontologies
  8. How BERTMap and BERTMapLt work

    main

    BERTMap is a BERT-based ontology alignment system that uses a synonym classifier to find mappings between source and target ontologies. The pipeline follows these steps:

    1. Annotation Indexing: Builds indices from source and target ontologies using selected annotation properties.
    2. Corpus Construction: Creates text semantics corpora (intra-ontology, cross-ontology, and auxiliary).
    3. Training: Splits samples into training/validation sets and fine-tunes a BERT synonym classifier.
    4. Global Matching:
      • Predicts mappings by selecting candidates based on IDF scores from a sub-word inverted index.
      • Calculates mapping scores by averaging synonym scores of annotation combinations.
      • Uses an iterative algorithm based on the locality principle to extend mappings to parents/children (using threshold $\kappa$, default $0.9$).
      • Truncates mappings using threshold $\lambda$ (default $0.9995$).
      • Repairs mappings using a LogMap-based module.

    BERTMapLt is a lightweight version that skips BERT training and mapping refinement, using a fixed string-match threshold of $1.0$.

    Note: For efficiency, set the ontology with the smaller number of classes as the source ontology.

  9. Perform ontology reasoning

    main

    Reasoning tasks are performed via the .reasoner attribute of an Ontology instance. Supported reasoners are Hermit and ELK.

    Inferring Hierarchies

    • Super-entities (Ancestors): Use get_inferred_super_entities(entity, direct=False). Set direct=True to get only immediate parents, or direct=False to get all ancestors.
    • Sub-entities (Descendants): Use get_inferred_sub_entities(entity, direct=False).

    Class Instances and Entailment

    • Get Instances: Use get_instances(class_entity) to retrieve all entailed instances of a class.
    • Check Entailment: Use check_subsumption(potential_sub_entity, potential_super_entity) to verify if one entity is a subclass of another.
    from deeponto.onto import Ontology
    
    doid = Ontology("doid.owl", "elk")
    doid_class = doid.get_owl_object("http://purl.obolibrary.org/obo/DOID_9969")
    
    # 1. Infer ancestors (direct=False returns all ancestors)
    ancestors = doid.reasoner.get_inferred_super_entities(doid_class, direct=False)
    
    # 2. Infer descendants
    descendants = doid.reasoner.get_inferred_sub_entities(doid_class, direct=False)
    
    # 3. Get entailed instances of a class
    instances = doid.reasoner.get_instances(doid_class)
    
    # 4. Check subsumption (entailment)
    is_subsumed = doid.reasoner.check_subsumption(sub_entity, super_entity)
  10. Customize Synonym Annotation Properties

    main

    To improve matching performance, you can specify which annotation properties contain synonym information using config.annotation_property_iris.

    • Usage: Append or delete IRIs in this list to match your specific input ontologies.
    • Safety: It is safe to include IRIs that are not present in your input ontologies; the system will simply ignore them.
  11. How BERTSubs works for subsumption prediction

    main

    BERTSubs is a pipeline for predicting subsumption relationships (whether one class is a subclass of another) using language models like BERT. It operates in two modes:

    1. Intra-ontology subsumption: Predicting relationships between classes within a single ontology.
    2. Inter-ontology subsumption: Predicting relationships between classes across two different ontologies (subsumption mapping).

    The pipeline follows three main stages:

    1. Corpus Construction: Transforming ontology classes into sentence pairs using one of three templates:
      • isolated: Uses only the class names.
      • path: Uses the names of the upper or lower paths starting from the superclass or subclass.
      • traversal (or breadth-first): Uses the names of the surrounding classes in the ontology.
    2. Model Fine-tuning: Fine-tuning a language model (e.g., BERT) on the constructed sentence pairs.
    3. Prediction: Using the fine-tuned model to score candidate class pairs.

    You can optionally provide a train_subsumption_file to assist in the fine-tuning process.

  12. Verbalise complex ontology concepts

    main

    DeepOnto provides a rule-based recursive verbaliser (OntologyVerbaliser) that converts complex logical concept expressions into natural language text. It works by parsing expressions into a sub-formula tree and recursively merging verbalisations from the bottom up. This is particularly useful for preparing textual inputs for language models.

    To use it, initialize an OntologyVerbaliser with an Ontology instance, then use verbalise_class_expression to process complex classes.

    from deeponto.onto import Ontology, OntologyVerbaliser
    
    # Load an ontology and initialize the verbaliser
    onto = Ontology("some_ontology_file.owl")
    verbaliser = OntologyVerbaliser(onto)
    
    # Get complex concepts asserted in the ontology
    complex_concepts = list(onto.get_asserted_complex_classes())
    
    # Verbalise the first complex concept
    v_concept = verbaliser.verbalise_class_expression(complex_concepts[0])
    
    # Access the final verbalised string
    print(v_concept.verbal)