poprox_recommender.lkpipeline.components#

Definition of the component interfaces.

Functions

instantiate_component(comp, config)

Classes

Component(*args, **kwargs)

Base class for pipeline component objects.

Configurable(*args, **kwargs)

Interface for configurable objects such as pipeline components with settings or hyperparameters.

class poprox_recommender.lkpipeline.components.Configurable(*args, **kwargs)#

Bases: Protocol

Interface for configurable objects such as pipeline components with settings or hyperparameters. A configurable object supports two operations:

  • saving its configuration with get_config().

  • creating a new instance from a saved configuration with the class method from_config().

An object must implement both of these methods to be considered configurable. Components extending the Component class automatically have working versions of these methods if they define their constructor parameters and fields appropriately.

Note

Configuration data should be JSON-compatible (strings, numbers, etc.).

classmethod from_config(cfg)#

Reinstantiate this component from configuration values.

Parameters:

cfg (dict[str, Any])

Return type:

Self

get_config()#

Get this component’s configured hyperparameters.

Return type:

dict[str, object]

class poprox_recommender.lkpipeline.components.Component(*args, **kwargs)#

Bases: Configurable, Generic[COut]

Base class for pipeline component objects. Any component that is not just a function should extend this class.

Components are Configurable. The base class provides default implementations of get_config() and from_config() that inspect the constructor arguments and instance variables to automatically provide configuration support. By default, all constructor parameters will be considered configuration parameters, and their values will be read from instance variables of the same name. Components can also define EXTRA_CONFIG_FIELDS and IGNORED_CONFIG_FIELDS class variables to modify this behavior. Missing attributes are silently ignored.

To work as components, derived classes also need to implement a __call__ method to perform their operations.

EXTRA_CONFIG_FIELDS: ClassVar[list[str]] = []#

Names of instance variables that should be included in the configuration dictionary even though they do not correspond to named constructor arguments.

Note

This is rarely needed, and usually needs to be coupled with **kwargs in the constructor to make the resulting objects constructible.

IGNORED_CONFIG_FIELDS: ClassVar[list[str]] = []#

Names of constructor parameters that should be excluded from the configuration dictionary.

get_config()#

Get the configuration by inspecting the constructor and instance variables.

Return type:

dict[str, object]

classmethod from_config(cfg)#

Create a class from the specified construction. Configuration elements are passed to the constructor as keywrod arguments.

Parameters:

cfg (dict[str, Any])

Return type:

Self