class_docstr: Temporal Fusion Transformer neural network.
  
  Partially based on the implementation in github.com/kashif/pytorch-transformer-ts.
  
  Inputs feat_static_real, feat_static_cat and feat_dynamic_real are mandatory.
  Inputs feat_dynamic_cat, past_feat_dynamic_real and past_feat_dynamic_cat are optional.
class_docstr_tok: ["Temporal","Fusion","Transformer","neural","network",".","Partially","based","on","the","implementation","in","github.com\/kashif\/pytorch-transformer-ts",".","Inputs","feat_static_real",",","feat_static_cat","and","feat_dynamic_real","are","mandatory",".","Inputs","feat_dynamic_cat",",","past_feat_dynamic_real","and","past_feat_dynamic_cat","are","optional","."]
code: def __init__(
      self,
      context_length: int,
      prediction_length: int,
      d_feat_static_real: Optional[
          List[int]
      ] = None,  #  Defaults to [1]
      c_feat_static_cat: Optional[List[int]] = None,  #  Defaults to [1]
      d_feat_dynamic_real: Optional[
          List[int]
      ] = None,  # Defaults to [1]
      c_feat_dynamic_cat: Optional[List[int]] = None,  # Defaults to []
      d_past_feat_dynamic_real: Optional[
          List[int]
      ] = None,  # Defaults to []
      c_past_feat_dynamic_cat: Optional[
          List[int]
      ] = None,  # Defaults to []
      num_heads: int = 4,
      d_hidden: int = 32,
      d_var: int = 32,
      dropout_rate: float = 0.1,
      distr_output: Optional[Output] = None,
  ):
      super().__init__()
  
      self.context_length = context_length
      self.prediction_length = prediction_length
      self.num_heads = num_heads
      self.d_hidden = d_hidden
      self.d_var = d_var
      self.dropout_rate = dropout_rate
  
      if distr_output is None:
          distr_output = QuantileOutput(
              [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]
          )
      self.distr_output = distr_output
      self.args_proj = self.distr_output.get_args_proj(
          in_features=self.d_hidden
      )
  
      self.d_feat_static_real = d_feat_static_real or [1]
      self.d_feat_dynamic_real = d_feat_dynamic_real or [1]
      self.d_past_feat_dynamic_real = d_past_feat_dynamic_real or []
      self.c_feat_static_cat = c_feat_static_cat or [1]
      self.c_feat_dynamic_cat = c_feat_dynamic_cat or []
      self.c_past_feat_dynamic_cat = c_past_feat_dynamic_cat or []
  
      self.num_feat_static = len(self.d_feat_static_real) + len(
          self.c_feat_static_cat
      )
      self.num_feat_dynamic = len(self.d_feat_dynamic_real) + len(
          self.c_feat_dynamic_cat
      )
      self.num_past_feat_dynamic = len(
          self.d_past_feat_dynamic_real
      ) + len(self.c_past_feat_dynamic_cat)
  
      self.scaler = StdScaler(dim=1, keepdim=True)
  
      self.target_proj = nn.Linear(
          in_features=1, out_features=self.d_var
      )
      # Past-only dynamic features
      if self.d_past_feat_dynamic_real:
          self.past_feat_dynamic_proj: Optional[
              FeatureProjector
          ] = FeatureProjector(
              feature_dims=self.d_past_feat_dynamic_real,
              embedding_dims=[self.d_var]
              * len(self.d_past_feat_dynamic_real),
          )
      else:
          self.past_feat_dynamic_proj = None
  
      if self.c_past_feat_dynamic_cat:
          self.past_feat_dynamic_embed: Optional[
              FeatureEmbedder
          ] = FeatureEmbedder(
              cardinalities=self.c_past_feat_dynamic_cat,
              embedding_dims=[self.d_var]
              * len(self.c_past_feat_dynamic_cat),
          )
      else:
          self.past_feat_dynamic_embed = None
  
      # Known dynamic features
      if self.d_feat_dynamic_real:
          self.feat_dynamic_proj: Optional[
              FeatureProjector
          ] = FeatureProjector(
              feature_dims=self.d_feat_dynamic_real,
              embedding_dims=[self.d_var]
              * len(self.d_feat_dynamic_real),
          )
      else:
          self.feat_dynamic_proj = None
  
      if self.c_feat_dynamic_cat:
          self.feat_dynamic_embed: Optional[
              FeatureEmbedder
          ] = FeatureEmbedder(
              cardinalities=self.c_feat_dynamic_cat,
              embedding_dims=[self.d_var]
              * len(self.c_feat_dynamic_cat),
          )
      else:
          self.feat_dynamic_embed = None
  
      # Static features
      if self.d_feat_static_real:
          self.feat_static_proj: Optional[
              FeatureProjector
          ] = FeatureProjector(
              feature_dims=self.d_feat_static_real,
              embedding_dims=[self.d_var]
              * len(self.d_feat_static_real),
          )
      else:
          self.feat_static_proj = None
  
      if self.c_feat_static_cat:
          self.feat_static_embed: Optional[
              FeatureEmbedder
          ] = FeatureEmbedder(
              cardinalities=self.c_feat_static_cat,
              embedding_dims=[self.d_var] * len(self.c_feat_static_cat),
          )
      else:
          self.feat_static_embed = None
  
      self.static_selector = VariableSelectionNetwork(
          d_hidden=self.d_var,
          num_vars=self.num_feat_static,
          dropout=self.dropout_rate,
      )
      self.ctx_selector = VariableSelectionNetwork(
          d_hidden=self.d_var,
          num_vars=self.num_past_feat_dynamic
          + self.num_feat_dynamic
          + 1,
          add_static=True,
          dropout=self.dropout_rate,
      )
      self.tgt_selector = VariableSelectionNetwork(
          d_hidden=self.d_var,
          num_vars=self.num_feat_dynamic,
          add_static=True,
          dropout=self.dropout_rate,
      )
      self.selection = GatedResidualNetwork(
          d_hidden=self.d_var,
          dropout=self.dropout_rate,
      )
      self.enrichment = GatedResidualNetwork(
          d_hidden=self.d_var,
          dropout=self.dropout_rate,
      )
      self.state_h = GatedResidualNetwork(
          d_hidden=self.d_var,
          d_output=self.d_hidden,
          dropout=self.dropout_rate,
      )
      self.state_c = GatedResidualNetwork(
          d_hidden=self.d_var,
          d_output=self.d_hidden,
          dropout=self.dropout_rate,
      )
      self.temporal_encoder = TemporalFusionEncoder(
          d_input=self.d_var,
          d_hidden=self.d_hidden,
      )
      self.temporal_decoder = TemporalFusionDecoder(
          context_length=self.context_length,
          prediction_length=self.prediction_length,
          d_hidden=self.d_hidden,
          d_var=self.d_var,
          num_heads=self.num_heads,
          dropout=self.dropout_rate,
      )
  
file_path: gluonts/src/gluonts/torch/model/tft/module.py
imports: import logging
  from typing import Dict, List, Optional, Tuple
  import torch
  import torch.nn
  from gluonts.core.component import validated
  from gluonts.model import Input, InputSpec
  from gluonts.torch.distributions import Output
  from gluonts.torch.distributions.quantile_output import QuantileOutput
  from gluonts.torch.scaler import StdScaler
  from gluonts.torch.util import weighted_average
  from .layers import FeatureEmbedder, FeatureProjector, GatedResidualNetwork, TemporalFusionDecoder, TemporalFusionEncoder, VariableSelectionNetwork
label_desc: Use image node_id 1 to create a new TemporalFusionTransformerModel object from inherited base classes: nn with example: obj = TemporalFusionTransformerModel(context_length, prediction_length, d_feat_static_real, c_feat_static_cat, d_feat_dynamic_real, c_feat_dynamic_cat, d_past_feat_dynamic_real, c_past_feat_dynamic_cat, num_heads, d_hidden, d_var, dropout_rate, distr_output)