Ejemplo n.º 1
0
                os.makedirs('../results/{}/'.format(model_name))
            with open('../results/{}/res.csv'.format(model_name),
                      'a',
                      encoding='utf-8') as resfile:
                resfile.write('step,loss,rmse\n')

            sess.run(tf.global_variables_initializer())

            saver = tf.train.Saver()
            bad_count = 0
            init_rmse = 0.86
            last_best_rmse = init_rmse
            last_best_loss = 0
            for epoch in range(hp.NUM_EPOCHS):
                # load trainset
                train_batches = data.load_data('train')
                # training
                for (batch_X_user,
                     batch_X_movie), batch_Y in tqdm(train_batches):
                    # unpack
                    batch_u_oids, batch_bu_seq = batch_X_user
                    batch_m_oids, batch_info, batch_actors, batch_des, batch_bm_seq = batch_X_movie
                    batch_r_seq = batch_Y
                    feed_dict = {
                        model.m_oids: batch_m_oids,
                        model.info: batch_info,
                        model.actors: batch_actors,
                        model.descriptions: batch_des,
                        model.u_oids: batch_u_oids,
                        model.r_seq: batch_r_seq,
                        model.dropout_keep_prob: hp.DROPOUT_KEEP_PROB
Ejemplo n.º 2
0
                saver.restore(sess, fpath)

                # Get the placeholders from the graph by name
                m_oids = graph.get_tensor_by_name('movie_order_ids:0')
                info = graph.get_tensor_by_name('info:0')
                actors = graph.get_tensor_by_name('actors:0')
                descriptions = graph.get_tensor_by_name('descriptions:0')
                u_oids = graph.get_tensor_by_name('user_order_ids:0')
                r_seq = graph.get_tensor_by_name('rating_sequence:0')
                dropout_keep_prob = graph.get_tensor_by_name("dropout_keep_prob:0")

                # Tensors we want to evaluate
                mse_op = graph.get_tensor_by_name('mse/mse_op:0')

                # load evalset
                eval_iter = data.load_data('eval')
                mse, count = 0.0, 0
                for (sub_X_user, sub_X_movie), sub_Y in tqdm(eval_iter):
                    # unpack
                    sub_u_oids, sub_bu_seq = sub_X_user
                    sub_m_oids, sub_info, sub_actors, sub_des, sub_bm_seq = sub_X_movie
                    sub_r_seq = sub_Y
                    dev_feed_dict = {
                        m_oids: sub_m_oids,
                        info: sub_info,
                        actors: sub_actors,
                        descriptions: sub_des,
                        u_oids: sub_u_oids,
                        r_seq: sub_r_seq,
                        dropout_keep_prob: hp.DROPOUT_KEEP_PROB}