def __init__(self, num_classes, class_weights=None): LossNM.__init__(self) if class_weights: class_weights = torch.FloatTensor(class_weights).to(self._device) self._criterion = nn.CrossEntropyLoss(weight=class_weights) self.num_classes = num_classes
def __init__( self, num_slots, slot_classes_loss_weights=None, intent_classes_loss_weights=None, intent_loss_weight=0.6, ): LossNM.__init__(self) self.num_slots = num_slots self.intent_loss_weight = intent_loss_weight self.slot_classes_loss_weights = slot_classes_loss_weights self.intent_classes_loss_weights = intent_classes_loss_weights # For weighted loss to tackle class imbalance if slot_classes_loss_weights: self.slot_classes_loss_weights = torch.FloatTensor( slot_classes_loss_weights).to(self._device) if intent_classes_loss_weights: self.intent_classes_loss_weights = torch.FloatTensor( intent_classes_loss_weights).to(self._device) self._criterion_intent = nn.CrossEntropyLoss( weight=self.intent_classes_loss_weights) self._criterion_slot = nn.CrossEntropyLoss( weight=self.slot_classes_loss_weights)
def __init__(self, pad_id=None, label_smoothing=0, predict_last_k=0): LossNM.__init__(self) self._loss_fn = SmoothedCrossEntropy(label_smoothing, predict_last_k) self._pad_id = pad_id
def __init__(self, num_inputs=2): # Store number of inputs/losses. self.num_losses = num_inputs LossNM.__init__(self)
def __init__(self): LossNM.__init__(self)
def __init__(self, label_smoothing=0.0): LossNM.__init__(self) self._criterion = SmoothedCrossEntropyLoss(label_smoothing)