ELModule
- class mowl.nn.ELModule[source]
Bases:
ModuleSubclass of
torch.nn.Modulefor \(\mathcal{EL}\) models.This class provides an interface for loss functions of the 7 possible normal forms existing in the \(\mathcal{EL}\) language. In case a negative version of one of the loss function exist, it must be placed inside the original loss function and be accesed through the
negparameter. More information of this can be found at Embedding the EL languageSubclasses should override
neg_capable_gcisto declare which GCI loss functions genuinely implement a different code path whenneg=True.Attributes Summary
Set of GCI names for which this module implements a true negative loss (i.e. the loss function behaves differently when called with
neg=True).Methods Summary
class_assertion_loss(axiom_data[, neg])Loss function for class assertion: \(C(a)\).
forward(gci, gci_name[, neg])Define the computation performed at every call.
gci0_bot_loss(gci[, neg])Loss function for GCI0 with bottom concept: \(C \sqsubseteq \perp\).
gci0_loss(gci[, neg])Loss function for GCI0: \(C \sqsubseteq D\).
gci1_bot_loss(gci[, neg])Loss function for GCI1 with bottom concept: \(C_1 \sqcap C_2 \sqsubseteq \perp\).
gci1_loss(gci[, neg])Loss function for GCI1: \(C_1 \sqcap C_2 \sqsubseteq D\).
gci2_loss(gci[, neg])Loss function for GCI2: \(C \sqsubseteq \exists R.D\).
gci3_bot_loss(gci[, neg])Loss function for GCI3 with bottom concept: \(\exists R.C \sqsubseteq \perp\).
gci3_loss(gci[, neg])Loss function for GCI3: \(\exists R.C \sqsubseteq D\).
get_loss_function(gci_name)This chooses the corresponding loss fuction given the name of the GCI.
object_property_assertion_loss(axiom_data[, neg])Loss function for role assertion: \(R(a,b)\).
Attributes Documentation
- neg_capable_gcis = frozenset({})
Set of GCI names for which this module implements a true negative loss (i.e. the loss function behaves differently when called with
neg=True). Subclasses must override this to declare their capabilities.
Methods Documentation
- class_assertion_loss(axiom_data, neg=False)[source]
Loss function for class assertion: \(C(a)\). :param axiom_data: Input tensor of shape (*,2) where
Cclasses will be ataxiom_data[:,0]andaindividuals will be ataxiom_data[:,1]. It is recommended to use theELDataset. :type axiom_data:torch.Tensor:param neg: Parameter indicating that the negative version of this loss function must be used. Defaults toFalse. :type neg: bool, optional.
- forward(gci, gci_name, neg=False)[source]
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- gci0_bot_loss(gci, neg=False)[source]
Loss function for GCI0 with bottom concept: \(C \sqsubseteq \perp\).
- Parameters:
gci (
torch.Tensor) – Input tensor of shape (*,2) whereCclasses will be atgci[:,0]andbottomclasses will be atgci[:,1]. It is recommended to use theELDataset.neg (bool, optional.) – Parameter indicating that the negative version of this loss function must be used. Defaults to
False.
- gci0_loss(gci, neg=False)[source]
Loss function for GCI0: \(C \sqsubseteq D\).
- Parameters:
gci (
torch.Tensor) – Input tensor of shape (*,2) whereCclasses will be atgci[:,0]andDclasses will be atgci[:,1]. It is recommended to use theELDataset.neg (bool, optional.) – Parameter indicating that the negative version of this loss function must be used. Defaults to
False.
- gci1_bot_loss(gci, neg=False)[source]
Loss function for GCI1 with bottom concept: \(C_1 \sqcap C_2 \sqsubseteq \perp\).
- Parameters:
gci (
torch.Tensor) – Input tensor of shape (*,3) whereC1classes will be atgci[:,0],C2classes will be atgci[:,1] andbottomclasses will be atgci[:,2]. It is recommended to use theELDataset.neg (bool, optional.) – Parameter indicating that the negative version of this loss function must be used. Defaults to
False.
- gci1_loss(gci, neg=False)[source]
Loss function for GCI1: \(C_1 \sqcap C_2 \sqsubseteq D\).
- Parameters:
gci (
torch.Tensor) – Input tensor of shape (*,3) whereC1classes will be atgci[:,0],C2classes will be atgci[:,1]andDclasses will be atgci[:,2]. It is recommended to use theELDataset.neg (bool, optional.) – Parameter indicating that the negative version of this loss function must be used. Defaults to
False.
- gci2_loss(gci, neg=False)[source]
Loss function for GCI2: \(C \sqsubseteq \exists R.D\). \(C \sqsubseteq \exists R. D\). :param gci: Input tensor of shape (*,3) where
Cclasses will be atgci[:,0],Robject properties will be atgci[:,1]andDclasses will be atgci[:,2]. It is recommended to use theELDataset. :type gci:torch.Tensor:param neg: Parameter indicating that the negative version of this loss function must be used. Defaults toFalse. :type neg: bool, optional.
- gci3_bot_loss(gci, neg=False)[source]
Loss function for GCI3 with bottom concept: \(\exists R.C \sqsubseteq \perp\).
- Parameters:
gci (
torch.Tensor) – Input tensor of shape (*,3) whereRobject properties will be at gci[:,0],Cclasses will be atgci[:,1]andbottomclasses will be atgci[:,2]. It is recommended to use theELDataset.neg (bool, optional.) – Parameter indicating that the negative version of this loss function must be used. Defaults to
False.
- gci3_loss(gci, neg=False)[source]
Loss function for GCI3: \(\exists R.C \sqsubseteq D\).
- Parameters:
gci (
torch.Tensor) – Input tensor of shape (*,3) whereRobject properties will be at gci[:,0],Cclasses will be atgci[:,1]andDclasses will be atgci[:,2]. It is recommended to use theELDataset.neg (bool, optional.) – Parameter indicating that the negative version of this loss function must be used. Defaults to
False.
- get_loss_function(gci_name)[source]
This chooses the corresponding loss fuction given the name of the GCI.
- Parameters:
gci_name (str) – Name of the GCI. Choices are
gci0,gci1,gci2,gci3,gci0_bot,gci1_botandgci3_bot.
- object_property_assertion_loss(axiom_data, neg=False)[source]
Loss function for role assertion: \(R(a,b)\). :param axiom_data: Input tensor of shape (*,3) where
aobject properties will be ataxiom_data[0], ``Robject properties will be ataxiom_data[:,1]andbindividuals will be ataxiom_data[:,2]. It is recommended to use theELDataset. :type axiom_data:torch.Tensor:param neg: Parameter indicating that the negative version of this loss function must be used. Defaults toFalse. :type neg: bool, optional.