class_docstr: TransRec is translation-based model for sequential recommendation.
  It assumes that the `prev. item` + `user`  = `next item`.
  We use the Euclidean Distance to calculate the similarity in this implementation.
class_docstr_tok: ["TransRec","is","translation-based","model","for","sequential","recommendation",".","It","assumes","that","the","`","prev",".","item","`","+","`","user","`","=","`","next","item","`",".","We","use","the","Euclidean","Distance","to","calculate","the","similarity","in","this","implementation","."]
code: def calculate_loss(self, interaction):
      user = interaction[self.USER_ID]  # [B]
      item_seq = interaction[self.ITEM_SEQ]  # [B Len]
      item_seq_len = interaction[self.ITEM_SEQ_LEN]
  
      seq_output = self.forward(user, item_seq, item_seq_len)  # [B H]
  
      pos_items = interaction[self.POS_ITEM_ID]  # [B]
      neg_items = interaction[
          self.NEG_ITEM_ID
      ]  # [B] sample 1 negative item
  
      pos_items_emb = self.item_embedding(pos_items)  # [B H]
      neg_items_emb = self.item_embedding(neg_items)
  
      pos_bias = self.bias(pos_items)  # [B 1]
      neg_bias = self.bias(neg_items)
  
      pos_score = pos_bias - self._l2_distance(
          seq_output, pos_items_emb
      )
      neg_score = neg_bias - self._l2_distance(
          seq_output, neg_items_emb
      )
  
      bpr_loss = self.bpr_loss(pos_score, neg_score)
      item_emb_loss = self.emb_loss(
          self.item_embedding(pos_items).detach()
      )
      user_emb_loss = self.emb_loss(self.user_embedding(user).detach())
      bias_emb_loss = self.emb_loss(self.bias(pos_items).detach())
  
      reg_loss = self.reg_loss(self.T)
      return (
          bpr_loss
          + item_emb_loss
          + user_emb_loss
          + bias_emb_loss
          + reg_loss
      )
  
file_path: RecBole/recbole/model/sequential_recommender/transrec.py
imports: import torch
  from torch import nn
  from recbole.model.abstract_recommender import SequentialRecommender
  from recbole.model.init import xavier_normal_initialization
  from recbole.model.loss import BPRLoss, EmbLoss, RegLoss
  from recbole.utils import InputType
label_desc: Use image node_id 5 for calling the TransRec obj's underlying member method code with example usage: obj.calculate_loss(interaction) and returns: unknown