class_docstr: NCL is a neighborhood-enriched contrastive learning paradigm for graph collaborative filtering.
  Both structural and semantic neighbors are explicitly captured as contrastive learning objects.
class_docstr_tok: ["NCL","is","a","neighborhood-enriched","contrastive","learning","paradigm","for","graph","collaborative","filtering",".","Both","structural","and","semantic","neighbors","are","explicitly","captured","as","contrastive","learning","objects","."]
code: def ProtoNCE_loss(self, node_embedding, user, item):
      user_embeddings_all, item_embeddings_all = torch.split(
          node_embedding, [self.n_users, self.n_items]
      )
  
      user_embeddings = user_embeddings_all[user]  # [B, e]
      norm_user_embeddings = F.normalize(user_embeddings)
  
      user2cluster = self.user_2cluster[user]  # [B,]
      user2centroids = self.user_centroids[user2cluster]  # [B, e]
      pos_score_user = torch.mul(
          norm_user_embeddings, user2centroids
      ).sum(dim=1)
      pos_score_user = torch.exp(pos_score_user / self.ssl_temp)
      ttl_score_user = torch.matmul(
          norm_user_embeddings, self.user_centroids.transpose(0, 1)
      )
      ttl_score_user = torch.exp(ttl_score_user / self.ssl_temp).sum(
          dim=1
      )
  
      proto_nce_loss_user = -torch.log(
          pos_score_user / ttl_score_user
      ).sum()
  
      item_embeddings = item_embeddings_all[item]
      norm_item_embeddings = F.normalize(item_embeddings)
  
      item2cluster = self.item_2cluster[item]  # [B, ]
      item2centroids = self.item_centroids[item2cluster]  # [B, e]
      pos_score_item = torch.mul(
          norm_item_embeddings, item2centroids
      ).sum(dim=1)
      pos_score_item = torch.exp(pos_score_item / self.ssl_temp)
      ttl_score_item = torch.matmul(
          norm_item_embeddings, self.item_centroids.transpose(0, 1)
      )
      ttl_score_item = torch.exp(ttl_score_item / self.ssl_temp).sum(
          dim=1
      )
      proto_nce_loss_item = -torch.log(
          pos_score_item / ttl_score_item
      ).sum()
  
      proto_nce_loss = self.proto_reg * (
          proto_nce_loss_user + proto_nce_loss_item
      )
      return proto_nce_loss
  
imports: import numpy
  import scipy.sparse
  import torch
  import torch.nn.functional
  from recbole.model.abstract_recommender import GeneralRecommender
  from recbole.model.init import xavier_uniform_initialization
  from recbole.model.loss import BPRLoss, EmbLoss
  from recbole.utils import InputType
label_desc: Use image node_id 7 for calling the NCL obj's underlying member method code with example usage: obj.ProtoNCE_loss(node_embedding, user, item) and returns: proto_nce_loss