Trying to compute softmax

I’m trying to use torch.nn.functional.Softmax with Variable input, but getting an error. Where am I wrong?

a = np.random.randint(0,3,size=(10))
v = Variable(torch.from_numpy(a))
F.softmax(v)

Getting KeyError: <class ‘torch.LongTensor’>

Hi

you need to change the data type of a from in to float or doule, i.e ,you can try this:

a =1.0 * np.random.randint(0,3,size=(10))
v = Variable(torch.from_numpy(a))
F.softmax(v)

1 Like