Esempio n. 1
0
    def __init__(self, opt):
        self.log = open(cfg.log_filename +
                        '.txt', 'w') if not cfg.if_test else None
        self.model_log = open(cfg.save_root +
                              'log.txt', 'w') if not cfg.if_test else None
        self.sig = Signal(cfg.signal_file)
        self.opt = opt
        self.show_config()

        # load dictionary
        self.word_index_dict, self.index_word_dict = load_dict(cfg.dataset)
    def __init__(self, opt):
        self.log = create_logger(__name__, silent=False, to_disk=True,
                                 log_file=cfg.log_filename if cfg.if_test
                                 else [cfg.log_filename, cfg.save_root + 'log.txt'])
        self.sig = Signal(cfg.signal_file)
        self.opt = opt
        self.show_config()

        self.clas = None

        # load dictionary
        self.word2idx_dict, self.idx2word_dict = load_dict(cfg.dataset)

        # Dataloader
        try:
            self.train_data = GenDataIter(cfg.train_data)
            self.test_data = GenDataIter(cfg.test_data, if_test_data=True)
        except:
            pass

        try:
            self.train_data_list = [GenDataIter(cfg.cat_train_data.format(i)) for i in range(cfg.k_label)]
            self.test_data_list = [GenDataIter(cfg.cat_test_data.format(i), if_test_data=True) for i in
                                   range(cfg.k_label)]
            self.clas_data_list = [GenDataIter(cfg.cat_test_data.format(str(i)), if_test_data=True) for i in
                                   range(cfg.k_label)]

            self.train_samples_list = [self.train_data_list[i].target for i in range(cfg.k_label)]
            self.clas_samples_list = [self.clas_data_list[i].target for i in range(cfg.k_label)]
        except:
            pass

        # Criterion
        self.mle_criterion = nn.NLLLoss()
        self.dis_criterion = nn.CrossEntropyLoss()
        self.clas_criterion = nn.CrossEntropyLoss()

        # Optimizer
        self.clas_opt = None

        # Metrics
        self.bleu = BLEU('BLEU', gram=[2, 3, 4, 5], if_use=cfg.use_bleu)
        self.nll_gen = NLL('NLL_gen', if_use=cfg.use_nll_gen, gpu=cfg.CUDA)
        self.nll_div = NLL('NLL_div', if_use=cfg.use_nll_div, gpu=cfg.CUDA)
        self.self_bleu = BLEU('Self-BLEU', gram=[2, 3, 4], if_use=cfg.use_self_bleu)
        self.clas_acc = ACC(if_use=cfg.use_clas_acc)
        self.ppl = PPL(self.train_data, self.test_data, n_gram=5, if_use=cfg.use_ppl)
        self.all_metrics = [self.bleu, self.nll_gen, self.nll_div, self.self_bleu, self.ppl]
    def __init__(self, opt):
        self.log = create_logger(__name__,
                                 silent=False,
                                 to_disk=False if cfg.if_test else True,
                                 log_file=None if cfg.if_test else
                                 [cfg.log_filename, cfg.save_root + 'log.txt'])
        self.sig = Signal(cfg.signal_file)
        self.opt = opt
        self.show_config()

        # load dictionary
        self.word_index_dict, self.index_word_dict = load_dict(cfg.dataset)

        # Dataloader
        self.oracle_data = GenDataIter(cfg.train_data)
        self.test_data = GenDataIter(cfg.test_data)
Esempio n. 4
0
    def __init__(self, opt):
        self.log = create_logger(__name__,
                                 silent=False,
                                 to_disk=True,
                                 log_file=cfg.log_filename if cfg.if_test else
                                 [cfg.log_filename, cfg.save_root + 'log.txt'])
        self.sig = Signal(cfg.signal_file)
        self.opt = opt
        self.show_config()

        # load dictionary
        self.word_index_dict, self.index_word_dict = load_dict(cfg.dataset)

        # Dataloader
        self.train_data = GenDataIter(cfg.train_data)
        self.test_data = GenDataIter(cfg.test_data, if_test_data=True)
        self.gen_data = None

        # Criterion
        self.mle_criterion = nn.NLLLoss()
        self.dis_criterion = None
        self.bleu = None
        self.self_bleu = None