Negative learning implementation in pytorch
One implementation is
( (loss+loss_neg) / (float((labels&gt;=0).sum())+float((labels_neg[:,0]&gt;=0).sum())) ).backward()

from NLNL-Negative-Learning-for-Noisy-Labels GitHub repo.