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:
- 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:
- lir.config.transform.parse_pairing_config(module_config: ContextAwareDict | str, output_dir: Path, context: list[str]) PairingMethod[source]
Parse and delegate pairing to the corresponding function for the defined pairing method.
The argument module_config defines the pairing method. If its value is a str, the registry is queried and the corresponding pairing method is returned. If its value is a dict, the pairing method is defined by the value module_config[“method”], and the registry is queried for the config parser of the corresponding pairing method. The remaining values in module_config are passed as arguments to the configuration parser of the pairing method.
If the registry cannot resolve the pairing method, an exception is raised.
- Parameters:
module_config (ContextAwareDict | str) – Pairing method configuration.
output_dir (Path) – Output directory for parser calls.
context (list[str]) – Context used when
module_configis a string.
- Returns:
Parsed pairing method.
- Return type: