Ejemplo n.º 1
0
	def __init__(self, vocab, args, device):
		super().__init__()

		self.m_pad_idx = vocab.pad_idx

		self.m_Recon_loss_fn = None
		self.m_KL_loss_fn = None
		self.m_RRe_loss_fn = None
		self.m_ARe_loss_fn = None

		self.m_save_mode = True

		self.m_mean_en_train_loss = 0
		self.m_mean_en_val_loss = 0

		self.m_mean_de_train_loss = 0
		self.m_mean_en_val_loss = 0
		
		self.m_device = device

		self.m_epochs = args.epochs
		self.m_batch_size = args.batch_size

		self.m_x0 = args.x0
		self.m_k = args.k

		self.m_anneal_func = args.anneal_func
		
		self.m_rec_loss = _REC_LOSS(self.m_device, ignore_index=self.m_pad_idx)
		self.m_rec_l_loss = _REC_LOSS(self.m_device, ignore_index=0)
		self.m_bow_loss = _BOW_LOSS(self.m_device)
		self.m_kl_loss_z = _KL_LOSS_CUSTOMIZE(self.m_device)
		self.m_kl_loss_s = _KL_LOSS_CUSTOMIZE(self.m_device)
		self.m_kl_loss_l = _KL_LOSS_STANDARD(self.m_device)

		self.m_train_step = 0
		self.m_valid_step = 0
		self.m_model_path = args.model_path
		self.m_model_file = args.model_file

		self.m_train_iteration = 0
		self.m_valid_iteration = 0
		self.m_print_interval = args.print_interval
		self.m_overfit_epoch_threshold = 3
Ejemplo n.º 2
0
    def f_init_eval(self, network, model_file=None, reload_model=False):
        if reload_model:
            print("reload model")
            if not model_file:
                model_file = "model_best.pt"
            model_name = os.path.join(self.m_model_path, model_file)
            print("model name", model_name)
            check_point = torch.load(model_name)
            network.load_state_dict(check_point['model'])

        self.m_network = network

        self.m_Recon_loss_fn = _REC_LOSS(ignore_index=self.m_pad_idx,
                                         device=self.m_device,
                                         reduction=True)
        self.m_KL_loss_z_fn = _KL_LOSS_STANDARD(self.m_device, reduction=True)
Ejemplo n.º 3
0
    def __init__(self, vocab_obj, args, device):
        super().__init__()

        self.m_pad_idx = vocab_obj.pad_idx

        self.m_save_mode = True
        self.m_mean_train_loss = 0
        self.m_mean_val_loss = 0
        
        self.m_device = device

        self.m_epochs = args.epochs
        self.m_batch_size = args.batch_size

        self.m_x0 = args.x0
        self.m_k = args.k

        self.m_anneal_func = args.anneal_func
        print("args.anneal_func", args.anneal_func)
        
        self.m_Recon_loss_fn = _REC_LOSS(ignore_index=self.m_pad_idx, device=self.m_device)
        self.m_KL_loss_z_fn = _KL_LOSS_STANDARD(self.m_device)
    
        self.m_train_step = 0
        self.m_valid_step = 0
        self.m_model_path = args.model_path
        self.m_model_name = "VAE"

        self.m_train_iteration = 0
        self.m_valid_iteration = 0

        self.m_KL_weight = 0.0
        # self.m_KL_weight_list = []

        self.m_grads = {}
        self.m_model_file = args.model_file

        self.m_train_loss_list = []
        self.m_train_rec_loss_list = []
        self.m_train_kl_loss_list = []

        self.m_print_interval = args.print_interval