theeluwin / pytorch-sgns

Skipgram Negative Sampling implemented in PyTorch
MIT License
302 stars 59 forks source link

An error occurred when testing the repo #3

Closed DexterZeng closed 6 years ago

DexterZeng commented 6 years ago

Hi Thank you for sharing the code. However, when I tried to test the repo with "python preprocess.py" and " python train.py --weights --cuda", the first one worked well and generated processed data, whereas the second reported the error as follows:

[Epoch 1]: 0%| | 0/1 [00:00<?, ?it/s]Traceback (most recent call last): File "train.py", line 93, in train(parse_args()) File "train.py", line 81, in train loss = sgns(iword, owords) File "/home/weixin/anaconda2/envs/p3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 325, in call result = self.forward(*input, *kwargs) File "/home/weixin/Downloads/pytorch-sgns-master/model.py", line 70, in forward ivectors = self.embedding.forward_i(iword).unsqueeze(2) File "/home/weixin/Downloads/pytorch-sgns-master/model.py", line 42, in forward_i return self.ivectors(v) File "/home/weixin/anaconda2/envs/p3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 325, in call result = self.forward(input, **kwargs) File "/home/weixin/anaconda2/envs/p3/lib/python3.6/site-packages/torch/nn/modules/sparse.py", line 103, in forward self.scale_grad_by_freq, self.sparse RuntimeError: save_for_backward can only save input or output tensors, but argument 0 doesn't satisfy this condition

I am quite new to Pytorch so any idea what might go wrong? Many thanks.

theeluwin commented 6 years ago

Can you offer your pytorch version? It seems that the error here looks similar to https://discuss.pytorch.org/t/why-i-cant-use-torch-index-select-in-forward-function/8010

DexterZeng commented 6 years ago

Hi, thanks for the reply. The pytorch version is 0.3.0.post4. The error does look similar to the post. Should I wrap the Tensors in the Variables? Many thanks.

theeluwin commented 6 years ago

Yes, you should wrap tensors with Variable properly. I removed all Variable because it was removed in 0.4.0 (see https://pytorch.org/2018/04/22/0_4_0-migration-guide.html).

DexterZeng commented 6 years ago

Many thanks for your feedback. I will try it later.