lenskit.state#

Support code for managing model state.

Many LensKit components are built on machine learning models of various forms. While lenskit.training provides support for training those models, this module provides support for managing their learned state and weights.

Classes#

ParameterContainer

Protocol for components with learned parameters to enable saving, reloading,

Package Contents#

class lenskit.state.ParameterContainer#

Bases: Protocol

Protocol for components with learned parameters to enable saving, reloading, checkpointing, etc.

Components that learn parameters from training data should implement this protocol, and also work when pickled or pickled. Pickling is sometimes used for convenience, but parameter / state dictionaries allow serializing wtih tools like safetensors or zarr.

Initializing a component with the same configuration as a trained component, and loading its parameters with load_parameters(), should result in a component that is functionally equivalent to the original trained component.

Stability:

Experimental

abstractmethod get_parameters()#

Get the component’s parameters.

Returns:

The model’s parameters, as a dictionary from names to parameter data (usually arrays, tensors, etc.).

Return type:

collections.abc.Mapping[str, object]

abstractmethod load_parameters(state)#

Reload model state from parameters saved via get_parameters().

Parameters:
Return type:

None