Basic Transformer
- class flood_forecast.transformer_xl.transformer_basic.SimpleTransformer(number_time_series: int, seq_length: int = 48, output_seq_len: int = None, d_model: int = 128, n_heads: int = 8, dropout=0.1, forward_dim=2048, sigmoid=False)[source]
- __init__(number_time_series: int, seq_length: int = 48, output_seq_len: int = None, d_model: int = 128, n_heads: int = 8, dropout=0.1, forward_dim=2048, sigmoid=False)[source]
A full transformer model.
- Parameters:
number_time_series (int) – The total number of time series present (e.g. n_feature_time_series + n_targets)
seq_length (int, optional) – The length of your input sequence, defaults to 48
output_seq_len (int, optional) – The length of your output sequence, defaults to None
d_model (int, optional) – The dimensions of your model, defaults to 128
n_heads (int, optional) – The number of heads in each encoder/decoder block, defaults to 8
dropout (float, optional) – The fraction of dropout you wish to apply during training, defaults to 0.1 (currently not functional)
forward_dim (int, optional) – Currently not functional, defaults to 2048
sigmoid (bool, optional) – Whether to apply a sigmoid activation to the final layer (useful for binary classification), defaults to False
- forward(x: Tensor, t: Tensor, tgt_mask=None, src_mask=None)[source]
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class flood_forecast.transformer_xl.transformer_basic.CustomTransformerDecoder(seq_length: int, output_seq_length: int, n_time_series: int, d_model=128, output_dim=1, n_layers_encoder=6, forward_dim=2048, dropout=0.1, use_mask=False, meta_data=None, final_act=None, squashed_embedding=False, n_heads=8)[source]
- __init__(seq_length: int, output_seq_length: int, n_time_series: int, d_model=128, output_dim=1, n_layers_encoder=6, forward_dim=2048, dropout=0.1, use_mask=False, meta_data=None, final_act=None, squashed_embedding=False, n_heads=8)[source]
Uses a number of encoder layers with simple linear decoder layer.
- Parameters:
seq_length (int) – The number of historical time-steps fed into the model in each forward pass.
output_seq_length (int) – The number of forecasted time-steps outputted by the model.
n_time_series (int) – The total number of time series present (targets + features)
d_model (int, optional) – The embedding dim of the mode, defaults to 128
output_dim (int, optional) – The output dimension (should correspond to n_targets), defaults to 1
n_layers_encoder (int, optional) – The number of encoder layers, defaults to 6
forward_dim (int, optional) – The forward embedding dim, defaults to 2048
dropout (float, optional) – How much dropout to use, defaults to 0.1
use_mask (bool, optional) – Whether to use subsquent sequence mask during training, defaults to False
meta_data (str, optional) – Whether to use static meta-data, defaults to None
final_act (str, optional) – Whether to use a final activation function, defaults to None
squashed_embedding (bool, optional) – Whether to create a one 1-D time embedding, defaults to False
n_heads (int, optional) – [description], defaults to 8
- class flood_forecast.transformer_xl.transformer_basic.SimplePositionalEncoding(d_model, dropout=0.1, max_len=5000)[source]
- flood_forecast.transformer_xl.transformer_basic.greedy_decode(model, src: Tensor, max_len: int, real_target: Tensor, unsqueeze_dim=1, output_len=1, device='cpu', multi_targets=1, probabilistic=False, scaler=None)[source]
Mechanism to sequentially decode the model :src The Historical time series values :real_target The real values (they should be masked), however if you want can include known real values. :returns torch.Tensor