.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/elmodels/plot_2_elboxembeddings.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_2_elboxembeddings.py: ELBoxEmbeddings =========================== This example is based on the paper `Description Logic EL++ Embeddings with Intersectional Closure `_. This paper is based on the idea of :doc:`/examples/elmodels/plot_1_elembeddings`, but in this work the main point is to solve the *intersectional closure* problem. In the case of :doc:`/examples/elmodels/plot_1_elembeddings`, the geometric objects representing ontology classes are :math:`n`-dimensional balls. One of the normal forms in EL is: .. math:: C_1 \sqcap C_2 \sqsubseteq D As we can see, there is an intersection operation :math:`C_1 \sqcap C_2`. Computing this intersection using balls is not a closed operations because the region contained in the intersection of two balls is not a ball. To solve that issue, this paper proposes the idea of changing the geometric objects to boxes, for which the intersection operation has the closure property. .. GENERATED FROM PYTHON SOURCE LINES 24-27 This example is quite similar to the one found in :doc:`/examples/elmodels/plot_1_elembeddings`. There might be slight changes in the training part but the most important changes are in the definition of loss functions definition of the loss functions for each normal form. .. GENERATED FROM PYTHON SOURCE LINES 27-34 .. code-block:: Python import mowl mowl.init_jvm("10g") import torch as th .. GENERATED FROM PYTHON SOURCE LINES 35-40 ELBoxEmbeddings (PyTorch) module --------------------------------- ELBoxEmbeddings 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.ELBoxModule` .. GENERATED FROM PYTHON SOURCE LINES 43-55 ELBoxEmbeddings model ---------------------- The module :class:`mowl.nn.el.elem.module.ELBoxModule` is used in the :class:`mowl.models.elboxembeddings.model.ELBoxEmbeddings`. 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.ELBoxPPI` mode, which uses the :class:`mowl.datasets.builtin.PPIYeastSlimDataset` dataset. .. GENERATED FROM PYTHON SOURCE LINES 60-62 Training the model ------------------- .. GENERATED FROM PYTHON SOURCE LINES 62-83 .. code-block:: Python from mowl.datasets.builtin import PPIYeastSlimDataset from mowl.models.elboxembeddings.examples.model_ppi import ELBoxPPI dataset = PPIYeastSlimDataset() model = ELBoxPPI(dataset, embed_dim=30, margin=-0.05, reg_norm=1, learning_rate=0.001, epochs=20, batch_size=20000, model_filepath=None, device='cpu') model.train() .. rst-class:: sphx-glr-script-out .. code-block:: none 0%| | 0/20 [00:00` class. .. GENERATED FROM PYTHON SOURCE LINES 89-95 .. code-block:: Python from mowl.evaluation import PPIEvaluator model.set_evaluator(PPIEvaluator) model.evaluate(dataset.testing) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 37.188 seconds) **Estimated memory usage:** 1681 MB .. _sphx_glr_download_examples_elmodels_plot_2_elboxembeddings.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_2_elboxembeddings.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_2_elboxembeddings.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_2_elboxembeddings.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_