if args.cuda:
input = input.cuda()
temperature = max(args.temperature, 1e-3)
with open(args.outf, "w") as outf:
for i in range(args.nwords):
output, hidden = model(Variable(input, volatile=True), hidden)
gen = torch.multinomial(output[0].data.div(temperature).exp().cpu(), 1)[0][0] // FIXME: multinomial is only for CPU
input.fill_(gen)
word = corpus.dic.idx2word[gen]
outf.write(word)
if i % 20 == 19:
outf.write("\n")
else: