RGCN¶
-
class
RGCN
(triples_factory, embedding_dim=500, loss=None, predict_with_sigmoid=False, preferred_device=None, random_seed=None, num_bases_or_blocks=5, num_layers=2, use_bias=True, use_batch_norm=False, activation_cls=None, activation_kwargs=None, sparse_messages_slcwa=True, edge_dropout=0.4, self_loop_dropout=0.2, edge_weighting=<function inverse_indegree_edge_weights>, decomposition='basis', buffer_messages=True, entity_initializer='xavier_uniform', relation_initializer='uniform')[source]¶ Bases:
pykeen.models.base._OldAbstractModel
An implementation of R-GCN from [schlichtkrull2018].
This model uses graph convolutions with relation-specific weights.
Initialize the module.
- Parameters
triples_factory (
TriplesFactory
) – The triples factory facilitates access to the dataset.loss (
Optional
[Loss
]) – The loss to use. If None is given, use the loss default specific to the model subclass.predict_with_sigmoid (
bool
) – Whether to apply sigmoid onto the scores when predicting scores. Applying sigmoid at prediction time may lead to exactly equal scores for certain triples with very high, or very low score. When not trained with applying sigmoid (or using BCEWithLogitsLoss), the scores are not calibrated to perform well with sigmoid.preferred_device (
Union
[None
,str
,device
]) – The preferred device for model training and inference.random_seed (
Optional
[int
]) – A random seed to use for initialising the model’s weights. Should be set when aiming at reproducibility.regularizer – A regularizer to use for training.
Attributes Summary
The default strategy for optimizing the model’s hyper-parameters
Methods Summary
Has to be called after each parameter update.
score_hrt
(hrt_batch)Forward pass.
Attributes Documentation
-
hpo_default
: ClassVar[Mapping[str, Any]] = {'activation_cls': {'choices': [None, <class 'torch.nn.modules.activation.ReLU'>, <class 'torch.nn.modules.activation.LeakyReLU'>], 'type': 'categorical'}, 'base_model_cls': {'choices': [<class 'pykeen.models.unimodal.distmult.DistMult'>, <class 'pykeen.models.unimodal.complex.ComplEx'>, <class 'pykeen.models.unimodal.ermlp.ERMLP'>], 'type': 'categorical'}, 'decomposition': {'choices': ['basis', 'block'], 'type': 'categorical'}, 'edge_dropout': {'high': 0.5, 'low': 0.0, 'q': 0.1, 'type': <class 'float'>}, 'edge_weighting': {'choices': [None, <function inverse_indegree_edge_weights>, <function inverse_outdegree_edge_weights>, <function symmetric_edge_weights>], 'type': 'categorical'}, 'embedding_dim': {'high': 1024, 'low': 16, 'q': 16, 'type': <class 'int'>}, 'num_bases_or_blocks': {'high': 20, 'low': 2, 'q': 1, 'type': <class 'int'>}, '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_batch_norm': {'type': 'bool'}, 'use_bias': {'type': 'bool'}}¶ The default strategy for optimizing the model’s hyper-parameters
Methods Documentation
-
score_hrt
(hrt_batch)[source]¶ Forward pass.
This method takes head, relation and tail of each triple and calculates the corresponding score.
- Parameters
hrt_batch (
LongTensor
) – shape: (batch_size, 3), dtype: long The indices of (head, relation, tail) triples.- Raises
NotImplementedError – If the method was not implemented for this class.
- Return type
FloatTensor
- Returns
shape: (batch_size, 1), dtype: float The score for each triple.