(inputs,
               num_units,
               bidirectional,
               is_training,
               lengths=None,
               stack_size=1,
               dropout_keep_prob=1)
Create a LSTM layer using the specified backend.
Create a LSTM layer using the specified backend.
Create a LSTM layer using the specified backend .
def lstm_layer(inputs,
               num_units,
               bidirectional,
               is_training,
               lengths=None,
               stack_size=1,
               dropout_keep_prob=1):
  """Create a LSTM layer using the specified backend."""
  cells_fw = []
  for i in range(stack_size):
    del i
    cell = tf.nn.rnn_cell.BasicLSTMCell(num_units)
    cell = tf.nn.rnn_cell.DropoutWrapper(
        cell, output_keep_prob=dropout_keep_prob if is_training else 1.0)
    cells_fw.append(cell)

  if bidirectional:
    cells_bw = []
    for i in range(stack_size):
      del i
      cell = tf.nn.rnn_cell.BasicLSTMCell(num_units)
      cell = tf.nn.rnn_cell.DropoutWrapper(
          cell, output_keep_prob=dropout_keep_prob if is_training else 1.0)
      cells_bw.append(cell)
    with tf.variable_scope('lstm'):
      (outputs, unused_state_f,
       unused_state_b) = contrib_rnn.stack_bidirectional_dynamic_rnn(
           cells_fw,
           cells_bw,
           inputs,
           dtype=tf.float32,
           sequence_length=lengths,
           parallel_iterations=1)

    return outputs
  else:
    with tf.variable_scope('lstm'):
      outputs, unused_state = tf.nn.dynamic_rnn(
          cell=tf.nn.rnn_cell.MultiRNNCell(cells_fw),
          inputs=inputs,
          dtype=tf.float32,
          sequence_length=lengths,
          parallel_iterations=1)
      return outputs
def lstm_layer ( inputs , num_units , bidirectional , is_training , lengths = None , stack_size = 1 , dropout_keep_prob = 1 ) : cells_fw = [ ] for i in range ( stack_size ) : del i cell = tf . nn . rnn_cell . BasicLSTMCell ( num_units ) cell = tf . nn . rnn_cell . DropoutWrapper ( cell , output_keep_prob = dropout_keep_prob if is_training else 1.0 ) cells_fw . append ( cell ) if bidirectional : cells_bw = [ ] for i in range ( stack_size ) : del i cell = tf . nn . rnn_cell . BasicLSTMCell ( num_units ) cell = tf . nn . rnn_cell . DropoutWrapper ( cell , output_keep_prob = dropout_keep_prob if is_training else 1.0 ) cells_bw . append ( cell ) with tf . variable_scope ( 'lstm' ) : ( outputs , unused_state_f , unused_state_b ) = contrib_rnn . stack_bidirectional_dynamic_rnn ( cells_fw , cells_bw , inputs , dtype = tf . float32 , sequence_length = lengths , parallel_iterations = 1 ) return outputs else : with tf . variable_scope ( 'lstm' ) : outputs , unused_state = tf . nn . dynamic_rnn ( cell = tf . nn . rnn_cell . MultiRNNCell ( cells_fw ) , inputs = inputs , dtype = tf . float32 , sequence_length = lengths , parallel_iterations = 1 ) return outputs