RGCNRepresentation

class RGCNRepresentation(triples_factory: CoreTriplesFactory, max_id: int | None = None, shape: Sequence[int] | None = None, entity_representations: str | Representation | type[Representation] | None = None, entity_representations_kwargs: Mapping[str, Any] | None = None, num_layers: int = 2, use_bias: bool = True, activation: str | Module | None = None, activation_kwargs: Mapping[str, Any] | None = None, edge_dropout: float = 0.4, self_loop_dropout: float = 0.2, edge_weighting: str | EdgeWeighting | None = None, edge_weighting_kwargs: Mapping[str, Any] | None = None, decomposition: str | Decomposition | None = None, decomposition_kwargs: Mapping[str, Any] | None = None, cache: bool = True, **kwargs)[source]

Bases: Representation

Entity representations enriched by R-GCN.

The GCN employed by the entity encoder is adapted to include typed edges. The forward pass of the GCN is defined by:

\[\textbf{e}_{i}^{l+1} = \sigma \left( \sum_{r \in \mathcal{R}}\sum_{j\in \mathcal{N}_{i}^{r}} \frac{1}{c_{i,r}} \textbf{W}_{r}^{l} \textbf{e}_{j}^{l} + \textbf{W}_{0}^{l} \textbf{e}_{i}^{l}\right)\]

where \(\mathcal{N}_{i}^{r}\) is the set of neighbors of node \(i\) that are connected to \(i\) by relation \(r\), \(c_{i,r}\) is a fixed normalization constant (but it can also be introduced as an additional parameter), and \(\textbf{W}_{r}^{l} \in \mathbb{R}^{d^{(l)} \times d^{(l)}}\) and \(\textbf{W}_{0}^{l} \in \mathbb{R}^{d^{(l)} \times d^{(l)}}\) are weight matrices of the l-th layer of the R-GCN.

The encoder aggregates for each node \(e_i\) the latent representations of its neighbors and its own latent representation \(e_{i}^{l}\) into a new latent representation \(e_{i}^{l+1}\). In contrast to standard GCN, R-GCN defines relation specific transformations \(\textbf{W}_{r}^{l}\) which depend on the type and direction of an edge.

Since having one matrix for each relation introduces a large number of additional parameters, the authors instead propose to use a decomposition, cf. Decomposition.

Instantiate the R-GCN encoder.

Parameters:
  • triples_factory (CoreTriplesFactory) – The triples factory holding the training triples used for message passing.

  • max_id (int) – The maximum number of IDs. Could either be None (the default), or match the triples factory’s number of entities.

  • shape (tuple[int, ...]) – The shape information. If None, will propagate the shape information of the base entity representations.

  • entity_representations (HintOrType[Representation]) – The base entity representations (or a hint for them).

  • entity_representations_kwargs (OptionalKwargs) – Additional keyword-based parameters for the base entity representations.

  • num_layers (int) – The number of layers.

  • use_bias (bool) – Whether to use a bias.

  • activation (Hint[nn.Module]) – The activation.

  • activation_kwargs (Mapping[str, Any] | None) – Additional keyword based arguments passed if the activation is not pre-instantiated. Ignored otherwise.

  • edge_dropout (float) – The edge dropout to use. Does not apply to self-loops.

  • self_loop_dropout (float) – The self-loop dropout to use.

  • edge_weighting (Hint[EdgeWeighting]) – The edge weighting mechanism.

  • edge_weighting_kwargs (OptionalKwargs) – Additional keyword-based parameters for the edge weighting.

  • decomposition (Hint[Decomposition]) – The decomposition.

  • decomposition_kwargs (Mapping[str, Any] | None) – Additional keyword based arguments passed to the decomposition upon instantiation.

  • kwargs – Additional keyword-based parameters passed to Representation.

  • cache (bool) – Whether to cache representations.

Raises:

ValueError – If the triples factory creates inverse triples.

Note

4 resolvers are used in this function.

An explanation of resolvers and how to use them is given in https://class-resolver.readthedocs.io/en/latest/.

Methods Summary

post_parameter_update()

Apply constraints which should not be included in gradients.

reset_parameters()

Reset the module's parameters.

Methods Documentation

post_parameter_update() None[source]

Apply constraints which should not be included in gradients.

Return type:

None

reset_parameters()[source]

Reset the module’s parameters.