code: def create_src_lengths_mask(batch_size: int, src_lengths):
      """
      Generate boolean mask to prevent attention beyond the end of source
  
      Inputs:
        batch_size : int
        src_lengths : [batch_size] of sentence lengths
  
      Outputs:
        [batch_size, max_src_len]
      """
      max_srclen = src_lengths.max()
      src_indices = (
          torch.arange(0, max_srclen).unsqueeze(0).type_as(src_lengths)
      )
      src_indices = src_indices.expand(batch_size, max_srclen)
      src_lengths = src_lengths.unsqueeze(dim=1).expand(
          batch_size, max_srclen
      )
      # returns [batch_size, max_seq_len]
      return (src_indices < src_lengths).int().detach()
  
imports: from typing import Dict, Optional, Tuple
  import numpy
  import torch
  import torch.nn.functional
  from pytext.config import ConfigBase
  from pytext.utils.usage import log_class_usage
  from torch import nn, Tensor
  from .base import PyTextIncrementalDecoderComponent
  from .utils import Linear
label_desc: Use image node_id 1 for calling a global function with example usage: create_src_lengths_mask(batch_size, src_lengths) and returns: unknown