class_docstr: Defines Temporal Fusion Transformer.
  
  Attributes:
    name: Name of model
    time_steps: Total number of input time steps per forecast date (i.e. Width
      of Temporal fusion decoder N)
    input_size: Total number of inputs
    output_size: Total number of outputs
    category_counts: Number of categories per categorical variable
    n_multiprocessing_workers: Number of workers to use for parallel
      computations
    column_definition: List of tuples of (string, DataType, InputType) that
      define each column
    quantiles: Quantiles to forecast for TFT
    use_cudnn: Whether to use Keras CuDNNLSTM or standard LSTM layers
    hidden_layer_size: Internal state size of TFT
    dropout_rate: Dropout discard rate
    max_gradient_norm: Maximum norm for gradient clipping
    learning_rate: Initial learning rate of ADAM optimizer
    minibatch_size: Size of minibatches for training
    num_epochs: Maximum number of epochs for training
    early_stopping_patience: Maximum number of iterations of non-improvement
      before early stopping kicks in
    num_encoder_steps: Size of LSTM encoder -- i.e. number of past time steps
      before forecast date to use
    num_stacks: Number of self-attention layers to apply (default is 1 for basic
      TFT)
    num_heads: Number of heads for interpretable mulit-head attention
    model: Keras model for TFT
class_docstr_tok: ["Defines","Temporal","Fusion","Transformer",".","Attributes",":","name",":","Name","of","model","time_steps",":","Total","number","of","input","time","steps","per","forecast","date","(","i.e",".","Width","of","Temporal","fusion","decoder","N",")","input_size",":","Total","number","of","inputs","output_size",":","Total","number","of","outputs","category_counts",":","Number","of","categories","per","categorical","variable","n_multiprocessing_workers",":","Number","of","workers","to","use","for","parallel","computations","column_definition",":","List","of","tuples","of","(","string",",","DataType",",","InputType",")","that","define","each","column","quantiles",":","Quantiles","to","forecast","for","TFT","use_cudnn",":","Whether","to","use","Keras","CuDNNLSTM","or","standard","LSTM","layers","hidden_layer_size",":","Internal","state","size","of","TFT","dropout_rate",":","Dropout","discard","rate","max_gradient_norm",":","Maximum","norm","for","gradient","clipping","learning_rate",":","Initial","learning","rate","of","ADAM","optimizer","minibatch_size",":","Size","of","minibatches","for","training","num_epochs",":","Maximum","number","of","epochs","for","training","early_stopping_patience",":","Maximum","number","of","iterations","of","non-improvement","before","early","stopping","kicks","in","num_encoder_steps",":","Size","of","LSTM","encoder","--","i.e",".","number","of","past","time","steps","before","forecast","date","to","use","num_stacks",":","Number","of","self-attention","layers","to","apply","(","default","is","1","for","basic","TFT",")","num_heads",":","Number","of","heads","for","interpretable","mulit-head","attention","model",":","Keras","model","for","TFT"]
docstr: Transforms raw inputs to embeddings.
  
  Applies linear transformation onto continuous variables and uses embeddings
  for categorical variables.
  
  Args:
    all_inputs: Inputs to transform
  
  Returns:
    Tensors for transformed inputs.
