lir.config.transform module
- class lir.config.transform.GenericTransformerConfigParser(component_class: object)[source]
Bases:
ConfigParserParser class to help parse the defined component into its corresponding Transformer object.
Since the scikit-learn Pipeline expects a fit() and transform() method on each of the pipeline steps, the configured components should adhere to this contract and implement these methods.
The parse() function offered in this helper class, implements a branching strategy to determine which strategy is best suited to make the component compatible with the scikit-learn pipeline.
- Parameters:
component_class (object) – Component class or callable to adapt to the transformer interface.
- parse(config: ContextAwareDict, output_dir: Path) Transformer[source]
Prepare a configured component for use in a scikit-learn pipeline.
- Parameters:
config (ContextAwareDict) – Constructor arguments for the component class.
output_dir (Path) – Unused output directory argument required by parser API.
- Returns:
Component adapted to the
Transformerinterface.- Return type:
- class lir.config.transform.NumpyWrappingConfigParser(module_parser: ConfigParser)[source]
Bases:
ConfigParserWrap a Transformer to add a header to FeatureData.
- Parameters:
module_parser (ConfigParser) – Parser used to create the wrapped transformer.
- parse(config: ContextAwareDict, output_dir: Path) Transformer[source]
Parse the provided header configuration.
- Parameters:
config (ContextAwareDict) – Configuration possibly containing
headerand module fields.output_dir (Path) – Output directory passed to the wrapped parser.
- Returns:
Wrapped transformer that preserves numpy headers.
- Return type:
- lir.config.transform.parse_module(module_config: ContextAwareDict | str | None, output_dir: Path, config_context_path: list[str], default_method: str | None = None) Transformer[source]
Construct a
Transformerfrom a string or configuration section.If
module_configisNone, anIdentitytransformer is returned.If
module_configis a dictionary, it must contain amethodfield whose value is the name of an object looked up in the registry. All remaining fields are passed as initialisation arguments. If no arguments are required, the input may be given directly as the object name.The resolved object is handled as follows:
If it is a subclass of
ConfigParser, the class is instantiated and the result of itsparse()method is returned.If it defines a
transformmethod, or is a subclass ofTransformer, it is instantiated and returned.If it defines a
predict_probamethod, it is instantiated, wrapped inEstimatorTransformer, and returned.Any other callable is wrapped in
FunctionTransformerand returned.
If
module_configis a string, this function behaves as if a dictionary with a single fieldmethodset to that string had been provided.- Parameters:
module_config (ContextAwareDict | str | None) – Specification of the module.
output_dir (Path) – Directory where any output produced by the module is written.
config_context_path (list[str]) – Context path of this configuration, used for error reporting.
default_method (str | None, optional) – Default value for the
methodfield if it is not provided.
- Returns:
The constructed transformer instance.
- Return type: