def test_zero_eps(self):
     self.args.label_smoothing = 0.0
     nll_crit = CrossEntropyCriterion.build_criterion(self.args, self.task)
     smooth_crit = LabelSmoothedCrossEntropyCriterion.build_criterion(self.args, self.task)
     nll_loss, nll_sample_size, nll_logging_output = nll_crit(self.model, self.sample)
     smooth_loss, smooth_sample_size, smooth_logging_output = smooth_crit(self.model, self.sample)
     self.assertAlmostEqual(nll_loss, smooth_loss)
 def test_nll_loss(self):
     self.args.label_smoothing = 0.1
     nll_crit = CrossEntropyCriterion.build_criterion(self.args, self.task)
     smooth_crit = LabelSmoothedCrossEntropyCriterion.build_criterion(self.args, self.task)
     nll_loss, nll_sample_size, nll_logging_output = nll_crit(self.model, self.sample)
     smooth_loss, smooth_sample_size, smooth_logging_output = smooth_crit(self.model, self.sample)
     self.assertLess(abs(nll_loss - nll_logging_output['loss']), 1e-6)
     self.assertLess(abs(nll_loss - smooth_logging_output['nll_loss']), 1e-6)