uma-pi1 / kge

LibKGE - A knowledge graph embedding library for reproducible research
MIT License
765 stars 124 forks source link

Error on tensor scoring #273

Open ramesesz opened 1 year ago

ramesesz commented 1 year ago

I was following the example on the tensor scoring in the readme file

import torch
from kge.model import KgeModel
from kge.util.io import load_checkpoint

checkpoint = load_checkpoint('fb15k-237-rescal.pt')
model = KgeModel.create_from(checkpoint)

s = torch.Tensor([0, 2,]).long()             # subject indexes
p = torch.Tensor([0, 1,]).long()             # relation indexes
scores = model.score_sp(s, p)                # scores of all objects for (s,p,?)
o = torch.argmax(scores, dim=-1)             # index of highest-scoring objects

print(o)
print(model.dataset.entity_strings(s))       # convert indexes to mentions
print(model.dataset.relation_strings(p))
print(model.dataset.entity_strings(o))

When running

print(model.dataset.entity_strings(s)) 
print(model.dataset.entity_strings(o))

It returns the following error Traceback (most recent call last): File "", line 1, in File "/home/ramab/workspace/kge/kge/dataset.py", line 494, in entitystrings map = self.load_map( File "/home/ramab/workspace/kge/kge/dataset.py", line 315, in load_map ids = self.load_map(ids_key, as_list=True) File "/home/ramab/workspace/kge/kge/dataset.py", line 296, in load_map self.ensure_available(key) File "/home/ramab/workspace/kge/kge/dataset.py", line 88, in ensure_available raise IOError( OSError: File /home/ramab/workspace/kge/data/fb15k-237/entity_map.del for key entity_ids could not be found

I've downloaded all the data through the bash script. Am I missing something?

rgemulla commented 1 year ago

Thanks for pointing this out. The pretrained checkpoint used an old naming scheme. For now, it suffices to copy (not rename) entity_ids.del to entity_map.del, likewise relation_ids.del to relations_map.del, in the dataset folder.

I leave this issue open until we fixed this backward compatibility issue.