def test_eval(self):
        x_dev = np.random.randint(0, VOCABULARY_SIZE, [BATCH_SIZE * 5, SEQUENCE_LENGTH])
        y_dev = np.eye(2)[np.ones(BATCH_SIZE * 5, dtype=np.int32)]

        def make_eval_iter():
            data_iter = tfmodels.data.utils.batch_iter(list(zip(x_dev, y_dev)), BATCH_SIZE, 1, fill=True, seed=42)
            return map(lambda batch: zip(*batch), data_iter)

        with self.graph.as_default(), self.sess.as_default():
            rnn = self._build_classifier()
            ev = RNNClassifierEvaluator(rnn)
            self.sess.run(tf.initialize_all_variables())
            loss, acc, current_step = ev.eval(make_eval_iter())
            loss2, acc2, current_step = ev.eval(make_eval_iter())

        self.assertGreater(loss, 0)
        self.assertGreater(acc, 0)
        self.assertEqual(loss, loss2)
        self.assertEqual(acc, acc2)
    def test_eval(self):
        x_dev = np.random.randint(0, VOCABULARY_SIZE,
                                  [BATCH_SIZE * 5, SEQUENCE_LENGTH])
        y_dev = np.eye(2)[np.ones(BATCH_SIZE * 5, dtype=np.int32)]

        def make_eval_iter():
            data_iter = tfmodels.data.utils.batch_iter(list(zip(x_dev, y_dev)),
                                                       BATCH_SIZE,
                                                       1,
                                                       fill=True,
                                                       seed=42)
            return map(lambda batch: zip(*batch), data_iter)

        with self.graph.as_default(), self.sess.as_default():
            rnn = self._build_classifier()
            ev = RNNClassifierEvaluator(rnn)
            self.sess.run(tf.initialize_all_variables())
            loss, acc, current_step = ev.eval(make_eval_iter())
            loss2, acc2, current_step = ev.eval(make_eval_iter())

        self.assertGreater(loss, 0)
        self.assertGreater(acc, 0)
        self.assertEqual(loss, loss2)
        self.assertEqual(acc, acc2)
    model_params.update(FLAGS.__flags)
    model = RNNClassifier.from_dict(model_params)
    model.print_params()
    x = tf.placeholder(tf.int32, [FLAGS.batch_size, SEQUENCE_LENGTH])
    y = tf.placeholder(tf.float32, [FLAGS.batch_size, 2])
    model.build_graph(x, y)

    # Directory for training and dev summaries
    timestamp = str(int(time.time()))
    rundir = os.path.abspath(os.path.join(os.path.curdir, "runs", timestamp))
    train_dir = os.path.join(rundir, "train")
    dev_dir = os.path.join(rundir, "dev")

    # Build the Trainer/Evaluator
    trainer = RNNClassifierTrainer(model, train_summary_dir=train_dir)
    evaluator = RNNClassifierEvaluator(model, summary_dir=dev_dir)

    # Saving/Checkpointing
    checkpoint_dir = os.path.join(rundir, "checkpoints")
    if not os.path.exists(checkpoint_dir):
        os.makedirs(checkpoint_dir)
    checkpoint_file = os.path.join(checkpoint_dir, "model.ckpt")
    saver = tf.train.Saver(keep_checkpoint_every_n_hours=2)

    # Initialization, optinally load from checkpoint
    sess.run(tf.initialize_all_variables())
    latest_checkpoint = tf.train.latest_checkpoint(checkpoint_dir)
    if latest_checkpoint:
        print("Restoring checkpoint from {}".format(latest_checkpoint))
        saver.restore(sess, latest_checkpoint)
    model_params.update(FLAGS.__flags)
    model = RNNClassifier.from_dict(model_params)
    model.print_params()
    x = tf.placeholder(tf.int32, [FLAGS.batch_size, SEQUENCE_LENGTH])
    y = tf.placeholder(tf.float32, [FLAGS.batch_size, 2])
    model.build_graph(x, y)

    # Directory for training and dev summaries
    timestamp = str(int(time.time()))
    rundir = os.path.abspath(os.path.join(os.path.curdir, "runs", timestamp))
    train_dir = os.path.join(rundir, "train")
    dev_dir = os.path.join(rundir, "dev")

    # Build the Trainer/Evaluator
    trainer = RNNClassifierTrainer(model, train_summary_dir=train_dir)
    evaluator = RNNClassifierEvaluator(model, summary_dir=dev_dir)

    # Saving/Checkpointing
    checkpoint_dir = os.path.join(rundir, "checkpoints")
    if not os.path.exists(checkpoint_dir):
        os.makedirs(checkpoint_dir)
    checkpoint_file = os.path.join(checkpoint_dir, "model.ckpt")
    saver = tf.train.Saver(keep_checkpoint_every_n_hours=2)

    # Initialization, optinally load from checkpoint
    sess.run(tf.initialize_all_variables())
    latest_checkpoint = tf.train.latest_checkpoint(checkpoint_dir)
    if latest_checkpoint:
        print("Restoring checkpoint from {}".format(latest_checkpoint))
        saver.restore(sess, latest_checkpoint)