dlspit 2.2.0__tar.gz → 2.4.0__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.
Files changed (91) hide show
  1. dlspit-2.2.0/README.md → dlspit-2.4.0/PKG-INFO +228 -45
  2. dlspit-2.2.0/PKG-INFO → dlspit-2.4.0/README.md +175 -90
  3. {dlspit-2.2.0 → dlspit-2.4.0}/dl_experiments/__init__.py +13 -2
  4. {dlspit-2.2.0 → dlspit-2.4.0}/dl_experiments/__main__.py +57 -22
  5. dlspit-2.4.0/dl_experiments/display.py +194 -0
  6. dlspit-2.4.0/dl_experiments/genai/experiments/chatbot.py +114 -0
  7. dlspit-2.4.0/dl_experiments/genai/experiments/cyclegan.py +122 -0
  8. dlspit-2.4.0/dl_experiments/genai/experiments/diffusion.py +131 -0
  9. dlspit-2.4.0/dl_experiments/genai/experiments/face_swap.py +115 -0
  10. dlspit-2.4.0/dl_experiments/genai/experiments/gan.py +108 -0
  11. dlspit-2.4.0/dl_experiments/genai/experiments/mini_gpt.py +140 -0
  12. dlspit-2.4.0/dl_experiments/genai/experiments/music_generation.py +167 -0
  13. dlspit-2.4.0/dl_experiments/genai/experiments/text_to_image.py +140 -0
  14. dlspit-2.4.0/dl_experiments/genai/experiments/vae.py +131 -0
  15. {dlspit-2.2.0 → dlspit-2.4.0}/dl_experiments/genai/registry.py +47 -7
  16. dlspit-2.4.0/dl_experiments/xai/experiments/grad_cam.py +134 -0
  17. dlspit-2.4.0/dl_experiments/xai/experiments/gradient_input.py +139 -0
  18. dlspit-2.4.0/dl_experiments/xai/experiments/ice.py +102 -0
  19. dlspit-2.4.0/dl_experiments/xai/experiments/lime_local.py +109 -0
  20. dlspit-2.4.0/dl_experiments/xai/experiments/lrp.py +107 -0
  21. dlspit-2.4.0/dl_experiments/xai/experiments/pdp.py +96 -0
  22. dlspit-2.4.0/dl_experiments/xai/experiments/regression.py +100 -0
  23. dlspit-2.4.0/dl_experiments/xai/experiments/shapley.py +127 -0
  24. dlspit-2.4.0/dl_experiments/xai/experiments/tree_knn.py +113 -0
  25. dlspit-2.4.0/dl_experiments/xai/experiments/xrai.py +136 -0
  26. {dlspit-2.2.0 → dlspit-2.4.0}/dl_experiments/xai/registry.py +49 -7
  27. {dlspit-2.2.0 → dlspit-2.4.0}/pyproject.toml +11 -5
  28. dlspit-2.4.0/tests/test_display.py +246 -0
  29. {dlspit-2.2.0 → dlspit-2.4.0}/tests/test_genai_core.py +12 -7
  30. dlspit-2.4.0/tests/test_standalone.py +385 -0
  31. {dlspit-2.2.0 → dlspit-2.4.0}/tests/test_xai_core.py +18 -13
  32. {dlspit-2.2.0 → dlspit-2.4.0}/dl_experiments/dl/__init__.py +0 -0
  33. {dlspit-2.2.0 → dlspit-2.4.0}/dl_experiments/dl/experiments/__init__.py +0 -0
  34. {dlspit-2.2.0 → dlspit-2.4.0}/dl_experiments/dl/experiments/exp10_transfer.py +0 -0
  35. {dlspit-2.2.0 → dlspit-2.4.0}/dl_experiments/dl/experiments/exp1a_mcculloch_pitts.py +0 -0
  36. {dlspit-2.2.0 → dlspit-2.4.0}/dl_experiments/dl/experiments/exp1b_mlp_binary.py +0 -0
  37. {dlspit-2.2.0 → dlspit-2.4.0}/dl_experiments/dl/experiments/exp2a_activations.py +0 -0
  38. {dlspit-2.2.0 → dlspit-2.4.0}/dl_experiments/dl/experiments/exp2b_backprop_mnist.py +0 -0
  39. {dlspit-2.2.0 → dlspit-2.4.0}/dl_experiments/dl/experiments/exp3_regularisation.py +0 -0
  40. {dlspit-2.2.0 → dlspit-2.4.0}/dl_experiments/dl/experiments/exp4_cnn.py +0 -0
  41. {dlspit-2.2.0 → dlspit-2.4.0}/dl_experiments/dl/experiments/exp5_resnet.py +0 -0
  42. {dlspit-2.2.0 → dlspit-2.4.0}/dl_experiments/dl/experiments/exp6_rnn.py +0 -0
  43. {dlspit-2.2.0 → dlspit-2.4.0}/dl_experiments/dl/experiments/exp7_lstm.py +0 -0
  44. {dlspit-2.2.0 → dlspit-2.4.0}/dl_experiments/dl/experiments/exp8_transformer.py +0 -0
  45. {dlspit-2.2.0 → dlspit-2.4.0}/dl_experiments/dl/experiments/exp9_gan.py +0 -0
  46. {dlspit-2.2.0 → dlspit-2.4.0}/dl_experiments/dl/experiments/exp9b_vae.py +0 -0
  47. {dlspit-2.2.0 → dlspit-2.4.0}/dl_experiments/dl/registry.py +0 -0
  48. {dlspit-2.2.0 → dlspit-2.4.0}/dl_experiments/genai/__init__.py +0 -0
  49. {dlspit-2.2.0 → dlspit-2.4.0}/dl_experiments/genai/_nn.py +0 -0
  50. {dlspit-2.2.0 → dlspit-2.4.0}/dl_experiments/genai/_viz.py +0 -0
  51. {dlspit-2.2.0 → dlspit-2.4.0}/dl_experiments/genai/chatbot.py +0 -0
  52. {dlspit-2.2.0 → dlspit-2.4.0}/dl_experiments/genai/cyclegan.py +0 -0
  53. {dlspit-2.2.0 → dlspit-2.4.0}/dl_experiments/genai/diffusion.py +0 -0
  54. {dlspit-2.2.0 → dlspit-2.4.0}/dl_experiments/genai/face_swap.py +0 -0
  55. {dlspit-2.2.0 → dlspit-2.4.0}/dl_experiments/genai/gan.py +0 -0
  56. {dlspit-2.2.0 → dlspit-2.4.0}/dl_experiments/genai/mini_gpt.py +0 -0
  57. {dlspit-2.2.0 → dlspit-2.4.0}/dl_experiments/genai/music_generation.py +0 -0
  58. {dlspit-2.2.0 → dlspit-2.4.0}/dl_experiments/genai/text_to_image.py +0 -0
  59. {dlspit-2.2.0 → dlspit-2.4.0}/dl_experiments/genai/vae.py +0 -0
  60. {dlspit-2.2.0 → dlspit-2.4.0}/dl_experiments/ml_ese/__init__.py +0 -0
  61. {dlspit-2.2.0 → dlspit-2.4.0}/dl_experiments/ml_ese/experiments/__init__.py +0 -0
  62. {dlspit-2.2.0 → dlspit-2.4.0}/dl_experiments/ml_ese/experiments/decision_tree.py +0 -0
  63. {dlspit-2.2.0 → dlspit-2.4.0}/dl_experiments/ml_ese/experiments/eda_titanic.py +0 -0
  64. {dlspit-2.2.0 → dlspit-2.4.0}/dl_experiments/ml_ese/experiments/kmeans_clustering.py +0 -0
  65. {dlspit-2.2.0 → dlspit-2.4.0}/dl_experiments/ml_ese/experiments/linear_regression.py +0 -0
  66. {dlspit-2.2.0 → dlspit-2.4.0}/dl_experiments/ml_ese/experiments/random_forest.py +0 -0
  67. {dlspit-2.2.0 → dlspit-2.4.0}/dl_experiments/ml_ese/experiments/svm_classifier.py +0 -0
  68. {dlspit-2.2.0 → dlspit-2.4.0}/dl_experiments/ml_ese/experiments/svm_rbf_kernel.py +0 -0
  69. {dlspit-2.2.0 → dlspit-2.4.0}/dl_experiments/ml_ese/experiments/xgboost_classifier.py +0 -0
  70. {dlspit-2.2.0 → dlspit-2.4.0}/dl_experiments/ml_ese/registry.py +0 -0
  71. {dlspit-2.2.0 → dlspit-2.4.0}/dl_experiments/utils/__init__.py +0 -0
  72. {dlspit-2.2.0 → dlspit-2.4.0}/dl_experiments/xai/__init__.py +0 -0
  73. {dlspit-2.2.0 → dlspit-2.4.0}/dl_experiments/xai/_common.py +0 -0
  74. {dlspit-2.2.0 → dlspit-2.4.0}/dl_experiments/xai/_plot.py +0 -0
  75. {dlspit-2.2.0 → dlspit-2.4.0}/dl_experiments/xai/decision_tree_knn.py +0 -0
  76. {dlspit-2.2.0 → dlspit-2.4.0}/dl_experiments/xai/grad_cam.py +0 -0
  77. {dlspit-2.2.0 → dlspit-2.4.0}/dl_experiments/xai/gradient_input.py +0 -0
  78. {dlspit-2.2.0 → dlspit-2.4.0}/dl_experiments/xai/ice.py +0 -0
  79. {dlspit-2.2.0 → dlspit-2.4.0}/dl_experiments/xai/lime.py +0 -0
  80. {dlspit-2.2.0 → dlspit-2.4.0}/dl_experiments/xai/lrp.py +0 -0
  81. {dlspit-2.2.0 → dlspit-2.4.0}/dl_experiments/xai/pdp.py +0 -0
  82. {dlspit-2.2.0 → dlspit-2.4.0}/dl_experiments/xai/regression.py +0 -0
  83. {dlspit-2.2.0 → dlspit-2.4.0}/dl_experiments/xai/shap.py +0 -0
  84. {dlspit-2.2.0 → dlspit-2.4.0}/dl_experiments/xai/xrai.py +0 -0
  85. {dlspit-2.2.0 → dlspit-2.4.0}/tests/conftest.py +0 -0
  86. {dlspit-2.2.0 → dlspit-2.4.0}/tests/test_genai_chatbot_diffusion_music.py +0 -0
  87. {dlspit-2.2.0 → dlspit-2.4.0}/tests/test_genai_images.py +0 -0
  88. {dlspit-2.2.0 → dlspit-2.4.0}/tests/test_genai_mini_gpt.py +0 -0
  89. {dlspit-2.2.0 → dlspit-2.4.0}/tests/test_genai_vae_gan.py +0 -0
  90. {dlspit-2.2.0 → dlspit-2.4.0}/tests/test_xai_neural.py +0 -0
  91. {dlspit-2.2.0 → dlspit-2.4.0}/tests/test_xai_tabular.py +0 -0
