parameters: (input_seq, lengths)
return_statement: return results
docstring: Reverse a list of Tensors up to specified lengths.
  
    Args:
      input_seq: Sequence of seq_len tensors of dimension (batch_size, n_features)
                 or nested tuples of tensors.
      lengths:   A `Tensor` of dimension batch_size, containing lengths for each
                 sequence in the batch. If "None" is specified, simply reverses
                 the list.
  
    Returns:
      time-reversed sequence
docstring_summary: Reverse a list of Tensors up to specified lengths.
docstring_tokens: Reverse a list of Tensors up to specified lengths .
function: def _reverse_seq(input_seq, lengths):
    """Reverse a list of Tensors up to specified lengths.
  
    Args:
      input_seq: Sequence of seq_len tensors of dimension (batch_size, n_features)
                 or nested tuples of tensors.
      lengths:   A `Tensor` of dimension batch_size, containing lengths for each
                 sequence in the batch. If "None" is specified, simply reverses
                 the list.
  
    Returns:
      time-reversed sequence
    """
    if lengths is None:
      return list(reversed(input_seq))
  
    flat_input_seq = tuple(nest.flatten(input_) for input_ in input_seq)
  
    flat_results = [[] for _ in range(len(input_seq))]
    for sequence in zip(*flat_input_seq):
      input_shape = tensor_shape.unknown_shape(
          ndims=sequence[0].get_shape().ndims)
      for input_ in sequence:
        input_shape.merge_with(input_.get_shape())
        input_.set_shape(input_shape)
  
      # Join into (time, batch_size, depth)
      s_joined = array_ops.pack(sequence)
  
      # TODO(schuster, ebrevdo): Remove cast when reverse_sequence takes int32
      if lengths is not None:
        lengths = math_ops.to_int64(lengths)
  
      # Reverse along dimension 0
      s_reversed = array_ops.reverse_sequence(s_joined, lengths, 0, 1)
      # Split again into list
      result = array_ops.unpack(s_reversed)
      for r, flat_result in zip(result, flat_results):
        r.set_shape(input_shape)
        flat_result.append(r)
  
    results = [nest.pack_sequence_as(structure=input_, flat_sequence=flat_result)
               for input_, flat_result in zip(input_seq, flat_results)]
    return results
function_tokens: def _reverse_seq ( input_seq , lengths ) : if lengths is None : return list ( reversed ( input_seq ) ) flat_input_seq = tuple ( nest . flatten ( input_ ) for input_ in input_seq ) flat_results = [ [ ] for _ in range ( len ( input_seq ) ) ] for sequence in zip ( * flat_input_seq ) : input_shape = tensor_shape . unknown_shape ( ndims = sequence [ 0 ] . get_shape ( ) . ndims ) for input_ in sequence : input_shape . merge_with ( input_ . get_shape ( ) ) input_ . set_shape ( input_shape ) # Join into (time, batch_size, depth) s_joined = array_ops . pack ( sequence ) # TODO(schuster, ebrevdo): Remove cast when reverse_sequence takes int32 if lengths is not None : lengths = math_ops . to_int64 ( lengths ) # Reverse along dimension 0 s_reversed = array_ops . reverse_sequence ( s_joined , lengths , 0 , 1 ) # Split again into list result = array_ops . unpack ( s_reversed ) for r , flat_result in zip ( result , flat_results ) : r . set_shape ( input_shape ) flat_result . append ( r ) results = [ nest . pack_sequence_as ( structure = input_ , flat_sequence = flat_result ) for input_ , flat_result in zip ( input_seq , flat_results ) ] return results