mowl.training

Training regimes (mowl.training.regime): the DELE regimes and the shared deductive-closure utility (mowl.training.dele, mowl.training.closure), and the regimes of the literature (negatives, losses, positives, schedules, model selection, batching).

Functions

margin_semantics(model)

"strict" or "slack": what a positive margin means for the model's module.

dele_regime([closure, epsilon, ...])

The DELE training regime: negatives and negative losses for all normal forms ("+l") and, if filter_negatives is True, filtering of entailed negatives ("+n").

validation_f1(model[, gci_name, ...])

Best achievable F1 on the first validation axioms of one normal form, negated (so that lower is better): the model-selection quantity of the RegD code (train of EXP_ontology/baseline_sweep.py computes compute_ranks(val_data[nf][:1000], threshold=None) every 100 epochs and keeps the checkpoint with the best F1).

Classes

TrainingRegime()

Base class of training regimes.

ComposedRegime(*regimes)

Combination of several regimes.

SlackMargin(margin)

Inclusions may be violated by up to margin in every dimension (see the module documentation).

StrictMargin(margin)

Inclusions must hold with a gap of at least margin on every side (see the module documentation).

Box2ELCodeTraining([batch_size, ...])

How train.py of the Box2EL code (KRR-Oxford/BoxSquaredEL) trains Box2EL and its baselines, and how the numbers of Jackermeier et al. (WWW 2024) were obtained.

TransBoxCodeTraining([batch_size, ...])

How the TransBox code (HuiYang1997/TransBox, model/TransBox_reg.py and baseline_sweep.py) trains TransBox, and how the numbers of Yang et al. (WWW 2025) were obtained.

ELKEmCodeTraining([batch_size, k_neg, ...])

How paper/ranking/train.py of the ELK-Em code (city-artificial-intelligence/elk-em) trains, and how the numbers of Singh, Jiménez-Ruiz & Weyde (KG-NeSy 2026, Table 3) were obtained.

EmELppCodeTraining([batch_size, ...])

