CP

class CP(embedding_dim: int = 64, rank: int = 64, entity_initializer: str | Callable[[Tensor], Tensor] | None = None, entity_initializer_kwargs: Mapping[str, Any] | None = None, entity_normalizer: str | Callable[[Tensor], Tensor] | None = None, entity_normalizer_kwargs: Mapping[str, Any] | None = None, relation_initializer: str | Callable[[Tensor], Tensor] | None = None, relation_initializer_kwargs: Mapping[str, Any] | None = None, **kwargs)[source]

Bases: ERModel[Tensor, Tensor, Tensor]

An implementation of CP as described in [lacroix2018] based on [hitchcock1927].

It has separate entity representations for the head and tail role, both a \(r \times d\)-dimensional matrices. Relations are also represented by a \(r \times d\)-dimensional matrix. All three components can be stored as Embedding.

On top of these, CPInteraction is applied to obtain scores.

Initialize the model.

Parameters:
  • embedding_dim (int) – The entity embedding dimension \(d\).

  • rank (int) – The tensor decomposition rank \(k\).

  • entity_initializer (str | Callable[[Tensor], Tensor] | None) – Entity initializer function. Defaults to None

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

  • entity_normalizer (str | Callable[[Tensor], Tensor] | None) – Entity normalizer function. Defaults to None

  • entity_normalizer_kwargs (Mapping[str, Any] | None) – Keyword arguments to be used when calling the entity normalizer

  • relation_initializer (str | Callable[[Tensor], Tensor] | None) – Relation initializer function. Defaults to None

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

  • kwargs – Remaining keyword arguments passed through to ERModel.

Attributes Summary

hpo_default

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

Attributes Documentation

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

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