Exemple #1
0
def test_qgen(sess, testset, tokenizer, qgen, cpu_pool, batch_size, logger):
    qgen_sources = qgen.get_sources(sess)
    qgen_evaluator = Evaluator(qgen_sources, qgen.scope_name, network=qgen, tokenizer=tokenizer)
    qgen_batchifier = QuestionerBatchifier(tokenizer, qgen_sources, status=('success',))
    qgen_iterator = Iterator(testset, pool=cpu_pool,
                                 batch_size=batch_size,
                                 batchifier=qgen_batchifier)
    [qgen_loss] = qgen_evaluator.process(sess, qgen_iterator, outputs=[qgen.ml_loss])
    logger.info("QGen test loss: {}".format(qgen_loss))
Exemple #2
0
def test_guesser(sess, testset, tokenizer, guesser, cpu_pool, batch_size, logger):
    guesser_sources = guesser.get_sources(sess)
    guesser_evaluator = Evaluator(guesser_sources, guesser.scope_name, network=guesser, tokenizer=tokenizer)
    guesser_batchifier = QuestionerBatchifier(tokenizer, guesser_sources, status=('success',))
    guesser_iterator = Iterator(testset, pool=cpu_pool,
                             batch_size=batch_size,
                             batchifier=guesser_batchifier)
    [guesser_loss, guesser_error] = guesser_evaluator.process(sess, guesser_iterator, [guesser.loss, guesser.error])
    logger.info("Guesser test loss: {}".format(guesser_loss))
    logger.info("Guesser test error: {}".format(guesser_error))
Exemple #3
0
class SingleGameIterator(object):
    """ Single game iterator """
    def __init__(self, tokenizer, game):
        self.n_examples = 1
        #self.batchifier = LooperBatchifier(tokenizer, generate_new_games=False)
        self.batchifier = QuestionerBatchifier(tokenizer, None)
        self.game = game

    def __iter__(self):
        """ Applies batching (and transforms into dict) """
        # Futurely consider yielding games from the queue for the same looper
        return iter([self.batchifier.apply([self.game])])
Exemple #4
0
        sources = network.get_sources(sess)
        logger.info("Sources: " + ', '.join(sources))

        sess.run(tf.global_variables_initializer())
        start_epoch = load_checkpoint(sess, saver, args, save_path)

        best_val_err = 0
        best_train_err = None

        # create training tools
        evaluator = Evaluator(sources,
                              network.scope_name,
                              network=network,
                              tokenizer=tokenizer)
        batchifier = QuestionerBatchifier(tokenizer,
                                          sources,
                                          status=('success', ))

        for t in range(start_epoch, no_epoch):
            logger.info('Epoch {}..'.format(t + 1))

            train_iterator = Iterator(trainset,
                                      batch_size=batch_size,
                                      pool=cpu_pool,
                                      batchifier=batchifier,
                                      shuffle=True)
            train_loss, train_accuracy = evaluator.process(sess,
                                                           train_iterator,
                                                           outputs=outputs +
                                                           [optimizer])
Exemple #5
0
 def __init__(self, tokenizer, game):
     self.n_examples = 1
     #self.batchifier = LooperBatchifier(tokenizer, generate_new_games=False)
     self.batchifier = QuestionerBatchifier(tokenizer, None)
     self.game = game