Sampling new text from Pytorch language model example
Hi, <SCODE>        output, hidden = model(input, hidden)
        word_weights = output.squeeze().data.div(args.temperature).exp().cpu()
        word_idx = torch.multinomial(word_weights, 1)[0]
        input.data.fill_(word_idx)
        word = corpus.dictionary.idx2word[word_idx]
<ECODE> I understand that this is not necessarily a Pytorch question, but would appreciate if someone could share details behind the sampling.
jatinganhotra
A guess would be that it makes the output richer. Sticking to the most probable words would restrict the model to always use the most commonly used words, while if you use softmax, it should end up using the words approximately as often as they appear in natural language (so it will sometimes insert some more complex ones too).
apaszke