Closed abdullahfathi closed 3 years ago
Hello @abdullahfathi ,
The index error appears to occurs in self.emb_rel_real(rel_idx))
. This implies that self.emb_rel_real(.)
received an index that is larger than initially given parameter. I would suggest you to catch this error and verify whether this assumption holds. I would expect that you would catch an index that is greater thanINFO - Number of relations:4020
.
Finally, I would suggest you to ensure the both datasets have the same formats.
I printed the length of rel_idx
by adding this before print(" rel_idx= ", len(rel_idx))
and I got this
2021-01-07 20:11:54,272 - ConEx_0_target - INFO - Loss at 5.th epoch:1.1014062364120036
2021-01-07 20:11:54,427 - ConEx_0_target - INFO - Standard Link Prediction evaluation on Testing Data
rel_idx = 1024
rel_idx = 1024
rel_idx = 1024
rel_idx = 1024
rel_idx = 1024
rel_idx = 1024
rel_idx = 1024
rel_idx = 1024
rel_idx = 1024
rel_idx = 1024
rel_idx = 1024
rel_idx = 1024
rel_idx = 1024
rel_idx = 1024
rel_idx = 1024
rel_idx = 1024
rel_idx = 1024
rel_idx = 1024
rel_idx = 1024
rel_idx = 1024
rel_idx = 1024
Traceback (most recent call last):
File "search.py", line 38, in <module>
experiment.train_and_eval()
File "/home/a/afaahmed/profiles/unix/cs/nellie/100datasetexp/Convolutional-Complex-Knowledge-Graph-Embeddings/util/experiment.py", line 195, in train_and_eval
self.evaluate_one_to_n(model, self.dataset.test_data, 'Standard Link Prediction evaluation on Testing Data')
File "/home/a/afaahmed/profiles/unix/cs/nellie/100datasetexp/Convolutional-Complex-Knowledge-Graph-Embeddings/util/experiment.py", line 97, in evaluate_one_to_n
predictions = model.forward_head_batch(e1_idx=e1_idx, rel_idx=r_idx)
File "/home/a/afaahmed/profiles/unix/cs/nellie/100datasetexp/Convolutional-Complex-Knowledge-Graph-Embeddings/models/complex_models.py", line 136, in forward_head_batch
emb_rel_real = self.bn_rel_real(self.emb_rel_real(rel_idx))
File "/upb/users/a/afaahmed/profiles/unix/cs/miniconda3/envs/quat/lib/python3.6/site-packages/torch/nn/modules/module.py", line 550, in __call__
result = self.forward(*input, **kwargs)
File "/upb/users/a/afaahmed/profiles/unix/cs/miniconda3/envs/quat/lib/python3.6/site-packages/torch/nn/modules/sparse.py", line 114, in forward
self.norm_type, self.scale_grad_by_freq, self.sparse)
File "/upb/users/a/afaahmed/profiles/unix/cs/miniconda3/envs/quat/lib/python3.6/site-packages/torch/nn/functional.py", line 1724, in embedding
return torch.embedding(weight, input, padding_idx, scale_grad_by_freq, sparse)
IndexError: index out of range in self
Please note that the size of relation INFO - Number of relations:2054
I hope I am doing that correctly. Thanks
rel_idx
is a tensor holding the indexes of relations in the current mini-batch. Consequently, the length of rel_idx
must be indeed 1024
since the batch size was set to 1024
(see the text above HyperParameter Settings:{'batch_size': 1024, ...
).
As stated in my previous message, you need to find the index of the relation causing the IndexError.
I would suggest you the following steps:
self.entity_idxs = {self.dataset.entities[i]: i for i in range(len(self.dataset.entities))}
self.relation_idxs = {self.dataset.relations[i]: i for i in range(len(self.dataset.relations))}
self.kwargs.update({'num_entities': len(self.entity_idxs),'num_relations': len(self.relation_idxs)})
...
ConEx(self.kwargs)
self.num_entities = params['num_entities']
self.num_relations = params['num_relations']
...
self.emb_rel_real = nn.Embedding(self.param['num_relations'], self.embedding_dim) # real
...
I would assume that the index error stems from the fact that rel_idx
contains a value that is greater than self.param['num_relations']
.
Hello, I am using your model and it works fine on a dataset but when I wnat to try it on another dataset, I got this error
Any idea? Thanks