save_model

save_model(model: Model, file: Path | str | BinaryIO) None[source]

Save a model to a file.

Parameters:
  • model (Model) – the model to save

  • file (Path | str | BinaryIO) – the file to save to, either as a path, or a binary file-like object

Return type:

None

Example:

from pykeen.pipeline import pipeline
from pykeen.checkpoints import save_model, load_state_torch

result = pipeline(dataset="nations", model="tucker")

# save model's weights to a file
save_model(result.model, "/tmp/tucker.pt")
# load weights again
state_dict = load_state_torch("/tmp/tucket.pt")
# update the model
result.model.load_state_dict(state_dict)