Skip to content

Add 10 new explainers and model specific explainability mixins#768

Draft
Irozuku wants to merge 6 commits into
feat/explainer-model-compatibilityfrom
feat/more-explainers
Draft

Add 10 new explainers and model specific explainability mixins#768
Irozuku wants to merge 6 commits into
feat/explainer-model-compatibilityfrom
feat/more-explainers

Conversation

@Irozuku

@Irozuku Irozuku commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

Summary

Grows the explainer catalog from 3 to 13, giving image classification, text classification, and regression their first explainers. Adds counterfactual and contrastive explainers for tabular classification. Model specific explainers are declared through new model mixins that also enforce the preprocessing contract image explainers need, keeping explainability responsibilities out of the core model API.


Type of Change

  • Backend change
  • Frontend change
  • CI / Workflow change
  • Build / Packaging change
  • Bug fix
  • Documentation

Changes (by file)

  • DashAI/back/explainability/explainers/: 10 new explainers, all emitting typed artifacts:
    • Tabular: contrastive_shap.py (why P rather than Q, SHAP deltas), nearest_counterfactual.py (nearest real training rows, highlighted table), dice_counterfactual.py (synthetic counterfactuals via dice-ml).
    • Image: grad_cam.py (CAM heatmap overlays, gradcam/gradcam++/eigencam), occlusion_saliency.py (probability drop maps, works on any torch image model).
    • Text: lime_text.py (word attributions), token_ablation.py (per token probability drop).
    • Regression: regression_partial_dependence.py, regression_kernel_shap.py, regression_permutation_feature_importance.py.
    • image_explainer_utils.py: shared white box helpers (torch module access, inference transform, plotly heatmap overlay).
  • DashAI/back/models/image_explainable_model.py: new OcclusionSaliencyCompatibleModel and GradCamCompatibleModel mixins; they carry the explainer COMPATIBLE_COMPONENTS entries and force get_inference_transform() as an abstract method.
  • DashAI/back/models/{base_torchvision_image_classifier,cnn_image_classifier,lenet5_image_classifier}.py: inherit GradCamCompatibleModel and implement the transform; mlp_image_classifier.py inherits occlusion only (no conv layers).
  • DashAI/back/models/scikit_learn/sklearn_like_classifier.py: declares DiceCounterfactual (requires predict_proba); all sklearn classifiers inherit it via the MRO merge.
  • DashAI/back/initial_components.py: registers the 10 new explainers.
  • DashAI/back/dependencies/registry/component_registry.py: get_related_components skips unregistered relation names (a model declaring an uninstalled plugin explainer no longer breaks component lookups).
  • pyproject.toml / uv.lock: new dependencies grad-cam, dice-ml, lime.
  • tests/back/explainers/test_{new_explainers,lib_explainers,image_explainers,task_explainers}.py: coverage for all 10 explainers with tiny or fake models (fast).

Testing

  • uv run pytest tests/back/explainers tests/back/registries (46 tests).
  • Manual checklist: ResNet/CNN/LeNet5 run offers GradCam + OcclusionSaliency; MLP run offers only OcclusionSaliency; sklearn tabular run offers KernelShap/PDP/PFI + ContrastiveShap/NearestCounterfactual/DiceCounterfactual; regression run offers exactly the regression trio; text run offers LimeText + TokenAblation.

Notes

  • GradCAM heatmaps are plotly overlays (interactive zoom); the native image artifact type remains available for future explainers.
  • Translation task explainers were deferred (candidates discussed: source token ablation, cross attention heatmaps).
  • Explainer runtimes vary: KernelShap/DiCE on large instance scopes are slow; the scope percentage selector caps this.

@Irozuku Irozuku added enhancement New feature or request back Backend work labels Jul 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

back Backend work enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant