Save/load models#

Models can be saved and loaded from bytes. Standard Python APIs can be used to read and write the serialized bytes to/from a file.

To save a model, use the vowpal_wabbit_next.Workspace.serialize() method. To load a model, use the model_data argument in the vowpal_wabbit_next.Workspace constructor.

import vowpal_wabbit_next as vw

workspace = vw.Workspace()

text_parser = vw.TextFormatParser(workspace)

workspace.learn_one(text_parser.parse_line("1 | a b c"))
workspace.learn_one(text_parser.parse_line("1 | b c d"))
workspace.learn_one(text_parser.parse_line("0.5 | a c"))

serialized_workspace = workspace.serialize()

loaded_workspace = vw.Workspace(model_data=serialized_workspace)
text_parser2 = vw.TextFormatParser(loaded_workspace)

print(workspace.predict_one(text_parser.parse_line("| a:0.7 c:0.6")))
print(loaded_workspace.predict_one(text_parser2.parse_line("| a:0.7 c:0.6")))
0.43031615018844604
0.43031615018844604