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","."]
docstr: define write operator
docstr_tok: ["define","write","operator"]
code: def memory_update(self, item_seq, item_seq_len):
      """define write operator"""
      step_length = item_seq.size()[1]
      last_item = item_seq_len - 1
      # init user memory with 0s
      user_memory = (
          torch.zeros(
              item_seq.size()[0],
              self.n_relations,
              self.kg_embedding_size,
          )
          .float()
          .to(self.device)
      )  # [B R K]
      last_user_memory = torch.zeros_like(user_memory)
      for i in range(step_length):  # [len]
          _, update_memory = self._get_kg_embedding(
              item_seq[:, i]
          )  # [B R K]
          user_memory = self._memory_update_cell(
              user_memory, update_memory
          )  # [B R K]
          last_user_memory[last_item == i] = user_memory[
              last_item == i
          ].float()
      return last_user_memory
  
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 5 for calling the KSR obj's underlying member method code with example usage: obj.memory_update(item_seq, item_seq_len) and returns: last_user_memory