def train(self, n_iters, feedback='teacher', **kwargs):
    ' Train for a given number of iterations '
    self.feedback = feedback
    self.encoder.train()
    self.decoder.train()
    self.critic.train()
    self.losses = []
    for iter in tqdm(range(1, (n_iters + 1))):
        self.encoder_optimizer.zero_grad()
        self.decoder_optimizer.zero_grad()
        self.critic_optimizer.zero_grad()
        self.loss = 0
        if (feedback == 'teacher'):
            self.feedback = 'teacher'
            self.rollout(train_ml=args.teacher_weight, train_rl=False, **kwargs)
        elif (feedback == 'sample'):
            if (args.ml_weight != 0):
                self.feedback = 'teacher'
                self.rollout(train_ml=args.ml_weight, train_rl=False, **kwargs)
            self.feedback = 'sample'
            self.rollout(train_ml=None, train_rl=True, **kwargs)
        else:
            assert False
        self.loss.backward()
        torch.nn.utils.clip_grad_norm(self.encoder.parameters(), 40.0)
        torch.nn.utils.clip_grad_norm(self.decoder.parameters(), 40.0)
        self.encoder_optimizer.step()
        self.decoder_optimizer.step()
        self.critic_optimizer.step()
Train for a given number of iterations
def train(self, n_iters, feedback='teacher', **kwargs):
    '  '
    self.feedback = feedback
    self.encoder.train()
    self.decoder.train()
    self.critic.train()
    self.losses = []
    for iter in tqdm(range(1, (n_iters + 1))):
        self.encoder_optimizer.zero_grad()
        self.decoder_optimizer.zero_grad()
        self.critic_optimizer.zero_grad()
        self.loss = 0
        if (feedback == 'teacher'):
            self.feedback = 'teacher'
            self.rollout(train_ml=args.teacher_weight, train_rl=False, **kwargs)
        elif (feedback == 'sample'):
            if (args.ml_weight != 0):
                self.feedback = 'teacher'
                self.rollout(train_ml=args.ml_weight, train_rl=False, **kwargs)
            self.feedback = 'sample'
            self.rollout(train_ml=None, train_rl=True, **kwargs)
        else:
            assert False
        self.loss.backward()
        torch.nn.utils.clip_grad_norm(self.encoder.parameters(), 40.0)
        torch.nn.utils.clip_grad_norm(self.decoder.parameters(), 40.0)
        self.encoder_optimizer.step()
        self.decoder_optimizer.step()
        self.critic_optimizer.step()