class_docstr: The :class:`RNN` class is a fixed length recurrent layer for implementing simple RNN,
  LSTM, GRU and etc.
  
  Parameters
  ----------
  cell : TensorFlow cell function
      A RNN cell implemented by tf.keras
          - E.g. tf.keras.layers.SimpleRNNCell, tf.keras.layers.LSTMCell, tf.keras.layers.GRUCell
          - Note TF2.0+, TF1.0+ and TF1.0- are different
  
  return_last_output : boolean
      Whether return last output or all outputs in a sequence.
  
          - If True, return the last output, "Sequence input and single output"
          - If False, return all outputs, "Synced sequence input and output"
          - In other word, if you want to stack more RNNs on this layer, set to False
  
      In a dynamic model, `return_last_output` can be updated when it is called in customised forward().
      By default, `False`.
  return_seq_2d : boolean
      Only consider this argument when `return_last_output` is `False`
  
          - If True, return 2D Tensor [batch_size * n_steps, n_hidden], for stacking Dense layer after it.
          - If False, return 3D Tensor [batch_size, n_steps, n_hidden], for stacking multiple RNN after it.
  
      In a dynamic model, `return_seq_2d` can be updated when it is called in customised forward().
      By default, `False`.
  return_last_state: boolean
      Whether to return the last state of the RNN cell. The state is a list of Tensor.
      For simple RNN and GRU, last_state = [last_output]; For LSTM, last_state = [last_output, last_cell_state]
  
          - If True, the layer will return outputs and the final state of the cell.
          - If False, the layer will return outputs only.
  
      In a dynamic model, `return_last_state` can be updated when it is called in customised forward().
      By default, `False`.
  in_channels: int
      Optional, the number of channels of the previous layer which is normally the size of embedding.
      If given, the layer will be built when init.
      If None, it will be automatically detected when the layer is forwarded for the first time.
  name : str
      A unique layer name.
  
  Examples
  --------
  For synced sequence input and output, see `PTB example <https://github.com/tensorlayer/tensorlayer/blob/master/example/tutorial_ptb_lstm.py>`__
  
  A simple regression model below.
  
  >>> inputs = tl.layers.Input([batch_size, num_steps, embedding_size])
  >>> rnn_out, lstm_state = tl.layers.RNN(
  >>>     cell=tf.keras.layers.LSTMCell(units=hidden_size, dropout=0.1),
  >>>     in_channels=embedding_size,
  >>>     return_last_output=True, return_last_state=True, name='lstmrnn'
  >>> )(inputs)
  >>> outputs = tl.layers.Dense(n_units=1)(rnn_out)
  >>> rnn_model = tl.models.Model(inputs=inputs, outputs=[outputs, rnn_state[0], rnn_state[1]], name='rnn_model')
  >>> # If LSTMCell is applied, the rnn_state is [h, c] where h the hidden state and c the cell state of LSTM.
  
  A stacked RNN model.
  
  >>> inputs = tl.layers.Input([batch_size, num_steps, embedding_size])
  >>> rnn_out1 = tl.layers.RNN(
  >>>     cell=tf.keras.layers.SimpleRNNCell(units=hidden_size, dropout=0.1),
  >>>     return_last_output=False, return_seq_2d=False, return_last_state=False
  >>> )(inputs)
  >>> rnn_out2 = tl.layers.RNN(
  >>>     cell=tf.keras.layers.SimpleRNNCell(units=hidden_size, dropout=0.1),
  >>>     return_last_output=True, return_last_state=False
  >>> )(rnn_out1)
  >>> outputs = tl.layers.Dense(n_units=1)(rnn_out2)
  >>> rnn_model = tl.models.Model(inputs=inputs, outputs=outputs)
  
  An example if the sequences have different length and contain padding.
  Similar to the DynamicRNN in TL 1.x.
  
  If the `sequence_length` is provided in RNN's forwarding and both `return_last_output` and `return_last_state`
  are set as `True`, the forward function will automatically ignore the paddings. Note that if `return_last_output`
  is set as `False`, the synced sequence outputs will still include outputs which correspond with paddings,
  but users are free to select which slice of outputs to be used in following procedure.
  
  The `sequence_length` should be a list of integers which indicates the length of each sequence.
  It is recommended to
  `tl.layers.retrieve_seq_length_op3 <https://tensorlayer.readthedocs.io/en/latest/modules/layers.html#compute-sequence-length-3>`__
  to calculate the `sequence_length`.
  
  >>> data = [[[1], [2], [0], [0], [0]], [[1], [2], [3], [0], [0]], [[1], [2], [6], [1], [1]]]
  >>> data = tf.convert_to_tensor(data, dtype=tf.float32)
  >>> class DynamicRNNExample(tl.models.Model):
  >>>     def __init__(self):
  >>>         super(DynamicRNNExample, self).__init__()
  >>>         self.rnnlayer = tl.layers.RNN(
  >>>             cell=tf.keras.layers.SimpleRNNCell(units=6, dropout=0.1), in_channels=1, return_last_output=True,
  >>>             return_last_state=True
  >>>         )
  >>>     def forward(self, x):
  >>>         z, s = self.rnnlayer(x, sequence_length=tl.layers.retrieve_seq_length_op3(x))
  >>>         return z, s
  >>> model = DynamicRNNExample()
  >>> model.eval()
  >>> output, state = model(data)
  
  
  Notes
  -----
  Input dimension should be rank 3 : [batch_size, n_steps, n_features], if no, please see layer :class:`Reshape`.
