class_docstr: NARM explores a hybrid encoder with an attention mechanism to model the user’s sequential behavior,
  and capture the user’s main purpose in the current session.
class_docstr_tok: ["NARM","explores","a","hybrid","encoder","with","an","attention","mechanism","to","model","the","user","\u2019","s","sequential","behavior",",","and","capture","the","user","\u2019","s","main","purpose","in","the","current","session","."]
code: def forward(self, item_seq, item_seq_len):
      item_seq_emb = self.item_embedding(item_seq)
      item_seq_emb_dropout = self.emb_dropout(item_seq_emb)
      gru_out, _ = self.gru(item_seq_emb_dropout)
  
      # fetch the last hidden state of last timestamp
      c_global = ht = self.gather_indexes(gru_out, item_seq_len - 1)
      # avoid the influence of padding
      mask = item_seq.gt(0).unsqueeze(2).expand_as(gru_out)
      q1 = self.a_1(gru_out)
      q2 = self.a_2(ht)
      q2_expand = q2.unsqueeze(1).expand_as(q1)
      # calculate weighted factors α
      alpha = self.v_t(mask * torch.sigmoid(q1 + q2_expand))
      c_local = torch.sum(alpha.expand_as(gru_out) * gru_out, 1)
      c_t = torch.cat([c_local, c_global], 1)
      c_t = self.ct_dropout(c_t)
      seq_output = self.b(c_t)
      return seq_output
  
file_path: RecBole/recbole/model/sequential_recommender/narm.py
imports: import torch
  from torch import nn
  from torch.nn.init import xavier_normal_, constant_
  from recbole.model.abstract_recommender import SequentialRecommender
  from recbole.model.loss import BPRLoss
label_desc: Use image node_id 3 for calling the NARM obj's underlying member method code with example usage: obj.forward(item_seq, item_seq_len) and returns: seq_output