pytorch > 1.0
git clone https://github.com/wangleiofficial/label-smoothing-pytorch.git
import LabelSmoothingCrossEntropy
criterion = LabelSmoothingCrossEntropy(reduction='sum')
loss = criterion(preds, labels)
Müller, Rafael, Simon Kornblith, and Geoffrey E. Hinton. "When does label smoothing help?." Advances in Neural Information Processing Systems. 2019.