scvi.nn.Embedding#

class scvi.nn.Embedding(num_embeddings, embedding_dim, padding_idx=None, max_norm=None, norm_type=2.0, scale_grad_by_freq=False, sparse=False, _weight=None, _freeze=False, device=None, dtype=None)[source]#

Bases: Embedding

EXPERIMENTAL Embedding layer with utility methods for extending.

Notes

Lifecycle: experimental in v1.2.

Attributes table#

Methods table#

extend(embedding, init[, freeze_prev])

Factory class method for extending an existing Embedding.

Attributes#

Embedding.num_embeddings: int#
Embedding.embedding_dim: int#
Embedding.padding_idx: Optional[int]#
Embedding.max_norm: Optional[float]#
Embedding.norm_type: float#
Embedding.scale_grad_by_freq: bool#
Embedding.weight: Tensor#
Embedding.freeze: bool#
Embedding.sparse: bool#
Embedding.training: bool#

Methods#

classmethod Embedding.extend(embedding, init, freeze_prev=True)[source]#

Factory class method for extending an existing Embedding.

Initializes new embeddings with random values or copies from the original embedding.

Parameters:
  • embedding (Embedding) – Embedding layer to extend. Not modified in-place as a new instance is returned.

  • init (int | list[int]) – If an int, specifies the number of new random embeddings to initialize with normal_(). If a list[int], initializes len(init) new embeddings with the values of the given indices in the original embedding.

  • freeze_prev (bool (default: True)) – If True, gradients for the original embeddings are set to zero.

Return type:

Embedding

Returns:

New Embedding instance with num_embeddings increased by the specified init and with gradients frozen for the first embedding.num_embeddings entries if freeze_prev is True.