INK-USC / RE-Net

Recurrent Event Network: Autoregressive Structure Inference over Temporal Knowledge Graphs (EMNLP 2020)
http://inklab.usc.edu/renet/
435 stars 95 forks source link

IndexError: tensors used as indices must be long, byte or bool tensors #29

Closed Bryan2Chow closed 4 years ago

Bryan2Chow commented 4 years ago

Hi, Thanks for your nice work!

Traceback (most recent call last): File "train.py", line 241, in train(args) File "train.py", line 136, in train loss_s = model(batch_data, (s_hist, s_hist_t), (o_hist, o_hist_t), graph_dict, subject=True) File "C:\ProgramData\Anaconda3\lib\site-packages\torch\nn\modules\module.py", line 532, in call result = self.forward(*input, **kwargs) File "F:\RE-Net-master\model.py", line 90, in forward self.dropout(torch.cat((self.ent_embeds[s[s_idx]], s_h, rel_embeds[r[s_idx]]), dim=1))) IndexError: tensors used as indices must be long, byte or bool tensors

My environment is Python 3.6.3. Windows 10. Pytorch 1.4.0.
Besides, I changed to another environment called Pytorch 0.4.0 Both of them all got the same error.

I am very pleased to hear from you on the question's comments.

woojeongjin commented 4 years ago

Hi! Thanks for your interest. In my environment, I have no issue. Pytorch is 1.4.0. CUDA is 10.1. Anyway, I have updated the train.py so that the batch should be LongTensor. If you have an issue again, please let me know!

Bryan2Chow commented 4 years ago

Thanks a lot! Thumbs-up! It works!

Bryan2Chow commented 4 years ago

Hi, Jin

Sorry to bother you again. I don’t know if it is a good time to ask you for help.

It works well on #29. Unfortunately, I got another problem as follows.

I have tried to run the train.py several times on different environments(Win10, GTX1660Ti, Pytorch 1.4.0; GTX2060Super, Pytorch 1.5.0).

I got the same error as follows.

On Win10, GTX1660Ti, Pytorch 1.4.0

F:\RE-Net-master\RE-Net-master>python train.py -d ICEWS18 --gpu 0 --dropout 0.5 --n-hidden 200 --lr 1e-3 --max-epochs 20 --batch-size 612 Namespace(backup=False, batch_size=612, dataset='ICEWS18', dropout=0.5, gpu=0, grad_norm=1.0, lr=0.001, max_epochs=20, maxpool=1, model=0, n_hidden=200, num_k=1000, raw=False, rnn_layers=1, seq_len=10, valid=False, valid_every=1) start training... Epoch 0001 | Loss 13.5864 | time 4689.0738 Epoch 0002 | Loss 11.2268 | time 4662.5388 Epoch 0003 | Loss 10.4561 | time 4701.4585 Epoch 0004 | Loss 10.0074 | time 4678.1132 Epoch 0005 | Loss 9.7030 | time 4654.4500 Epoch 0006 | Loss 9.4716 | time 4700.5059 Epoch 0007 | Loss 9.2895 | time 4825.0436 Epoch 0008 | Loss 9.1377 | time 4836.3495 Epoch 0009 | Loss 9.0149 | time 4813.6240 Epoch 0010 | Loss 8.9143 | time 4709.8022 Traceback (most recent call last): File "train.py", line 241, in train(args) File "train.py", line 172, in train ranks, loss = model.evaluate_filter(batch_data, (s_hist, s_hist_t), (o_hist, o_hist_t), global_model, total_data) File "F:\RE-Net-master\RE-Net-master\model.py", line 387, in evaluate_filter loss, sub_pred, ob_pred = self.predict(triplet, s_hist, o_hist, global_model) File "F:\RE-Net-master\RE-Net-master\model.py", line 357, in predict loss_sub = self.criterion(ob_pred.view(1, -1), o.view(-1)) File "C:\ProgramData\Anaconda3\lib\site-packages\torch\nn\modules\module.py", line 532, in call result = self.forward(*input, **kwargs) File "C:\ProgramData\Anaconda3\lib\site-packages\torch\nn\modules\loss.py", line 916, in forward ignore_index=self.ignore_index, reduction=self.reduction) File "C:\ProgramData\Anaconda3\lib\site-packages\torch\nn\functional.py", line 2021, in cross_entropy return nll_loss(log_softmax(input, 1), target, weight, None, ignore_index, None, reduction) File "C:\ProgramData\Anaconda3\lib\site-packages\torch\nn\functional.py", line 1838, in nll_loss ret = torch._C._nn.nll_loss(input, target, weight, _Reduction.get_enum(reduction), ignore_index) RuntimeError: Expected object of scalar type Long but got scalar type Int for argument #2 'target' in call to _thnn_nll_loss_forward

On Win10, GTX2060Super, Pytorch 1.5.0

Epoch 0001 | Loss 14.1012 | time 3442.2008 Epoch 0002 | Loss 11.6059 | time 3389.5754 Epoch 0003 | Loss 10.7389 | time 3392.1087 Epoch 0004 | Loss 10.2516 | time 3445.8607 Epoch 0005 | Loss 9.9192 | time 3457.0420 Epoch 0006 | Loss 9.6717 | time 3470.7660 Epoch 0007 | Loss 9.4748 | time 3465.5875 Epoch 0008 | Loss 9.3085 | time 3458.9042 Epoch 0009 | Loss 9.1718 | time 3460.7169 Epoch 0010 | Loss 9.0509 | time 3479.4802 Traceback (most recent call last): File "train.py", line 241, in train(args) File "train.py", line 172, in train ranks, loss = model.evaluate_filter(batch_data, (s_hist, s_hist_t), (o_hist, o_hist_t), global_model, total_data) File "E:\Users\RE-Net-master\model.py", line 387, in evaluate_filter loss, sub_pred, ob_pred = self.predict(triplet, s_hist, o_hist, global_model) File "E:\Users\RE-Net-master\model.py", line 357, in predict loss_sub = self.criterion(ob_pred.view(1, -1), o.view(-1)) File "D:\LearningApp\Anaconda3\lib\site-packages\torch\nn\modules\module.py", line 550, in call result = self.forward(*input, **kwargs) File "D:\LearningApp\Anaconda3\lib\site-packages\torch\nn\modules\loss.py", line 932, in forward ignore_index=self.ignore_index, reduction=self.reduction) File "D:\LearningApp\Anaconda3\lib\site-packages\torch\nn\functional.py", line 2317, in cross_entropy return nll_loss(log_softmax(input, 1), target, weight, None, ignore_index, None, reduction) File "D:\LearningApp\Anaconda3\lib\site-packages\torch\nn\functional.py", line 2115, in nll_loss ret = torch._C._nn.nll_loss(input, target, weight, _Reduction.get_enum(reduction), ignore_index) RuntimeError: Expected object of scalar type Long but got scalar type Int for argument #2 'target' in call to _thnn_nll_loss_forward

I have tried to solve the problem, but it still doesn’t work.

I would greatly appreciate it if you could please take a moment to help me with this issue!

Sincerely