RGCN
- class RGCN(*, triples_factory: ~pykeen.triples.triples_factory.CoreTriplesFactory, embedding_dim: int = 500, num_layers: int = 2, base_entity_initializer: str | ~typing.Callable[[~torch.Tensor], ~torch.Tensor] | None = <function xavier_uniform_>, base_entity_initializer_kwargs: ~collections.abc.Mapping[str, ~typing.Any] | None = None, relation_representations: str | ~pykeen.nn.representation.Representation | type[~pykeen.nn.representation.Representation] | None = None, relation_initializer: str | ~typing.Callable[[~torch.Tensor], ~torch.Tensor] | None = <function xavier_uniform_>, relation_initializer_kwargs: ~collections.abc.Mapping[str, ~typing.Any] | None = None, interaction: str | ~pykeen.nn.modules.Interaction[~torch.Tensor, ~pykeen.typing.RelationRepresentation, ~torch.Tensor] | type[~pykeen.nn.modules.Interaction[~torch.Tensor, ~pykeen.typing.RelationRepresentation, ~torch.Tensor]] | None = 'DistMult', interaction_kwargs: ~collections.abc.Mapping[str, ~typing.Any] | None = None, use_bias: bool = True, activation: str | ~torch.nn.modules.module.Module | None = None, activation_kwargs: ~collections.abc.Mapping[str, ~typing.Any] | None = None, edge_dropout: float = 0.4, self_loop_dropout: float = 0.2, edge_weighting: str | ~pykeen.nn.weighting.EdgeWeighting | None = None, decomposition: str | ~pykeen.nn.message_passing.Decomposition | None = None, decomposition_kwargs: ~collections.abc.Mapping[str, ~typing.Any] | None = None, regularizer: str | ~pykeen.regularizers.Regularizer | None = None, regularizer_kwargs: ~collections.abc.Mapping[str, ~typing.Any] | None = None, **kwargs)[source]
Bases:
ERModel
[Tensor
,RelationRepresentation
,Tensor
]An implementation of R-GCN from [schlichtkrull2018].
The Relational Graph Convolutional Network (R-GCN) comprises three parts:
A GCN-based entity encoder that computes enriched representations for entities, cf.
pykeen.nn.message_passing.RGCNRepresentations
. The representation for entity \(i\) at level \(l \in (1,\dots,L)\) is denoted as \(\textbf{e}_i^l\). The GCN is modified to use different weights depending on the type of the relation.Relation representations \(\textbf{R}_{r} \in \mathbb{R}^{d \times d}\) is a diagonal matrix that are learned independently from the GCN-based encoder.
An arbitrary interaction model which computes the plausibility of facts given the enriched representations, cf.
pykeen.nn.modules.Interaction
.
Scores for each triple \((h,r,t) \in \mathcal{K}\) are calculated by using the representations in the final level of the GCN-based encoder \(\textbf{e}_h^L\) and \(\textbf{e}_t^L\) along with relation representation \(\textbf{R}_{r}\). While the original implementation of R-GCN used the DistMult model and we use it as a default, this implementation allows the specification of an arbitrary interaction model.
\[f(h,r,t) = \textbf{e}_h^L \textbf{R}_{r} \textbf{e}_t^L\]Initialize the model.
- Parameters:
triples_factory (CoreTriplesFactory) – the (training) triples factory
embedding_dim (int) – the embedding dimension
num_layers (int) – >0 the number of layers
base_entity_initializer (str | Callable[[Tensor], Tensor] | None) – the entity base representation initializer
base_entity_initializer_kwargs (Mapping[str, Any] | None) – the entity base representation initializer’s keyword-based parameters
relation_representations (str | Representation | type[Representation] | None) – the relation representations, or a hint thereof
relation_initializer (str | Callable[[Tensor], Tensor] | None) – the entity base representation initializer
relation_initializer_kwargs (Mapping[str, Any] | None) – the entity base representation initializer’s keyword-based parameters
interaction (str | Interaction[Tensor, RelationRepresentation, Tensor] | type[Interaction[Tensor, RelationRepresentation, Tensor]] | None) – the interaction function, or a hint thereof
interaction_kwargs (Mapping[str, Any] | None) – additional keyword-based parameters passed to the interaction function
use_bias (bool) – whether to use a bias on the message passing layers
activation (str | Module | None) – the activation function, or a hint thereof
activation_kwargs (Mapping[str, Any] | None) – additional keyword-based parameters passed to the activation function
edge_dropout (float) – the edge dropout, except for self-loops
self_loop_dropout (float) – the self-loop dropout
edge_weighting (str | EdgeWeighting | None) – the edge weighting
decomposition (str | Decomposition | None) – the convolution weight decomposition
decomposition_kwargs (Mapping[str, Any] | None) – additional keyword-based parameters passed to the weight decomposition
regularizer (str | Regularizer | None) – the regularizer applied to the base representations
regularizer_kwargs (Mapping[str, Any] | None) – additional keyword-based parameters passed to the regularizer
kwargs – additional keyword-based parameters passed to
ERModel.__init__()
Attributes Summary
The default strategy for optimizing the model's hyper-parameters
Attributes Documentation
- hpo_default: ClassVar[Mapping[str, Any]] = {'activation': {'choices': [<class 'torch.nn.modules.activation.ReLU'>, <class 'torch.nn.modules.activation.LeakyReLU'>], 'type': 'categorical'}, 'decomposition': {'choices': ['bases', 'block'], 'type': 'categorical'}, 'edge_dropout': {'high': 0.5, 'low': 0.0, 'q': 0.1, 'type': <class 'float'>}, 'edge_weighting': {'choices': ['inverse_in_degree', 'inverse_out_degree', 'symmetric'], 'type': 'categorical'}, 'embedding_dim': {'high': 256, 'low': 16, 'q': 16, 'type': <class 'int'>}, 'interaction': {'choices': ['distmult', 'complex', 'ermlp'], 'type': 'categorical'}, 'num_layers': {'high': 5, 'low': 1, 'q': 1, 'type': <class 'int'>}, 'self_loop_dropout': {'high': 0.5, 'low': 0.0, 'q': 0.1, 'type': <class 'float'>}, 'use_bias': {'type': 'bool'}}
The default strategy for optimizing the model’s hyper-parameters