nlpmodels/utils/label_smoother.py
def forward(self, y_hat: torch.Tensor, target: torch.Tensor) -> Variable:
        """
        Main function call of label smoother.
        Args:
            y_hat (torch.Tensor):
                A sequence of (batch_size*max_seq_length,target_vocab_size) probability values.
            target (torch.Tensor):
                A 1D sequence of (batch_size) indicating the token values of the target (one-hot-encoding).

        Returns:
            Variable object containing the loss function.
        """

        # produces a target_smooth distribution that is (batch_size*max_seq_length,target_vocab_size)
        true_dist = self._compute_label_smoothing(target, y_hat)

        # return KL divergence
        return self._criterion(y_hat, Variable(true_dist, requires_grad=False))

        Main function call of label smoother.
        Args:
            y_hat (torch.Tensor):
                A sequence of (batch_size*max_seq_length,target_vocab_size) probability values.
            target (torch.Tensor):
                A 1D sequence of (batch_size) indicating the token values of the target (one-hot-encoding).

        Returns:
            Variable object containing the loss function.
        
Main function call of label smoother.
Main function call of label smoother .
def forward(self, y_hat: torch.Tensor, target: torch.Tensor) -> Variable:
        true_dist = self._compute_label_smoothing(target, y_hat)
        return self._criterion(y_hat, Variable(true_dist, requires_grad=False))
def forward ( self , y_hat : torch . Tensor , target : torch . Tensor ) -> Variable : true_dist = self . _compute_label_smoothing ( target , y_hat ) return self . _criterion ( y_hat , Variable ( true_dist , requires_grad = False ) )
Main function call of label smoother.
Main function call of label smoother .
"""
        Main function call of label smoother.
        Args:
            y_hat (torch.Tensor):
                A sequence of (batch_size*max_seq_length,target_vocab_size) probability values.
            target (torch.Tensor):
                A 1D sequence of (batch_size) indicating the token values of the target (one-hot-encoding).

        Returns:
            Variable object containing the loss function.
        """ # produces a target_smooth distribution that is (batch_size*max_seq_length,target_vocab_size) # return KL divergence
Variable object containing the loss function.
Variable object containing the loss function .
self
y_hat
torch.Tensor
A sequence of (batch_size*max_seq_length,target_vocab_size) probability values.
A sequence of ( batch_size * max_seq_length target_vocab_size ) probability values .
target
torch.Tensor
A 1D sequence of (batch_size) indicating the token values of the target (one-hot-encoding).
A 1D sequence of ( batch_size ) indicating the token values of the target ( one - hot - encoding ) .