lda2vec-pytorch icon indicating copy to clipboard operation
lda2vec-pytorch copied to clipboard

I run python train.py and get error with File "../utils/alias_multinomial.py", line 57

Open thucnt opened this issue 7 years ago • 13 comments

Traceback (most recent call last): File "train.py", line 36, in main() File "train.py", line 32, in main save_every=20, grad_clip=5.0 File "../utils/training.py", line 127, in train neg_loss, dirichlet_loss = model(doc_indices, pivot_words, target_words) File "/Users/macbook/anaconda/lib/python3.6/site-packages/torch/nn/modules/module.py", line 325, in call result = self.forward(input, **kwargs) File "../utils/lda2vec_loss.py", line 72, in forward neg_loss = self.neg(pivot_words, target_words, doc_vectors, w) File "/Users/macbook/anaconda/lib/python3.6/site-packages/torch/nn/modules/module.py", line 325, in call result = self.forward(input, **kwargs) File "../utils/lda2vec_loss.py", line 142, in forward noise = self.multinomial.draw(batch_sizewindow_sizeself.num_sampled) File "../utils/alias_multinomial.py", line 57, in draw b = torch.bernoulli(q) RuntimeError: invalid argument 1: must be >= 0 and <= 1 at /Volumes/OSX/Downloads/pytorch/aten/src/TH/THRandom.c:300

thucnt avatar Nov 30 '17 14:11 thucnt

I just tested the code and didn't get any errors. Have you changed any parameters in the code? Do you have up-to-date pytorch installed?

TropComplique avatar Nov 30 '17 19:11 TropComplique

Thanks for your response. But I have upgrade the latest pytorch using condo -c soumith pytorch and get a new error:

RuntimeError: invalid argument 1: must be >= 0 and <= 1 at /Users/soumith/miniconda2/conda-bld/pytorch_1503975723910/work/torch/lib/TH/THRandom.c:270

Because I run your code on my computer without GPU so I have to change your code by deleting anything relating to cuda(). Because I have just used pytorch, please tell me is it right?

thucnt avatar Dec 01 '17 07:12 thucnt

Hi. Have you changed any parameters in the code?

TropComplique avatar Dec 01 '17 08:12 TropComplique

Let's debug together. Add to utils/alias_multinomial.py before line 57 (line with b = torch.bernoulli(q)) the following print(q).

TropComplique avatar Dec 01 '17 08:12 TropComplique

This is result before program raise error: 0.3298 0.5141 0.6557 ⋮
0.3008 0.8198 0.8300 [torch.FloatTensor of size 1075200] main() File "/Volumes/OSX/Users/thucnt/git/lda2vec-pytorch/20newsgroups/train.py", line 32, in main save_every=20, grad_clip=5.0 File "/Volumes/OSX/Users/thucnt/git/lda2vec-pytorch/utils/training.py", line 127, in train neg_loss, dirichlet_loss = model(doc_indices, pivot_words, target_words) File "/Users/macbook/anaconda/envs/pytorch/lib/python3.6/site-packages/torch/nn/modules/module.py", line 224, in call result = self.forward(input, **kwargs) File "/Volumes/OSX/Users/thucnt/git/lda2vec-pytorch/utils/lda2vec_loss.py", line 72, in forward neg_loss = self.neg(pivot_words, target_words, doc_vectors, w) File "/Users/macbook/anaconda/envs/pytorch/lib/python3.6/site-packages/torch/nn/modules/module.py", line 224, in call result = self.forward(input, **kwargs) File "/Volumes/OSX/Users/thucnt/git/lda2vec-pytorch/utils/lda2vec_loss.py", line 142, in forward noise = self.multinomial.draw(batch_sizewindow_sizeself.num_sampled) File "/Volumes/OSX/Users/thucnt/git/lda2vec-pytorch/utils/alias_multinomial.py", line 58, in draw b = torch.bernoulli(q) RuntimeError: invalid argument 1: must be >= 0 and <= 1 at /Users/soumith/miniconda2/conda-bld/pytorch_1503975723910/work/torch/lib/TH/THRandom.c:270

thucnt avatar Dec 01 '17 08:12 thucnt

Now try print(q.min(), q.max()).

TropComplique avatar Dec 01 '17 09:12 TropComplique

number of documents: 12829 number of windows: 1023189 number of topics: 25 vocabulary size: 7460 word embedding dim: 50 number of batches: 143

epoch 1 0%| | 0/143 [00:00<?, ?it/s]Min and Max 0.20730416476726532 1.0001881122589111

thucnt avatar Dec 01 '17 09:12 thucnt

Add q = q.clamp(0.0, 1.0) before b = torch.bernoulli(q). It must solve the problem.

TropComplique avatar Dec 01 '17 09:12 TropComplique

Wow. A great support!!! Thank you very much. It runs now.

thucnt avatar Dec 01 '17 09:12 thucnt

Hello, thucnt Would you like to send me a copy of your modified program on CPU, thank you.

Oliveche avatar Jan 08 '18 05:01 Oliveche

I want to know If I want to run on CPU, is it ok if I just delete the.Cuda () in the code?

Oliveche avatar Jan 08 '18 05:01 Oliveche

@Oliveche I don't recommend to run this on CPU because it will be very slow. But yeah, if you delete cuda in right places the code will run on CPU.

TropComplique avatar Jan 09 '18 16:01 TropComplique

Thanks! I have deleted. But there is still the following problem,

number of documents: 12829 number of windows: 1023189 number of topics: 25 vocabulary size: 7460 word embedding dim: 50 number of batches: 143

epoch 1 0%| | 0/143 [00:00<?, ?it/s]

Please help me , thank you very much.

Oliveche avatar Jan 10 '18 01:01 Oliveche