code: def unpad_sequence(
      padded_sequences: Tensor,
      lengths: Tensor,
      batch_first: bool = False,
  ) -> List[Tensor]:
      r"""Unpad padded Tensor into a list of variable length Tensors.
  
      ``unpad_sequence`` unstacks padded Tensor into a list of variable length Tensors.
  
      Example:
          >>> from torch.nn.utils.rnn import pad_sequence, unpad_sequence
          >>> a = torch.ones(25, 300)
          >>> b = torch.ones(22, 300)
          >>> c = torch.ones(15, 300)
          >>> sequences = [a, b, c]
          >>> padded_sequences = pad_sequence(sequences)
          >>> lengths = torch.as_tensor([v.size(0) for v in sequences])
          >>> unpadded_sequences = unpad_sequence(padded_sequences, lengths)
          >>> torch.allclose(sequences[0], unpadded_sequences[0])
          True
          >>> torch.allclose(sequences[1], unpadded_sequences[1])
          True
          >>> torch.allclose(sequences[2], unpadded_sequences[2])
          True
  
      Args:
          padded_sequences (Tensor): padded sequences.
          lengths (Tensor): length of original (unpadded) sequences.
          batch_first (bool, optional): whether batch dimension first or not. Default: False.
  
      Returns:
          a list of :class:`Tensor` objects
      """
      unpadded_sequences = []
  
      if not batch_first:
          padded_sequences.transpose_(0, 1)
  
      max_length = padded_sequences.shape[1]
      idx = torch.arange(max_length, device=lengths.device)
  
      for seq, length in zip(padded_sequences, lengths):
          mask = idx < length
          unpacked_seq = seq[mask]
          unpadded_sequences.append(unpacked_seq)
  
      return unpadded_sequences
  
imports: import warnings
  from typing import Iterable, List, NamedTuple, Tuple, Union
  import torch
  from torch import Tensor
  from ...None import _VF
  from ..._jit_internal import Optional
label_desc: Use image node_id 8 for calling a global function with example usage: unpad_sequence(padded_sequences, lengths, batch_first) and returns: unpadded_sequences