code: def get_lengths_from_binary_sequence_mask(mask):
      """
      Compute sequence lengths for each batch element in a tensor using a
      binary mask.
  
      Parameters
      ----------
      mask : torch.Tensor, required.
          A 2D binary mask of shape (batch_size, sequence_length) to
          calculate the per-batch sequence lengths from.
  
      Returns
      -------
      A torch.LongTensor of shape (batch_size,) representing the lengths
      of the sequences in the batch.
      """
      return mask.long().sum(-1)
  
imports: from __future__ import division
  from __future__ import absolute_import
  from collections import defaultdict
  import logging
  import math
  import torch
  from allennlp.common.checks import ConfigurationError
label_desc: Use image node_id 2 for calling a global function with example usage: get_lengths_from_binary_sequence_mask(mask) and returns: mask