docstr: :param embedding_size: it is the maximum embedding size, the actual
         size will be `min(vocabulary_size, embedding_size)`
         for `dense` representations and exactly `vocabulary_size`
         for the `sparse` encoding, where `vocabulary_size` is
         the number of different strings appearing in the training set
         in the column the feature is named after (plus 1 for
         `<UNK>`).
  :type embedding_size: Integer
  :param embeddings_on_cpu: by default embeddings matrices are stored
         on GPU memory if a GPU is used, as it allows
         for faster access, but in some cases the embedding matrix
         may be really big and this parameter forces the placement
         of the embedding matrix in regular memory and the CPU is used
         to resolve them, slightly slowing down the process
         as a result of data transfer between CPU and GPU memory.
  :param num_layers: the number of stacked recurrent layers.
  :type num_layers: Integer
  :param cell_type: the type of recurrent cell to use.
         Available values are: `rnn`, `lstm`, `lstm_block`, `lstm`,
         `ln`, `lstm_cudnn`, `gru`, `gru_block`, `gru_cudnn`.
         For reference about the differences between the cells please
         refer to PyTorch's documentation. We suggest to use the
         `block` variants on CPU and the `cudnn` variants on GPU
         because of their increased speed.
  :type cell_type: str
  :param hidden_size: the size of the state of the rnn.
  :type hidden_size: Integer
  :param bidirectional: if `True` two recurrent networks will perform
         encoding in the forward and backward direction and
         their outputs will be concatenated.
  :type bidirectional: Boolean
  :param activation: Activation function to use.
  :type activation: string
  :param recurrent_activation: Activation function to use for the
          recurrent step.
  :type recurrent_activation: string
  :param use_bias: bool determines where to use a bias vector
  :type use_bias: bool
  :param unit_forget_bias: if True add 1 to the bias forget gate at
         initialization.
  :type unit_forget_bias: bool
  :param weights_initializer: Initializer for the weights (aka kernel)
         matrix
  :type weights_initializer: string
  :param recurrent_initializer: Initializer for the recurrent weights
         matrix
  :type recurrent_initializer: string
  :param bias_initializer: Initializer for the bias vector
  :type bias_initializer: string
  :param dropout: determines if there should be a dropout layer before
         returning the encoder output.
  :type dropout: float
  :param recurrent_dropout: Dropout rate for the RNN encoder of the H3 embeddings.
  :type recurrent_dropout: float
