Loading fairseq/criterions/label_smoothed_cross_entropy.py +3 −0 Changes for fairseq/criterions/label_smoothed_cross_entropy.py: 3 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -7,6 +7,7 @@ import math import torch from torch.autograd import Variable import torch.nn.functional as F from fairseq import utils Loading @@ -24,6 +25,8 @@ class LabelSmoothedNLLLoss(torch.autograd.Function): norm = grad_input.size(-1) if weights is not None: if isinstance(grad_input, Variable) and not isinstance(weights, Variable): weights = Variable(weights, requires_grad=False) norm = weights.sum() grad_input.mul(weights.view(1, weights.size(0)).expand_as(grad_input)) Loading Loading
fairseq/criterions/label_smoothed_cross_entropy.py +3 −0 Changes for fairseq/criterions/label_smoothed_cross_entropy.py: 3 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -7,6 +7,7 @@ import math import torch from torch.autograd import Variable import torch.nn.functional as F from fairseq import utils Loading @@ -24,6 +25,8 @@ class LabelSmoothedNLLLoss(torch.autograd.Function): norm = grad_input.size(-1) if weights is not None: if isinstance(grad_input, Variable) and not isinstance(weights, Variable): weights = Variable(weights, requires_grad=False) norm = weights.sum() grad_input.mul(weights.view(1, weights.size(0)).expand_as(grad_input)) Loading