def __init__(self, label_dictionary: Dictionary, multi_label: bool=False, multi_label_threshold: float=0.5, loss_weights: Dict[(str, float)]=None):
    super().__init__()
    self.label_dictionary: Dictionary = label_dictionary
    self.multi_label = multi_label
    self.multi_label_threshold = multi_label_threshold
    self.weight_dict = loss_weights
    if (loss_weights is not None):
        n_classes = len(self.label_dictionary)
        weight_list = [1.0 for i in range(n_classes)]
        for (i, tag) in enumerate(self.label_dictionary.get_items()):
            if (tag in loss_weights.keys()):
                weight_list[i] = loss_weights[tag]
        self.loss_weights = torch.FloatTensor(weight_list).to(flair.device)
    else:
        self.loss_weights = None
    if self.multi_label:
        self.loss_function = torch.nn.BCEWithLogitsLoss(weight=self.loss_weights)
    else:
        self.loss_function = torch.nn.CrossEntropyLoss(weight=self.loss_weights)
def __init__(self, label_dictionary: Dictionary, multi_label: bool=False, multi_label_threshold: float=0.5, loss_weights: Dict[(str, float)]=None):
    super().__init__()
    self.label_dictionary: Dictionary = label_dictionary
    self.multi_label = multi_label
    self.multi_label_threshold = multi_label_threshold
    self.weight_dict = loss_weights
    if (loss_weights is not None):
        n_classes = len(self.label_dictionary)
        weight_list = [1.0 for i in range(n_classes)]
        for (i, tag) in enumerate(self.label_dictionary.get_items()):
            if (tag in loss_weights.keys()):
                weight_list[i] = loss_weights[tag]
        self.loss_weights = torch.FloatTensor(weight_list).to(flair.device)
    else:
        self.loss_weights = None
    if self.multi_label:
        self.loss_function = torch.nn.BCEWithLogitsLoss(weight=self.loss_weights)
    else:
        self.loss_function = torch.nn.CrossEntropyLoss(weight=self.loss_weights)