code: def sample_negatives(y, num_neg):
      """Samples negatives from target tensor y.
      Arguments
      ---------
      y : torch.Tensor
          Tensor of shape (B, T, C)
      num_neg : int
          Number of negatives to sample.
      Returns
      -------
      negs : torch.Tensor
          Negatives in shape (N, B, T, C)
      """
      B, T, C = y.shape
      high = T - 1
      with torch.no_grad():
          targets = (
              torch.arange(T)
              .unsqueeze(-1)
              .expand(-1, num_neg)
              .flatten()
          )
          neg_indcs = torch.randint(
              low=0, high=high, size=(B, T * num_neg)
          )
          # negative should not be target and to make distribution uniform shift all >
          neg_indcs[neg_indcs >= targets] += 1
  
      neg_indcs = neg_indcs + torch.arange(B).unsqueeze(1) * high
      y = y.view(-1, C)
      negs = y[neg_indcs.view(-1)]
      negs = negs.view(B, T, num_neg, C).permute(
          2, 0, 1, 3
      )  # to N, B, T, C
      return negs
  
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 2 for calling a global function with example usage: sample_negatives(y, num_neg) and returns: negs