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 ssl_layer_loss(
      self, current_embedding, previous_embedding, user, item
  ):
      current_user_embeddings, current_item_embeddings = torch.split(
          current_embedding, [self.n_users, self.n_items]
      )
      (
          previous_user_embeddings_all,
          previous_item_embeddings_all,
      ) = torch.split(previous_embedding, [self.n_users, self.n_items])
  
      current_user_embeddings = current_user_embeddings[user]
      previous_user_embeddings = previous_user_embeddings_all[user]
      norm_user_emb1 = F.normalize(current_user_embeddings)
      norm_user_emb2 = F.normalize(previous_user_embeddings)
      norm_all_user_emb = F.normalize(previous_user_embeddings_all)
      pos_score_user = torch.mul(norm_user_emb1, norm_user_emb2).sum(
          dim=1
      )
      ttl_score_user = torch.matmul(
          norm_user_emb1, norm_all_user_emb.transpose(0, 1)
      )
      pos_score_user = torch.exp(pos_score_user / self.ssl_temp)
      ttl_score_user = torch.exp(ttl_score_user / self.ssl_temp).sum(
          dim=1
      )
  
      ssl_loss_user = -torch.log(pos_score_user / ttl_score_user).sum()
  
      current_item_embeddings = current_item_embeddings[item]
      previous_item_embeddings = previous_item_embeddings_all[item]
      norm_item_emb1 = F.normalize(current_item_embeddings)
      norm_item_emb2 = F.normalize(previous_item_embeddings)
      norm_all_item_emb = F.normalize(previous_item_embeddings_all)
      pos_score_item = torch.mul(norm_item_emb1, norm_item_emb2).sum(
          dim=1
      )
      ttl_score_item = torch.matmul(
          norm_item_emb1, norm_all_item_emb.transpose(0, 1)
      )
      pos_score_item = torch.exp(pos_score_item / self.ssl_temp)
      ttl_score_item = torch.exp(ttl_score_item / self.ssl_temp).sum(
          dim=1
      )
  
      ssl_loss_item = -torch.log(pos_score_item / ttl_score_item).sum()
  
      ssl_loss = self.ssl_reg * (
          ssl_loss_user + self.alpha * ssl_loss_item
      )
      return ssl_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 8 for calling the NCL obj's underlying member method code with example usage: obj.ssl_layer_loss(current_embedding, previous_embedding, user, item) and returns: ssl_loss