How the Keras code of EmEL++ (kracr/EmELpp, experiments/*/models/*_EmEL.py) trains EmEL++, and its *_EL.py scripts train the ELEmbeddings baseline; the numbers of Mondal et al. (AAAI-MAKE 2021, Table 3) were obtained this way.

EmELppCodeObjective([batch_size, ...])

The objective of the Keras code of EmEL++ (kracr/EmELpp, *_EmEL.py) and of the ELEmbeddings baseline in the same repository (*_EL.py), which differs from the losses printed in the paper:

ValidationAxiomsAsPositives([normal_forms])

Add the validation axioms of a normal form to the training data.

RegDCodeTraining([task, design, batch_size, ...])

How EXP_ontology/baseline_sweep.py of the RegD code (HuiYang1997/RegD) trains RegD and the ELBE / ELEm baselines, and how the numbers of Yang and Chen (arXiv:2501.17518, Tables 3 and 4) were obtained.

CateCodeTraining([interaction_loss])

How the CatE code trains, and how the numbers of Zhapa-Camacho and Hoehndorf (arXiv:2305.07163v3, Tables 2-4) were obtained.

DeductiveClosure(normalized_gcis, ...[, ...])

Approximate deductive closure of a normalised ontology (see the module documentation for exactly what is included).

DELECodeLoss()

How the DELE reference code combines the per-axiom losses of one normal form (models/*.py, the training loops), per model:

DELECodeLosses([elem_axiom_reg])

Train (and score) with the loss functions of the DELE reference code.

DELECodeTraining([batch_size, negatives, ...])

How the DELE reference code (bio-ontology-research-group/DELE) trains, and how the numbers of DELE's Tables 3-6 were obtained: the composition of

AllNormalFormNegatives([epsilon, ...])

Negatives and negative losses for all seven \(\mathcal{EL}^{++}\) normal forms (DELE, Section 4; NeSy 2024, Section 4.2).

ClosureFilteredNegatives([closure, ...])

Filter entailed axioms out of the sampled negatives (DELE, Section 5; NeSy 2024, Section 4.3 "Negatives Filtration").

ClosurePositives([closure, normal_forms, ...])

Add axioms of the deductive closure to the training data as positives.

CorruptionNegatives([columns, mode, ...])

Uniform corruption of one or more columns of the training axioms.

FixedColumnCorruption([columns, mode, ...])

Corrupt one fixed column of every axiom with a uniformly drawn entity.

EitherSideCorruption([columns, mode, ...])

Every negative corrupts one side of the axiom, chosen uniformly at random.

PerColumnCorruption([columns, mode, ...])

Every positive gets one block of negatives per side: one with the left-hand side corrupted and one with the right-hand side corrupted.

TypeConstrainedCorruption(types[, columns, ...])

Corrupt an entity only with an entity of the same type.

KnownPositiveFilter([pools, max_resample, seed])

Never use a known positive as a negative: a sampled negative that is itself an axiom of the training data is re-sampled in its corrupted column.

SiblingHardNegatives([num_negatives, ...])

Hard negatives for \(C \sqsubseteq D\) from the siblings of \(C\).

ContradictionNegatives([p_bot, ...])

Negatives that are provably false: corruptions that contradict an asserted disjointness axiom.

FixedNegatives([sampler, batch_size, seed])

Negatives drawn once, before training, and reused at every step.

JointNormalisedInitialisation([size_low, ...])

Re-initialise centre and radius (or offset) of every class as one vector: uniform in \([-1, 1]\), then the concatenation is scaled to unit norm.

UnboundedNegativeLoss()

The negative loss of \(C \not\sqsubseteq \exists R.D\) without the hinge: \(r_C + r_D - \lVert c + R - d \rVert + \gamma\) instead of \(\max(0, \cdot)\).

PerAxiomNormPenalty()

The penalty \(|\lVert c \rVert - 1|\) of every class centre that occurs in an axiom is added to the loss of that axiom (positives and negatives alike), instead of once per step as the mean over all classes.

Box2ELBaselineLosses([negative_loss, ...])

The loss details of the baseline models of the Box2EL code (KRR-Oxford/BoxSquaredEL, model/Elem.py, model/EmELpp.py, model/BoxEL.py) that differ from mOWL's modules:

SumLoss([neg_weight, normal_forms])

Mean loss of the positives plus neg_weight times the mean negative loss.

MSETargetLoss([pos_target, neg_target, ...])

Squared distance of the scores to targets: \(\mathrm{mean}((s^+ - t^+)^2) + \mathrm{mean}((s^- - t^-)^2)\), negatives scored by the module's negative loss.

PairwiseMarginRankingLoss([margin, ...])

\(\mathrm{mean}_{i,k} \max(0, \gamma + s^+_i - s^-_{ik})\): every positive must score at least \(\gamma\) better than each of its negatives.

LogSigmoidLoss([margin, ...])

Negative-sampling loss with a log-sigmoid, optionally self-adversarial:

BPRLoss([normal_forms, neg_scores])

Bayesian personalised ranking (Rendle et al. 2012): \(-\mathrm{mean}_{i,k} \log\sigma(s^-_{ik} - s^+_i)\).

LogSumExpContrastiveLoss([gamma1, gamma2, ...])

The contrastive loss RegD (Yang and Chen, Section 3.3, Eq.

SoftmaxEnergyContrastiveLoss([gamma1, ...])

The loss the RegD code trains with (PluginRegD.loss_cross of HuiYang1997/RegD, inherited from the ShadowCones code): for every positive pair, the cross-entropy of \(e^{-E}\) against its \(K\) sampled negatives,

PearsonCorrelationLoss([eps, weight, ...])

ELK-Em's contrastive loss (Singh et al. 2026, Section 4.2, Eq.

ProbabilisticBCELoss([...])

Binary cross-entropy with the score read as a negative log-probability, \(p(\alpha) = e^{-s(\alpha)}\):

NormalFormFrequencyWeighting([base, ...])

Weight the loss of every normal form by its share of the training data.

TransitiveReductionPositives([gci_name])

Train only on the transitive reduction of the asserted atomic subsumptions.

TransitiveClosurePositives([gci_name, max_new])

Train on the transitive closure of the asserted atomic subsumptions: every \(C \sqsubseteq E\) with a path \(C \sqsubseteq \dots \sqsubseteq E\) of asserted gci0 axioms is added as a positive (reflexive pairs excluded).

StepDecay(milestones[, gamma, base_optimizer])

Multiply the learning rate by gamma after each epoch in milestones.

ConstantThenCosine([constant_fraction, ...])

Constant learning rate for the first constant_fraction of the epochs, then a cosine decay to min_lr at the last epoch.

CyclicLearningRate([base_lr, max_lr, ...])

Triangular cyclical learning rate between base_lr and max_lr (torch.optim.lr_scheduler.CyclicLR, Smith 2017), stepped once per epoch.

ReduceOnPlateau([metric, patience, factor, ...])

Reduce the learning rate by factor when a monitored quantity has not improved for patience epochs (torch.optim.lr_scheduler.ReduceLROnPlateau).

EarlyStopping([metric, patience, every, ...])

End training when a validation quantity has not improved for patience monitored epochs, without changing the learning rate ("early stopping if validation loss does not improve for 20 epochs", Mashkova et al., 2024).

ValidationSelection([metric, every, rank_kwargs])

Keep the parameters with the best validation quantity.

ValidationRankSelection([every])

ValidationSelection with metric="rank": the median rank of the first 1,000 validation gci0 axioms by default, as in Box2EL's reference code and ELK-Em.

ValidationF1Selection([every, gci_name, ...])

ValidationSelection with validation_f1(): keep the parameters with the best F1 on the first 1,000 validation axioms of the task's normal form, the threshold tuned on that split, as the RegD code selects its checkpoint every 100 epochs.

PerNormalFormMiniBatches([batch_size, ...])

One mini-batch per normal form per optimisation step.

Class Inheritance Diagram

Inheritance diagram of mowl.training.regime.TrainingRegime, mowl.training.regime.ComposedRegime, mowl.training.margin.SlackMargin, mowl.training.margin.StrictMargin, mowl.training.reference.Box2ELCodeTraining, mowl.training.reference.TransBoxCodeTraining, mowl.training.reference.ELKEmCodeTraining, mowl.training.reference.EmELppCodeTraining, mowl.training.loss_forms.EmELppCodeObjective, mowl.training.positives.ValidationAxiomsAsPositives, mowl.training.reference.RegDCodeTraining, mowl.training.cate.CateCodeTraining, mowl.training.closure.DeductiveClosure, mowl.training.dele.DELECodeLoss, mowl.training.dele.DELECodeLosses, mowl.training.dele.DELECodeTraining, mowl.training.dele.AllNormalFormNegatives, mowl.training.dele.ClosureFilteredNegatives, mowl.training.dele.ClosurePositives, mowl.training.negatives.CorruptionNegatives, mowl.training.negatives.FixedColumnCorruption, mowl.training.negatives.EitherSideCorruption, mowl.training.negatives.PerColumnCorruption, mowl.training.negatives.TypeConstrainedCorruption, mowl.training.negatives.KnownPositiveFilter, mowl.training.negatives.SiblingHardNegatives, mowl.training.negatives.ContradictionNegatives, mowl.training.negatives.FixedNegatives, mowl.training.initialisation.JointNormalisedInitialisation, mowl.training.loss_forms.UnboundedNegativeLoss, mowl.training.loss_forms.PerAxiomNormPenalty, mowl.training.loss_forms.Box2ELBaselineLosses, mowl.training.losses.SumLoss, mowl.training.losses.MSETargetLoss, mowl.training.losses.PairwiseMarginRankingLoss, mowl.training.losses.LogSigmoidLoss, mowl.training.losses.BPRLoss, mowl.training.losses.LogSumExpContrastiveLoss, mowl.training.losses.SoftmaxEnergyContrastiveLoss, mowl.training.losses.PearsonCorrelationLoss, mowl.training.losses.ProbabilisticBCELoss, mowl.training.losses.NormalFormFrequencyWeighting, mowl.training.positives.TransitiveReductionPositives, mowl.training.positives.TransitiveClosurePositives, mowl.training.schedules.StepDecay, mowl.training.schedules.ConstantThenCosine, mowl.training.schedules.CyclicLearningRate, mowl.training.schedules.ReduceOnPlateau, mowl.training.schedules.EarlyStopping, mowl.training.selection.ValidationSelection, mowl.training.selection.ValidationRankSelection, mowl.training.selection.ValidationF1Selection, mowl.training.batching.PerNormalFormMiniBatches