chenxijun1029 / DeepFM_with_PyTorch

A PyTorch implementation of DeepFM for CTR prediction problem.
379 stars 100 forks source link

RuntimeError: index out of range at /pytorch/aten/src/TH/generic/THTensorEvenMoreMath.cpp:191 #1

Open lthakur007 opened 5 years ago

lthakur007 commented 5 years ago

observing the following error while running deep ctr on the gpu:

Traceback (most recent call last): File "main.py", line 31, in model.fit(loader_train, loader_val, optimizer, epochs=5, verbose=True) File "/root/deepctr/DeepFM_with_PyTorch/model/DeepFM.py", line 153, in fit total = model(xi, xv) File "/usr/local/lib/python3.5/dist-packages/torch/nn/modules/module.py", line 489, in call result = self.forward(*input, *kwargs) File "/root/deepctr/DeepFM_with_PyTorch/model/DeepFM.py", line 98, in forward fm_first_order_emb_arr = [(torch.sum(emb(Xi[:, i, :]), 1).t() Xv[:, i]).t() for i, emb in enumerate(self.fm_first_order_embeddings)] File "/root/deepctr/DeepFM_with_PyTorch/model/DeepFM.py", line 98, in fm_first_order_emb_arr = [(torch.sum(emb(Xi[:, i, :]), 1).t() Xv[:, i]).t() for i, emb in enumerate(self.fm_first_order_embeddings)] File "/usr/local/lib/python3.5/dist-packages/torch/nn/modules/module.py", line 489, in call result = self.forward(input, **kwargs) File "/usr/local/lib/python3.5/dist-packages/torch/nn/modules/sparse.py", line 118, in forward self.norm_type, self.scale_grad_by_freq, self.sparse) File "/usr/local/lib/python3.5/dist-packages/torch/nn/functional.py", line 1454, in embedding return torch.embedding(weight, input, padding_idx, scale_grad_by_freq, sparse) RuntimeError: index out of range at /pytorch/aten/src/TH/generic/THTensorEvenMoreMath.cpp:191

cserken commented 5 years ago

hi~ anybody know how to fix this issue?

thanks!

leadtoit commented 5 years ago

the same problem~

mojirml commented 5 years ago

the same problem~

monkeyusage commented 5 years ago

the same problem~

ice16 commented 5 years ago

same problem

lewisbakkero commented 5 years ago

Same issue when using flair0.4.1, pythorch1.1.0 and BertEmbeddings on 2 x NVIDIA Tesla P100

zqs01 commented 5 years ago

the same problem

monkeyusage commented 5 years ago

the same problem~

I had an issue with the embeddings I fixed it initializing the embedding layer with the right size which is the size of the vocabulary I am using.

when creating your Encoder/Model:

self.embed = nn.Embedding(vocab_size, embed_size) I was using a smaller number than my actual vocab_size thus resulting in an error.

vinklibrary commented 5 years ago

the same problem

RyanAmaudruz commented 5 years ago

same issue

ganyuqi commented 5 years ago

hi, is anybody fix the problem?

anksng commented 5 years ago

Hi, try to inspect the size of your vocabulary , if using the vocab_size in the Embedding layer initialization, try to add +1 to it like -> self.embed = nn.Embedding(vocab_size+1, embed_size)

loretoparisi commented 5 years ago

we have the same problem using LASER bi-LSTM model with PyTorch 1.0 / Python 3.7 https://github.com/facebookresearch/LASER

shantam21 commented 5 years ago

Did anyone get the solution? I'm stuck! just wanted to confirm what vocab_size here means. Does it mean the length of the tokenized words set?

shira-g commented 5 years ago

It happened to me when I had out-of-vocabulary words which were assigned a -1 value, and also it happens when you set the vocab-size to a smaller value than the size of the vocabulary + 1

chenxijun1029 commented 5 years ago

Sorry for answering so late! I think I've fixed this bug. The main reason is that I accumulated offset when iterate feature size in data preprocess, so index of categorial feature is out of embedding size. Please refer to the update in dataPreprocess.py. Also, I've found that I should set the index of coutinous feature as 0, and the value of coutinous feature as its original value instead of 1. Refer to the update of dataset.py for more details. Thanks for your attention.

loretoparisi commented 5 years ago

@chenxijun1029 in which version this has been fixed? Thank you.

Guilherme26 commented 5 years ago

Hey guys, I had the same problem. In my case, what happened was that I was presenting the Input (X) and the Output (Y) to the model with len(X) != len(Y) due to an error in a third-party library.

Best regards and good luck!

maulberto3 commented 4 years ago

the same problem~

I had an issue with the embeddings I fixed it initializing the embedding layer with the right size which is the size of the vocabulary I am using.

when creating your Encoder/Model:

self.embed = nn.Embedding(vocab_size, embed_size) I was using a smaller number than my actual vocab_size thus resulting in an error.

Hi. I too resolved my issue by fixing what @MCSZN suggested.

tinaty commented 4 years ago

Hi, try to inspect the size of your vocabulary , if using the vocab_size in the Embedding layer initialization, try to add +1 to it like -> self.embed = nn.Embedding(vocab_size+1, embed_size)

Hi, this works. But would you mind providing an explanation for this?

anksng commented 4 years ago

Hi, try to inspect the size of your vocabulary , if using the vocab_size in the Embedding layer initialization, try to add +1 to it like -> self.embed = nn.Embedding(vocab_size+1, embed_size)

Hi, this works. But would you mind providing an explanation for this?

I guess it was a bug, which is now fixed by @chenxijun1029 . What I remember is that the error is because embedding_dim must be equal to the vocab size, but when initializing the embedding layer with len(voca_size) it somehow subtracts 1.

tinaty commented 4 years ago

Hi, try to inspect the size of your vocabulary , if using the vocab_size in the Embedding layer initialization, try to add +1 to it like -> self.embed = nn.Embedding(vocab_size+1, embed_size)

Hi, this works. But would you mind providing an explanation for this?

I guess it was a bug, which is now fixed by @chenxijun1029 . What I remember is that the error is because embedding_dim must be equal to the vocab size, but when initializing the embedding layer with len(voca_size) it somehow subtracts 1.

got it. thanks very much.

lyleshaw commented 4 years ago

same issue

lu161513 commented 4 years ago

Hi, try to inspect the size of your vocabulary , if using the vocab_size in the Embedding layer initialization, try to add +1 to it like -> self.embed = nn.Embedding(vocab_size+1, embed_size)

Why +1 will solve the problem,The initialization of embedding should not be used vocab_size rather than vocab_size+1?

onlyhebo commented 4 years ago

I have the same issue. See DeepFM_with_PyTorch/data/dataset.py Row7 : continous_features = 13. Change the value for your dataset. You can have a correct result.