I’m using a code from github for multi-class classification that uses a modified cross entropy loss function, that discards one class from the loss (first class).
Could someone please recognize the type of CE loss used ? and give me its name if it has one, or a resource to read about it ?
I could know that per_example_loss
is a CE loss without the class ‘0’
Could someone tell me what ‘rc_loss’ refers to ?
probabilities = F.softmax(logits, dim=-1)
log_probs = F.log_softmax(logits, dim=-1)
print("labels",labels)
one_hot_labels = F.one_hot(labels, num_classes=self.num_labels)
if device >= 0:
one_hot_labels = one_hot_labels.to(device)
print("hot labels", one_hot_labels)
dist = one_hot_labels[:, 1:].float() * log_probs[:, 1:]
print("hot labels except others", one_hot_labels[:, 1:].float())
print("log prob except others", log_probs[:, 1:])
example_loss_except_other, _ = dist.min(dim=-1)
print("example loss except others", example_loss_except_other)
per_example_loss = - example_loss_except_other.mean()
rc_probabilities = probabilities - probabilities * one_hot_labels.float()
print("rc_prob ",rc_probabilities )
second_pre, _ = rc_probabilities[:, 1:].max(dim=-1)
print("seconde prob ",second_pre)
rc_loss = - (1 - second_pre).log().mean()
print("rc loss ",rc_loss)
#print(loss, per_example_loss, rc_loss)
loss += per_example_loss + 5 * rc_loss
Thanks in advance !