code: def compute_mask(shape, sample_lens, mask_prob, mask_length):
      """This creates the boolean mask for a target shape which respects
      the sample lengths and will half roughly ``mask_prob`` entries set to
      ``True``.
  
      Arguments
      ---------
      shape : list of ints, like (N, M)
          Shape of boolean mask to return.
      sample_lens: list of ints
          Absolute lengths of per sample lengths.
      mask_prob : float
          Percentage to mask.
      mask_length: int
          Length of contiguous subsequence to mask.
  
      Returns
      -------
      mask : numpy.ndarray
          Boolean mask with shape of input argument ``shape``.
      """
      bs, padded_sample_len = shape
  
      min_sample_len = min(sample_lens)
      # So we dont have ragged tensors number of masks is the same for each sample.
      num_mask = int(
          mask_prob * min_sample_len / float(mask_length)
          + random.random()
          + 1
      )
      # Now loop through and for each sample select indices so that no indices land
      # in the padded part of the signal.
      mask_idcs = []
      for i in range(bs):
          sample_len = sample_lens[i]
          # This are the starting indices.
          mask_indices = np.random.choice(
              sample_len - mask_length, num_mask, replace=False
          )
  
          # Now using the starting indices create contiguous masks.
          mask_indices = np.asarray(
              [
                  mask_indices[j] + offset
                  for j in range(len(mask_indices))
                  for offset in range(mask_length)
              ]
          )
  
          # Last step might have created overlapping masks, remove overlapping part.
          mask_idcs.append(
              np.unique(mask_indices[mask_indices < sample_len])
          )
  
      mask = np.full((bs, padded_sample_len), False)
      num_mask_total = num_mask * mask_length
      # Unique could have caused number to go below target count,
      # this randomly adds some unused indices.
      for i, mask_idc in enumerate(mask_idcs):
          if len(mask_idc) < num_mask_total:
              num_mask_missing = num_mask_total - len(mask_idc)
              arange = np.arange(sample_lens[i])
              arange = np.delete(arange, mask_idc)
              extra_indcs = np.random.choice(
                  arange, num_mask_missing, replace=False
              )
              mask[i, extra_indcs] = True
          mask[i, mask_idc] = True
      return mask
  
imports: import logging
  import torch
  import torch.nn.functional
  import torch.nn
  import random
  import numpy
  from speechbrain.lobes.models.transformer.Transformer import PositionalEncoding
  from speechbrain.utils.data_utils import batch_pad_right
  from speechbrain.dataio.dataio import length_to_mask
  from speechbrain.lobes.models.convolution import ConvolutionFrontEnd
  from speechbrain.nnet.CNN import Conv1d
  from speechbrain.nnet.normalization import LayerNorm
  from speechbrain.nnet.quantisers import GumbelVectorQuantizer
label_desc: Use image node_id 1 for calling a global function with example usage: compute_mask(shape, sample_lens, mask_prob, mask_length) and returns: mask