espnet2.asr_transducer.encoder.modules.positional_encoding.RelPositionalEncoding
Less than 1 minute
espnet2.asr_transducer.encoder.modules.positional_encoding.RelPositionalEncoding
class espnet2.asr_transducer.encoder.modules.positional_encoding.RelPositionalEncoding(size: int, dropout_rate: float = 0.0, max_len: int = 5000)
Bases: Module
Relative positional encoding.
- Parameters:
- size – Module size.
- max_len – Maximum input length.
- dropout_rate – Dropout rate.
Construct a RelativePositionalEncoding object.
extend_pe(x: Tensor, left_context: int = 0) → None
Reset positional encoding.
- Parameters:
- x – Input sequences. (B, T, ?)
- left_context – Number of previous frames the attention module can see in current chunk.
forward(x: Tensor, left_context: int = 0) → Tensor
Compute positional encoding.
- Parameters:
- x – Input sequences. (B, T, ?)
- left_context – Number of previous frames the attention module can see in current chunk.
- Returns: Positional embedding sequences. (B, 2 * (T - 1), ?)
- Return type: pos_enc