code: def mask_by_length(xs, lengths, fill=0):
      """Mask tensor according to length.
  
      Args:
          xs (Tensor): Batch of input tensor (B, `*`).
          lengths (LongTensor or List): Batch of lengths (B,).
          fill (int or float): Value to fill masked part.
  
      Returns:
          Tensor: Batch of masked input tensor (B, `*`).
  
      Examples:
          >>> x = torch.arange(5).repeat(3, 1) + 1
          >>> x
          tensor([[1, 2, 3, 4, 5],
                  [1, 2, 3, 4, 5],
                  [1, 2, 3, 4, 5]])
          >>> lengths = [5, 3, 2]
          >>> mask_by_length(x, lengths)
          tensor([[1, 2, 3, 4, 5],
                  [1, 2, 3, 0, 0],
                  [1, 2, 0, 0, 0]])
  
      """
      assert xs.size(0) == len(lengths)
      ret = xs.data.new(*xs.size()).fill_(fill)
      for i, l in enumerate(lengths):
          ret[i, :l] = xs[i, :l]
      return ret
  
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 8 for calling a global function with example usage: mask_by_length(xs, lengths, fill) and returns: ret