Git Product home page Git Product logo

Comments (4)

mali-git avatar mali-git commented on May 29, 2024 1

Hi,
you can load a trained model as follows (https://pytorch.org/tutorials/beginner/saving_loading_models.html):

import torch
path = 'path/to/trained_model.pkl'
model = torch.load(path)
model.eval()

Here we provide a tutorial of how to introspect a trained model and how to make predictions.

We provide further functions to make predictions, e.g., predict_scores(), predict_scores_all_tails(), and predict_scores_all_heads() which are defined in the base model class. However, these functions require that the entities and relations are already mapped to their unique ids (https://pykeen.readthedocs.io/en/latest/tutorial/performance.html#entity-and-relation-ids).
Entities and relations in triples can be mapped to their unique ids as follows:

import numpy as np
# Here, we assume that we trained the model on the 'Nations' dataset
triples = np.array([['brazil','conferences','china']])
mapped_triples = model.triples_factory.map_triples_to_id(triples=triples)

You then can, for instance, use the function predict_scores() to make predictions:

model.predict_scores(triples=mapped_triples)

If you want to map entities/relations individually, you can make use of the internal mappings model.triples_factory.entity_to_id and model.triples_factory.relation_to_id.

from pykeen.

mali-git avatar mali-git commented on May 29, 2024

A further example of how to make predictions can be found here.

from pykeen.

cthoyt avatar cthoyt commented on May 29, 2024

A further example of how to make predictions can be found here.

I would definitely suggest using the models from the tutorial from Mehdi's second post. If you're very comfortable with PyTorch, you might consider going into the guts he described in his first post.

from pykeen.

Woooooody avatar Woooooody commented on May 29, 2024

Thank you so much, great work :)

from pykeen.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.