lenskit.pipeline.TrainableComponent#

class lenskit.pipeline.TrainableComponent(*args, **kwargs)#

Bases: Generic[COut], Protocol

Interface for pipeline components that can learn parameters from training data, and expose those parameters for serialization as an alternative to pickling (components also need to be picklable).

Note

Trainable components must also implement __call__.

__init__(*args, **kwargs)#

Methods

__init__(*args, **kwargs)

get_params()

Get the model's learned parameters for serialization.

load_params(params)

Reload model state from parameters saved via get_params().

train(data)

Train the pipeline component to learn its parameters from a training dataset.

train(data)#

Train the pipeline component to learn its parameters from a training dataset.

Parameters:

data (Dataset) – The training dataset.

Returns:

The component.

Return type:

Self

get_params()#

Get the model’s learned parameters for serialization.

LensKit components that learn parameters from training data should both implement this method and work when pickled and unpickled. Pickling is sometimes used for convenience, but parameter / state dictionaries allow serializing wtih tools like safetensors.

Parameters:

include_caches – Whether the parameter dictionary should include ephemeral caching structures only used for runtime performance optimizations.

Returns:

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

Return type:

dict[str, object]

load_params(params)#

Reload model state from parameters saved via get_params().

Parameters:

params (dict[str, object])

Return type:

None