@@ -1,4 +1,57 @@
1
- # dlspit v2.2.0 — Multi-Domain Experiment Package
1
+ Metadata-Version: 2.5
2
+ Name: dlspit
3
+ Version: 2.4.0
4
+ Summary: A multi-domain experiment package: Deep Learning (MLP, CNN, ResNet, RNN, LSTM, Transformer, GAN, VAE), ML ESE Lab (regression, SVM, decision tree, random forest, XGBoost, k-means) Generative AI from scratch in NumPy (VAE, GAN, mini GPT, text-to-image, face swap, music, CycleGAN, chatbot, diffusion) and Explainable AI from scratch (SHAP, PDP, ICE, LIME, Grad-CAM, XRAI-style, Gradient x Input, LRP).
5
+ Project-URL: Repository, https://github.com/PrathamShid07/DL_Expts
6
+ Project-URL: Issues, https://github.com/PrathamShid07/DL_Expts/issues
7
+ Author: DLSPIT Team Open Source Contributor
8
+ License: MIT
9
+ Keywords: chatbot,clustering,cnn,cyclegan,decision-tree,deep-learning,diffusion,education,explainable-ai,from-scratch,gan,generative-ai,gpt,grad-cam,interpretability,kmeans,lime,lrp,lstm,machine-learning,mlp,neural-network,numpy,pytorch,random-forest,resnet,rnn,shap,sklearn,standalone-scripts,svm,tensorflow,transformer,vae,xai,xgboost
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Intended Audience :: Education
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
18
+ Requires-Python: >=3.10
19
+ Requires-Dist: numpy>=1.24
20
+ Provides-Extra: all
21
+ Requires-Dist: matplotlib>=3.6; extra == 'all'
22
+ Requires-Dist: pandas>=1.5; extra == 'all'
23
+ Requires-Dist: scikit-learn>=1.3; extra == 'all'
24
+ Requires-Dist: scipy>=1.9; extra == 'all'
25
+ Requires-Dist: seaborn>=0.12; extra == 'all'
26
+ Requires-Dist: tensorflow>=2.12; extra == 'all'
27
+ Requires-Dist: torch>=2.0; extra == 'all'
28
+ Requires-Dist: xgboost>=1.7; extra == 'all'
29
+ Provides-Extra: dev
30
+ Requires-Dist: build>=1.0; extra == 'dev'
31
+ Requires-Dist: hatchling>=1.18; extra == 'dev'
32
+ Requires-Dist: pytest>=7.0; extra == 'dev'
33
+ Requires-Dist: twine>=5.0; extra == 'dev'
34
+ Provides-Extra: dl
35
+ Requires-Dist: tensorflow>=2.12; extra == 'dl'
36
+ Provides-Extra: genai
37
+ Requires-Dist: matplotlib>=3.6; extra == 'genai'
38
+ Requires-Dist: scikit-learn>=1.3; extra == 'genai'
39
+ Requires-Dist: torch>=2.0; extra == 'genai'
40
+ Provides-Extra: ml-ese
41
+ Requires-Dist: matplotlib>=3.6; extra == 'ml-ese'
42
+ Requires-Dist: pandas>=1.5; extra == 'ml-ese'
43
+ Requires-Dist: scikit-learn>=1.3; extra == 'ml-ese'
44
+ Requires-Dist: seaborn>=0.12; extra == 'ml-ese'
45
+ Requires-Dist: xgboost>=1.7; extra == 'ml-ese'
46
+ Provides-Extra: sklearn
47
+ Requires-Dist: scikit-learn>=1.3; extra == 'sklearn'
48
+ Provides-Extra: xai
49
+ Requires-Dist: matplotlib>=3.6; extra == 'xai'
50
+ Requires-Dist: scikit-learn>=1.3; extra == 'xai'
51
+ Requires-Dist: scipy>=1.9; extra == 'xai'
52
+ Description-Content-Type: text/markdown
53
+
54
+ # dlspit v2.4.0 — Multi-Domain Experiment Package
2
55
 
