MCPcopy Create free account
hub / github.com/Tencent/NeuralNLP-NeuralClassifier / __init__

Method __init__

model/loss.py:101–117  ·  view source on GitHub ↗
(self, label_size, class_weight=None,
                 loss_type=LossType.SOFTMAX_CROSS_ENTROPY)

Source from the content-addressed store, hash-verified

99
100class ClassificationLoss(torch.nn.Module):
101 def __init__(self, label_size, class_weight=None,
102 loss_type=LossType.SOFTMAX_CROSS_ENTROPY):
103 super(ClassificationLoss, self).__init__()
104 self.label_size = label_size
105 self.loss_type = loss_type
106 if loss_type == LossType.SOFTMAX_CROSS_ENTROPY:
107 self.criterion = torch.nn.CrossEntropyLoss(class_weight)
108 elif loss_type == LossType.SOFTMAX_FOCAL_CROSS_ENTROPY:
109 self.criterion = FocalLoss(label_size, ActivationType.SOFTMAX)
110 elif loss_type == LossType.SIGMOID_FOCAL_CROSS_ENTROPY:
111 self.criterion = FocalLoss(label_size, ActivationType.SIGMOID)
112 elif loss_type == LossType.BCE_WITH_LOGITS:
113 self.criterion = torch.nn.BCEWithLogitsLoss()
114 else:
115 raise TypeError(
116 "Unsupported loss type: %s. Supported loss type is: %s" % (
117 loss_type, LossType.str()))
118
119 def forward(self, logits, target,
120 use_hierar=False,

Callers

nothing calls this directly

Calls 3

FocalLossClass · 0.85
__init__Method · 0.45
strMethod · 0.45

Tested by

no test coverage detected