save_model

ampligraph.latent_features.save_model(model, loc)

Save a trained model to disk.

Examples

>>> import numpy as np
>>> from ampligraph.latent_features import ComplEx, save_model, restore_model
>>> X = np.array([['a', 'y', 'b'],
>>>               ['b', 'y', 'a'],
>>>               ['a', 'y', 'c'],
>>>               ['c', 'y', 'a'],
>>>               ['a', 'y', 'd'],
>>>               ['c', 'y', 'd'],
>>>               ['b', 'y', 'c'],
>>>               ['f', 'y', 'e']])
>>> model.fit(X)
>>> y_pred_before = model.predict(np.array([['f', 'y', 'e'], ['b', 'y', 'd']]))
>>> EXAMPLE_LOC = 'saved_models'
>>> save_model(model, EXAMPLE_LOC)
>>> print(y_pred_before)
[1.261404, -1.324778]
Parameters:
  • model (EmbeddingModel) – A trained neural knowledge graph embedding model, the model must be an instance of TransE, DistMult, ComplEx, or HolE.
  • loc (string) – Directory where the model will be saved.