class_docstr_tok: ["The",":","class",":","`","RNN","`","class","is","a","fixed","length","recurrent","layer","for","implementing","simple","RNN",",","LSTM",",","GRU","and","etc",".","Parameters","--","--","--","--","--","cell",":","TensorFlow","cell","function","A","RNN","cell","implemented","by","tf.keras","-","E.g",".","tf.keras.layers.SimpleRNNCell",",","tf.keras.layers.LSTMCell",",","tf.keras.layers.GRUCell","-","Note","TF2.0+",",","TF1.0+","and","TF1.0-","are","different","return_last_output",":","boolean","Whether","return","last","output","or","all","outputs","in","a","sequence",".","-","If","True",",","return","the","last","output",",","``","Sequence","input","and","single","output","''","-","If","False",",","return","all","outputs",",","``","Synced","sequence","input","and","output","''","-","In","other","word",",","if","you","want","to","stack","more","RNNs","on","this","layer",",","set","to","False","In","a","dynamic","model",",","`","return_last_output","`","can","be","updated","when","it","is","called","in","customised","forward","(",")",".","By","default",",","`","False","`",".","return_seq_2d",":","boolean","Only","consider","this","argument","when","`","return_last_output","`","is","`","False","`","-","If","True",",","return","2D","Tensor","[","batch_size","*","n_steps",",","n_hidden","]",",","for","stacking","Dense","layer","after","it",".","-","If","False",",","return","3D","Tensor","[","batch_size",",","n_steps",",","n_hidden","]",",","for","stacking","multiple","RNN","after","it",".","In","a","dynamic","model",",","`","return_seq_2d","`","can","be","updated","when","it","is","called","in","customised","forward","(",")",".","By","default",",","`","False","`",".","return_last_state",":","boolean","Whether","to","return","the","last","state","of","the","RNN","cell",".","The","state","is","a","list","of","Tensor",".","For","simple","RNN","and","GRU",",","last_state","=","[","last_output","]",";","For","LSTM",",","last_state","=","[","last_output",",","last_cell_state","]","-","If","True",",","the","layer","will","return","outputs","and","the","final","state","of","the","cell",".","-","If","False",",","the","layer","will","return","outputs","only",".","In","a","dynamic","model",",","`","return_last_state","`","can","be","updated","when","it","is","called","in","customised","forward","(",")",".","By","default",",","`","False","`",".","in_channels",":","int","Optional",",","the","number","of","channels","of","the","previous","layer","which","is","normally","the","size","of","embedding",".","If","given",",","the","layer","will","be","built","when","init",".","If","None",",","it","will","be","automatically","detected","when","the","layer","is","forwarded","for","the","first","time",".","name",":","str","A","unique","layer","name",".","Examples","--","--","--","--","For","synced","sequence","input","and","output",",","see","`","PTB","example","<","https",":","\/\/github.com\/tensorlayer\/tensorlayer\/blob\/master\/example\/tutorial_ptb_lstm.py",">","`","__","A","simple","regression","model","below",".",">",">",">","inputs","=","tl.layers.Input","(","[","batch_size",",","num_steps",",","embedding_size","]",")",">",">",">","rnn_out",",","lstm_state","=","tl.layers.RNN","(",">",">",">","cell=tf.keras.layers.LSTMCell","(","units=hidden_size",",","dropout=0.1",")",",",">",">",">","in_channels=embedding_size",",",">",">",">","return_last_output=True",",","return_last_state=True",",","name='lstmrnn'",">",">",">",")","(","inputs",")",">",">",">","outputs","=","tl.layers.Dense","(","n_units=1",")","(","rnn_out",")",">",">",">","rnn_model","=","tl.models.Model","(","inputs=inputs",",","outputs=","[","outputs",",","rnn_state","[","0","]",",","rnn_state","[","1","]","]",",","name='rnn_model","'",")",">",">",">","#","If","LSTMCell","is","applied",",","the","rnn_state","is","[","h",",","c","]","where","h","the","hidden","state","and","c","the","cell","state","of","LSTM",".","A","stacked","RNN","model",".",">",">",">","inputs","=","tl.layers.Input","(","[","batch_size",",","num_steps",",","embedding_size","]",")",">",">",">","rnn_out1","=","tl.layers.RNN","(",">",">",">","cell=tf.keras.layers.SimpleRNNCell","(","units=hidden_size",",","dropout=0.1",")",",",">",">",">","return_last_output=False",",","return_seq_2d=False",",","return_last_state=False",">",">",">",")","(","inputs",")",">",">",">","rnn_out2","=","tl.layers.RNN","(",">",">",">","cell=tf.keras.layers.SimpleRNNCell","(","units=hidden_size",",","dropout=0.1",")",",",">",">",">","return_last_output=True",",","return_last_state=False",">",">",">",")","(","rnn_out1",")",">",">",">","outputs","=","tl.layers.Dense","(","n_units=1",")","(","rnn_out2",")",">",">",">","rnn_model","=","tl.models.Model","(","inputs=inputs",",","outputs=outputs",")","An","example","if","the","sequences","have","different","length","and","contain","padding",".","Similar","to","the","DynamicRNN","in","TL","1.x",".","If","the","`","sequence_length","`","is","provided","in","RNN","'s","forwarding","and","both","`","return_last_output","`","and","`","return_last_state","`","are","set","as","`","True","`",",","the","forward","function","will","automatically","ignore","the","paddings",".","Note","that","if","`","return_last_output","`","is","set","as","`","False","`",",","the","synced","sequence","outputs","will","still","include","outputs","which","correspond","with","paddings",",","but","users","are","free","to","select","which","slice","of","outputs","to","be","used","in","following","procedure",".","The","`","sequence_length","`","should","be","a","list","of","integers","which","indicates","the","length","of","each","sequence",".","It","is","recommended","to","`","tl.layers.retrieve_seq_length_op3","<","https",":","\/\/tensorlayer.readthedocs.io\/en\/latest\/modules\/layers.html","#","compute-sequence-length-3",">","`","__","to","calculate","the","`","sequence_length","`",".",">",">",">","data","=","[","[","[","1","]",",","[","2","]",",","[","0","]",",","[","0","]",",","[","0","]","]",",","[","[","1","]",",","[","2","]",",","[","3","]",",","[","0","]",",","[","0","]","]",",","[","[","1","]",",","[","2","]",",","[","6","]",",","[","1","]",",","[","1","]","]","]",">",">",">","data","=","tf.convert_to_tensor","(","data",",","dtype=tf.float32",")",">",">",">","class","DynamicRNNExample","(","tl.models.Model",")",":",">",">",">","def","__init__","(","self",")",":",">",">",">","super","(","DynamicRNNExample",",","self",")",".__init__","(",")",">",">",">","self.rnnlayer","=","tl.layers.RNN","(",">",">",">","cell=tf.keras.layers.SimpleRNNCell","(","units=6",",","dropout=0.1",")",",","in_channels=1",",","return_last_output=True",",",">",">",">","return_last_state=True",">",">",">",")",">",">",">","def","forward","(","self",",","x",")",":",">",">",">","z",",","s","=","self.rnnlayer","(","x",",","sequence_length=tl.layers.retrieve_seq_length_op3","(","x",")",")",">",">",">","return","z",",","s",">",">",">","model","=","DynamicRNNExample","(",")",">",">",">","model.eval","(",")",">",">",">","output",",","state","=","model","(","data",")","Notes","--","--","-","Input","dimension","should","be","rank","3",":","[","batch_size",",","n_steps",",","n_features","]",",","if","no",",","please","see","layer",":","class",":","`","Reshape","`","."]
docstr: Parameters
  ----------
  inputs_shape : tuple
      the shape of inputs tensor
docstr_tok: ["Parameters","--","--","--","--","--","inputs_shape",":","tuple","the","shape","of","inputs","tensor"]
code: def build(self, inputs_shape):
      """
      Parameters
      ----------
      inputs_shape : tuple
          the shape of inputs tensor
      """
      # Input dimension should be rank 3 [batch_size, n_steps(max), n_features]
      if len(inputs_shape) != 3:
          raise Exception(
              "RNN : Input dimension should be rank 3 : [batch_size, n_steps, n_features]"
          )
  
      with tf.name_scope(self.name) as scope:
          self.cell.build(tuple(inputs_shape))
  
      if self._trainable_weights is None:
          self._trainable_weights = list()
      for var in self.cell.trainable_variables:
          self._trainable_weights.append(var)
  
imports: import numpy
  import tensorflow
  import tensorlayer
  from tensorlayer import logging
  from tensorlayer.decorators import deprecated_alias
  from tensorlayer.layers.core import Layer
label_desc: Use image node_id 3 for calling the RNN obj's underlying member method code with example usage: obj.build(inputs_shape) without return types