RADAR.time_series.algorithms.modelsTransformersTS.vanillaTransformer
Submodules
RADAR.time_series.algorithms.modelsTransformersTS.vanillaTransformer.attn module
- class RADAR.time_series.algorithms.modelsTransformersTS.vanillaTransformer.attn.MultiHeadAttention(*args: Any, **kwargs: Any)[source]
Bases:
ModuleThe MultiHeadAttention class is used to perform multi-head attention in the transformer model. It splits the input vectors into different heads or projections, calculates the attention scores, and concatenates the results before applying a linear transformation to obtain the final output.
d_model: number of units in the model (dimensionality of the feature vectors)
RADAR.time_series.algorithms.modelsTransformersTS.vanillaTransformer.decoder module
RADAR.time_series.algorithms.modelsTransformersTS.vanillaTransformer.embed module
- class RADAR.time_series.algorithms.modelsTransformersTS.vanillaTransformer.embed.PositionalEmbedding(*args: Any, **kwargs: Any)[source]
Bases:
Module
- class RADAR.time_series.algorithms.modelsTransformersTS.vanillaTransformer.embed.PositionalEncoding(*args: Any, **kwargs: Any)[source]
Bases:
ModulePositional Encoding class for Transformers.
This module implements positional encoding for a Transformer model. Positional encoding helps maintain the temporal information of the data. The chosen implementation follows the vanilla method as originally defined in the “Attention Is All You Need” paper.
- Parameters:
d_model (int) – The dimensionality of the model, representing the number of features or channels in the input and output embeddings.
dropout (float, optional) – The dropout probability applied to the positional encodings, by default 0.1.
max_len (int, optional) – The maximum sequence length for which positional encodings are calculated, by default 5000.
- pe
The positional encodings matrix.
- Type:
torch.Tensor
Examples
Create a PositionalEncoding instance:
>>> positional_encoder = PositionalEncoding(d_model=512, dropout=0.1, max_len=1000) >>> input_data = torch.rand(32, 1000, 512) >>> output_data = positional_encoder(input_data)
Notes
PositionalEncoding is a crucial component in Transformer models to capture the order of tokens in input sequences.
References
Vaswani, A., Shazeer, N., Parmar, N., Uszkoreit, J., Jones, L., Gomez, A.N., … & Polosukhin, I. (2017). Attention is all you need. In Advances in neural information processing systems (pp. 30-31).
- forward(x, pos=0)[source]
Apply positional encoding to the input data.
- Parameters:
x (torch.Tensor) – The input tensor to which positional encoding is applied.
pos (int, optional) – The starting position for adding positional encodings, by default 0.
- Returns:
The input tensor with positional encoding added and dropout applied.
- Return type:
torch.Tensor
RADAR.time_series.algorithms.modelsTransformersTS.vanillaTransformer.encoder module
RADAR.time_series.algorithms.modelsTransformersTS.vanillaTransformer.model module
- class RADAR.time_series.algorithms.modelsTransformersTS.vanillaTransformer.model.Transformer(*args: Any, **kwargs: Any)[source]
Bases:
ModuleTransformer para detección de anomalías en series temporales.
- Parameters:
size_enc_in – dimensión de entrada del encoder
size_dec_in – dimensión de entrada/salida del decoder
ulayers_feedfwd – número de unidades en las capas feedforward
d_qk – dimensión de claves y consultas (Q/K)
d_v – dimensión de los valores (V)
d_model – dimensión interna del modelo
n_layers – número de capas en encoder y decoder
n_heads – número de cabezas de atención
dropout_rate – tasa de dropout
embedding_scale – si escalar embeddings por sqrt(d_model)
attns_outs – si retornar atenciones como salida