class_docstr: MKR is a Multi-task feature learning approach for Knowledge graph enhanced Recommendation. It is a deep
  end-to-end framework that utilizes knowledge graph embedding task to assist recommendation task. The two
  tasks are associated by cross&compress units, which automatically share latent features and learn high-order
  interactions between items in recommender systems and entities in the knowledge graph.
class_docstr_tok: ["MKR","is","a","Multi-task","feature","learning","approach","for","Knowledge","graph","enhanced","Recommendation",".","It","is","a","deep","end-to-end","framework","that","utilizes","knowledge","graph","embedding","task","to","assist","recommendation","task",".","The","two","tasks","are","associated","by","cross","&","compress","units",",","which","automatically","share","latent","features","and","learn","high-order","interactions","between","items","in","recommender","systems","and","entities","in","the","knowledge","graph","."]
docstr: Calculate the training loss for a batch data of KG.
docstr_tok: ["Calculate","the","training","loss","for","a","batch","data","of","KG","."]
code: def calculate_kg_loss(self, interaction):
      r"""Calculate the training loss for a batch data of KG."""
      # inputs
      self.item_indices = interaction[self.HEAD_ENTITY_ID]
      self.head_indices = interaction[self.HEAD_ENTITY_ID]
      self.relation_indices = interaction[self.RELATION_ID]
      self.tail_indices = interaction[self.TAIL_ENTITY_ID]
      # KGE model
      head_embeddings, tail_embeddings, scores_kge, rmse = self.forward(
          user_indices=None,
          item_indices=self.item_indices,
          head_indices=self.head_indices,
          relation_indices=self.relation_indices,
          tail_indices=self.tail_indices,
      )
      # loss
      base_loss_kge = -scores_kge
      l2_loss_kge = self._l2_loss(head_embeddings) + self._l2_loss(
          tail_embeddings
      )
      loss_kge = base_loss_kge + l2_loss_kge * self.reg_weight
  
      return loss_kge.sum()
  
file_path: RecBole/recbole/model/knowledge_aware_recommender/mkr.py
imports: import torch
  import torch.nn
  from recbole.model.abstract_recommender import KnowledgeRecommender
  from recbole.model.init import xavier_normal_initialization
  from recbole.model.layers import MLPLayers
  from recbole.utils import InputType
label_desc: Use image node_id 5 for calling the MKR obj's underlying member method code with example usage: obj.calculate_kg_loss(interaction) and returns: loss_kge