class_docstr: SASRec is the first sequential recommender based on self-attentive mechanism.
  
  NOTE:
      In the author's implementation, the Point-Wise Feed-Forward Network (PFFN) is implemented
      by CNN with 1x1 kernel. In this implementation, we follows the original BERT implementation
      using Fully Connected Layer to implement the PFFN.
class_docstr_tok: ["SASRec","is","the","first","sequential","recommender","based","on","self-attentive","mechanism",".","NOTE",":","In","the","author","'s","implementation",",","the","Point-Wise","Feed-Forward","Network","(","PFFN",")","is","implemented","by","CNN","with","1x1","kernel",".","In","this","implementation",",","we","follows","the","original","BERT","implementation","using","Fully","Connected","Layer","to","implement","the","PFFN","."]
code: def __init__(self, config, dataset):
      super(SASRecCPR, self).__init__(config, dataset)
  
      # load parameters info
      self.n_layers = config["n_layers"]
      self.n_heads = config["n_heads"]
      self.hidden_size = config["hidden_size"]  # same as embedding_size
      self.inner_size = config[
          "inner_size"
      ]  # the dimensionality in feed-forward layer
      self.hidden_dropout_prob = config["hidden_dropout_prob"]
      self.attn_dropout_prob = config["attn_dropout_prob"]
      self.hidden_act = config["hidden_act"]
      self.layer_norm_eps = config["layer_norm_eps"]
      self.initializer_range = config["initializer_range"]
      self.loss_type = config["loss_type"]
      self.n_facet_all = config["n_facet_all"]  # added for mfs
      self.n_facet = config["n_facet"]  # added for mfs
      self.n_facet_window = config["n_facet_window"]  # added for mfs
      self.n_facet_hidden = min(
          config["n_facet_hidden"], config["n_layers"]
      )  # added for mfs
      self.n_facet_MLP = config["n_facet_MLP"]  # added for mfs
      self.n_facet_context = config[
          "n_facet_context"
      ]  # added for dynamic partioning
      self.n_facet_reranker = config[
          "n_facet_reranker"
      ]  # added for dynamic partioning
      self.n_facet_emb = config[
          "n_facet_emb"
      ]  # added for dynamic partioning
      self.weight_mode = config["weight_mode"]  # added for mfs
      self.context_norm = config["context_norm"]  # added for mfs
      self.post_remove_context = config[
          "post_remove_context"
      ]  # added for mfs
      self.partition_merging_mode = config[
          "partition_merging_mode"
      ]  # added for mfs
      self.reranker_merging_mode = config[
          "reranker_merging_mode"
      ]  # added for mfs
      self.reranker_CAN_NUM = [
          int(x) for x in str(config["reranker_CAN_NUM"]).split(",")
      ]
      self.candidates_from_previous_reranker = True
      if self.weight_mode == "max_logits":
          self.n_facet_effective = 1
      else:
          self.n_facet_effective = self.n_facet
  
      assert (
          self.n_facet
          + self.n_facet_context
          + self.n_facet_reranker * len(self.reranker_CAN_NUM)
          + self.n_facet_emb
          == self.n_facet_all
      )
      assert self.n_facet_emb == 0 or self.n_facet_emb == 2
      assert self.n_facet_MLP <= 0  # -1 or 0
      assert self.n_facet_window <= 0
      self.n_facet_window = -self.n_facet_window
      self.n_facet_MLP = -self.n_facet_MLP
      self.softmax_nonlinear = "None"  # added for mfs
      self.use_proj_bias = config["use_proj_bias"]  # added for mfs
      hidden_state_input_ratio = 1 + self.n_facet_MLP  # 1 + 1
      self.MLP_linear = nn.Linear(
          self.hidden_size
          * (self.n_facet_hidden * (self.n_facet_window + 1)),
          self.hidden_size * self.n_facet_MLP,
      )  # (hid_dim*2) -> (hid_dim)
      total_lin_dim = self.hidden_size * hidden_state_input_ratio
      self.project_arr = nn.ModuleList(
          [
              nn.Linear(
                  total_lin_dim,
                  self.hidden_size,
                  bias=self.use_proj_bias,
              )
              for i in range(self.n_facet_all)
          ]
      )
  
      self.project_emb = nn.Linear(
          self.hidden_size, self.hidden_size, bias=self.use_proj_bias
      )
      if len(self.weight_mode) > 0:
          self.weight_facet_decoder = nn.Linear(
              self.hidden_size * hidden_state_input_ratio,
              self.n_facet_effective,
          )
          self.weight_global = nn.Parameter(
              torch.ones(self.n_facet_effective)
          )
      self.output_probs = True
      self.item_embedding = nn.Embedding(
          self.n_items, self.hidden_size, padding_idx=0
      )
      self.position_embedding = nn.Embedding(
          self.max_seq_length, self.hidden_size
      )
      self.trm_encoder = TransformerEncoder(
          n_layers=self.n_layers,
          n_heads=self.n_heads,
          hidden_size=self.hidden_size,
          inner_size=self.inner_size,
          hidden_dropout_prob=self.hidden_dropout_prob,
          attn_dropout_prob=self.attn_dropout_prob,
          hidden_act=self.hidden_act,
          layer_norm_eps=self.layer_norm_eps,
      )
  
      self.LayerNorm = nn.LayerNorm(
          self.hidden_size, eps=self.layer_norm_eps
      )
      self.dropout = nn.Dropout(self.hidden_dropout_prob)
  
      if self.loss_type == "BPR":
          print("current softmax-cpr code does not support BPR loss")
          sys.exit(0)
      elif self.loss_type == "CE":
          self.loss_fct = nn.NLLLoss(
              reduction="none", ignore_index=0
          )  # modified for mfs
      else:
          raise NotImplementedError(
              "Make sure 'loss_type' in ['BPR', 'CE']!"
          )
  
      # parameters initialization
      self.apply(self._init_weights)
  
      small_value = 0.0001
  
file_path: RecBole/recbole/model/sequential_recommender/sasreccpr.py
imports: import sys
  import torch
  from torch import nn
  import torch.nn.functional
  from recbole.model.abstract_recommender import SequentialRecommender
  from recbole.model.layers import TransformerEncoder
  import math
label_desc: Use image node_id 1 to create a new SASRecCPR object from inherited base classes: SequentialRecommender with example: obj = SASRecCPR(config, dataset)