docstr_tok: ["Transforms","raw","inputs","to","embeddings",".","Applies","linear","transformation","onto","continuous","variables","and","uses","embeddings","for","categorical","variables",".","Args",":","all_inputs",":","Inputs","to","transform","Returns",":","Tensors","for","transformed","inputs","."]
code: def get_tft_embeddings(self, all_inputs):
      """Transforms raw inputs to embeddings.
  
      Applies linear transformation onto continuous variables and uses embeddings
      for categorical variables.
  
      Args:
        all_inputs: Inputs to transform
  
      Returns:
        Tensors for transformed inputs.
      """
  
      time_steps = self.time_steps
  
      # Sanity checks
      for i in self._known_regular_input_idx:
          if i in self._input_obs_loc:
              raise ValueError("Observation cannot be known a priori!")
      for i in self._input_obs_loc:
          if i in self._static_input_loc:
              raise ValueError("Observation cannot be static!")
  
      if all_inputs.get_shape().as_list()[-1] != self.input_size:
          raise ValueError(
              "Illegal number of inputs! Inputs observed={}, expected={}".format(
                  all_inputs.get_shape().as_list()[-1], self.input_size
              )
          )
  
      num_categorical_variables = len(self.category_counts)
      num_regular_variables = (
          self.input_size - num_categorical_variables
      )
  
      embedding_sizes = [
          self.hidden_layer_size
          for i, size in enumerate(self.category_counts)
      ]
  
      embeddings = []
      for i in range(num_categorical_variables):
          embedding = tf.keras.Sequential(
              [
                  tf.keras.layers.InputLayer([time_steps]),
                  tf.keras.layers.Embedding(
                      self.category_counts[i],
                      embedding_sizes[i],
                      input_length=time_steps,
                      dtype=tf.float32,
                  ),
              ]
          )
          embeddings.append(embedding)
  
      regular_inputs, categorical_inputs = (
          all_inputs[:, :, :num_regular_variables],
          all_inputs[:, :, num_regular_variables:],
      )
  
      embedded_inputs = [
          embeddings[i](categorical_inputs[Ellipsis, i])
          for i in range(num_categorical_variables)
      ]
  
      # Static inputs
      if self._static_input_loc:
          static_inputs = [
              tf.keras.layers.Dense(self.hidden_layer_size)(
                  regular_inputs[:, 0, i : i + 1]
              )
              for i in range(num_regular_variables)
              if i in self._static_input_loc
          ] + [
              embedded_inputs[i][:, 0, :]
              for i in range(num_categorical_variables)
              if i + num_regular_variables in self._static_input_loc
          ]
          static_inputs = tf.keras.backend.stack(static_inputs, axis=1)
  
      else:
          static_inputs = None
  
      def convert_real_to_embedding(x):
          """Applies linear transformation for time-varying inputs."""
          return tf.keras.layers.TimeDistributed(
              tf.keras.layers.Dense(self.hidden_layer_size)
          )(x)
  
      # Targets
      obs_inputs = tf.keras.backend.stack(
          [
              convert_real_to_embedding(
                  regular_inputs[Ellipsis, i : i + 1]
              )
              for i in self._input_obs_loc
          ],
          axis=-1,
      )
  
      # Observed (a prioir unknown) inputs
      wired_embeddings = []
      for i in range(num_categorical_variables):
          if (
              i not in self._known_categorical_input_idx
              and i + num_regular_variables not in self._input_obs_loc
          ):
              e = embeddings[i](categorical_inputs[:, :, i])
              wired_embeddings.append(e)
  
      unknown_inputs = []
      for i in range(regular_inputs.shape[-1]):
          if (
              i not in self._known_regular_input_idx
              and i not in self._input_obs_loc
          ):
              e = convert_real_to_embedding(
                  regular_inputs[Ellipsis, i : i + 1]
              )
              unknown_inputs.append(e)
  
      if unknown_inputs + wired_embeddings:
          unknown_inputs = tf.keras.backend.stack(
              unknown_inputs + wired_embeddings, axis=-1
          )
      else:
          unknown_inputs = None
  
      # A priori known inputs
      known_regular_inputs = [
          convert_real_to_embedding(regular_inputs[Ellipsis, i : i + 1])
          for i in self._known_regular_input_idx
          if i not in self._static_input_loc
      ]
      known_categorical_inputs = [
          embedded_inputs[i]
          for i in self._known_categorical_input_idx
          if i + num_regular_variables not in self._static_input_loc
      ]
  
      known_combined_layer = tf.keras.backend.stack(
          known_regular_inputs + known_categorical_inputs, axis=-1
      )
  
      return (
          unknown_inputs,
          known_combined_layer,
          obs_inputs,
          static_inputs,
      )
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import gc
  import json
  import os
  import shutil
  import data_formatters.base
  import libs.utils
  import numpy
  import pandas
  import tensorflow
label_desc: Use image node_id 2 for calling the TemporalFusionTransformer obj's underlying member method code with example usage: obj.get_tft_embeddings(all_inputs) and returns: unknown_inputs,  known_combined_layer,  obs_inputs,  static_inputs, tf