dl-doctor 0.2.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.
- dl_doctor-0.2.0/CHANGELOG.md +22 -0
- dl_doctor-0.2.0/CITATION.cff +23 -0
- dl_doctor-0.2.0/LICENSE +21 -0
- dl_doctor-0.2.0/MANIFEST.in +5 -0
- dl_doctor-0.2.0/PKG-INFO +220 -0
- dl_doctor-0.2.0/README.md +181 -0
- dl_doctor-0.2.0/docs/CODES.md +516 -0
- dl_doctor-0.2.0/docs/GUIDE.fa.md +269 -0
- dl_doctor-0.2.0/examples/01_quickstart.py +48 -0
- dl_doctor-0.2.0/examples/02_numpy_mlp_from_scratch.py +118 -0
- dl_doctor-0.2.0/examples/03_data_checks.py +42 -0
- dl_doctor-0.2.0/examples/04_fairness_and_deployment.py +36 -0
- dl_doctor-0.2.0/examples/05_pytorch.py +44 -0
- dl_doctor-0.2.0/examples/06_keras.py +27 -0
- dl_doctor-0.2.0/examples/07_reports_plots_and_cli.py +52 -0
- dl_doctor-0.2.0/examples/README.md +18 -0
- dl_doctor-0.2.0/pyproject.toml +59 -0
- dl_doctor-0.2.0/setup.cfg +4 -0
- dl_doctor-0.2.0/src/dl_doctor.egg-info/PKG-INFO +220 -0
- dl_doctor-0.2.0/src/dl_doctor.egg-info/SOURCES.txt +45 -0
- dl_doctor-0.2.0/src/dl_doctor.egg-info/dependency_links.txt +1 -0
- dl_doctor-0.2.0/src/dl_doctor.egg-info/entry_points.txt +2 -0
- dl_doctor-0.2.0/src/dl_doctor.egg-info/requires.txt +8 -0
- dl_doctor-0.2.0/src/dl_doctor.egg-info/top_level.txt +1 -0
- dl_doctor-0.2.0/src/dldoctor/__init__.py +64 -0
- dl_doctor-0.2.0/src/dldoctor/__main__.py +5 -0
- dl_doctor-0.2.0/src/dldoctor/checks/__init__.py +40 -0
- dl_doctor-0.2.0/src/dldoctor/checks/data.py +135 -0
- dl_doctor-0.2.0/src/dldoctor/checks/deploy.py +61 -0
- dl_doctor-0.2.0/src/dldoctor/checks/fairness.py +54 -0
- dl_doctor-0.2.0/src/dldoctor/checks/network.py +64 -0
- dl_doctor-0.2.0/src/dldoctor/checks/torch_check.py +55 -0
- dl_doctor-0.2.0/src/dldoctor/checks/training.py +125 -0
- dl_doctor-0.2.0/src/dldoctor/cli.py +167 -0
- dl_doctor-0.2.0/src/dldoctor/diagnose.py +59 -0
- dl_doctor-0.2.0/src/dldoctor/explain.py +352 -0
- dl_doctor-0.2.0/src/dldoctor/findings.py +194 -0
- dl_doctor-0.2.0/src/dldoctor/messages.py +222 -0
- dl_doctor-0.2.0/src/dldoctor/persian.py +264 -0
- dl_doctor-0.2.0/src/dldoctor/plots.py +201 -0
- dl_doctor-0.2.0/src/dldoctor/py.typed +0 -0
- dl_doctor-0.2.0/src/dldoctor/recorder.py +45 -0
- dl_doctor-0.2.0/src/dldoctor/render.py +129 -0
- dl_doctor-0.2.0/tests/test_checks.py +277 -0
- dl_doctor-0.2.0/tests/test_persian_and_cli.py +106 -0
- dl_doctor-0.2.0/tests/test_plots.py +41 -0
- dl_doctor-0.2.0/tests/test_v020.py +214 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.2.0 (2026-11-08)
|
|
4
|
+
|
|
5
|
+
- New checks: `GRAD_VANISHING`, `GRAD_EXPLODING` (`check_gradient_norms`, `gradient_norms(model)`) and
|
|
6
|
+
`DEAD_RELU` (`check_activations`).
|
|
7
|
+
- `dldoctor explain CODE` / `dldoctor list [--md]` and `dldoctor.explain()`: why each finding happens and how
|
|
8
|
+
to fix it, in Persian and English, for all 28 codes.
|
|
9
|
+
- Reports: `Report.to_html()`, `to_markdown()`, `save(path)` and `dldoctor report FILE --out report.html`.
|
|
10
|
+
The HTML page is self-contained, RTL/LTR aware and dark-mode friendly.
|
|
11
|
+
- Full Persian guide (`docs/GUIDE.fa.md`), generated code reference (`docs/CODES.md`) and seven runnable
|
|
12
|
+
examples (`examples/`), including a NumPy network trained four ways.
|
|
13
|
+
- CLI reads UTF-8 BOM and UTF-16 files (PowerShell) and explains quoted-JSON mistakes from Windows `echo`.
|
|
14
|
+
- **Fix:** learning-rate findings (`TRAIN_NONFINITE`, `LR_*`) pointed to book chapter 5; the topic is covered in
|
|
15
|
+
chapter 8 (optimisers).
|
|
16
|
+
|
|
17
|
+
## 0.1.0 (2026-11-07)
|
|
18
|
+
|
|
19
|
+
- First release: training-curve, data, fairness, digit-image and PyTorch-module checks with Persian and English messages.
|
|
20
|
+
- Persian-ready matplotlib plots (`plot_history`, `plot_confusion_matrix`, `plot_group_rates`) with a built-in
|
|
21
|
+
fallback shaper for matplotlib versions that cannot join Arabic-script text.
|
|
22
|
+
- `dldoctor` command line and `HistoryRecorder` helper.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
cff-version: 1.2.0
|
|
2
|
+
message: "If you use this software, please cite it as below."
|
|
3
|
+
title: "dl-doctor: bilingual diagnostics for deep-learning training"
|
|
4
|
+
version: 0.2.0
|
|
5
|
+
date-released: 2026-11-08
|
|
6
|
+
license: MIT
|
|
7
|
+
authors:
|
|
8
|
+
- alias: "Tirotir"
|
|
9
|
+
repository-code: "https://github.com/worker2025/dl-doctor"
|
|
10
|
+
url: "https://tirotir.com"
|
|
11
|
+
# Add the book's DOI under `references` once it is issued.
|
|
12
|
+
references:
|
|
13
|
+
- type: book
|
|
14
|
+
title: "یادگیری عمیق؛ با پروژههای کاربردی برای مربیان و علاقهمندان کارگاههای هوش مصنوعی"
|
|
15
|
+
authors:
|
|
16
|
+
- name: "دکتر داریوش علیپور"
|
|
17
|
+
- name: "دکتر مینوش حیدری"
|
|
18
|
+
publisher:
|
|
19
|
+
name: "انتشارات علیپور (تیروتیر)"
|
|
20
|
+
year: 2026
|
|
21
|
+
edition: "اول"
|
|
22
|
+
license: CC-BY-NC-4.0
|
|
23
|
+
url: "https://github.com/worker2025/DL_book"
|
dl_doctor-0.2.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 tirotir
|
|
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.
|
dl_doctor-0.2.0/PKG-INFO
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: dl-doctor
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Bilingual (Persian/English) doctor for deep-learning training: finds common mistakes, explains why and how to fix them. By Tirotir.com
|
|
5
|
+
Author: Tirotir
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://tirotir.com
|
|
8
|
+
Project-URL: Documentation, https://github.com/worker2025/dl-doctor/blob/main/docs/GUIDE.fa.md
|
|
9
|
+
Project-URL: Changelog, https://github.com/worker2025/dl-doctor/blob/main/CHANGELOG.md
|
|
10
|
+
Project-URL: Book website, https://tirotir.ir
|
|
11
|
+
Project-URL: Repository, https://github.com/worker2025/dl-doctor
|
|
12
|
+
Project-URL: Issues, https://github.com/worker2025/dl-doctor/issues
|
|
13
|
+
Project-URL: Companion book, https://github.com/worker2025/DL_book
|
|
14
|
+
Keywords: deep-learning,training,diagnostics,debugging,persian,farsi,matplotlib,rtl,fairness,education,pytorch,keras,tirotir
|
|
15
|
+
Classifier: Development Status :: 3 - Alpha
|
|
16
|
+
Classifier: Intended Audience :: Developers
|
|
17
|
+
Classifier: Intended Audience :: Education
|
|
18
|
+
Classifier: Intended Audience :: Science/Research
|
|
19
|
+
Classifier: Natural Language :: English
|
|
20
|
+
Classifier: Natural Language :: Persian
|
|
21
|
+
Classifier: Programming Language :: Python :: 3
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
25
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
26
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
27
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
28
|
+
Classifier: Typing :: Typed
|
|
29
|
+
Requires-Python: >=3.9
|
|
30
|
+
Description-Content-Type: text/markdown
|
|
31
|
+
License-File: LICENSE
|
|
32
|
+
Requires-Dist: numpy>=1.21
|
|
33
|
+
Provides-Extra: plots
|
|
34
|
+
Requires-Dist: matplotlib>=3.5; extra == "plots"
|
|
35
|
+
Provides-Extra: dev
|
|
36
|
+
Requires-Dist: pytest>=7; extra == "dev"
|
|
37
|
+
Requires-Dist: matplotlib>=3.5; extra == "dev"
|
|
38
|
+
Dynamic: license-file
|
|
39
|
+
|
|
40
|
+
# dl-doctor
|
|
41
|
+
|
|
42
|
+
**A bilingual (Persian / English) doctor for deep-learning training.** *By [Tirotir.com](https://tirotir.com)*
|
|
43
|
+
|
|
44
|
+
`dl-doctor` reads your training curves, datasets, predictions, gradients and models and tells you what is
|
|
45
|
+
probably wrong, **why it happens and how to fix it**, in Persian and English: a learning rate that is too high,
|
|
46
|
+
overfitting, test-set leakage through normalisation, vanishing gradients, dead ReLUs, an inverted digit image,
|
|
47
|
+
a model left in training mode. It also writes shareable HTML reports and draws loss curves, confusion matrices
|
|
48
|
+
and group-rate charts with correctly joined right-to-left Persian text.
|
|
49
|
+
|
|
50
|
+
Built as a companion to the Persian book
|
|
51
|
+
*یادگیری عمیق؛ با پروژههای کاربردی برای مربیان و علاقهمندان کارگاههای هوش مصنوعی*
|
|
52
|
+
(Dr. Dariush Alipour and Dr. Minoosh Heidari); each finding points to the book chapter that covers the topic.
|
|
53
|
+
The library does **not** depend on the book and works with any PyTorch / Keras / NumPy workflow.
|
|
54
|
+
|
|
55
|
+
- Core dependency: NumPy only. PyTorch, Keras and matplotlib are optional and never imported unless you use them.
|
|
56
|
+
- Python 3.9+.
|
|
57
|
+
- 📘 **Full Persian guide:** [docs/GUIDE.fa.md](docs/GUIDE.fa.md) · 📋 all codes: [docs/CODES.md](docs/CODES.md) ·
|
|
58
|
+
🧪 [examples/](examples/)
|
|
59
|
+
|
|
60
|
+
## Install
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
pip install dl-doctor # diagnostics only
|
|
64
|
+
pip install "dl-doctor[plots]" # + matplotlib plots
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Quick start
|
|
68
|
+
|
|
69
|
+
```python
|
|
70
|
+
import dldoctor as dd
|
|
71
|
+
|
|
72
|
+
history = {
|
|
73
|
+
"loss": [1.0, 0.8, 0.6, 0.5, 0.4, 0.3, 0.2, 0.1],
|
|
74
|
+
"val_loss": [1.0, 0.8, 0.7, 0.75, 0.8, 0.9, 1.0, 1.1],
|
|
75
|
+
}
|
|
76
|
+
report = dd.diagnose(history=history)
|
|
77
|
+
print(report) # English + Persian
|
|
78
|
+
report.to_text("fa") # Persian only
|
|
79
|
+
report.save("report.html") # shareable page with explanations and fixes
|
|
80
|
+
report.raise_for_errors() # raise TrainingProblem if any ERROR finding
|
|
81
|
+
|
|
82
|
+
print(dd.explain("OVERFITTING_VAL_RISING")) # why it happens, how to fix it
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Everything at once; every argument is optional:
|
|
86
|
+
|
|
87
|
+
```python
|
|
88
|
+
report = dd.diagnose(
|
|
89
|
+
history=history, # dict, Keras History or HistoryRecorder
|
|
90
|
+
X_train=X_train, y_train=y_train, X_test=X_test, # leakage, scaling, class balance
|
|
91
|
+
y_pred=y_pred, groups=gender, # statistical parity
|
|
92
|
+
model=model, model_expect="eval", # PyTorch-like module
|
|
93
|
+
grad_norms=dd.gradient_norms(model), # vanishing / exploding gradients
|
|
94
|
+
activations=hidden_output, # dead ReLUs
|
|
95
|
+
digit_image=img28x28, # MNIST-style deployment check
|
|
96
|
+
)
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
In a hand-written loop:
|
|
100
|
+
|
|
101
|
+
```python
|
|
102
|
+
rec = dd.HistoryRecorder()
|
|
103
|
+
for epoch in range(epochs):
|
|
104
|
+
...
|
|
105
|
+
rec.log(loss=train_loss, val_loss=val_loss, accuracy=train_acc, val_accuracy=val_acc)
|
|
106
|
+
print(rec.diagnose())
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### What it checks (28 codes)
|
|
110
|
+
|
|
111
|
+
| Area | Finding codes |
|
|
112
|
+
|------|---------------|
|
|
113
|
+
| Training curves | `TRAIN_NONFINITE`, `LR_DIVERGING`, `LR_OSCILLATING`, `LR_STALLED`, `OVERFITTING_VAL_RISING`, `OVERFITTING_GAP`, `NO_VALIDATION_METRICS` |
|
|
114
|
+
| Network internals | `GRAD_VANISHING`, `GRAD_EXPLODING`, `DEAD_RELU` |
|
|
115
|
+
| Data | `DATA_NONFINITE`, `DATA_SPLIT_OVERLAP`, `NORM_FIT_ON_FULL_DATA`, `NORM_PER_SPLIT`, `DATA_UNSCALED`, `CLASS_IMBALANCE` |
|
|
116
|
+
| Fairness | `FAIRNESS_PARITY`, `FAIRNESS_OK` |
|
|
117
|
+
| Deployment | `DIGIT_SHAPE`, `DIGIT_BLANK`, `DIGIT_RANGE`, `DIGIT_BACKGROUND`, `DIGIT_SIZE`, `DIGIT_OFF_CENTER` |
|
|
118
|
+
| Frameworks | `TORCH_TRAIN_MODE`, `TORCH_EVAL_MODE_IN_TRAINING`, `TORCH_NONFINITE_PARAMS` |
|
|
119
|
+
|
|
120
|
+
Each `Finding` has `code`, `severity` (`INFO` / `WARNING` / `ERROR`), `message_fa`, `message_en`, `chapter`
|
|
121
|
+
and `details`. The checks are heuristics: a warning is a hint to look, not proof of a bug. Fairness output in
|
|
122
|
+
particular is one metric among several and never a verdict on its own.
|
|
123
|
+
|
|
124
|
+
## Persian plots
|
|
125
|
+
|
|
126
|
+
```python
|
|
127
|
+
from dldoctor.plots import plot_history, plot_confusion_matrix, plot_group_rates
|
|
128
|
+
|
|
129
|
+
plot_history(history, lang="fa", save="curves.png")
|
|
130
|
+
plot_confusion_matrix(y_true, y_pred, labels=["گربه", "سگ", "پرنده"], save="cm.png")
|
|
131
|
+
plot_group_rates({"الف": 0.80, "ب": 0.45}, save="rates.png")
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
Recent matplotlib releases join and reorder Arabic-script text themselves; `dl-doctor` detects this at run time.
|
|
135
|
+
On older releases it falls back to a built-in, dependency-free shaper (`dldoctor.shape_text`) that works for short
|
|
136
|
+
labels. Persian digits are used automatically. For the best look install a Persian font such as Vazirmatn;
|
|
137
|
+
otherwise DejaVu Sans is used.
|
|
138
|
+
|
|
139
|
+
## Command line
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
dldoctor check history.json # or .csv; exit status 1 on ERROR (--fail-on warning|never)
|
|
143
|
+
dldoctor check history.json --lang fa --json
|
|
144
|
+
dldoctor report history.json --out report.html # .html, .md or .json
|
|
145
|
+
dldoctor explain LR_DIVERGING # why + how to fix, fa and en
|
|
146
|
+
dldoctor list # every code (add --md for the full reference)
|
|
147
|
+
dldoctor check-digit digit.npy # a 28x28 image saved with numpy
|
|
148
|
+
dldoctor plot history.json --out curves.png
|
|
149
|
+
dldoctor demo
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## Examples
|
|
153
|
+
|
|
154
|
+
| File | Shows |
|
|
155
|
+
|------|-------|
|
|
156
|
+
| `01_quickstart.py` | six common mistakes diagnosed in one call each |
|
|
157
|
+
| `02_numpy_mlp_from_scratch.py` | a tiny NumPy network trained four ways: clean, diverging, overfitting, dead ReLU |
|
|
158
|
+
| `03_data_checks.py` | leakage, wrong normalisation, duplicates, imbalance, unscaled pixels |
|
|
159
|
+
| `04_fairness_and_deployment.py` | statistical parity and digit-image deployment mistakes |
|
|
160
|
+
| `05_pytorch.py`, `06_keras.py` | framework loops (need torch / tensorflow) |
|
|
161
|
+
| `07_reports_plots_and_cli.py` | HTML/Markdown reports, `explain`, Persian plots, CLI |
|
|
162
|
+
|
|
163
|
+
## Limitations
|
|
164
|
+
|
|
165
|
+
- The PyTorch checks are duck-typed (`model.training`, `model.named_parameters()`, `param.grad`); they were tested
|
|
166
|
+
with stand-in objects, not against every PyTorch release. Examples 05 and 06 need real torch / tensorflow and are
|
|
167
|
+
not part of the automated tests.
|
|
168
|
+
- `check_split_overlap` compares rows bit-for-bit, so it finds exact duplicates only.
|
|
169
|
+
- Normalisation checks need at least 30 rows in each split and standardised (mean 0, std 1) data.
|
|
170
|
+
|
|
171
|
+
---
|
|
172
|
+
|
|
173
|
+
## فارسی
|
|
174
|
+
|
|
175
|
+
`dl-doctor` منحنی آموزش، دادهها، پیشبینیها، گرادیانها و مدل شما را بررسی میکند و به **فارسی و انگلیسی** میگوید
|
|
176
|
+
چه چیزی احتمالاً مشکل دارد، **چرا رخ میدهد و چطور درستش کنیم**: نرخ یادگیری بزرگ، بیشبرازش، نشت داده در نرمالسازی، محو
|
|
177
|
+
گرادیان، ReLU مرده، تصویر وارونهٔ رقم دستنویس، یا مدلی که در حالت آموزش مانده است. گزارش HTML قابل اشتراک میسازد و
|
|
178
|
+
نمودارها (منحنی هزینه، ماتریس درهمریختگی، نرخ گروهها) را با متن فارسیِ درست رسم میکند.
|
|
179
|
+
|
|
180
|
+
هر یافته به فصل مربوط در کتاب «یادگیری عمیق؛ با پروژههای کاربردی برای مربیان و علاقهمندان کارگاههای هوش مصنوعی»
|
|
181
|
+
(دکتر داریوش علیپور – دکتر مینوش حیدری) ارجاع میدهد؛ ولی کتابخانه به کتاب وابسته نیست و با هر پروژهٔ PyTorch / Keras / NumPy
|
|
182
|
+
کار میکند.
|
|
183
|
+
|
|
184
|
+
📘 **راهنمای کامل فارسی:** [docs/GUIDE.fa.md](docs/GUIDE.fa.md)
|
|
185
|
+
|
|
186
|
+
```bash
|
|
187
|
+
pip install dl-doctor
|
|
188
|
+
pip install "dl-doctor[plots]" # برای نمودارها
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
```python
|
|
192
|
+
import dldoctor as dd
|
|
193
|
+
گزارش = dd.diagnose(history={"loss": [...], "val_loss": [...]})
|
|
194
|
+
print(گزارش.to_text("fa")) # فقط فارسی
|
|
195
|
+
گزارش.save("report.html") # گزارش با توضیح و راهحل
|
|
196
|
+
print(dd.explain("LR_DIVERGING", "fa")) # توضیح کامل یک کد
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
بررسیها تشخیصهای تجربی (heuristic) هستند؛ هشدار یعنی «نگاه کنید»، نه اثبات خطا. خروجی انصاف (fairness) فقط یکی از
|
|
200
|
+
چند معیار است و بهتنهایی حکم نهایی نیست.
|
|
201
|
+
|
|
202
|
+
## Book, license and attribution
|
|
203
|
+
|
|
204
|
+
The **code** of this library is released under the MIT License (see `LICENSE`).
|
|
205
|
+
|
|
206
|
+
The companion **book** is a separate work licensed under
|
|
207
|
+
[CC BY-NC 4.0](https://creativecommons.org/licenses/by-nc/4.0). This repository contains only short, original
|
|
208
|
+
messages that point to chapter numbers; it does not reproduce the book's text, figures or code. If you reuse the
|
|
209
|
+
book itself, keep its attribution and update link:
|
|
210
|
+
|
|
211
|
+
- Authors: Dr. Dariush Alipour and Dr. Minoosh Heidari (انتشارات علیپور، تیروتیر), first edition, Aban 1405 (Nov 2026)
|
|
212
|
+
- Telegram: [@AI_and_Philosophy](https://t.me/AI_and_Philosophy)
|
|
213
|
+
- GitHub: <https://github.com/worker2025/DL_book> and <https://github.com/worker2025/>
|
|
214
|
+
- Web: <https://tirotir.ir>
|
|
215
|
+
|
|
216
|
+
Chapter numbers in findings refer to the first edition and may change in later editions.
|
|
217
|
+
|
|
218
|
+
---
|
|
219
|
+
|
|
220
|
+
*dl-doctor · By [Tirotir.com](https://tirotir.com)*
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
# dl-doctor
|
|
2
|
+
|
|
3
|
+
**A bilingual (Persian / English) doctor for deep-learning training.** *By [Tirotir.com](https://tirotir.com)*
|
|
4
|
+
|
|
5
|
+
`dl-doctor` reads your training curves, datasets, predictions, gradients and models and tells you what is
|
|
6
|
+
probably wrong, **why it happens and how to fix it**, in Persian and English: a learning rate that is too high,
|
|
7
|
+
overfitting, test-set leakage through normalisation, vanishing gradients, dead ReLUs, an inverted digit image,
|
|
8
|
+
a model left in training mode. It also writes shareable HTML reports and draws loss curves, confusion matrices
|
|
9
|
+
and group-rate charts with correctly joined right-to-left Persian text.
|
|
10
|
+
|
|
11
|
+
Built as a companion to the Persian book
|
|
12
|
+
*یادگیری عمیق؛ با پروژههای کاربردی برای مربیان و علاقهمندان کارگاههای هوش مصنوعی*
|
|
13
|
+
(Dr. Dariush Alipour and Dr. Minoosh Heidari); each finding points to the book chapter that covers the topic.
|
|
14
|
+
The library does **not** depend on the book and works with any PyTorch / Keras / NumPy workflow.
|
|
15
|
+
|
|
16
|
+
- Core dependency: NumPy only. PyTorch, Keras and matplotlib are optional and never imported unless you use them.
|
|
17
|
+
- Python 3.9+.
|
|
18
|
+
- 📘 **Full Persian guide:** [docs/GUIDE.fa.md](docs/GUIDE.fa.md) · 📋 all codes: [docs/CODES.md](docs/CODES.md) ·
|
|
19
|
+
🧪 [examples/](examples/)
|
|
20
|
+
|
|
21
|
+
## Install
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
pip install dl-doctor # diagnostics only
|
|
25
|
+
pip install "dl-doctor[plots]" # + matplotlib plots
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Quick start
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
import dldoctor as dd
|
|
32
|
+
|
|
33
|
+
history = {
|
|
34
|
+
"loss": [1.0, 0.8, 0.6, 0.5, 0.4, 0.3, 0.2, 0.1],
|
|
35
|
+
"val_loss": [1.0, 0.8, 0.7, 0.75, 0.8, 0.9, 1.0, 1.1],
|
|
36
|
+
}
|
|
37
|
+
report = dd.diagnose(history=history)
|
|
38
|
+
print(report) # English + Persian
|
|
39
|
+
report.to_text("fa") # Persian only
|
|
40
|
+
report.save("report.html") # shareable page with explanations and fixes
|
|
41
|
+
report.raise_for_errors() # raise TrainingProblem if any ERROR finding
|
|
42
|
+
|
|
43
|
+
print(dd.explain("OVERFITTING_VAL_RISING")) # why it happens, how to fix it
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Everything at once; every argument is optional:
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
report = dd.diagnose(
|
|
50
|
+
history=history, # dict, Keras History or HistoryRecorder
|
|
51
|
+
X_train=X_train, y_train=y_train, X_test=X_test, # leakage, scaling, class balance
|
|
52
|
+
y_pred=y_pred, groups=gender, # statistical parity
|
|
53
|
+
model=model, model_expect="eval", # PyTorch-like module
|
|
54
|
+
grad_norms=dd.gradient_norms(model), # vanishing / exploding gradients
|
|
55
|
+
activations=hidden_output, # dead ReLUs
|
|
56
|
+
digit_image=img28x28, # MNIST-style deployment check
|
|
57
|
+
)
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
In a hand-written loop:
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
rec = dd.HistoryRecorder()
|
|
64
|
+
for epoch in range(epochs):
|
|
65
|
+
...
|
|
66
|
+
rec.log(loss=train_loss, val_loss=val_loss, accuracy=train_acc, val_accuracy=val_acc)
|
|
67
|
+
print(rec.diagnose())
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### What it checks (28 codes)
|
|
71
|
+
|
|
72
|
+
| Area | Finding codes |
|
|
73
|
+
|------|---------------|
|
|
74
|
+
| Training curves | `TRAIN_NONFINITE`, `LR_DIVERGING`, `LR_OSCILLATING`, `LR_STALLED`, `OVERFITTING_VAL_RISING`, `OVERFITTING_GAP`, `NO_VALIDATION_METRICS` |
|
|
75
|
+
| Network internals | `GRAD_VANISHING`, `GRAD_EXPLODING`, `DEAD_RELU` |
|
|
76
|
+
| Data | `DATA_NONFINITE`, `DATA_SPLIT_OVERLAP`, `NORM_FIT_ON_FULL_DATA`, `NORM_PER_SPLIT`, `DATA_UNSCALED`, `CLASS_IMBALANCE` |
|
|
77
|
+
| Fairness | `FAIRNESS_PARITY`, `FAIRNESS_OK` |
|
|
78
|
+
| Deployment | `DIGIT_SHAPE`, `DIGIT_BLANK`, `DIGIT_RANGE`, `DIGIT_BACKGROUND`, `DIGIT_SIZE`, `DIGIT_OFF_CENTER` |
|
|
79
|
+
| Frameworks | `TORCH_TRAIN_MODE`, `TORCH_EVAL_MODE_IN_TRAINING`, `TORCH_NONFINITE_PARAMS` |
|
|
80
|
+
|
|
81
|
+
Each `Finding` has `code`, `severity` (`INFO` / `WARNING` / `ERROR`), `message_fa`, `message_en`, `chapter`
|
|
82
|
+
and `details`. The checks are heuristics: a warning is a hint to look, not proof of a bug. Fairness output in
|
|
83
|
+
particular is one metric among several and never a verdict on its own.
|
|
84
|
+
|
|
85
|
+
## Persian plots
|
|
86
|
+
|
|
87
|
+
```python
|
|
88
|
+
from dldoctor.plots import plot_history, plot_confusion_matrix, plot_group_rates
|
|
89
|
+
|
|
90
|
+
plot_history(history, lang="fa", save="curves.png")
|
|
91
|
+
plot_confusion_matrix(y_true, y_pred, labels=["گربه", "سگ", "پرنده"], save="cm.png")
|
|
92
|
+
plot_group_rates({"الف": 0.80, "ب": 0.45}, save="rates.png")
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Recent matplotlib releases join and reorder Arabic-script text themselves; `dl-doctor` detects this at run time.
|
|
96
|
+
On older releases it falls back to a built-in, dependency-free shaper (`dldoctor.shape_text`) that works for short
|
|
97
|
+
labels. Persian digits are used automatically. For the best look install a Persian font such as Vazirmatn;
|
|
98
|
+
otherwise DejaVu Sans is used.
|
|
99
|
+
|
|
100
|
+
## Command line
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
dldoctor check history.json # or .csv; exit status 1 on ERROR (--fail-on warning|never)
|
|
104
|
+
dldoctor check history.json --lang fa --json
|
|
105
|
+
dldoctor report history.json --out report.html # .html, .md or .json
|
|
106
|
+
dldoctor explain LR_DIVERGING # why + how to fix, fa and en
|
|
107
|
+
dldoctor list # every code (add --md for the full reference)
|
|
108
|
+
dldoctor check-digit digit.npy # a 28x28 image saved with numpy
|
|
109
|
+
dldoctor plot history.json --out curves.png
|
|
110
|
+
dldoctor demo
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Examples
|
|
114
|
+
|
|
115
|
+
| File | Shows |
|
|
116
|
+
|------|-------|
|
|
117
|
+
| `01_quickstart.py` | six common mistakes diagnosed in one call each |
|
|
118
|
+
| `02_numpy_mlp_from_scratch.py` | a tiny NumPy network trained four ways: clean, diverging, overfitting, dead ReLU |
|
|
119
|
+
| `03_data_checks.py` | leakage, wrong normalisation, duplicates, imbalance, unscaled pixels |
|
|
120
|
+
| `04_fairness_and_deployment.py` | statistical parity and digit-image deployment mistakes |
|
|
121
|
+
| `05_pytorch.py`, `06_keras.py` | framework loops (need torch / tensorflow) |
|
|
122
|
+
| `07_reports_plots_and_cli.py` | HTML/Markdown reports, `explain`, Persian plots, CLI |
|
|
123
|
+
|
|
124
|
+
## Limitations
|
|
125
|
+
|
|
126
|
+
- The PyTorch checks are duck-typed (`model.training`, `model.named_parameters()`, `param.grad`); they were tested
|
|
127
|
+
with stand-in objects, not against every PyTorch release. Examples 05 and 06 need real torch / tensorflow and are
|
|
128
|
+
not part of the automated tests.
|
|
129
|
+
- `check_split_overlap` compares rows bit-for-bit, so it finds exact duplicates only.
|
|
130
|
+
- Normalisation checks need at least 30 rows in each split and standardised (mean 0, std 1) data.
|
|
131
|
+
|
|
132
|
+
---
|
|
133
|
+
|
|
134
|
+
## فارسی
|
|
135
|
+
|
|
136
|
+
`dl-doctor` منحنی آموزش، دادهها، پیشبینیها، گرادیانها و مدل شما را بررسی میکند و به **فارسی و انگلیسی** میگوید
|
|
137
|
+
چه چیزی احتمالاً مشکل دارد، **چرا رخ میدهد و چطور درستش کنیم**: نرخ یادگیری بزرگ، بیشبرازش، نشت داده در نرمالسازی، محو
|
|
138
|
+
گرادیان، ReLU مرده، تصویر وارونهٔ رقم دستنویس، یا مدلی که در حالت آموزش مانده است. گزارش HTML قابل اشتراک میسازد و
|
|
139
|
+
نمودارها (منحنی هزینه، ماتریس درهمریختگی، نرخ گروهها) را با متن فارسیِ درست رسم میکند.
|
|
140
|
+
|
|
141
|
+
هر یافته به فصل مربوط در کتاب «یادگیری عمیق؛ با پروژههای کاربردی برای مربیان و علاقهمندان کارگاههای هوش مصنوعی»
|
|
142
|
+
(دکتر داریوش علیپور – دکتر مینوش حیدری) ارجاع میدهد؛ ولی کتابخانه به کتاب وابسته نیست و با هر پروژهٔ PyTorch / Keras / NumPy
|
|
143
|
+
کار میکند.
|
|
144
|
+
|
|
145
|
+
📘 **راهنمای کامل فارسی:** [docs/GUIDE.fa.md](docs/GUIDE.fa.md)
|
|
146
|
+
|
|
147
|
+
```bash
|
|
148
|
+
pip install dl-doctor
|
|
149
|
+
pip install "dl-doctor[plots]" # برای نمودارها
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
```python
|
|
153
|
+
import dldoctor as dd
|
|
154
|
+
گزارش = dd.diagnose(history={"loss": [...], "val_loss": [...]})
|
|
155
|
+
print(گزارش.to_text("fa")) # فقط فارسی
|
|
156
|
+
گزارش.save("report.html") # گزارش با توضیح و راهحل
|
|
157
|
+
print(dd.explain("LR_DIVERGING", "fa")) # توضیح کامل یک کد
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
بررسیها تشخیصهای تجربی (heuristic) هستند؛ هشدار یعنی «نگاه کنید»، نه اثبات خطا. خروجی انصاف (fairness) فقط یکی از
|
|
161
|
+
چند معیار است و بهتنهایی حکم نهایی نیست.
|
|
162
|
+
|
|
163
|
+
## Book, license and attribution
|
|
164
|
+
|
|
165
|
+
The **code** of this library is released under the MIT License (see `LICENSE`).
|
|
166
|
+
|
|
167
|
+
The companion **book** is a separate work licensed under
|
|
168
|
+
[CC BY-NC 4.0](https://creativecommons.org/licenses/by-nc/4.0). This repository contains only short, original
|
|
169
|
+
messages that point to chapter numbers; it does not reproduce the book's text, figures or code. If you reuse the
|
|
170
|
+
book itself, keep its attribution and update link:
|
|
171
|
+
|
|
172
|
+
- Authors: Dr. Dariush Alipour and Dr. Minoosh Heidari (انتشارات علیپور، تیروتیر), first edition, Aban 1405 (Nov 2026)
|
|
173
|
+
- Telegram: [@AI_and_Philosophy](https://t.me/AI_and_Philosophy)
|
|
174
|
+
- GitHub: <https://github.com/worker2025/DL_book> and <https://github.com/worker2025/>
|
|
175
|
+
- Web: <https://tirotir.ir>
|
|
176
|
+
|
|
177
|
+
Chapter numbers in findings refer to the first edition and may change in later editions.
|
|
178
|
+
|
|
179
|
+
---
|
|
180
|
+
|
|
181
|
+
*dl-doctor · By [Tirotir.com](https://tirotir.com)*
|