docstr_tok: [":","param","embedding_size",":","it","is","the","maximum","embedding","size",",","the","actual","size","will","be","`","min","(","vocabulary_size",",","embedding_size",")","`","for","`","dense","`","representations","and","exactly","`","vocabulary_size","`","for","the","`","sparse","`","encoding",",","where","`","vocabulary_size","`","is","the","number","of","different","strings","appearing","in","the","training","set","in","the","column","the","feature","is","named","after","(","plus","1","for","`","<","UNK",">","`",")",".",":","type","embedding_size",":","Integer",":","param","embeddings_on_cpu",":","by","default","embeddings","matrices","are","stored","on","GPU","memory","if","a","GPU","is","used",",","as","it","allows","for","faster","access",",","but","in","some","cases","the","embedding","matrix","may","be","really","big","and","this","parameter","forces","the","placement","of","the","embedding","matrix","in","regular","memory","and","the","CPU","is","used","to","resolve","them",",","slightly","slowing","down","the","process","as","a","result","of","data","transfer","between","CPU","and","GPU","memory",".",":","param","num_layers",":","the","number","of","stacked","recurrent","layers",".",":","type","num_layers",":","Integer",":","param","cell_type",":","the","type","of","recurrent","cell","to","use",".","Available","values","are",":","`","rnn","`",",","`","lstm","`",",","`","lstm_block","`",",","`","lstm","`",",","`","ln","`",",","`","lstm_cudnn","`",",","`","gru","`",",","`","gru_block","`",",","`","gru_cudnn","`",".","For","reference","about","the","differences","between","the","cells","please","refer","to","PyTorch","'s","documentation",".","We","suggest","to","use","the","`","block","`","variants","on","CPU","and","the","`","cudnn","`","variants","on","GPU","because","of","their","increased","speed",".",":","type","cell_type",":","str",":","param","hidden_size",":","the","size","of","the","state","of","the","rnn",".",":","type","hidden_size",":","Integer",":","param","bidirectional",":","if","`","True","`","two","recurrent","networks","will","perform","encoding","in","the","forward","and","backward","direction","and","their","outputs","will","be","concatenated",".",":","type","bidirectional",":","Boolean",":","param","activation",":","Activation","function","to","use",".",":","type","activation",":","string",":","param","recurrent_activation",":","Activation","function","to","use","for","the","recurrent","step",".",":","type","recurrent_activation",":","string",":","param","use_bias",":","bool","determines","where","to","use","a","bias","vector",":","type","use_bias",":","bool",":","param","unit_forget_bias",":","if","True","add","1","to","the","bias","forget","gate","at","initialization",".",":","type","unit_forget_bias",":","bool",":","param","weights_initializer",":","Initializer","for","the","weights","(","aka","kernel",")","matrix",":","type","weights_initializer",":","string",":","param","recurrent_initializer",":","Initializer","for","the","recurrent","weights","matrix",":","type","recurrent_initializer",":","string",":","param","bias_initializer",":","Initializer","for","the","bias","vector",":","type","bias_initializer",":","string",":","param","dropout",":","determines","if","there","should","be","a","dropout","layer","before","returning","the","encoder","output",".",":","type","dropout",":","float",":","param","recurrent_dropout",":","Dropout","rate","for","the","RNN","encoder","of","the","H3","embeddings",".",":","type","recurrent_dropout",":","float"]
code: def __init__(
      self,
      embedding_size: int = 10,
      embeddings_on_cpu: bool = False,
      num_layers: int = 1,
      hidden_size: int = 10,
      cell_type: str = "rnn",
      bidirectional: bool = False,
      activation: str = "tanh",
      recurrent_activation: str = "sigmoid",
      use_bias: bool = True,
      unit_forget_bias: bool = True,
      weights_initializer: str = "xavier_uniform",
      recurrent_initializer: str = "orthogonal",
      bias_initializer: str = "zeros",
      dropout: float = 0.0,
      recurrent_dropout: float = 0.0,
      reduce_output: str = "last",
      encoder_config=None,
      **kwargs,
  ):
      """
      :param embedding_size: it is the maximum embedding size, the actual
             size will be `min(vocabulary_size, embedding_size)`
             for `dense` representations and exactly `vocabulary_size`
             for the `sparse` encoding, where `vocabulary_size` is
             the number of different strings appearing in the training set
             in the column the feature is named after (plus 1 for
             `<UNK>`).
      :type embedding_size: Integer
      :param embeddings_on_cpu: by default embeddings matrices are stored
             on GPU memory if a GPU is used, as it allows
             for faster access, but in some cases the embedding matrix
             may be really big and this parameter forces the placement
             of the embedding matrix in regular memory and the CPU is used
             to resolve them, slightly slowing down the process
             as a result of data transfer between CPU and GPU memory.
      :param num_layers: the number of stacked recurrent layers.
      :type num_layers: Integer
      :param cell_type: the type of recurrent cell to use.
             Available values are: `rnn`, `lstm`, `lstm_block`, `lstm`,
             `ln`, `lstm_cudnn`, `gru`, `gru_block`, `gru_cudnn`.
             For reference about the differences between the cells please
             refer to PyTorch's documentation. We suggest to use the
             `block` variants on CPU and the `cudnn` variants on GPU
             because of their increased speed.
      :type cell_type: str
      :param hidden_size: the size of the state of the rnn.
      :type hidden_size: Integer
      :param bidirectional: if `True` two recurrent networks will perform
             encoding in the forward and backward direction and
             their outputs will be concatenated.
      :type bidirectional: Boolean
      :param activation: Activation function to use.
      :type activation: string
      :param recurrent_activation: Activation function to use for the
              recurrent step.
      :type recurrent_activation: string
      :param use_bias: bool determines where to use a bias vector
      :type use_bias: bool
      :param unit_forget_bias: if True add 1 to the bias forget gate at
             initialization.
      :type unit_forget_bias: bool
      :param weights_initializer: Initializer for the weights (aka kernel)
             matrix
      :type weights_initializer: string
      :param recurrent_initializer: Initializer for the recurrent weights
             matrix
      :type recurrent_initializer: string
      :param bias_initializer: Initializer for the bias vector
      :type bias_initializer: string
      :param dropout: determines if there should be a dropout layer before
             returning the encoder output.
      :type dropout: float
      :param recurrent_dropout: Dropout rate for the RNN encoder of the H3 embeddings.
      :type recurrent_dropout: float
      """
      super().__init__()
      self.config = encoder_config
  
      logger.debug(f" {self.name}")
  
      self.embedding_size = embedding_size
  
      self.h3_embed = H3Embed(
          embedding_size,
          embeddings_on_cpu=embeddings_on_cpu,
          dropout=dropout,
          weights_initializer=weights_initializer,
          bias_initializer=bias_initializer,
          reduce_output="None",
      )
  
      logger.debug("  RecurrentStack")
      self.recurrent_stack = RecurrentStack(
          input_size=self.h3_embed.output_shape[0],
          max_sequence_length=H3_INPUT_SIZE,
          hidden_size=hidden_size,
          cell_type=cell_type,
          num_layers=num_layers,
          bidirectional=bidirectional,
          use_bias=use_bias,
          dropout=recurrent_dropout,
      )
  
imports: import logging
  from typing import Dict, List, Optional, Type
  import torch
  from ludwig.api_annotations import DeveloperAPI
  from ludwig.constants import ENCODER_OUTPUT, ENCODER_OUTPUT_STATE, H3
  from ludwig.encoders.base import Encoder
  from ludwig.encoders.registry import register_encoder
  from ludwig.encoders.types import EncoderOutputDict
  from ludwig.modules.embedding_modules import Embed, EmbedSequence
  from ludwig.modules.fully_connected_modules import FCStack
  from ludwig.modules.initializer_modules import get_initializer
  from ludwig.modules.recurrent_modules import RecurrentStack
  from ludwig.modules.reduction_modules import SequenceReducer
  from ludwig.schema.encoders.base import BaseEncoderConfig
  from ludwig.schema.encoders.h3_encoders import H3EmbedConfig, H3RNNConfig, H3WeightedSumConfig
  from ludwig.utils import torch_utils
label_desc: Use image node_id 1 to create a new H3RNN object from inherited base classes: Encoder with example: obj = H3RNN(embedding_size, embeddings_on_cpu, num_layers, hidden_size, cell_type, bidirectional, activation, recurrent_activation, use_bias, unit_forget_bias, weights_initializer, recurrent_initializer, bias_initializer, dropout, recurrent_dropout, reduce_output, encoder_config)