.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/elmodels/plot_1_elembeddings.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_elmodels_plot_1_elembeddings.py: EL Embeddings =============== This example corresponds to the paper `EL Embeddings: Geometric Construction of Models for the Description Logic EL++ `_. The idea of this paper is to embed EL by modeling ontology classes as :math:`n`-dimensional balls (:math:`n`-balls) and ontology object properties as transformations of those :math:`n`-balls. For each of the normal forms, there is a distance function defined that will work as loss functions in the optimization framework. .. GENERATED FROM PYTHON SOURCE LINES 15-16 Let's just define the imports that will be needed along the example: .. GENERATED FROM PYTHON SOURCE LINES 16-23 .. code-block:: Python import mowl mowl.init_jvm("10g") import torch as th .. GENERATED FROM PYTHON SOURCE LINES 24-40 The EL-Embeddings model, maps ontology classes, object properties and operators into a geometric model. The :math:`\mathcal{EL}` description logic is expressed using the following General Concept Inclusions (GCIs): .. math:: \begin{align} C &\sqsubseteq D & (\text{GCI 0}) \\ C_1 \sqcap C_2 &\sqsubseteq D & (\text{GCI 1}) \\ C &\sqsubseteq \exists R. D & (\text{GCI 2})\\ \exists R. C &\sqsubseteq D & (\text{GCI 3})\\ C &\sqsubseteq \bot & (\text{GCI BOT 0}) \\ C_1 \sqcap C_2 &\sqsubseteq \bot & (\text{GCI BOT 1}) \\ \exists R. C &\sqsubseteq \bot & (\text{GCI BOT 3}) \end{align} where :math:`C,C_1, C_2,D` are ontology classes and :math:`R` is an ontology object property .. GENERATED FROM PYTHON SOURCE LINES 42-60 EL-Embeddings (PyTorch) module. ------------------------------- EL-Embeddings defines a geometric modelling for all the GCIs in the EL language. The implementation of ELEmbeddings module can be found at :class:`mowl.nn.el.elem.module.ELEmModule`. EL-Embeddings model ------------------- The module :class:`mowl.nn.el.elem.module.ELEmModule` is used in the :class:`mowl.models.elembeddings.model.ELEmbeddings`. In the use case of this example, we will test over a biological problem, which is protein-protein interactions. Given two proteins :math:`p_1,p_2`, the phenomenon ":math:`p_1` interacts with :math:`p_2`" is encoded using GCI 2 as: .. math:: p_1 \sqsubseteq \exists interacts\_with. p_2 For that, we can use the class :class:`mowl.models.elembeddings.examples.model_ppi.ELEmPPI` mode, which uses the :class:`mowl.datasets.builtin.PPIYeastSlimDataset` dataset. .. GENERATED FROM PYTHON SOURCE LINES 63-65 Training the model ------------------- .. GENERATED FROM PYTHON SOURCE LINES 65-85 .. code-block:: Python from mowl.datasets.builtin import PPIYeastSlimDataset from mowl.models.elembeddings.examples.model_ppi import ELEmPPI dataset = PPIYeastSlimDataset() model = ELEmPPI(dataset, embed_dim=30, margin=0.1, reg_norm=1, learning_rate=0.001, epochs=20, batch_size=20000, model_filepath=None, device='cuda') model.train() .. rst-class:: sphx-glr-script-out .. code-block:: none 0%| | 0/20 [00:00` class. .. GENERATED FROM PYTHON SOURCE LINES 91-99 .. code-block:: Python from mowl.evaluation import PPIEvaluator model.set_evaluator(PPIEvaluator) model.evaluate(dataset.testing) print(model.metrics) .. rst-class:: sphx-glr-script-out .. code-block:: none {'mr': 2464.669435215947, 'mrr': 0.0024686094502139495, 'f_mr': 2464.669435215947, 'f_mrr': 0.0024686094502139495, 'auc': 0.5919726009910654, 'f_auc': 0.5919726009910654, 'hits@1': 0.00016611295681063124, 'hits@3': 0.0009966777408637873, 'hits@10': 0.0027408637873754154, 'hits@50': 0.016777408637873754, 'hits@100': 0.03106312292358804, 'f_hits@1': 0.00016611295681063124, 'f_hits@3': 0.0009966777408637873, 'f_hits@10': 0.0027408637873754154, 'f_hits@50': 0.016777408637873754, 'f_hits@100': 0.03106312292358804} .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 36.813 seconds) **Estimated memory usage:** 2066 MB .. _sphx_glr_download_examples_elmodels_plot_1_elembeddings.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_1_elembeddings.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_1_elembeddings.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_1_elembeddings.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_