TimeDistributedEmbeddingBag¶
- class pytorch_forecasting.models.nn.embeddings.TimeDistributedEmbeddingBag(*args, batch_first: bool = False, **kwargs)[source]¶
Bases:
torch.nn.modules.sparse.EmbeddingBagInitializes internal Module state, shared by both nn.Module and ScriptModule.
Methods
forward(x)Forward pass of EmbeddingBag.
- forward(x)[source]¶
Forward pass of EmbeddingBag.
- Parameters
input (Tensor) – Tensor containing bags of indices into the embedding matrix.
offsets (Tensor, optional) – Only used when
inputis 1D.offsetsdetermines the starting index position of each bag (sequence) ininput.per_sample_weights (Tensor, optional) – a tensor of float / double weights, or None to indicate all weights should be taken to be
1. If specified,per_sample_weightsmust have exactly the same shape as input and is treated as having the sameoffsets, if those are notNone. Only supported formode='sum'.
- Returns
Tensor output shape of (B, embedding_dim).
Note
A few notes about
inputandoffsets:inputandoffsetshave to be of the same type, either int or longIf
inputis 2D of shape (B, N), it will be treated asBbags (sequences) each of fixed lengthN, and this will returnBvalues aggregated in a way depending on themode.offsetsis ignored and required to beNonein this case.If
inputis 1D of shape (N), it will be treated as a concatenation of multiple bags (sequences).offsetsis required to be a 1D tensor containing the starting index positions of each bag ininput. Therefore, foroffsetsof shape (B),inputwill be viewed as havingBbags. Empty bags (i.e., having 0-length) will have returned vectors filled by zeros.