LearnableInversePositionalEncoding
- class rectools.models.nn.transformers.net_blocks.LearnableInversePositionalEncoding(use_pos_emb: bool, session_max_len: int, n_factors: int, use_scale_factor: bool = False, **kwargs: Any)[source]
Bases:
PositionalEncodingBaseClass to introduce learnable positional embeddings.
- Parameters
use_pos_emb (bool) – If
True, learnable positional encoding will be added to session item embeddings.session_max_len (int) – Maximum length of user sequence.
n_factors (int) – Latent embeddings size.
use_scale_factor (int) – Use multiplication embedding on the root of the dimension embedding
kwargs (Any) –
Methods
forward(sessions)Forward pass to add learnable positional encoding to sessions and mask padding elements.
Attributes
- forward(sessions: Tensor) Tensor[source]
Forward pass to add learnable positional encoding to sessions and mask padding elements.
- Parameters
sessions (torch.Tensor) – User sessions in the form of sequences of items ids.
- Returns
Encoded user sessions with added positional encoding if use_pos_emb is
True.- Return type
torch.Tensor