docstr: We do not sample negative examples explicitly.
  Instead, given a positive pair, similar to (Chen et al., 2017), we treat the other 2(N − 1) augmented examples within a minibatch as negative examples.
docstr_tok: ["We","do","not","sample","negative","examples","explicitly",".","Instead",",","given","a","positive","pair",",","similar","to","(","Chen","et","al.",",","2017",")",",","we","treat","the","other","2","(","N","\u2212","1",")","augmented","examples","within","a","minibatch","as","negative","examples","."]
code: def info_nce(self, z_i, z_j, temp, batch_size, sim="dot"):
      """
      We do not sample negative examples explicitly.
      Instead, given a positive pair, similar to (Chen et al., 2017), we treat the other 2(N − 1) augmented examples within a minibatch as negative examples.
      """
      N = 2 * batch_size
  
      z = torch.cat((z_i, z_j), dim=0)
  
      if sim == "cos":
          sim = (
              nn.functional.cosine_similarity(
                  z.unsqueeze(1), z.unsqueeze(0), dim=2
              )
              / temp
          )
      elif sim == "dot":
          sim = torch.mm(z, z.T) / temp
  
      sim_i_j = torch.diag(sim, batch_size)
      sim_j_i = torch.diag(sim, -batch_size)
  
      positive_samples = torch.cat((sim_i_j, sim_j_i), dim=0).reshape(
          N, 1
      )
      if batch_size != self.batch_size:
          mask = self.mask_correlated_samples(batch_size)
      else:
          mask = self.mask_default
      negative_samples = sim[mask].reshape(N, -1)
  
      labels = torch.zeros(N).to(positive_samples.device).long()
      logits = torch.cat((positive_samples, negative_samples), dim=1)
      return logits, labels
  
imports: import random
  import numpy
  import torch
  from torch import nn
  import torch.nn.functional
  import math
  import torch.nn.functional
  from recbole.model.abstract_recommender import SequentialRecommender
  from recbole.model.loss import BPRLoss
  from recbole.data.interaction import Interaction
label_desc: Use image node_id 12 for calling the FEARec obj's underlying member method code with example usage: obj.info_nce(z_i, z_j, temp, batch_size, sim) and returns: logits,  labels