BPR-pytorch icon indicating copy to clipboard operation
BPR-pytorch copied to clipboard

测试阶段(偶尔)出现IndexError: index out of range in self

Open Lulu20220 opened this issue 2 years ago • 1 comments

您好! 在我预处理数据的时候,偶尔会在测试阶段出现以下错误:

   Traceback (most recent call last):
      File , line 215, in <module>
        HR, NDCG = metrics(model, test_loader, top_k)
      File "t.py", line 174, in metrics
        prediction_i, prediction_j = model(user, item_i, item_j)
      File "anaconda3/envs/BPR/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1110, in _call_impl
        return forward_call(*input, **kwargs)
      File "/t.py", line 137, in forward
        item_i = self.embed_item(item_i)
      File "/anaconda3/envs/BPR/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1110, in _call_impl
        return forward_call(*input, **kwargs)
      File "/anaconda3/envs/BPR/lib/python3.10/site-packages/torch/nn/modules/sparse.py", line 158, in forward
        return F.embedding(
      File "/anaconda3/envs/BPR/lib/python3.10/site-packages/torch/nn/functional.py", line 2183, in embedding
        return torch.embedding(weight, input, padding_idx, scale_grad_by_freq, sparse)
    IndexError: index out of range in self

我用了同样的预处理方:假设我用原始数据前1000行,就会顺利跑;但如果我用全部数据,就会出现这个错误。实在debug不出来,想问问您知道原因吗? 我的train data都是[[1,2],[1,3],...]. test data [[1,4],[1,34]..]. (第一对是seen user item,之后的99对是从全部item 中挑 user1 没有看过的,以此类推。 感谢!

Lulu20220 avatar Apr 23 '22 06:04 Lulu20220

补充一点就是 同一个train 和 test,再跑一次也偶尔会出现这个错误

Lulu20220 avatar Apr 23 '22 07:04 Lulu20220