Can someone please explain what torch.multinomial does?
With numpy’s np.random.multinomial it is more or less clear: it take the number of trials (experiments), the probabilities for each outcome (which sum up to 1) and the size of the output (i.e. the number of drawn samples). So for example, if we the experiment is to throw a six-sided fair dice and we do it n=20 times, then
>>> np.random.multinomial(20, [1/6.]*6, size=1)
array([[4, 1, 7, 5, 2, 1]])

meaning that the dice landed 4 times on 1, once on 2, etc.
How can we do the same thing with torch.multinomial?
I found the following example which unfortunately doesn’t make much sense to me:
>>> weights = torch.tensor([0, 10, 3, 0], dtype=torch.float)
>>> torch.multinomial(weights, 2)
tensor([1, 2])
>>> torch.multinomial(weights, 4) # ERROR!

How do the weights translate to probabilities? What is the meaning of tensor([1, 2]) and why the second example gives error?