Saltar al contenido principal

PrepareExplanationDataUnit

Unit
DashAI.back.units.PrepareExplanationDataUnit

Rebuild the exact train/test/val split the run was trained on.

Deliberately not PrepareAndSplitUnit: that one computes a split from a ratio configuration, which would hand the explainer different rows than the model ever saw. This one replays the row indexes the run recorded, so the explanation is about the model that exists.

Those indexes are positions in the dataset the task prepared, because that is what training partitioned, and a task may reorder the rows (forecasting sorts them by date). So the loaded dataset is prepared first, with the columns training prepared with, and cut once afterwards. Cutting first and preparing the parts was doubly wrong: it read the loaded order, and the task merges a dict of parts back in alphabetical order of their names, so the second cut handed each partition rows of the others.

Features stay unprepared — models apply their own preprocessing inside predict, and preparing beforehand would break the ones that replace their input columns with derived features — while targets are encoded, because explainers compare them against the model's class indexes.

Session preprocessing is another matter: converters the session fitted ahead of training (PreprocessingJob) are not part of the model, and the input columns the session records are the names they produced. Such a session supplies preprocessing_artifacts_path and input_column_refs together. The task is then prepared with the raw refs, as training did, since the converters' outputs do not exist yet; the run's split is cut from the prepared rows and the persisted final.pkl is applied to each part, so the explainer's data is in the feature space the model was trained on. Cutting before transforming keeps the run's indexes valid when a step removes rows (NanRemover), and no part is resampled, so no synthetic rows get in. The transformed dataset stays local to this unit: dataset in the context is left as it was loaded, since nothing downstream reads it and a unit that rewrote a key it requires would blur what it consumes and what it produces.

Parameters​

task_name : string, default=TabularClassificationTask
Name of the task the dataset is prepared for.
input_columns : array, default=[]
Names of the columns used as model input.
output_columns : array, default=[]
Names of the columns the model predicts.
input_column_refs, default=None
Column references the model reads when the session ran a preprocessing sequence: {'kind': 'raw', 'name': ...} for a column of the dataset, {'kind': 'group', 'step': n} for what converter step n produces. Set together with the artifacts path, or not at all.

Methods​

execute(self, ctx: DashAI.back.units.context.ExecutionContext) -> None

Defined on PrepareExplanationDataUnit

Do the unit's work, reading from and writing to the context.

Parameters

ctx : ExecutionContext
The shared execution context.

validate(self, ctx: DashAI.back.units.context.ExecutionContext) -> None

Defined on PrepareExplanationDataUnit

Resolve the task before anything observable happens.

get_credential(self, name: str)

Defined on ConfigObject

Resolve a registered credential component by name.

Parameters

name : str
Credential component class name (e.g. "HuggingFaceCredential").

Returns

BaseCredential
An instance of the requested credential component.

get_schema(cls) -> dict

Defined on ConfigObject

Generates the component related Json Schema.

Returns

dict
Dictionary representing the Json Schema of the component.

validate_and_transform(self, raw_data: dict) -> dict

Defined on ConfigObject

It takes the data given by the user to initialize the model and returns it with all the objects that the model needs to work.

Parameters

raw_data : dict
A dictionary with the data provided by the user to initialize the model.

Returns

dict
A validated dictionary with the necessary objects.