Meta Models
- class flood_forecast.meta_models.merging_model.MergingModel(method: str, other_params: Dict)[source]
- __init__(method: str, other_params: Dict)[source]
A model meant to help merge meta-data with the temporal data
- Parameters:
method (str) – The method you want to use (Bilinear, Bilinear2, MultiAttn, Concat)
other_params (Dict) – A dictionary of the additional parameters necessary to init the inner part.
..code-block:: python
merging_mod = MergingModel(“Bilinear”, {“in_features1”: 5, “in_features_2”:1, “out_features”:40 }) print(merging_mod(torch.rand(4, 5, 128), torch.rand(128)).shape) # (4, 40, 128)
…
- forward(temporal_data: Tensor, meta_data: Tensor)[source]
Performs the forward pass on both meta and temporal data. Returns merged tensor.
- Parameters:
temporal_data (torch.Tensor) – The temporal data should be in shape (batch_size, n_time_series, n_feats)
meta_data (torch.Tensor) – The meta-data passed to the model will have dimension (d_meta)
- Returns:
The combined tensor with both the meta-data and temporal data. Shape will vary.
- Return type:
torch.Tensor
- class flood_forecast.meta_models.merging_model.Concatenation(cat_dim: int, repeat: bool = True, use_layer: bool = False, combined_d: int = 1, out_shape: int = 1)[source]
- __init__(cat_dim: int, repeat: bool = True, use_layer: bool = False, combined_d: int = 1, out_shape: int = 1)[source]
A function to combine two tensors together via concantenation
- Parameters:
cat_dim (int) – The dimension that you want to concatenate along (e.g. 0, 1, 2)
repeat (bool, optional) – boolean of whether to repeate meta_data along temporal_dim , defaults to True
use_layer (bool, optional) – to use a layer to get the final out_shape , defaults to False
combined_shape (int, optional) – The final combined shape, defaults to 1
out_shape (int, optional) – The output shape you want, defaults to 1
- class flood_forecast.meta_models.merging_model.MultiModalSelfAttention(d_model: int, n_heads: int, dropout: float)[source]
- __init__(d_model: int, n_heads: int, dropout: float)[source]
Uses self-attention to combine the meta-data and the temporal data.
- Parameters:
d_model (int) – The dimension of the meta-data
n_heads (int) – The number of heads to use in multi-head mechanism
dropout (float) – The dropout score as a flow
- forward(temporal_data: Tensor, meta_data: Tensor) Tensor [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.