Closed Demirrr closed 4 years ago
Hmm, python -c "from kge.model import KgeModel"
works for me. @Demirrr Can you post the full stack trace? @AdrianKs Can you reproduce this error?
I also cannot reproduce it. @Demirrr what is your python version?
Thank you for prompt answers. The ImportError appears to stem from the old python version (3.6.4). By following below commands, everything went smoothly.
conda create -n tempkg python=3.7
conda activate tempkg
git clone https://github.com/uma-pi1/kge.git
cd kge
pip install -e .
# download and preprocess datasets
cd data
sh download_all.sh
cd ..
kge start examples/toy-complex-train.yaml --job.device cpu
cd ..
python -c "import kge"
python -c "from kge.util.io import load_checkpoint"
python -c "from kge.util.io import load_checkpoint"
python -c "from kge.model import KgeModel"
I am interested in reusing pre-trained models to analyse scores that are assigned by pre-trained models, for any given, (e_i,r_j,e_j) where e_i,_e_j \in Entities and r_j \in Relations. Consequently, I would like to know whether it is possible to provide string representations of entities and relations into models and generate scores. If not, I reckon the easiest solution would be parsing ids.del files locating in data folder.
While playing with the interface, I stumble upon following outputs
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
model.dataset.entity_ids(0) => '/m/027rn'
model.dataset.entity_strings(0) => ''Dominican Republic''
Thank you for the great work and fostering reproducible research.
'/m/027rn' looks like an ID from the Freebase dumps used to make FB15K and FB15K-237.
On Sat, 3 Oct 2020, 09:27 Caglar Demir, notifications@github.com wrote:
I am interested in reusing pre-trained models to analyse scores that are assigned by pre-trained models, for any given, (e_i,r_j,e_j) where e_i,_e_j \in Entities and r_j \in Relations. Consequently, I would like to know whether it is possible to provide string representations of entities and relations into models and generate scores. If not, I reckon the easiest solution would be parsing ids.del files locating in data folder.
While playing with the interface, I stumble upon following outputs
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
model.dataset.entity_ids(0) => '/m/027rn' model.dataset.entity_strings(0) => ''Dominican Republic''
If not mistaken, '/m/027rn' does not occur in fb15k-237 but wn18rr.
Thank you for the great work and fostering reproducible research.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/uma-pi1/kge/issues/150#issuecomment-703061092, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABEWXZF7NHREIV5B6DLTW63SI3G63ANCNFSM4SB2UNHA .
We currently do not support directly to go from strings to ids. See #130 for details.
Closing since setup.py does state that Python 3.7 is required.
The above code works as expectedly. However, unfortunately,
python -c "from kge.model import KgeModel"
does not work due to ImportError: cannot import name 'KgeModel' from partially initialized module 'kge.model' (most likely due to a circular import) (/home/demir/Desktop/KGE_models/kge/kge/model/init.py)