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 __init__(self, config, dataset):
      super(KSR, self).__init__(config, dataset)
  
      # load dataset info
      self.ENTITY_ID = config["ENTITY_ID_FIELD"]
      self.RELATION_ID = config["RELATION_ID_FIELD"]
      self.n_entities = dataset.num(self.ENTITY_ID)
      self.n_relations = dataset.num(self.RELATION_ID) - 1
      self.entity_embedding_matrix = dataset.get_preload_weight(
          "ent_id"
      )
      self.relation_embedding_matrix = dataset.get_preload_weight(
          "rel_id"
      )
  
      # load parameters info
      self.embedding_size = config[
          "embedding_size"
      ]  # later use "E" to represent
      self.kg_embedding_size = config[
          "kg_embedding_size"
      ]  # later use "K" to represent
      self.hidden_size = config[
          "hidden_size"
      ]  # later use "H" to represent
      self.loss_type = config["loss_type"]
      self.num_layers = config["num_layers"]
      self.dropout_prob = config["dropout_prob"]
      self.gamma = config["gamma"]  # Scaling factor
      self.device = config["device"]
      self.loss_type = config["loss_type"]
      self.freeze_kg = config["freeze_kg"]
  
      # define layers and loss
      self.item_embedding = nn.Embedding(
          self.n_items, self.embedding_size, padding_idx=0
      )
      self.entity_embedding = nn.Embedding(
          self.n_items, self.kg_embedding_size, padding_idx=0
      )
      self.entity_embedding.weight.requires_grad = not self.freeze_kg
  
      self.emb_dropout = nn.Dropout(self.dropout_prob)
      self.gru_layers = nn.GRU(
          input_size=self.embedding_size,
          hidden_size=self.hidden_size,
          num_layers=self.num_layers,
          bias=False,
          batch_first=True,
      )
      self.dense = nn.Linear(self.hidden_size, self.kg_embedding_size)
      self.dense_layer_u = nn.Linear(
          self.hidden_size + self.kg_embedding_size, self.embedding_size
      )
      self.dense_layer_i = nn.Linear(
          self.embedding_size + self.kg_embedding_size,
          self.embedding_size,
      )
      if self.loss_type == "BPR":
          self.loss_fct = BPRLoss()
      elif self.loss_type == "CE":
          self.loss_fct = nn.CrossEntropyLoss()
      else:
          raise NotImplementedError(
              "Make sure 'loss_type' in ['BPR', 'CE']!"
          )
  
      # parameters initialization
      self.apply(self._init_weights)
      self.entity_embedding.weight.data.copy_(
          torch.from_numpy(self.entity_embedding_matrix[: self.n_items])
      )
      self.relation_Matrix = torch.from_numpy(
          self.relation_embedding_matrix[: self.n_relations]
      ).to(self.device)
  
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 1 to create a new KSR object from inherited base classes: SequentialRecommender with example: obj = KSR(config, dataset)