code: def get_key_padding_mask(padded_input, pad_idx):
      """Creates a binary mask to prevent attention to padded locations.
      We suggest using get_mask_from_lengths instead of this function.
      Arguments
      ----------
      padded_input: int
          Padded input.
      pad_idx:
          idx for padding element.
      Example
      -------
      >>> a = torch.LongTensor([[1,1,0], [2,3,0], [4,5,0]])
      >>> get_key_padding_mask(a, pad_idx=0)
      tensor([[False, False,  True],
              [False, False,  True],
              [False, False,  True]])
      """
      if len(padded_input.shape) == 4:
          bz, time, ch1, ch2 = padded_input.shape
          padded_input = padded_input.reshape(bz, time, ch1 * ch2)
  
      key_padded_mask = padded_input.eq(pad_idx).to(padded_input.device)
  
      # if the input is more than 2d, mask the locations where they are silence
      # across all channels
      if len(padded_input.shape) > 2:
          key_padded_mask = key_padded_mask.float().prod(dim=-1).bool()
          return key_padded_mask.detach()
  
      return key_padded_mask.detach()
  
imports: import math
  import torch
  import torch.nn
  import speechbrain
  from typing import Optional
  import numpy
  from .Conformer import ConformerEncoder
  from .Branchformer import BranchformerEncoder
  from speechbrain.nnet.activations import Swish
  from speechbrain.nnet.attention import RelPosEncXL
  from speechbrain.nnet.CNN import Conv1d
label_desc: Use image node_id 1 for calling a global function with example usage: get_key_padding_mask(padded_input, pad_idx) and returns: key_padded_mask, key_padded_mask