code: def get_mask_from_lengths(
      lengths: Optional[torch.Tensor] = None,
      x: Optional[torch.Tensor] = None,
  ) -> torch.Tensor:
      """Constructs binary mask from a 1D torch tensor of input lengths
  
      Args:
          lengths: Optional[torch.tensor] (torch.tensor): 1D tensor with lengths
          x: Optional[torch.tensor] = tensor to be used on, last dimension is for mask
      Returns:
          mask (torch.tensor): num_sequences x max_length binary tensor
      """
      if lengths is None:
          assert x is not None
          return torch.ones(
              x.shape[-1], dtype=torch.bool, device=x.device
          )
      else:
          if x is None:
              max_len = torch.max(lengths)
          else:
              max_len = x.shape[-1]
      ids = torch.arange(
          0, max_len, device=lengths.device, dtype=lengths.dtype
      )
      mask = ids < lengths.unsqueeze(1)
      return mask
  
imports: from enum import Enum
  from typing import Optional, Tuple
  import librosa
  import matplotlib.pylab
  import numpy
  import torch
  from einops import rearrange
  from numba import jit, prange
  from nemo.collections.tts.torch.tts_data_types import DATA_STR2DATA_CLASS, MAIN_DATA_TYPES, WithLens
  from nemo.utils import logging
  from nemo.utils.decorators import deprecated
label_desc: Use image node_id 5 for calling a global function with example usage: get_mask_from_lengths(lengths, x) and returns: mask, torch