Hi!
I am trying to compute softmax_cross_entropy_with_logits in PyTorch. I couldn’t get the existing APIs working because of the smoothed labels. In my case where logits and labels have shape [2,3,4], I currently use following function -
I think you want torch.nn.functional.log_softmax instead of the module. I’m not sure about the output shape you want (maybe an additional mean or sum somewhere?), but other than that it looks very reasonable to me.
Thanks for the reply. nn.LogSoftmax uses torch.nn.functional.log_softmax in its backend so I guess both are same as far as functioning and speed is concerned.
Here is a snippet from my implementation, where I basically assign smoothed label to whole tensor and then later add high confidence labels. Note that your case of smoothing might be different and the function is specific for my requirement of computation over a language model -