Esempio n. 1
0
 def __init__(self, reduction: Optional[Union[nn.Module, str]] = 'sum'):
     """
     Initialize BayesianPersonalizedRankingLoss
     
     Args:
         reduction Union[nn.Module, str], optional): reduction method to calculate loss. Defaults to sum
     """
     super().__init__()
     self.reduction = get_reduction(reduction)
Esempio n. 2
0
 def __init__(self,
              margin: float = 1.0,
              reduction: Optional[nn.Module] = torch.sum):
     """
     Initialize HingeLoss
     
     Args:
         margin (float, optional): Margin size of loss. Defaults to 1.0
         reduction (nn.Module, optional): Reduction method to calculate loss. Defaults to sum
     """
     super().__init__()
     self.margin = margin
     self.reduction = get_reduction(reduction)
    def __init__(self, 
                 reduction: Union[Callable[[torch.Tensor], torch.Tensor], str] = "sum"):
        r"""Initialize BayesianPersonalizedRankingLoss
        
        Args:
            reduction Union[Callable[T, T], str], optional): reduction method to calculate loss.
                Defaults to torch.sum.
        
        Attributes:
            reduction (Union[Callable[T, T], str]): reduction method to calculate loss.
        """
        # Refer to parent class
        super(BayesianPersonalizedRankingLoss, self).__init__()

        # Bind reduction to reduction
        self.reduction = get_reduction(reduction)
    def __init__(self, 
                 margin: float = 1.0,
                 reduction: Callable[[torch.Tensor], torch.Tensor] = torch.sum):
        r"""Initialize HingeLoss
        
        Args:
            margin (float, optional): Margin size of loss. Defaults to 1.0.
            reduction (Callable[T, T], optional): Reduction method to calculate loss.
                Defaults to torch.sum.
        
        Attributes:
            margin (float): Margin size of loss.
            reduction (Callable[T, T]): Reduction method to calculate loss.
        """
        # Refer to parent class
        super(HingeLoss, self).__init__()

        # Bind margin and reduction to margin and reduction
        self.margin = margin
        self.reduction = get_reduction(reduction)