The current version of cross-entropy loss only accepts one-hot vectors for target outputs.
I need to implement a version of cross-entropy loss that supports continuous target distributions. What I don’t know is how to implement a version of cross-entropy loss that is numerically stable.
For example, would the following implementation work well?

output = model(input)     #model output is a softmax distribution over 3 categories
target = Variable(torch.FloatTensor([0.1, 0.7, 0.2]))   #target distribution is continuous – not one-hot
loss = -1 * torch.sum(target * torch.log(output))   #compute the cross-entropy
loss.backward()

Is this stable? Is there a built-in version I can use?
Thank you