dice-group / dice-embeddings

Hardware-agnostic Framework for Large-scale Knowledge Graph Embeddings
MIT License
48 stars 13 forks source link

Problem with relation embedding #44

Closed umairq closed 2 years ago

umairq commented 2 years ago

Hi Demir, After loading the pretrained embedding, I get the entity embedding without any problem. However, when I try to get the relation embedding there is an error. Can you please fix. works fine -> pre_trained_kge.get_entity_embeddings([entity]) error -> pre_trained_kge.get_relation_embeddings([relation])

following is the error:

 File "/home/umair/Documents/pythonProjects/dice-embeddings/get_embeddings_from_py_model.py", line 180, in main
    testt = pre_trained_kge.get_relation_embeddings([rel])
  File "/home/umair/Documents/pythonProjects/dice-embeddings/core/abstracts.py", line 261, in get_relation_embeddings
    return self.model.relation_to_idx(torch.LongTensor(self.relation_to_idx.loc[uri]['relation'].values))
  File "/home/umair/anaconda3/envs/dice/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1207, in __getattr__
    raise AttributeError("'{}' object has no attribute '{}'".format(
AttributeError: 'ConEx' object has no attribute 'relation_to_idx

Thanks a lot in advance.

umairq commented 2 years ago

I actually found the issue in your code myself. Please update this line https://github.com/dice-group/dice-embeddings/blob/e729c9027346e933a8fe0ae00faac5d7fad16640/core/abstracts.py#L258 with the following code: return self.model.relation_embeddings(torch.LongTensor(self.relation_to_idx.loc[uri]['relation'].values)) thanks