lenskit.pipeline.Component#
- class lenskit.pipeline.Component(config=None, **kwargs)#
Bases:
ABC
,Generic
[COut
,CArgs
]Base class for pipeline component objects. Any component that is not just a function should extend this class.
Pipeline components support configuration (e.g., hyperparameters or random seeds) through Pydantic models or Python dataclasses; see Configuring Components for further details. If the pipeline’s configuration class is
C
, it has the following:The configuration is exposed through an instance variable
config
.The constructor accepts the configuration object as its first parameter, also named
config
, and saves this in the member variable.
The base class constructor handles both of these, so long as you declare the type of the
config
member:class MyComponent(Component): config: MyComponentConfig ...
If you do not declare a
config
attribute, the base class will assume the pipeline uses no configuration.To work as components, derived classes also need to implement a
__call__
method to perform their operations.- Parameters:
config (Any) – The configuration object. If
None
, the configuration class will be instantiated withkwargs
.kwargs (Any)
- Stability:
- Full (see Stability Levels).
Methods
__init__
([config])config_class
([return_any])Dump the configuration to JSON-serializable format.
validate_config
([data])Validate and return a configuration object for this component.
Attributes
The component configuration object.
- config: Any = None#
The component configuration object. Component classes that support configuration must redefine this attribute with their specific configuration class type, which can be a Python dataclass or a Pydantic model class.
- dump_config()#
Dump the configuration to JSON-serializable format.