class_docstr: KSR integrates the RNN-based networks with Key-Value Memory Network (KV-MN).
  And it further incorporates knowledge base (KB) information to enhance the semantic representation of KV-MN.
class_docstr_tok: ["KSR","integrates","the","RNN-based","networks","with","Key-Value","Memory","Network","(","KV-MN",")",".","And","it","further","incorporates","knowledge","base","(","KB",")","information","to","enhance","the","semantic","representation","of","KV-MN","."]
code: def calculate_loss(self, interaction):
      item_seq = interaction[self.ITEM_SEQ]
      item_seq_len = interaction[self.ITEM_SEQ_LEN]
      seq_output = self.forward(item_seq, item_seq_len)
      pos_items = interaction[self.POS_ITEM_ID]
      if self.loss_type == "BPR":
          neg_items = interaction[self.NEG_ITEM_ID]
          pos_items_emb = self._get_item_comb_embedding(pos_items)
          neg_items_emb = self._get_item_comb_embedding(neg_items)
          pos_score = torch.sum(
              seq_output * pos_items_emb, dim=-1
          )  # [B]
          neg_score = torch.sum(
              seq_output * neg_items_emb, dim=-1
          )  # [B]
          loss = self.loss_fct(pos_score, neg_score)
          return loss
      else:  # self.loss_type = 'CE'
          test_items_emb = self.dense_layer_i(
              torch.cat(
                  (
                      self.item_embedding.weight,
                      self.entity_embedding.weight,
                  ),
                  -1,
              )
          )  # [n_items E]
          logits = torch.matmul(
              seq_output, test_items_emb.transpose(0, 1)
          )
          loss = self.loss_fct(logits, pos_items)
          return loss
  
file_path: RecBole/recbole/model/sequential_recommender/ksr.py
imports: import torch
  from torch import nn
  from torch.nn.init import xavier_uniform_, xavier_normal_
  from recbole.model.abstract_recommender import SequentialRecommender
  from recbole.model.loss import BPRLoss
label_desc: Use image node_id 9 for calling the KSR obj's underlying member method code with example usage: obj.calculate_loss(interaction) and returns: loss, loss