Training regimes and the DELE regime
A paper on ontology embeddings usually bundles a representation (balls, boxes, …), a
training regime (which negatives are sampled, which axioms count as positives, how the
losses are combined) and an evaluation regime. mOWL keeps them apart: the representation
is the model, and a training regime is a TrainingRegime object
that is assigned to any EmbeddingELModel:
from mowl.datasets.builtin import FamilyDataset
from mowl.models import ELEmbeddings
from mowl.training import dele_regime
dataset = FamilyDataset()
model = ELEmbeddings(dataset, embed_dim=10)
model.training_regime = dele_regime() # ELEm+l+n of DELE
model.train(epochs=2)
Without a regime (model.training_regime = None, the default) training is exactly as
before. The generic training loop of EmbeddingELModel.train consults the regime’s hooks
(training_datasets, negatives, filter_negatives, loss, on_epoch_start,
additional_loss, optimizer) and falls back to the model whenever a hook returns
its neutral default. Several regimes are combined with
ComposedRegime. Models that override train with a loop of their
own may ignore regimes.
Strict and slack margins
The margin \(\gamma\) of an inclusion loss has two meanings in the literature, and implementations of the same method disagree on which one they use.
Strict: the inner box must lie inside the outer one with a gap of \(\gamma\). Zero loss implies that the axiom holds.
Slack: the inner box may stick out by up to \(\gamma\). Zero loss does not imply that the axiom holds, so the embedding need not be a model of the ontology.
Each module declares the meaning of its margin parameter in
mowl.nn.ELModule.margin_semantics (ELBE and TransBox: strict;
ELEmbeddings, EmEL++ and Box2EL: slack). The regimes
StrictMargin and SlackMargin set the
margin by meaning, whatever the module’s convention:
from mowl.datasets.builtin import FamilyDataset
from mowl.models import ELBE
from mowl.training import SlackMargin, margin_semantics
model = ELBE(FamilyDataset(), embed_dim=4)
print(margin_semantics(model))
model.training_regime = SlackMargin(0.05)
print(model.module.margin)
...strict
-0.05
The published Box2EL-benchmark numbers of ELBE, Box2EL and TransBox were obtained with a slack margin; see Benchmarks.
DELE
DELE [mashkova2024dele] (and its NeSy 2024 predecessor [mashkova2024nesy]) is not an embedding method but a way to train and evaluate any geometric \(\mathcal{EL}^{++}\) embedding with the help of the deductive closure. Its training part is made of two composable regimes:
AllNormalFormNegatives(“+l” in DELE’s tables)Negatives are sampled for all seven normal forms, not only \(C \sqsubseteq \exists R.D\), and trained with the negative losses of DELE, Section 4. The losses are implemented in
ELEmModule,ELBEModuleandBoxSquaredELModuleand switched on withall_negative_losses=True(the regime does this for you); by default these modules are unchanged.ClosureFilteredNegatives(“+n”)A negative that is entailed by the training ontology is never used: it is re-sampled, or dropped if no non-entailed replacement is found. The filter applies to negatives from any sampler, so it can be combined with the regimes of other papers.
dele_regime() composes both (the “+l+n” rows of DELE’s Tables 3-6);
dele_regime(filter_negatives=False) gives “+l”. Use the regime when the ontology has
many non-trivial entailments (deep hierarchies, conjunctions, disjointness) and when the
model is evaluated on entailed knowledge as well as on novel axioms.
ClosurePositives adds entailed axioms as training positives. It is
not part of the papers and is provided as an extension.
The reference code
The published numbers of DELE’s tables were not produced with the losses and the training loop described above, but with the reference implementation (bio-ontology-research-group/DELE), which differs from mOWL’s models in ways the paper does not mention. Two regimes make those differences explicit instead of hiding them in the modules:
DELECodeLossesThe reference’s loss functions. It corrects the GCI3 losses of ELEmbeddings and ELBE (the filler’s radius / offset is added, not subtracted) and gives ELBE slack margins and a GCI2 negative loss that penalises overlap instead of separation. For Box2EL the positive losses return the unsquared scores of the reference module, so that the validation loss is the reference’s.
DELECodeLossHow the reference training loops combine the per-axiom losses: squares for every normal form of ELBE and Box2EL, for GCI2 with negatives only in ELEmbeddings. Without it mOWL’s ELBE combination (squared means, negatives pulled to 1) trains the DELE negatives to be violated.
DELECodeTrainingThe reference’s training design: cyclic mini-batches of 32,768 axioms per normal form (an epoch is \(\max_t \lceil n_t / b \rceil\) steps), negatives corrupted with a class of the same kind on the GO & STRING data (
kind_prefixes), entailed negatives dropped for the “+n” rows, and ReduceLROnPlateau with early stopping acting once per paper epoch. It composesDELECodeLossesandDELECodeLosswith the regimes above; the recipes of thedele-*benchmarks use it.negative_seed=0restarts the negative draws from seed 0 at every step, as the reference does, so that every positive keeps one fixed negative.
from mowl.models import ELEmbeddings
from mowl.training import DELECodeTraining
model.training_regime = DELECodeTraining( # baseline: GCI2 negatives only
negatives="gci2", kind_prefixes=("4932.",))
The deductive closure
DeductiveClosure computes DELE’s approximation of the deductive
closure with respect to the normal forms: the full class hierarchy (computed by
mOWL’s pure-Python EL++ completion or by ELK), and sound but incomplete syntactic rules
for the other normal forms (DELE, Algorithms 1 and 2). It can be queried, enumerated and
cached:
from mowl.training import DeductiveClosure
closure = DeductiveClosure.from_model(model, reasoner="canonical")
gci0 = closure.axioms("gci0") # entailed A ⊑ B, as model indices
train_gci0 = model.training_datasets["gci0"][:]
assert closure.contains("gci0", train_gci0).all() # training axioms are entailed
See mowl.training.closure for exactly which rules are applied, and
Evaluation with the deductive closure (DELE) for the matching evaluation regime.