You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
RuntimeError: Expected tensor for argument #1 'indices' to have scalar type Long; but got torch.cuda.IntTensor instead (while checking arguments for embedding)
#11
Open
Lydiasc34 opened this issue
Dec 7, 2020
· 4 comments
Hi, thank you for sharing the rcv data source and I managed to request data and preprocessed it. I used my preprocessed rcv text and its id as X_train/X_test, train_id/text_id in readData_rcv1. I chose TextCNN as base model and no pkl file exists so I started from the training.
And when processing data in load_data_rcv1, I noticed X_train = [[[word_index[word] for word in sent] for sent in doc] for doc in X_train]. So the type for X_train is list. Then the script works fine until it comes to the train_taxo() and below is the error I got.
(For the mode in config, I set it as hilap. And I use gpu to run.)
0it [00:00, ?it/s]
Traceback (most recent call last):
File "C:/Users/HiLAP/main.py", line 816, in <module>
train_taxo()
File "C:/HiLAP/main.py", line 277, in train_taxo
_, flat_probs = forward_step_sl(tokens, doc_ids, flat_probs_only=(args.global_ratio == 1))
File "C:/HiLAP/main.py", line 134, in forward_step_sl
probs = policy.base_model(tokens, True)
File "C:\Local\Continuum\anaconda3\envs\HiLAP\lib\site-packages\torch\nn\modules\module.py", line 727, in _call_impl
result = self.forward(*input, **kwargs)
File "C:\HiLAP\TextCNN.py", line 36, in forward
x = self.embed(x) # (N, W, D)
File "C:\Local\Continuum\anaconda3\envs\HiLAP\lib\site-packages\torch\nn\modules\module.py", line 727, in _call_impl
result = self.forward(*input, **kwargs)
File "C:\Local\Continuum\anaconda3\envs\HiLAP\lib\site-packages\torch\nn\modules\sparse.py", line 126, in forward
self.norm_type, self.scale_grad_by_freq, self.sparse)
File "C:\Local\Continuum\anaconda3\envs\HiLAP\lib\site-packages\torch\nn\functional.py", line 1852, in embedding
return torch.embedding(weight, input, padding_idx, scale_grad_by_freq, sparse)
RuntimeError: Expected tensor for argument #1 'indices' to have scalar type Long; but got torch.cuda.IntTensor instead (while checking arguments for embedding)
It seems like the error is about input type. So I was trying to convert the tokens input to LongTensor but it keeps getting me errors. So I would like to show you the very first error I got to see if it was indeed the issue about tersor type. I've been researching and trying solutions but they did not work.
Looking forward to your reply. Thanks!
The text was updated successfully, but these errors were encountered:
Also, even if I converted tokens to LongTensor ( and also some other variables such as mini_batch, cur_class_batch and next_classes_batch in the generate_logits function from model.py, that needs LongTensor type otherwise same error occurs), I got another error that:
0it [00:01, ?it/s]
Traceback (most recent call last):
File "C:/HiLAP/main.py", line 822, in
train_taxo()
File "C:/HiLAP/main.py", line 331, in train_taxo
finish_episode(policy, update=True)
File "C:/HiLAP/main.py", line 89, in finish_episode
entropy = torch.cat(policy.entropy_l).mean()
RuntimeError: zero-dimensional tensor (at position 0) cannot be concatenated
Have you ever had similar issues? Any thoughts would be appreciated!
I searched the first error, and the web suggested there might be some difference when running on Win and Linux. Sry I never tried on Win but I think the code should be runnable on Linux as ppl in other issues have reproduced the results.
Hi, thank you for sharing the rcv data source and I managed to request data and preprocessed it. I used my preprocessed rcv text and its id as X_train/X_test, train_id/text_id in readData_rcv1. I chose TextCNN as base model and no pkl file exists so I started from the training.
And when processing data in load_data_rcv1, I noticed
X_train = [[[word_index[word] for word in sent] for sent in doc] for doc in X_train]
. So the type for X_train is list. Then the script works fine until it comes to the train_taxo() and below is the error I got.(For the mode in config, I set it as hilap. And I use gpu to run.)
It seems like the error is about input type. So I was trying to convert the tokens input to LongTensor but it keeps getting me errors. So I would like to show you the very first error I got to see if it was indeed the issue about tersor type. I've been researching and trying solutions but they did not work.
Looking forward to your reply. Thanks!
The text was updated successfully, but these errors were encountered: