predict-idlab / pyRDF2Vec

🐍 Python Implementation and Extension of RDF2Vec
https://pyrdf2vec.readthedocs.io/en/latest/
MIT License
246 stars 51 forks source link

How to burn pyRDF2Vec embeds #198

Closed STALINFIGUEROAALAVA closed 1 year ago

STALINFIGUEROAALAVA commented 1 year ago

❓ Question

Very Dear Guilles and Bram, please help me with the following query: You could save or export to a file the embeddings made with pyRDF2Vec in a wikidata knowledge graph, to later work with that file, and not be doing the embeddings again.

bsteenwi commented 1 year ago

Euhm... Sure by saving the embeddings in

embeddings, literals = transformer.fit_transform(knowledge_graph, entities)

To a file using standard python functionality... (With open(...), Pickle dump, or whatever you want to use..)

STALINFIGUEROAALAVA commented 1 year ago

Hi Bram. With the following code, I can read the pickle file and load it into an object. Before, how do I convert the embeddings file to a pickle file? Next, how would you read the embeds from the downloaded pickle file. Please. Do you have an example in python code? to see how to do it. Thank you very much Bram.

import pickle
import pprint
obj = pickle.load(open("sample_data.pickle", "rb"))
with open("out.txt", "a") as f:
     pprint.pprint(obj, stream=f)