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#
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 anint
, specifies the number of new random embeddings to initialize withnormal_()
. If alist[int]
, initializeslen(init)
new embeddings with the values of the given indices in the original embedding.freeze_prev (
bool
(default:True
)) – IfTrue
, gradients for the original embeddings are set to zero.
- Return type:
- Returns:
New
Embedding
instance withnum_embeddings
increased by the specifiedinit
and with gradients frozen for the firstembedding.num_embeddings
entries iffreeze_prev
isTrue
.