Ejemplo n.º 1
0
    def __init__(self, options, corpus, session):
        Model.__init__(self, options, corpus, session)
        # Key node
        self._pop_per_item = list()

        self.train()
        self.build_eval_graph()
Ejemplo n.º 2
0
    def __init__(self, options, corpus, session):
        Model.__init__(self, options, corpus, session)
        self.last_save_epoch = -1

        # Model parameter
        self._all_user_emb = None
        self._user_emb = None
        self._item_emb = None
        self._item_bias = None

        # Best parameter
        self._all_user_emb_best = None
        self._user_emb_best = None
        self._item_emb_best = None
        self._item_bias_best = None

        # Nodes in the graph which are used to run/feed/fetch.
        self._cur_user = None
        self._prev_item = None
        self._pos_item = None
        self._neg_item = None

        # Key Nodes
        # Train
        self._loss, self._loss1, self._loss2 = None, None, None
        self._train = None
        self.global_step = None
        self._debug = None
        # Op
        self._norm_all_user_emb_op = None
        self._norm_item_emb_op = None
        self._save_best_param_op = None
        self._restore_best_param_op = None
        # Summary
        self._loss_summary = None
        self._train_writer = None

        self.build_graph()
        self.build_eval_graph()

        # Properly initialize all variables.
        tf.global_variables_initializer().run()
        self.saver = tf.train.Saver()

        if len(self._options.checkpoint_name) > 0:
            ckpt_path = self._options.checkpoints_path + self._options.checkpoint_name
            self.load_model(ckpt_path)

        if self._options.write_summary:
            self._train_writer = tf.summary.FileWriter(
                "{}{}_{}/train".format(self._options.save_path,
                                       self._options.timestamp,
                                       self.to_string()), self._session.graph)
            self._test_writer = tf.summary.FileWriter("{}{}_{}/test".format(
                self._options.save_path, self._options.timestamp,
                self.to_string()))