3
56
  A pip-installable multi-domain experiment viewer and runner covering:
4
57
 
@@ -13,9 +66,9 @@ A pip-installable multi-domain experiment viewer and runner covering:
13
66
  regression, tree/KNN, SHAP, PDP, ICE, XRAI-style, Grad-CAM, LIME, Gradient × Input, LRP
14
67
  → see [Explainable AI experiments](#explainable-ai-experiments-dlspit-xai--new-in-v220)
15
68
 
16
- For the `DL` and `ML-ESE` domains, `dlspit` **prints the source code** of the selected experiment by default.
17
- Use `--run` to actually execute it. (The `GENAI` and `XAI` domains are the exception: `dlspit genai vae` and `dlspit xai shap` run
18
- immediately; add `--source` to print the code instead.)
69
+ For **all four domains** (`DL`, `ML-ESE`, `GENAI`, `XAI`) `dlspit` **prints the experiment** — aim, theory, formulas and the complete
70
+ code — by default, and `--run` executes it. For GenAI and XAI the printed code is a **standalone script**: copy it into Google Colab,
71
+ Jupyter or a `.py` file and it runs without this package (see [GenAI and XAI: show → copy → run](#genai-and-xai-show--copy--run)).
19
72
 
20
73
  ---
21
74
 
@@ -34,9 +87,10 @@ pip install "dlspit[ml-ese]"
34
87
  # Everything
35
88
  pip install "dlspit[all]"
36
89
 
37
- # Generative AI (dlspit genai ...) and Explainable AI (dlspit xai ...) experiments need nothing beyond the core install
38
- # Optional figures for the XAI experiments (--plot):
39
- pip install "dlspit[xai]"
90
+ # Showing any experiment (dlspit genai gan, dlspit xai shap, ...) needs nothing beyond the core install.
91
+ # To RUN the standalone GenAI / XAI scripts, install what each script lists under REQUIREMENTS:
92
+ pip install "dlspit[genai]" # torch, matplotlib, scikit-learn
93
+ pip install "dlspit[xai]" # scikit-learn, scipy, matplotlib (Grad-CAM and XRAI also need: pip install torch)
40
94
  ```
41
95
 
42
96
  ---
@@ -90,6 +144,120 @@ python -m dl_experiments ML-ESE --run random_forest
90
144
 
91
145
  ---
92
146
 
147
+ ## GenAI and XAI: show → copy → run
148
+
149
+ Every GenAI and XAI experiment is a **standalone script** that starts with its title, aim, theory and formulas and then
150
+ contains the complete code. `dlspit` prints it, exactly like it prints the ML-ESE experiments:
151
+
152
+ ```bash
153
+ dlspit genai gan # SHOW: title, aim, theory, formulas + the complete standalone code
154
+ dlspit genai gan --run # EXECUTE the very same script
155
+ dlspit xai shap # same for the XAI experiments
156
+ dlspit xai shap --run
157
+ dlspit genai --list # the names (also: dlspit xai --list)
158
+ ```
159
+
160
+ **Google Colab** (copy the code from the output into a cell and run it):
161
+
162
+ ```python
163
+ !pip install dlspit
164
+ !dlspit genai gan # shows the theory and the code
165
+ # ... copy the code into a new cell and run it - nothing else from dlspit is needed.
166
+ # Colab already has torch, scikit-learn, scipy and matplotlib. Or run it directly:
167
+ !dlspit genai gan --run
168
+ ```
169
+
170
+ In a notebook you can also display it nicely, with highlighting: `from dl_experiments import show_experiment; show_experiment("genai", "gan")`
171
+ (see the next section). In **VS Code** (or any editor) save the script with `dlspit genai gan --raw > gan.py` — `--raw` prints only the file, no banner —
172
+ and run `python gan.py`.
173
+
174
+ **Why the code can be copied:** the scripts import only NumPy, scikit-learn, scipy, matplotlib and (for the neural networks) PyTorch —
175
+ never `dl_experiments`. Figures appear with `plt.show()` when you paste the code into a notebook cell or run it as a script
176
+ (`!dlspit ... --run` in Colab runs in a separate process, so paste the code into a cell to *see the figures*; the printed results always appear).
177
+ Settings you may want to change are constants at the top of each script (`SEED`, `EPOCHS`, `INSTANCE`, ...).
178
+
179
+ | GenAI command | What the script shows | `pip install` | |
180
+ |---|---|---|---|
181
+ | `dlspit genai vae` | encoder → (μ, log σ²) → reparameterisation → decoder; reconstruction + KL loss; sampling and interpolation | `torch matplotlib numpy` | |
182
+ | `dlspit genai gan` | generator, discriminator, BCE losses, two optimisers, training loop, generated samples | `torch matplotlib numpy` | |
183
+ | `dlspit genai gpt` | tokenisation, embeddings, causal self-attention, next-word loss, training, text generation | `torch numpy` | |
184
+ | `dlspit genai text-to-image` | prompt → numbers → conditional VAE that draws 8×8 pictures | `torch matplotlib numpy` | |
185
+ | `dlspit genai face-swap` | one shared encoder + two decoders; swap = A's code through B's decoder | `torch matplotlib numpy` | |
186
+ | `dlspit genai music` | next-note model with a genre input, sine-wave synthesis, WAV files, spectrum analysis | `numpy scikit-learn matplotlib` | |
187
+ | `dlspit genai cyclegan` | two generators + two discriminators, adversarial + cycle loss | `torch matplotlib numpy` | |
188
+ | `dlspit genai chatbot` | bag-of-words intent classifier with an "I did not understand" fallback | `numpy scikit-learn` | |
189
+ | `dlspit genai diffusion` | forward noising, noise-prediction training, reverse sampling | `torch matplotlib numpy` | |
190
+
191
+ | XAI command | What the script shows | `pip install` |
192
+ |---|---|---|
193
+ | `dlspit xai regression` | R², adjusted R², t-statistics, 95 % CI, odds ratios | `numpy scipy scikit-learn` |
194
+ | `dlspit xai tree-knn` | decision-tree rules, impurity vs permutation importance, KNN neighbours and vote | `numpy scikit-learn matplotlib` |
195
+ | `dlspit xai shap` | exact Shapley values and permutation-sampling approximation | `numpy scikit-learn matplotlib` |
196
+ | `dlspit xai pdp` | partial dependence and PDP importance (numerical and categorical) | `numpy scikit-learn matplotlib` |
197
+ | `dlspit xai ice` | ICE curves, PDP = mean of ICE, centred ICE | `numpy scikit-learn matplotlib` |
198
+ | `dlspit xai xrai` | Integrated Gradients → fixed-grid regions → ranking (**XRAI-style**, not full XRAI) | `torch matplotlib numpy` |
199
+ | `dlspit xai grad-cam` | gradients × feature maps → class heat map | `torch matplotlib numpy` |
200
+ | `dlspit xai lime` | perturb, weight, weighted least squares | `numpy scikit-learn matplotlib` |
201
+ | `dlspit xai gradient-input` | CBOW embeddings and Gradient × Input | `numpy scikit-learn` |
202
+ | `dlspit xai lrp` | LRP-ε, relevance conservation | `numpy scikit-learn` |
203
+
204
+ If a package is missing, `--run` says which one and prints the `pip install` line. All scripts use small synthetic data (nothing is downloaded,
205
+ no pretrained model is used), fixed random seeds, and finish in roughly 1–15 seconds on a laptop CPU (no GPU needed; the first run is slower while PyTorch loads).
206
+
207
+ **Also available:** the original parameterised implementations that need only NumPy (hand-written back-propagation, `--epochs`, `--samples`, ... ,
208
+ and the Python API `dl_experiments.genai.vae.run_experiment(...)`) are still there: add `--library`, e.g.
209
+ `dlspit genai vae --library --epochs 50` or `dlspit xai pdp --library --feature 1 --plot`; `dlspit genai vae --library --source` prints that code.
210
+ The sections "Generative AI experiments" and "Explainable AI experiments" further below describe this library version (and contain
211
+ viva questions and exam modifications that apply to both).
212
+
213
+ ---
214
+
215
+ ## Read an experiment in Google Colab / Jupyter
216
+
217
+ Install the package in a notebook and call one function. The cell output shows the experiment's **theory** followed by its
218
+ **complete Python source code** (syntax-highlighted), exactly as stored in the package. Nothing is executed and nothing is
219
+ rewritten: the theory is the header docstring of the experiment's `.py` file (GenAI, XAI: title, aim, theory, formulas) or its leading
220
+ `# THEORY` comment block (DL, ML-ESE), and the code is the file itself. For GenAI and XAI that file is the standalone script, so the
221
+ code you see runs when you paste it into a cell.
222
+
223
+ ```python
224
+ !pip install dlspit
225
+
226
+ from dl_experiments import show_experiment
227
+
228
+ show_experiment("genai", "chatbot") # theory + full source of the chatbot experiment
229
+ show_experiment("xai", "shap") # domains: "genai", "xai", "dl", "ml-ese"
230
+ show_experiment("dl", "4CNN")
231
+ show_experiment("ml-ese", "decision_tree")
232
+ ```
233
+
234
+ Useful options:
235
+
236
+ ```python
237
+ show_experiment("xai", "grad-cam", code=False) # theory only
238
+ show_experiment("xai", "grad-cam", theory=False) # code only
239
+ show_experiment("xai", "lrp", output="text") # force plain text (default: HTML in a notebook, text in a terminal)
240
+ ```
241
+
242
+ The valid names are listed by `dl_experiments.genai.list_experiments()`, `dl_experiments.xai.list_experiments()`,
243
+ `dl_experiments.dl.list_experiments()` and `dl_experiments.ml_ese.list_experiments()`; the same aliases as the command line work
244
+ (`"gradcam"`, `"text_to_image"`, ...). An invalid name raises an error that lists the valid ones.
245
+
246
+ To get the text itself (for example to copy it into a journal, or to print it):
247
+
248
+ ```python
249
+ from dl_experiments import get_theory, get_source
250
+
251
+ print(get_theory("genai", "chatbot")) # the explanation only
252
+ print(get_source("genai", "chatbot")) # the complete file
253
+ ```
254
+
255
+ Syntax highlighting uses Pygments, which Colab and Jupyter already include (without it the code is shown as plain monospaced
256
+ text); no extra package is required. To *run* an experiment instead of reading it, use `dlspit genai chatbot` or
257
+ `from dl_experiments.genai.chatbot import run_experiment`.
258
+
259
+ ---
260
+
93
261
  ## DL Experiment Index
94
262
 
95
263
  | Key | Description |
@@ -156,20 +324,26 @@ run_experiment("decision_tree") # executes (requires scikit-learn)
156
324
  | core | `numpy>=1.24` | Always |
157
325
  | `dl` | `tensorflow>=2.12` | Running DL experiments |
158
326
  | `ml-ese` | `scikit-learn`, `pandas`, `matplotlib`, `seaborn`, `xgboost` | Running ML-ESE experiments |
159
- | *(none)* | NumPy only (core) | Running the GenAI and XAI experiments |
160
- | `xai` | `matplotlib>=3.6` | Optional XAI figures (`--plot`) |
327
+ | *(none)* | NumPy only (core) | Showing any experiment; running the `--library` GenAI / XAI versions |
328
+ | `genai` | `torch`, `matplotlib`, `scikit-learn` | Running the standalone GenAI scripts (`--run`, or paste them) |
329
+ | `xai` | `scikit-learn`, `scipy`, `matplotlib` | Running the standalone XAI scripts (Grad-CAM, XRAI also need `torch`) |
161
330
 
162
331
  ---
163
332
 
164
333
  # Generative AI experiments (`dlspit genai`) — new in v2.1.0
165
334
 
166
- Nine Generative AI experiments, implemented **from scratch in Python + NumPy** and designed for
335
+ > **Which version is this section about?** `dlspit genai <name>` now shows the **standalone script** (PyTorch / scikit-learn; see
336
+ > [show → copy → run](#genai-and-xai-show--copy--run)). This section describes the original **NumPy-only library version**
337
+ > (`--library`, Python API `dl_experiments.genai.<module>`), including the educational substitutions, viva questions and exam
338
+ > modifications, which apply to both. Function names in the "code walk-through" lines refer to the library modules.
339
+
340
+ Nine Generative AI experiments, implemented **from scratch in Python + NumPy** (library version) and designed for
167
341
  college practical examinations:
168
342
 
169
343
  * **No pretrained models** — nothing is loaded from TensorFlow Hub, Hugging Face, PyTorch Hub, an API, …
170
344
  * **No dataset downloads** — every experiment builds a small synthetic dataset in code.
171
345
  * **No internet, no API keys, no GPU** — each experiment runs in seconds on a laptop.
172
- * **No TensorFlow / PyTorch needed** — the networks use a tiny NumPy toolkit with hand-written back-propagation
346
+ * **No TensorFlow / PyTorch needed (library version)** — the networks use a tiny NumPy toolkit with hand-written back-propagation
173
347
  (`dl_experiments/genai/_nn.py`, about 350 lines, gradient-checked in the tests).
174
348
  * **Short, commented code** — one file per experiment, split into *data → model → training → demo*.
175
349
 
@@ -180,7 +354,8 @@ college practical examinations:
180
354
  ## A. Installation
181
355
 
182
356
  ```bash
183
- pip install dlspit # this is all you need for the GenAI experiments (NumPy only)
357
+ pip install dlspit # enough for the --library versions and for showing any experiment (NumPy only)
358
+ pip install "dlspit[genai]" # to RUN the standalone scripts: torch, matplotlib, scikit-learn
184
359
 
185
360
  # optional extras of the other domains are unchanged:
186
361
  pip install "dlspit[dl]" # TensorFlow, for the original DL experiments
@@ -207,7 +382,7 @@ The numbering follows the PDFs in `Genai/Expt Done Docs/`.
207
382
  | 8 | Chatbot | bag-of-words intent classifier with an "unknown" fallback | `dl_experiments.genai.chatbot` | `dlspit genai chatbot` |
208
383
  | 9 | Diffusion (DDPM) | forward noising, noise prediction, reverse sampling, schedules, guidance | `dl_experiments.genai.diffusion` | `dlspit genai diffusion` |
209
384
 
210
- **Required optional dependencies: none** (NumPy only) for all nine.
385
+ **Dependencies of the library versions: none** (NumPy only). The standalone scripts need the packages listed in the table above.
211
386
 
212
387
  ### Educational substitutions (what the lab document uses → what is implemented here)
213
388
 
@@ -228,23 +403,24 @@ The numbering follows the PDFs in `Genai/Expt Done Docs/`.
228
403
  ### Command line
229
404
 
230
405
  ```bash
231
- dlspit genai --list # the nine experiments
232
- dlspit genai vae # RUN an experiment (GenAI keys run by default)
233
- dlspit genai gan --epochs 100 # change a parameter
234
- dlspit genai diffusion --samples 1000 --seed 3
235
- dlspit genai music --save-dir out # also write WAV / PNG files into ./out
236
- dlspit genai gpt --source # print the source code instead of running
237
- dlspit genai vae gan # several experiments in a row
238
- dlspit genai chatbot # interactive chat; type 'exit' to stop
239
- dlspit genai chatbot --demo # scripted conversation instead
240
- python -m dl_experiments genai vae # same thing without the console script
406
+ dlspit genai --list # the nine experiments
407
+ dlspit genai vae # SHOW the standalone script (theory + code)
408
+ dlspit genai vae --run # run that script
409
+ dlspit genai vae --library # RUN the NumPy-only library version
410
+ dlspit genai gan --library --epochs 100 # ... and change a parameter (options need --library)
411
+ dlspit genai diffusion --library --samples 1000 --seed 3
412
+ dlspit genai music --library --save-dir out # also write WAV / PNG files into ./out
413
+ dlspit genai gpt --library --source # print the LIBRARY source code
414
+ dlspit genai chatbot --library # interactive chat (library); type 'exit' to stop
415
+ dlspit genai chatbot --library --demo # scripted conversation instead
416
+ python -m dl_experiments genai vae # same thing without the console script
241
417
  ```
242
418
 
243
419
  Names are case-insensitive and accept `_`/`-` and a few aliases (`mini_gpt`, `text_to_image`, `faceswap`, `ddpm`, or the
244
420
  experiment number `1`–`9`). Options: `--epochs`, `--samples` (size of the synthetic training set), `--seed`,
245
- `--save-dir`, `--demo` (chatbot only), `--source`. An option an experiment does not have (for example `--samples` for
246
- `gpt`) produces a clear error. **Unlike `DL` and `ML-ESE`, which print source code unless `--run` is given, GenAI keys run
247
- immediately**; use `--source` to read the code.
421
+ `--save-dir`, `--demo` (chatbot only), `--source`. These options apply to the library version, so they require `--library`
422
+ (without it the command explains this and exits). An option an experiment does not have (for example `--samples` for `gpt`)
423
+ produces a clear error. The standalone scripts have their settings as constants at the top of the file.
248
424
 
249
425
  ### Python
250
426
 
@@ -679,14 +855,20 @@ of Part 3 is *not* included because it needs pretrained weights. Sample quality
679
855
 
680
856
  # Explainable AI experiments (`dlspit xai`) — new in v2.2.0
681
857
 
682
- Ten Explainable AI (XAI) experiments, implemented **from scratch in Python + NumPy** for college practical examinations.
858
+ > **Which version is this section about?** `dlspit xai <name>` now shows the **standalone script** (scikit-learn, and PyTorch for Grad-CAM
859
+ > and XRAI; see [show → copy → run](#genai-and-xai-show--copy--run)). This section describes the original **NumPy-only library version**
860
+ > (`--library`, Python API `dl_experiments.xai.<module>`) with its viva questions and exam modifications, which apply to both.
861
+ > The standalone scripts use scikit-learn models and `torch` where this section says "NumPy only", and they have no `plot=` argument
862
+ > (their figures are always drawn).
863
+
864
+ Ten Explainable AI (XAI) experiments, implemented **from scratch in Python + NumPy** (library version) for college practical examinations.
683
865
  Every explanation method (Shapley values, PDP, ICE, LIME, Grad-CAM, Integrated Gradients / XRAI-style regions,
684
866
  Gradient × Input, LRP, …) is written out in the module itself, and each one is applied to a small model that is
685
867
  **trained here on synthetic data**.
686
868
 
687
869
  * **No pretrained models** and **no dataset downloads** — nothing is fetched from Kaggle, scikit-learn, TensorFlow Hub, etc.; no internet is needed.
688
- * **No XAI libraries** — the `shap`, `lime`, `captum`, … packages are *not* used (a test checks the imports), and neither are scikit-learn or scipy.
689
- * **NumPy only** — plots are optional (`pip install "dlspit[xai]"` adds Matplotlib). The neural networks reuse the small NumPy toolkit of the GenAI package (`dl_experiments/genai/_nn.py`).
870
+ * **No XAI libraries** — the `shap`, `lime`, `captum`, … packages are *not* used (a test checks the imports). The library version does not use scikit-learn or scipy either; the standalone scripts do use scikit-learn / scipy for ordinary model training and the t-distribution.
871
+ * **NumPy only (library version)** — plots are optional (`pip install "dlspit[xai]"` adds Matplotlib). The neural networks reuse the small NumPy toolkit of the GenAI package (`dl_experiments/genai/_nn.py`).
690
872
  * **Short, commented, modifiable code** — one file per experiment: data → model → explanation → demonstration.
691
873
 
692
874
  > **Honest scope.** These are *educational* implementations on toy models. They show how each algorithm works and are
@@ -696,8 +878,8 @@ Gradient × Input, LRP, …) is written out in the module itself, and each one i
696
878
  ## A. Installation
697
879
 
698
880
  ```bash
699
- pip install dlspit # enough to run all ten XAI experiments (text output)
700
- pip install "dlspit[xai]" # adds matplotlib, only needed for the optional figures (--plot / plot=True)
881
+ pip install dlspit # enough for the --library versions and for showing any experiment
882
+ pip install "dlspit[xai]" # to RUN the standalone scripts: scikit-learn, scipy, matplotlib (+ pip install torch for grad-cam / xrai)
701
883
  pip install "dlspit[all]" # everything (TensorFlow, scikit-learn, pandas, matplotlib, ...)
702
884
  ```
703
885
 
@@ -744,25 +926,26 @@ The numbering follows the PDFs in `XAI/expt_details/`. The completed notebooks/P
744
926
  ### Command line
745
927
 
746
928
  ```bash
747
- dlspit xai --list # the ten experiments
748
- dlspit xai shap # RUN an experiment (XAI keys run by default)
749
- dlspit xai shap --instance 5 # explain a different test row
750
- dlspit xai pdp --feature 1 --epochs 200 --plot # choose the feature; also draw a figure
751
- dlspit xai tree-knn --k 7 --instance 3
752
- dlspit xai grad-cam --target 0 # explain class 0 only
753
- dlspit xai lrp --target 0 --instance 4
754
- dlspit xai grad-cam --save-dir out # also write PNG files into ./out
755
- dlspit xai lrp --source # print the source code instead of running it
756
- dlspit xai ice xrai # several experiments in a row
757
- python -m dl_experiments xai lime # same thing without the console script
929
+ dlspit xai --list # the ten experiments
930
+ dlspit xai shap # SHOW the standalone script (theory + code)
931
+ dlspit xai shap --run # run that script
932
+ dlspit xai shap --library --instance 5 # NumPy-only library version; options need --library
933
+ dlspit xai pdp --library --feature 1 --epochs 200 --plot # choose the feature; also draw a figure
934
+ dlspit xai tree-knn --library --k 7 --instance 3
935
+ dlspit xai grad-cam --library --target 0 # explain class 0 only
936
+ dlspit xai lrp --library --target 0 --instance 4
937
+ dlspit xai grad-cam --library --save-dir out # also write PNG files into ./out
938
+ dlspit xai lrp --library --source # print the LIBRARY source code
939
+ dlspit xai ice xrai # several experiments in a row (shown)
940
+ python -m dl_experiments xai lime # same thing without the console script
758
941
  ```
759
942
 
760
943
  Names are case-insensitive and accept aliases (`knn`, `gradcam`, `gxi`, `linear`, `shapley`, …) or the experiment number `1`–`10`.
761
944
  Command-line options: `--epochs`, `--samples` (size of the synthetic data set), `--seed`, `--save-dir`, `--feature` (pdp, ice),
762
945
  `--target` (grad-cam, xrai, gradient-input, lrp), `--instance` (shap, lime, gradient-input, lrp, tree-knn), `--k` (tree-knn), `--plot`, `--source`.
763
- An option that an experiment does not have (for example `--epochs` for `regression`) produces a clear error. Parameters such as
764
- `epsilon`, `rule`, `kernel_width`, `grid`, `steps`, `n_grid`, `n_permutations` are Python arguments (see below). **Unlike `DL` and `ML-ESE`, XAI keys run
765
- immediately**; use `--source` to read the code.
946
+ These options apply to the library version and therefore require `--library`. An option that an experiment does not have (for example
947
+ `--epochs` for `regression`) produces a clear error. Parameters such as `epsilon`, `rule`, `kernel_width`, `grid`, `steps`, `n_grid`,
948
+ `n_permutations` are Python arguments of the library (see below); in the standalone scripts they are constants at the top of the file.
766
949
 
767
950
  ### Python
768
951