docstr: Convert data into numpy arrays that are good for further model operation.
  
  Args:
      label_list (list): A list of ground-truth labels.
      user_list (list): A list of user indexes.
      item_list (list): A list of item indexes.
      item_cate_list (list): A list of category indexes.
      item_history_batch (list): A list of item history indexes.
      item_cate_history_batch (list): A list of category history indexes.
      time_list (list): A list of current timestamp.
      time_diff_list (list): A list of timestamp between each sequential operations.
      time_from_first_action_list (list): A list of timestamp from the first operation.
      time_to_now_list (list): A list of timestamp to the current time.
      batch_num_ngs (int): The number of negative sampling while training in mini-batch.
  
  Returns:
      dict: A dictionary, containing multiple numpy arrays that are convenient for further operation.
docstr_tok: ["Convert","data","into","numpy","arrays","that","are","good","for","further","model","operation",".","Args",":","label_list","(","list",")",":","A","list","of","ground-truth","labels",".","user_list","(","list",")",":","A","list","of","user","indexes",".","item_list","(","list",")",":","A","list","of","item","indexes",".","item_cate_list","(","list",")",":","A","list","of","category","indexes",".","item_history_batch","(","list",")",":","A","list","of","item","history","indexes",".","item_cate_history_batch","(","list",")",":","A","list","of","category","history","indexes",".","time_list","(","list",")",":","A","list","of","current","timestamp",".","time_diff_list","(","list",")",":","A","list","of","timestamp","between","each","sequential","operations",".","time_from_first_action_list","(","list",")",":","A","list","of","timestamp","from","the","first","operation",".","time_to_now_list","(","list",")",":","A","list","of","timestamp","to","the","current","time",".","batch_num_ngs","(","int",")",":","The","number","of","negative","sampling","while","training","in","mini-batch",".","Returns",":","dict",":","A","dictionary",",","containing","multiple","numpy","arrays","that","are","convenient","for","further","operation","."]
code: def _convert_data(
      self,
      label_list,
      user_list,
      item_list,
      item_cate_list,
      item_history_batch,
      item_cate_history_batch,
      time_list,
      time_diff_list,
      time_from_first_action_list,
      time_to_now_list,
      batch_num_ngs,
  ):
      """Convert data into numpy arrays that are good for further model operation.
  
      Args:
          label_list (list): A list of ground-truth labels.
          user_list (list): A list of user indexes.
          item_list (list): A list of item indexes.
          item_cate_list (list): A list of category indexes.
          item_history_batch (list): A list of item history indexes.
          item_cate_history_batch (list): A list of category history indexes.
          time_list (list): A list of current timestamp.
          time_diff_list (list): A list of timestamp between each sequential operations.
          time_from_first_action_list (list): A list of timestamp from the first operation.
          time_to_now_list (list): A list of timestamp to the current time.
          batch_num_ngs (int): The number of negative sampling while training in mini-batch.
  
      Returns:
          dict: A dictionary, containing multiple numpy arrays that are convenient for further operation.
      """
      if batch_num_ngs:
          instance_cnt = len(label_list)
          if instance_cnt < 5:
              return
  
          label_list_all = []
          item_list_all = []
          item_cate_list_all = []
          user_list_all = np.asarray(
              [[user] * (batch_num_ngs + 1) for user in user_list],
              dtype=np.int32,
          ).flatten()
          time_list_all = np.asarray(
              [[t] * (batch_num_ngs + 1) for t in time_list],
              dtype=np.float32,
          ).flatten()
  
          history_lengths = [
              len(item_history_batch[i]) for i in range(instance_cnt)
          ]
          max_seq_length_batch = self.max_seq_length
          item_history_batch_all = np.zeros(
              (instance_cnt * (batch_num_ngs + 1), max_seq_length_batch)
          ).astype("int32")
          item_cate_history_batch_all = np.zeros(
              (instance_cnt * (batch_num_ngs + 1), max_seq_length_batch)
          ).astype("int32")
          time_diff_batch = np.zeros(
              (instance_cnt * (batch_num_ngs + 1), max_seq_length_batch)
          ).astype("float32")
          time_from_first_action_batch = np.zeros(
              (instance_cnt * (batch_num_ngs + 1), max_seq_length_batch)
          ).astype("float32")
          time_to_now_batch = np.zeros(
              (instance_cnt * (batch_num_ngs + 1), max_seq_length_batch)
          ).astype("float32")
          mask = np.zeros(
              (instance_cnt * (1 + batch_num_ngs), max_seq_length_batch)
          ).astype("float32")
  
          for i in range(instance_cnt):
              this_length = min(
                  history_lengths[i], max_seq_length_batch
              )
              for index in range(batch_num_ngs + 1):
                  item_history_batch_all[
                      i * (batch_num_ngs + 1) + index, :this_length
                  ] = np.asarray(
                      item_history_batch[i][-this_length:],
                      dtype=np.int32,
                  )
                  item_cate_history_batch_all[
                      i * (batch_num_ngs + 1) + index, :this_length
                  ] = np.asarray(
                      item_cate_history_batch[i][-this_length:],
                      dtype=np.int32,
                  )
                  mask[
                      i * (batch_num_ngs + 1) + index, :this_length
                  ] = 1.0
                  time_diff_batch[
                      i * (batch_num_ngs + 1) + index, :this_length
                  ] = np.asarray(
                      time_diff_list[i][-this_length:], dtype=np.float32
                  )
                  time_from_first_action_batch[
                      i * (batch_num_ngs + 1) + index, :this_length
                  ] = np.asarray(
                      time_from_first_action_list[i][-this_length:],
                      dtype=np.float32,
                  )
                  time_to_now_batch[
                      i * (batch_num_ngs + 1) + index, :this_length
                  ] = np.asarray(
                      time_to_now_list[i][-this_length:],
                      dtype=np.float32,
                  )
  
          for i in range(instance_cnt):
              positive_item = item_list[i]
              label_list_all.append(1)
              item_list_all.append(positive_item)
              item_cate_list_all.append(item_cate_list[i])
              count = 0
              while batch_num_ngs:
                  random_value = random.randint(0, instance_cnt - 1)
                  negative_item = item_list[random_value]
                  if negative_item == positive_item:
                      continue
                  label_list_all.append(0)
                  item_list_all.append(negative_item)
                  item_cate_list_all.append(
                      item_cate_list[random_value]
                  )
                  count += 1
                  if count == batch_num_ngs:
                      break
  
          res = {}
          res["labels"] = np.asarray(
              label_list_all, dtype=np.float32
          ).reshape(-1, 1)
          res["users"] = user_list_all
          res["items"] = np.asarray(item_list_all, dtype=np.int32)
          res["cates"] = np.asarray(item_cate_list_all, dtype=np.int32)
          res["item_history"] = item_history_batch_all
          res["item_cate_history"] = item_cate_history_batch_all
          res["mask"] = mask
          res["time"] = time_list_all
          res["time_diff"] = time_diff_batch
          res["time_from_first_action"] = time_from_first_action_batch
          res["time_to_now"] = time_to_now_batch
          return res
  
      else:
          instance_cnt = len(label_list)
          history_lengths = [
              len(item_history_batch[i]) for i in range(instance_cnt)
          ]
          max_seq_length_batch = self.max_seq_length
          item_history_batch_all = np.zeros(
              (instance_cnt, max_seq_length_batch)
          ).astype("int32")
          item_cate_history_batch_all = np.zeros(
              (instance_cnt, max_seq_length_batch)
          ).astype("int32")
          time_diff_batch = np.zeros(
              (instance_cnt, max_seq_length_batch)
          ).astype("float32")
          time_from_first_action_batch = np.zeros(
              (instance_cnt, max_seq_length_batch)
          ).astype("float32")
          time_to_now_batch = np.zeros(
              (instance_cnt, max_seq_length_batch)
          ).astype("float32")
          mask = np.zeros((instance_cnt, max_seq_length_batch)).astype(
              "float32"
          )
  
          for i in range(instance_cnt):
              this_length = min(
                  history_lengths[i], max_seq_length_batch
              )
              item_history_batch_all[
                  i, :this_length
              ] = item_history_batch[i][-this_length:]
              item_cate_history_batch_all[
                  i, :this_length
              ] = item_cate_history_batch[i][-this_length:]
              mask[i, :this_length] = 1.0
              time_diff_batch[i, :this_length] = time_diff_list[i][
                  -this_length:
              ]
              time_from_first_action_batch[
                  i, :this_length
              ] = time_from_first_action_list[i][-this_length:]
              time_to_now_batch[i, :this_length] = time_to_now_list[i][
                  -this_length:
              ]
  
          res = {}
          res["labels"] = np.asarray(
              label_list, dtype=np.float32
          ).reshape(-1, 1)
          res["users"] = np.asarray(user_list, dtype=np.float32)
          res["items"] = np.asarray(item_list, dtype=np.int32)
          res["cates"] = np.asarray(item_cate_list, dtype=np.int32)
          res["item_history"] = item_history_batch_all
          res["item_cate_history"] = item_cate_history_batch_all
          res["mask"] = mask
          res["time"] = np.asarray(time_list, dtype=np.float32)
          res["time_diff"] = time_diff_batch
          res["time_from_first_action"] = time_from_first_action_batch
          res["time_to_now"] = time_to_now_batch
          return res
  
file_path: recommenders/recommenders/models/deeprec/io/sequential_iterator.py
imports: import tensorflow
  import numpy
  import random
  from recommenders.models.deeprec.io.iterator import BaseIterator
  from recommenders.models.deeprec.deeprec_utils import load_dict
label_desc: Use image node_id 5 for calling the SequentialIterator obj's underlying member method code with example usage: obj._convert_data(label_list, user_list, item_list, item_cate_list, item_history_batch, item_cate_history_batch, time_list, time_diff_list, time_from_first_action_list, time_to_now_list, batch_num_ngs) and returns: res, res