class_docstr: Variational Dropout RNN 实现.
  
  论文参考: `A Theoretically Grounded Application of Dropout in Recurrent Neural Networks (Yarin Gal and Zoubin Ghahramani, 2016)
  https://arxiv.org/abs/1512.05287`.
class_docstr_tok: ["Variational","Dropout","RNN","\u5b9e\u73b0",".","\u8bba\u6587\u53c2\u8003",":","`","A","Theoretically","Grounded","Application","of","Dropout","in","Recurrent","Neural","Networks","(","Yarin","Gal","and","Zoubin","Ghahramani",",","2016",")","https",":","\/\/arxiv.org\/abs\/1512.05287","`","."]
docstr: :param mode: rnn 模式, (lstm or not)
  :param Cell: rnn cell 类型, (lstm, gru, etc)
  :param input_size:  输入 `x` 的特征维度
  :param hidden_size: 隐状态 `h` 的特征维度
  :param num_layers: rnn的层数. Default: 1
  :param bias: 如果为 ``False``, 模型将不会使用bias. Default: ``True``
  :param batch_first: 若为 ``True``, 输入和输出 ``Tensor`` 形状为
      (batch, seq, feature). Default: ``False``
  :param input_dropout: 对输入的dropout概率. Default: 0
  :param hidden_dropout: 对每个隐状态的dropout概率. Default: 0
  :param bidirectional: 若为 ``True``, 使用双向的RNN. Default: ``False``
docstr_tok: [":","param","mode",":","rnn","\u6a21\u5f0f",",","(","lstm","or","not",")",":","param","Cell",":","rnn","cell","\u7c7b\u578b",",","(","lstm",",","gru",",","etc",")",":","param","input_size",":","\u8f93\u5165","`","x","`","\u7684\u7279\u5f81\u7ef4\u5ea6",":","param","hidden_size",":","\u9690\u72b6\u6001","`","h","`","\u7684\u7279\u5f81\u7ef4\u5ea6",":","param","num_layers",":","rnn\u7684\u5c42\u6570",".","Default",":","1",":","param","bias",":","\u5982\u679c\u4e3a","``","False","``",",","\u6a21\u578b\u5c06\u4e0d\u4f1a\u4f7f\u7528bias",".","Default",":","``","True","``",":","param","batch_first",":","\u82e5\u4e3a","``","True","``",",","\u8f93\u5165\u548c\u8f93\u51fa","``","Tensor","``","\u5f62\u72b6\u4e3a","(","batch",",","seq",",","feature",")",".","Default",":","``","False","``",":","param","input_dropout",":","\u5bf9\u8f93\u5165\u7684dropout\u6982\u7387",".","Default",":","0",":","param","hidden_dropout",":","\u5bf9\u6bcf\u4e2a\u9690\u72b6\u6001\u7684dropout\u6982\u7387",".","Default",":","0",":","param","bidirectional",":","\u82e5\u4e3a","``","True","``",",","\u4f7f\u7528\u53cc\u5411\u7684RNN",".","Default",":","``","False","``"]
code: def __init__(
      self,
      mode,
      Cell,
      input_size,
      hidden_size,
      num_layers=1,
      bias=True,
      batch_first=False,
      input_dropout=0,
      hidden_dropout=0,
      bidirectional=False,
  ):
      r"""
  
      :param mode: rnn 模式, (lstm or not)
      :param Cell: rnn cell 类型, (lstm, gru, etc)
      :param input_size:  输入 `x` 的特征维度
      :param hidden_size: 隐状态 `h` 的特征维度
      :param num_layers: rnn的层数. Default: 1
      :param bias: 如果为 ``False``, 模型将不会使用bias. Default: ``True``
      :param batch_first: 若为 ``True``, 输入和输出 ``Tensor`` 形状为
          (batch, seq, feature). Default: ``False``
      :param input_dropout: 对输入的dropout概率. Default: 0
      :param hidden_dropout: 对每个隐状态的dropout概率. Default: 0
      :param bidirectional: 若为 ``True``, 使用双向的RNN. Default: ``False``
      """
      super(VarRNNBase, self).__init__()
      self.mode = mode
      self.input_size = input_size
      self.hidden_size = hidden_size
      self.num_layers = num_layers
      self.bias = bias
      self.batch_first = batch_first
      self.input_dropout = input_dropout
      self.hidden_dropout = hidden_dropout
      self.bidirectional = bidirectional
      self.num_directions = 2 if bidirectional else 1
      self._all_cells = nn.ModuleList()
      for layer in range(self.num_layers):
          for direction in range(self.num_directions):
              input_size = (
                  self.input_size
                  if layer == 0
                  else self.hidden_size * self.num_directions
              )
              cell = Cell(input_size, self.hidden_size, bias)
              self._all_cells.append(
                  VarRnnCellWrapper(
                      cell,
                      self.hidden_size,
                      input_dropout,
                      hidden_dropout,
                  )
              )
      self.is_lstm = self.mode == "LSTM"
  
imports: import torch
  import torch.nn
  from torch.nn.utils.rnn import PackedSequence, pack_padded_sequence, pad_packed_sequence
label_desc: Use image node_id 1 to create a new VarRNNBase object from inherited base classes: nn with example: obj = VarRNNBase(mode, Cell, input_size, hidden_size, num_layers, bias, batch_first, input_dropout, hidden_dropout, bidirectional)