class_docstr: MCCLK is a knowledge-based recommendation model.
  It focuses on the contrastive learning in KG-aware recommendation and proposes a novel multi-level cross-view
  contrastive learning mechanism. This model comprehensively considers three different graph views for KG-aware
  recommendation, including global-level structural view, local-level collaborative and semantic views. It hence
  performs contrastive learning across three views on both local and global levels, mining comprehensive graph
  feature and structure information in a self-supervised manner.
class_docstr_tok: ["MCCLK","is","a","knowledge-based","recommendation","model",".","It","focuses","on","the","contrastive","learning","in","KG-aware","recommendation","and","proposes","a","novel","multi-level","cross-view","contrastive","learning","mechanism",".","This","model","comprehensively","considers","three","different","graph","views","for","KG-aware","recommendation",",","including","global-level","structural","view",",","local-level","collaborative","and","semantic","views",".","It","hence","performs","contrastive","learning","across","three","views","on","both","local","and","global","levels",",","mining","comprehensive","graph","feature","and","structure","information","in","a","self-supervised","manner","."]
code: def calculate_loss(self, interaction):
      if (
          self.restore_user_e is not None
          or self.restore_item_e is not None
      ):
          self.restore_user_e, self.restore_item_e = None, None
  
      # get loss for training rs
      user = interaction[self.USER_ID]
      pos_item = interaction[self.ITEM_ID]
      neg_item = interaction[self.NEG_ITEM_ID]
      all_item = torch.cat((pos_item, neg_item), dim=0)
  
      (
          item_semantic_emb,
          user_lightgcn_emb,
          item_lightgcn_emb,
          user_gcn_emb,
          item_gcn_emb,
      ) = self.forward()
      item_emb_1 = item_semantic_emb[all_item]
      user_emb_1 = user_lightgcn_emb[user]
      item_emb_2 = item_lightgcn_emb[all_item]
      user_emb_2 = user_gcn_emb[user]
      item_emb_3 = item_gcn_emb[all_item]
  
      local_loss = self.local_level_loss(item_emb_1, item_emb_2)
      global_loss = self.global_level_loss_1(
          user_emb_2, user_emb_1
      ) + self.global_level_loss_2(item_emb_3, item_emb_1 + item_emb_2)
  
      user_embedding = torch.cat((user_emb_2, user_emb_1), dim=-1)
      pos_item_embedding = torch.cat(
          (
              item_gcn_emb[pos_item],
              item_semantic_emb[pos_item] + item_lightgcn_emb[pos_item],
          ),
          dim=-1,
      )
      neg_item_embedding = torch.cat(
          (
              item_gcn_emb[neg_item],
              item_semantic_emb[neg_item] + item_lightgcn_emb[neg_item],
          ),
          dim=-1,
      )
  
      pos_scores = torch.mul(user_embedding, pos_item_embedding).sum(
          dim=1
      )
      neg_scores = torch.mul(user_embedding, neg_item_embedding).sum(
          dim=1
      )
      if self.loss_type.lower() == "bpr":
          rec_loss = self.rec_loss(pos_scores, neg_scores)
      else:
          predict = torch.cat((pos_scores, neg_scores))
          target = torch.zeros(
              len(pos_item) + len(neg_item), dtype=torch.float32
          ).to(self.device)
          target[: len(pos_item)] = 1
          rec_loss = self.rec_loss(predict, target)
  
      reg_loss = self.reg_loss(
          user_embedding, pos_item_embedding, neg_item_embedding
      )
      loss = (
          rec_loss
          + self.reg_weight * reg_loss
          + self.beta
          * (self.alpha * local_loss + (1 - self.alpha) * global_loss)
      )
  
      return loss
  
imports: import numpy
  import scipy.sparse
  import torch
  import torch.nn
  import torch.nn.functional
  from recbole.model.abstract_recommender import KnowledgeRecommender
  from recbole.model.init import xavier_normal_initialization
  from recbole.model.layers import SparseDropout
  from recbole.model.loss import BPRLoss, EmbLoss
  from recbole.utils import InputType
label_desc: Use image node_id 7 for calling the MCCLK obj's underlying member method code with example usage: obj.calculate_loss(interaction) and returns: loss