adaptive-xai 1.0.0b1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- adaptive_xai-1.0.0b1/LICENSE +21 -0
- adaptive_xai-1.0.0b1/PKG-INFO +229 -0
- adaptive_xai-1.0.0b1/README.md +215 -0
- adaptive_xai-1.0.0b1/adaptive_xai/__init__.py +1 -0
- adaptive_xai-1.0.0b1/adaptive_xai/cli_display.py +175 -0
- adaptive_xai-1.0.0b1/adaptive_xai/dependency_manager/__init__.py +3 -0
- adaptive_xai-1.0.0b1/adaptive_xai/dependency_manager/checker.py +4 -0
- adaptive_xai-1.0.0b1/adaptive_xai/dependency_manager/constants.py +94 -0
- adaptive_xai-1.0.0b1/adaptive_xai/dependency_manager/installer.py +51 -0
- adaptive_xai-1.0.0b1/adaptive_xai/dependency_manager/manager.py +68 -0
- adaptive_xai-1.0.0b1/adaptive_xai/explanation_generator/generator.py +210 -0
- adaptive_xai-1.0.0b1/adaptive_xai/explanation_generator/rank_features.py +0 -0
- adaptive_xai-1.0.0b1/adaptive_xai/explanation_generator/template_engine.py +37 -0
- adaptive_xai-1.0.0b1/adaptive_xai/explanation_generator/templates/common.json +22 -0
- adaptive_xai-1.0.0b1/adaptive_xai/explanation_generator/templates/feature_importance.json +6 -0
- adaptive_xai-1.0.0b1/adaptive_xai/explanation_generator/templates/gradcam.json +5 -0
- adaptive_xai-1.0.0b1/adaptive_xai/explanation_generator/templates/lime.json +10 -0
- adaptive_xai-1.0.0b1/adaptive_xai/explanation_generator/templates/shap.json +9 -0
- adaptive_xai-1.0.0b1/adaptive_xai/explanation_generator/templates/tree_interpreter.json +9 -0
- adaptive_xai-1.0.0b1/adaptive_xai/model_analyzer/__init__.py +3 -0
- adaptive_xai-1.0.0b1/adaptive_xai/model_analyzer/analyzer.py +65 -0
- adaptive_xai-1.0.0b1/adaptive_xai/model_analyzer/classify_file_type.py +16 -0
- adaptive_xai-1.0.0b1/adaptive_xai/model_analyzer/constants.py +315 -0
- adaptive_xai-1.0.0b1/adaptive_xai/model_analyzer/evidence.py +15 -0
- adaptive_xai-1.0.0b1/adaptive_xai/model_analyzer/evidence_ranker.py +37 -0
- adaptive_xai-1.0.0b1/adaptive_xai/model_analyzer/evidence_reducer.py +55 -0
- adaptive_xai-1.0.0b1/adaptive_xai/model_analyzer/load_model_files.py +80 -0
- adaptive_xai-1.0.0b1/adaptive_xai/model_analyzer/read_config.py +49 -0
- adaptive_xai-1.0.0b1/adaptive_xai/model_analyzer/read_dataset.py +131 -0
- adaptive_xai-1.0.0b1/adaptive_xai/model_analyzer/read_input_type.py +148 -0
- adaptive_xai-1.0.0b1/adaptive_xai/model_analyzer/read_notebook.py +30 -0
- adaptive_xai-1.0.0b1/adaptive_xai/model_analyzer/read_requirements.py +44 -0
- adaptive_xai-1.0.0b1/adaptive_xai/model_analyzer/read_source.py +601 -0
- adaptive_xai-1.0.0b1/adaptive_xai/model_analyzer/report_generator.py +35 -0
- adaptive_xai-1.0.0b1/adaptive_xai/notebook_converter.py +134 -0
- adaptive_xai-1.0.0b1/adaptive_xai/run.py +401 -0
- adaptive_xai-1.0.0b1/adaptive_xai/xai_integration/__init__.py +24 -0
- adaptive_xai-1.0.0b1/adaptive_xai/xai_integration/adapters/__init__.py +18 -0
- adaptive_xai-1.0.0b1/adaptive_xai/xai_integration/adapters/adapter_registry.py +59 -0
- adaptive_xai-1.0.0b1/adaptive_xai/xai_integration/adapters/base_adapter.py +105 -0
- adaptive_xai-1.0.0b1/adaptive_xai/xai_integration/adapters/generic_adapter.py +33 -0
- adaptive_xai-1.0.0b1/adaptive_xai/xai_integration/adapters/pytorch_adapter.py +140 -0
- adaptive_xai-1.0.0b1/adaptive_xai/xai_integration/adapters/sklearn_adapter.py +87 -0
- adaptive_xai-1.0.0b1/adaptive_xai/xai_integration/adapters/tensorflow_adapter.py +154 -0
- adaptive_xai-1.0.0b1/adaptive_xai/xai_integration/base_plugin.py +28 -0
- adaptive_xai-1.0.0b1/adaptive_xai/xai_integration/dependency_manager.py +172 -0
- adaptive_xai-1.0.0b1/adaptive_xai/xai_integration/engine.py +161 -0
- adaptive_xai-1.0.0b1/adaptive_xai/xai_integration/exceptions.py +39 -0
- adaptive_xai-1.0.0b1/adaptive_xai/xai_integration/manual_detection.py +60 -0
- adaptive_xai-1.0.0b1/adaptive_xai/xai_integration/model_loader.py +392 -0
- adaptive_xai-1.0.0b1/adaptive_xai/xai_integration/output_schema.py +19 -0
- adaptive_xai-1.0.0b1/adaptive_xai/xai_integration/persistent.py +529 -0
- adaptive_xai-1.0.0b1/adaptive_xai/xai_integration/plugin_registry.py +52 -0
- adaptive_xai-1.0.0b1/adaptive_xai/xai_integration/plugins/__init__.py +5 -0
- adaptive_xai-1.0.0b1/adaptive_xai/xai_integration/plugins/feature_importance_plugin.py +76 -0
- adaptive_xai-1.0.0b1/adaptive_xai/xai_integration/plugins/gradcam_plugin.py +39 -0
- adaptive_xai-1.0.0b1/adaptive_xai/xai_integration/plugins/lime_plugin.py +153 -0
- adaptive_xai-1.0.0b1/adaptive_xai/xai_integration/plugins/shap_plugin.py +195 -0
- adaptive_xai-1.0.0b1/adaptive_xai/xai_integration/plugins/tree_interpreter_plugin.py +72 -0
- adaptive_xai-1.0.0b1/adaptive_xai/xai_integration/prediction_utils.py +58 -0
- adaptive_xai-1.0.0b1/adaptive_xai/xai_integration/utils/__init__.py +0 -0
- adaptive_xai-1.0.0b1/adaptive_xai/xai_integration/visualization.py +70 -0
- adaptive_xai-1.0.0b1/adaptive_xai/xai_selector/__init__.py +7 -0
- adaptive_xai-1.0.0b1/adaptive_xai/xai_selector/adapter.py +27 -0
- adaptive_xai-1.0.0b1/adaptive_xai/xai_selector/cli.py +66 -0
- adaptive_xai-1.0.0b1/adaptive_xai/xai_selector/knowledge.py +94 -0
- adaptive_xai-1.0.0b1/adaptive_xai/xai_selector/mapping_rules.py +55 -0
- adaptive_xai-1.0.0b1/adaptive_xai/xai_selector/matcher.py +28 -0
- adaptive_xai-1.0.0b1/adaptive_xai/xai_selector/recommender.py +28 -0
- adaptive_xai-1.0.0b1/adaptive_xai/xai_selector/report_formatter.py +46 -0
- adaptive_xai-1.0.0b1/adaptive_xai/xai_selector/report_parser.py +30 -0
- adaptive_xai-1.0.0b1/adaptive_xai/xai_selector/selector.py +41 -0
- adaptive_xai-1.0.0b1/adaptive_xai.egg-info/PKG-INFO +229 -0
- adaptive_xai-1.0.0b1/adaptive_xai.egg-info/SOURCES.txt +78 -0
- adaptive_xai-1.0.0b1/adaptive_xai.egg-info/dependency_links.txt +1 -0
- adaptive_xai-1.0.0b1/adaptive_xai.egg-info/entry_points.txt +5 -0
- adaptive_xai-1.0.0b1/adaptive_xai.egg-info/requires.txt +3 -0
- adaptive_xai-1.0.0b1/adaptive_xai.egg-info/top_level.txt +1 -0
- adaptive_xai-1.0.0b1/pyproject.toml +35 -0
- adaptive_xai-1.0.0b1/setup.cfg +4 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Charan, Dhyan KJ, Jeevitha Shetty, Poorvi J Poojary
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: adaptive-xai
|
|
3
|
+
Version: 1.0.0b1
|
|
4
|
+
Summary: An adaptive explainable-AI framework for integrating XAI into machine learning projects.
|
|
5
|
+
Author: Charan, Dhyan KJ, Jeevitha Shetty, Poorvi J Poojary
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Requires-Python: >=3.14
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Requires-Dist: pandas
|
|
11
|
+
Requires-Dist: numpy
|
|
12
|
+
Requires-Dist: nbformat
|
|
13
|
+
Dynamic: license-file
|
|
14
|
+
|
|
15
|
+
# Adaptive XAI Framework for Healthcare Systems
|
|
16
|
+
|
|
17
|
+
An adaptive explainable-AI framework for helping developers integrate XAI into
|
|
18
|
+
existing machine learning projects, especially healthcare and clinical modeling
|
|
19
|
+
workflows.
|
|
20
|
+
|
|
21
|
+
The framework analyzes a project, infers a model profile, selects a suitable XAI
|
|
22
|
+
technique, prepares dependencies, generates an integration, and produces
|
|
23
|
+
human-readable explanations for model predictions.
|
|
24
|
+
|
|
25
|
+
## Overview
|
|
26
|
+
|
|
27
|
+
Adaptive XAI is designed to support the following workflow:
|
|
28
|
+
|
|
29
|
+
1. Analyze a project directory to infer the model type, architecture, input
|
|
30
|
+
modality, and available feature metadata.
|
|
31
|
+
2. Select a suitable XAI technique from the inferred model profile.
|
|
32
|
+
3. Prepare any required dependencies for the chosen technique.
|
|
33
|
+
4. Generate a model integration that can run explanations against the project.
|
|
34
|
+
5. Produce readable explanation output in a format suitable for downstream use,
|
|
35
|
+
reporting, and debugging.
|
|
36
|
+
|
|
37
|
+
The framework is intended to work with existing ML projects without requiring the
|
|
38
|
+
user to rebuild a separate example model or re-run the analysis repeatedly.
|
|
39
|
+
|
|
40
|
+
## Package name and installation
|
|
41
|
+
|
|
42
|
+
The Python package is published as:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
adaptive-xai
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Install it from PyPI with:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
pip install adaptive-xai
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
This installs the package and registers the command-line tools defined in
|
|
55
|
+
`pyproject.toml` in the target Python environment.
|
|
56
|
+
|
|
57
|
+
## CLI commands
|
|
58
|
+
|
|
59
|
+
### `adaptive-xai`
|
|
60
|
+
|
|
61
|
+
Run the full framework workflow from the project root:
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
adaptive-xai
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
This starts the framework orchestration flow, including model analysis,
|
|
68
|
+
selection, dependency preparation, and integration generation.
|
|
69
|
+
|
|
70
|
+
### `analyze`
|
|
71
|
+
|
|
72
|
+
Run the analyzer directly inside a target project directory:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
analyze
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
This scans the project and generates or updates `model_report.json` in the
|
|
79
|
+
current working directory.
|
|
80
|
+
|
|
81
|
+
### `xai-select`
|
|
82
|
+
|
|
83
|
+
Use an existing analysis report without rerunning the full analyzer:
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
xai-select
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
By default, it reads `model_report.json` from the current directory. It can also
|
|
90
|
+
accept a path to a report file.
|
|
91
|
+
|
|
92
|
+
### `convert`
|
|
93
|
+
|
|
94
|
+
Convert one or more Jupyter notebooks into runnable Python scripts:
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
convert my_notebook.ipynb
|
|
98
|
+
convert notebooks/
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
The generated `.py` file keeps the same base name as the notebook and preserves
|
|
102
|
+
cell contents in plain Python while commenting out notebook magics and shell
|
|
103
|
+
commands that are not valid in a normal script.
|
|
104
|
+
|
|
105
|
+
## Framework architecture
|
|
106
|
+
|
|
107
|
+
The repository is organized as follows:
|
|
108
|
+
|
|
109
|
+
```text
|
|
110
|
+
adaptive_xai/
|
|
111
|
+
├── __init__.py
|
|
112
|
+
├── run.py # orchestration entry point
|
|
113
|
+
├── cli_display.py # terminal output and UI helpers
|
|
114
|
+
├── model_analyzer/ # project/model profiling
|
|
115
|
+
├── xai_selector/ # technique selection logic
|
|
116
|
+
├── dependency_manager/ # dependency preparation and validation
|
|
117
|
+
├── xai_integration/ # model loading, plugin integration, execution
|
|
118
|
+
├── explanation_generator/ # template-based explanation rendering
|
|
119
|
+
├── notebook_converter.py # notebook-to-Python conversion tool
|
|
120
|
+
└── ...
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## Module responsibilities
|
|
124
|
+
|
|
125
|
+
### `adaptive_xai/model_analyzer/`
|
|
126
|
+
|
|
127
|
+
Responsible for inferring project and model characteristics including:
|
|
128
|
+
|
|
129
|
+
- ML framework
|
|
130
|
+
- model architecture or category
|
|
131
|
+
- task type
|
|
132
|
+
- input modality
|
|
133
|
+
- feature metadata
|
|
134
|
+
- dataset and config signals
|
|
135
|
+
|
|
136
|
+
It writes a `model_report.json` that summarizes the inferred profile.
|
|
137
|
+
|
|
138
|
+
### `adaptive_xai/xai_selector/`
|
|
139
|
+
|
|
140
|
+
Selects a compatible XAI method based on the model profile and other signals.
|
|
141
|
+
It includes:
|
|
142
|
+
|
|
143
|
+
- mapping rules and strategy logic
|
|
144
|
+
- recommendation/ranking support
|
|
145
|
+
- CLI tooling for continuing from a saved report
|
|
146
|
+
|
|
147
|
+
### `adaptive_xai/dependency_manager/`
|
|
148
|
+
|
|
149
|
+
Prepares dependencies required by the selected explanation method and checks
|
|
150
|
+
whether required libraries are available.
|
|
151
|
+
|
|
152
|
+
### `adaptive_xai/xai_integration/`
|
|
153
|
+
|
|
154
|
+
Handles the execution side of XAI integration, including:
|
|
155
|
+
|
|
156
|
+
- model loading
|
|
157
|
+
- explanation execution
|
|
158
|
+
- plugin generation and integration
|
|
159
|
+
- output schema definition
|
|
160
|
+
- persistent integration generation for project use
|
|
161
|
+
|
|
162
|
+
### `adaptive_xai/explanation_generator/`
|
|
163
|
+
|
|
164
|
+
Transforms structured XAI outputs into readable and presentation-friendly text.
|
|
165
|
+
|
|
166
|
+
This module contains:
|
|
167
|
+
|
|
168
|
+
- `template_engine.py` for JSON template loading and formatting
|
|
169
|
+
- `generator.py` for rendering explanation output
|
|
170
|
+
- `templates/*.json` for technique-specific output templates
|
|
171
|
+
|
|
172
|
+
Supported techniques include:
|
|
173
|
+
|
|
174
|
+
- SHAP
|
|
175
|
+
- LIME
|
|
176
|
+
- Feature Importance
|
|
177
|
+
- Grad-CAM
|
|
178
|
+
- Tree Interpreter
|
|
179
|
+
|
|
180
|
+
This is the module added to the framework for explanation formatting and result
|
|
181
|
+
presentation.
|
|
182
|
+
|
|
183
|
+
## Typical workflow
|
|
184
|
+
|
|
185
|
+
From a project directory:
|
|
186
|
+
|
|
187
|
+
```bash
|
|
188
|
+
analyze
|
|
189
|
+
xai-select
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
or:
|
|
193
|
+
|
|
194
|
+
```bash
|
|
195
|
+
adaptive-xai
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
The workflow produces a `model_report.json`, identifies the best XAI approach,
|
|
199
|
+
prepares dependencies, and generates the integration needed to explain model
|
|
200
|
+
predictions.
|
|
201
|
+
|
|
202
|
+
## Output artifacts
|
|
203
|
+
|
|
204
|
+
The framework generates and relies on the following artifacts:
|
|
205
|
+
|
|
206
|
+
- `model_report.json` — inferred project/model profile
|
|
207
|
+
- generated XAI integration files
|
|
208
|
+
- selected technique metadata and explanation output
|
|
209
|
+
- template-based explanation reports
|
|
210
|
+
|
|
211
|
+
## Example usage
|
|
212
|
+
|
|
213
|
+
```bash
|
|
214
|
+
cd /path/to/your/project
|
|
215
|
+
analyze
|
|
216
|
+
xai-select
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
Or directly:
|
|
220
|
+
|
|
221
|
+
```bash
|
|
222
|
+
cd /path/to/your/project
|
|
223
|
+
adaptive-xai
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
## License
|
|
227
|
+
|
|
228
|
+
This project is licensed under the terms of the LICENSE file included in this
|
|
229
|
+
repository.
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
# Adaptive XAI Framework for Healthcare Systems
|
|
2
|
+
|
|
3
|
+
An adaptive explainable-AI framework for helping developers integrate XAI into
|
|
4
|
+
existing machine learning projects, especially healthcare and clinical modeling
|
|
5
|
+
workflows.
|
|
6
|
+
|
|
7
|
+
The framework analyzes a project, infers a model profile, selects a suitable XAI
|
|
8
|
+
technique, prepares dependencies, generates an integration, and produces
|
|
9
|
+
human-readable explanations for model predictions.
|
|
10
|
+
|
|
11
|
+
## Overview
|
|
12
|
+
|
|
13
|
+
Adaptive XAI is designed to support the following workflow:
|
|
14
|
+
|
|
15
|
+
1. Analyze a project directory to infer the model type, architecture, input
|
|
16
|
+
modality, and available feature metadata.
|
|
17
|
+
2. Select a suitable XAI technique from the inferred model profile.
|
|
18
|
+
3. Prepare any required dependencies for the chosen technique.
|
|
19
|
+
4. Generate a model integration that can run explanations against the project.
|
|
20
|
+
5. Produce readable explanation output in a format suitable for downstream use,
|
|
21
|
+
reporting, and debugging.
|
|
22
|
+
|
|
23
|
+
The framework is intended to work with existing ML projects without requiring the
|
|
24
|
+
user to rebuild a separate example model or re-run the analysis repeatedly.
|
|
25
|
+
|
|
26
|
+
## Package name and installation
|
|
27
|
+
|
|
28
|
+
The Python package is published as:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
adaptive-xai
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Install it from PyPI with:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
pip install adaptive-xai
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
This installs the package and registers the command-line tools defined in
|
|
41
|
+
`pyproject.toml` in the target Python environment.
|
|
42
|
+
|
|
43
|
+
## CLI commands
|
|
44
|
+
|
|
45
|
+
### `adaptive-xai`
|
|
46
|
+
|
|
47
|
+
Run the full framework workflow from the project root:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
adaptive-xai
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
This starts the framework orchestration flow, including model analysis,
|
|
54
|
+
selection, dependency preparation, and integration generation.
|
|
55
|
+
|
|
56
|
+
### `analyze`
|
|
57
|
+
|
|
58
|
+
Run the analyzer directly inside a target project directory:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
analyze
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
This scans the project and generates or updates `model_report.json` in the
|
|
65
|
+
current working directory.
|
|
66
|
+
|
|
67
|
+
### `xai-select`
|
|
68
|
+
|
|
69
|
+
Use an existing analysis report without rerunning the full analyzer:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
xai-select
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
By default, it reads `model_report.json` from the current directory. It can also
|
|
76
|
+
accept a path to a report file.
|
|
77
|
+
|
|
78
|
+
### `convert`
|
|
79
|
+
|
|
80
|
+
Convert one or more Jupyter notebooks into runnable Python scripts:
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
convert my_notebook.ipynb
|
|
84
|
+
convert notebooks/
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
The generated `.py` file keeps the same base name as the notebook and preserves
|
|
88
|
+
cell contents in plain Python while commenting out notebook magics and shell
|
|
89
|
+
commands that are not valid in a normal script.
|
|
90
|
+
|
|
91
|
+
## Framework architecture
|
|
92
|
+
|
|
93
|
+
The repository is organized as follows:
|
|
94
|
+
|
|
95
|
+
```text
|
|
96
|
+
adaptive_xai/
|
|
97
|
+
├── __init__.py
|
|
98
|
+
├── run.py # orchestration entry point
|
|
99
|
+
├── cli_display.py # terminal output and UI helpers
|
|
100
|
+
├── model_analyzer/ # project/model profiling
|
|
101
|
+
├── xai_selector/ # technique selection logic
|
|
102
|
+
├── dependency_manager/ # dependency preparation and validation
|
|
103
|
+
├── xai_integration/ # model loading, plugin integration, execution
|
|
104
|
+
├── explanation_generator/ # template-based explanation rendering
|
|
105
|
+
├── notebook_converter.py # notebook-to-Python conversion tool
|
|
106
|
+
└── ...
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## Module responsibilities
|
|
110
|
+
|
|
111
|
+
### `adaptive_xai/model_analyzer/`
|
|
112
|
+
|
|
113
|
+
Responsible for inferring project and model characteristics including:
|
|
114
|
+
|
|
115
|
+
- ML framework
|
|
116
|
+
- model architecture or category
|
|
117
|
+
- task type
|
|
118
|
+
- input modality
|
|
119
|
+
- feature metadata
|
|
120
|
+
- dataset and config signals
|
|
121
|
+
|
|
122
|
+
It writes a `model_report.json` that summarizes the inferred profile.
|
|
123
|
+
|
|
124
|
+
### `adaptive_xai/xai_selector/`
|
|
125
|
+
|
|
126
|
+
Selects a compatible XAI method based on the model profile and other signals.
|
|
127
|
+
It includes:
|
|
128
|
+
|
|
129
|
+
- mapping rules and strategy logic
|
|
130
|
+
- recommendation/ranking support
|
|
131
|
+
- CLI tooling for continuing from a saved report
|
|
132
|
+
|
|
133
|
+
### `adaptive_xai/dependency_manager/`
|
|
134
|
+
|
|
135
|
+
Prepares dependencies required by the selected explanation method and checks
|
|
136
|
+
whether required libraries are available.
|
|
137
|
+
|
|
138
|
+
### `adaptive_xai/xai_integration/`
|
|
139
|
+
|
|
140
|
+
Handles the execution side of XAI integration, including:
|
|
141
|
+
|
|
142
|
+
- model loading
|
|
143
|
+
- explanation execution
|
|
144
|
+
- plugin generation and integration
|
|
145
|
+
- output schema definition
|
|
146
|
+
- persistent integration generation for project use
|
|
147
|
+
|
|
148
|
+
### `adaptive_xai/explanation_generator/`
|
|
149
|
+
|
|
150
|
+
Transforms structured XAI outputs into readable and presentation-friendly text.
|
|
151
|
+
|
|
152
|
+
This module contains:
|
|
153
|
+
|
|
154
|
+
- `template_engine.py` for JSON template loading and formatting
|
|
155
|
+
- `generator.py` for rendering explanation output
|
|
156
|
+
- `templates/*.json` for technique-specific output templates
|
|
157
|
+
|
|
158
|
+
Supported techniques include:
|
|
159
|
+
|
|
160
|
+
- SHAP
|
|
161
|
+
- LIME
|
|
162
|
+
- Feature Importance
|
|
163
|
+
- Grad-CAM
|
|
164
|
+
- Tree Interpreter
|
|
165
|
+
|
|
166
|
+
This is the module added to the framework for explanation formatting and result
|
|
167
|
+
presentation.
|
|
168
|
+
|
|
169
|
+
## Typical workflow
|
|
170
|
+
|
|
171
|
+
From a project directory:
|
|
172
|
+
|
|
173
|
+
```bash
|
|
174
|
+
analyze
|
|
175
|
+
xai-select
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
or:
|
|
179
|
+
|
|
180
|
+
```bash
|
|
181
|
+
adaptive-xai
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
The workflow produces a `model_report.json`, identifies the best XAI approach,
|
|
185
|
+
prepares dependencies, and generates the integration needed to explain model
|
|
186
|
+
predictions.
|
|
187
|
+
|
|
188
|
+
## Output artifacts
|
|
189
|
+
|
|
190
|
+
The framework generates and relies on the following artifacts:
|
|
191
|
+
|
|
192
|
+
- `model_report.json` — inferred project/model profile
|
|
193
|
+
- generated XAI integration files
|
|
194
|
+
- selected technique metadata and explanation output
|
|
195
|
+
- template-based explanation reports
|
|
196
|
+
|
|
197
|
+
## Example usage
|
|
198
|
+
|
|
199
|
+
```bash
|
|
200
|
+
cd /path/to/your/project
|
|
201
|
+
analyze
|
|
202
|
+
xai-select
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
Or directly:
|
|
206
|
+
|
|
207
|
+
```bash
|
|
208
|
+
cd /path/to/your/project
|
|
209
|
+
adaptive-xai
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
## License
|
|
213
|
+
|
|
214
|
+
This project is licensed under the terms of the LICENSE file included in this
|
|
215
|
+
repository.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Adaptive XAI Framework
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
def print_banner():
|
|
2
|
+
print(r"""
|
|
3
|
+
────────────────────────────────────────────────────────────────────────────────────────────────────
|
|
4
|
+
▄▖ ▌ ▗ ▘ ▖▖▄▖▄▖ ▄▖ ▌ ▐▘ ▖▖ ▜ ▗ ▌ ▄▖ ▗
|
|
5
|
+
▌▌▛▌▀▌▛▌▜▘▌▌▌█▌ ▚▘▌▌▐ ▙▖▛▘▀▌▛▛▌█▌▌▌▌▛▌▛▘▙▘ ▜▘▛▌▛▘ ▙▌█▌▀▌▐ ▜▘▛▌▛▘▀▌▛▘█▌ ▚ ▌▌▛▘▜▘█▌▛▛▌▛▘
|
|
6
|
+
▛▌▙▌█▌▙▌▐▖▌▚▘▙▖ ▌▌▛▌▟▖ ▌ ▌ █▌▌▌▌▙▖▚▚▘▙▌▌ ▛▖ ▐ ▙▌▌ ▌▌▙▖█▌▐▖▐▖▌▌▙▖█▌▌ ▙▖ ▄▌▙▌▄▌▐▖▙▖▌▌▌▄▌
|
|
7
|
+
▌ ▄▌
|
|
8
|
+
────────────────────────────────────────────────────────────────────────────────────────────────────
|
|
9
|
+
""")
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def print_status(message):
|
|
13
|
+
print(f"[✓] {message}")
|
|
14
|
+
|
|
15
|
+
def print_error(message):
|
|
16
|
+
print(f"[✗] {message}")
|
|
17
|
+
|
|
18
|
+
def print_analysis_validation_error(reasons):
|
|
19
|
+
print()
|
|
20
|
+
print(
|
|
21
|
+
"\033[1;37;41m The selected folder may not be the correct "
|
|
22
|
+
"model project. \033[0m"
|
|
23
|
+
)
|
|
24
|
+
print("\033[1;31mSetup stopped because the analyzer could not identify:\033[0m")
|
|
25
|
+
for reason in reasons:
|
|
26
|
+
print(f" - {reason}")
|
|
27
|
+
print(
|
|
28
|
+
"Check that you selected the project folder containing the model "
|
|
29
|
+
"source/configuration files, then rerun the setup."
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def print_model_compatibility_error(message):
|
|
34
|
+
print()
|
|
35
|
+
print("\033[1;37;41m MODEL VERSION INCOMPATIBILITY \033[0m")
|
|
36
|
+
print(f"\033[1;31m{message}\033[0m")
|
|
37
|
+
print(
|
|
38
|
+
"Retrain and save the model with the installed scikit-learn version, "
|
|
39
|
+
"or use a separate environment with a compatible Python and "
|
|
40
|
+
"scikit-learn version. The active environment was not downgraded."
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def print_model_load_error(error):
|
|
45
|
+
from .xai_integration.exceptions import ModelCompatibilityError
|
|
46
|
+
|
|
47
|
+
root_cause = error
|
|
48
|
+
seen = set()
|
|
49
|
+
while root_cause.__cause__ is not None and id(root_cause) not in seen:
|
|
50
|
+
seen.add(id(root_cause))
|
|
51
|
+
root_cause = root_cause.__cause__
|
|
52
|
+
|
|
53
|
+
detail = str(root_cause)
|
|
54
|
+
normalized_detail = detail.lower()
|
|
55
|
+
if (
|
|
56
|
+
isinstance(error, ModelCompatibilityError)
|
|
57
|
+
and error.package == "scikit-learn"
|
|
58
|
+
and error.saved_versions
|
|
59
|
+
):
|
|
60
|
+
saved_versions = ", ".join(error.saved_versions)
|
|
61
|
+
suggested_version = error.saved_versions[0]
|
|
62
|
+
title = "SCIKIT-LEARN VERSION MISMATCH"
|
|
63
|
+
message = (
|
|
64
|
+
f"The model metadata says it was saved with scikit-learn "
|
|
65
|
+
f"{saved_versions}; this environment has scikit-learn "
|
|
66
|
+
f"{error.installed_version}. To try using it, create a separate "
|
|
67
|
+
"environment with a Python version supported by the saved "
|
|
68
|
+
f"scikit-learn release and install "
|
|
69
|
+
f"`scikit-learn=={suggested_version}`. A compatible NumPy version "
|
|
70
|
+
"may also be required. This is a best starting point, not a "
|
|
71
|
+
"guarantee; retraining and re-saving with the current environment "
|
|
72
|
+
"is the most reliable option."
|
|
73
|
+
)
|
|
74
|
+
elif isinstance(error, ModelCompatibilityError) or (
|
|
75
|
+
"node array from the pickle has an incompatible dtype"
|
|
76
|
+
in normalized_detail
|
|
77
|
+
):
|
|
78
|
+
title = "MODEL VERSION INCOMPATIBILITY"
|
|
79
|
+
message = (
|
|
80
|
+
"The model was saved with a scikit-learn tree format that is "
|
|
81
|
+
"incompatible with the installed version. Retrain/re-save it "
|
|
82
|
+
"with the installed version or load it in a separate environment "
|
|
83
|
+
"using a compatible Python and scikit-learn version."
|
|
84
|
+
)
|
|
85
|
+
elif (
|
|
86
|
+
"sklearn.compose._column_transformer" in normalized_detail
|
|
87
|
+
and "_remaindercolslist" in normalized_detail
|
|
88
|
+
):
|
|
89
|
+
title = "SCIKIT-LEARN PIPELINE VERSION MISMATCH"
|
|
90
|
+
message = (
|
|
91
|
+
"This pipeline uses an internal scikit-learn component that "
|
|
92
|
+
"differs from the version installed here. This is a model/library "
|
|
93
|
+
"compatibility issue, not a problem with adap_xai.py, and the "
|
|
94
|
+
"framework has not modified your model file. To continue, "
|
|
95
|
+
"preferably retrain and re-save the pipeline with the installed "
|
|
96
|
+
"scikit-learn version. If you cannot retrain, use a separate "
|
|
97
|
+
"environment with a compatible Python and the scikit-learn "
|
|
98
|
+
"version used to save the model; avoid downgrading a shared "
|
|
99
|
+
"environment."
|
|
100
|
+
)
|
|
101
|
+
elif (
|
|
102
|
+
"xgboost" in normalized_detail
|
|
103
|
+
and (
|
|
104
|
+
"estimator" in normalized_detail
|
|
105
|
+
or "xgboost.sklearn" in normalized_detail
|
|
106
|
+
)
|
|
107
|
+
):
|
|
108
|
+
title = "XGBOOST MODEL INTERFACE UNAVAILABLE"
|
|
109
|
+
message = (
|
|
110
|
+
"XGBoost is required, but its scikit-learn estimator interface "
|
|
111
|
+
"is unavailable in the active Python environment. Verify the "
|
|
112
|
+
"installed XGBoost version and import path, then use an "
|
|
113
|
+
"environment that provides the interface/version used to save "
|
|
114
|
+
"this pickle. If possible, re-export the model in XGBoost's "
|
|
115
|
+
"native JSON or UBJ format."
|
|
116
|
+
)
|
|
117
|
+
elif isinstance(root_cause, ModuleNotFoundError):
|
|
118
|
+
title = "MODEL DEPENDENCY UNAVAILABLE"
|
|
119
|
+
module_name = root_cause.name or "a required module"
|
|
120
|
+
message = (
|
|
121
|
+
f"The model requires Python module '{module_name}', which could "
|
|
122
|
+
"not be imported. Install a compatible dependency in the active "
|
|
123
|
+
"Python environment or use the environment that created the model."
|
|
124
|
+
)
|
|
125
|
+
elif isinstance(root_cause, FileNotFoundError):
|
|
126
|
+
title = "MODEL FILE NOT FOUND"
|
|
127
|
+
message = "Check that the configured model path exists and is accessible."
|
|
128
|
+
else:
|
|
129
|
+
title = "MODEL LOAD FAILED"
|
|
130
|
+
message = (
|
|
131
|
+
"The model could not be loaded. Check that the selected file is "
|
|
132
|
+
"valid and compatible with the installed framework and dependency "
|
|
133
|
+
"versions."
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
print()
|
|
137
|
+
print(f"\033[1;37;41m {title} \033[0m")
|
|
138
|
+
print(f"\033[1;31m{message}\033[0m")
|
|
139
|
+
if detail:
|
|
140
|
+
print(f"Details: {detail}")
|
|
141
|
+
|
|
142
|
+
def print_explanation_error(error):
|
|
143
|
+
detail = str(error)
|
|
144
|
+
if "background_data" in detail.lower():
|
|
145
|
+
title = "EXPLANATION BACKGROUND DATA REQUIRED"
|
|
146
|
+
message = (
|
|
147
|
+
"The selected tabular SHAP or LIME explanation needs representative "
|
|
148
|
+
"background rows. Add a matching CSV/Excel dataset to the project, "
|
|
149
|
+
"or edit BACKGROUND_DATA in adap_xai.py with rows in the same "
|
|
150
|
+
"feature order the model expects. The framework will not invent "
|
|
151
|
+
"or modify model inputs."
|
|
152
|
+
)
|
|
153
|
+
else:
|
|
154
|
+
title = "EXPLANATION FAILED"
|
|
155
|
+
message = (
|
|
156
|
+
"The model loaded, but the selected XAI technique could not produce "
|
|
157
|
+
"an explanation. Check the technique's input requirements and the "
|
|
158
|
+
"details below."
|
|
159
|
+
)
|
|
160
|
+
|
|
161
|
+
print()
|
|
162
|
+
print(f"\033[1;37;41m {title} \033[0m")
|
|
163
|
+
print(f"\033[1;31m{message}\033[0m")
|
|
164
|
+
if detail:
|
|
165
|
+
print(f"Details: {detail}")
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
def print_section(title):
|
|
169
|
+
print("\n" + "─" * 62)
|
|
170
|
+
print(f"{title:^62}")
|
|
171
|
+
print("─" * 62)
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def print_step(message):
|
|
175
|
+
print(f" → {message}")
|