f466871be6ee80533c997cf6c958aa41a697936f,trainer.py,Trainer,train_one_epoch,#Trainer#,137

Before Change


            // initialize location and hidden state vectors
            h_t = torch.zeros(self.batch_size, self.hidden_size)
            l_t = torch.Tensor(self.batch_size, 2).uniform_(-1, 1)
            h_t, l_t = Variable(h_t), Variable(l_t)

            for t in range(self.num_glimpses - 1):
                // forward pass through model
                h_t, l_t = self.model(img, l_t, h_t)

                // bookeeping for later plotting
                self.locs.append(l_t)

            // last iteration
            probas = self.model(img, l_t, h_t, last=True)

            // to be continued

After Change


            l_t = Variable(l_t)

            // extract the glimpses
            sum_grad_log_pi = 0.
            for t in range(self.num_glimpses - 1):

                // forward pass through model
                self.h_t, mu, l_t = self.model(x, l_t, self.h_t)

                // compute gradient of log of policy across batch
                grad_log_pi = (mu-l_t) / (self.std*self.std)

                // accumulate
                sum_grad_log_pi += grad_log_pi

            // last iteration
            self.h_t, mu, l_t, b_t, log_probas = self.model(
                img, l_t, self.h_t, last=True
            )

            // calculate reward
            R = (torch.max(log_probas, 1)[1] == y)

            // compute losses for differentiable modules
            self.loss_action = F.nll_loss(log_probas, y)
            self.loss_baseline = F.mse_loss(R, b_t)

            // compute reinforce loss
            
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 3

Non-data size: 6

Instances


Project Name: kevinzakka/recurrent-visual-attention
Commit Name: f466871be6ee80533c997cf6c958aa41a697936f
Time: 2018-01-22
Author: kevinarmandzakka@gmail.com
File Name: trainer.py
Class Name: Trainer
Method Name: train_one_epoch


Project Name: kevinzakka/recurrent-visual-attention
Commit Name: f466871be6ee80533c997cf6c958aa41a697936f
Time: 2018-01-22
Author: kevinarmandzakka@gmail.com
File Name: trainer.py
Class Name: Trainer
Method Name: train_one_epoch


Project Name: jadore801120/attention-is-all-you-need-pytorch
Commit Name: 15b19130a9162feb9153a2f38c5c8b0af02c6a1d
Time: 2018-08-21
Author: yhhuang@nlg.csie.ntu.edu.tw
File Name: train.py
Class Name:
Method Name: eval_epoch


Project Name: jadore801120/attention-is-all-you-need-pytorch
Commit Name: 15b19130a9162feb9153a2f38c5c8b0af02c6a1d
Time: 2018-08-21
Author: yhhuang@nlg.csie.ntu.edu.tw
File Name: train.py
Class Name:
Method Name: train_epoch