code: def _make_pad_mask(lengths, xs=None, length_dim=-1, maxlen=None):
      if not isinstance(lengths, list):
          lengths = lengths.long().tolist()
  
      bs = int(len(lengths))
      if maxlen is None:
          if xs is None:
              maxlen = int(max(lengths))
          else:
              maxlen = xs.size(length_dim)
      else:
          assert (
              xs is None
          ), "When maxlen is specified, xs must not be specified."
          assert maxlen >= int(
              max(lengths)
          ), f"maxlen {maxlen} must be >= max(lengths) {max(lengths)}"
  
      seq_range = torch.arange(0, maxlen, dtype=torch.int64)
      seq_range_expand = seq_range.unsqueeze(0).expand(bs, maxlen)
      seq_length_expand = seq_range_expand.new(lengths).unsqueeze(-1)
      mask = seq_range_expand >= seq_length_expand
  
      if xs is not None:
          assert (
              xs.size(0) == bs
          ), f"The size of x.size(0) {xs.size(0)} must match the batch size {bs}"
  
          if length_dim < 0:
              length_dim = xs.dim() + length_dim
          # ind = (:, None, ..., None, :, , None, ..., None)
          ind = tuple(
              slice(None) if i in (0, length_dim) else None
              for i in range(xs.dim())
          )
          mask = mask[ind].expand_as(xs).to(xs.device)
      return mask
  
file_path: espnet/espnet/nets/pytorch_backend/nets_utils.py
imports: import logging
  from typing import Dict
  import numpy
  import torch
label_desc: Use image node_id 4 for calling a global function with example usage: _make_pad_mask(lengths, xs, length_dim, maxlen) and returns: mask