out, hid, tgt, sel_out, sel_tgt = Engine.forward(self.model, batch, volatile=True)
// evaluate LM and selection losses
valid_loss += tgt.size(0) * self.crit(out.view(-1, N), tgt).data[0]
select_loss += self.sel_crit(sel_out, sel_tgt).data[0]
// dividing by the number of words in the input, not the tokens modeled,
// because the latter includes padding
After Change
out, hid, tgt, sel_out, sel_tgt = Engine.forward(self.model, batch, volatile=True)
// evaluate LM and selection losses
valid_loss += tgt.size(0) * self.crit(out.view(-1, N), tgt).item()
select_loss += self.sel_crit(sel_out, sel_tgt).item()
// dividing by the number of words in the input, not the tokens modeled,
// because the latter includes padding