class_docstr: Data loader for the DKN model.
  DKN requires a special type of data format, where each instance contains a label, the candidate news article,
  and user's clicked news article. Articles are represented by title words and title entities. Words and entities
  are aligned.
  
  Iterator will not load the whole data into memory. Instead, it loads data into memory
  per mini-batch, so that large files can be used as input data.
class_docstr_tok: ["Data","loader","for","the","DKN","model",".","DKN","requires","a","special","type","of","data","format",",","where","each","instance","contains","a","label",",","the","candidate","news","article",",","and","user","'s","clicked","news","article",".","Articles","are","represented","by","title","words","and","title","entities",".","Words","and","entities","are","aligned",".","Iterator","will","not","load","the","whole","data","into","memory",".","Instead",",","it","loads","data","into","memory","per","mini-batch",",","so","that","large","files","can","be","used","as","input","data","."]
docstr: Initialize an iterator. Create necessary placeholders for the model.
  
  Args:
      hparams (object): Global hyper-parameters. Some key setttings such as #_feature and #_field are there.
      graph (object): the running graph. All created placeholder will be added to this graph.
      col_spliter (str): column spliter in one line.
      ID_spliter (str): ID spliter in one line.
docstr_tok: ["Initialize","an","iterator",".","Create","necessary","placeholders","for","the","model",".","Args",":","hparams","(","object",")",":","Global","hyper-parameters",".","Some","key","setttings","such","as","#","_feature","and","#","_field","are","there",".","graph","(","object",")",":","the","running","graph",".","All","created","placeholder","will","be","added","to","this","graph",".","col_spliter","(","str",")",":","column","spliter","in","one","line",".","ID_spliter","(","str",")",":","ID","spliter","in","one","line","."]
code: def __init__(self, hparams, graph, col_spliter=" ", ID_spliter="%"):
      """Initialize an iterator. Create necessary placeholders for the model.
  
      Args:
          hparams (object): Global hyper-parameters. Some key setttings such as #_feature and #_field are there.
          graph (object): the running graph. All created placeholder will be added to this graph.
          col_spliter (str): column spliter in one line.
          ID_spliter (str): ID spliter in one line.
      """
      self.col_spliter = col_spliter
      self.ID_spliter = ID_spliter
      self.batch_size = hparams.batch_size
      self.doc_size = hparams.doc_size
      self.history_size = hparams.history_size
  
      self.graph = graph
      with self.graph.as_default():
          self.labels = tf.compat.v1.placeholder(
              tf.float32, [None, 1], name="label"
          )
          self.candidate_news_index_batch = tf.compat.v1.placeholder(
              tf.int64,
              [self.batch_size, self.doc_size],
              name="candidate_news_index",
          )
          self.click_news_index_batch = tf.compat.v1.placeholder(
              tf.int64,
              [self.batch_size, self.history_size, self.doc_size],
              name="click_news_index",
          )
          self.candidate_news_entity_index_batch = (
              tf.compat.v1.placeholder(
                  tf.int64,
                  [self.batch_size, self.doc_size],
                  name="candidate_news_entity_index",
              )
          )
          self.click_news_entity_index_batch = tf.compat.v1.placeholder(
              tf.int64,
              [self.batch_size, self.history_size, self.doc_size],
              name="click_news_entity_index",
          )
      self.news_word_index = {}
      self.news_entity_index = {}
      with tf.io.gfile.GFile(hparams.news_feature_file, "r") as rd:
          for line in rd:
              newsid, word_index, entity_index = line.strip().split(
                  col_spliter
              )
              self.news_word_index[newsid] = [
                  int(item) for item in word_index.split(",")
              ]
              self.news_entity_index[newsid] = [
                  int(item) for item in entity_index.split(",")
              ]
      self.user_history = {}
      with tf.io.gfile.GFile(hparams.user_history_file, "r") as rd:
          for line in rd:
              if len(line.strip().split(col_spliter)) == 1:
                  userid = line.strip()
                  user_history = []
              else:
                  userid, user_history_string = line.strip().split(
                      col_spliter
                  )
                  user_history = user_history_string.split(",")
              click_news_index = []
              click_news_entity_index = []
              if len(user_history) > self.history_size:
                  user_history = user_history[-self.history_size :]
              for newsid in user_history:
                  click_news_index.append(self.news_word_index[newsid])
                  click_news_entity_index.append(
                      self.news_entity_index[newsid]
                  )
              for i in range(self.history_size - len(user_history)):
                  click_news_index.append(np.zeros(self.doc_size))
                  click_news_entity_index.append(
                      np.zeros(self.doc_size)
                  )
              self.user_history[userid] = (
                  click_news_index,
                  click_news_entity_index,
              )
  
file_path: recommenders/recommenders/models/deeprec/io/dkn_iterator.py
imports: import tensorflow
  import numpy
  from recommenders.models.deeprec.io.iterator import BaseIterator
label_desc: Use image node_id 1 to create a new DKNTextIterator object from inherited base classes: BaseIterator with example: obj = DKNTextIterator(hparams, graph, col_spliter, ID_spliter)