class_docstr: RNN embedding class: apply the RNN network to a sequence of word embeddings.
  
  Parameters
  ----------
  input_size : int
      The input feature size.
  hidden_size : int
      The hidden layer size.
  dropout : float, optional
      Dropout ratio, default: ``None``.
  bidirectional : boolean, optional
      Whether to use bidirectional RNN, default: ``False``.
  rnn_type : str
      The RNN cell type, default: ``lstm``.
class_docstr_tok: ["RNN","embedding","class",":","apply","the","RNN","network","to","a","sequence","of","word","embeddings",".","Parameters","--","--","--","--","--","input_size",":","int","The","input","feature","size",".","hidden_size",":","int","The","hidden","layer","size",".","dropout",":","float",",","optional","Dropout","ratio",",","default",":","``","None","``",".","bidirectional",":","boolean",",","optional","Whether","to","use","bidirectional","RNN",",","default",":","``","False","``",".","rnn_type",":","str","The","RNN","cell","type",",","default",":","``","lstm","``","."]
docstr: Apply the RNN network to a sequence of word embeddings.
  
  Parameters
  ----------
  x : torch.Tensor
      The word embedding sequence.
  x_len : torch.LongTensor
      The input sequence length.
  
  Returns
  -------
  torch.Tensor
      The hidden states at every time step.
  torch.Tensor
      The hidden state at the last time step.
docstr_tok: ["Apply","the","RNN","network","to","a","sequence","of","word","embeddings",".","Parameters","--","--","--","--","--","x",":","torch.Tensor","The","word","embedding","sequence",".","x_len",":","torch.LongTensor","The","input","sequence","length",".","Returns","--","--","--","-","torch.Tensor","The","hidden","states","at","every","time","step",".","torch.Tensor","The","hidden","state","at","the","last","time","step","."]
code: def forward(self, x, x_len):
      """Apply the RNN network to a sequence of word embeddings.
  
      Parameters
      ----------
      x : torch.Tensor
          The word embedding sequence.
      x_len : torch.LongTensor
          The input sequence length.
  
      Returns
      -------
      torch.Tensor
          The hidden states at every time step.
      torch.Tensor
          The hidden state at the last time step.
      """
      sorted_x_len, indx = torch.sort(x_len, 0, descending=True)
      device = x.device
      x = pack_padded_sequence(
          x[indx], sorted_x_len.data.tolist(), batch_first=True
      )
  
      h0 = torch.zeros(
          self.num_directions * self.num_layers,
          x_len.size(0),
          self.hidden_size,
      ).to(device)
      if self.rnn_type == "lstm":
          c0 = torch.zeros(
              self.num_directions * self.num_layers,
              x_len.size(0),
              self.hidden_size,
          ).to(device)
          packed_h, (packed_h_t, _) = self.model(x, (h0, c0))
      else:
          packed_h, packed_h_t = self.model(x, h0)
  
      if self.num_layers > 1:
          # use the last RNN layer hidden state
          packed_h_t = packed_h_t.view(
              self.num_layers, self.num_directions, -1, self.hidden_size
          )[-1]
  
      if self.num_directions == 2:
          packed_h_t = torch.cat((packed_h_t[-1], packed_h_t[-2]), 1)
      else:
          packed_h_t = packed_h_t[-1]
  
      hh, _ = pad_packed_sequence(packed_h, batch_first=True)
  
      # restore the sorting
      _, inverse_indx = torch.sort(indx, 0)
      restore_hh = hh[inverse_indx]
      restore_packed_h_t = packed_h_t[inverse_indx]
  
      # add dropout
      restore_hh = dropout_fn(
          restore_hh,
          self.dropout,
          shared_axes=[-2],
          training=self.training,
      )
      restore_packed_h_t = dropout_fn(
          restore_packed_h_t, self.dropout, training=self.training
      )
  
      return restore_hh, restore_packed_h_t
  
imports: import torch
  from torch import nn
  from torch.nn.utils.rnn import pack_padded_sequence, pad_packed_sequence
  from ...data.data import from_batch
  from ..utils.bert_utils import convert_text_to_bert_features, extract_bert_hidden_states
  from ..utils.generic_utils import dropout_fn
  from ..utils.padding_utils import pad_4d_vals
  from ..utils.vocab_utils import Vocab
label_desc: Use image node_id 2 for calling the RNNEmbedding obj's underlying member method code with example usage: obj.forward(x, x_len) and returns: restore_hh,  restore_packed_h_t