PretrainedInitializer

class PretrainedInitializer(tensor)[source]

Bases: object

Initialize tensor with pretrained weights.

Example usage:

import torch
from pykeen.pipeline import pipeline
from pykeen.nn.init import PretrainedInitializer

# this is usually loaded from somewhere else
# the shape must match, as well as the entity-to-id mapping
pretrained_embedding_tensor = torch.rand(14, 128)

result = pipeline(
    dataset="nations",
    model="transe",
    model_kwargs=dict(
        embedding_dim=pretrained_embedding_tensor.shape[-1],
        entity_initializer=PretrainedInitializer(tensor=pretrained_embedding_tensor),
    ),
)

Initialize the initializer.

Parameters:

tensor (FloatTensor) – the tensor of pretrained embeddings.

Methods Summary

__call__(x)

Initialize the tensor with the given tensor.

as_embedding(**kwargs)

Get a static embedding from this pre-trained initializer.

Methods Documentation

__call__(x)[source]

Initialize the tensor with the given tensor.

Return type:

Tensor

Parameters:

x (Tensor) –

as_embedding(**kwargs)[source]

Get a static embedding from this pre-trained initializer.

Parameters:

kwargs (Any) – Keyword arguments to pass to pykeen.nn.representation.Embedding

Returns:

An embedding

Return type:

pykeen.nn.representation.Embedding