peal.architectures.basic_modules.SelfAttentionLayer¶
- class peal.architectures.basic_modules.SelfAttentionLayer[source]¶
Bases:
ModuleMulti-head self-attention over a
(B, L, C)sequence.A sinusoidal positional encoding is computed from the sequence length and added to the input on every forward pass before attention is applied.
- Parameters:
Methods
Add sin/cos positional encodings and apply self-attention.
- forward(x)[source]¶
Add sin/cos positional encodings and apply self-attention.
- Parameters:
x (
torch.Tensor) – Shape(B, L, C);Cmust be even for the encoding.- Returns:
Attention output of shape
(B, L, C).- Return type: