Esempio n. 1
0
    def evaluate(self):
        logger = logging.getLogger("brc")
        logger.info("====== evaluating ======")
        logger.info('Load data_set and vocab...')
        with open(os.path.join(self.config.get_filepath().vocab_dir, 'vocab.data'), 'rb') as fin:
            vocab = pickle.load(fin)

        assert len(self.dev_files) > 0, 'No dev files are provided.'
        dataloader = Propress(self.config.get_default_params().max_p_num,
                              self.config.get_default_params().max_p_len,
                              self.config.get_default_params().max_q_len,
                              self.config.get_default_params().max_ch_len,
                              dev_files=self.dev_files)

        logger.info('Converting text into ids...')
        dataloader.convert_to_ids(vocab)

        logger.info('Restoring the model...')
        model = Model(vocab, trainable=False)
        model.restore(self.config.get_filepath().model_dir, self.algo)
        logger.info('Evaluating the model on dev set...')
        dev_batches = dataloader.next_batch('dev',
                                            self.config.get_default_params().batch_size,
                                            vocab.get_id_byword(vocab.pad_token),
                                            vocab.get_id_bychar(vocab.pad_token),
                                            shuffle=False)

        dev_loss, dev_bleu_rouge, summ = model.evaluate(
            dev_batches, 'dev', result_dir=self.config.get_filepath().output_dir, result_prefix='dev.predicted')

        logger.info('Loss on dev set: {}'.format(dev_loss))
        logger.info('Result on dev set: {}'.format(dev_bleu_rouge))
        logger.info('Predicted answers are saved to {}'.format(os.path.join(self.config.get_filepath().output_dir)))
Esempio n. 2
0
    def predict(self):
        logger = logging.getLogger("brc")

        logger.info('Load data_set and vocab...')
        with open(os.path.join(self.config.get_filepath().vocab_dir, 'vocab.data'), 'rb') as fin:
            vocab = pickle.load(fin)

        assert len(self.test_files) > 0, 'No test files are provided.'
        dataloader = Propress(self.config.get_default_params().max_p_num,
                              self.config.get_default_params().max_p_len,
                              self.config.get_default_params().max_q_len,
                              self.config.get_default_params().max_ch_len,
                              test_files=self.test_files)

        logger.info('Converting text into ids...')
        dataloader.convert_to_ids(vocab)
        logger.info('Restoring the model...')

        model = Model(vocab, trainable=False)
        model.restore(self.config.get_filepath().model_dir, self.algo)
        logger.info('Predicting answers for test set...')
        test_batches = dataloader.next_batch('test',
                                             self.config.get_default_params().batch_size,
                                             vocab.get_word_id(vocab.pad_token),
                                             vocab.get_char_id(vocab.pad_token),
                                             shuffle=False)

        model.evaluate(test_batches, 'test', result_dir=self.config.get_filepath().output_dir, result_prefix='test.predicted')
Esempio n. 3
0
def evaluate(args):
    logger = logging.getLogger("brc")
    logger.info("====== evaluating ======")
    logger.info('Load data_set and vocab...')
    with open(os.path.join(args.vocab_dir, 'vocab.data'), 'rb') as fin:
        vocab = pickle.load(fin)

    assert len(args.dev_files) > 0, 'No dev files are provided.'
    dataloader = Propress(args.max_p_num,
                          args.max_p_len,
                          args.max_q_len,
                          args.max_ch_len,
                          dev_files=args.dev_files)

    logger.info('Converting text into ids...')
    dataloader.convert_to_ids(vocab)

    logger.info('Restoring the model...')
    model = Model(vocab, args)
    model.restore(args.model_dir, args.algo)
    logger.info('Evaluating the model on dev set...')
    dev_batches = dataloader.next_batch('dev',
                                        args.batch_size,
                                        vocab.get_word_id(vocab.pad_token),
                                        vocab.get_char_id(vocab.pad_token),
                                        shuffle=False)

    dev_loss, dev_bleu_rouge = model.evaluate(dev_batches,
                                              result_dir=args.result_dir,
                                              result_prefix='dev.predicted')

    logger.info('Loss on dev set: {}'.format(dev_loss))
    logger.info('Result on dev set: {}'.format(dev_bleu_rouge))
    logger.info('Predicted answers are saved to {}'.format(
        os.path.join(args.result_dir)))