SpringerNLP / Chapter10

Chapter 10: Multi-task Learning
7 stars 3 forks source link

IndexError: too many indices for array #1

Open antgr opened 5 years ago

antgr commented 5 years ago

I run the code on colab. Here is the notebook: https://colab.research.google.com/drive/1bmTNr6UxN_PL5MTn4bgTVFaRWdgEHGgb

!echo "Joint Training on the different level" !python main.py --data './data' --emsize 256 --npos_layers 1 --nchunk_layers 2 --nhid 128 --batch_size 128 --seq_len 10 --cuda --train_mode 'Joint' --epochs 300 --log_interval 20 --save './result/joint_diff'

Joint Training on the different level Loading corpus... Begin training... main.py:108: UserWarning: torch.nn.utils.clip_grad_norm is now deprecated in favor of torch.nn.utils.clip_gradnorm. torch.nn.utils.clip_grad_norm(model.parameters(), args.clip) Traceback (most recent call last): File "main.py", line 200, in loss_log = train(loss_log) File "main.py", line 114, in train cur_loss = cur_loss.cpu().numpy()[0] IndexError: too many indices for array

antgr commented 5 years ago

I know what is the problem. I will come back with a PR.

vivien000 commented 5 years ago

I faced the same problem. @antgr, could you please tell us more about the bug you identified? Many thanks

antgr commented 5 years ago

Hi, @vivien000 , you can run my code. I fixed all the bugs. https://github.com/antgr/nlp_multi_task_learning_pytorch For example in the above issue the fix is: cur_loss = cur_loss.cpu().numpy() (remove the [0])

(I pushed all my fixes in the repo from where I forked. This repo was broken as well. This probably has to do with pytorch version. Or else I do not know how the code was running in the past. I think that the code that is used in the book is from that fork. Keep in mind that now my code has one extra feature: skip connections, so I would recommend use my code)