lda2vec-pytorch
lda2vec-pytorch copied to clipboard
I run python train.py and get error with File "../utils/alias_multinomial.py", line 57
Traceback (most recent call last):
File "train.py", line 36, in
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?
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?
Hi. Have you changed any parameters in the code?
Let's debug together.
Add to utils/alias_multinomial.py
before
line 57 (line with b = torch.bernoulli(q)
)
the following print(q)
.
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
Now try print(q.min(), q.max())
.
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
Add q = q.clamp(0.0, 1.0)
before b = torch.bernoulli(q)
.
It must solve the problem.
Wow. A great support!!! Thank you very much. It runs now.
Hello, thucnt Would you like to send me a copy of your modified program on CPU, thank you.
I want to know If I want to run on CPU, is it ok if I just delete the.Cuda () in the code?
@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.
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.