保存模型

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

将模型保存到文件中。

Parameters:
  • model (Model) – 要保存的模型

  • 文件 (Path | str | BinaryIO) – 要保存到的文件,可以是路径,也可以是二进制文件类对象

Return type:

示例:

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)