Feat/explainer story i18n - #803
Open
Creylay wants to merge 5 commits into
Open
Conversation
…ainer; introduce story formatting utilities
…improved narrative structure
…nd enhance plot retrieval methods
- Added story generation methods to RegressionKernelShap, RegressionPartialDependence, RegressionPermutationFeatureImportance, and TokenAblation explainers to provide narrative summaries of predictions and feature contributions. - Updated plot methods to remove text artifacts and focus solely on visual representations. - Introduced StoryBox component in the frontend to display narrative summaries alongside artifacts. - Modified existing tests to validate the new story functionality and ensure compatibility with the updated plot outputs. - Updated localization files to include new keys for narrative summaries in multiple languages.
…and regression explainers with multilingual support
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a
story()narrative hook to every explainer (13/13), so global and local explanations come with a deterministic, human-readable summary in addition to their plots. Stories are generated in all 5 supported languages (en,es,pt,de,zh) at once and returned alongside the plot response, so the frontend can switch languages instantly (via the existing i18n selector) without refetching. Also removes redundant hardcoded English text that a subset of explainers previously baked into their plots, now superseded by the multilingualstory()output.Type of Change
Changes (by file)
Core story infrastructure
DashAI/back/explainability/story.py: newformat_story()/concat_stories()helpers that build aMultilingualStringfrom per-language templates, reused by every explainer instead of duplicating 5-language boilerplate.DashAI/back/explainability/global_explainer.py,local_explainer.py: added an optionalstory(explanation, explainer_output)hook toBaseGlobalExplainer/BaseLocalExplainer(defaultNone), mirroring the existingplot()contract.DashAI/back/explainability/explainers/ (Explainers)permutation_feature_importance.py,regression_permutation_feature_importance.py: newstory()ranking features by importance; only claims the model "relies on" features with measurable (>0) importance, calling out separately when the rest showed none instead of lumping them together.partial_dependence.py,regression_partial_dependence.py: newstory()classifying each curve as increasing/decreasing/flat/non-monotonic from its actual values; added a dedicated "flat" case for curves with no real change (previously misreported as "increases").kernel_shap.py: newstory(); removed the old English-only Plotly annotation baked into the chart (predicted class/probability), now covered — with more detail — bystory().contrastive_shap.py,dice_counterfactual.py,nearest_counterfactual.py,regression_kernel_shap.py,token_ablation.py,grad_cam.py,occlusion_saliency.py,lime_text.py: migrated each explainer's existing hardcoded EnglishTextArtifactsummary into a multilingualstory()with equivalent wording, and removed the now-redundantTextArtifactfromplot().**
DashAI/back/api/api_v1/endpoints/explainers.py(API)**GET /global/plot/{id}andGET /local/plot/{id}now also loadexplanation_path(previously onlyplot_path/plots_path) and attach a"story"key ({"en": ..., "es": ..., ...}ornull) to each artifact/group in the response._resolve_story_explainer()to reconstruct the explainer from its registered class + stored parameters (no trained model needed —story()never touches it) and_attach_stories()/_attach_one_story()to compute and attach stories per artifact, never raising: any failure (unbuildable explainer, mismatched shape) just leaves"story": null._as_group_target()/_as_artifact_target()to reconstruct a real (unvalidated)ArtifactGroup/Artifactfrom the wire-format dict thatexplainer_job.pyactually persists (it normalizesplot()'s output before pickling), sostory()'sisinstancechecks work against real data, not just hand-built test objects.DashAI/front/src/components/explainers/(Frontend)StoryBox.jsx: new component that reads the active i18next language fromstoryand renders it as a plain "text" artifact through the existingArtifactViewer— same box, same download button, nothing new to maintain visually.ExplainersPlot.jsx: rendersStoryBoxunder each grouped and ungrouped artifact.utils/i18n/locales/{en,es,pt,de,zh}/explainers.json: added thestoryTitlelabel.Tests
tests/back/api/test_explainer_story_attach.py(new): covers_attach_storiesagainst the real dict-shaped outputexplainer_job.pypersists (not hand-built Pydantic objects), including the no-explainer no-op case.tests/back/explainers/test_image_explainers.py,test_lib_explainers.py,test_new_explainers.py,test_task_explainers.py: updated assertions that expected the now-removedTextArtifactinplot()'s output; assertstory()'s content directly instead.Testing