original_docstring: 
      Sort batch data and labels by length.
      Useful for variable length inputs, for utilizing PackedSequences
      Args:
          lengths (nn.Tensor): tensor containing the lengths for the data
  
      Returns:
          - sorted lengths Tensor
          - sort (callable) which will sort a given iterable
              according to lengths
          - unsort (callable) which will revert a given iterable to its
              original order
  
      
docstring: Sort batch data and labels by length.
  Useful for variable length inputs, for utilizing PackedSequences
docstring_tokens: Sort batch data and labels by length . Useful for variable length inputs for utilizing PackedSequences
code: def sort_by_lengths(lengths):
      """
      Sort batch data and labels by length.
      Useful for variable length inputs, for utilizing PackedSequences
      Args:
          lengths (nn.Tensor): tensor containing the lengths for the data
  
      Returns:
          - sorted lengths Tensor
          - sort (callable) which will sort a given iterable
              according to lengths
          - unsort (callable) which will revert a given iterable to its
              original order
  
      """
      batch_size = lengths.size(0)
  
      sorted_lengths, sorted_idx = lengths.sort()
      _, original_idx = sorted_idx.sort(0, descending=True)
      reverse_idx = torch.linspace(batch_size - 1, 0, batch_size).long()
  
      if lengths.data.is_cuda:
          reverse_idx = reverse_idx.cuda()
  
      sorted_lengths = sorted_lengths[reverse_idx]
  
      def sort(iterable):
          if len(iterable.shape) > 1:
              return iterable[sorted_idx.data][reverse_idx]
          else:
              return iterable
  
      def unsort(iterable):
          if len(iterable.shape) > 1:
              return iterable[reverse_idx][original_idx][reverse_idx]
          else:
              return iterable
  
      return sorted_lengths, sort, unsort
code_tokens: def sort_by_lengths ( lengths ) : batch_size = lengths . size ( 0 ) sorted_lengths , sorted_idx = lengths . sort ( ) _ , original_idx = sorted_idx . sort ( 0 , descending = True ) reverse_idx = torch . linspace ( batch_size - 1 , 0 , batch_size ) . long ( ) if lengths . data . is_cuda : reverse_idx = reverse_idx . cuda ( ) sorted_lengths = sorted_lengths [ reverse_idx ] def sort ( iterable ) : if len ( iterable . shape ) > 1 : return iterable [ sorted_idx . data ] [ reverse_idx ] else : return iterable def unsort ( iterable ) : if len ( iterable . shape ) > 1 : return iterable [ reverse_idx ] [ original_idx ] [ reverse_idx ] else : return iterable return sorted_lengths , sort , unsort
short_docstring: Sort batch data and labels by length.
short_docstring_tokens: Sort batch data and labels by length .
comment: """
      Sort batch data and labels by length.
      Useful for variable length inputs, for utilizing PackedSequences
      Args:
          lengths (nn.Tensor): tensor containing the lengths for the data
  
      Returns:
          - sorted lengths Tensor
          - sort (callable) which will sort a given iterable
              according to lengths
          - unsort (callable) which will revert a given iterable to its
              original order
  
      """