BoxE

class BoxE(*, embedding_dim=256, tanh_map=True, p=2, power_norm=False, entity_initializer=<pykeen.utils.compose object>, entity_initializer_kwargs=None, relation_initializer=<pykeen.utils.compose object>, relation_initializer_kwargs=None, relation_size_initializer=<function uniform_>, relation_size_initializer_kwargs=None, **kwargs)[source]

Bases: ERModel

An implementation of BoxE from [abboud2020].

It combines a number of pykeen.nn.Embedding for both entities and relation representations with the pykeen.nn.BoxEInteraction interaction function.

Note

This implementation only currently supports unimodal knowledge graphs consisting only of binary facts, whereas the original BoxE applies to arbitrary facts of any arity, i.e., unary facts, binary facts, ternary facts, etc. For use on higher-arity knowledge bases, please refer to the original implementation at https://www.github.com/ralphabb/BoxE.

Initialize BoxE.

Parameters:
  • embedding_dim (int) – The entity embedding dimension \(d\). Defaults to 200. Is usually \(d \in [50, 300]\).

  • tanh_map (bool) – Whether to use tanh mapping after BoxE computation (defaults to true). The hyperbolic tangent mapping restricts the embedding space to the range [-1, 1], and thus this map implicitly regularizes the space to prevent loss reduction by growing boxes arbitrarily large.

  • p (int) – order of norm in score computation

  • power_norm (bool) – whether to use the p-th power of the norm instead

  • entity_initializer (Union[str, Callable[[FloatTensor], FloatTensor], None]) – Entity initializer function. Defaults to pykeen.nn.init.uniform_norm_()

  • entity_initializer_kwargs (Optional[Mapping[str, Any]]) – Keyword arguments to be used when calling the entity initializer

  • relation_initializer (Union[str, Callable[[FloatTensor], FloatTensor], None]) – Relation initializer function. Defaults to pykeen.nn.init.uniform_norm_()

  • relation_initializer_kwargs (Optional[Mapping[str, Any]]) – Keyword arguments to be used when calling the relation initializer

  • relation_size_initializer (Union[str, Callable[[FloatTensor], FloatTensor], None]) – Relation initializer function. Defaults to torch.nn.init.uniform_() Defaults to torch.nn.init.uniform_()

  • relation_size_initializer_kwargs (Optional[Mapping[str, Any]]) – Keyword arguments to be used when calling the relation matrix initializer

  • kwargs – Remaining keyword arguments passed through to pykeen.models.ERModel.

This interaction relies on Abboud’s point-to-box distance pykeen.utils.point_to_box_distance().

Attributes Summary

hpo_default

The default strategy for optimizing the model's hyper-parameters

loss_default_kwargs

The default parameters for the default loss function class

Attributes Documentation

hpo_default: ClassVar[Mapping[str, Any]] = {'embedding_dim': {'high': 256, 'low': 16, 'q': 16, 'type': <class 'int'>}, 'p': {'high': 2, 'low': 1, 'type': <class 'int'>}}

The default strategy for optimizing the model’s hyper-parameters

loss_default_kwargs: ClassVar[Mapping[str, Any] | None] = {'adversarial_temperature': 2.0, 'margin': 3, 'reduction': 'sum'}

The default parameters for the default loss function class