save_model¶
- ampligraph.utils.save_model(model, model_name_path=None, protocol=5)¶
Save a trained model to disk.
Example
>>> import numpy as np >>> from ampligraph.latent_features import ComplEx >>> from ampligraph.utils import save_model >>> model = ComplEx(batches_count=2, seed=555, epochs=20, k=10) >>> 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_name = 'helloworld.pkl' >>> save_model(model, model_name_path=example_name) >>> print(y_pred_before) [-0.29721245, 0.07865551]
- Parameters:
model (EmbeddingModel) – A trained neural knowledge graph embedding model. The model must be an instance of TransE, DistMult, ComplEx, or HolE.
model_name_path (str) – The name of the model to be saved. If not specified, a default name with current datetime is selected and the model is saved to the working directory.