timbmg / Sentence-VAE

PyTorch Re-Implementation of "Generating Sentences from a Continuous Space" by Bowman et al 2015 https://arxiv.org/abs/1511.06349
580 stars 152 forks source link

Word Dropout not working #11

Closed dhanajitb closed 5 years ago

dhanajitb commented 5 years ago

Using --word_dropout causes an error. For eg. python3 train.py --word_dropout 0.62 gives the following error:

Traceback (most recent call last):
  File "train.py", line 214, in <module>
    main(args)
  File "train.py", line 118, in main
    logp, mean, logv, z = model(batch['input'], batch['length'])
  File "/user1/anaconda3/envs/sentence-vae/lib/python3.6/site-packages/torch/nn/modules/module.py", line 357, in __call__
    result = self.forward(*input, **kwargs)
  File "/user1/Sentence-VAE/model.py", line 90, in forward
    prob[(input_sequence.data - self.sos_idx) * (input_sequence.data - self.pad_idx) == 0] = 1
TypeError: Performing basic indexing on a tensor and encountered an error indexing dim 0 with an object of type torch.cuda.ByteTensor. The only supported types are integers, slices, numpy scalars, or if indexing with a torch.LongTensor or torch.ByteTensor only a single Tensor may be passed.
dhanajitb commented 5 years ago

The following fix works: Add

if torch.cuda.is_available():
    prob=prob.cuda()

after line 89 in model.py.