espnet.nets.pytorch_backend.transformer.embedding.StreamPositionalEncoding
Less than 1 minute
espnet.nets.pytorch_backend.transformer.embedding.StreamPositionalEncoding
class espnet.nets.pytorch_backend.transformer.embedding.StreamPositionalEncoding(d_model, dropout_rate, max_len=5000)
Bases: Module
Streaming Positional encoding.
- Parameters:
- d_model (int) – Embedding dimension.
- dropout_rate (float) – Dropout rate.
- max_len (int) – Maximum input length.
Construct an PositionalEncoding object.
extend_pe(length, device, dtype)
Reset the positional encodings.
forward(x: Tensor, start_idx: int = 0)
Add positional encoding.
- Parameters:x (torch.Tensor) – Input tensor (batch, time, *).
- Returns: Encoded tensor (batch, time, *).
- Return type: torch.Tensor