Note

Go to the end to download the full example code.

# ELBoxEmbeddings

This example is based on the paper Description Logic EL++ Embeddings with Intersectional Closure. This paper is based on the idea of EL Embeddings, but in this work the main point is to solve the *intersectional closure* problem.

In the case of EL Embeddings, the geometric objects representing ontology classes are \(n\)-dimensional balls. One of the normal forms in EL is:

As we can see, there is an intersection operation \(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.

This example is quite similar to the one found in EL Embeddings. 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.

```
import mowl
mowl.init_jvm("10g")
import torch as th
```

## 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 `mowl.nn.el.elem.module.ELBoxModule`

## ELBoxEmbeddings model

The module `mowl.nn.el.elem.module.ELBoxModule`

is used in the `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 \(p_1,p_2\), the phenomenon
“\(p_1\) interacts with \(p_2\)” is encoded using GCI 2 as:

For that, we can use the class `mowl.models.elembeddings.examples.model_ppi.ELBoxPPI`

mode, which uses the `mowl.datasets.builtin.PPIYeastSlimDataset`

dataset.

## Training the model

```
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=4096,
model_filepath=None,
device='cpu')
model.train()
```

```
Number of evaluation classes: 6039
0%| | 0/20 [00:00<?, ?it/s]
5%|▌ | 1/20 [00:00<00:06, 2.99it/s]
10%|█ | 2/20 [00:00<00:05, 3.08it/s]
15%|█▌ | 3/20 [00:00<00:05, 3.06it/s]
20%|██ | 4/20 [00:01<00:05, 2.99it/s]
25%|██▌ | 5/20 [00:01<00:04, 3.02it/s]
30%|███ | 6/20 [00:02<00:04, 2.96it/s]
35%|███▌ | 7/20 [00:02<00:04, 2.95it/s]
40%|████ | 8/20 [00:02<00:04, 2.94it/s]
45%|████▌ | 9/20 [00:03<00:03, 2.94it/s]
50%|█████ | 10/20 [00:03<00:03, 2.97it/s]
55%|█████▌ | 11/20 [00:03<00:03, 2.95it/s]
60%|██████ | 12/20 [00:04<00:02, 2.95it/s]
65%|██████▌ | 13/20 [00:04<00:02, 2.95it/s]
70%|███████ | 14/20 [00:04<00:02, 2.99it/s]
75%|███████▌ | 15/20 [00:05<00:01, 2.93it/s]
80%|████████ | 16/20 [00:05<00:01, 2.94it/s]
85%|████████▌ | 17/20 [00:05<00:01, 2.93it/s]
90%|█████████ | 18/20 [00:06<00:00, 2.94it/s]
95%|█████████▌| 19/20 [00:06<00:00, 2.93it/s]
100%|██████████| 20/20 [00:06<00:00, 2.95it/s]
100%|██████████| 20/20 [00:06<00:00, 2.96it/s]
1
```

## Evaluating the model

Now, it is time to evaluate embeddings. For this, we use the
`ModelRankBasedEvaluator`

class.

```
from mowl.evaluation import PPIEvaluator
model.set_evaluator(PPIEvaluator)
model.evaluate()
```

```
Number of evaluation classes: 6039
```

**Total running time of the script:** (1 minutes 30.418 seconds)

**Estimated memory usage:** 3174 MB