def rnn_helper(inp, length, cell_type=None, direction='forward', name=None, *args, **kwargs):
 assert (cell_type is not None)
 rnn_func = None
 if (cell_type == 'lstm'):
  rnn_func = lstm_layer
 assert (rnn_func is not None)
 assert (direction in ['forward', 'backward', 'bidirectional'])
 with tf.variable_scope(name):
  if (direction in ['forward', 'bidirectional']):
   forward = rnn_func(inp=inp, length=length, backward=False, name='forward', *args, **kwargs)
   if isinstance(forward, tuple):
    forward = forward[0]
  if (direction in ['backward', 'bidirectional']):
   backward = rnn_func(inp=inp, length=length, backward=True, name='backward', *args, **kwargs)
   if isinstance(backward, tuple):
    backward = backward[0]
  if (direction == 'forward'):
   out = forward
  elif (direction == 'backward'):
   out = backward
  else:
   out = tf.concat(2, [forward, backward])
 return out

def rnn_helper ( inp , length , cell_type = None , direction = 'forward' , name = None , * args , ** kwargs ) : assert ( cell_type is not None ) rnn_func = None if ( cell_type == 'lstm' ) : rnn_func = lstm_layer assert ( rnn_func is not None ) assert ( direction in [ 'forward' , 'backward' , 'bidirectional' ] ) with tf . variable_scope ( name ) : if ( direction in [ 'forward' , 'bidirectional' ] ) : forward = rnn_func ( inp = inp , length = length , backward = False , name = 'forward' , * args , ** kwargs ) if isinstance ( forward , tuple ) : forward = forward [ 0 ] if ( direction in [ 'backward' , 'bidirectional' ] ) : backward = rnn_func ( inp = inp , length = length , backward = True , name = 'backward' , * args , ** kwargs ) if isinstance ( backward , tuple ) : backward = backward [ 0 ] if ( direction == 'forward' ) : out = forward elif ( direction == 'backward' ) : out = backward else : out = tf . concat ( 2 , [ forward , backward ] ) return out
adds ops for a recurrent neural network layer .