-
Notifications
You must be signed in to change notification settings - Fork 15
Description
I received the following error during training and predicting based on the Games dataset.
'''
start training: 2022-04-25 23:07:12.871280
Iter 400, loss 9.3309 2022-04-25 23:17:20.633740
Iter 800, loss 9.1787 2022-04-25 23:27:15.086462
Epoch 0, loss 9.1725 =============================================
start predicting: 2022-04-25 23:27:29.583910
KeyError Traceback (most recent call last)
/content/drive/MyDrive/TCSS556/DGSR-master/new_main.py in ()
145 all_loss = []
146 with torch.no_grad():
--> 147 for user, batch_graph, label, last_item, neg_tar in test_data:
148 iter+=1
149 score, top = model(batch_graph.to(device), user.to(device), last_item.to(device), neg_tar=torch.cat([label.unsqueeze(1), neg_tar],-1).to(device), is_training=False)
3 frames
/usr/local/lib/python3.7/dist-packages/torch/_utils.py in reraise(self)
455 # instantiate since we don't know how to
456 raise RuntimeError(msg) from None
--> 457 raise exception
458
459
KeyError: Caught KeyError in DataLoader worker process 0.
Original Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/pandas/core/indexes/base.py", line 3361, in get_loc
return self._engine.get_loc(casted_key)
File "pandas/_libs/index.pyx", line 76, in pandas._libs.index.IndexEngine.get_loc
File "pandas/_libs/index_class_helper.pxi", line 105, in pandas._libs.index.Int64Engine._check_type
File "pandas/_libs/index_class_helper.pxi", line 105, in pandas._libs.index.Int64Engine._check_type
KeyError: tensor([0])
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/torch/utils/data/_utils/worker.py", line 287, in _worker_loop
data = fetcher.fetch(index)
File "/usr/local/lib/python3.7/dist-packages/torch/utils/data/_utils/fetch.py", line 52, in fetch
return self.collate_fn(data)
File "/content/drive/MyDrive/TCSS556/DGSR-master/new_main.py", line 92, in
test_data = DataLoader(dataset=test_set, batch_size=opt.batchSize, collate_fn=lambda x: collate_test(x, data_neg), pin_memory=True, num_workers=8)
File "/content/drive/MyDrive/TCSS556/DGSR-master/DGSR.py", line 341, in collate_test
return torch.tensor(user).long(), dgl.batch(graph), torch.tensor(label).long(), torch.tensor(last_item).long(), torch.Tensor(neg_generate(user, user_neg)).long()
File "/content/drive/MyDrive/TCSS556/DGSR-master/DGSR.py", line 326, in neg_generate
neg[i] = np.random.choice(data_neg[u], neg_num, replace=False)
File "/usr/local/lib/python3.7/dist-packages/pandas/core/series.py", line 942, in getitem
return self._get_value(key)
File "/usr/local/lib/python3.7/dist-packages/pandas/core/series.py", line 1051, in _get_value
loc = self.index.get_loc(label)
File "/usr/local/lib/python3.7/dist-packages/pandas/core/indexes/base.py", line 3363, in get_loc
raise KeyError(key) from err
KeyError: tensor([0])
'''
Here is all the steps I did to produce this error. I ran the code in google colab.
'''
%run new_data.py --data=Games --job=10 --item_max_length=50 --user_max_length=50 --k_hop=2
%run generate_neg.py
%run new_main.py --data=Games
--gpu=0
--epoch=20
--hidden_size=50
--batchSize=50
--user_long=orgat
--user_short=att
--item_long=orgat
--item_short=att
--user_update=rnn
--item_update=rnn
--lr=0.001
--l2=0.0001
--layer_num=2
--item_max_length=50
--user_max_length=50
--attn_drop=0.3
--feat_drop=0.3
--record \